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

ldapconf.cc

Go to the documentation of this file.
00001 /**************************************************************************
00002 
00003     LDAPCONF - Linuxconf module for LDAP operations.
00004 
00005     Copyright (C) 1999,2000,2001 Stein Vråle <stein@terminator.net>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020  
00021 **************************************************************************/
00022 #pragma implementation
00023 #include "ldapconf_defs.h"
00024 #include <userconf.h>
00025 #include <string.h>
00026 
00027 const char subsys_ldap[]="ldapconf";
00028 
00029 const char PAM_SERVICES[]="/etc/pam.d";
00030 const char PAM_MODULES[]="/lib/security";
00031 const char OPENLDAP_DATA_DIR[]="/var/lib/ldap";
00032 const char OPENLDAP_CONF_DIR[]="/etc/openldap";
00033 const char LDAPCONF_CONF_DIR[]="/etc/ldapconf";
00034 const char DBCONF_DIR[]="/etc/ldapconf/db";
00035 const char DBBIND_DIR[]="/etc/ldapconf/bind";
00036 const char DBFORM_DIR[]="/etc/ldapconf/form";
00037 const char PROFILE_DIR[]="/etc/ldapconf/profile";
00038 const char DBCONF_SUFFIX[]=".db.conf"; // File extension on directory config-files
00039 
00040 LINUXCONF_SUBSYS sub_ldap (subsys_ldap,P_MSG_U(M_LDAP_SUBSYS,"LDAP subsystem"));
00041 PRIVILEGE p_ldap_admin (subsys_ldap,P_MSG_U(M_LDAP_ADMIN,"LDAP Admin"),P_MSG_U(T_PMISC,"9-Miscellaneous"));
00042 PRIVILEGE p_ldap_user (subsys_ldap,P_MSG_U(M_LDAP_USER,"LDAP user"),P_MSG_R(T_PMISC));
00043 
00044 CONFIG_FILE f_ldap_conf ("ldap.conf",help_ldapclient
00045                          ,CONFIGF_OPTIONNAL|CONFIGF_MANAGED
00046                          ,subsys_ldap);
00047 CONFIG_FILE f_ldap_sec ("ldap.sec",help_ldapsystem
00048                         ,CONFIGF_OPTIONNAL|CONFIGF_MANAGED
00049                         ,subsys_ldap);
00050 CONFIG_FILE f_nss_conf ("nsswitch.conf",help_ldap
00051                         ,CONFIGF_OPTIONNAL|CONFIGF_MANAGED
00052                         ,subsys_ldap);
00053 CONFIG_FILE f_ldapconf ("/etc/ldapconf/conf.ldapconf",help_setup
00054                         ,CONFIGF_OPTIONNAL|CONFIGF_MANAGED
00055                         ,subsys_ldap);
00056 // Module setup modes
00057 char mode_ldap_system;
00058 char mode_ldap_client;
00059 char mode_ldap_server;
00060 char mode_ldap_devel;
00061 int mode_ldap_debug;
00062 char mode_ldap_directory;
00063 char mode_ldap_profile;
00064 char mode_ldap_userinfo;
00065 char mode_ldap_pwsync;
00066 char mode_ldap_formclient;
00067 char mode_ldap_useraccount;
00068 char mode_ldap_wwwclient;
00069 SSTRING mode_ldap_protocol;
00070 SSTRING mode_openldap_version;
00071 SSTRING mode_openldap_params;
00072 SSTRING mode_slapd_user;
00073 SSTRING mode_slapd_group;
00074 SSTRING mode_logfile;
00075 int mode_loglevel;
00076 
00077 // Menu keys
00078 static const char *key_ldap_main = NULL;
00079 static const char *key_ldap_client_config = NULL;
00080 static const char *key_ldap_system_config = NULL;
00081 static const char *key_ldap_server_config = NULL;
00082 static const char *key_ldap_server_control = NULL;
00083 static const char *key_ldap_server_status = NULL;
00084 static const char *key_userinfo_config = NULL;
00085 static const char *key_ldap_useradmin = NULL;
00086 
00087 MODULE_DEFINE_VERSION(ldapconf);
00088 
00089 PUBLIC MODULE_ldapconf::MODULE_ldapconf()
00090     : LINUXCONF_MODULE("ldapconf")
00091 {
00092     linuxconf_loadmsg ("ldapconf",PACKAGE_REV);
00093     ldapconf_setup_read();
00094 
00095     /*
00096       Configure the logfiles before use - we need one mainlog and one debuglog for now.
00097       use logf(level,0,msg,...) for ordinary logs
00098       use D(debugf(level,0,msg,...)) for debug
00099       level can go from 0 to 7: 1 is serious problems/short messages, 
00100       7 is info/long messages/many messages in loop for instance.
00101       level 0 will always be written. See loghandler.h and .cc for more info. 
00102     */
00103     loghandler_init(0,mode_logfile.get(),MAIN_LOG,mode_loglevel,SHOW_DATE | SHOW_TIME | SHOW_LEVEL);
00104     D(loghandler_init(1,"/tmp/ldapconf.debug",MAIN_LOG,mode_ldap_debug + 8, SHOW_CLASS | SHOW_LEVEL));
00105 }
00106 
00107 PUBLIC void MODULE_ldapconf::setmenu (
00108     DIALOG &dia,
00109     MENU_CONTEXT context)
00110 {
00111     if (context == MENU_MISCSERV){
00112         key_ldap_main = MSG_U(M_LDAP_MAIN,"LDAPconf");
00113         dia.new_menuitem ("ldapconf","",key_ldap_main);
00114     } 
00115     if (context == MENU_NETWORK_CLIENT && mode_ldap_system){
00116         key_ldap_system_config = MSG_U(M_LDAP_SYSTEM_CONFIG,"LDAP auth");
00117         dia.new_menuitem ("ldapconf","",key_ldap_system_config);
00118     }
00119     if (context == MENU_NETWORK_CLIENT && mode_ldap_client){
00120         key_ldap_client_config = MSG_U(M_LDAP_CLIENT_CONFIG,"LDAP client");
00121         dia.new_menuitem ("ldapconf","",key_ldap_client_config);
00122     }
00123     if (context == MENU_NETWORK_SERVER && mode_ldap_server){
00124         key_ldap_server_config = MSG_U(M_LDAP_SERVER_CONFIG,"LDAP server");
00125         dia.new_menuitem ("ldapconf","",key_ldap_server_config);
00126     }
00127     if (context == MENU_CONTROL_PANEL && mode_ldap_server){
00128         key_ldap_server_control = MSG_U(M_LDAP_SERVER_CONTROL,"LDAP control");
00129         dia.new_menuitem ("ldapconf","",key_ldap_server_control);
00130     }
00131     if (context == MENU_SYS_STATUS && mode_ldap_server){
00132         key_ldap_server_status = MSG_U(M_LDAP_STATUS,"LDAP status");
00133         dia.new_menuitem ("ldapconf","",key_ldap_server_status);
00134     }
00135     if (context == MENU_USER_POLICIES && mode_ldap_userinfo){
00136         key_userinfo_config = MSG_U(M_LDAP_USERINFO,"LDAP userconf");
00137         dia.new_menuitem ("ldapconf","",key_userinfo_config);
00138     }
00139     if (context == MENU_USER_SPC && mode_ldap_formclient){
00140         key_ldap_useradmin = MSG_U(M_LDAP_USERS,"LDAP accounts");
00141         dia.new_menuitem ("ldapconf","",key_ldap_useradmin);
00142     }
00143 }
00144 
00145 PUBLIC int MODULE_ldapconf::domenu (
00146     MENU_CONTEXT context,
00147     const char *key)
00148 
00149 {
00150     if (context == MENU_MISCSERV){
00151         if (key == key_ldap_main){
00152             ldap_mainmenu();
00153         }
00154     } else if (context == MENU_NETWORK_CLIENT){
00155         if (key == key_ldap_client_config){
00156             ldap_client_config();
00157         } else if (key == key_ldap_system_config){
00158             ldap_system_config();
00159         }
00160     } else if (context == MENU_NETWORK_SERVER){
00161         if (key == key_ldap_server_config){
00162             ldap_mainmenu_server();
00163         }
00164     } else if (context == MENU_CONTROL_PANEL){
00165         if (key == key_ldap_server_control){
00166             ldap_server_control();
00167         }
00168     } else if (context == MENU_SYS_STATUS){
00169         if (key == key_ldap_server_status){
00170             ldap_status();
00171         }
00172     }
00173     else if (context == MENU_USER_POLICIES){
00174         if (key == key_userinfo_config){
00175             profile_edit("userinfo");
00176         }
00177     }   
00178     else if (context == MENU_USER_SPC){
00179         if (key == key_ldap_useradmin){
00180             profile_select();
00181         }
00182     }
00183 
00184     return 0;
00185 }
00186 
00187 PUBLIC int MODULE_ldapconf::dohtml (const char *key)
00188 {
00189     int ret = LNCF_NOT_APPLICABLE;
00190 
00191     if (strcmp(key,"ldapconf")==0){
00192         profile_select();
00193         ret = 0;
00194     }
00195 
00196     return ret;
00197 }
00198 
00199 static void usage()
00200 {
00201     xconf_error (MSG_U(T_USAGE,
00202                        "ldapconf usage\n"
00203                        "\n"
00204                        "ldapconf --text\n")
00205         );
00206 }
00207 
00208 PUBLIC void MODULE_ldapconf::usage (SSTRINGS &tb)
00209 {
00210     tb.add (new SSTRING (MSG_R(T_USAGE)));
00211 }
00212 
00213 PUBLIC int MODULE_ldapconf::execmain (int argc , char *argv[],bool sa)
00214 {
00215     int ret = LNCF_NOT_APPLICABLE;
00216     const char *pt = strrchr(argv[0],'/');
00217     if (pt != NULL){
00218         pt++;
00219     }else{
00220         pt = argv[0];
00221     }
00222     if (strcmp(pt,"ldapconf")==0){
00223         ret = -1;
00224         if (argc == 1){
00225             ldap_mainmenu();
00226         }else{
00227             // ### Add some option parsing for the module
00228             ::usage();
00229         }
00230     }
00231     else if (strcmp(pt,"ldapuser")==0){
00232         ret = -1;
00233         if (argc == 1){
00234             profile_select();
00235         }else{
00236             // ### Add some option parsing for the module
00237             ::usage();
00238         }
00239     }
00240     return ret;
00241 }
00242 
00243 PUBLIC int MODULE_ldapconf::message (
00244     const char *msg,        // message
00245     int argc,                   // argc
00246     const char *argv[])         // argv[]
00247 {
00248     int ret = LNCF_NOT_APPLICABLE;
00249     if (strcmp(msg,"listspc")==0 && mode_ldap_wwwclient){
00250         ret = 0;
00251         html_printf ("<hr>\n");
00252         html_printf ("<center><a href=/htmlmod:ldapconf:>%s"
00253                      ,MSG_U(T_HTMLMENU,"LDAP tools"));
00254         html_printf ("</A></center><P>\n");
00255     } else if (strcmp(msg,"chgpasswd")==0 && mode_ldap_pwsync){
00256         const char *username = NULL;
00257         const char *newpassword = NULL;
00258         const char *locked = NULL;
00259         const char *domain = NULL;
00260         if (argc >= 1) username = argv[0];
00261         if (argc >= 2) newpassword = argv[1];
00262         if (argc >= 3) locked = argv[2];
00263         if (argc >= 4) domain = argv[3];
00264         ret = ldap_pwsync(username,domain,newpassword);
00265     }       
00266     return ret;
00267 }
00268 
00269 static MODULE_ldapconf ldapconf;
00270 
00271 
00272 
00273 
00274 
00275 
00276 
00277 
00278 
00279 
00280 
00281 
00282 
00283 
00284 
00285 
00286 
00287 
00288 
00289 
00290 

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