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

profile.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 /* ldapconf profiles 
00013     
00014     (FIXME: need better description of the ldapconf profile types)
00015 
00016     The client profiles are used to hold information for directory binding and layout.
00017     A client profile will point to:
00018     - a bind profile - which holds the authentication information for a directory
00019     - a form profile - which provides fields for updating a directory
00020     - other settings for handling this directory    
00021     
00022 ***************************************************************************/
00023 #include <stdlib.h>
00024 #include <confdb.h>
00025 #include <unistd.h>
00026 #include "profiles.h"
00027 #include "fields.h"
00028 #include "ldapconf_defs.h"
00029 
00030 HELP_FILE help_profile("ldapconf","profile");
00031 
00032 static PROFILES profiles(PROFILE_DIR,"Directory");
00033 static PROFILES bindings(DBBIND_DIR,"Binding");
00034 static PROFILES forms(DBFORM_DIR,"Form");
00035 
00036 /*
00037 static PRIVILEGES priv_profile;
00038 
00039 static void profiles_priv(){
00040 
00041     profiles.setup_priv(priv_profile,MSG_U(T_PROFILE_PRIV,"LDAP Profile"));
00042 }
00043 
00044 static PRIVILEGE_DECLARATOR profiles_decl(profiles_priv);
00045 
00046 */
00047 
00048 /*
00049 
00050   Edit LDAP user profile
00051 
00052 */
00053 
00054 void profile_edit(const char *id)
00055 {
00056     while (profiles.dia_admin() != -1){
00057 
00058         CONFDB c_profile = *profiles.profile.data;
00059     
00060         D(debugf(2,"profile_edit profile.id = %s \n",profiles.id.get()));
00061 
00062         SSTRINGS tb;
00063         int n;
00064 
00065         SSTRING bind_name = c_profile.getval ("profile","bind","userinfo");
00066         SSTRING form_name = c_profile.getval ("profile","form","userinfo");
00067         SSTRING ldap_protocol = c_profile.getval ("profile","protocol",mode_ldap_protocol.get());
00068         SSTRING dn_prefix = c_profile.getval ("profile","prefix","ou=People");
00069         SSTRING primary_key = c_profile.getval ("profile","primarykey","uid");  
00070         SSTRING group_prefix = c_profile.getval ("profile","groupprefix","ou=Group");
00071         SSTRING member_key = c_profile.getval ("profile","memberkey","memberuid");
00072         char userconf_comng = c_profile.getvalnum ("profile","userconf_comng",0);
00073         char userconf_pwsync = c_profile.getvalnum ("profile","userconf_pwsync",0);     
00074         SSTRING crypt_hash = c_profile.getval ("profile","crypt_hash","crypt");
00075         SSTRING comment = c_profile.getval ("profile","comment","");
00076         char user_access = c_profile.getvalnum ("profile","useraccess",0);
00077         int max_uid = c_profile.getvalnum ("profile","max_uid",50000);
00078         int min_uid = c_profile.getvalnum ("profile","min_uid",10000);
00079 
00080         DIALOG dia;
00081 
00082         // General
00083         dia.newf_info("Profilename",profiles.profile.id.get());
00084         dia.newf_str (MSG_U(F_PROFILE_COMMENT,"Comment"),comment);
00085         char protocol = atoi(ldap_protocol.get()); 
00086         dia.newf_radio (MSG_U(F_PROFILE_PROTOCOL,"LDAP Protocol"),protocol,2,"v2");
00087         dia.newf_radio("",protocol,3,"v3");
00088         dia.newf_title(MSG_U(T_PROFILE_PERM,"Permission"),1,"",MSG_R(T_PROFILE_PERM));
00089         FIELD_COMBO *bindlist = dia.newf_combo(MSG_U(F_PROFILE_BIND,"Bind profile"),bind_name);
00090         tb.remove_all();
00091         n = bindings.get_list(tb);
00092         for (int i=0; i<n; i++){
00093             bindlist->addopt(tb.getitem(i)->get());
00094         }
00095         dia.newf_chk (MSG_U(F_PROFILE_ACCESS,"User access"),user_access,"Allow");
00096 
00097         dia.newf_title(MSG_U(T_PROFILE_FORM,"Form"),1,"",MSG_R(T_PROFILE_FORM));
00098         FIELD_COMBO *formlist = dia.newf_combo(MSG_U(F_PROFILE_FORM,"Form profile"),form_name);
00099         tb.remove_all();
00100         n = forms.get_list(tb);
00101         for (int i=0; i<n; i++){
00102             formlist->addopt(tb.getitem(i)->get());
00103         }
00104         // Accounts
00105         dia.newf_title(MSG_U(T_PROFILE_ACCOUNTS,"Accounts"),1,"",MSG_R(T_PROFILE_ACCOUNTS));
00106         dia.newf_str (MSG_U(F_PROFILE_KEY,"Account key attribute"),primary_key);
00107         dia.newf_str (MSG_U(F_PROFILE_PREFIX,"Account prefix component"),dn_prefix);
00108         dia.newf_chk (MSG_U(F_PROFILE_COMNG,"Userconf comanager"),userconf_comng,"Enable");
00109         dia.newf_chk (MSG_U(F_PROFILE_PWSYNC,"Userconf password sync"),userconf_pwsync,"Enable");
00110         FIELD_COMBO *hashlist = dia.newf_combo(MSG_U(F_CRYPT_HASH,"Password crypt algorithm"),crypt_hash);
00111         hashlist->addopt ("none");
00112         hashlist->addopt ("crypt");
00113         hashlist->addopt ("md5");
00114         hashlist->addopt ("smd5");
00115         hashlist->addopt ("sha");
00116         hashlist->addopt ("ssha");
00117         dia.newf_num (MSG_U(F_PROFILE_MAXUID,"Max uid"),max_uid);
00118         dia.newf_num (MSG_U(F_PROFILE_MINUID,"Min uid"),min_uid);
00119         // Groups
00120         dia.newf_title(MSG_U(T_PROFILE_GROUPCONF,"Groups"),1,"",MSG_R(T_PROFILE_GROUPCONF));
00121         dia.newf_str (MSG_U(F_PROFILE_MEMBER,"Member key attribute"),member_key);
00122         dia.newf_str (MSG_U(F_PROFILE_GROUP,"Group prefix component"),group_prefix);
00123     
00124         int nof = 0;
00125 
00126         while (1){
00127             MENU_STATUS code = dia.edit (MSG_U(T_PROFILE_EDIT,"Profile")
00128                                          ,MSG_U(I_PROFILE_EDIT
00129                                                 ,"Profile setup")
00130                                          ,help_formclient           
00131                                          ,nof,
00132                                          MENUBUT_ACCEPT|MENUBUT_CANCEL|MENUBUT_ADD|MENUBUT_DEL);
00133             if (code == MENU_CANCEL || code == MENU_ESCAPE){
00134                 break;
00135             }else if (code == MENU_DEL && profiles.del()) {
00136                     break;
00137             }else if (code == MENU_ADD && profiles.add(&c_profile)) {
00138                     break;
00139             }else if (code == MENU_ACCEPT){
00140                 // Save profile 
00141                 ldap_protocol.setfrom(protocol);
00142                 
00143                 c_profile.replace ("profile","bind",bind_name);
00144                 c_profile.replace ("profile","form",form_name);
00145                 c_profile.replace ("profile","protocol",ldap_protocol.get());
00146                 c_profile.replace ("profile","prefix",dn_prefix);
00147                 c_profile.replace ("profile","primarykey",primary_key);
00148                 c_profile.replace ("profile","userconf_comng",userconf_comng);
00149                 c_profile.replace ("profile","userconf_pwsync",userconf_pwsync);
00150                 c_profile.replace ("profile","crypt_hash",crypt_hash);
00151                 c_profile.replace ("profile","memberkey",member_key);
00152                 c_profile.replace ("profile","groupprefix",group_prefix);
00153                 c_profile.replace ("profile","useraccess",user_access);
00154                 c_profile.replace ("profile","comment",comment);
00155                 c_profile.replace ("profile","max_uid",max_uid);
00156                 c_profile.replace ("profile","min_uid",min_uid);
00157 
00158                 c_profile.save();
00159                 break;
00160             }
00161         }   
00162     }
00163 }
00164 
00165 void profile_select()
00166 {
00167     while (profiles.dia_select() != -1){
00168         ldap_usermenu(profiles.profile.id.get());
00169     }
00170 }
00171 
00172 /*
00173   Config binding
00174 */
00175 void bindprofile_edit() 
00176 {
00177     while (bindings.dia_admin() != -1){
00178         CONFDB conf = *bindings.profile.data;
00179         /* Defaults */
00180 
00181         SSTRING binddn = conf.getval ("ldap","binddn");
00182         SSTRING bindpw = conf.getval ("ldap","bindpw");
00183         SSTRING host = conf.getval ("ldap","host");
00184         SSTRING base = conf.getval ("ldap","base");
00185 
00186         DIALOG dia;
00187         dia.newf_info("Profilename",bindings.profile.id.get());
00188         dia.newf_str(MSG_U(F_BINDPROFILE_BASE,"Base"),base);
00189         dia.newf_str(MSG_U(F_BINDPROFILE_HOST,"Host"),host);
00190         dia.newf_str(MSG_U(F_BINDPROFILE_DN,"Bind DN"),binddn);
00191         dia.newf_str(MSG_U(F_BINDPROFILE_PW,"Password"),bindpw);
00192     
00193         int nof = 0;        
00194         while (1){      
00195             MENU_STATUS code = dia.edit (MSG_U(T_BINDPROFILE_CONFIG,"LDAP Bind profile")
00196                                          ,MSG_U(I_BINDPROFILE_CONFIG,"Configure LDAP binding profile")
00197                                          ,help_ldap
00198                                          ,nof
00199                                          ,MENUBUT_ADD|MENUBUT_ACCEPT|MENUBUT_CANCEL|MENUBUT_DEL);
00200             if (code == MENU_QUIT || code == MENU_CANCEL || code == MENU_ESCAPE){                   
00201                 break;          
00202             }else if (code == MENU_DEL && bindings.del()){
00203                 break;
00204             }else if (code == MENU_ADD && bindings.add(&conf)){
00205                 break;
00206             }else if (code == MENU_ACCEPT){
00207                 conf.replace("ldap","base",base.get());
00208                 conf.replace("ldap","host",host.get());
00209                 conf.replace("ldap","binddn",binddn.get());
00210                 conf.replace("ldap","bindpw",bindpw.get());
00211                 conf.save();            
00212                 break;
00213             }
00214         }
00215     }
00216 }
00217 
00218 /*
00219 
00220   Collections of database forms using FORM_DEFS from the userinfo module.
00221   All forms will be saved in separate files, to allow "dropin" forms from database implementations.
00222   The forms are saved in /etc/ldapconf/dbform.
00223 
00224 */
00225 
00226 /*
00227 
00228   Edit form profiles
00229 
00230 */
00231 
00232 void formprofile_edit()
00233 {
00234     while (forms.dia_admin() != -1){
00235         FIELD_DEFS defs(forms.profile.data);
00236         defs.read();
00237         defs.edit();
00238         defs.write();
00239     }
00240 }
00241 
00242 
00243 
00244 

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