#pragma implementation #include #include #include #include "pickgroups.h" #include "pickgroups.m" #include #include #include MODULE_DEFINE_VERSION(pickgroups); static const char *keymenu=NULL; static HELP_FILE help_pickgroups("pickgroups","intro"); static const char K_PICKGROUPS[]="pickgroups"; static const char K_GROUPS[]="groups"; static const char *pickgroups_getgroups() { return linuxconf_getval (K_PICKGROUPS,K_GROUPS,""); } static int pickgroups_validate (const SSTRING &groups) { int ret = 0; SSTRING errors; SSTRINGS tb; str_splitline (groups.get(),' ',tb); for (int i=0; iget(); if (getgrnam(g)==NULL) errors.appendf ("\t%s\n",g); } if (errors.is_filled()){ xconf_error (MSG_U(E_IVLDGROUPS ,"The following group(s) do not exist\n%s") ,errors.get()); ret = -1; } return ret; } static void pickgroups_conf() { DIALOG dia; SSTRING groups (pickgroups_getgroups()); dia.newf_str (MSG_U(F_IMPORTANTG,"Important groups"),groups); int nof = 0; while (1){ MENU_STATUS code = dia.edit (MSG_U(T_IMPORTG,"Important groups") ,MSG_U(I_IMPORTANTG,"Enter the list of important groups") ,help_pickgroups ,nof); if (code == MENU_CANCEL || code == MENU_ESCAPE){ break; }else{ if (pickgroups_validate (groups)!=-1){ if (groups.is_empty()){ linuxconf_removeall (K_PICKGROUPS,K_GROUPS); }else{ linuxconf_replace (K_PICKGROUPS,K_GROUPS,groups); } linuxconf_save(); break; } } } } ("pickgroups",PACKAGE_REV); tb.add (new SSTRING(MSG_U(T_USAGE ,"linuxconf --modulemain pickgroups usage\n" "\n" " pickgroups --option ...\n"))); if (context == MENU_USER_POLICIES){ keymenu = MSG_U(M_pickgroups,"Identify important groups"); dia.new_menuitem ("pickgroups","",keymenu); } if (context == MENU_USER_POLICIES){ if (key == keymenu){ CONTEXT_LOCK l("pickgroups"); if (l.isok()){ pickgroups_conf(); } } } return 0; int ret = LNCF_NOT_APPLICABLE; #if 0 // ### Check the variable key to provide your own html hook ret = 0; #endif return ret; int ret = -1; if (argc == 1){ CONTEXT_LOCK l("pickgroups"); if (l.isok()){ pickgroups_conf(); } }else{ printusage(); } return ret; class GROUPCHK: public ARRAY_OBJ{ public: SSTRING group; bool selected; /*~PROTOBEG~ GROUPCHK */ public: GROUPCHK (const char *_group, bool _selected); /*~PROTOEND~ GROUPCHK */ }; PUBLIC GROUPCHK::GROUPCHK (const char *_group, bool _selected) { group = _group; selected = _selected; } class PICKGROUPS_COMNG: public USERACCT_COMNG{ ARRAY_OBJS groups; bool is_new; SSTRING name; SSTRING others; // Other supplementary groups int field_others; // Position of this field in the dialog /*~PROTOBEG~ PICKGROUPS_COMNG */ public: PICKGROUPS_COMNG (DICTIONARY&_dict); int save (PRIVILEGE *priv); int savegrs (void); void setupdia (DIALOG&dia); int validate (DIALOG&, int &nof); /*~PROTOEND~ PICKGROUPS_COMNG */ }; /* Prepare the edition of important groups. */ PUBLIC PICKGROUPS_COMNG::PICKGROUPS_COMNG ( DICTIONARY &_dict) : USERACCT_COMNG (_dict) { override_exgroups(); name.setfrom(dict.get_str("name")); is_new = dict.get_bool ("is_new"); SSTRING tmp (pickgroups_getgroups()); { SSTRINGS tb; str_splitline (tmp,' ',tb); for (int i=0; iget(); groups.add (new GROUPCHK(g,false)); } } } PUBLIC void PICKGROUPS_COMNG::setupdia(DIALOG &dia) { // Extract the supplementary groups and fill the various // variables. USER *usr = (USER*)dict.get_obj("user"); if (usr != NULL){ const char *altgr = usr->getaltgrs(); SSTRINGS tb; str_splitline (altgr,' ',tb); tb.sort(); for (int i=0; iget(); bool found = false; for (int j=0; jgroup.cmp(g)==0){ found = true; c->selected = true; break; } } if (!found){ if (others.is_filled()) others.append (" "); others.append (g); } } } dia.addhelp (help_pickgroups,MSG_R(T_EXTRAGROUPS)); dia.newf_title (MSG_U(T_EXTRAGROUPS,"Extra groups"),1,"" ,MSG_R(T_EXTRAGROUPS)); for (int i=0; igroup.get(),g->selected,""); } field_others = dia.size(); dia.newf_str (MSG_U(F_OTHERSUP,"Extra groups"),others); } PUBLIC int PICKGROUPS_COMNG::savegrs() { USER *usr = (USER*)dict.get_obj ("user"); if (usr != NULL){ SSTRING tmp; for (int i=0; iselected){ tmp.appendf (" %s",c->group.get()); } } tmp.appendf (" %s",others.get()); usr->setaltgrs(tmp.get()); } return 0; } PUBLIC int PICKGROUPS_COMNG::save( PRIVILEGE *priv) { return 0; } PUBLIC int PICKGROUPS_COMNG::validate( DIALOG &, int &nof) { int ret = 0; if (pickgroups_validate (others)==-1){ nof = field_others; ret = -1; }else{ // We update the altgrs field here because the // "save" method is called after the USER object is saved. // The "save" method was meant to save extra informations about // the user, not in the user database itself. savegrs(); } return ret; } static USERACCT_COMNG *pickgroups_newcomng1( const char *key, DICTIONARY &dict) { USERACCT_COMNG *ret = NULL; if (strcmp(key,"user")==0){ const char *domain = dict.get_str("domain"); if (domain != NULL && strcmp(domain,"/")==0){ int may_edit = dict.get_int("may_edit"); if ((may_edit & USRACCT_EDITSUPGRP)!=0){ SSTRING groups(pickgroups_getgroups()); if (groups.is_filled()){ ret = new PICKGROUPS_COMNG (dict); } } } } return ret; } static REGISTER_USERACCT_COMNG qqq1 (pickgroups_newcomng1);