| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- /** --- BEGIN COPYRIGHT BLOCK ---
- * This Program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; version 2 of the License.
- *
- * This Program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA.
- *
- * In addition, as a special exception, Red Hat, Inc. gives You the additional
- * right to link the code of this Program with code not covered under the GNU
- * General Public License ("Non-GPL Code") and to distribute linked combinations
- * including the two, subject to the limitations in this paragraph. Non-GPL Code
- * permitted under this exception must only link to the code of this Program
- * through those well defined interfaces identified in the file named EXCEPTION
- * found in the source code files (the "Approved Interfaces"). The files of
- * Non-GPL Code may instantiate templates or use macros or inline functions from
- * the Approved Interfaces without causing the resulting work to be covered by
- * the GNU General Public License. Only Red Hat, Inc. may make changes or
- * additions to the list of Approved Interfaces. You must obey the GNU General
- * Public License in all respects for all of the Program code and other code used
- * in conjunction with the Program except the Non-GPL Code covered by this
- * exception. If you modify this file, you may extend this exception to your
- * version of the file, but you are not obligated to do so. If you do not wish to
- * provide this exception without modification, you must delete this exception
- * statement from your version and license this file solely under the GPL without
- * exception.
- *
- *
- * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
- * Copyright (C) 2005 Red Hat, Inc.
- * All rights reserved.
- --- END COPYRIGHT BLOCK --- */
- /*
- * edit.c -- CGI editable entry display -- HTTP gateway
- */
- #include "dsgw.h"
- #include "dbtdsgw.h"
- static void get_request(char *dn, char *tmplname,
- char *parent, unsigned long options);
- int main( argc, argv, env )
- int argc;
- char *argv[];
- #ifdef DSGW_DEBUG
- char *env[];
- #endif
- {
- char *dn, *tmplname, *p, *parent;
- unsigned long options;
- /*
- * If the QUERY_STRING is non-NULL, it looks like this:
- *
- * template [&CONTEXT=context] [ &INFO=infostring ] [ &ADD ] [ &DN=dn ] \
- * [&DNATTR=attrname&DNDESC=description]
- *
- * where:
- * "template" is the name of the edit template to use for display,
- * "dn" is escaped dn,
- * "infostring" is a message used to replace DS_LAST_OP_INFO directives
- * "attrname" is the name of a DN-valued attribute
- * "dndesc" is the destriptive name of the above DN-valued attribute
- *
- * If "&ADD" is present, we check to make sure the entry
- * does not exist, then we check that the parent entry exists, and then
- * we present an "add entry" form.
- *
- * Note: original form http://host/edit/dn[/...]?template[&...] is
- * supported for keeping backward compatibility.
- * But passing DN as PATH_INFO is NOT recommended.
- * Since PATH_INFO is passed to CGI as is (non-escaped),
- * the content has a risk to get broken especially when
- * it contains 8-bit UTF-8 data. (This is a known problem
- * on localized Windows machines.)
- */
- options = DSGW_DISPLAY_OPT_EDITABLE;
- dn = NULL;
- #ifndef __LP64__
- #ifdef HPUX
- #ifndef __ia64
- /* call the static constructors in libnls */
- _main();
- #endif
- #endif
- #endif
- if (( tmplname = getenv( "QUERY_STRING" )) != NULL && *tmplname != '\0' ) {
- tmplname = dsgw_ch_strdup( tmplname );
- while ( tmplname != NULL && ((( p = strrchr( tmplname, '&' )) != NULL ) || (p=tmplname) != NULL )) {
- if (p == tmplname) {
- tmplname = NULL;
- } else {
- *p++ = '\0';
- }
- if ( strcasecmp( p, "add" ) == 0 ) {
- options |= DSGW_DISPLAY_OPT_ADDING;
- if (( p = strrchr( tmplname, '&' )) != NULL ) {
- *p++ = '\0';
- }
- }
- if ( p != NULL && strncasecmp( p, "info=", 5 ) == 0 ) {
- dsgw_last_op_info = dsgw_ch_strdup( p + 5 );
- dsgw_form_unescape( dsgw_last_op_info );
- continue;
- }
- if ( p != NULL && strncasecmp( p, "dn=", 3 ) == 0 ) {
- dn = dsgw_ch_strdup( p + 3 );
- dsgw_form_unescape( dn );
- continue;
- }
- if ( p != NULL && strncasecmp( p, "dnattr=", 7 ) == 0 ) {
- dsgw_dnattr = dsgw_ch_strdup( p + 7 );
- dsgw_form_unescape( dsgw_dnattr );
- continue;
- }
- if ( p != NULL && strncasecmp( p, "dndesc=", 7 ) == 0 ) {
- dsgw_dndesc = dsgw_ch_strdup( p + 7 );
- dsgw_form_unescape( dsgw_dndesc );
- continue;
- }
- if ( p != NULL && strncasecmp( p, "context=", 8 ) == 0) {
- context = dsgw_ch_strdup( p + 8 );
- dsgw_form_unescape( context );
- continue;
- }
-
- /*
- * If none of the if-statements above matched,
- * then it's the template name
- */
- tmplname = p;
- break;
- }
-
- } else {
- tmplname = NULL;
- }
- (void)dsgw_init( argc, argv, DSGW_METHOD_GET );
- dsgw_send_header();
- #ifdef DSGW_DEBUG
- dsgw_logstringarray( "env", env );
- #endif
- get_request(dn, tmplname, parent, options);
- exit( 0 );
- }
- static void
- get_request(char *dn, char *tmplname, char *parent, unsigned long options)
- {
- LDAP *ld;
- if ( dn == NULL ) { /* not found in QUERY_STRING */
- dsgw_error( DSGW_ERR_MISSINGINPUT, NULL, DSGW_ERROPT_EXIT, 0, NULL );
- }
- #ifdef DSGW_DEBUG
- dsgw_log( "get_request: dn: \"%s\", tmplname: \"%s\" "
- "dnattr: \"%s\", dndesc: \"%s\"\n", dn,
- ( tmplname == NULL ) ? "(null)" : tmplname,
- ( dsgw_dnattr == NULL ) ? "(null)" : dsgw_dnattr,
- ( dsgw_dndesc == NULL ) ? "(null)" : dsgw_dndesc );
- #endif
- (void)dsgw_init_ldap( &ld, NULL, 0, 0);
- if (( options & DSGW_DISPLAY_OPT_ADDING ) == 0 ) {
- /*
- * editing an existing entry -- if no DN is provided and we are running
- * under the admin server, try to get DN from admin. server
- */
- if ( *dn == '\0' ) {
- (void)dsgw_get_adm_identity( ld, NULL, &dn, NULL,
- DSGW_ERROPT_EXIT );
- }
- dsgw_read_entry( ld, dn, NULL, tmplname, NULL, options );
- } else {
- dsgwtmplinfo *tip;
- char *matched;
- /*
- * new entry -- check to make sure it doesn't exist
- */
- if ( dsgw_ldap_entry_exists( ld, dn, &matched, DSGW_ERROPT_EXIT )) {
- char **rdns;
- dsgw_html_begin( XP_GetClientStr(DBT_entryAlreadyExists_), 1 );
- dsgw_emits( XP_GetClientStr(DBT_anEntryNamed_) );
- rdns = ldap_explode_dn( dn, 1 );
- dsgw_html_href(
- dsgw_build_urlprefix(),
- dn, ( rdns == NULL || rdns[ 0 ] == NULL ) ? dn : rdns[ 0 ],
- NULL, XP_GetClientStr(DBT_onmouseoverWindowStatusClickHere_) );
- if ( rdns != NULL ) {
- ldap_value_free( rdns );
- }
- dsgw_emits( XP_GetClientStr(DBT_alreadyExistsPPleaseChooseAnothe_) );
- dsgw_form_begin( NULL, NULL );
- dsgw_emits( "\n<CENTER><TABLE border=2 width=\"100%\"><TR>\n" );
- dsgw_emits( "<TD WIDTH=\"50%\" ALIGN=\"center\">\n" );
- dsgw_emitf( "<INPUT TYPE=\"button\" VALUE=\"%s\" "
- "onClick=\"parent.close()\">", XP_GetClientStr(DBT_closeWindow_1) );
- dsgw_emits( "<TD WIDTH=\"50%\" ALIGN=\"center\">\n" );
- dsgw_emit_helpbutton( "ENTRYEXISTS" );
- dsgw_emits( "\n</TABLE></CENTER></FORM>\n" );
- dsgw_html_end();
- } else if ( !dsgw_is_dnparent( matched, dn ) &&
- !dsgw_dn_cmp( dn, gc->gc_ldapsearchbase )) {
- /*
- * The parent entry does not exist, and the dn being added is not
- * the same as the suffix for which the gateway is configured.
- */
- dsgw_html_begin( XP_GetClientStr(DBT_parentEntryDoesNotExist_), 1 );
- dsgw_emitf( XP_GetClientStr(DBT_youCannotAddAnEntryByTheNamePBSB_),
- dn );
- parent = dsgw_dn_parent( dn );
- if ( parent == NULL || strlen( parent ) == 0 ) {
- dsgw_emits( XP_GetClientStr(DBT_itsParentN_) );
- } else {
- dsgw_emitf( XP_GetClientStr(DBT_anEntryNamedPBSBN_), parent );
- free( parent );
- }
- dsgw_form_begin( NULL, NULL );
- dsgw_emits( "\n<CENTER><TABLE border=2 width=\"100%\"><TR>\n" );
- dsgw_emits( "<TD WIDTH=\"50%\" ALIGN=\"center\">\n" );
- dsgw_emitf( "<INPUT TYPE=\"button\" VALUE=\"%s\" "
- "onClick=\"parent.close()\">", XP_GetClientStr(DBT_closeWindow_2) );
- dsgw_emits( "<TD WIDTH=\"50%\" ALIGN=\"center\">\n" );
- dsgw_emit_helpbutton( "ADD_NOPARENT" );
- dsgw_emits( "\n</TABLE></CENTER></FORM>\n" );
- dsgw_html_end();
- } else {
- /*
- * The parent exists, or the user is adding the entry whose DN
- * is the same as the suffix for which the gateway is configured.
- * Display the "add entry" form.
- */
- if ( tmplname == NULL ) {
- #ifdef DSGW_DEBUG
- dsgw_log( "NULL tmplname\n" );
- #endif
- dsgw_error( DSGW_ERR_MISSINGINPUT,
- XP_GetClientStr(DBT_missingTemplate_),
- DSGW_ERROPT_EXIT, 0, NULL );
- }
- tip = dsgw_display_init( DSGW_TMPLTYPE_DISPLAY, tmplname, options );
-
- dsgw_display_entry( tip, ld, NULL, NULL, dn );
- dsgw_display_done( tip );
- }
- }
- ldap_unbind( ld );
- }
|