From 494c6feca44f009eb68f2c1dfb820a2f1ede7acc Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Fri, 5 Apr 2024 10:22:41 +0600 Subject: [PATCH] Test fix for add . at password beginning --- source/ubl-settings-usergroups.c | 68 +++++++++++++++++++++++++------- source/ubl-settings-usergroups.h | 1 + 2 files changed, 54 insertions(+), 15 deletions(-) diff --git a/source/ubl-settings-usergroups.c b/source/ubl-settings-usergroups.c index ac3537a..21837f0 100644 --- a/source/ubl-settings-usergroups.c +++ b/source/ubl-settings-usergroups.c @@ -104,6 +104,8 @@ void yon_interface_update(main_window *widgets){ if (!check_is_password_hash(parameters[5])&¶meters[5][0]!='%'&¶meters[5][1]!='%'){ pars = ENCRYPTED_LABEL; + } else if (!strcmp(parameters[5],"!*")){ + pars = NO_PASSWORD_LABEL; } else { pars = UNENCRYPTED_LABEL; @@ -113,7 +115,7 @@ void yon_interface_update(main_window *widgets){ } gtk_list_store_set(widgets->UsersList,&iter, - 0,parameters[5][0]=='!'||parameters[5][0]=='*', + 0,(parameters[5][0]=='!'||parameters[5][0]=='*')||(parameters[5][0]=='!'&¶meters[5][1]=='*'), 2,login, 3,parameters_size>0?parameters[0]:"", 1,parameters_size>1&&!yon_char_is_empty(parameters[1])?parameters[1]:"", @@ -394,6 +396,19 @@ void on_save_done(main_window *widgets, config_str output, int size){ yon_accept_changes(); yon_samba_sync_proceed(); } + textdomain(template_ui_LocaleName); + switch (main_config.save_config){ + case 0: + yon_ubl_status_box_render(GLOBAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE); + break; + case 1: + yon_ubl_status_box_render(LOCAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE); + break; + case 2: + yon_ubl_status_box_render(GLOBAL_LOCAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE); + break; + } + textdomain(LocaleName); } @@ -401,6 +416,7 @@ void on_save_done(main_window *widgets, config_str output, int size){ void on_config_save(GtkWidget *self, main_window *widgets){ yon_accept_changes(); yon_samba_sync_proceed(); + main_config.save_config=2; template_saving_window *window = yon_save_proceed(NULL,YON_CONFIG_BOTH,config_get_command("global"),NULL); if (window){ if (main_config.load_mode==0){ @@ -459,6 +475,7 @@ void on_config_save(GtkWidget *self, main_window *widgets){ } void on_config_global_save(GtkWidget *self, main_window *widgets){ + main_config.save_config=0; template_saving_window *window = yon_save_proceed("global",YON_CONFIG_GLOBAL,config_get_command("global"),NULL); if (window){ yon_hide_passwords(window); @@ -466,6 +483,7 @@ void on_config_global_save(GtkWidget *self, main_window *widgets){ } void on_config_local_save(GtkWidget *self, main_window *widgets){ + main_config.save_config=1; int size; config_str keys = yon_config_get_all_by_key(USERADD_SEARCH_macro,&size); int passw_size; @@ -489,8 +507,6 @@ void on_config_local_save(GtkWidget *self, main_window *widgets){ } yon_accept_changes(); yon_samba_sync_proceed(); - // char *output = yon_config_save_simple(YON_CONFIG_LOCAL,"system"); - // if (output) puts(output); template_saving_window *window = yon_save_proceed("system",YON_CONFIG_LOCAL,config_get_command("system"),NULL); if (window){ yon_hide_passwords(window); @@ -503,6 +519,7 @@ void on_config_local_save(GtkWidget *self, main_window *widgets){ } void on_config_custom_save(GtkWidget *self, main_window *widgets){ + main_config.save_config=1; template_saving_window *window = yon_save_proceed(NULL,YON_CONFIG_CUSTOM,config_get_command("system"),NULL); if (window){ yon_hide_passwords(window); @@ -659,6 +676,25 @@ void yon_group_delete_confirmation_save(GtkWidget *self, dictionary *dict){ on_subwindow_close(self); } +int yon_check_password_blocked(char *password){ + if (!yon_char_is_empty(password)){ + if (!strcmp(password,"!*")){ + memset(password,0,strlen(password)); + return 1; + } else if (password[0]=='!'&&password[1]=='*'){ + char *copy = yon_char_new(password); + memcpy(copy,password+2,strlen(password+2)); + memset(password,0,strlen(password)); + memcpy(password,copy,strlen(copy)); + free(copy); + return 1; + } else if (password[0]=='!'||password[0]=='*'){ + free(yon_char_divide(password,0)); + return 1; + } + } else return 0; +} + yon_confirmation_window *yon_delete_confirmation_new(){ yon_confirmation_window *window = malloc(sizeof(yon_confirmation_window)); GtkBuilder *builder = gtk_builder_new_from_resource(glade_path_ubl_settings_usergroups_confirmation); @@ -1883,14 +1919,16 @@ void on_user_save(GtkWidget *self, dictionary *dict){ yon_ubl_status_highlight_incorrect(window->userPasswordEntry); return; } - } else { - password=""; + } else if (password_active==1){ + password = "!*"; + } else { + password=""; } char *old_password = NULL; if (window->old_password){ old_password = window->old_password; - if (old_password[0]=='!'||old_password[0]=='*') free(yon_char_divide(old_password,0)); + yon_check_password_blocked(old_password); } if (!old_password||old_password&&strcmp(old_password,password)){ time_t t = time(NULL); @@ -2493,19 +2531,18 @@ void on_main_edit(GtkWidget *self, main_window *widgets){ } } if (parsed_size>5){ - window->old_password=yon_char_new(parameters[5]); - if (!yon_char_is_empty(window->old_password)&&strlen(window->old_password)&&window->old_password[0]=='!'&&window->old_password[1]=='*'){ - free(yon_char_divide(window->old_password,1)); - } - if (!strcmp(parameters[5],"!*")) parameters[5][1]='\0'; + window->old_password=yon_char_new(parameters[5]); if (strcmp(parameters[5],"x")&&strcmp(parameters[5],"")){ - if (parameters[5][0]=='!'||parameters[5][0]=='*'){ + if (yon_check_password_blocked(parameters[5])){ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->userDeactivatedCheck),1); } - free(yon_char_divide(parameters[5],0)); if (!yon_char_is_empty(parameters[5])){ - gtk_entry_set_text(GTK_ENTRY(window->userPasswordEntry),parameters[5]); - gtk_combo_box_set_active(GTK_COMBO_BOX(window->userPasswordCombo),2); + if (!strcmp(parameters[5],"!*")){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->userPasswordCombo),1); + } else { + gtk_entry_set_text(GTK_ENTRY(window->userPasswordEntry),parameters[5]); + gtk_combo_box_set_active(GTK_COMBO_BOX(window->userPasswordCombo),2); + } } } } @@ -2674,6 +2711,7 @@ void config_init(){ main_config.users_size=0; main_config.load_mode=1; main_config.hash_default_id=-1; + main_config.save_config=0; main_config.groups = yon_file_open(groups_path,&main_config.groups_size); main_config.users = yon_file_open(users_path,&main_config.users_size); main_config.users_list=NULL; diff --git a/source/ubl-settings-usergroups.h b/source/ubl-settings-usergroups.h index e14a39b..9a7fb76 100644 --- a/source/ubl-settings-usergroups.h +++ b/source/ubl-settings-usergroups.h @@ -130,6 +130,7 @@ typedef struct { config_str remove_homes; int homes_size; char *default_home; + int save_config; } config; typedef struct {