00001
00002 00003 00004 00005 00006 00007 00008 00009 00010 00011
00012 00013 00014 00015 00016
00017 #include <unistd.h>
00018 #include "modregister.h"
00019 #include "ldapconf_defs.h"
00020
00021 static char ID_CLIENT[]="client";
00022 00023 00024 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 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
00082 SSTRING slapd_schemacheck = "off";
00083 SSTRING slapd_loglevel = "0";
00084 SSTRING slapd_defaultaccess = "read";
00085 SSTRING slapd_referral = "";
00086
00087
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
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
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
00121 break;
00122 }
00123 else if (code == MENU_ACCEPT){
00124
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 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
00145 int n = tb.getnb();
00146 for (int i=0; i<n; i++){
00147 if (tb.getitem(i)->strstr(DBCONF_SUFFIX)){
00148
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
00155 lst.add(new SSTRING(name));
00156 }
00157 }
00158 lst.sort();
00159 return lst.getnb();
00160 }
00161 00162 00163 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 00212 00213
00214 void ldap_client_config()
00215 {
00216 VIEWITEMS v_ldap_conf;
00217 LDAPPROFILE profile;
00218 char buf[ATTR_VAL_MAX];
00219
00220
00221 gethostname(buf,sizeof(buf));
00222 dns2dc(buf,sizeof(buf),1);
00223
00224
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
00236 dia.set_registry_id (ID_CLIENT);
00237
00238
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
00262 break;
00263 }
00264 else if (code == MENU_ACCEPT){
00265
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 00280 00281 00282 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