Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cellframe/libdap-server-http-db-auth
1 result
Show changes
Commits on Source (4)
#pragma once
#define DAP_APP_NAME NODE_NETNAME "-node"
//#ifdef _WIN32
// #define SYSTEM_PREFIX "%USERPROFILE%/opt/"DAP_APP_NAME
//#else
#define SYSTEM_PREFIX "/opt/"DAP_APP_NAME
// #define SYSTEM_PREFIX "opt/"DAP_APP_NAME
//#endif
#define LOCAL_PREFIX "~/."DAP_APP_NAME
#define SYSTEM_CONFIGS_DIR SYSTEM_PREFIX"/etc"
#define LOCAL_CONFIGS_DIR LOCAL_PREFIX"/etc"
#define SYSTEM_LOGS_DIR SYSTEM_PREFIX"/var/log"
#define SYSTEM_CONFIG_GLOBAL_FILENAME SYSTEM_PREFIX"/etc/"DAP_APP_NAME".cfg"
#define LOCAL_CONFIG_GLOBAL LOCAL_PREFIX"/etc/"DAP_APP_NAME".cfg"
#define SYSTEM_PID_FILE_PATH SYSTEM_PREFIX"/run/"DAP_APP_NAME".pid"
#define LOCAL_PID_FILE_PATH SYSTEM_PREFIX"/run/"DAP_APP_NAME".pid"
......@@ -30,13 +30,12 @@
//#include "dap_client.h"
#include "dap_common.h"
#include "dap_config.h"
#include "dap_strfuncs.h"
#ifdef _WIN32
#include "registry.h"
#endif
#include "dap_defines.h"
#include "db_auth.h"
static void s_help(const char * a_app_name)
......@@ -49,22 +48,27 @@ static void s_help(const char * a_app_name)
int main(int argc, const char * argv[])
{
#ifdef _WIN32
dap_sprintf(s_sys_dir_path, "%s/%s", regGetUsrPath(), DAP_APP_NAME);
l_sys_dir_path_len = strlen(s_sys_dir_path);
#endif
// set_default_locale();
// command_execution_string = shell_script_filename = (char *) NULL;
dap_set_appname("http_db_auth_tool");
#ifdef DAP_OS_LINUX
g_sys_dir_path = dap_strdup_printf("/opt/%s",dap_get_appname() );
#elif _WIN32
dap_sprintf(s_sys_dir_path, "%s/%s", regGetUsrPath(), dap_get_appname() );
#endif
g_sys_dir_path_len = strlen(g_sys_dir_path);
char * l_app_title = dap_strdup_printf("%s console interface",dap_get_appname());
char * l_config_path = dap_strdup_printf("%s/etc", g_sys_dir_path);
memcpy(s_sys_dir_path + l_sys_dir_path_len, SYSTEM_CONFIGS_DIR, sizeof(SYSTEM_CONFIGS_DIR) );
dap_common_init( DAP_APP_NAME " Console interface", NULL );
dap_common_init( l_app_title, NULL );
dap_log_level_set( L_CRITICAL );
dap_config_init( s_sys_dir_path );
memset(s_sys_dir_path + l_sys_dir_path_len, '\0', MAX_PATH - l_sys_dir_path_len);
dap_config_init( g_sys_dir_path );
if((g_config = dap_config_open(DAP_APP_NAME)) == NULL) {
printf("Can't init general configurations " DAP_APP_NAME ".cfg\n");
if((g_config = dap_config_open(dap_get_appname())) == NULL) {
printf("Can't init general configurations %s.cfg\n",dap_get_appname());
exit(-1);
}
......
......@@ -698,8 +698,8 @@ int db_auth_login(const char* login, const char* password,
log_it(L_INFO,"Login accepted");
*ai = DAP_NEW_Z(db_auth_info_t);
strncpy((*ai)->user,login,sizeof((*ai)->user));
strncpy((*ai)->password,password,sizeof((*ai)->password));
strncpy((*ai)->user,login,sizeof((*ai)->user)-1);
strncpy((*ai)->password,password,sizeof((*ai)->password)-1);
if ( !bson_iter_init (&iter, doc) )
log_it(L_ERROR,"Error iter init");
......@@ -719,17 +719,17 @@ int db_auth_login(const char* login, const char* password,
if (bson_iter_init (&iter, doc) &&
bson_iter_find_descendant (&iter, "profile.first_name", &sub_iter))
strncpy((*ai)->first_name,bson_iter_value(&sub_iter)->value.v_utf8.str,
sizeof((*ai)->first_name));
sizeof((*ai)->first_name)-1);
if (bson_iter_init (&iter, doc) &&
bson_iter_find_descendant (&iter, "profile.last_name", &sub_iter))
strncpy((*ai)->last_name,bson_iter_value(&sub_iter)->value.v_utf8.str,
sizeof((*ai)->last_name));
sizeof((*ai)->last_name)-1);
if (bson_iter_init (&iter, doc) &&
bson_iter_find_descendant (&iter, "profile.email", &sub_iter))
strncpy((*ai)->email,bson_iter_value(&sub_iter)->value.v_utf8.str,
sizeof((*ai)->email));
sizeof((*ai)->email)-1);
for(int i=0; i < sizeof((*ai)->cookie); i++)
(*ai)->cookie[i] = 65 + rand() % 25;
......@@ -851,11 +851,11 @@ db_auth_info_t * db_auth_register(const char *user,const char *password,
else
{
db_auth_info_t * ai = DAP_NEW_Z(db_auth_info_t);
strncpy(ai->user,user,sizeof(ai->user));
strncpy(ai->password,password,sizeof(ai->password));
strncpy(ai->last_name,last_name,sizeof(ai->last_name));
strncpy(ai->first_name,first_name,sizeof(ai->first_name));
strncpy(ai->email,email,sizeof(ai->email));
strncpy(ai->user,user,sizeof(ai->user)-1);
strncpy(ai->password,password,sizeof(ai->password)-1);
strncpy(ai->last_name,last_name,sizeof(ai->last_name)-1);
strncpy(ai->first_name,first_name,sizeof(ai->first_name)-1);
strncpy(ai->email,email,sizeof(ai->email)-1);
for(int i=0;i<sizeof(ai->cookie);i++)
ai->cookie[i]=65+rand()%25;
......@@ -943,10 +943,10 @@ db_auth_info_t * db_auth_register_channel(const char* name_channel, const char*
}
db_auth_info_t * ai = DAP_NEW_Z(db_auth_info_t);
strncpy(ai->user,name_channel,sizeof(ai->user));
strncpy(ai->password,password,sizeof(ai->password));
strncpy(ai->user,name_channel,sizeof(ai->user)-1);
strncpy(ai->password,password,sizeof(ai->password)-1);
for(int i=0;i<sizeof(ai->cookie);i++)
for(size_t i=0;i<sizeof(ai->cookie);i++)
ai->cookie[i]=65+rand()%25;
pthread_mutex_lock(&mutex_on_auth_hash);
......@@ -1038,13 +1038,18 @@ void db_auth_http_proc(enc_http_delegate_t *a_delegate, void * a_arg)
char l_password[1024]={0};
char l_domain[64]={0};
char l_pkey[4096]={0};
char l_something[64] = {0};
if(sscanf(a_delegate->request_str,"%255s %1023s %63s %4095s",l_user,l_password,l_domain,l_pkey)>=3){
if(sscanf(a_delegate->request_str,"%255s %1023s %63s %4095s %64s",l_user,l_password,l_domain,l_pkey,l_something)>=3){
log_it(L_INFO, "Trying to login with username '%s'",l_user);
if(!check_user_data_for_space(strlen(a_delegate->request_str), (strlen(l_user)+strlen(l_password)+strlen(l_domain)))){
log_it(L_WARNING,"Wrong symbols in username or password or domain");
log_it(L_DEBUG,"%s@%s %s", l_user,l_pkey);
if(!check_user_data_for_space(strlen(a_delegate->request_str), strlen(l_user) + strlen(l_password) + strlen(l_domain) + strlen(l_pkey) + strlen(l_something))){
log_it(L_WARNING,"Wrong symbols in username or password or domain, misfit is %d", strlen(a_delegate->request_str) - strlen(l_user) - strlen(l_password) - strlen(l_domain) - strlen(l_pkey) - strlen(l_something));
//log_it(L_WARNING, "l_user size: %d", strlen(l_user));
//log_it(L_WARNING, "l_pass size: %d", strlen(l_password));
//log_it(L_WARNING, "l_pkey size: %d", strlen(l_pkey));
log_it(L_DEBUG,"%s@%s", l_user, l_password);
enc_http_reply_f(a_delegate, OP_CODE_INCORRECT_SYMOLS);
*return_code = Http_Status_BadRequest;
return;
......@@ -1243,5 +1248,5 @@ static bool mongod_is_running()
/// (there are 2 separator spaces), otherwise false.
bool check_user_data_for_space(size_t before_parsing, size_t after_parsing)
{
return (before_parsing - after_parsing) == 2;
return (before_parsing - after_parsing) == 3;
}