/************* PAMCONF License: Linuxconf/GPL (see the file COPYING for details) Author: Stein Vråle This is the start of a pam configurator. Currently it doesn't really work at all, expect you may hand edit the various services. **************/ #include "ldapconf_defs.h" /* PAM menu */ void pam_config_main() { const char *pam_services = MSG_U(M_PAM_SERVICES_MENU,"Services"); const char *pam_modules = MSG_U(M_PAM_MODULES_MENU,"Modules"); static const char *tbopt[]={ "", pam_services, "", pam_modules, NULL }; DIALOG_MENU dia; dia.new_menuitems(tbopt); int nof = 0; while (1){ MENU_STATUS code = dia.editmenu (MSG_U(T_PAM_MENU,"PAM") ,MSG_U(I_PAM_MENU ,"Select PAM services or PAM modules") ,help_ldap ,nof,0); if (code == MENU_ESCAPE || code == MENU_QUIT){ break; }else{ const char *key = dia.getmenustr(nof); if (key == pam_services){ pam_service_list(); }else if (key == pam_modules){ pam_module_list(); }else{ const char *argv[2]; argv[0] = key; argv[1] = NULL; module_sendmessage ("statusshow",1,argv); } } } } /* PAM service */ void pam_config_service() { /* Set config */ SSTRING pam_service_name = "samba"; SSTRING pam_module_result = "required"; SSTRING pam_module_type = "auth"; SSTRING pam_module_file = "/lib/security/samba"; SSTRING pam_options = "debug"; /* Draw dialog */ DIALOG dia; dia.newf_str (MSG_U(F_PAM_SERVICE_NAME,"Service name"),pam_service_name); dia.newf_str (MSG_U(F_PAM_MODULE_RESULT,"Module result"),pam_module_result); dia.newf_str (MSG_U(F_PAM_MODULE_TYPE,"Module type"),pam_module_type); dia.newf_str (MSG_U(F_PAM_MODULE_FILE,"Module file"),pam_module_file); dia.newf_str (MSG_U(F_PAM_OPTIONS,"Options"),pam_options); /* Wait for dialog */ int nof = 0; while (1){ MENU_STATUS code = dia.edit (MSG_U(T_PAM_CONFIG,"PAM config") ,MSG_U(I_PAM_CONFIG ,"One line of a PAM service\n This is not ready, just an example") ,help_ldap ,nof); /* Exit */ if (code == MENU_CANCEL || code == MENU_ESCAPE){ break; } } } /* PAM service */ void pam_service_edit(const char *name) { char path[PATH_MAX] = ""; int nof=0; sprintf (path,"%s/%s",PAM_SERVICES,name); CONFIG_FILE f_pam_service (path ,help_ldap ,CONFIGF_OPTIONAL|CONFIGF_MANAGED ,subsys_ldap); SSTRINGS tb; FILE_CFG *fin = f_pam_service.fopen("r"); if (fin != NULL){ char buf[200]; while (fgets(buf,sizeof(buf)-1,fin)!=NULL){ strip_end(buf); tb.add (new SSTRING (buf)); } } for (int i=0; i<5; i++) tb.add (new SSTRING); DIALOG dia; dia.newf_title("",MSG_U(F_PAM_SERVICE,"PAM Service settings")); for (int i=0; i=0; i--){ SSTRING *s = tb.getitem(i); if (s->is_empty()) tb.remove_del (s); } FILE_CFG *fout = f_pam_service.fopen (&p_ldap_admin,"w"); if (fout != NULL){ for (int i=0; iget()); } fclose (fout); break; } } } } /* Return the list of all PAM modules */ int pam_module_getlist (SSTRINGS &lst) { dir_getlist (PAM_MODULES,lst); lst.sort(); return lst.getnb(); } /* Return the list of all PAM services */ int pam_service_getlist (SSTRINGS &lst) { dir_getlist (PAM_SERVICES,lst); lst.sort(); return lst.getnb(); } /* Select pam service */ void pam_service_list() { SSTRINGS tb; DIALOG_LISTE *dia = NULL; int nof = 0; while (1){ if (dia == NULL){ dia = new DIALOG_LISTE; tb.remove_all(); int n = pam_service_getlist(tb); dia->newf_head ("",MSG_U(F_PAM_SERVICE_LIST,"PAM services")); for (int i=0; inew_menuitem (tb.getitem(i)->get(),""); } } MENU_STATUS code = dia->editmenu (MSG_U(T_PAM_SERVICE_LIST,"PAM service config") ,MSG_U(I_PAM_SERVICE_LIST,"Select a configuration to edit") ,help_ldap ,nof ,MENUBUT_ADD); if (code == MENU_QUIT || code == MENU_ESCAPE){ break; } else if (nof >=0 && nof < tb.getnb()){ const char *name = tb.getitem(nof)->get(); pam_service_edit(name); } } delete dia; } /* Select pam module */ void pam_module_list() { SSTRINGS tb; DIALOG_LISTE *dia = NULL; int nof = 0; while (1){ if (dia == NULL){ dia = new DIALOG_LISTE; tb.remove_all(); dia->newf_head ("",MSG_U(F_PAM_MODULE_LIST,"PAM modules")); int n = pam_module_getlist(tb); for (int i=0; inew_menuitem (tb.getitem(i)->get(),""); } } MENU_STATUS code = dia->editmenu (MSG_U(T_PAM_MODULE_LIST,"PAM module list") ,MSG_U(I_PAM_MODULE_LIST,"Currently disabled") ,help_ldap ,nof ,0); if (code == MENU_QUIT || code == MENU_ESCAPE){ break; } else if (nof >=0 && nof < tb.getnb()){ // const char *name = tb.getitem(nof)->get(); pam_config_service(); } } delete dia; }