#include <ldapconf_defs.h>
Inheritance diagram for LDAPDB:

Public Methods | |
| LDAPDB (const char *dbname) | |
| LDAPDB (void) | |
| void | config (const char *dbname) |
| int | create (void) |
| int | export_ldif (const char *profile_name) |
| int | export_ldif (void) |
| int | import_ldif (void) |
| int | init (const char *dbname) |
| void | menu (void) |
| int | read (const char *dbname) |
Public Attributes | |
| LDAPPROFILE | bind |
| SSTRING | name |
| SSTRING | database |
| SSTRING | directory |
| SSTRING | replogfile |
| SSTRING | updatedn |
| SSTRING | replica |
| SSTRING | lastmod |
| SSTRING | readonly |
| SSTRINGS | access_list |
| SSTRINGS | attribute_list |
| SSTRINGS | objectclass_list |
| SSTRINGS | index_list |
| SSTRING | defaultaccess |
| SSTRING | loglevel |
| SSTRING | schemacheck |
| SSTRING | referral |
|
|
Definition at line 29 of file ldap_db.cc. 00030 {
00031 name.setfrom (dbname);
00032 }
|
|
|
Definition at line 24 of file ldap_db.cc. 00025 {
00026
00027 }
|
|
|
Definition at line 528 of file ldap_db.cc. Referenced by ldap_db_select(), and menu(). 00528 {
00529 CONFIG_FILE f_slapd_conf ("slapd.conf",
00530 help_ldap,
00531 CONFIGF_OPTIONNAL|CONFIGF_MANAGED,
00532 mode_slapd_user.get(),
00533 mode_slapd_group.get(),
00534 0400,
00535 subsys_ldap);
00536 VIEWITEMS v_db_conf;
00537 VIEWITEMS v_slapd_conf;
00538
00539 char was_enabled = false;
00540 char enable_database = true;
00541 char acl_selfwrite = true; // Sample ACL for self write access
00542 char index_nss = true; // Sample indexing to improve nss performance
00543 char path[PATH_MAX] = "";
00544
00545 /* Calculate filename */
00546 sprintf (path,"%s/%s%s",DBCONF_DIR,dbname,DBCONF_SUFFIX);
00547
00548 /* Check if this db is enabled in slapd.conf */
00549 VIEWITEMS inc_items;
00550 VIEWITEM *inc_item=NULL;
00551 v_slapd_conf.read (f_slapd_conf);
00552 int n = v_slapd_conf.locate("include",inc_items);
00553 for (int i=0; i<n; i++){
00554 inc_item = inc_items.getitem(i);
00555 if (inc_item->line.strstr(path)!=0) {
00556 enable_database = true;
00557 was_enabled = true;
00558 break; /* inc_item will point to this db entry */
00559 }
00560 }
00561
00562 /* Draw dialog */
00563 SSTRING filename(path);
00564 DIALOG dia;
00565
00566 dia.newf_title (MSG_U(I_GENERAL_PARAM,"General"),1,"","");
00567 dia.newf_chk (MSG_U(F_DB_ENABLE,"Enable database"),enable_database," ");
00568 dia.newf_str (MSG_U(F_DB_PROFILE,"Config file"),filename);
00569 FIELD_COMBO *dblist = dia.newf_combo(MSG_U(F_SLAPD_DATABASE,"Database type"),database);
00570 dblist->addopt ("ldbm");
00571 dblist->addopt ("shell");
00572 dblist->addopt ("passwd");
00573 dia.newf_str (MSG_U(F_DB_DIRECTORY,"LDBM directory path"),directory);
00574 FIELD_COMBO *readonly_key = dia.newf_combo (MSG_U(F_DB_READONLY,"Readonly"),readonly);
00575 readonly_key->addopt ("on");
00576 readonly_key->addopt ("off");
00577
00578 FIELD_COMBO *schema = dia.newf_combo(MSG_U(F_DB_SCHEMACHECK,"Schemacheck"),schemacheck);
00579 schema->addopt ("on");
00580 schema->addopt ("off");
00581 dia.newf_str (MSG_U(F_DB_LOGLEVEL,"Loglevel"),loglevel);
00582 FIELD_COMBO *accesslist = dia.newf_combo(MSG_U(F_DB_DEFAULTACCESS,"Default access"),defaultaccess);
00583 accesslist->addopt ("none");
00584 accesslist->addopt ("compare");
00585 accesslist->addopt ("search");
00586 accesslist->addopt ("read");
00587 accesslist->addopt ("write");
00588 // accesslist->addopt ("delete");
00589 dia.newf_str (MSG_U(F_DB_REFERRAL,"Referral"),referral);
00590
00591 dia.newf_title (MSG_U(I_MASTER_DATABASE,"Root"),1,"","");
00592 dia.newf_str (MSG_R(F_API_BASE),bind.base);
00593 dia.newf_str (MSG_R(F_API_DN),bind.dn);
00594 dia.newf_str (MSG_R(F_API_PW),bind.pw);
00595
00596 dia.newf_title (MSG_U(I_MASTER_PARAM,"Master"),1,"","");
00597 FIELD_COMBO *lastmod_key= dia.newf_combo (MSG_U(F_DB_LASTMOD,"Lastmod recording"),lastmod);
00598 lastmod_key->addopt ("on");
00599 lastmod_key->addopt ("off");
00600 dia.newf_str (MSG_U(F_DB_REPLOG,"Replicaton log"),replogfile);
00601 dia.newf_str (MSG_U(F_DB_REPLICA,"Replica host"),replica);
00602
00603 dia.newf_title (MSG_U(I_SLAVE_PARAM,"Slave"),1,"","");
00604 dia.newf_str (MSG_U(F_DB_UPDATEDN,"Update DN"),updatedn);
00605
00606 dia.newf_title (MSG_U(I_ACL_PARAM,"ACL"),1,"","");
00607 dia.newf_info ("","Simple ACL config only");
00608 dia.newf_chk (MSG_U(F_ACL_SELFWRITE,"Add ACL to allow writing SELF object"),acl_selfwrite,"");
00609
00610 dia.newf_title (MSG_U(I_ACCESS_PARAM,"Attributes"),1,"","");
00611 dia.newf_info ("","Not done");
00612
00613 dia.newf_title (MSG_U(I_INDEXES_PARAM,"Indexes"),1,"","");
00614 dia.newf_info ("","Simple index config only");
00615 dia.newf_chk (MSG_U(F_INDEX_NSS,"Add indexes to improve NSS performance"),index_nss,"");
00616
00617 dia.setbutinfo (MENU_USR1,MSG_U(B_EXPORT,"Export")
00618 ,MSG_U(X_EXPORT,"Export"));
00619 dia.setbutinfo (MENU_USR2,MSG_U(B_IMPORT,"Import")
00620 ,MSG_U(X_IMPORT,"Import"));
00621 /* Dialog */
00622 int nof = 0;
00623 while (1){
00624 MENU_STATUS code = dia.edit (MSG_U(T_DATABASE_MENU,"LDAP database")
00625 ,MSG_U(I_DATABASE_MENU
00626 ,"Here you may configure a LDAP directory.\n"
00627 "Currently ldapconf will save directory setting in individual files,\n"
00628 "and then include this files in the main slapd.conf file.\n"
00629 "You may still have database settings in the main file,\n"
00630 "but ldapconf will not operate on those.")
00631 ,help_ldap
00632 ,nof
00633 ,MENUBUT_ACCEPT|MENUBUT_CANCEL);
00634
00635 /* Exit */ if (code == MENU_CANCEL || code == MENU_ESCAPE){
00636 break;
00637 }
00638 /* Export */ else if (code == MENU_USR1){
00639 export_ldif();
00640 }
00641 /* Import */ else if (code == MENU_USR2){
00642 import_ldif();
00643 }
00644 /* Save */ else if (code == MENU_ACCEPT){
00645 set_keyval(v_db_conf,"database",database.get());
00646 set_keyval(v_db_conf,"suffix",bind.base.get());
00647 set_keyval(v_db_conf,"rootdn",bind.dn.get());
00648 set_keyval(v_db_conf,"rootpw",bind.pw.get());
00649 set_keyval(v_db_conf,"directory",directory.get());
00650 set_keyval(v_db_conf,"readonly",readonly.get());
00651 set_keyval(v_db_conf,"lastmod",lastmod.get());
00652 set_keyval(v_db_conf,"replogfile",replogfile.get());
00653 set_keyval(v_db_conf,"replica",replica.get());
00654 set_keyval(v_db_conf,"updatedn",updatedn.get());
00655 set_keyval(v_db_conf,"schemacheck",schemacheck.get());
00656 set_keyval(v_db_conf,"loglevel",loglevel.get());
00657 set_keyval(v_db_conf,"defaultaccess",defaultaccess.get());
00658 set_keyval(v_db_conf,"referral",referral.get());
00659
00660 if (acl_selfwrite){ // ACL
00661 v_db_conf.add(new VIEWITEM("access to attr=userpassword by self write by * compare"));
00662 v_db_conf.add(new VIEWITEM("access to * by self write"));
00663 }
00664 if (index_nss) { // INDEX
00665 v_db_conf.add(new VIEWITEM("index objectclass,uid,uidNumber,gidNumber\teq"));
00666 v_db_conf.add(new VIEWITEM("index cn,mail,surname,givenname\teq,subinitial"));
00667 }
00668
00669 CONFIG_FILE f_db_conf_save (path,
00670 help_ldap,
00671 CONFIGF_OPTIONNAL|CONFIGF_MANAGED,
00672 mode_slapd_user.get(),
00673 mode_slapd_group.get(),
00674 0400,
00675 subsys_ldap);
00676 v_db_conf.write (f_db_conf_save,&p_ldap_admin);
00677 if (enable_database && !was_enabled) {
00678 char buf[1000];
00679 VIEWITEM *it;
00680 sprintf(buf,"%s %s","include",path);
00681 it = new VIEWITEM(buf);
00682 v_slapd_conf.add(it); /* add db entry */
00683 logf(LOG_NOTICE,"Enabling database profile %s",path);
00684 }
00685 else if (was_enabled && !enable_database) {
00686 inc_item->line.setfrom(""); /* remove db entry */
00687 logf(LOG_NOTICE,"Disabling database profile %s",path);
00688 }
00689
00690 v_slapd_conf.write(f_slapd_conf,&p_ldap_admin);
00691
00692 // Confirm server restart (needed for activation, but restart may fail if something is wrong)
00693 if (xconf_yesno(MSG_U(T_SERVER_RESTART_OK,"Confirm server restart"),
00694 MSG_U(I_SERVER_RESTART_OK,
00695 "To activate the changes, the server must be restarted.\n"
00696 "But be aware that if anything is wrong in the new configuration\n"
00697 "the server may refuse to start. This may be critical if the server\n"
00698 "is publishing production critical directory data to clients.\n"
00699 "Do you want to restart the server now?\n"
00700 ),
00701 help_ldap) == MENU_YES){
00702 sys_command_title ("Server restart","slapd.init","restart");
00703 }
00704 break;
00705 }
00706 }
00707 }
|
|
|
Definition at line 206 of file ldap_db.cc. Referenced by menu(). 00207 {
00208 int ret=0;
00209 char domain[PATH_MAX];
00210 char conffile[PATH_MAX];
00211 SSTRINGS dc_lst;
00212 LDAPOBJECT ldap;
00213 char profile_name[PATH_MAX];
00214
00215 // Default database init
00216 char add_suffixobject = true;
00217 char add_peopleobject = true;
00218 char add_groupobject = true;
00219 char gen_manager_profile = true;
00220
00221 sprintf (conffile,"%s/%s%s",DBCONF_DIR,name.get(),DBCONF_SUFFIX);
00222
00223 // Compute DNS domain
00224 strcpy(domain,bind.base.get());
00225 dc2list(domain,dc_lst); // DC list
00226 dc2dns(domain,sizeof(domain));
00227
00228 int nof;
00229
00230 DIALOG dia;
00231
00232 dia.newf_chk (MSG_U(F_ADD_DC_DOMAIN,"Add domain DC objects"),add_suffixobject,"Domain");
00233 dia.newf_chk (MSG_U(F_ADD_OU_PEOPLE,"Add people OU object"),add_peopleobject,"People");
00234 dia.newf_chk (MSG_U(F_ADD_OU_GROUP,"Add group OU object"),add_groupobject,"Group");
00235 dia.newf_chk (MSG_U(F_GEN_MANAGER_PROFILE,"Generate manager profile"),gen_manager_profile,"Manager");
00236
00237 while (1){
00238 MENU_STATUS code = dia.edit (MSG_U(T_CREATE,"Create")
00239 ,MSG_U(I_CREATE
00240 ,"This will init a new database.")
00241 ,help_ldap
00242 ,nof);
00243 if (code == MENU_CANCEL || code == MENU_ESCAPE){
00244 break;
00245 }
00246 else if (code == MENU_ACCEPT){
00247 char path[PATH_MAX];
00248 CONFIG_FILE *f_profile;
00249 CONFDB *c_profile;
00250
00251 if (gen_manager_profile==true) { // Generate a manager profile for this directory
00252
00253 sprintf(profile_name,"%s-manager",name.get());
00254
00255 // Generate bind profile
00256 sprintf(path,"%s/%s",DBBIND_DIR,profile_name);
00257 f_profile = new CONFIG_FILE (path,
00258 help_ldap,
00259 CONFIGF_MANAGED|CONFIGF_OPTIONAL,
00260 "root","root",0600);
00261 c_profile = new CONFDB(*f_profile);
00262
00263 c_profile->replace("ldap","base",bind.base.get());
00264 c_profile->replace("ldap","host","localhost");
00265 c_profile->replace("ldap","binddn",bind.dn.get());
00266 c_profile->replace("ldap","bindpw",bind.pw.get());
00267
00268 c_profile->save();
00269
00270 delete c_profile;
00271 delete f_profile;
00272
00273 // Generate directory profile
00274 sprintf(path,"%s/%s",PROFILE_DIR,name.get());
00275 f_profile = new CONFIG_FILE (path,
00276 help_ldap,
00277 CONFIGF_MANAGED|CONFIGF_OPTIONAL,
00278 "root","root",0600);
00279 c_profile = new CONFDB(*f_profile);
00280
00281 c_profile->replace("profile","bind",profile_name);
00282
00283 char buf[100];
00284 sprintf(buf,"Manager profile for directory %s",name.get());
00285 c_profile->replace("profile","comment",buf);
00286
00287 c_profile->save();
00288
00289 delete c_profile;
00290 delete f_profile;
00291 }
00292 else {
00293 // Need a profile with full access for online init
00294 // TODO: Add a root manager (with full access to all server directories) to samples
00295 sprintf(profile_name,"%s","root-manager");
00296 }
00297
00298 SSTRING line;
00299 if (add_suffixobject==true) {
00300 ldap.load_profile(name.get());
00301
00302 ldap.dn.setfromf("dn: %s",bind.base.get());
00303 ldap.at_add("dc",dc_lst.getitem(0)->get());
00304 ldap.oc_add("top");
00305 ldap.oc_add("domain");
00306 ldap.oc_add("domainRelatedObject");
00307 ldap.at_add("associatedDomain",domain);
00308
00309 ldap.add();
00310 }
00311 if (add_peopleobject==true) {
00312 ldap.load_profile(name.get());
00313 ldap.reset_data();
00314
00315 ldap.dn.setfromf("dn: ou=People,%s",bind.base.get());
00316 ldap.at_add("ou","People");
00317 ldap.oc_add("top");
00318 ldap.oc_add("organizationalUnit");
00319 ldap.oc_add("domainRelatedObject");
00320 ldap.at_add("associatedDomain",domain);
00321
00322 ldap.add();
00323 }
00324 if (add_groupobject==true) {
00325 ldap.load_profile(name.get());
00326 ldap.reset_data();
00327
00328 ldap.dn.setfromf("dn: ou=Group,%s",bind.base.get());
00329 ldap.at_add("ou","Group");
00330 ldap.oc_add("top");
00331 ldap.oc_add("organizationalUnit");
00332 ldap.oc_add("domainRelatedObject");
00333 ldap.at_add("associatedDomain",domain);
00334
00335 ldap.add();
00336 }
00337
00338 /*
00339 if (add_suffixobject==true) {
00340 fprintf (fout,"dn: %s\n",bind.base.get());
00341 for (int i=0;i<dc_lst.getnb();i++){
00342 fprintf (fout,"dc: %s\n",dc_lst.getitem(i)->get());
00343 }
00344 fprintf (fout,"objectClass: top\n");
00345 fprintf (fout,"objectClass: domain\n");
00346 fprintf (fout,"objectClass: domainRelatedObject\n");
00347 fprintf (fout,"associatedDomain: %s\n\n",domain);
00348 }
00349 if (add_peopleobject==true) {
00350 fprintf (fout,"dn: ou=People,%s\n",bind.base.get());
00351 fprintf (fout,"ou: People\n");
00352 fprintf (fout,"objectClass: top\n");
00353 fprintf (fout,"objectClass: organizationalUnit\n");
00354 fprintf (fout,"objectClass: domainRelatedObject\n");
00355 fprintf (fout,"associatedDomain: %s\n\n",domain);
00356 }
00357 if (add_groupobject==true) {
00358 fprintf (fout,"dn: ou=Group,%s\n",bind.base.get());
00359 fprintf (fout,"ou: Group\n");
00360 fprintf (fout,"objectClass: top\n");
00361 fprintf (fout,"objectClass: organizationalUnit\n");
00362 fprintf (fout,"objectClass: domainRelatedObject\n");
00363 fprintf (fout,"associatedDomain: %s\n\n",domain);
00364 }
00365 fprintf (fout,"\n");
00366 fclose (fout);
00367
00368 */
00369 /* Import into database */
00370 /*
00371 if (mode_openldap_version == 2) { // OpenLDAP 2.x
00372 sprintf (arg,"-l %s -f %s",tmpfile,conffile);
00373 // make sure the directory holding the database exist
00374 file_mkdirp (directory.get(),SLAPD_USER,SLAPD_GROUP,0700);
00375 sys_command_title("DB create","slapadd",arg);
00376 }
00377 else { // OpenLDAP 1.x
00378 sprintf (arg,"-i %s -f %s",tmpfile,conffile);
00379 // make sure the directory holding the database exist
00380 file_mkdirp (directory.get(),0,0,0700);
00381 sys_command_title("DB create","ldif2ldbm",arg); // OpenLDAP 1.x
00382 */
00383 break;
00384 }
00385 }
00386 return ret;
00387 }
|
|
|
Definition at line 144 of file ldap_db.cc. 00145 {
00146 int ret=0;
00147 char path [PATH_MAX];
00148 sprintf(path,"/tmp/%s.ldif",profile_name);
00149 int nof;
00150
00151 SSTRING export_file(path);
00152 SSTRING export_filter("objectclass=*");
00153 SSTRING export_attributes("");
00154
00155 SSTRINGS data;
00156 LDAPOBJECT ldap;
00157
00158 DIALOG dia;
00159
00160 dia.newf_str (MSG_U(F_EXPORT_FILE,"Filename"),export_file,40);
00161 dia.newf_str (MSG_U(F_EXPORT_FILTER,"Search filter"),export_filter);
00162 dia.newf_str (MSG_U(F_EXPORT_ATTR,"Attribute list"),export_attributes);
00163
00164 while (1){
00165 MENU_STATUS code = dia.edit (MSG_R(T_EXPORT_LDIF),
00166 MSG_U(I_EXPORT_LDIF_ONLINE,
00167 "Use this dialog to export data from the directory into the specified file.\n"
00168 "The default search filter will include all entries.\n"
00169 "The default (empty) attribute list will include all attributes."
00170 ),
00171 help_ldap,
00172 nof);
00173 if (code == MENU_CANCEL || code == MENU_ESCAPE){
00174 break;
00175 }
00176 else if (code == MENU_ACCEPT){
00177 // Setup
00178 ldap.load_profile(profile_name);
00179 ldap.filter.setfrom(export_filter.get());
00180 ldap.command_line = export_attributes;
00181 // Search
00182 ldap.command("ldapsearch",data);
00183
00184 int n = data.getnb();
00185
00186 // Write to file
00187 FILE *fout = fopen (export_file.get(),"w");
00188 if (fout != NULL){
00189 for (int i=0; i<n; i++){
00190 fprintf(fout,"%s",data.getitem(i)->get());
00191 }
00192 xconf_notice("Wrote %i lines of LDIF data to file",n);
00193 }
00194 else {
00195 xconf_error("File error");
00196 }
00197 break;
00198 }
00199 }
00200 return ret;
00201 }
|
|
|
Definition at line 104 of file ldap_db.cc. Referenced by config(), and menu(). 00105 {
00106 char include_indexnumber=true;
00107 int ret=0;
00108 char dbfile[PATH_MAX] = "";
00109 sprintf (dbfile,"%s/id2entry.dbb",directory.get());
00110 char exportfile [PATH_MAX] = "";
00111 sprintf (exportfile,"/tmp/%s.ldif",name.get());
00112 SSTRING filename(exportfile);
00113 int nof;
00114 DIALOG dia;
00115 dia.newf_str (MSG_U(F_EXPORT_LDIF_FILE,"LDIF Filename"),exportfile,40);
00116 dia.newf_chk ("",include_indexnumber,"Include index number ");
00117 while (1){
00118 MENU_STATUS code = dia.edit (MSG_U(T_EXPORT_LDIF,"LDIF Export")
00119 ,MSG_U(I_EXPORT_LDIF
00120 ,"This will export all entries from this database\n"
00121 "into a LDIF file.\n"
00122 "You must stop the server before you export using this dialog.")
00123 ,help_ldap
00124 ,nof);
00125 if (code == MENU_CANCEL || code == MENU_ESCAPE){
00126 break;
00127 }
00128 else if (code == MENU_ACCEPT){
00129 char arg[1000] = "";
00130 if (!include_indexnumber) {
00131 sprintf (arg,"-n");
00132 }
00133 sprintf (arg,"%s > %s",dbfile,exportfile);
00134 sys_command_title("LDIF Export","ldbmcat",arg);
00135 break;
00136 }
00137 }
00138 return ret;
00139 }
|
|
|
Definition at line 395 of file ldap_db.cc. Referenced by config(), and menu(). 00396 {
00397 int ret=0;
00398 char add_suffix=true;
00399 char add_suffixobject=true;
00400 char conffile[PATH_MAX] = "";
00401 sprintf (conffile,"%s/%s%s",DBCONF_DIR,name.get(),DBCONF_SUFFIX);
00402 char importfile [PATH_MAX] = "";
00403 sprintf (importfile,"/tmp/%s.ldif",name.get());
00404 SSTRING filename(importfile);
00405 SSTRING profile;
00406 int nof;
00407
00408 LDAPOBJECT ldap;
00409
00410 profile.setfrom(name.get());
00411
00412 DIALOG dia;
00413
00414 dia.newf_str (MSG_U(F_IMPORT_LDIF_FILE,"LDIF Filename"),importfile,40);
00415 dia.newf_str (MSG_U(F_IMPORT_LDIF_PROFILE,"Use directory profile"),profile,40);
00416 dia.newf_chk ("Add domainsuffix to DN attributes",add_suffix,"DN Suffix ");
00417 dia.newf_chk ("Add domainobject to database",add_suffixobject,"DB Suffix");
00418 while (1){
00419 MENU_STATUS code = dia.edit (MSG_U(T_IMPORT_LDIF,"LDIF Import")
00420 ,MSG_U(I_IMPORT_LDIF
00421 ,"Import entries from LDIF file into directory")
00422 ,help_ldap
00423 ,nof);
00424 if (code == MENU_CANCEL || code == MENU_ESCAPE){
00425 break;
00426 }
00427 else if (code == MENU_ACCEPT){
00428
00429 ldap.load_profile(profile.get());
00430
00431 // Parse all input data, manipulate if needed, and write to tmp file
00432 FILE *fin = fopen(importfile,"r");
00433 FILE *fout = fopen(ldap.ldapconf_entry,"w");
00434 if ((fin != NULL)) {
00435 SSTRING line;
00436 char buf[1000];
00437 int n=0;
00438
00439 if (add_suffixobject==true) {
00440 // Add domain object
00441 fprintf (fout,"dn: %s\n",bind.base.get());
00442 fprintf (fout,"%s\n",bind.base.get());
00443 fprintf (fout,"objectclass: top\n");
00444 fprintf (fout,"objectclass: domain\n");
00445 fprintf (fout,"\n");
00446 }
00447
00448 while (fgets(buf,sizeof(buf)-1,fin)!=NULL){
00449 strip_end(buf);
00450 line.setfrom(buf);
00451 if (line.strstr("dn:")){ // DN entry
00452 n++; // Count it
00453 if (add_suffixobject==true){ // Add domain suffix to DN
00454 line.appendf(",%s",bind.base.get());
00455 }
00456 D(debugf(5,"Adding object count=%i %s",n,line.get()));
00457 }
00458 fprintf (fout,"%s\n",line.get());
00459 }
00460 fclose (fin);
00461 fclose (fout);
00462
00463 // Now add the new ldif file to the directory
00464 // TODO: Move this to ldap_object as a new importfile method
00465 ldap.command_line.setfrom(" -a"); // Add
00466 ldap.command_line.appendf(" -f %s",ldap.ldapconf_entry); // Entry
00467 SSTRINGS resmsg;
00468 ret = ldap.command ("ldapmodify",resmsg);
00469 unlink(ldap.ldapconf_entry);
00470 logf(LOG_NORMAL,"Importing LDIF file %s using profile %s",importfile,profile.get());
00471 }
00472 break;
00473 }
00474 }
00475 return ret;
00476
00477 /*
00478
00479 char tmpfile[PATH_MAX] = "/tmp/import.ldif.tmp";
00480 FILE *fin = fopen(importfile,"r");
00481 FILE *fout = fopen (tmpfile,"w");
00482 if ((fin != NULL)&&(fout != NULL)) {
00483 char buf[1000];
00484 SSTRING line;
00485 if (add_suffixobject==true) {
00486 fprintf (fout,"dn: %s\n",bind.base.get());
00487 fprintf (fout,"%s\n",bind.base.get());
00488 fprintf (fout,"objectclass: top\n");
00489 fprintf (fout,"objectclass: domain\n");
00490 }
00491 fprintf (fout,"\n");
00492 while (fgets(buf,sizeof(buf)-1,fin)!=NULL){
00493 strip_end(buf);
00494 line.setfrom(buf);
00495 // xconf_notice(buf);
00496 if ((line.strstr("dn:")!=NULL)&&(add_suffixobject==true))
00497 char newdn[ATTR_VAL_MAX];
00498 snprintf(newdn,ATTR_VAL_MAX,",%s",bind.base.get());
00499 line.append(newdn);
00500 }
00501 fprintf (fout,"%s\n",line.get());
00502 }
00503 fclose (fout);
00504 fclose (fin);
00505
00506 if (mode_openldap_version == 2) { // OpenLDAP 2.x
00507 sprintf (arg,"-l %s -f %s",tmpfile,conffile);
00508 // make sure the directory holding the database exist
00509 file_mkdirp (directory.get(),SLAPD_USER,SLAPD_GROUP,0700);
00510 sys_command_title("LDIF import","slapadd",arg);
00511 }
00512 else { // OpenLDAP 1.x
00513 sprintf (arg,"-i %s -f %s",tmpfile,conffile);
00514 // make sure the directory holding the database exist
00515 file_mkdirp (directory.get(),0,0,0700);
00516 sys_command_title("LDIF import","ldif2ldbm",arg); // OpenLDAP 1.x
00517 }
00518 }
00519
00520 */
00521
00522 }
|
|
|
Definition at line 34 of file ldap_db.cc. Referenced by ldap_db_select(). 00035 {
00036 int ret = 0;
00037
00038 // Get fqdn and convert it to internet style suffix
00039 char buf[256];
00040 gethostname(buf,sizeof(buf));
00041 dns2dc(buf,sizeof(buf),1);
00042
00043 // Set initial config
00044 bind.base.setfrom(buf);
00045 bind.dn.setfromf ("cn=manager,%s",buf);
00046 bind.pw.setfrom ("secret");
00047 database.setfrom ("ldbm");
00048 directory.setfromf ("%s/%s",OPENLDAP_DATA_DIR,dbname);
00049 replogfile.setfromf ("%s/%s/%s.log",OPENLDAP_DATA_DIR,dbname,dbname);
00050 updatedn.setfrom ("");
00051 replica.setfrom ("");
00052 lastmod.setfrom ("off");
00053 readonly.setfrom ("off");
00054 schemacheck.setfrom("on");
00055 defaultaccess.setfrom("none");
00056 loglevel.setfrom("0");
00057
00058 // Create directory
00059 file_mkdirp(directory.get(),
00060 mode_slapd_user.get(),
00061 mode_slapd_group.get(),
00062 0700);
00063 return ret;
00064 }
|
|
|
Definition at line 712 of file ldap_db.cc. Referenced by ldap_db_select(). 00713 {
00714 const char *config_key = MSG_U(M_DB_CONFIG,"Configure directory");
00715 const char *create_key = MSG_U(M_DB_CREATE,"Init a new empty directory");
00716 const char *export_key = MSG_U(M_DB_EXPORT,"Export from directory to LDIF file");
00717 const char *import_key = MSG_U(M_DB_IMPORT,"Import from LDIF file to directory");
00718 const char *migrate_key = MSG_U(M_DB_MIGRATE,"Migrate from system to directory");
00719
00720 DIALOG_MENU dia;
00721 dia.new_menuinfo("Directory name",name.get());
00722 dia.new_menuitem("Config",config_key);
00723 dia.new_menuitem("Init",create_key);
00724 dia.new_menuitem("Export LDIF",export_key);
00725 dia.new_menuitem("Import LDIF",import_key);
00726 dia.new_menuitem("Import users",migrate_key);
00727
00728 int nof = 0;
00729 while (1){
00730 MENU_STATUS code = dia.editmenu (MSG_U(T_DB_MENU,"Directory menu")
00731 ,MSG_U(I_DB_MENU,"Select operation to perform on this directory")
00732 ,help_ldap
00733 ,nof,0);
00734 const char *key = dia.getmenustr(nof);
00735
00736 if (code == MENU_ESCAPE || code == MENU_QUIT){
00737 break;
00738 }else{
00739 if (key == config_key){
00740 config(name.get());
00741 }else if (key == export_key){
00742 export_ldif(name.get());
00743 }else if (key == import_key){
00744 import_ldif();
00745 }else if (key == migrate_key){
00746 ldap_migrate_users(name.get());
00747 }else if (key == create_key){
00748 create();
00749 }
00750 }
00751 }
00752 }
|
|
|
Definition at line 66 of file ldap_db.cc. Referenced by ldap_db_select(). 00067 {
00068 int ret = 0;
00069 VIEWITEMS v_db_conf;
00070 char path[PATH_MAX] = "";
00071 sprintf (path,"%s/%s%s",DBCONF_DIR,dbname,DBCONF_SUFFIX);
00072 CONFIG_FILE f_db_conf (path,
00073 help_ldap,
00074 CONFIGF_OPTIONNAL|CONFIGF_MANAGED,
00075 mode_slapd_user.get(),
00076 mode_slapd_group.get(),
00077 0400,
00078 subsys_ldap);
00079
00080 name.setfrom (dbname);
00081 /* Read config */
00082 v_db_conf.read (f_db_conf);
00083 bind.base.setfrom (get_keyval(v_db_conf,"suffix"));
00084 bind.dn.setfrom (get_keyval(v_db_conf,"rootdn"));
00085 bind.pw.setfrom (get_keyval(v_db_conf,"rootpw"));
00086 database.setfrom (get_keyval(v_db_conf,"database"));
00087 directory.setfrom (get_keyval(v_db_conf,"directory"));
00088 replogfile.setfrom (get_keyval(v_db_conf,"replogfile"));
00089 updatedn.setfrom (get_keyval(v_db_conf,"updatedn"));
00090 replica.setfrom (get_keyval(v_db_conf,"replica"));
00091 lastmod.setfrom (get_keyval(v_db_conf,"lastmod"));
00092 readonly.setfrom (get_keyval(v_db_conf,"readonly"));
00093 schemacheck.setfrom (get_keyval(v_db_conf,"schemacheck"));
00094 loglevel.setfrom (get_keyval(v_db_conf,"loglevel"));
00095 defaultaccess.setfrom (get_keyval(v_db_conf,"defaultaccess"));
00096 referral.setfrom (get_keyval(v_db_conf,"referral"));
00097
00098 return ret;
00099 }
|
|
|
Definition at line 121 of file ldapconf_defs.h. |
|
|
Definition at line 122 of file ldapconf_defs.h. |
|
|
Definition at line 123 of file ldapconf_defs.h. |
|
|
Definition at line 124 of file ldapconf_defs.h. |
|
|
Definition at line 125 of file ldapconf_defs.h. |
|
|
Definition at line 126 of file ldapconf_defs.h. |
|
|
Definition at line 127 of file ldapconf_defs.h. |
|
|
Definition at line 128 of file ldapconf_defs.h. |
|
|
Definition at line 129 of file ldapconf_defs.h. |
|
|
Definition at line 130 of file ldapconf_defs.h. |
|
|
Definition at line 131 of file ldapconf_defs.h. |
|
|
Definition at line 132 of file ldapconf_defs.h. |
|
|
Definition at line 133 of file ldapconf_defs.h. |
|
|
Definition at line 134 of file ldapconf_defs.h. |
|
|
Definition at line 135 of file ldapconf_defs.h. |
|
|
Definition at line 136 of file ldapconf_defs.h. |
|
|
Definition at line 137 of file ldapconf_defs.h. |
1.2.1 written by Dimitri van Heesch,
© 1997-2000