1 /*_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
5 * Function:..WorldWideWeb-X.500-Gateway - X.500-Access-Routines *
6 * Based on web500gw.c 1.3 written by Frank Richter, TU Chemmniz *
7 * which is based on go500gw by Tim Howes, University of *
8 * Michigan - All rights reserved *
10 * Authors:...Dr. Kurt Spanier & Bernhard Winkler, *
11 * Zentrum fuer Datenverarbeitung, Bereich Entwicklung *
12 * neuer Dienste, Universitaet Tuebingen, GERMANY *
15 * Creation date: Z D D V V *
16 * August 16 1995 Z D D V V *
17 * Last modification: Z D D V V *
18 * September 13 1999 ZZZZZ DDD V *
20 _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_*/
23 * $Id: x500.c,v 1.10 1999/09/13 13:47:48 zrnsk01 Exp $
31 #include "support_exp.h"
35 #include "tueTel_exp.h"
38 #if defined( TUE_TEL ) || defined( AMBIXGW )
39 #include "resort_exp.h"
43 PRIVATE int compare(a,b)
46 return strcmp((*a)->string,(*b)->string);
48 /* end of function: compare */
51 PRIVATE char * pick_oc(oclist)
59 for ( i = 0; oclist[i] != NULL; i++ ) {
60 if ( strcasecmp( oclist[i], "top" ) != 0 &&
61 strcasecmp( oclist[i], "quipuObject" ) != 0 &&
62 strcasecmp( oclist[i], "quipuNonLeafObject" ) != 0 )
63 return( str_tolower (oclist[i]) );
68 /* end of function: pick_oc */
71 PUBLIC char * make_oc_to_string(oc)
74 static char oc_res[BUFSIZ];
81 for(i = 0; oc[i] && *oc[i]; i++) {
82 sprintf(oc_res, "%s%s|", oc_res, oc[i]);
84 return(str_tolower (oc_res));
86 /* end of function: make_oc_to_string */
89 PUBLIC void do_xtend(ld, fp, query, filter, glob)
96 char *strptr, dn[BUFSIZ], command[BUFSIZ], extension[BUFSIZ];
98 strptr = strchr(query, '?');
101 strcpy(command, strptr);
102 if( ( strptr = strchr(command, '#')) ) {
104 strcpy(extension, strptr);
107 if(!strcasecmp(command, "MENU")){
108 glob->tables_marker = strdup(extension);
109 do_menu(ld, fp, dn, "", glob);
113 if(!strcasecmp(command, "PHONEBOOK")){
114 do_phonebook(ld, fp, strstr(dn, "ou=TELEFONBUCH") ? dn
115 : NULL, extension, glob, 1);
120 /* end of function: do_xtend */
122 PUBLIC void do_menu(ld, fp, dn, filter, glob)
131 struct timeval timeout;
132 static char *sattrs[] = { "objectClass", "labeledURI",
133 "aliasedObjectName", "mail",
134 "cn", "telephonenumber",
136 "tat_ton", "tat_refphone",
139 static char **attrs = NULL;
141 pSEARCH_ONLY_LINE so_ptr;
151 attrs = (char**) charray_dup(sattrs);
153 charray_merge(&attrs, glob->sort_attribs);
156 charray_merge(&attrs, glob->raw_attrs);
158 for(so_ptr = glob->search_only; so_ptr; so_ptr = so_ptr->next) {
159 if (dn_cmp(dn, so_ptr->dn) == 0) {
166 timeout.tv_sec = glob->timeout;
171 ldap_opt = LDAP_DEREF_FINDING;
172 ldap_set_option( ld, LDAP_OPT_DEREF, &ldap_opt );
175 ld->ld_deref = LDAP_DEREF_FINDING;
178 if ( (rc = ldap_search_st( ld, dn, LDAP_SCOPE_ONELEVEL,
179 glob->menu_filter, attrs, 0, &timeout, &pres )) != LDAP_SUCCESS
180 && rc != LDAP_SIZELIMIT_EXCEEDED
181 && rc != LDAP_INSUFFICIENT_ACCESS ) {
182 do_error(fp, rc, NOT_FOUND, glob);
186 if (rc == LDAP_SIZELIMIT_EXCEEDED) glob->persRestricted = TRUE;
190 ldap_opt = LDAP_DEREF_ALWAYS;
191 ldap_set_option( ld, LDAP_OPT_DEREF, &ldap_opt );
194 ld->ld_deref = LDAP_DEREF_ALWAYS;
197 if ((count = (ldap_count_entries(ld, pres) )) < 1) {
199 do_read (ld, fp, dn, 0, glob);
202 items_displayed = count;
208 if (request == HEAD) {
212 fprintf( fp, HTML_HEAD_TITLE, ufn = friendly_dn(dn, glob), glob->la[100]);
213 if ( ufn ) free( ufn );
215 if (dn_cmp(dn, glob->basedn->dn) == 0)
216 disp_file(glob, glob->basedn->head, fp);
217 else if(so_ptr && so_ptr->head)
218 disp_file(glob, so_ptr->head, fp);
220 disp_file(glob, glob->header, fp);
223 fprintf (fp, "\n<A NAME=\"phonebook=Telefonbuch\"></A>\n");
224 fprintf (fp, "\n<A NAME=\"phonebook\"></A>\n");
227 make_la_buttons("M", fp, ld, dn, la_url, glob );
229 make_header( fp, dn, 0, glob);
231 print_rdn(fp, dn, glob);
233 make_search_box(fp, ld, dn, glob);
236 /* Button leading to cgi-script */
237 if( glob->form_button && !glob->selbsteintrag[0]){
240 struct timeval timeout;
241 static char *attrs[] = { "objectClass", 0 };
243 timeout.tv_sec = glob->timeout;
245 if ( ldap_search_st( ld, dn, LDAP_SCOPE_BASE, "objectClass=*",
246 attrs, 0, &timeout, &res ) != LDAP_SUCCESS ) {
249 oc = ldap_get_values( ld, ldap_first_entry( ld, res ), "objectClass" );
251 disp_form_button(0, oc, dn, ld, fp, glob);
254 /* check to see if selfinsert-buttons are appropriate here */
255 if(glob->selbsteintrag[0])
256 self_insert(ld,fp,dn,glob);
260 /* Named link to skip header */
261 fprintf (fp, "\n<A NAME=\"pure-data\"></A>\n");
264 fprintf(fp, glob->la[101]);
270 counter = sort_result( ld, pres, dn, glob);
272 /* get time for performance log */
273 gettimeofday(×tore[4], NULL);
275 list_output(fp, glob);
277 if ( ldap_result2error( ld, pres, 1 ) == LDAP_SIZELIMIT_EXCEEDED
278 || glob->restricted )
279 do_sizelimit(fp, 1, glob);
281 if(glob->legal && !glob->legal_top)
282 fprintf (fp, "%s\n%s\n", glob->la[101],
283 glob->is_proxy ? glob->la[104] : glob->la[65]);
286 if (dn_cmp(dn,glob->basedn->dn) == 0)
287 disp_file(glob, glob->basedn->foot, fp);
288 else if(so_ptr && so_ptr->foot)
289 disp_file(glob, so_ptr->foot, fp);
291 disp_file(glob, glob->footer, fp);
295 /* end of function: do_menu */
298 PRIVATE int make_scope(ld, dn, glob)
306 struct timeval timeout;
307 static char *attrs[] = { "objectClass", 0 };
309 if ( strcmp( dn, "" ) == 0 )
310 return( LDAP_SCOPE_ONELEVEL );
312 timeout.tv_sec = glob->timeout;
314 if ( ldap_search_st( ld, dn, LDAP_SCOPE_BASE, "objectClass=*",
315 attrs, 0, &timeout, &res ) != LDAP_SUCCESS ) {
319 oc = ldap_get_values( ld, ldap_first_entry( ld, res ), "objectClass" );
321 /* set scope according to configured object-classes */
322 scope = LDAP_SCOPE_ONELEVEL;
323 for(idx = 0; glob->subtree_search && glob->subtree_search[idx]; idx++)
324 if( charray_inlist( oc, glob->subtree_search[idx]))
325 scope = LDAP_SCOPE_SUBTREE;
327 ldap_value_free( oc );
332 /* end of function: make_scope */
334 PUBLIC int do_search(ld, fp, query, glob)
341 char *base, *filter, *strptr;
344 struct timeval timeout;
346 LDAPMessage *e, *res = NULL;
347 static char *attrs[] = { "objectClass", "cn", "sn", "labeledURI",
348 "aliasedObjectName", 0 };
351 char title[BUFSIZ], title2[BUFSIZ];
357 glob->no_browse = FALSE;
359 /* query string: base-DN?[OS]=filter
360 * search onelevel <--||--> search subtree
362 if ( (filter = strchr( query, '?' )) == NULL ) {
363 explain_error( fp, glob->la[89], BAD_REQUEST, glob );
367 if (*filter == '\0' || *(filter+1) != '=') {
368 explain_error( fp, glob->la[90], BAD_REQUEST, glob);
371 if( ( strptr = strchr(filter, '&')) )
373 if( ( strptr = strchr(filter, '*')) )
375 if (*filter == 'S') {
376 scope = LDAP_SCOPE_SUBTREE;
378 scope = LDAP_SCOPE_ONELEVEL;
381 if (*filter == '\0') {
382 explain_error( fp, glob->la[92], BAD_REQUEST, glob);
385 /* deutsche Umlaute plaetten */
386 filter = flatten_chars(filter);
390 filtertype = (scope == LDAP_SCOPE_ONELEVEL ? "web500gw onelevel" :
395 ldap_opt = ( scope == LDAP_SCOPE_ONELEVEL ? LDAP_DEREF_FINDING :
397 ldap_set_option( ld, LDAP_OPT_DEREF, &ldap_opt );
400 ld->ld_deref = (scope == LDAP_SCOPE_ONELEVEL ? LDAP_DEREF_FINDING :
404 timeout.tv_sec = glob->timeout;
407 for (fi=ldap_getfirstfilter( filtd, filtertype, filter ); fi != NULL;
408 fi = ldap_getnextfilter( filtd ) ) {
409 if ( (rc = ldap_search_st( ld, base, scope, fi->lfi_filter,
410 attrs, 0, &timeout, &res )) != LDAP_SUCCESS
411 && rc != LDAP_SIZELIMIT_EXCEEDED ) {
419 ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &ld_errno);
420 syslog (LOG_INFO, "ldap_search_st(): %s",
421 ldap_err2string ( ld_errno ));
424 syslog (LOG_INFO, "ldap_search_st(): %s",
425 ldap_err2string (ld->ld_errno));
430 do_error(fp, rc, NOT_FOUND, glob);
434 if ( res && (count = ldap_count_entries( ld, res )) != 0 ) {
440 items_displayed = count;
444 ldap_opt = LDAP_DEREF_ALWAYS;
445 ldap_set_option( ld, LDAP_OPT_DEREF, &ldap_opt );
448 ld->ld_deref = LDAP_DEREF_ALWAYS;
454 fprintf(fp, "HTTP/1.0 404 %s \n", glob->la[6]);
455 fprintf(fp, "MIME-Version: 1.0\n");
456 fprintf(fp, "Content-Type: text/html\n\n");
459 if (request == HEAD) {
464 sprintf( title, "%s %s", filter, glob->la[36]);
465 fprintf( fp, HTML_HEAD_TITLE, title, glob->la[100]);
467 disp_file(glob, glob->header, fp);
470 "<H2>%s</H2> %s <STRONG>%s</STRONG> in <STRONG>%s</STRONG></BODY></HTML>\n\n",
471 glob->la[37], glob->la[38], filter,
472 (strlen(base) == 0) ? glob->la[77] : ldap_dn2ufn(base));
476 else if ( count == 1 ) {
477 e = ldap_first_entry( ld, res );
480 oc = ldap_get_values(ld, e, "objectClass");
481 dn = ldap_get_dn(ld, e);
484 /* GW-Switch if one search-result and dyn-URL by
485 PRINT_REDIRECT_HEADER */
486 if ( glob->gw_switch->dynamic) {
487 char **uri, query[10*BUFSIZ];
490 uri = ldap_get_values( ld, e, "labeledURI" );
491 for(j=0; uri && uri[j] && *uri[j]; j++) {
494 if( ( sp = strchr(uri[j], ' ')) ) {
496 if(strstr(sp, glob->gw_switch->lagws)) {
497 /*sprintf(query, "%s/M%s", uri[j], dn);*/
498 strcpy(query, uri[j]);
500 PRINT_REDIRECT_HEADER;
507 /* By default on one result: */
508 do_menu(ld, fp, dn, "", glob);
516 if (request == HEAD) {
521 sprintf( title2, "%s %s", glob->la[39], filter);
522 fprintf( fp, HTML_HEAD_TITLE, title2, glob->la[100]);
524 disp_file(glob, glob->header, fp);
526 ufn = friendly_dn(base, glob);
527 fprintf( fp, "%s <STRONG>\"%s\"</STRONG> in <STRONG>\"%s\"</STRONG> ",
528 glob->la[40], filter, ufn );
529 if ( ufn ) free( ufn );
532 fprintf( fp, "(%d %s)<br>", count,
533 count == 1 ? glob->la[70] : glob->la[71]);
536 counter = sort_result( ld, res, base, glob);
538 /* get time for performance log */
539 gettimeofday(×tore[4], NULL);
541 list_output(fp, glob);
543 if ( ldap_result2error( ld, res, 1 ) == LDAP_SIZELIMIT_EXCEEDED )
544 do_sizelimit(fp, 0, glob);
546 if(glob->legal && !glob->legal_top)
547 fprintf (fp, "%s\n%s\n", glob->la[101],
548 glob->is_proxy ? glob->la[104] : glob->la[65]);
550 disp_file(glob, glob->footer, fp);
557 /* end of function: do_search */
561 find_dPtr( displayList, displayType )
562 pDISPLAY displayList;
567 for ( dis = displayList; dis; dis = dis->next ) {
569 if ( !strcasecmp( dis->ocs, displayType )) return( dis );
578 PUBLIC void do_read(ld, fp, dn, amore, glob)
588 LDAPMessage *res, *e;
589 struct timeval timeout;
591 pDISPLAY d_ptr = NULL;
592 pDISPLAY_LINE dis_ptr = NULL;
596 char already_displayed[BUFSIZ];
597 int header_attr_mode = 0;
599 #if defined( TUE_TEL ) || defined( AMBIXGW )
604 *already_displayed = ':';
605 *(already_displayed+1) = '\0';
608 timeout.tv_sec = glob->timeout;
612 if ( (rc = ldap_search_st( ld, dn, LDAP_SCOPE_BASE, "objectClass=*",
613 NULL, 0, &timeout, &res )) != LDAP_SUCCESS ) {
614 do_error(fp, rc, NOT_FOUND, glob);
619 if ( (e = ldap_first_entry( ld, res )) == NULL ) {
620 do_error(fp, -2, SERVER_ERROR, glob);
624 val = ldap_get_values( ld, e, "objectClass" );
626 #if defined( TUE_TEL ) || defined( AMBIXGW )
627 /* toc_derefalias: read entry, aliasedObjectName is referring to */
628 if(charray_inlist(val, "toc_derefalias")){
631 new_dn = ldap_get_values( ld, e, "aliasedObjectName" );
632 if(new_dn && new_dn[0]) {
633 do_read(ld, fp, new_dn[0], amore, glob);
638 /* before displaying check for dynamic changes of the sorting parms */
639 parentDN = get_parentDN( dn );
640 dynamicResort( ld, glob, parentDN );
644 * check for objectClass via displayLists-Table which List
645 * of attributes we want to use.
648 for(s_ptr = glob->sort; s_ptr; s_ptr = s_ptr->next) {
651 d_ptr = s_ptr->display_class_ptr;
653 for( j=0; val[j]; j++ ) {
654 sprintf( buf, "|%s|", str_tolower( val[j] ));
656 if ( strstr( s_ptr->object_class, buf )) {
661 if (classFound == 1) break;
664 #if defined( TUE_TEL ) || defined( AMBIXGW )
665 dynamicDisplay( ld, glob, parentDN,
666 s_ptr ? s_ptr->display_class : "default" );
669 if((classFound == -1) && (glob->default_display_type)) {
670 d_ptr = glob->default_display_type;
674 /* if we did not find a fitting objectClass, simply return */
675 if(classFound == -1) {
677 fprintf( fp, HTML_HEAD_TITLE, glob->la[22], glob->la[100]);
678 fprintf( fp, "\n%s</BODY></HTML>", glob->la[41]);
682 /* is the display description defined already */
683 if ( !d_ptr && (( d_ptr = find_dPtr( glob->display,
684 s_ptr->display_class )) == NULL )) {
688 "do_read(%08d): couldn't find display type <%s> -- FATAL.",
689 glob->svc_cnt, s_ptr->display_class );
691 fprintf( fp, HTML_HEAD_TITLE, glob->la[22], glob->la[100]);
692 fprintf( fp, "\n%s</BODY></HTML>", glob->la[41]);
697 /* now we can point to the final display screen */
698 dis_ptr = ( amore ? d_ptr->second_page : d_ptr->first_page );
700 if (http == 1) PRINT_HTML_HEADER;
701 if (request == HEAD) {
706 dn = ldap_get_dn( ld, e );
708 if ( strcmp( dn, "" ) != 0 ) { /* Not the root */
709 s = ldap_explode_dn( dn, 1 );
710 if ( s[1] == NULL ) /* toplevel */
711 rdn = ldap_friendly_name( glob->friendlyfile, s[0], &fm );
717 fprintf( fp, HTML_HEAD_TITLE, ufn = friendly_dn( dn, glob ),
719 if ( ufn ) free( ufn );
721 disp_file(glob, glob->header, fp);
723 if ( !glob->ldap_referral_mode ) {
725 make_la_buttons("R", fp, ld, dn, la_url, glob);
726 make_header( fp, dn, 0, glob );
728 fprintf( fp, glob->la[105]);
730 fprintf( fp, "<DL>");
732 fprintf( fp, glob->la[101]);
734 /* don't display rdn if first attribute is in header-mode */
735 if ( dis_ptr->ty == HEADER )
736 header_attr_mode = 1;
737 if( ( dis_ptr && !header_attr_mode ) || !dis_ptr ) {
738 if(glob->strip_pin && strstr(glob->strip_pin, d_ptr->ocs)) {
739 char rdnstriped[BUFSIZ];
741 strcpy( rdnstriped, rdn);
742 trimright (rdnstriped, " 1234567890");
743 fprintf( fp, "<H1>%s</H1>", rdnstriped );
745 fprintf( fp, "<H1>%s</H1>", rdn);
749 get_ref_attrs( ld, dn, e, glob );
751 /* get time for performance log */
753 gettimeofday(×tore[4], NULL);
755 if ( header_attr_mode )
758 for( ; dis_ptr; dis_ptr = dis_ptr->next) {
762 int n, m, iatlabel=0, replace=0;
763 IND_ATTR_ARR *vnodes;
769 retcode = displayTueRefPhone( ld, fp, dn, dis_ptr,
770 e, rdn, glob, already_displayed );
772 if(strstr(already_displayed, dis_ptr->label)) {
776 vnodes = glob->ind_attrs->valid_nodes;
778 for(n=0; vnodes && vnodes[n].key && *(vnodes[n].key) ; n++) {
780 if(!strcasecmp(vnodes[n].attr, dis_ptr->attribute)) {
782 for(m=0; vnodes[n].e[m]; m++)
783 print_attr( vnodes[n].ld, fp, dn,
784 m==0 ? dis_ptr->label : "", dis_ptr->attribute,
785 vnodes[n].e[m], dis_ptr->ty, rdn, glob);
788 if(vnodes[n].replace)
794 if( iatlabel && !replace)
795 print_attr( ld, fp, dn, "",
796 dis_ptr->attribute, e, dis_ptr->ty, rdn, glob);
799 print_attr( ld, fp, dn, dis_ptr->label,
800 dis_ptr->attribute, e, dis_ptr->ty, rdn, glob);
803 print_attr( ld, fp, dn, dis_ptr->label,
804 dis_ptr->attribute, e, dis_ptr->ty, rdn, glob);
809 if ( !amore && d_ptr && d_ptr->second_page ) {
811 fprintf( fp, "</DL><A HREF=\"/L%s\"><B>%s</B></A>\n",
812 hex_encode(dn), glob->la[42]);
816 fprintf( fp, "</DL>\n");
818 if (strcasecmp(dn + strlen(dn) - strlen(glob->basedn->dn),
819 glob->basedn->dn) == 0) {
825 aoc = make_oc_to_string(oc = ldap_get_values( ld, e, "objectClass" ));
827 if(!strlstcmp (aoc, glob->no_modify, '|')) {
828 for (p_mod = glob->modify; aoc && p_mod; p_mod = p_mod->next) {
829 if (strlstcmp (aoc, p_mod->ocs, '|')) {
830 fprintf( fp, "%s<TT>%s</TT><P><FORM ACTION=\"F%s\">\n",
831 glob->la[101], glob->la[43], hex_encode(dn));
832 fprintf (fp, "%s <INPUT TYPE=\"password\" ",
834 fprintf (fp, "NAME=\"userPassword\"><BR>%s ",
836 fprintf (fp, "<INPUT TYPE=\"submit\" VALUE=\"%s\">",
838 fprintf (fp, " %s. </FORM>\n",
845 ldap_value_free( oc );
849 /* Button leading to cgi-script */
850 if( glob->form_button ){
853 oc = ldap_get_values( ld, e, "objectClass" );
854 disp_form_button(1, oc, dn, ld, fp, glob);
857 disp_file(glob, glob->footer, fp);
862 /* end of function: do_read */
864 PRIVATE void disp_form_button(read_menu, oc, dn, ld, fp, glob)
873 char dn_used[BUFSIZ], button_label[BUFSIZ];
877 char **selfInsertWho = NULL;
878 char **studie = NULL;
879 int selfInsReadFlag = 0;
882 for(fo_ptr = glob->form_button; fo_ptr; fo_ptr = fo_ptr->next) {
883 if(read_menu != fo_ptr->read_menu ||
884 ( !charray_inlist(oc, fo_ptr->object_class)
885 && strncasecmp( "cn=", fo_ptr->object_class, 3 ) ) )
888 strcpy(button_label, fo_ptr->button_label);
891 /* new-AMBIX cn=Selbst-Eintrag etc. support */
892 /* object-class field contains here cn=xyz e.g. cn=Selbst-Eintrag */
893 if ( !strncasecmp( "cn=", fo_ptr->object_class, 3 )) {
895 LDAPMessage *res, *e;
896 struct timeval timeout;
897 static char *attrs[] = { "objectClass", "selfInsertWho",
900 /* cn=Selbsteintrag nur einmal lesen */
901 if (!selfInsReadFlag ) {
904 timeout.tv_sec = glob->timeout;
907 sprintf(dn_buf, "%s,%s", fo_ptr->object_class, dn);
908 if (ldap_search_st( ld, dn_buf, LDAP_SCOPE_BASE, "objectClass=*",
909 attrs, 0, &timeout, &res ) != LDAP_SUCCESS )
911 if(( e = ldap_first_entry( ld, res )) == NULL )
914 selfInsertWho = ldap_get_values( ld, e, "selfInsertWho" );
915 studie = ldap_get_values( ld, e, "studie" );
918 if ( (who_val = strchr(button_label, '|')))
924 if ( !selfInsertWho || !selfInsertWho[0] )
927 /* exception for all + studiedn != dn -> two buttons stud + ang */
928 if ( strcasecmp(selfInsertWho[0], who_val ) &&
929 !(!strcasecmp(selfInsertWho[0], "all") && studie && studie[0] && dn_cmp(dn, studie[0]) && strcasecmp(who_val, "all")))
932 /* filter for exception all-button */
933 if( studie && studie[0] && dn_cmp(dn, studie[0]) && !strcasecmp(selfInsertWho[0], "all") && !strcasecmp(who_val, "all") )
936 if(!strcasecmp(who_val, "stud" ) && studie && studie[0]
937 && dn_cmp(dn, studie[0]))
938 strcpy(dn_used, studie[0]);
942 fprintf (fp, "<FORM METHOD=%s ACTION=%s>\n", fo_ptr->method,
944 fprintf (fp, "%s\n<INPUT type=hidden name=\"%s\" value=\"%s\">\n",
945 fo_ptr->text, fo_ptr->dn_name, hex_encode(dn_used));
946 fprintf (fp, "<INPUT TYPE=\"submit\" name=\"%s\" value=\"%s\">\n",
947 fo_ptr->form_name, button_label);
948 fprintf (fp, "</FORM>\n");
951 /* end of function: disp_form_button */
954 PUBLIC void do_form(ld, fp, query, glob)
961 char *dn = query, *pw;
964 LDAPMessage *res, *e;
965 struct timeval timeout;
966 pMODIFY_LINE mod_ptr;
970 if ( (pw = strchr( dn, '?' )) == NULL ) {
971 fprintf( fp, "%s<br>", glob->la[49]);
975 if (strncmp(pw, "userPassword=", 13) == 0)
978 fprintf( fp, "%s %s!<br>", glob->la[50], pw);
981 if (strlen(pw) == 0) {
982 /* we need a password for simple auth */
983 do_error( fp, LDAP_INVALID_CREDENTIALS, FORBIDDEN, glob);
987 if ( (rc = ldap_simple_bind_s( ld, dn, pw )) != LDAP_SUCCESS ) {
988 if ( debug ) ldap_perror( ld, "ldap_simple_bind_s" );
989 do_error( fp, rc, FORBIDDEN, glob);
992 if (debug) fprintf(stderr, "BOUND as %s\n", dn);
993 timeout.tv_sec = glob->timeout;
995 if ( (rc = ldap_search_st( ld, dn, LDAP_SCOPE_BASE, "objectClass=*",
996 0, 0, &timeout, &res )) != LDAP_SUCCESS ) {
997 do_error(fp, rc, NOT_FOUND, glob);
1000 if ( (e = ldap_first_entry( ld, res )) == NULL ) {
1001 do_error(fp, -2, SERVER_ERROR, glob);
1004 dn = ldap_get_dn( ld, e );
1005 ufn = ldap_dn2ufn( dn );
1009 sprintf( title, "%s %s", glob->la[51], ufn );
1010 fprintf( fp, HTML_HEAD_TITLE, title, glob->la[100] );
1012 disp_file(glob, glob->header, fp);
1014 fprintf( fp, "<FORM ACTION=\"Y%s\">\n<INPUT TYPE= \"radio\" ", hex_encode(dn));
1015 fprintf( fp, "NAME=\"oldPassword\" VALUE=\"%s\" CHECKED><TT>%s</TT>\n<H1>%s</H1><DL><br>", hex_encode(pw), glob->la[53], ufn );
1017 for(mod_ptr = glob->modify->modattr; mod_ptr; mod_ptr = mod_ptr->next){
1018 a = mod_ptr->attribute;
1019 count = mod_ptr->count;
1020 if ( strcmp( a, "homepostaladdress" ) == 0
1021 || strcmp( a, "postaladdress" ) == 0)
1023 print_attr(ld,fp,dn,mod_ptr->label,a,e,MULTILINE,NULL, glob);
1025 form_attr(ld,fp,mod_ptr->label,a,e,1,count, glob);
1026 else if (count == 0)
1027 print_attr( ld, fp, dn, mod_ptr->label, a, e, DEFAULT, NULL, glob);
1029 form_attr( ld, fp, mod_ptr->label, a, e, 0, count, glob );
1031 fprintf( fp, "</DL><InPut TYPE=\"reset\" VALUE=\"%s\"> ", glob->la[72]);
1032 fprintf( fp, "<InPut TYPE=\"submit\" VALUE=\"%s\">", glob->la[47]);
1033 fprintf( fp, "</FORM>");
1035 disp_file(glob, glob->footer, fp);
1040 /* end of function: do_form */
1043 PUBLIC void do_modify(ld, fp, query, glob)
1049 char *dn, *ufn, *pw, *what, *next, *val, *oldval, *cp;
1050 int rc, changes = 0, delete_flag;
1051 static char *value1[2], *value2[2];
1052 static LDAPMod mod1, mod2;
1053 static LDAPMod *mods[3] = { &mod1 , &mod2, NULL};
1056 /* Patch: we can't run the modification of attributes in two distinct steps,
1057 since inheritage might copy a value into the entry after deletion
1064 /* query: DN?oldPassword=oldpw&att1=oldval1=val1&att2=oldval2=val2&...
1065 * or: DN?oldPassword=oldpw&att1%3Doldval1=val1&att2%3Doldval2=...
1071 if ( (what = strchr( dn, '?' )) == NULL ) {
1072 explain_error( fp, glob->la[93], BAD_REQUEST, glob );
1077 if (debug) fprintf(stderr, "What: %s\n", what);
1078 /* At first there should be the old userPassword */
1079 if ( (pw = strstr( what, "oldPassword")) == NULL ) {
1080 explain_error( fp, glob->la[94], BAD_REQUEST, glob);
1083 pw += 12; /* strlen("oldPassword") + 1 */
1084 /* skip to the first real attribute */
1085 if ( (what = strchr(pw, '&')) == NULL ) {
1086 explain_error( fp, glob->la[95], BAD_REQUEST, glob);
1091 if (debug) fprintf(stderr,
1092 "\ndo_modify: DN = %s PW = ####### CONTENT =\n%s\n ", dn, what );
1093 if ( (rc = ldap_simple_bind_s( ld, dn, pw )) != LDAP_SUCCESS ) {
1094 if ( debug ) ldap_perror( ld, "ldap_simple_bind_s" );
1095 do_error( fp, rc, FORBIDDEN, glob);
1098 if (debug) fprintf(stderr, "BOUND as %s.\n", dn);
1104 if (request == HEAD) {
1108 ufn = ldap_dn2ufn( dn );
1109 sprintf( title, "%s %s", glob->la[8], ufn);
1110 fprintf(fp, HTML_HEAD_TITLE, title, glob->la[100]);
1112 disp_file(glob, glob->header, fp);
1114 fprintf(fp, "<H2>%s %s</H2>%s<DL>\n", glob->la[9], ufn, glob->la[10]);
1118 if ((next = strchr(what, '&')) != NULL) {
1120 } else { /* last in query */
1123 if ((val = strrchr(what, '=')) == NULL) {
1125 fprintf( fp, "<P>%s ", glob->la[54]);
1126 fprintf( fp, "%s %s!<P>", glob->la[55], hex_qdecode(what));
1132 if ((oldval = strchr(what, '=')) == NULL) {
1134 fprintf( fp, "<P>%s ", glob->la[56]);
1135 fprintf( fp, "%s %s!<P>\n", glob->la[55], what);
1139 if (strcmp(oldval, val) == 0 ) { /* no changes */
1143 if ((strcasecmp(what, "homePostalAddress") == 0) ||
1144 (strcasecmp(what, "postalAddress") == 0)) {
1147 while ((cp = strchr(cp, '\n')) != NULL) *cp = '$';
1149 while ((cp = strchr(cp, '\n')) != NULL) *cp = '$';
1153 "what = %s, oldval = %s, val = %s\n",
1156 /* there is something to do:
1157 * - delete the old value
1158 * - add the new value if not empty */
1159 mod1.mod_type = what;
1160 mod2.mod_type = what;
1163 mod1.mod_values = value1;
1164 mod2.mod_values = value2;
1166 delete_flag = FALSE;
1170 if (strlen(oldval) > 0) {
1172 if (strlen (val) > 0) {
1174 mod1.mod_op = LDAP_MOD_ADD;
1177 /* mod2.mod_op = LDAP_MOD_DELETE;
1181 if ((rc = ldap_modify_s(ld, dn, mods)) != LDAP_SUCCESS) {
1184 "%s <TT>%s</TT> %s <TT>%s</TT>!<P>\n<EM> %d: %s.</EM><p>\n",
1185 glob->la[80], oldval, glob->la[81], what,
1186 rc, ldap_err2string(rc));
1193 mod1.mod_op = LDAP_MOD_DELETE;
1198 mod1.mod_op = LDAP_MOD_DELETE;
1206 mod1.mod_op = LDAP_MOD_ADD;
1212 fprintf(stderr, "trying: %s = %s.\n", what, val);
1214 if (((rc=ldap_modify_s(ld, dn, mods)) != LDAP_SUCCESS) &&
1215 (mod1.mod_op != LDAP_MOD_DELETE) && (rc != LDAP_NO_SUCH_ATTRIBUTE)){
1218 syslog (LOG_INFO, "ERROR: ldap_modify_s: ADD\n");
1220 ldap_perror( ld, "ldap_modify_s: ADD");
1222 "%s <TT>%s</TT> %s <TT>%s</TT><P>\n%s <EM> %d: %s.</EM><P>\n",
1223 glob->la[57], val, glob->la[58], what, glob->la[59],
1224 rc, ldap_err2string( rc ) );
1225 if (strlen(oldval) > 0 && rc != LDAP_INSUFFICIENT_ACCESS) {
1226 /* try to reset to old value */
1228 mod1.mod_op = LDAP_MOD_ADD;
1232 if ((rc = ldap_modify_s(ld, dn, mods)) != LDAP_SUCCESS) {
1234 "%s <TT>%s</TT> %s <TT>%s</TT>!<P>\n<EM> %d: %s.</EM><P>\n",
1235 glob->la[60], oldval, glob->la[61], what,
1236 rc, ldap_err2string(rc));
1240 fprintf( fp, "%s <TT>%s</TT> %s <TT>%s</TT><P>\n",
1241 glob->la[62], oldval, glob->la[61], what);
1248 if (debug) fprintf(stderr, "MOD: %s = %s.\n", what, val);
1250 fprintf(fp, "<DT><B>%s</B> <DD>%s <TT>(%s)</TT>\n",
1251 ldap_friendly_name(glob->friendlyfile, what, &fm), value1[0],
1252 delete_flag ? glob->la[74] : strlen(oldval) > 0 ?
1253 glob->la[75] : glob->la[76]);
1256 fprintf(fp, "</DL>%d %s%s%s!\n", changes, glob->la[15],
1257 changes != 1 ? glob->la[73] : "",
1258 changes > 0 ? glob->la[16] : "");
1260 char *dn2 = hex_encode(dn);
1262 fprintf(fp, "<UL><LI><B><A HREF=\"/R%s\">%s</A>\n",
1264 fprintf(fp, "<LI><A HREF=\"/F%s?userPassword=%s\">%s</A></B></UL>\n",
1265 dn2, pw, glob->la[19]);
1269 disp_file(glob, glob->footer, fp);
1274 /* end of function: do_modify */
1276 PRIVATE int no_show( rdn, glob)
1280 if ( glob->no_show_rdn ) {
1282 char rdn_cpy[BUFSIZ], *toc, no_sh[BUFSIZ];
1284 strcpy(no_sh, glob->no_show_rdn);
1285 sprintf(rdn_cpy, "|%s|", rdn);
1286 toc = strtok(no_sh, " ");
1288 if(strstr(str_tolower((char *) rdn_cpy), str_tolower(toc)))
1290 } while( ( toc = strtok(NULL, " ")) );
1296 /* end of function: no_show */
1299 PRIVATE int sort_result(ld, res, dn, glob)
1307 int counter = 0, baselen;
1310 pMY_LDAP_LIST lmptr;
1311 LFP getfirst = glob->prefer_ref_uris ? my_first_entry : ldap_first_entry,
1312 getnext = glob->prefer_ref_uris ? my_next_entry : ldap_next_entry;
1316 ufn = ldap_dn2ufn(dn);
1317 baselen = ufn ? strlen(ufn) : 0;
1318 basecount = ufn ? chrcnt(ufn, UFNSEP) : 0;
1320 #if defined( TUE_TEL ) || defined( AMBIXGW )
1321 /* before sorting check for dynamic changes of the sorting instructions */
1322 dynamicResort( ld, glob, dn );
1325 for ( e = (*getfirst)(ld, res); e != NULL && counter < glob->maxcount;
1326 e = (*getnext)(ld, e ) ) {
1327 sort_parse(ld, e, dn, ufn, baselen, basecount, counter, glob);
1329 for(lmptr = mllroot; lmptr; lmptr = lmptr->next) {
1330 sort_parse(ld, lmptr->e, dn, ufn, baselen, basecount, counter, glob);
1334 for(s_ptr = glob->sort; s_ptr; s_ptr = s_ptr->next) {
1336 qsort(s_ptr->dnList, s_ptr->dnLast, sizeof(int), compare);
1340 /* end of function: sort_result */
1343 PRIVATE void list_output(fp, glob)
1350 if(glob->tables_marker)
1351 fprintf (fp, "</H3><TABLE WIDTH=\"100%%\">");
1353 for (i = 0 ; i < MAX_OCS ; i++ ) {
1354 if(!glob->sorty[i]) continue;
1355 s_ptr = glob->sorty[i];
1357 if(glob->tables_marker)
1358 fprintf( fp, "<TR><TH ALIGN=LEFT><BR>");
1360 fprintf( fp, "<H3>%s", s_ptr->label);
1363 if(glob->ton_urls && glob->ton_urls->department
1364 && (strlen(s_ptr->label) >1) )
1365 fprintf( fp, " / %s", glob->ton_urls->department);
1368 if(s_ptr->restricted) {
1369 fprintf( fp, " %s", glob->la[33]);
1370 if (glob->legal && !glob->legal_top)
1371 fprintf( fp, ", %s", glob->la[34]);
1375 if(glob->tables_marker)
1376 fprintf (fp, "</H3></TH></TR>");
1378 fprintf (fp, "</H3><MENU>\n");
1380 for(x=0; x < s_ptr->dnLast; x++) {
1381 if(glob->strip_pin && strstr(glob->strip_pin, s_ptr->object_class)){
1382 s_ptr->dnList[x]->href[strlen(s_ptr->dnList[x]->href) -5] = '\0';
1383 trimright (s_ptr->dnList[x]->href, " 1234567890");
1384 strcat(s_ptr->dnList[x]->href, "</A>\n");
1387 if( glob->raw_data ) {
1388 fprintf(fp,"%s",s_ptr->dnList[x]->raw);
1389 free(s_ptr->dnList[x]->raw);
1391 fprintf(fp,"%s",s_ptr->dnList[x]->href);
1392 free(s_ptr->dnList[x]->href);
1394 free(s_ptr->dnList[x]->string);
1397 if(!glob->tables_marker)
1398 fprintf (fp, "</MENU>\n");
1400 glob->sorty[i] = NULL;
1402 if(glob->tables_marker)
1403 fprintf (fp, "</TABLE>\n");
1405 /* end of function: list_output */
1407 PRIVATE void make_la_buttons(sep, fp, ld, dn, la_url, glob)
1418 /* Inform users from unknown */
1419 if(glob->unknown_host) fprintf( fp, glob->la[102]);
1421 if(glob->legal && glob->legal_top)
1422 fprintf (fp, "%s\n%s\n",
1423 glob->is_proxy ? glob->la[104] : glob->la[65], glob->la[101]);
1425 /* if allowed -> allow-file-message */
1426 if(glob->allowed && glob->allow_msg)
1427 disp_file(glob, glob->allow_msg, fp);
1429 if(glob->pull_down_menus) {
1430 make_la_buttons_pull_down(sep, fp, ld, dn, la_url, glob);
1434 fprintf( fp, "<B>");
1435 fprintf( fp, " [ <A HREF=\"/H\">%s</A> ] ",glob->la[29]);
1436 for(k=0; k<strlen(glob->olang); k++){
1437 if(glob->olang[k] == glob->lang[0]) continue;
1438 sprintf(la_url, "http://%s:%d/%s%s",
1439 glob->hostname, glob->webport+glob->olang[k]-'0',
1440 sep, hex_encode(dn));
1441 fprintf( fp, " [ <A HREF=\"%s\"> %s </A> ] ",
1442 la_url, glob->language[glob->olang[k]-'0']);
1444 fprintf( fp, "</B><p>");
1446 /* end of function: make_la_buttons */
1448 PRIVATE void make_la_buttons_pull_down(sep, fp, ld, dn, la_url, glob)
1458 TABLE_DISPLAY *tab_ptr;
1460 fprintf( fp, "<FORM ACTION=\"/B\">\n");
1461 fprintf( fp, "<INPUT TYPE=SUBMIT NAME=H Value = \"%s\">\n",glob->la[29]);
1463 fprintf( fp, "_\n");
1465 for(k=0; k<strlen(glob->olang); k++){
1466 if(glob->olang[k] == glob->lang[0]) continue;
1467 sprintf(la_url, "http://%s:%d/%s%s",
1468 glob->hostname, glob->webport+glob->olang[k]-'0',
1469 sep, hex_encode(dn));
1470 fprintf( fp, "<INPUT TYPE=SUBMIT NAME=%s Value = \"%s\">\n",
1471 la_url, glob->language[glob->olang[k]-'0']);
1474 /* make tables button in order to have table-display requests */
1475 for(tab_ptr = glob->tables; tab_ptr; tab_ptr = tab_ptr->next) {
1478 struct timeval timeout;
1480 static char *attrs[] = { "objectClass", 0 };
1482 if( !((!tab_ptr->allow || glob->allowed) && !glob->tables_marker))
1485 /* Check objectclass for tables_oc */
1486 timeout.tv_sec = glob->timeout;
1487 timeout.tv_usec = 0;
1488 if ( ldap_search_st( ld, dn, LDAP_SCOPE_BASE, "objectClass=*",
1489 attrs, 0, &timeout, &res ) == LDAP_SUCCESS ){
1490 oc = ldap_get_values(ld, ldap_first_entry(ld, res), "objectClass");
1492 if ( oc && charray_inlist( oc, tab_ptr->select_oc)) {
1494 fprintf( fp, "_______\n");
1495 fprintf( fp, "<INPUT TYPE=SUBMIT NAME=X%s?%s#%s Value = \"%s\">\n",
1498 strstr(tab_ptr->dn_extension, "persontable") ?
1499 "MENU" : "PHONEBOOK",
1503 tab_ptr->dn_extension, tab_ptr->button_label);
1507 fprintf( fp, "</FORM>\n");
1509 /* end of function: make_la_buttons_pull_down */
1511 PRIVATE void print_rdn(fp, dn, glob)
1519 if(glob->pull_down_menus) {
1520 print_rdn_pull_down(fp, dn, glob);
1524 s = ldap_explode_dn( dn, 1 );
1525 if ( strcmp( dn, "" ) != 0 ) { /* Not the root */
1526 if ( s[1] == NULL ) { /* toplevel */
1527 rdn = ldap_friendly_name( glob->friendlyfile, s[0], &fm );
1531 fprintf( fp,"%s <B><A HREF=\"/R%s\">%s</A></B>\n",glob->la[28],hex_encode(dn),rdn?rdn:s[0]);
1532 } else { /* the root */
1533 fprintf( fp, "<B>%s</B>\n", glob->la[77]);
1535 ldap_value_free( s );
1537 /* end of function: print_rdn */
1539 PRIVATE void print_rdn_pull_down(fp, dn, glob)
1547 fprintf( fp, "<FORM ACTION=\"/B\">\n");
1549 s = ldap_explode_dn( dn, 1 );
1550 if ( strcmp( dn, "" ) != 0 ) { /* Not the root */
1551 if ( s[1] == NULL ) { /* toplevel */
1552 rdn = ldap_friendly_name( glob->friendlyfile, s[0], &fm );
1556 fprintf( fp,"%s <BIG><STRONG>%s</STRONG></BIG> ",
1557 glob->la[28], rdn?rdn:s[0]);
1558 fprintf( fp, "<INPUT TYPE=SUBMIT NAME=R%s Value = \"%s\">\n",
1559 hex_encode(dn), glob->la[98]);
1560 } else { /* the root */
1561 fprintf( fp, "<BIG><STRONG>%s</STRONG></BIG>\n", glob->la[77]);
1563 ldap_value_free( s );
1564 fprintf( fp, "</FORM>\n");
1566 /* end of function: print_rdn_pull_down */
1568 PRIVATE void make_search_box(fp, ld, dn, glob)
1576 scope = make_scope(ld, dn, glob); /* onelevel or subtree search ? */
1577 fprintf( fp, "<DL><DT><FORM ACTION=\"/S%s\">%s <inPUT NAME=\"%s\"><INPUT TYPE=submit VALUE=%s><INPUT TYPE=reset VALUE=\"%s\">\n",
1579 scope == LDAP_SCOPE_ONELEVEL ? glob->la[66] : glob->la[67],
1580 scope == LDAP_SCOPE_ONELEVEL ? "O" : "S",
1581 glob->la[68], glob->la[69]);
1583 fprintf( fp, "</FORM></DL>\n");
1585 /* end of function: make_search_box */
1587 PRIVATE LDAPMessage *my_first_entry( ld, e )
1591 return(ldap_list_eval(ld, e , ldap_first_entry));
1593 /* end of function: my_first_entry */
1595 PRIVATE LDAPMessage *my_next_entry(ld, e )
1599 return(ldap_list_eval(ld, e , ldap_next_entry));
1601 /* end of function: my_next_entry */
1603 PRIVATE LDAPMessage *ldap_list_eval(ld, e, funcp )
1609 char **value = NULL;
1610 pMY_LDAP_LIST *lmhandle; /* , lmptr; */
1612 for(lmhandle = &mllroot; *lmhandle; lmhandle = &(*lmhandle)->next)
1615 for( e = (*funcp)( ld, e ) ;
1616 e && strstr(make_oc_to_string(value = ldap_get_values( ld, e, "objectClass" )),
1617 "|alias|"); e = ldap_next_entry( ld, e )) {
1618 *lmhandle = (pMY_LDAP_LIST) ch_malloc(sizeof(MY_LDAP_LIST));
1620 lmhandle = &(*lmhandle)->next;
1621 ldap_value_free(value);
1625 if (value) ldap_value_free(value);
1628 for(lmptr = mllroot; lmptr; lmptr = lmptr->next) {
1631 val = ldap_get_values(ld, lmptr->e, "aliasedObjectName");
1632 if (dosyslog) syslog (LOG_INFO, "alias: %s", val[0]);
1633 ldap_value_free(val);
1640 /* end of function: ldap_list_eval */
1642 PRIVATE void sort_parse(ld, e, dn, ufn, baselen, basecount, counter, glob)
1653 char *dn2, *urldn = NULL, *rdn, *doc, *aoc;
1654 char *ufn2, *sortstring = NULL, *cp;
1655 char **sattr = NULL, href[20*BUFSIZ], *temp;
1656 int spaces = 0, iscountry;
1657 pGW_SWITCH_LINE gw_ptr;
1658 int flag, found_oc, i;
1662 char **uri = NULL, *urlnola, raw_string[BUFSIZ];
1668 oc = ldap_get_values( ld, e, "objectClass" );
1670 if(!(aoc = make_oc_to_string(oc))) return;
1675 if(glob->ton_urls && glob->ton_urls->value && strstr(aoc, "|person|")) {
1680 tonvals = ldap_get_values( ld, e, glob->ton_urls->attribute);
1681 if(!tonvals) return;
1682 for(k=0; tonvals[k]; k++) {
1683 if(strstr(tonvals[k], glob->ton_urls->value)
1684 && !(strchr(tonvals[k], '.')
1685 && (strcspn(tonvals[k],".") > strlen(glob->ton_urls->value)))){
1695 /* Begin New Sort */
1698 for(s_hndl = &(glob->sort); *s_hndl; s_hndl = &(*s_hndl)->next) {
1701 if(strstr( aoc, (*s_hndl)->object_class )) {
1703 if(strstr(aoc, "|person|") && glob->no_browse)
1711 if(glob->show_defoc) {
1712 *s_hndl = s_ptr = (pSORT_LINE) ch_malloc(sizeof(SORT_LINE));
1713 s_ptr->object_class = strdup(pick_oc(oc));
1714 s_ptr->label = ldap_friendly_name(glob->friendlyfile,
1715 s_ptr->object_class, &fm);
1716 s_ptr->priority = i;
1722 doc = s_ptr->object_class;
1724 dn2 = ldap_get_dn( ld, e );
1725 if(urldn) free(urldn);
1726 if(strstr(aoc, "|alias|")) {
1730 val = ldap_get_values(ld, e, "aliasedObjectName");
1731 urldn = strdup(hex_encode(val[0]));
1732 ldap_value_free(val);
1735 urldn = strdup(hex_encode(dn2));
1737 ufn2 = strdup (ldap_dn2ufn(dn2));
1738 s = ldap_explode_dn( dn2, 1 );
1741 ufn2 = dnrcut(ufn2, UFNSEP, basecount);
1743 /* Support raw data delivery */
1744 if(glob->raw_data) {
1748 sprintf(raw_string, "%s", ufn2);
1749 trimright (raw_string, " 1234567890");
1751 for(l=0; glob->raw_attrs[l]; l++) {
1752 rvals = ldap_get_values( ld, e, glob->raw_attrs[l]);
1754 sprintf(raw_string, "%s%% %s=", raw_string, glob->raw_attrs[l]);
1755 for(k=0; rvals[k]; k++) {
1756 sprintf(raw_string, "%s%s%s",raw_string,
1757 k>0 ? "&":"", rvals[k] );
1760 sprintf(raw_string, "%s|<br><br>", raw_string);
1763 iscountry = (strstr( doc, "country" ) != NULL);
1765 rdn = ldap_friendly_name( glob->friendlyfile, s[0], &fm );
1766 sortstring = ufn2 = ldap_friendly_name( glob->friendlyfile,
1773 if (( strncasecmp( rdn, "{ASN}", 5 ) == 0 )
1774 || no_show( rdn, glob)) {
1776 ldap_value_free( s );
1777 ldap_value_free( oc );
1780 if ( !iscountry ) { /* not a country */
1781 sattr = ldap_get_values( ld, e, s_ptr->sort_attr);
1782 sortstring = strdup(dn2);
1783 if ( ( cp = strchr(sortstring,'=')) ) {
1785 /* DNs may have components in '"', ignored when sorting */
1786 if ( *sortstring == '"' )
1791 while ( ( cp = strchr(cp,' ')) ) {
1796 while ( spaces > 0 ) {
1797 if ( ( cp = strrchr(sortstring,' ')) ) {
1804 ufn2 = trim(ufn2, "\"");
1810 if (glob->gw_switch && glob->gw_switch->dynamic) {
1812 uri = ldap_get_values( ld, e, "labeledURI" );
1814 /* PREFER-REF-URIS Code */
1815 if(strstr(aoc, "|alias|") && glob->prefer_ref_uris){
1817 LDAPMessage *ures, *ue;
1818 struct timeval timeout;
1821 timeout.tv_sec = glob->timeout;
1822 timeout.tv_usec = 0;
1826 ldap_opt = LDAP_DEREF_ALWAYS;
1827 ldap_set_option( ld, LDAP_OPT_DEREF, &ldap_opt );
1830 ld->ld_deref = LDAP_DEREF_ALWAYS;
1833 if ( (ldap_search_st( ld, dn2, LDAP_SCOPE_BASE, "objectClass=*",
1834 NULL, 0, &timeout, &ures )) == LDAP_SUCCESS ) {
1835 if ( (ue = ldap_first_entry( ld, ures ))) {
1836 if( ( val = ldap_get_values( ld, ue, "labeledURI" )) ) {
1837 if(uri) ldap_value_free(uri);
1845 for(i=0; uri && uri[i] && *uri[i]; i++) {
1848 if( ( sp = strchr(uri[i], ' ')) ) {
1850 if(strstr(sp, glob->gw_switch->lagws)) {
1854 } else if(strstr(sp, GWS))
1860 if(!flag && urlnola) {
1865 if (glob->gw_switch) {
1867 for(gw_ptr = glob->gw_switch->list;
1868 !flag && gw_ptr; gw_ptr = gw_ptr->next) {
1869 if (!dn_cmp (dn2, gw_ptr->dn)) {
1879 sprintf( href, "<LI><A HREF=\"%s\">%s</A>\n",
1880 (url_tmp = url_complete(url, urldn, "M")),
1881 glob->disp_sea_rdn ? rdn : ufn2);
1888 if(glob->strip_pin && strstr(glob->strip_pin, doc))
1889 if ( ( strptr = strchr(ufn2, ',')) ) {
1892 trimright(ufn2, " 1234567890");
1893 sprintf(ufn2, "%s,%s", ufn2, strptr);
1896 trimright(ufn2, " 1234567890");
1898 ufn2 = trim(ufn2, "\"");
1900 /* TABLES DISPLAY CODE */
1901 if(glob->tables_marker){
1903 char disp_rule[BUFSIZ], *strptr, strbuf[BUFSIZ];
1904 char tab_attr[BUFSIZ], percent[BUFSIZ];
1908 strcpy(disp_rule, glob->tables_marker);
1909 strptr = strstr(disp_rule, "persontable");
1912 strptr = strchr(strptr, ':') + 1;
1913 strcpy(disp_rule, strptr);
1914 strptr = strchr(disp_rule, '$');
1915 if(strptr) *strptr = '\0';
1916 strcat(disp_rule, "&");
1918 strcpy( href, "<TR>\n");
1921 strcpy(strbuf, disp_rule);
1922 strptr=strchr(disp_rule, '&');
1923 strcpy(disp_rule, strptr+1);
1925 strptr=strchr(strbuf, '&');
1927 strcpy(tab_attr, strbuf);
1928 strptr = strchr(tab_attr, ',');
1930 strcpy(percent, strptr);
1932 sprintf( href, "%s <TD WIDTH=\"%s%%\" VALIGN=TOP %s>",
1934 !strcasecmp(tab_attr, "telephonenumber") ?
1935 "ALIGN=RIGHT NOWRAP" : "ALIGN=LEFT");
1937 if(!strcasecmp(tab_attr, "rdn")){
1938 trimright (ufn2, " 1234567890");
1939 sprintf( href, "%s<A HREF=\"/M%s\">%s</A><BR>\n",
1943 /* use tat_refphone & fallback to telephonenumber */
1944 } else if(!strcasecmp(tab_attr, "phone")){
1945 displayTueTelList( ld, e, href, glob );
1948 } else if(!strncasecmp(tab_attr, "objectclass", 11)){
1949 char objectclass[BUFSIZ], letter[BUFSIZ], *trptr;
1950 char tab_attr_buf[BUFSIZ];
1952 *(letter+1) = *letter = '\0';
1953 strcpy(tab_attr_buf, tab_attr);
1954 trptr = tab_attr_buf;
1955 while( ( trptr = strchr(trptr, '=')) )
1958 sscanf(tab_attr_buf, "%*s%s%s",
1959 objectclass, letter);
1960 if(!*letter) *letter = '*';
1963 ldap_get_values( ld, e, "objectclass")) ) {
1964 if(charray_inlist(aval, objectclass))
1965 sprintf(href, "%s %s",
1969 ldap_get_values( ld, e, tab_attr )) ) {
1970 for(n=0; aval[n]; n++){
1971 if(!strcasecmp(tab_attr, "mail"))
1973 "%s<A HREF=\"mailto:%s\">%s</A><BR>",
1974 href, aval[n], aval[n]);
1976 sprintf(href, "%s %s<BR>", href, aval[n]);
1979 sprintf( href, "%s</TD>", href);
1981 sprintf( href, "%s</TR>", href);
1984 /* without tables */
1986 sprintf( href, "<LI><A HREF=\"%s%sM%s\">%s</A>\n",
1989 (glob->dit_config && !glob->dit_config->not_browse) ?
1990 dn2server(urldn, glob) : "",
1996 glob->disp_sea_rdn ? rdn : ufn2);
2000 if (*sortstring == '&') {
2002 sortstring[0] = sortstring[1];
2003 sortstring[1] = 'e';
2007 if( (strstr(aoc, "person") && (s_ptr->dnLast >= glob->max_person) )
2008 || ( s_ptr->dnLast >= glob->maxcount) ) {
2009 s_ptr->restricted = 1;
2014 temp = (char *) ch_malloc(strlen(*sattr)+strlen(sortstring)+1);
2016 temp = (char *) ch_malloc(strlen(sortstring)+1);
2018 strcat(temp, *sattr);
2019 strcat(temp,sortstring);
2022 s_ptr->dnList = (DNLIST **) ch_calloc(glob->maxcount+1,
2024 if (!s_ptr->dnList[s_ptr->dnLast] )
2025 s_ptr->dnList[s_ptr->dnLast] = (pDNLIST)
2026 ch_malloc(sizeof(DNLIST));
2028 s_ptr->dnList[s_ptr->dnLast]->string = temp;
2030 if(glob->raw_data) {
2031 s_ptr->dnList[s_ptr->dnLast]->raw = strdup(raw_string);
2034 s_ptr->dnList[s_ptr->dnLast++]->href = strdup(href);
2035 glob->sorty[s_ptr->priority] = s_ptr;
2038 ldap_value_free( s );
2039 ldap_value_free( oc );
2040 ldap_value_free( uri );
2042 if(++counter >= glob->maxcount)
2043 glob->restricted = TRUE;
2049 /* end of function: sort_parse */
2052 PUBLIC void close_ldap_connections(glob)
2057 for(ldlptr = glob->ld_list; ldlptr; ldlptr = ldlptr->next)
2058 ldap_unbind(ldlptr->ld);
2060 /* end of function: close_ldap_connections */
2062 PUBLIC LDAP *get_ldap_connection( host, port, glob )
2067 pLD_LIST ldlptr, *ldlhdl;
2071 for(ldlptr = glob->ld_list; ldlptr; ldlptr = ldlptr->next) {
2072 if ( !strcasecmp(ldlptr->host, host) && (ldlptr->port == port))
2078 if ( (ld = ldap_open( host, port )) == NULL )
2080 if ( (rc=ldap_simple_bind_s( ld, glob->webdn, glob->webpw ))
2083 for(ldlhdl = &glob->ld_list; *ldlhdl; ldlhdl = &(*ldlhdl)->next)
2085 *ldlhdl = (pLD_LIST) ch_calloc(1, sizeof(LD_LIST));
2086 (*ldlhdl)->host = strdup(host);
2087 (*ldlhdl)->port = port;
2092 /* end of function: get_ldap_connection */
2095 PRIVATE void get_ref_attrs( ld1, dn, e1, glob )
2102 IND_ATTR_ARR *idx, **vnodes;
2106 LDAPMessage *res, *e;
2107 struct timeval timeout;
2109 char ref_dn[BUFSIZ], ref_cnbuf[BUFSIZ], *ref_cn;
2112 for(i_ptr = glob->ind_attrs; i_ptr; i_ptr = i_ptr->next) {
2115 if (i_ptr->ia_arr && (i_ptr->ia_arr[0].replace == 2))
2118 if ( (val1 = ldap_get_values( ld1, e1, i_ptr->ref_attr )) == NULL )
2121 for(idx = i_ptr->ia_arr, i=0; idx[i].key; i++){
2122 /* idx[i].key idx[i].replace idx[i].attr idx[i].host idx[i].port
2123 idx[i].base -- i_ptr->ref_attr */
2125 ld = get_ldap_connection( idx[i].host, idx[i].port, glob );
2127 timeout.tv_sec = glob->timeout;
2128 timeout.tv_usec = 0;
2130 for ( j = 0; val1[j] != NULL; j++ ) {
2131 if(strncasecmp(val1[j], idx[i].key, strlen(idx[i].key)))
2134 strcpy(ref_cnbuf, val1[j]);
2135 /* ref_cn = ref_cnbuf + strlen(idx[i].key);
2140 sprintf(ref_dn, "cn=%s,%s", ref_cn, idx[i].base);
2141 if ( (rc = ldap_search_st( ld, ref_dn, LDAP_SCOPE_BASE,
2142 "objectClass=*", NULL, 0, &timeout, &res )) != LDAP_SUCCESS )
2144 if ( (e = ldap_first_entry( ld, res )) == NULL )
2146 val = ldap_get_values( ld, e, idx[i].attr );
2147 if(val[0] != NULL) {
2149 idx[i].e = ( LDAPMessage ** )
2150 ch_malloc( 16 * sizeof(LDAPMessage *) );
2151 for(n=0; idx[i].e[n]; n++)
2155 vnodes = &glob->ind_attrs->valid_nodes;
2157 *vnodes = (IND_ATTR_ARR *)
2158 ch_malloc( 100 * sizeof(IND_ATTR_ARR *) );
2159 for(k=0; (*vnodes)[k].key; k++)
2162 (*vnodes)[k] = idx[i];
2168 /* end of function: get_ref_attrs */