You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ubl-settings-usergroups/source/ubl-settings-usergroups.h

461 lines
19 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <gtk/gtk.h>
#include <gtk/gtkx.h>
#include <locale.h>
#include <vte/vte.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <getopt.h>
#include <libintl.h>
#include <limits.h>
#include <sys/wait.h>
#include <libublsettings.h>
#include <libublsettings-gtk3.h>
#include <libublsettingsui-gtk3.h>
#ifdef WEBKIT_FOUND
#include <webkit2/webkit2.h>
#endif
#include "ubl-strings.h"
#define WIKI_LINK "https://wiki.ublinux.ru/ru/Программное_обеспечениерограммы_и_утилиты/Все/ubl-settings-usergroups"
#define _(String) gettext(String)
#define glade_path "/com/ublinux/ui/ubl-settings-usergroups.glade"
#define glade_path_ubl_settings_usergroups_additional_settings "/com/ublinux/ui/ubl-settings-usergroups-additional-settings.glade"
#define glade_path_ubl_settings_usergroups_group_creation "/com/ublinux/ui/ubl-settings-usergroups-group-creation.glade"
#define glade_path_ubl_settings_usergroups_group "/com/ublinux/ui/ubl-settings-usergroups-group.glade"
#define glade_path_ubl_settings_usergroups_password "/com/ublinux/ui/ubl-settings-usergroups-password.glade"
#define glade_path_ubl_settings_usergroups_system "/com/ublinux/ui/ubl-settings-usergroups-system.glade"
#define glade_path_ubl_settings_usergroups_user "/com/ublinux/ui/ubl-settings-usergroups-user.glade"
#define glade_path_ubl_settings_usergroups_savesettings "/com/ublinux/ui/ubl-settings-usergroups-savesettings.glade"
#define glade_path_ubl_settings_usergroups_confirmation "/com/ublinux/ui/ubl-settings-usergroups-confirmation.glade"
#define banner_path "/com/ublinux/images/ubl-settings-usergroups-banner.png"
#define CssPath "/com/ublinux/css/ubl-settings-usergroups.css"
#define config_path yon_char_unite(yon_ubl_user_get_home_directory(),"/.config/",LocaleName,"/",LocaleName,".conf",NULL)
#define LocalePath "/usr/share/locale"
#define LocaleName "ubl-settings-usergroups"
#define encrypt_passwords_command "/usr/lib/ublinux/functions globalconf_convert_pass_plain_to_hash"
#define get_default_hash_command "ubconfig --raw --source default get [users] HASHPASSWD"
#define clear_config_global_command "ubconfig --target global remove TEMP_SECTION TEMP_PATAMETER"
#define clear_config_local_command "ubconfig --target system remove TEMP_SECTION TEMP_PATAMETER"
#define samba_sync_command(user) yon_char_unite("sudo smbpasswd -Lan ",user,NULL)
#define samba_sync_password_command(user, password) yon_char_unite("(echo \"",password,"\"; echo \"",password,"\") | sudo smbpasswd -Las ",user,NULL)
#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 groups_path "/etc/group"
#define users_path "/etc/passwd"
#define shadow_path "/etc/shadow"
#define uid_path "/etc/login.defs"
#define password_limits_path "/etc/security/pwquiality.conf"
#define get_user_info_command(target) yon_char_unite("getent passwd \"",target,"\"",NULL)
#define get_home_command(target) yon_char_unite("getent passwd \"",target,"\" | cut -d: -f6",NULL)
#define remove_home_dirs_command(users_string) yon_char_append("/usr/lib/ublinux/functions remove_userhome ", users_string)
#define default_home_initiator_path "/etc/default/useradd"
#define user_shadow_command "cat /etc/shadow"
#define hash_list_path "/usr/share/ubl-settings-usergroups/csv/hash_list.csv"
#define shell_list_path "/usr/share/ubl-settings-usergroups/csv/shell_list.csv"
#define USERADD(user) yon_char_unite("USERADD[",user,"]",NULL)
#define GROUPADD(group) yon_char_unite("GROUPADD[",group,"]",NULL)
#define USERSHADOW(user) yon_char_unite("USERSHADOW[",user,"]",NULL)
#define USERADD_SYNC(user) yon_char_unite("USERADD_SYNC[",user,"]",NULL)
#define USERSHADOW_SYNC(user) yon_char_unite("USERSHADOW_SYNC[",user,"]",NULL)
#define GROUPADD_SYNC(user) yon_char_unite("GROUPADD_SYNC[",user,"]",NULL)
#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"
#define password_hash_get_command(passwd) yon_char_append("mkpasswd2 ",passwd)
#define config_get_command(source) yon_char_unite("ubconfig --source ",source," get users DEFAULTPASSWD DEFAULTROOTPASSWD DEFAULTUSER HASHPASSWD USERGROUPS ADDADM USERADD[*] USERADD_SYNC USERADD_SYNC[*] USERSHADOW[*] GROUPADD[*]",NULL),yon_char_unite("ubconfig --source ",source," get [system] SYSTEMBOOT_STATEMODE",NULL),yon_char_unite("ubconfig --source ",source," get [save] SAVE_ROOTCOPY_CHANGES",NULL)
#define config_get_default_command "ubconfig --source default get users DEFAULTPASSWD DEFAULTROOTPASSWD USERGROUPS DEFAULTUSER HASHPASSWD ADDADM"
#define config_get_global_only_parameters "ubconfig --source global get users DEFAULTPASSWD DEFAULTROOTPASSWD"
#define config_get_local_only_parameters ""
#define SAVE_ROOTCOPY_CHANGES_get_command "ubconfig --source global get [save] SAVE_ROOTCOPY_CHANGES"
#define DEFAULTUSER_get_command "ubconfig --source global get [users] DEFAULTUSER"
#define DEFAULTPASSWD_get_command "ubconfig --source global get [users] DEFAULTPASSWD"
#define DEFAULTROOTPASSWD_get_command "ubconfig --source global get [users] DEFAULTROOTPASSWD"
#define ADDADM_get_command "ubconfig --source global get [users] ADDADM"
#define HASHPASSWD_get_command "ubconfig --source global get [users] HASHPASSWD"
#define USERADD_SYNC_get_command "ubconfig --source global get [users] USERADD_SYNC"
#define USERGROUPS_get_command "ubconfig --source global get [users] USERGROUPS"
#define USERGROUPS_parameter "USERGROUPS"
#define USERGROUPS_parameter_command "ubconfig --source system get users USERGROUPS"
#define DEFAULTPASSWD_parameter "DEFAULTPASSWD"
#define DEFAULTPASSWD_parameter_command "ubconfig --source system get users DEFAULTPASSWD"
#define DEFAULTROOTPASSWD_parameter "DEFAULTROOTPASSWD"
#define DEFAULTROOTPASSWD_parameter_command "ubconfig --source system get users DEFAULTROOTPASSWD"
#define ADDADM_parameter "ADDADM"
#define ADDADM_parameter_command "ubconfig --source system get users ADDADM"
#define HASHPASSWD_parameter "HASHPASSWD"
#define HASHPASSWD_parameter_command "ubconfig --source system get users HASHPASSWD"
#define DEFAULTUSER_parameter "DEFAULTUSER"
#define DEFAULTUSER_parameter_command "ubconfig --source system get users DEFAULTUSER"
#define SAVE_ROOTCOPY_CHANGES_parameter "SAVE_ROOTCOPY_CHANGES"
#define SAVE_ROOTCOPY_CHANGES_parameter_command "ubconfig --source system get users SAVE_ROOTCOPY_CHANGES"
#define USERADD_parameter "USERADD"
#define USERADD_all_parameter_command "ubconfig --source system get users USERADD"
#define GROUPADD_parameter "GROUPADD"
#define GROUPADD_all_parameter_command "ubconfig --source system get users GROUPADD"
#define USERADD_SHADOW_parameter "USERADD_SHADOW"
#define USERADD_SHADOW_parameter_command "ubconfig --source system get users USERADD_SHADOW"
#define GROUPADD_SHADOW_parameter "GROUPADD_SHADOW"
#define GROUPADD_SHADOW_parameter_command "ubconfig --source system get users GROUPADD_SHADOW"
#define USERADD_SYNC_parameter "USERADD_SYNC"
#define USERADD_SYNC_parameter_command "ubconfig --source system get users USERADD_SYNC"
#define USERADD_SEARCH_macro "USERADD["
#define USERADD_parameter_command yon_char_unite("ubconfig --source system get users USERADD[",target,"]",NULL)
#define GROUPADD_SEARCH_macro "GROUPADD["
#define GROUPADD_parameter_command yon_char_unite("GROUPADD[",target,"]",NULL)
typedef char* string;
string version_application;
char *local;
typedef struct {
template_config_fields
config_str groups;
int groups_size;
config_str users;
int users_size;
GtkListStore *users_list;
GtkListStore *groups_list;
int MAXUID;
int MINUID;
int MAXGID;
int MINGID;
size_t password_min_length;
int hash_default_id;
config_str sync_users;
int sync_size;
config_str remove_homes;
int homes_size;
char *default_home;
int save_config;
int launch_size;
config_str launch_arguments;
} config;
typedef struct {
template_window_fields
GtkListStore *CacheAlgList;
GtkListStore *GroupsList;
GtkListStore *UsersList;
GtkWidget *UserAddToConfigButton;
GtkWidget *SystemTree;
GtkWidget *SystemGroupsTree;
GtkWidget *button2;
GtkWidget *button3;
GtkWidget *AddButton;
GtkWidget *EditButton;
GtkWidget *DeleteButton;
GtkWidget *UpdateButton;
GtkWidget *UsersTree;
GtkWidget *GroupsTree;
GtkWidget *MainNotebook;
GtkWidget *SavingSettingsButton;
rmb_menu_window *UsersMenu;
rmb_menu_window *GroupsMenu;
GtkListStore *liststore1;
GtkListStore *liststore2;
} main_window;
typedef struct {
GtkWidget *Window;
GtkWidget *AlwaysOpenCheck;
GtkWidget *CloseButton;
GtkWidget *AcceptButton;
} documentation_confirmation_window;
typedef struct{
GtkWidget *Window;
GtkWidget *StatusBox;
GtkWidget *DefaultUserNameEntry;
GtkWidget *DefaultUserAdministratorCheck;
GtkWidget *DefaultPasswordCombo;
GtkWidget *DefaultPasswordEntry;
GtkWidget *DefaultPasswordButton;
GtkWidget *RootPasswordCombo;
GtkWidget *RootPasswordEntry;
GtkWidget *RootPasswordButton;
GtkWidget *PasswordHashCombo;
GtkWidget *CancelButton;
GtkWidget *AcceptButton;
GtkWidget *EncryptAllPasswordsButton;
GtkWidget *UsersBootCheck;
GtkWidget *UsersShutdownCheck;
} ubl_settings_usergroups_additional_settings_window;
typedef struct{
GtkWidget *CreateGroupWindow;
GtkWidget *StatusBox;
GtkWidget *userUIDAutoCheck;
GtkWidget *userUIDEntry;
GtkWidget *userLoginEntry;
GtkWidget *userGroupsEntry;
GtkWidget *UserAdditionalGroupsButton;
GtkWidget *UserCancelButton;
GtkWidget *UserOkButton;
GtkWidget *AdditionalGroupsButton;
GtkWidget *UnuniqueGIDCheck;
GtkWidget *SystemGroupCheck;
GtkWidget *PasswordCombo;
GtkWidget *PasswordEntry;
GtkWidget *ChangePasswordButton;
GtkWidget *userTitleNameLabel;
GtkWidget *AdminGroupsEntry;
GtkWidget *AdminGroupsButton;
GtkWidget *GroupaddShutdownCheck;
GtkWidget *groupExtraOptionsEntry;
char *last_gid;
} ubl_settings_usergroups_group_creation_window;
typedef struct{
GtkWidget *GroupsWindow;
GtkWidget *GroupsTree;
GtkListStore *list;
GtkWidget *GroupsCancelButton;
GtkWidget *GroupsOkButton;
GtkWidget *HeaderLabel;
GtkCellRenderer *StatusCell;
GtkTreeViewColumn *GroupColumn;
} ubl_settings_usergroups_group_window;
typedef struct{
GtkWidget *CreateGroupWindow;
GtkWidget *StatusBox;
GtkWidget *UserCancelButton;
GtkWidget *UserOkButton;
GtkWidget *PasswordEntry;
GtkWidget *RepeatPasswordEntry;
GtkWidget *PasswordHashEntry;
GtkWidget *HashBox;
GtkWidget *PasswordBox;
GtkWidget *NoEncriptionCheck;
} ubl_settings_usergroups_password_window;
typedef struct{
GtkListStore *liststore1;
GtkListStore *liststore2;
GtkWidget *MonitorWindow;
GtkWidget *ToggleAllButton;
GtkWidget *UpdateButton;
GtkWidget *SystemTree;
int show_all;
} ubl_settings_usergroups_system_window;
typedef struct{
GtkWidget *CreateUserWindow;
GtkWidget *StatusBox;
GtkWidget *userUIDAutoCheck;
GtkWidget *userUIDEntry;
GtkWidget *userLoginEntry;
GtkWidget *userPasswordCombo;
GtkWidget *userPasswordEntry;
GtkWidget *userPasswordButton;
GtkWidget *userUserNameEntry;
GtkWidget *userGroupsCheck;
GtkWidget *userGroupsEntry;
GtkWidget *UserGroupsButton;
GtkWidget *userAdditionalGroupsEntry;
GtkWidget *userAdditionalGroupsButton;
GtkWidget *userPasswordChangedEntry;
GtkWidget *userPasswordExpirationEntry;
GtkWidget *userPasswordExpirationButton;
GtkWidget *userPasswordChangeDelayMinimumSpin;
GtkWidget *userPasswordChangeDelayMaximumSpin;
GtkWidget *userWarningSpin;
GtkWidget *userActivitySpin;
GtkWidget *userForceChangeCheck;
GtkWidget *userShellCombo;
GtkWidget *userShellEntry;
GtkWidget *userHomeCombo;
GtkWidget *userHomeEntry;
GtkWidget *userHomeButton;
GtkWidget *userCreateSystemCheck;
GtkWidget *userCreateUnuniqueCheck;
GtkWidget *userDontCheckCheck;
GtkWidget *userSyncSAMBACheck;
GtkWidget *userDeactivatedCheck;
GtkWidget *userExtraOptionsEntry;
GtkWidget *UserCancelButton;
GtkWidget *UserOkButton;
GtkWidget *CalendarPopup;
GtkWidget *ExpirationCalendar;
GtkWidget *UseraddBootCheck;
GtkWidget *UseraddShutdownCheck;
GtkWidget *UsershadowBootCheck;
GtkWidget *UsershadowShutdownCheck;
GtkWidget *userTitleNameLabel;
GtkWidget *userSyncSAMBAPasswordCheck;
char *expiration_unix;
char *old_password;
char *old_username;
char *last_uid;
} ubl_settings_usergroups_user_window;
typedef struct {
GtkWidget *Window;
GtkWidget *StatusBox;
GtkWidget *CancelButton;
GtkWidget *AcceptButton;
GtkWidget *SambaCheck;
} yon_savasettings_window;
typedef struct {
GtkWidget *Window;
GtkWidget *StatusBox;
GtkWidget *CancelButton;
GtkWidget *AcceptButton;
GtkWidget *DeletionTree;
GtkWidget *TitleLabel;
GtkWidget *HatLabel;
GtkListStore *list;
GtkCellRenderer *DeleteCell;
GtkCellRenderer *DeleteHomeCell;
GtkTreeViewColumn *UserCell;
} yon_confirmation_window;
ubl_settings_usergroups_additional_settings_window *yon_ubl_settings_usergroups_additional_settings_new();
void on_ubl_settings_usergroups_additional_settings_open(GtkWidget *self, main_window *widgets);
ubl_settings_usergroups_group_creation_window *yon_ubl_settings_usergroups_group_creation_new();
ubl_settings_usergroups_group_window *yon_ubl_settings_usergroups_group_new();
void on_standard_groups_open(GtkWidget *self, main_window *widgets);
ubl_settings_usergroups_password_window *yon_ubl_settings_usergroups_password_new();
ubl_settings_usergroups_system_window *yon_ubl_settings_usergroups_system_new();
void on_settings_usergroups_system_open(GtkWidget *self, main_window *widgets);
void on_remove_expired(GtkWidget *, GtkEntryIconPosition icon_pos, GdkEvent *, GtkEntry *target);
ubl_settings_usergroups_user_window *yon_ubl_settings_usergroups_user_new();
void on_password_accept(GtkWidget *self, dictionary *dict);
void on_config_update(GtkWidget *self, main_window *widgets);
int yon_load_proceed(YON_CONFIG_TYPE type);
void yon_interface_update(main_window *widgets);
void on_config_local_load(GtkWidget *self, main_window *widgets);
void on_config_global_load(GtkWidget *self, main_window *widgets);
void on_config_custom_load(GtkWidget *self,main_window *widgets);
void yon_samba_sync_proceed();
void yon_accept_changes();
void yon_hide_passwords(template_saving_window *window);
void on_save_done(main_window *widgets, config_str output, int size);
void on_config_save(GtkWidget *self, main_window *widgets);
void on_config_global_save(GtkWidget *self, main_window *widgets);
void on_config_local_save(GtkWidget *self, main_window *widgets);
void on_config_custom_save(GtkWidget *self, main_window *widgets);
void on_saving_settings_save(GtkWidget *self, yon_savasettings_window *window);
void yon_samba_sync_add(char *user, char*password);
void yon_samba_sync_remove(char *user);
int yon_samba_sync_get(char *user);
void on_delete_confirmation_delete_home_check(GtkCellRenderer *self, char *path, yon_confirmation_window *window);
void on_delete_confirmation_delete_check(GtkCellRenderer *self, char *path, yon_confirmation_window *window);
void yon_delete_confirmation_save(GtkWidget *self, dictionary *dict);
void yon_group_delete_confirmation_save(GtkWidget *self, dictionary *dict);
int yon_check_password_blocked(char *password);
yon_confirmation_window *yon_delete_confirmation_new();
void yon_delete_confirmation_open(main_window *widgets);
void yon_group_delete_confirmation_open(main_window *widgets);
yon_savasettings_window *yon_saving_settings_new();
void on_saving_settings_open(GtkWidget *self, main_window *widgets);
void on_password_combo_changed(GtkComboBox *self, GtkWidget *target);
void on_filechooser_open(GtkWidget *self, GtkEntry *output_target);
void on_groups_save(GtkWidget *self, dictionary *dict);
void on_groups_clicked(GtkWidget *self, GtkEntry *output_target);
void on_groups_multiple_save(GtkWidget *self, dictionary *dict);
void on_groups_multiple_clicked(GtkWidget *self, GtkEntry *output_target);
void on_passwords_encrypt();
void on_password_change(GtkWidget *self, dictionary *entry_dict);
void on_additional_settings_clicked(GtkWidget *self, GtkEntry *output_target);
void on_expiration_clicked(GtkWidget *self, ubl_settings_usergroups_user_window *window);
void on_additional_settings_save(GtkWidget *self, ubl_settings_usergroups_additional_settings_window *window);
void on_hash_changed(GtkWidget *self, ubl_settings_usergroups_additional_settings_window *window);
ubl_settings_usergroups_additional_settings_window *yon_ubl_settings_usergroups_additional_settings_new();
void on_ubl_settings_usergroups_additional_settings_open(GtkWidget *self, main_window *widgets);
void on_user_choose(GtkWidget *self, GtkEntry *target);
void on_GID_update(GtkWidget *self, ubl_settings_usergroups_group_creation_window *window);
void on_group_save(GtkWidget *self, dictionary *dict);
void on_system_parameter_changed(GtkWidget *self, ubl_settings_usergroups_group_creation_window *window);
ubl_settings_usergroups_group_creation_window *yon_ubl_settings_usergroups_group_creation_new();
void on_group_clicked(GtkCellRenderer *self, char *path, ubl_settings_usergroups_group_window *window);
ubl_settings_usergroups_group_window *yon_ubl_settings_usergroups_group_new(int mode);
void on_standard_groups_accept(GtkWidget *self, ubl_settings_usergroups_group_window *window);
void on_standard_groups_open(GtkWidget *self, main_window *widgets);
void on_password_show_hide(GtkEntry *self, GtkEntryIconPosition icon_pos, GdkEvent* event);
void on_password_changed(GtkEntry *self, ubl_settings_usergroups_password_window *window);
void on_password_accept(GtkWidget *self, dictionary *dict);
ubl_settings_usergroups_password_window *yon_ubl_settings_usergroups_password_new();
void yon_system_load(main_window *window);
void on_system_update(GtkWidget *self, main_window *window);
ubl_settings_usergroups_system_window *yon_ubl_settings_usergroups_system_new();
void on_settings_usergroups_system_open(GtkWidget *self, main_window *widgets);
void on_user_shell_changed(GtkWidget *self, ubl_settings_usergroups_user_window *window);
void on_UID_update(GtkWidget *self, ubl_settings_usergroups_user_window *window);
void on_user_login_update(GtkWidget *self, ubl_settings_usergroups_user_window *window);
void on_user_save(GtkWidget *self, dictionary *dict);
void on_toggle_button_set_active_from_combo_box(GtkComboBox *self,ubl_settings_usergroups_user_window *window);
void on_password_user_changed(GtkComboBox *self,ubl_settings_usergroups_user_window *window);
void on_toggle_button_set_active_from_toggle_button_inversed(GtkToggleButton *self, ubl_settings_usergroups_user_window *window);
void on_date_selected(GtkWidget *self, ubl_settings_usergroups_user_window *window);
void on_parameter_changed(GtkWidget *self,ubl_settings_usergroups_user_window *window);
void on_main_add(GtkWidget *self, main_window *widgets);
void on_main_edit(GtkWidget *self, main_window *widgets);
void on_main_edit_activate(GtkWidget *self, GtkTreePath *path, GtkTreeViewColumn *column, main_window *widgets);
void on_main_delete(GtkWidget *self, main_window *widgets);
void on_config_update(GtkWidget *self, main_window *widgets);
void on_user_sync_with_config(GtkWidget *,main_window *widgets);
int yon_element_chosen(GtkWidget *target);
void config_init();
void on_selection_changed(GtkWidget *self, main_window *widgets);
void on_notebook_page_changed(GtkWidget *self, GtkWidget *page, int num, main_window *widgets);
gboolean on_menu_open(GtkWidget *self,GdkEventButton *event, rmb_menu_window *window);
main_window *yon_main_window_complete(main_window *widgets);