]> git.sur5r.net Git - openldap/blobdiff - clients/ud/group.c
Don't depend error handling on exact resultCode.
[openldap] / clients / ud / group.c
index 5d6ed6d6848b29d35247fcc7e22ed3933e87ad08..16a0b6d0fecb41d83446b34f62ef6eaa7a0b2666 100644 (file)
@@ -1,3 +1,8 @@
+/* $OpenLDAP$ */
+/*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
 /*
  * Copyright (c) 1993, 1994  Regents of the University of Michigan.
  * All rights reserved.
  *
  */
 
+#include "portable.h"
+
 #include <stdio.h>
-#include <string.h>
-#include <time.h>
+
+#include <ac/string.h>
+#include <ac/ctype.h>
+#include <ac/time.h>
+#include <ac/unistd.h>
+
+#ifdef HAVE_IO_H
+#include <io.h>
+#endif
 
 #include <lber.h>
 #include <ldap.h>
 
-#include <ldapconfig.h>
+#include "ldap_defaults.h"
 #include "ud.h"
 
-extern LDAPMessage * find();
-
-#ifdef DEBUG
-extern int debug;
-#endif
+static char * bind_and_fetch(char *name);
 
-extern char *bound_dn, *group_base;
-extern int verbose, bind_status;
-extern struct entry Entry;
-extern LDAP *ld;
 
-extern void Free();
-
-void add_group(name)
-char *name;
+void
+add_group( char *name )
 {
-       register int i, idx = 0, prompt = 0;
+       int idx = 0, prompt = 0;
        char tmp[BUFSIZ], dn[BUFSIZ];
        static LDAPMod *attrs[9];
        LDAPMod init_rdn,    init_owner,   init_domain,
@@ -45,8 +49,6 @@ char *name;
        char *init_rdn_value[2], *init_owner_value[2], *init_domain_value[2],
                *init_errors_value[MAX_VALUES], *init_joinable_value[2],
                *init_request_value[MAX_VALUES];
-       extern void ldap_flush_cache();
-       extern char * strip_ignore_chars();
 
 #ifdef DEBUG
        if (debug & D_TRACE) {
@@ -160,10 +162,9 @@ char *name;
 
 #ifdef DEBUG
        if (debug & D_GROUPS) {
-               register LDAPMod **lpp;
-               register char **cpp;
-               register int j;
-               extern char * code_to_str();
+               LDAPMod **lpp;
+               char **cpp;
+               int i, j;
                printf("  About to call ldap_add()\n");
                printf("  ld = 0x%x\n", ld);
                printf("  dn = [%s]\n", dn);
@@ -202,11 +203,10 @@ char *name;
        return;
 }
 
-void remove_group(name)
-char *name;
+void
+remove_group( char *name )
 {
        char *dn, tmp[BUFSIZ];
-       static char * bind_and_fetch();
 
 #ifdef DEBUG
        if (debug & D_TRACE) {
@@ -219,9 +219,9 @@ char *name;
        if ((dn = bind_and_fetch(name)) == NULL)
                return;
 
-       printf("\n  The group '%s' will be permanently removed from\n",
-               name);
-       printf("  the Directory.  Are you absolutely sure that you want to\n" );        printf("  remove this entire group? ");
+       printf("\n  The entry\n    '%s'\n  will be permanently removed from", dn);
+       printf(" the Directory.\n  Are you absolutely sure that you want to" );
+       printf(" remove this entire group? ");
        fflush(stdout);
        fetch_buffer(tmp, sizeof(tmp), stdin);
        if (!(tmp[0] == 'y' || tmp[0] == 'Y'))
@@ -231,8 +231,10 @@ char *name;
         *  Now remove this from the LDAP Directory.
         */
        if (ldap_delete_s(ld, dn) != 0) {
-               if (ld->ld_errno == LDAP_INSUFFICIENT_ACCESS)
-                       printf("  You do not own the group \"%s\".\n", name);
+               int ld_errno = 0;
+               ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &ld_errno);
+               if (ld_errno == LDAP_INSUFFICIENT_ACCESS)
+                       printf("  You do not own the entry\n\t\"%s\".\n", dn);
                else
                        ldap_perror(ld, "  ldap_delete_s");
                printf("  Group not removed.\n");
@@ -241,23 +243,23 @@ char *name;
        }
        ldap_uncache_entry(ld, dn);
        if (verbose)
+       {
            if (name == NULL)
                printf("  The group has been removed.\n");
            else
                printf("  The group \"%s\" has been removed.\n", name);
+       }
        Free(dn);
        return;
 }
 
-void x_group(action, name)
-int action;
-char *name;
+void
+x_group( int action, char *name )
 {
        char **vp;
        char *values[2], *group_name;
        LDAPMod mod, *mods[2];
        static char *actions[] = { "join", "resign from", NULL };
-       static char * bind_and_fetch();
 
 #ifdef DEBUG
        if (debug & D_TRACE) {
@@ -323,9 +325,11 @@ char *name;
 #endif
 
        if (ldap_modify_s(ld, bound_dn, mods)) {
-               if ((action == G_JOIN) && (ld->ld_errno == LDAP_TYPE_OR_VALUE_EXISTS))
+               int ld_errno = 0;
+               ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &ld_errno);
+               if ((action == G_JOIN) && (ld_errno == LDAP_TYPE_OR_VALUE_EXISTS))
                        printf("  You are already subscribed to \"%s\"\n", group_name);
-               else if ((action == G_RESIGN) && (ld->ld_errno == LDAP_NO_SUCH_ATTRIBUTE))
+               else if ((action == G_RESIGN) && (ld_errno == LDAP_NO_SUCH_ATTRIBUTE))
                        printf("  You are not subscribed to \"%s\"\n", group_name);
                else
                        mod_perror(ld);
@@ -347,8 +351,8 @@ char *name;
        return;
 }
 
-void bulk_load(group)
-char *group;
+void
+bulk_load( char *group )
 {
        register int idx_mail, idx_x500;
        register int count_mail, count_x500;
@@ -503,15 +507,13 @@ char *group;
        return;
 }
 
-void purge_group(group)
-char *group;
+void
+purge_group( char *group )
 {
        int isclean = TRUE;
        LDAPMessage *lm;
        LDAPMod mod, *mods[2];
        char dn[BUFSIZ], tmp[BUFSIZ], *values[2], **vp, **rdns;
-       extern char * my_ldap_dn2ufn();
-       extern int col_size;
 
 #ifdef DEBUG
        if (debug & D_TRACE) {
@@ -657,7 +659,8 @@ ask:
        return;
 }
 
-void tidy_up()
+void
+tidy_up( void )
 {
        register int i = 0;
        int found_one = 0;
@@ -732,14 +735,11 @@ void tidy_up()
  *  Names or e-mail addresses.  This includes things like group members,
  *  the errors-to field in groups, and so on.
  */
-void mod_addrDN(group, offset)
-char *group;
-int offset;
+void
+mod_addrDN( char *group, int offset )
 {
-       extern struct attribute attrlist[];
        char s[BUFSIZ], *new_value /* was member */, *values[2];
        char attrtype[ 64 ];
-       int i;
        LDAPMod mod, *mods[2];
        LDAPMessage *mp;
 
@@ -878,10 +878,10 @@ int offset;
                         *      "Bryan Beecher" <bryan@umich.edu>
                         *       Bryan Beecher  <bryan@umich.edu>
                         */
-                       register char *cp;
+                       char *cp;
                        if (strchr(s, '<') == NULL) {
                                for (cp = s; *cp != '@'; cp++)
-                                       if (isspace(*cp))
+                                       if (isspace((unsigned char)*cp))
                                                *cp = '.';
                        }
                        new_value = s;
@@ -906,9 +906,9 @@ int offset;
 
 #ifdef DEBUG
                if (debug & D_GROUPS) {
-                       register LDAPMod **lpp;
-                       register char **cp;
-                       register int i, j;
+                       LDAPMod **lpp;
+                       char **cp;
+                       int i, j;
                        printf("  About to call ldap_modify_s()\n");
                        printf("  ld = 0x%x\n", ld);
                        printf("  dn = [%s]\n", group);
@@ -925,7 +925,9 @@ int offset;
 #endif
 
                if (my_ldap_modify_s(ld, group, mods)) {
-                       if (ld->ld_errno == LDAP_NO_SUCH_ATTRIBUTE) {
+                       int ld_errno = 0;
+                       ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &ld_errno);
+                       if (ld_errno == LDAP_NO_SUCH_ATTRIBUTE) {
                                printf("  Could not locate value \"%s\"\n", 
                                                                new_value);
                                continue;
@@ -963,9 +965,9 @@ int offset;
                        mod.mod_op = LDAP_MOD_DELETE;
 #ifdef DEBUG
                        if (debug & D_GROUPS) {
-                               register LDAPMod **lpp;
-                               register char **cp;
-                               register int i, j;
+                               LDAPMod **lpp;
+                               char **cp;
+                               int i, j;
                                printf("  About to call ldap_modify_s()\n");
                                printf("  ld = 0x%x\n", ld);
                                printf("  dn = [%s]\n", group);
@@ -984,7 +986,9 @@ int offset;
                                *  A "No such attribute" error is no big deal.
                                *  We only wanted to clear the attribute anyhow.
                                */
-                               if (ld->ld_errno != LDAP_NO_SUCH_ATTRIBUTE) {
+                               int ld_errno = 0;
+                               ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &ld_errno);
+                               if (ld_errno != LDAP_NO_SUCH_ATTRIBUTE) {
                                        mod_perror(ld);
                                        return;
                                }
@@ -1001,10 +1005,8 @@ int offset;
        }
 }
 
-my_ldap_modify_s(ldap, group, mods)
-LDAP *ldap;
-char *group;
-LDAPMod *mods[];
+int
+my_ldap_modify_s( LDAP *ldap, char *group, LDAPMod **mods )
 {
        int     was_rfc822member, rc;
 
@@ -1023,8 +1025,8 @@ LDAPMod *mods[];
        return(rc);
 }
 
-void list_groups(who)
-char *who;
+void
+list_groups( char *who )
 {
        LDAPMessage *mp;
        char name[BUFSIZ], filter[BUFSIZ], *search_attrs[2];
@@ -1072,7 +1074,7 @@ char *who;
 
        /* lookup the groups belonging to this person */
        sprintf(filter, "owner=%s", dn);
-       Free(dn);
+       ldap_memfree(dn);
        search_attrs[0] = "cn";
        search_attrs[1] = NULL;
        if ((rc = ldap_search_s(ld, UD_WHERE_ALL_GROUPS_LIVE, LDAP_SCOPE_SUBTREE, 
@@ -1102,12 +1104,11 @@ char *who;
        return;
 }
 
-static char * bind_and_fetch(name)
-char *name;
+static char *
+bind_and_fetch( char *name )
 {
        LDAPMessage *lm;
        char tmp[MED_BUF_SIZE];
-       extern char * strip_ignore_chars();
 
 #ifdef DEBUG
        if (debug & D_TRACE) {
@@ -1157,8 +1158,8 @@ char *name;
        return(strdup(Entry.DN));
 }
 
-void list_memberships(who)
-char *who;
+void
+list_memberships( char *who )
 {
        LDAPMessage *mp;
        char name[BUFSIZ], filter[BUFSIZ], *search_attrs[2];
@@ -1206,7 +1207,7 @@ char *who;
 
        /* lookup the groups belonging to this person */
        sprintf(filter, "member=%s", dn);
-       Free(dn);
+       ldap_memfree(dn);
        search_attrs[0] = "cn";
        search_attrs[1] = NULL;
        ldap_msgfree(mp);