From 5e13f75f1dee317a127a6b823d77be765d6b9f4e Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Mon, 19 May 2025 17:18:49 +0600 Subject: [PATCH] Changed user password saving and loading; default password and root password changes --- source/ubl-settings-usergroups-password.c | 12 ++---- source/ubl-settings-usergroups-settings.c | 34 ++++++++++++++--- source/ubl-settings-usergroups-user.c | 34 +++++++++++++++-- source/ubl-settings-usergroups.c | 25 +++++++++--- source/ubl-settings-usergroups.h | 3 ++ source/ubl-strings.h | 4 ++ ...tings-usergroups-additional-settings.glade | 19 +++++----- ubl-settings-usergroups-user.glade | 5 ++- ubl-settings-usergroups.glade | 10 ++--- ubl-settings-usergroups.pot | 36 ++++++++++++------ ubl-settings-usergroups_ru.po | 38 +++++++++++++------ 11 files changed, 159 insertions(+), 61 deletions(-) diff --git a/source/ubl-settings-usergroups-password.c b/source/ubl-settings-usergroups-password.c index 8805f47..ebe7fb8 100644 --- a/source/ubl-settings-usergroups-password.c +++ b/source/ubl-settings-usergroups-password.c @@ -147,20 +147,14 @@ return window; } 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]=='*'){ + if (!yon_char_is_empty(password)&&strlen(password)>0){ + if (password[0]=='!'&&password[1]!='*'){ char *copy = yon_char_new(password); - memcpy(copy,password+2,strlen(password+2)); + memcpy(copy,password+1,strlen(password+1)); 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; } } return 0; diff --git a/source/ubl-settings-usergroups-settings.c b/source/ubl-settings-usergroups-settings.c index f922cd8..2ffac0c 100644 --- a/source/ubl-settings-usergroups-settings.c +++ b/source/ubl-settings-usergroups-settings.c @@ -33,7 +33,15 @@ void on_additional_settings_changed(GtkWidget *self, ubl_settings_usergroups_add if (window->default_user_name) yon_config_remove_by_key(DEFAULTUSER_parameter); } - char *default_password = gtk_combo_box_get_active(GTK_COMBO_BOX(window->DefaultPasswordCombo))>1? (char*)gtk_entry_get_text(GTK_ENTRY(window->DefaultPasswordEntry)):NULL; + char *default_password = NULL; + int user_password_active = gtk_combo_box_get_active(GTK_COMBO_BOX(window->DefaultPasswordCombo)); + if (user_password_active==2) + default_password=(char*)gtk_entry_get_text(GTK_ENTRY(window->DefaultPasswordEntry)); + else if (user_password_active==1) + default_password=" "; + else if (user_password_active==3){ + default_password="!*"; + } if (!yon_char_is_empty(default_password)){ if (window->default_password) yon_config_register(DEFAULTPASSWD_parameter,DEFAULTPASSWD_parameter_command,default_password); @@ -41,7 +49,12 @@ void on_additional_settings_changed(GtkWidget *self, ubl_settings_usergroups_add if (window->default_password) yon_config_remove_by_key(DEFAULTPASSWD_parameter); } - char *root_password = gtk_combo_box_get_active(GTK_COMBO_BOX(window->RootPasswordCombo)) > 1 ? (char*)gtk_entry_get_text(GTK_ENTRY(window->RootPasswordEntry)) : NULL; + char *root_password = NULL; + int root_password_active = gtk_combo_box_get_active(GTK_COMBO_BOX(window->RootPasswordCombo)); + if (root_password_active==2) + root_password=(char*)gtk_entry_get_text(GTK_ENTRY(window->RootPasswordCombo)); + else if (root_password_active==1) + root_password=" "; if (!yon_char_is_empty(root_password)){ if (window->default_root_password) yon_config_register(DEFAULTROOTPASSWD_parameter,DEFAULTROOTPASSWD_parameter_command,root_password); @@ -660,15 +673,24 @@ ubl_settings_usergroups_additional_settings_window *yon_ubl_settings_usergroups_ g_signal_connect(G_OBJECT(window->DefaultPasswordCombo),"changed",G_CALLBACK(on_password_combo_changed),window->DefaultPasswordButton); char *default_password = yon_config_get_by_key(DEFAULTPASSWD_parameter); if (!yon_char_is_empty(default_password)){ - gtk_entry_set_text(GTK_ENTRY(window->DefaultPasswordEntry),default_password); - if(!yon_config_check_ignore(DEFAULTPASSWD_parameter)) + if (!strcmp(default_password," ")){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->DefaultPasswordCombo),1); + } else if (!strcmp(default_password,"!*")){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->DefaultPasswordCombo),3); + + } else { gtk_combo_box_set_active(GTK_COMBO_BOX(window->DefaultPasswordCombo),2); + gtk_entry_set_text(GTK_ENTRY(window->DefaultPasswordEntry),default_password); + } } char *root_password = yon_config_get_by_key(DEFAULTROOTPASSWD_parameter); if (!yon_char_is_empty(root_password)){ - gtk_entry_set_text(GTK_ENTRY(window->RootPasswordEntry),root_password); - if(!yon_config_check_ignore(DEFAULTROOTPASSWD_parameter)) + if (!strcmp(root_password," ")){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->RootPasswordCombo),1); + } else { gtk_combo_box_set_active(GTK_COMBO_BOX(window->RootPasswordCombo),2); + gtk_entry_set_text(GTK_ENTRY(window->DefaultPasswordEntry),root_password); + } } char *is_k_admin = yon_config_get_by_key(ADDADM_parameter); if (!yon_char_is_empty(is_k_admin)) diff --git a/source/ubl-settings-usergroups-user.c b/source/ubl-settings-usergroups-user.c index fdaa763..6757bd8 100644 --- a/source/ubl-settings-usergroups-user.c +++ b/source/ubl-settings-usergroups-user.c @@ -392,7 +392,11 @@ void on_user_save(GtkWidget *self, dictionary *dict){ } int password_active = gtk_combo_box_get_active(GTK_COMBO_BOX(window->userPasswordCombo)); - if (password_active > 1){ + if (password_active == 0){ + password = NULL; + } else if (password_active ==1){ + password = " "; + } else if (password_active ==2){ password = (char*)gtk_entry_get_text(GTK_ENTRY(window->userPasswordEntry)); if (yon_char_is_empty(password)){ yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); @@ -400,10 +404,31 @@ void on_user_save(GtkWidget *self, dictionary *dict){ gtk_notebook_set_current_page(GTK_NOTEBOOK(window->MainNotebook),0); return; } - } else if (password_active==1){ + } else if (password_active==3){ password = "!*"; - } else { - password=""; + } else if (password_active ==4){ + password = (char*)gtk_entry_get_text(GTK_ENTRY(window->userPasswordEntry)); + if (yon_char_is_empty(password)){ + yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); + yon_ubl_status_highlight_incorrect(window->userPasswordEntry); + gtk_notebook_set_current_page(GTK_NOTEBOOK(window->MainNotebook),0); + return; + } + if (password[0]!='!') { + char *temp = yon_char_append("!",password); + password=temp; + } + } else if (password_active == 5){ + password = yon_char_new((char*)gtk_entry_get_text(GTK_ENTRY(window->userPasswordEntry))); + if (yon_char_is_empty(password)){ + yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); + yon_ubl_status_highlight_incorrect(window->userPasswordEntry); + gtk_notebook_set_current_page(GTK_NOTEBOOK(window->MainNotebook),0); + return; + } + if (password[0]=='!'){ + free(yon_char_divide(password,0)); + } } char *old_password = NULL; @@ -432,6 +457,7 @@ void on_user_save(GtkWidget *self, dictionary *dict){ if (strlen(password)>1&&password[0]=='%'&&password[1]=='%'){ char *temp = yon_char_replace(password,"%%","!!"); password = yon_char_replace(temp,"!!","%%!"); + } else if (!yon_char_is_empty(password)&&password[0]=='!'){ } else { password = yon_char_append("!",password); } diff --git a/source/ubl-settings-usergroups.c b/source/ubl-settings-usergroups.c index 7d900d1..0c35df4 100644 --- a/source/ubl-settings-usergroups.c +++ b/source/ubl-settings-usergroups.c @@ -121,7 +121,7 @@ void yon_interface_update(main_window *widgets){ } gtk_list_store_set(widgets->UsersList,&iter, - 0,parameters_size>5?(parameters[5][0]=='!'||parameters[5][0]=='*')||(parameters[5][0]=='!'&¶meters[5][1]=='*'):0, + 0,parameters_size>5?(parameters[5][0]=='!'&¶meters[5][1]=='*')?check_checked_icon_name:(parameters[5][0]=='!'||parameters[5][0]=='*')?check_attention_icon_name:NULL:NULL, 2,login, 3,parameters_size>0?parameters[0]:"", 1,parameters_size>1&&!yon_char_is_empty(parameters[1])?parameters[1]:"", @@ -886,7 +886,20 @@ void on_saving_settings_open(GtkWidget *, main_window *widgets){ } void on_password_combo_changed(GtkComboBox *self, GtkWidget *target){ - gtk_widget_set_sensitive(target,gtk_combo_box_get_active(self)>1); + int active = gtk_combo_box_get_active(self); + switch(active){ + case 0: + case 1: + case 3: + case 4: + gtk_widget_set_sensitive(target,0); + break; + case 2: + case 5: + gtk_widget_set_sensitive(target,1); + break; + } + } @@ -1614,9 +1627,6 @@ void on_main_edit(GtkWidget *, main_window *widgets){ } window->old_password=yon_char_new(parameters[5]); if (strcmp(parameters[5],"x")&&strcmp(parameters[5],"")){ - if (yon_check_password_blocked(parameters[5])){ - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->userDeactivatedCheck),1); - } if (!yon_char_is_empty(parameters[5])){ if (check_is_password_hash(parameters[5])){ if (yon_char_check_begins_with(parameters[5],"%%")==-1){ @@ -1628,7 +1638,12 @@ void on_main_edit(GtkWidget *, main_window *widgets){ g_signal_handlers_block_by_func(G_OBJECT(window->userSyncSAMBACheck),G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button_inversed),window->userSyncSAMBAPasswordCheck); } if (!strcmp(parameters[5],"!*")){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->userPasswordCombo),3); + } else if (!strcmp(parameters[5]," ")) { gtk_combo_box_set_active(GTK_COMBO_BOX(window->userPasswordCombo),1); + } else if (parameters[5][0]=='!'){ + gtk_entry_set_text(GTK_ENTRY(window->userPasswordEntry),parameters[5]); + gtk_combo_box_set_active(GTK_COMBO_BOX(window->userPasswordCombo),4); } else { gtk_entry_set_text(GTK_ENTRY(window->userPasswordEntry),parameters[5]); gtk_combo_box_set_active(GTK_COMBO_BOX(window->userPasswordCombo),2); diff --git a/source/ubl-settings-usergroups.h b/source/ubl-settings-usergroups.h index 1deb992..f3820bf 100644 --- a/source/ubl-settings-usergroups.h +++ b/source/ubl-settings-usergroups.h @@ -87,6 +87,9 @@ #define GROUPADD_SYNC_parameter "GROUPADD_SYNC" #define GROUPADD_SYNC_parameter_command "ubconfig --source system get users USERADD_SYNC" +#define check_box_icon_name "com.ublinux.libublsettingsui-gtk3.checkbox-symbolic" +#define check_checked_icon_name "com.ublinux.libublsettingsui-gtk3.checkbox-checked-symbolic" +#define check_attention_icon_name "com.ublinux.libublsettingsui-gtk3.checkbox-attention-symbolic" #define add_icon_name "com.ublinux.ubl-settings-usergroups.increase-symbolic" #define edit_icon_name "com.ublinux.ubl-settings-usergroups.edit-symbolic" #define delete_icon_name "com.ublinux.ubl-settings-usergroups.trash-symbolic" diff --git a/source/ubl-strings.h b/source/ubl-strings.h index 830943c..b9a2c3d 100644 --- a/source/ubl-strings.h +++ b/source/ubl-strings.h @@ -271,5 +271,9 @@ #define SHUTDOWN_MINIMUM_GID_LABEL _("Minimum GID") #define SHUTDOWN_MAXIMUM_GID_LABEL _("Maximum GID") +#define DENY_LOGIN_LABEL _("Deny login") +#define BLOCK_LOGIN_LABEL _("Block login with password") +#define UNBOCK_LOGIN_LABEL _("Unblock login with password") + #define CONFIRMATION_GROUP_DEPENDS_SINGLE_LABEL(target,depends) yon_char_unite(_("User(-s)")," \"",depends,"\" ",_("is included into main group of users")," \"",target,"\", ",_("which will be deleted"),".\n",_("After reboot users")," ",depends," ",_("main group will be set to default group"),".",NULL) #define CONFIRMATION_GROUP_DEPENDS_MULTIPLE_LABEL _("Some of users, chosen for deletion, are included as main group for other users. This users will get default main group after reboot") diff --git a/ubl-settings-usergroups-additional-settings.glade b/ubl-settings-usergroups-additional-settings.glade index e2a11e8..8921f94 100644 --- a/ubl-settings-usergroups-additional-settings.glade +++ b/ubl-settings-usergroups-additional-settings.glade @@ -1,5 +1,5 @@ - + @@ -76,8 +76,8 @@ False Group GID range - - + + True True False @@ -90,8 +90,8 @@ False Group GID in system - - + + True True False @@ -176,8 +176,8 @@ False Users UID range - - + + True True False @@ -190,8 +190,8 @@ False User UID in system - - + + True True False @@ -461,6 +461,7 @@ Default No password required Set a password + Deny login diff --git a/ubl-settings-usergroups-user.glade b/ubl-settings-usergroups-user.glade index dc453a6..59c758c 100644 --- a/ubl-settings-usergroups-user.glade +++ b/ubl-settings-usergroups-user.glade @@ -1,5 +1,5 @@ - + @@ -237,6 +237,9 @@ Default No password required Set a password + Deny login + Block login with password + Unblock login with password diff --git a/ubl-settings-usergroups.glade b/ubl-settings-usergroups.glade index 4ec95c8..8077571 100644 --- a/ubl-settings-usergroups.glade +++ b/ubl-settings-usergroups.glade @@ -1,5 +1,5 @@ - - + + @@ -363,9 +363,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Locked 0 - + - 0 + 0 diff --git a/ubl-settings-usergroups.pot b/ubl-settings-usergroups.pot index 6d0f778..8312117 100644 --- a/ubl-settings-usergroups.pot +++ b/ubl-settings-usergroups.pot @@ -858,19 +858,19 @@ msgid "All system users" msgstr "" #: source/ubl-strings.h:253 source/ubl-strings.h:266 -msgid "Users GID range" +msgid "Users UID range" msgstr "" #: source/ubl-strings.h:254 source/ubl-strings.h:267 -msgid "User GID in system" +msgid "User UID in system" msgstr "" #: source/ubl-strings.h:255 -msgid "Users UID range" +msgid "Users GID range" msgstr "" #: source/ubl-strings.h:256 -msgid "User UID in system" +msgid "User GID in system" msgstr "" #: source/ubl-strings.h:258 @@ -913,26 +913,40 @@ msgstr "" msgid "Maximum GID" msgstr "" -#: source/ubl-strings.h:272 +#: source/ubl-strings.h:274 +msgid "Deny login" +msgstr "" + +#: source/ubl-strings.h:275 +msgid "Block login with password" +msgstr "" + +#: source/ubl-strings.h:276 +msgid "Unblock login with password" +msgstr "" + +#: source/ubl-strings.h:278 msgid "User(-s)" msgstr "" -#: source/ubl-strings.h:272 +#: source/ubl-strings.h:278 msgid "is included into main group of users" msgstr "" -#: source/ubl-strings.h:272 +#: source/ubl-strings.h:278 msgid "which will be deleted" msgstr "" -#: source/ubl-strings.h:272 +#: source/ubl-strings.h:278 msgid "After reboot users" msgstr "" -#: source/ubl-strings.h:272 +#: source/ubl-strings.h:278 msgid "main group will be set to default group" msgstr "" -#: source/ubl-strings.h:272 -msgid "Some of users, chosen for deletion, are included as main group for other users. This users will get default main group after reboot" +#: source/ubl-strings.h:279 +msgid "" +"Some of users, chosen for deletion, are included as main group for other " +"users. This users will get default main group after reboot" msgstr "" diff --git a/ubl-settings-usergroups_ru.po b/ubl-settings-usergroups_ru.po index 5d9930b..a6ccde3 100644 --- a/ubl-settings-usergroups_ru.po +++ b/ubl-settings-usergroups_ru.po @@ -926,19 +926,19 @@ msgid "All system users" msgstr "Все пользователи в системе" #: source/ubl-strings.h:253 source/ubl-strings.h:266 -msgid "Users GID range" +msgid "Users UID range" msgstr "Диапазон UID пользователей в системе" #: source/ubl-strings.h:254 source/ubl-strings.h:267 -msgid "User GID in system" +msgid "User UID in system" msgstr "Пользователь в системе с UID" #: source/ubl-strings.h:255 -msgid "Users UID range" +msgid "Users GID range" msgstr "Диапазон UID пользователей в системе" #: source/ubl-strings.h:256 -msgid "User UID in system" +msgid "User GID in system" msgstr "Пользователь в системе с UID" #: source/ubl-strings.h:258 @@ -981,28 +981,44 @@ msgstr "Минимальный GID" msgid "Maximum GID" msgstr "Максимальный GID" -#: source/ubl-strings.h:272 +#: source/ubl-strings.h:274 +msgid "Deny login" +msgstr "Запретить вход" + +#: source/ubl-strings.h:275 +msgid "Block login with password" +msgstr "Заблокировать вход по паролю" + +#: source/ubl-strings.h:276 +#, fuzzy +msgid "Unblock login with password" +msgstr "Разблокировать вход по паролю" + +#: source/ubl-strings.h:278 msgid "User(-s)" msgstr "Пользователь(-ли)" -#: source/ubl-strings.h:272 +#: source/ubl-strings.h:278 msgid "is included into main group of users" msgstr "включен(-ы) в основную группу" -#: source/ubl-strings.h:272 +#: source/ubl-strings.h:278 msgid "which will be deleted" msgstr "которая будет удалена" -#: source/ubl-strings.h:272 +#: source/ubl-strings.h:278 msgid "After reboot users" msgstr "После перезагрузки пользователь(-ли)" -#: source/ubl-strings.h:272 +#: source/ubl-strings.h:278 msgid "main group will be set to default group" msgstr "получит(-ат) основную группу по умолчанию" -#: source/ubl-strings.h:272 +#: source/ubl-strings.h:279 msgid "" "Some of users, chosen for deletion, are included as main group for other " "users. This users will get default main group after reboot" -msgstr "Часть пользователей выбранных на удаление используются как основные группы других пользователей. После перезагрузки эти пользователи получат основную группу по умолчанию" +msgstr "" +"Часть пользователей выбранных на удаление используются как основные группы " +"других пользователей. После перезагрузки эти пользователи получат основную " +"группу по умолчанию"