Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

pamconf.cc

Go to the documentation of this file.
00001 /*************
00002           
00003 PAMCONF
00004           
00005 License: Linuxconf/GPL (see the file COPYING for details)
00006 Author: Stein Vråle <stein@terminator.net>
00007 
00008 This is the start of a pam configurator. Currently it doesn't really work at all, 
00009 expect you may hand edit the various services.
00010 
00011 **************/
00012 
00013 #include "ldapconf_defs.h"
00014 
00015 /* 
00016    PAM menu 
00017 */
00018 void pam_config_main()
00019 {
00020     const char *pam_services = MSG_U(M_PAM_SERVICES_MENU,"Services");
00021     const char *pam_modules = MSG_U(M_PAM_MODULES_MENU,"Modules");
00022     
00023     static const char *tbopt[]={
00024         "", pam_services,
00025         "", pam_modules,
00026         NULL
00027     };
00028     
00029     DIALOG_MENU dia;
00030     dia.new_menuitems(tbopt);
00031     int nof = 0;
00032     while (1){
00033         MENU_STATUS code = dia.editmenu (MSG_U(T_PAM_MENU,"PAM")
00034                                          ,MSG_U(I_PAM_MENU
00035                                                 ,"Select PAM services or PAM modules")
00036                                          ,help_ldap
00037                                          ,nof,0);
00038         if (code == MENU_ESCAPE || code == MENU_QUIT){
00039             break;
00040         }else{
00041             const char *key = dia.getmenustr(nof);
00042             if (key == pam_services){
00043                 pam_service_list();
00044             }else if (key == pam_modules){
00045                 pam_module_list();
00046             }else{
00047                 const char *argv[2];
00048                 argv[0] = key;
00049                 argv[1] = NULL;
00050                 module_sendmessage ("statusshow",1,argv);
00051             }
00052         }
00053     }
00054 }
00055 
00056 
00057 /* 
00058    PAM service
00059 */
00060 void pam_config_service()
00061 {
00062 /* Set config */
00063     SSTRING pam_service_name = "samba";
00064     SSTRING pam_module_result = "required";
00065     SSTRING pam_module_type = "auth";
00066     SSTRING pam_module_file = "/lib/security/samba";
00067     SSTRING pam_options = "debug";
00068     
00069 /* Draw dialog */
00070     DIALOG dia;
00071     dia.newf_str (MSG_U(F_PAM_SERVICE_NAME,"Service name"),pam_service_name);
00072     dia.newf_str (MSG_U(F_PAM_MODULE_RESULT,"Module result"),pam_module_result);
00073     dia.newf_str (MSG_U(F_PAM_MODULE_TYPE,"Module type"),pam_module_type);
00074     dia.newf_str (MSG_U(F_PAM_MODULE_FILE,"Module file"),pam_module_file);
00075     dia.newf_str (MSG_U(F_PAM_OPTIONS,"Options"),pam_options);
00076     
00077 /* Wait for dialog */
00078     
00079     int nof = 0;
00080     
00081     while (1){
00082         MENU_STATUS code = dia.edit (MSG_U(T_PAM_CONFIG,"PAM config")
00083                                      ,MSG_U(I_PAM_CONFIG
00084                                             ,"One line of a PAM service\n This is not ready, just an example")              
00085                                      ,help_ldap
00086                                      ,nof);
00087 /* Exit */
00088         if (code == MENU_CANCEL || code == MENU_ESCAPE){
00089             break;
00090         }
00091     }
00092 }
00093 
00094 /* 
00095    PAM service
00096 */
00097 void pam_service_edit(const char *name)
00098 {
00099     char path[PATH_MAX] = "";
00100     int nof=0;
00101     sprintf (path,"%s/%s",PAM_SERVICES,name);
00102     CONFIG_FILE f_pam_service (path
00103                                ,help_ldap
00104                                ,CONFIGF_OPTIONNAL|CONFIGF_MANAGED
00105                                ,subsys_ldap);
00106     
00107     SSTRINGS tb;
00108     FILE_CFG *fin = f_pam_service.fopen("r");
00109     if (fin != NULL){
00110         char buf[200];
00111         while (fgets(buf,sizeof(buf)-1,fin)!=NULL){
00112             strip_end(buf);
00113             tb.add (new SSTRING (buf));
00114         }
00115     }
00116 
00117     for (int i=0; i<5; i++) tb.add (new SSTRING);
00118 
00119     DIALOG dia;
00120    
00121     dia.newf_title("",MSG_U(F_PAM_SERVICE,"PAM Service settings"));
00122     
00123     for (int i=0; i<tb.getnb(); i++){
00124         dia.newf_str ("",*tb.getitem(i));
00125     }
00126     while (1){
00127         MENU_STATUS code = dia.edit (MSG_U(M_PAM_SERVICE,"PAM service")
00128                                      ,MSG_U(I_PAM_SERVICE
00129                                             ,"Be very careful if you change this settings!")
00130                                      ,help_ldap
00131                                      ,nof);
00132         if (code == MENU_CANCEL || code == MENU_ESCAPE){
00133             break;
00134         }else{
00135             for (int i=tb.getnb()-1; i>=0; i--){
00136                 SSTRING *s = tb.getitem(i);
00137                 if (s->is_empty()) tb.remove_del (s);
00138             }
00139         
00140             FILE_CFG *fout = f_pam_service.fopen (&p_ldap_admin,"w");
00141             if (fout != NULL){
00142                 for (int i=0; i<tb.getnb(); i++){
00143                     fprintf (fout,"%s\n",tb.getitem(i)->get());
00144                 }
00145                 fclose (fout);
00146                 break;
00147             }
00148         }
00149     }
00150 }
00151 
00152 /*
00153   Return the list of all PAM modules
00154 */
00155 int pam_module_getlist (SSTRINGS &lst)
00156 {
00157     dir_getlist (PAM_MODULES,lst);
00158     lst.sort();
00159     return lst.getnb();
00160 }
00161 
00162 /*
00163   Return the list of all PAM services
00164 */
00165 int pam_service_getlist (SSTRINGS &lst)
00166 {
00167     dir_getlist (PAM_SERVICES,lst);
00168     lst.sort();
00169     return lst.getnb();
00170 }
00171 
00172 /*
00173   Select pam service
00174 */
00175 void pam_service_list()
00176 {
00177     SSTRINGS tb;
00178     DIALOG_LISTE *dia = NULL;
00179     int nof = 0;
00180     while (1){
00181         if (dia == NULL){
00182             dia = new DIALOG_LISTE;
00183             tb.remove_all();
00184             int n = pam_service_getlist(tb);
00185             dia->newf_head ("",MSG_U(F_PAM_SERVICE_LIST,"PAM services"));
00186             for (int i=0; i<n; i++){
00187                 dia->new_menuitem (tb.getitem(i)->get(),"");
00188             }
00189         }
00190         MENU_STATUS code = dia->editmenu (MSG_U(T_PAM_SERVICE_LIST,"PAM service config")
00191                                           ,MSG_U(I_PAM_SERVICE_LIST,"Select a configuration to edit")
00192                                           ,help_ldap
00193                                           ,nof
00194                                           ,MENUBUT_ADD);
00195         if (code == MENU_QUIT || code == MENU_ESCAPE){
00196             break;
00197         }
00198         else if (nof >=0 && nof < tb.getnb()){
00199             const char *name = tb.getitem(nof)->get();
00200             pam_service_edit(name);
00201         }
00202     }
00203     delete dia;
00204 }
00205 
00206 /*
00207   Select pam module
00208 */
00209 void pam_module_list()
00210 {
00211     SSTRINGS tb;
00212     DIALOG_LISTE *dia = NULL;
00213     int nof = 0;
00214     while (1){
00215         if (dia == NULL){
00216             dia = new DIALOG_LISTE;
00217             tb.remove_all();
00218             dia->newf_head ("",MSG_U(F_PAM_MODULE_LIST,"PAM modules"));
00219             int n = pam_module_getlist(tb);
00220             for (int i=0; i<n; i++){
00221                 dia->new_menuitem (tb.getitem(i)->get(),"");
00222             }
00223         }
00224         MENU_STATUS code = dia->editmenu (MSG_U(T_PAM_MODULE_LIST,"PAM module list")
00225                                           ,MSG_U(I_PAM_MODULE_LIST,"Currently disabled")
00226                                           ,help_ldap
00227                                           ,nof
00228                                           ,0);
00229         if (code == MENU_QUIT || code == MENU_ESCAPE){
00230             break;
00231         }
00232         else if (nof >=0 && nof < tb.getnb()){
00233             // const char *name = tb.getitem(nof)->get();
00234             pam_config_service();
00235         }
00236     }
00237     delete dia;
00238 }
00239 
00240 

Generated at Mon Jan 22 08:35:12 2001 for ldapconf by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000