diff --git a/source/ubl-settings-usergroups.c b/source/ubl-settings-usergroups.c index e7a807d..bcdfe3a 100644 --- a/source/ubl-settings-usergroups.c +++ b/source/ubl-settings-usergroups.c @@ -1416,6 +1416,7 @@ void on_user_save(GtkWidget *self, dictionary *dict){ char *login = NULL; char *username = NULL; char *main_group = NULL; + char *no_user_group=NULL; char *additional_groups = NULL; char *password_changed_date = NULL; char *password_expiration_date = NULL; @@ -1490,9 +1491,7 @@ void on_user_save(GtkWidget *self, dictionary *dict){ if (!main_group_active){ main_group = (char*)gtk_entry_get_text(GTK_ENTRY(window->userGroupsEntry)); if (yon_char_is_empty(main_group)){ - yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); - yon_ubl_status_highlight_incorrect(window->userGroupsEntry); - return; + no_user_group="--no-user-group"; } } else { main_group = ""; @@ -1621,14 +1620,6 @@ void on_user_save(GtkWidget *self, dictionary *dict){ ":",yon_char_return_if_exist(uid_string,"x"), ":",yon_char_return_if_exist(main_group,"x"), ":",yon_char_return_if_exist(additional_groups,"x"), - ":",yon_char_return_if_exist(user_home,""), - yon_char_return_if_exist(user_shell,""), - !yon_char_is_empty(user_shell)?" ":"", - yon_char_return_if_exist(create_system_user,""), - !yon_char_is_empty(create_system_user)?" ":"", - yon_char_return_if_exist(create_ununique,""), - !yon_char_is_empty(create_ununique)?" ":"", - yon_char_return_if_exist(do_not_check,""), !yon_char_is_empty(extra_options)?" ":"", yon_char_return_if_exist(extra_options,""), ":",yon_char_return_if_exist(password,""), @@ -1740,6 +1731,80 @@ void on_date_selected(GtkWidget *self, ubl_settings_usergroups_user_window *wind window->expiration_unix=date_string; } +void on_parameter_changed(GtkWidget *self,ubl_settings_usergroups_user_window *window){ + char *user_shell=NULL; + char *user_home=NULL; + char *login=NULL; + char *create_system_user=NULL; + char *create_ununique=NULL; + char *do_not_check=NULL; + char *main_group=NULL; + char *no_user_group=NULL; + + int do_not_check_actve = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->userDontCheckCheck)); + if (do_not_check_actve) + do_not_check = " --badnames"; + + login = (char*)gtk_entry_get_text(GTK_ENTRY(window->userLoginEntry)); + if (login[0]>'0'&&login[0]<'9'&&!do_not_check_actve){ + yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),USER_BEGINS_WITH_DIGIT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); + yon_ubl_status_highlight_incorrect(window->userLoginEntry); + return; + } + if (yon_char_is_empty(login)){ + yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); + yon_ubl_status_highlight_incorrect(window->userLoginEntry); + return; + } + + int user_shell_active = gtk_combo_box_get_active(GTK_COMBO_BOX(window->userShellCombo)); + if (user_shell_active>0){ + user_shell = yon_char_unite(" --shell ",(char*)gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(window->userShellCombo)),NULL); + if (!strcmp(user_shell,SET_LABEL)){ + user_shell = yon_char_unite(" --shell ",(char*)gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(window->userShellCombo)),NULL); + } + } else user_shell=""; + + int user_home_active = gtk_combo_box_get_active(GTK_COMBO_BOX(window->userHomeCombo)); + if (user_home_active==2){ + user_home=yon_char_unite("--home-dir ",(char*)gtk_entry_get_text(GTK_ENTRY(window->userHomeEntry)),NULL); + } else if (user_home_active==0){ + user_home=yon_char_unite("--home-dir ",main_config.default_home,"/",login,NULL); + } else if (user_home_active==1){ + user_home="--no-create-home"; + } else user_home = ""; + + int system_user_active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->userCreateSystemCheck)); + if (system_user_active) + create_system_user = " --system"; + + int create_ununique_active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->userCreateUnuniqueCheck)); + if (create_ununique_active) + create_ununique = " --non-unique"; + int main_group_active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->userGroupsCheck)); + if (!main_group_active){ + main_group = (char*)gtk_entry_get_text(GTK_ENTRY(window->userGroupsEntry)); + if (yon_char_is_empty(main_group)){ + no_user_group="--no-user-group"; + } + } else { + main_group = ""; + } + char *final_string = yon_char_unite(yon_char_return_if_exist(user_home,""), + yon_char_return_if_exist(user_shell,""), + !yon_char_is_empty(user_shell)?" ":"", + yon_char_return_if_exist(create_system_user,""), + !yon_char_is_empty(create_system_user)?" ":"", + yon_char_return_if_exist(create_ununique,""), + !yon_char_is_empty(create_ununique)?" ":"", + yon_char_return_if_exist(do_not_check,""), + !yon_char_is_empty(do_not_check)?" ":"", + yon_char_return_if_exist(no_user_group,""), + NULL); + gtk_entry_set_text(GTK_ENTRY(window->userExtraOptionsEntry),final_string); + free(final_string); +} + ubl_settings_usergroups_user_window *yon_ubl_settings_usergroups_user_new(){ ubl_settings_usergroups_user_window *window = malloc(sizeof(ubl_settings_usergroups_user_window)); GtkBuilder *builder = gtk_builder_new_from_resource(glade_path_ubl_settings_usergroups_user); @@ -1840,6 +1905,15 @@ ubl_settings_usergroups_user_window *yon_ubl_settings_usergroups_user_new(){ g_signal_connect(G_OBJECT(window->userPasswordCombo),"changed",G_CALLBACK(on_toggle_button_set_active_from_combo_box),window); g_signal_connect(G_OBJECT(window->userPasswordCombo),"changed",G_CALLBACK(on_toggle_button_set_active_from_combo_box),window); g_signal_connect(G_OBJECT(window->userPasswordEntry),"changed",G_CALLBACK(on_password_user_changed),window); + g_signal_connect(G_OBJECT(window->userHomeEntry),"changed",G_CALLBACK(on_parameter_changed),window); + g_signal_connect(G_OBJECT(window->userHomeCombo),"changed",G_CALLBACK(on_parameter_changed),window); + g_signal_connect(G_OBJECT(window->userShellCombo),"changed",G_CALLBACK(on_parameter_changed),window); + g_signal_connect(G_OBJECT(window->userShellEntry),"changed",G_CALLBACK(on_parameter_changed),window); + g_signal_connect(G_OBJECT(window->userCreateSystemCheck),"toggled",G_CALLBACK(on_parameter_changed),window); + g_signal_connect(G_OBJECT(window->userCreateUnuniqueCheck),"toggled",G_CALLBACK(on_parameter_changed),window); + g_signal_connect(G_OBJECT(window->userDontCheckCheck),"toggled",G_CALLBACK(on_parameter_changed),window); + g_signal_connect(G_OBJECT(window->userGroupsCheck),"toggled",G_CALLBACK(on_parameter_changed),window); + g_signal_connect(G_OBJECT(window->userGroupsEntry),"changed",G_CALLBACK(on_parameter_changed),window); return window; }