/*_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ * * * x500.c..... * * * * Function:..WorldWideWeb-X.500-Gateway - X.500-Access-Routines * * Based on web500gw.c 1.3 written by Frank Richter, TU Chemmniz * * which is based on go500gw by Tim Howes, University of * * Michigan - All rights reserved * * * * Authors:...Dr. Kurt Spanier & Bernhard Winkler, * * Zentrum fuer Datenverarbeitung, Bereich Entwicklung * * neuer Dienste, Universitaet Tuebingen, GERMANY * * * * ZZZZZ DDD V V * * Creation date: Z D D V V * * August 16 1995 Z D D V V * * Last modification: Z D D V V * * September 13 1999 ZZZZZ DDD V * * * _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_*/ /* * $Id: x500.c,v 1.10 1999/09/13 13:47:48 zrnsk01 Exp $ * */ #include "tgeneral.h" #include "tglobal.h" #include "x500.h" #include "init_exp.h" #include "support_exp.h" #include "html_exp.h" #ifdef TUE_TEL #include "tueTel_exp.h" #endif #if defined( TUE_TEL ) || defined( AMBIXGW ) #include "resort_exp.h" #endif PRIVATE int compare(a,b) DNLIST **a, **b; { return strcmp((*a)->string,(*b)->string); } /* end of function: compare */ PRIVATE char * pick_oc(oclist) char **oclist; { int i; if ( oclist == NULL ) return( "unknown" ); for ( i = 0; oclist[i] != NULL; i++ ) { if ( strcasecmp( oclist[i], "top" ) != 0 && strcasecmp( oclist[i], "quipuObject" ) != 0 && strcasecmp( oclist[i], "quipuNonLeafObject" ) != 0 ) return( str_tolower (oclist[i]) ); } return( "unknown" ); } /* end of function: pick_oc */ PUBLIC char * make_oc_to_string(oc) char **oc; { static char oc_res[BUFSIZ]; int i; if(!oc) return(NULL); *oc_res = '|'; *(oc_res+1) = '\0'; for(i = 0; oc[i] && *oc[i]; i++) { sprintf(oc_res, "%s%s|", oc_res, oc[i]); } return(str_tolower (oc_res)); } /* end of function: make_oc_to_string */ PUBLIC void do_xtend(ld, fp, query, filter, glob) LDAP *ld; FILE *fp; char *query; char *filter; GLOB_STRUCT *glob; { char *strptr, dn[BUFSIZ], command[BUFSIZ], extension[BUFSIZ]; strptr = strchr(query, '?'); *strptr++ = '\0'; strcpy(dn, query); strcpy(command, strptr); if( ( strptr = strchr(command, '#')) ) { *strptr++ = '\0'; strcpy(extension, strptr); } if(!strcasecmp(command, "MENU")){ glob->tables_marker = strdup(extension); do_menu(ld, fp, dn, "", glob); } #ifdef TUE_TEL if(!strcasecmp(command, "PHONEBOOK")){ do_phonebook(ld, fp, strstr(dn, "ou=TELEFONBUCH") ? dn : NULL, extension, glob, 1); } #endif } /* end of function: do_xtend */ PUBLIC void do_menu(ld, fp, dn, filter, glob) LDAP *ld; FILE *fp; char *dn; char *filter; GLOB_STRUCT *glob; { int rc; LDAPMessage *pres; struct timeval timeout; static char *sattrs[] = { "objectClass", "labeledURI", "aliasedObjectName", "mail", "cn", "telephonenumber", #ifdef TUE_TEL "tat_ton", "tat_refphone", #endif 0 }; static char **attrs = NULL; int counter = 0; pSEARCH_ONLY_LINE so_ptr; char la_url[BUFSIZ]; int count; char *ufn; #if OL_LDAPV > 0 int ldap_opt; #endif if(!attrs) attrs = (char**) charray_dup(sattrs); charray_merge(&attrs, glob->sort_attribs); if(glob->raw_data) charray_merge(&attrs, glob->raw_attrs); for(so_ptr = glob->search_only; so_ptr; so_ptr = so_ptr->next) { if (dn_cmp(dn, so_ptr->dn) == 0) { break; } } if(!so_ptr) { timeout.tv_sec = glob->timeout; timeout.tv_usec = 0; #if OL_LDAPV > 0 ldap_opt = LDAP_DEREF_FINDING; ldap_set_option( ld, LDAP_OPT_DEREF, &ldap_opt ); #else ld->ld_deref = LDAP_DEREF_FINDING; #endif if ( (rc = ldap_search_st( ld, dn, LDAP_SCOPE_ONELEVEL, glob->menu_filter, attrs, 0, &timeout, &pres )) != LDAP_SUCCESS && rc != LDAP_SIZELIMIT_EXCEEDED && rc != LDAP_INSUFFICIENT_ACCESS ) { do_error(fp, rc, NOT_FOUND, glob); return; } if (rc == LDAP_SIZELIMIT_EXCEEDED) glob->persRestricted = TRUE; #if OL_LDAPV > 0 ldap_opt = LDAP_DEREF_ALWAYS; ldap_set_option( ld, LDAP_OPT_DEREF, &ldap_opt ); #else ld->ld_deref = LDAP_DEREF_ALWAYS; #endif if ((count = (ldap_count_entries(ld, pres) )) < 1) { ldap_msgfree (pres); do_read (ld, fp, dn, 0, glob); return; } items_displayed = count; } if (http == 1) { PRINT_HTML_HEADER; } if (request == HEAD) { fflush(fp); exit_tweb (1); } fprintf( fp, HTML_HEAD_TITLE, ufn = friendly_dn(dn, glob), glob->la[100]); if ( ufn ) free( ufn ); if (dn_cmp(dn, glob->basedn->dn) == 0) disp_file(glob, glob->basedn->head, fp); else if(so_ptr && so_ptr->head) disp_file(glob, so_ptr->head, fp); else disp_file(glob, glob->header, fp); #ifdef TUE_TEL fprintf (fp, "\n\n"); fprintf (fp, "\n\n"); #endif make_la_buttons("M", fp, ld, dn, la_url, glob ); make_header( fp, dn, 0, glob); print_rdn(fp, dn, glob); make_search_box(fp, ld, dn, glob); #ifdef AMBIXGW /* Button leading to cgi-script */ if( glob->form_button && !glob->selbsteintrag[0]){ char **oc; LDAPMessage *res; struct timeval timeout; static char *attrs[] = { "objectClass", 0 }; timeout.tv_sec = glob->timeout; timeout.tv_usec = 0; if ( ldap_search_st( ld, dn, LDAP_SCOPE_BASE, "objectClass=*", attrs, 0, &timeout, &res ) != LDAP_SUCCESS ) { exit_tweb( 1 ); } oc = ldap_get_values( ld, ldap_first_entry( ld, res ), "objectClass" ); disp_form_button(0, oc, dn, ld, fp, glob); } /* check to see if selfinsert-buttons are appropriate here */ if(glob->selbsteintrag[0]) self_insert(ld,fp,dn,glob); #endif #ifdef TUE_TEL /* Named link to skip header */ fprintf (fp, "\n\n"); #endif fprintf(fp, glob->la[101]); if(!so_ptr) { /* DO_MENU */ counter = sort_result( ld, pres, dn, glob); /* get time for performance log */ gettimeofday(×tore[4], NULL); list_output(fp, glob); if ( ldap_result2error( ld, pres, 1 ) == LDAP_SIZELIMIT_EXCEEDED || glob->restricted ) do_sizelimit(fp, 1, glob); if(glob->legal && !glob->legal_top) fprintf (fp, "%s\n%s\n", glob->la[101], glob->is_proxy ? glob->la[104] : glob->la[65]); } if (dn_cmp(dn,glob->basedn->dn) == 0) disp_file(glob, glob->basedn->foot, fp); else if(so_ptr && so_ptr->foot) disp_file(glob, so_ptr->foot, fp); else disp_file(glob, glob->footer, fp); PRINT_HTML_FOOTER; } /* end of function: do_menu */ PRIVATE int make_scope(ld, dn, glob) LDAP *ld; char *dn; GLOB_STRUCT *glob; { int scope, idx; char **oc; LDAPMessage *res; struct timeval timeout; static char *attrs[] = { "objectClass", 0 }; if ( strcmp( dn, "" ) == 0 ) return( LDAP_SCOPE_ONELEVEL ); timeout.tv_sec = glob->timeout; timeout.tv_usec = 0; if ( ldap_search_st( ld, dn, LDAP_SCOPE_BASE, "objectClass=*", attrs, 0, &timeout, &res ) != LDAP_SUCCESS ) { return( -1 ); } oc = ldap_get_values( ld, ldap_first_entry( ld, res ), "objectClass" ); /* set scope according to configured object-classes */ scope = LDAP_SCOPE_ONELEVEL; for(idx = 0; glob->subtree_search && glob->subtree_search[idx]; idx++) if( charray_inlist( oc, glob->subtree_search[idx])) scope = LDAP_SCOPE_SUBTREE; ldap_value_free( oc ); ldap_msgfree( res ); return( scope ); } /* end of function: make_scope */ PUBLIC int do_search(ld, fp, query, glob) LDAP *ld; FILE *fp; char *query; GLOB_STRUCT *glob; { int scope; char *base, *filter, *strptr; char *filtertype; int count = 0, rc; struct timeval timeout; LDAPFiltInfo *fi; LDAPMessage *e, *res = NULL; static char *attrs[] = { "objectClass", "cn", "sn", "labeledURI", "aliasedObjectName", 0 }; int counter = 0; char *ufn; char title[BUFSIZ], title2[BUFSIZ]; #if OL_LDAPV > 0 int ldap_opt; #endif glob->no_browse = FALSE; /* query string: base-DN?[OS]=filter * search onelevel <--||--> search subtree */ if ( (filter = strchr( query, '?' )) == NULL ) { explain_error( fp, glob->la[89], BAD_REQUEST, glob ); exit_tweb( 1 ); } *filter++ = '\0'; if (*filter == '\0' || *(filter+1) != '=') { explain_error( fp, glob->la[90], BAD_REQUEST, glob); exit_tweb( 1 ); } if( ( strptr = strchr(filter, '&')) ) *strptr = '\0'; if( ( strptr = strchr(filter, '*')) ) *strptr = '\0'; if (*filter == 'S') { scope = LDAP_SCOPE_SUBTREE; } else { scope = LDAP_SCOPE_ONELEVEL; } filter += 2; if (*filter == '\0') { explain_error( fp, glob->la[92], BAD_REQUEST, glob); exit_tweb( 1 ); } /* deutsche Umlaute plaetten */ filter = flatten_chars(filter); base = query; filtertype = (scope == LDAP_SCOPE_ONELEVEL ? "web500gw onelevel" : "web500gw subtree"); #if OL_LDAPV > 0 ldap_opt = ( scope == LDAP_SCOPE_ONELEVEL ? LDAP_DEREF_FINDING : LDAP_DEREF_ALWAYS ); ldap_set_option( ld, LDAP_OPT_DEREF, &ldap_opt ); #else ld->ld_deref = (scope == LDAP_SCOPE_ONELEVEL ? LDAP_DEREF_FINDING : LDAP_DEREF_ALWAYS); #endif timeout.tv_sec = glob->timeout; timeout.tv_usec = 0; for (fi=ldap_getfirstfilter( filtd, filtertype, filter ); fi != NULL; fi = ldap_getnextfilter( filtd ) ) { if ( (rc = ldap_search_st( ld, base, scope, fi->lfi_filter, attrs, 0, &timeout, &res )) != LDAP_SUCCESS && rc != LDAP_SIZELIMIT_EXCEEDED ) { if (dosyslog) { #if OL_LDAPV > 0 int ld_errno; ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &ld_errno); syslog (LOG_INFO, "ldap_search_st(): %s", ldap_err2string ( ld_errno )); #else syslog (LOG_INFO, "ldap_search_st(): %s", ldap_err2string (ld->ld_errno)); #endif } do_error(fp, rc, NOT_FOUND, glob); return( 1 ); } if ( res && (count = ldap_count_entries( ld, res )) != 0 ) { break; } } items_displayed = count; #if OL_LDAPV > 0 ldap_opt = LDAP_DEREF_ALWAYS; ldap_set_option( ld, LDAP_OPT_DEREF, &ldap_opt ); #else ld->ld_deref = LDAP_DEREF_ALWAYS; #endif if ( count == 0 ) { if (http == 1) { fprintf(fp, "HTTP/1.0 404 %s \n", glob->la[6]); fprintf(fp, "MIME-Version: 1.0\n"); fprintf(fp, "Content-Type: text/html\n\n"); } if (request == HEAD) { fflush(fp); exit_tweb (1); } sprintf( title, "%s %s", filter, glob->la[36]); fprintf( fp, HTML_HEAD_TITLE, title, glob->la[100]); disp_file(glob, glob->header, fp); fprintf( fp, "