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

openldap.cc

Go to the documentation of this file.
00001 /*************************************************************************/
00002 /*  LDAPCONF - Linuxconf module for LDAP operation.
00003     
00004     Copyright (C) 1999,2000,2001 Stein Vråle <stein@terminator.net>
00005 
00006     This program is distributed in the hope that it will be useful,
00007     but WITHOUT ANY WARRANTY; without even the implied warranty of
00008     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
00009     GNU General Public License for more details.
00010     
00011 **************************************************************************/
00012 /*  OPENLDAP.cc
00013     
00014     Functions to support the openldap distribution.
00015     
00016 **************************************************************************/
00017 #include <unistd.h>
00018 #include "modregister.h"
00019 #include "ldapconf_defs.h"
00020 
00021 static char ID_CLIENT[]="client"; // vregistry
00022 
00023 /*! 
00024     LDAP master control dialog
00025 */
00026 void ldap_server_control(){
00027     const char *server_start = MSG_U(M_SERVER_START,"Start LDAP server");
00028     const char *server_stop = MSG_U(M_SERVER_STOP,"Stop LDAP server");
00029     const char *server_restart = MSG_U(M_SERVER_RESTART,"Restart LDAP server");
00030     const char *server_status = MSG_U(M_SERVER_STATUS,"LDAP server status");    
00031 
00032     const char *tbopt[]={
00033         "", server_start,
00034         "", server_stop,
00035         "", server_restart,
00036         "", server_status,
00037         NULL
00038     };
00039         
00040     DIALOG dia;
00041     dia.new_menuitems(tbopt);
00042     int nof = 0;
00043     while (1){
00044         MENU_STATUS code = dia.editmenu (MSG_U(T_SERVER_CONTROL,"Server Control")
00045                                          ,MSG_U(I_SERVER_CONTROL,
00046                                                 "Control LDAP server")
00047                                          ,help_ldap
00048                                          ,nof,0);
00049         if (code == MENU_ESCAPE || code == MENU_QUIT){
00050             break;
00051         }else{
00052             const char *key = dia.getmenustr(nof);
00053             if (key == server_start){
00054                 sys_command_title ("LDAP server","slapd.init","start");
00055             }else if (key == server_stop){
00056                 sys_command_title ("LDAP server","slapd.init","stop");
00057             }else if (key == server_restart){
00058                 sys_command_title ("LDAP server","slapd.init","restart");
00059             }else if (key == server_status){
00060                 ldap_status();
00061             }
00062         }
00063     }
00064 }
00065 
00066 /*! 
00067     LDAP master config dialog
00068 */
00069 void ldap_server_config()
00070 {
00071     CONFIG_FILE f_slapd_conf ("slapd.conf",
00072                               help_ldap,
00073                               CONFIGF_OPTIONNAL|CONFIGF_MANAGED,
00074                               mode_slapd_user.get(),
00075                               mode_slapd_group.get(),
00076                               0400,
00077                               subsys_ldap);
00078     
00079     VIEWITEMS v_slapd_conf;
00080 
00081     // Global defaults
00082     SSTRING slapd_schemacheck = "off";
00083     SSTRING slapd_loglevel = "0";
00084     SSTRING slapd_defaultaccess = "read";
00085     SSTRING slapd_referral = "";
00086 
00087     //  Read config
00088     v_slapd_conf.read (f_slapd_conf);
00089     slapd_schemacheck.setfrom (get_keyval(v_slapd_conf,"schemacheck"));
00090     slapd_loglevel.setfrom (get_keyval(v_slapd_conf,"loglevel"));
00091     slapd_defaultaccess.setfrom (get_keyval(v_slapd_conf,"defaultaccess"));
00092     slapd_referral.setfrom (get_keyval(v_slapd_conf,"referral"));
00093 
00094     // Edit config
00095     DIALOG dia;
00096 
00097     dia.newf_title ("",MSG_U(I_MASTER_GLOBAL,"Global settings"));
00098     FIELD_COMBO *schema = dia.newf_combo(MSG_U(F_SLAPD_SCHEMACHECK,"Schemacheck"),slapd_schemacheck);
00099     schema->addopt ("on");
00100     schema->addopt ("off");
00101     dia.newf_str (MSG_U(F_SLAPD_LOGLEVEL,"Loglevel"),slapd_loglevel);
00102     FIELD_COMBO *accesslist = dia.newf_combo(MSG_U(F_SLAPD_DEFAULTACCESS,"Default access"),slapd_defaultaccess);
00103     accesslist->addopt ("none");
00104     accesslist->addopt ("compare");
00105     accesslist->addopt ("search");
00106     accesslist->addopt ("read");
00107     accesslist->addopt ("write");
00108 //  accesslist->addopt ("delete");
00109     dia.newf_str (MSG_U(F_SLAPD_REFERRAL,"Referral"),slapd_referral);
00110 
00111     int nof = 0;
00112 
00113     while (1){
00114         MENU_STATUS code = dia.edit (MSG_U(T_MASTER_CONFIG,"Server")
00115                                      ,MSG_U(I_MASTER_CONFIG
00116                                             ,"Current LDAP server config")              
00117                                      ,help_ldap
00118                                      ,nof);
00119         if (code == MENU_CANCEL || code == MENU_ESCAPE){
00120             // Exit
00121             break;
00122         }
00123         else if (code == MENU_ACCEPT){
00124             // Save config
00125             set_keyval(v_slapd_conf,"schemacheck",slapd_schemacheck.get());
00126             set_keyval(v_slapd_conf,"loglevel",slapd_loglevel.get());
00127             set_keyval(v_slapd_conf,"defaultaccess",slapd_defaultaccess.get());
00128             set_keyval(v_slapd_conf,"referral",slapd_referral.get());
00129             v_slapd_conf.write (f_slapd_conf,&p_ldap_admin);
00130             break;
00131         }
00132     }
00133 }
00134 
00135 /*!
00136     Return list of all LDAP databases
00137 */
00138 int ldap_db_getlist (SSTRINGS &lst)
00139 {
00140     SSTRINGS tb;
00141 
00142     dir_getfiltered (DBCONF_DIR,tb,".OLD .rpmorig .rpmsave .rpmnew ~");
00143 
00144     /* Filter out DB configs */
00145     int n = tb.getnb();
00146     for (int i=0; i<n; i++){
00147         if (tb.getitem(i)->strstr(DBCONF_SUFFIX)){
00148             /* Remove suffix */
00149             SSTRINGS buf;
00150             char name[256];
00151             str_splitline(tb.getitem(i)->get(),'.',buf);
00152             sprintf(name,buf.getitem(0)->get());
00153             strip_end(name);
00154             /* Add profilename */
00155             lst.add(new SSTRING(name));
00156         }
00157     }
00158     lst.sort();
00159     return lst.getnb();
00160 }
00161 
00162 /*!
00163     Select LDAP db
00164 */
00165 void ldap_db_select()
00166 {
00167     SSTRINGS db_lst;
00168     DIALOG_LISTE dia;
00169     dia.newf_head ("",MSG_U(F_DB_LIST,"Database"));
00170     int nof = 0;
00171     
00172     while (1){
00173         db_lst.remove_all();    
00174         int n = ldap_db_getlist(db_lst);
00175         for (int i=0; i<n; i++){
00176             dia.set_menuitem (i,db_lst.getitem(i)->get(),"");
00177         }
00178         dia.remove_last (n+1);  
00179         MENU_STATUS code = dia.editmenu (
00180             MSG_U(T_LDAP_DB_LIST,"Server database list")
00181             ,MSG_U(I_LDAP_DB_LIST,"Select database")
00182             ,help_ldap
00183             ,nof,MENUBUT_ADD);
00184         if (code == MENU_QUIT || code == MENU_ESCAPE){                  
00185             break;
00186         }
00187         else if (code == MENU_ADD){
00188             char name[100];
00189             if (dialog_inputbox(MSG_U(T_NEWDIRECTORY,"New database")
00190                                 ,MSG_U(I_NEWDIRECTORY
00191                                        ,"Select a nickname for this database")
00192                                 ,help_ldap,name) == MENU_ACCEPT){
00193                 LDAPDB db(name);
00194                 db.init(name);
00195                 db.config(name);
00196                 db.menu();
00197             } else {
00198                 break;
00199             }
00200         }
00201         else if (nof >=0 && nof < db_lst.getnb()){
00202             const char *name = db_lst.getitem(nof)->get();
00203             LDAPDB db(name);
00204             db.read(name);
00205             db.menu();
00206         }
00207     }
00208 }
00209 
00210 /*! 
00211     LDAP Client config
00212     Used by normal user applications
00213 */
00214 void ldap_client_config()
00215 {
00216     VIEWITEMS v_ldap_conf;
00217     LDAPPROFILE profile;
00218     char buf[ATTR_VAL_MAX];
00219 
00220     // Generate defaults */ 
00221     gethostname(buf,sizeof(buf));
00222     dns2dc(buf,sizeof(buf),1);
00223 
00224     // Read configfile
00225     v_ldap_conf.read (f_ldap_conf);
00226     profile.host.setfrom (get_keyval(v_ldap_conf,"host","ldap"));
00227     profile.base.setfrom (get_keyval(v_ldap_conf,"base",buf));
00228     profile.dn.setfrom (get_keyval(v_ldap_conf,"binddn"));
00229     profile.pw.setfrom (get_keyval(v_ldap_conf,"bindpw"));
00230     profile.scope.setfrom (get_keyval(v_ldap_conf,"scope","sub"));
00231     profile.port.setfrom (get_keyval(v_ldap_conf,"port","389"));
00232 
00233     DIALOG dia;
00234 
00235     // Vregistry support
00236     dia.set_registry_id (ID_CLIENT);
00237 
00238     // Edit config
00239     dia.newf_title (MSG_U(I_GENERAL,"General"),1,"",MSG_R(I_GENERAL));
00240     dia.newf_str (MSG_R(F_API_HOST),profile.host);
00241     dia.newf_str (MSG_R(F_API_BASE),profile.base);
00242     dia.newf_title (MSG_R(I_LDAPBIND),1,"",MSG_R(I_LDAPBIND));
00243     dia.newf_str (MSG_R(F_API_DN),profile.dn);
00244     dia.newf_pass (MSG_R(F_API_PW),profile.pw);
00245     dia.newf_title (MSG_U(I_MISC,"Misc"),1,"",MSG_R(I_MISC));
00246     dia.newf_str (MSG_R(F_API_PORT),profile.port);
00247     FIELD_COMBO *scopelist = dia.newf_combo(MSG_R(F_API_SCOPE),profile.scope);
00248     scopelist->addopt ("one");
00249     scopelist->addopt ("base");
00250     scopelist->addopt ("sub");
00251     
00252     int nof = 0;
00253 
00254     while (1){
00255         MENU_STATUS code = dia.edit (MSG_U(T_CLIENT_MENU,"Client")
00256                                      ,MSG_U(I_CLIENT_MENU
00257                                             ,"Default LDAP client configuration for this system.")
00258                                      ,help_ldapclient
00259                                      ,nof);
00260         if (code == MENU_CANCEL || code == MENU_ESCAPE){
00261             // Exit
00262             break;
00263         }
00264         else if (code == MENU_ACCEPT){
00265             // Save config
00266             set_keyval(v_ldap_conf,"host",profile.host.get());
00267             set_keyval(v_ldap_conf,"port",profile.port.get());
00268             set_keyval(v_ldap_conf,"base",profile.base.get());
00269             set_keyval(v_ldap_conf,"binddn",profile.dn.get());
00270             set_keyval(v_ldap_conf,"bindpw",profile.pw.get());
00271             set_keyval(v_ldap_conf,"scope",profile.scope.get());
00272             v_ldap_conf.write (f_ldap_conf,&p_ldap_admin);
00273             break;
00274         }
00275     }
00276 }
00277 
00278 /*!
00279     VREGISTRY support:
00280 
00281     vregistry --set ldapconf.client.host = <host>
00282     vregistry --set ldapconf.client.base = <base>
00283 */
00284 static REGISTER_VARIABLE_LOOKUP_MSG ldapconf_var_list[]={
00285     {"client.host",ID_CLIENT,P_MSG_R(F_API_HOST),ldap_client_config,NULL},
00286     {"client.base",ID_CLIENT,P_MSG_R(F_API_BASE),ldap_client_config,NULL},
00287     { NULL, NULL, NULL, NULL }
00288 };
00289 
00290 static REGISTER_VARIABLES ldapconf_registry("ldapconf",ldapconf_var_list);
00291 
00292 
00293 
00294 
00295 
00296 
00297 
00298 
00299 
00300 
00301 
00302 

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