/** --- BEGIN COPYRIGHT BLOCK --- * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission. * Copyright (C) 2005 Red Hat, Inc. * All rights reserved. --- END COPYRIGHT BLOCK --- */ /* * Generate a DN edit screen. */ #include "dsgw.h" #include "dbtdsgw.h" #ifdef DSGW_DEBUG int main(int argc, char *argv[], char *env[] ) #else /* DSGW_DEBUG */ int main(int argc, char *argv[] ) #endif /* DSGW_DEBUG */ { char *tmplname, *attrname, *attrdesc, *qs, *dn, *edn; char *attrs[ 2 ], **attrvals, **xdn, *avedn, *js0, *js1; LDAP *ld; LDAPMessage *msgp; int i; /* * The URL used to invoke this CGI looks like: * http://host/dnedit?CONTEXT=context&TEMPLATE=tmplname&DN=dn&ATTR=attrname&DESC=description * * where: * "tmplname" is the name of the HTML template to render * "attrname" is the name of a dn-valued attribute to display * "description" is a textual description of the attribute * * Note: original form http://host/dnedit/dn?... is supported * for keeping backward compatibility. */ tmplname = attrname = attrdesc = dn = edn = NULL; if (( qs = getenv( "QUERY_STRING" )) != NULL && *qs != '\0' ) { char *p, *q; q = qs + strlen( qs ); while ((( p = strrchr( qs, '&' )) != NULL ) || ( q - qs > 1 )) { if ( p ) *p++ = '\0'; else p = qs; q = p; if ( p != NULL && strncasecmp( p, "dn=", 3 ) == 0 ) { edn = dsgw_ch_strdup( p + 3 ); dn = dsgw_ch_strdup( p + 3 ); dsgw_form_unescape( dn ); } else if ( p != NULL && strncasecmp( p, "template=", 9 ) == 0 ) { tmplname = dsgw_ch_strdup( p + 9 ); dsgw_form_unescape( tmplname ); } else if ( p != NULL && strncasecmp( p, "attr=", 5 ) == 0 ) { attrname = dsgw_ch_strdup( p + 5 ); dsgw_form_unescape( attrname ); } else if ( p != NULL && strncasecmp( p, "desc=", 5 ) == 0 ) { attrdesc = dsgw_ch_strdup( p + 5 ); /* Don't bother unescaping it; we're only going to put it back in another URL. */ } else if ( p != NULL && strncasecmp( p, "context=", 8 ) == 0) { context = dsgw_ch_strdup( p + 8 ); dsgw_form_unescape( context ); } } if ( !tmplname ) dsgw_error( DSGW_ERR_MISSINGINPUT, "template", DSGW_ERROPT_EXIT, 0, NULL ); if ( !attrname ) dsgw_error( DSGW_ERR_MISSINGINPUT, "attr", DSGW_ERROPT_EXIT, 0, NULL ); if ( !attrdesc ) dsgw_error( DSGW_ERR_MISSINGINPUT, "desc", DSGW_ERROPT_EXIT, 0, NULL ); } else { dsgw_error( DSGW_ERR_MISSINGINPUT, NULL, DSGW_ERROPT_EXIT, 0, NULL ); } if ( dn == NULL ) { dsgw_error( DSGW_ERR_MISSINGINPUT, "dn", DSGW_ERROPT_EXIT, 0, NULL ); } (void)dsgw_init( argc, argv, DSGW_METHOD_GET ); #ifdef DSGW_DEBUG dsgw_logstringarray( "env", env ); #endif dsgw_send_header(); /* Get the current attribute values */ (void) dsgw_init_ldap( &ld, NULL, 0, 0); attrs[ 0 ] = attrname; attrs[ 1 ] = NULL; if (ldap_search_s( ld, dn, LDAP_SCOPE_BASE, "(objectclass=*)", attrs, 0, &msgp ) != LDAP_SUCCESS ) { dsgw_error( DSGW_ERR_ENTRY_NOT_FOUND, dn, DSGW_ERROPT_EXIT, 0, NULL ); } attrvals = ldap_get_values( ld, msgp, attrname ); /* Send the top-level document HTML */ dsgw_emits( "\n" "\n" "\n" "
\n" "\n" ); return 0; }