#include #include "fields.h" #include "ldapconf_defs.h" #include "ldapconf.h" #include "ldapconf.m" void ldap_userlist(const char *profile_name) { const char *profile_name; LDAPOBJECT *ldap; FIELD_DEFS *defs; SSTRINGS users; glocal.profile_name = profile_name; LDAPOBJECT ldap (profile_name); glocal.ldap = &ldap; ldap.filter.setfromf("%s=*",ldap.primary_key.get()); ldap.search_base.setfromf("%s,%s",ldap.dn_prefix.get(),ldap.bind.base.get()); FIELD_DEFS defs(ldap.form); glocal.defs = &defs; defs.read(); (MSG_U(T_USER_LIST,"Users") ,MSG_U(I_USER_LIST,"Select user"),help_nil); SSTRING h; for (int i=0; igetnb(); i++){ FIELD_DEF *f = glocal.defs->getitem(i); if (f->browse){ if (h.is_filled()) h.append ("\t"); h.append (f->title); } } newf_head (h.get()); sortable(); sortpolicy ("a"); addwhat (MSG_U(I_NEWREC,"Use the [Add] button to add a new record")); int nba = 0; int nb = glocal.defs->getnb(); const char *atname[nb+1]; for (int i=0; igetitem(i); if (f->browse){ atname[nba++] = f->id.get(); logf(LOG_WARNING,"atname[]=%s",f->id.get()); } } logf(LOG_WARNING,"nba=%d nb=%d",nba,nb); atname[nba] = NULL; glocal.users.remove_all(); SSTRINGS lines; glocal.ldap->search_list_vals(lines,glocal.ldap->primary_key.get() ,atname); for (int i=0; iget(); // line contains the list of attributes attribute : value\tattribute2: value2.... // as we don't know the order, we have to look for value before we know which attribute to get str_splitline(line,'\t',tb); // tb is a table containing SSTRING of the form attribute: value // looking for the attribute corresponding to uid const char *key = getldapattribute(tb,atname[0]); if (key == NULL) { logf(LOG_WARNING,"%s not found for user!!! list index=%i",atname[0],i); continue ; // really bad ! it should not happen // we're going to the next user } glocal.users.add (new SSTRING(key)); char data[2000]=""; int ll=0; for (int k=1; k ldap_form_edituser(glocal.profile_name,glocal.users.getitem(no)->get()); ldap_form_adduser(glocal.profile_name,NULL); } #if 0 /* LDAPCLIENT userlist */ void ldap_userlist(const char *profile_name) { D(debugf(4,"-->USERADMIN::ldap_userlist (%s)",profile_name)); SSTRING form_key; SSTRINGS user_list; LDAPOBJECT ldap(profile_name); int NB_USERLIST_ATNAME=3; const char *atname[NB_USERLIST_ATNAME+1]; atname[0] = "cn"; atname[1] = "uidnumber"; atname[2] = "telephonenumber"; atname[3] = NULL; dia.newf_head ("",MSG_U(H_USERS,"User\tName\tUID\tPhone")); // ie in ldap : uid\tcn\tuidNumber\ttelephoneNumber SSTRING *key; int MAX_DATA=2048; char data [2048]; SSTRINGS tb; int nof = 0; while (1) { // Find all users user_list.remove_all(); ldap.search_list_vals(user_list,ldap.primary_key.get(),atname); user_list.sort(); // we're going through the user list for (int i=0; iget(); // line contains the list of attributes attribute : value\tattribute2: value2.... // as we don't know the order, we have to look for value before we know which attribute to get str_splitline(line,'\t',tb); // tb is a table containing SSTRING of the form attribute: value D(debugf(6,"i=%d, userlist: %s\n",i,line)); // looking for the attribute corresponding to uid key = getldapattribute(&tb,"uid"); if (!key) { logf(LOG_WARNING,"uid not found for user!!! list index=%i",i); continue ; // really bad ! it should not happen // we're going to the next user } D(debugf(6,"i=%d, key: %s\n",i,key->get())); strcpy(data,""); int ll=strlen(data); D(debugf(6,"i=%d, ll=%d,data = %s\n",i,ll,data)); for (int k=0; k<=NB_USERLIST_ATNAME; k++) { if (!atname[k]) continue; //next one ll=strlen(data); D(debugf(6,"i=%d, k=%d, looking for supplemental attribute: %s\n",i,k,atname[k])); SSTRING * attr=getldapattribute(&tb,atname[k]); if (!attr) { // ok attribute not present D(debugf(6,"i=%d, k=%d, attribute not found\n",i,k)); strncat(data,"\t",MAX_DATA-ll); continue; // going to next attribute } // we have the attribute content in attr D(debugf(6,"i=%d, k=%d, attribute found\n",i,k)); strncat(data,attr->get(),MAX_DATA-ll); strncat(data,"\t",MAX_DATA-ll-1); D(debugf(6,"i=%d, ik=%d, data = %s\n",i,k,data)); } // ok we have all the values added to data D(debugf(6,"i=%d, got all data,setting menu entry and going to next user%s\n",i,data)); dia.set_menuitem (i,key->get(),data); } dia.remove_last(user_list.getnb()+1); MENU_STATUS code = dia.editmenu (MSG_R(T_USER_LIST) ,MSG_R(I_USER_LIST) ,help_groupadmin ,nof ,MENUBUT_ADD); if (code == MENU_QUIT || code == MENU_ESCAPE){ /* Exit */ break; } else if (code == MENU_ADD ){ /* Add a new entry */ ldap_form_adduser(profile_name,NULL); } else if (nof >=0 && nof < user_list.getnb()){ /* Edit selected entry */ const char *line; line = user_list.getitem(nof)->get(); char *pt; pt = strchr(line,'\t'); // 2.x if (pt != NULL){ *pt = '\0'; } // line now contains uid entry, now extract the uid name char name[ATTR_NAME_MAX]; char val[ATTR_VAL_MAX]; ldap.ldif_splitline(line,name,val); ldap_form_edituser(profile_name,val); } } D(debugf(4,"<--USERADMIN::ldap_userlist")); } #endif