From 3c2e630e5acd9212f2707ec05c714ffbc6d7eb33 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Wed, 18 Dec 2024 15:32:22 +0600 Subject: [PATCH] Sync with config buttons done --- source/ubl-settings-usergroups.c | 84 +++++++++++++++++++------------- source/ubl-settings-usergroups.h | 4 ++ source/ubl-strings.h | 2 + 3 files changed, 57 insertions(+), 33 deletions(-) diff --git a/source/ubl-settings-usergroups.c b/source/ubl-settings-usergroups.c index 9d41bc1..dcc243e 100644 --- a/source/ubl-settings-usergroups.c +++ b/source/ubl-settings-usergroups.c @@ -149,7 +149,6 @@ void yon_interface_update(main_window *widgets){ if (parameters_size>1&&!strcmp(parameters[1],"x")) parameters[1]=""; char *pars=""; if (parameters_size>4&&strcmp(parameters[4],"x")&&strcmp(parameters[4],"")){ - if (!check_is_password_hash(parameters[4])&¶meters[4][0]!='%'&¶meters[4][1]!='%'){ pars = ENCRYPTED_LABEL; } else { @@ -2110,7 +2109,7 @@ void on_user_save(GtkWidget *self, dictionary *dict){ if (user_shell_active>0){ char *shell_string = (char*)gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(window->userShellCombo)); if (strcmp(shell_string,SET_LABEL)){ - user_shell = yon_char_unite("--shell ",shell_string,NULL); + user_shell = yon_char_unite("--shell ",shell_string," ",NULL); } else { user_shell = yon_char_unite("--shell ",(char*)gtk_entry_get_text(GTK_ENTRY(window->userShellEntry)),NULL); } @@ -2800,7 +2799,7 @@ void on_config_update(GtkWidget *, main_window *widgets){ void on_user_sync_with_config(GtkWidget *,main_window *widgets){ int active = gtk_notebook_get_current_page(GTK_NOTEBOOK(widgets->MainNotebook)); switch (active){ - case 2: + case 2:{ GtkTreeModel *model = GTK_TREE_MODEL(widgets->liststore1); GtkTreeIter iter; if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->SystemTree)),&model,&iter)){ @@ -2819,40 +2818,59 @@ void on_user_sync_with_config(GtkWidget *,main_window *widgets){ if (yon_confirmation_dialog_call(widgets->Window,&data)!=GTK_RESPONSE_ACCEPT){ return; } - int size; - config_str passwd_users = yon_file_open(users_path,&size); - int active_usr = yon_char_parsed_strstr(passwd_users,size,target); - int cur_size; - if (size){ - yon_char_remove_last_symbol(passwd_users[active_usr],'\n'); - config_str cur_user = yon_char_parse(passwd_users[active_usr],&cur_size,":"); - int final_size=0; - config_str final_user_parsed = NULL; - yon_char_parsed_add_or_create_if_exists(final_user_parsed,&final_size,cur_user[4]); - yon_char_parsed_add_or_create_if_exists(final_user_parsed,&final_size,cur_user[3]); - yon_char_parsed_add_or_create_if_exists(final_user_parsed,&final_size,"x"); - char *extra_groups = yon_char_unite(!yon_char_is_empty(cur_user[6])?"--shell ":"",!yon_char_is_empty(cur_user[6])?cur_user[6]:"",!yon_char_is_empty(cur_user[6])?" ":"",!yon_char_is_empty(cur_user[5])?"--home-dir ":"",!yon_char_is_empty(cur_user[5])?cur_user[5]:"",NULL); - yon_char_parsed_add_or_create_if_exists(final_user_parsed,&final_size,extra_groups); - yon_char_parsed_add_or_create_if_exists(final_user_parsed,&final_size,cur_user[1]); - char *final_user = yon_char_parsed_to_string(final_user_parsed,final_size,":"); - if (config(USERADD(target))){ - char *final_command = yon_config_parameter_prepare_command(dull_parameter_get_command,NULL,"users",USERADD_SYNC(target)); - yon_config_register(USERADD_SYNC(target),final_command,final_user); - - } else { - char *final_command = yon_config_parameter_prepare_command(dull_parameter_get_command,NULL,"users",USERADD(target)); - yon_config_register(USERADD(target),final_command,final_user); + int user_size; + int shadow_size; + config_str user = yon_config_load(yon_debug_output("%s\n",get_system_user_command(target)),&user_size); + if (user_size>0){ + yon_char_remove_last_symbol(user[0],'\n'); + free(yon_char_divide_search(user[0],"=",-1)); + yon_char_remove_brackets(user[0]); + char *user_command = yon_config_parameter_prepare_command(dull_parameter_get_command,NULL,"users",USERADD(target)); + yon_config_register(USERADD(target),user_command,user[0]); + } + config_str shadow = yon_config_load(yon_debug_output("%s\n",get_system_shadow_command(target)),&shadow_size); + if (shadow_size>0){ + yon_char_remove_last_symbol(shadow[0],'\n'); + free(yon_char_divide_search(shadow[0],"=",-1)); + yon_char_remove_brackets(shadow[0]); + char *shadow_command = yon_config_parameter_prepare_command(dull_parameter_get_command,NULL,"users",USERSHADOW(target)); + yon_config_register(USERSHADOW(target),shadow_command,shadow[0]); - } - - // int shadow_size; - // config_str shadow = yon_file_open(shadow_path,&shadow_size); } } yon_interface_update((main_window*)widgets); - break; - case 3: - break; + }break; + case 3:{ + GtkTreeModel *model = GTK_TREE_MODEL(widgets->liststore1); + GtkTreeIter iter; + if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->SystemGroupsTree)),&model,&iter)){ + + char *target; + gtk_tree_model_get(model,&iter,1,&target,-1); + dialog_confirmation_data data; + if (config(USERADD(target))){ + data.action_text = SYSTEM_GROUP_SYNC_CONFIRMATION_LABEL(target); + data.data=NULL; + data.function=NULL; + } else { + data.action_text = SYSTEM_GROUP_ADD_CONFIRMATION_LABEL(target); + data.data=NULL; + data.function=NULL; + } + if (yon_confirmation_dialog_call(widgets->Window,&data)!=GTK_RESPONSE_ACCEPT){ + return; + } + int group_size; + config_str group = yon_config_load(get_system_group_command(target),&group_size); + if (group_size>0){ + yon_char_remove_last_symbol(group[0],'\n'); + free(yon_char_divide_search(group[0],"=",-1)); + yon_char_remove_brackets(group[0]); + char *group_command = yon_config_parameter_prepare_command(dull_parameter_get_command,NULL,"users",USERADD(target)); + yon_config_register(GROUPADD(target),group_command,group[0]); + } + } + }break; } } diff --git a/source/ubl-settings-usergroups.h b/source/ubl-settings-usergroups.h index bef5bd8..b2c05c9 100644 --- a/source/ubl-settings-usergroups.h +++ b/source/ubl-settings-usergroups.h @@ -47,6 +47,10 @@ #define get_passwords_command "ubconfig --target global get [users] USERADD[*] GROUPADD[*]" #define check_is_password_hash(password) system(yon_char_unite("/lib/ublinux/functions is_hash_password '", password,"'",NULL)) +#define get_system_user_command(target) yon_char_unite("/usr/lib/ublinux/functions get_conf_useradd_from_system ",target,NULL) +#define get_system_shadow_command(target) yon_char_unite("/usr/lib/ublinux/functions get_conf_usershadow_from_system ",target,NULL) +#define get_system_group_command(target) yon_char_unite("/usr/lib/ublinux/functions get_conf_groupadd_from_system ",target,NULL) + #define groups_path "/etc/group" #define users_path "/etc/passwd" #define shadow_path "/etc/shadow" diff --git a/source/ubl-strings.h b/source/ubl-strings.h index d77577b..3f25dd8 100644 --- a/source/ubl-strings.h +++ b/source/ubl-strings.h @@ -53,6 +53,8 @@ #define SYSTEM_USER_ADD_CONFIRMATION_LABEL(target) yon_char_unite(_("This user doesn't exist in configuration. Are you sure want to add user")," ",target," ", _("to configuration?"),NULL) #define SYSTEM_USER_SYNC_CONFIRMATION_LABEL(target) yon_char_unite(_("This user exists in configuration. Are you sure want to update user")," ",target," ", _("data at configuration?"),NULL) +#define SYSTEM_GROUP_SYNC_CONFIRMATION_LABEL(target) yon_char_unite(_("This group doesn't exist in configuration. Are you sure want to add group")," ",target," ", _("to configuration?"),NULL) +#define SYSTEM_GROUP_ADD_CONFIRMATION_LABEL(target) yon_char_unite(_("This group exists in configuration. Are you sure want to update group")," ",target," ", _("data at configuration?"),NULL) //ubl-settings-usergroups-additional-settings.glade