Hi,

Here's the patch that includes this afternoon's fix for current CVS,
together with some other things:

- fix passdb, don't loop when loading all backends fails
- passdb fails when loading of at least one backend fails
- convert net to popt
- convert status to popt
- adapt examples/pdb/ to multiple passdb system
- add dynamic debug class example to examples/pdb/

The other patch I've attached is an attempt to convert testparm to
popt. It strangely crashes at lp_save_defaults however, and I can't
figure out why. Maybe someone else is smarter than I am ;-)

Jelmer

-- 
Jelmer Vernooij <[EMAIL PROTECTED]> - http://nl.linux.org/~jelmer/
Development And Underdevelopment: http://library.thinkquest.org/C0110231/
 20:55:47 up 5 days, 20:09, 15 users,  load average: 4.11, 4.33, 3.55
Index: source/utils/testparm.c
===================================================================
RCS file: /cvsroot/samba/source/utils/testparm.c,v
retrieving revision 1.47
diff -u -3 -p -r1.47 testparm.c
--- source/utils/testparm.c     9 May 2002 04:07:49 -0000       1.47
+++ source/utils/testparm.c     23 May 2002 18:56:27 -0000
@@ -4,6 +4,7 @@
    Copyright (C) Karl Auer 1993, 1994-1998
 
    Extensively modified by Andrew Tridgell, 1995
+   Converted to popt by Jelmer Vernooij ([EMAIL PROTECTED]), 2002
    
    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
@@ -170,158 +171,124 @@ via the %%o substitution. With encrypted
        return ret;
 }   
 
-static void usage(char *pname)
+int main(int argc, char *argv[])
 {
-       printf("Usage: %s [-sh] [-L servername] [configfilename] [hostname hostIP]\n", 
pname);
-       printf("\t-s                  Suppress prompt for enter\n");
-       printf("\t-h                  Print usage\n");
-       printf("\t-L servername       Set %%L macro to servername\n");
-       printf("\t-t encoding         Print parameters with encoding\n");
-       printf("\tconfigfilename      Configuration file to test\n");
-       printf("\thostname hostIP.    Hostname and Host IP address to test\n");
-       printf("\t                    against \"host allow\" and \"host deny\"\n");
-       printf("\n");
-}
+       extern char *optarg;
+       extern int optind;
+       extern fstring local_machine;
+       char *config_file = dyn_CONFIGFILE;
+       int s;
+       BOOL silent_mode = False;
+       int ret = 0;
+       int opt;
+       poptContext pc;
+       static char *term_code = "";
+       static char *new_local_machine = local_machine;
+       const char *cname;
+       const char *caddr;
+
+       struct poptOption long_options[] = {
+               POPT_AUTOHELP
+               {"suppress-prompt", 's', POPT_ARG_VAL, &silent_mode, 1, "Suppress 
+prompt for enter"},
+               {"server", 'L',POPT_ARG_STRING, &new_local_machine, 0, "Set %%L macro 
+to servername\n"},
+               {"encoding", 't', POPT_ARG_STRING, &term_code, 0, "Print parameters 
+with encoding"},
+               {0,0,0,0}
+       };
+
+       pc = poptGetContext(NULL, argc, (const char **) argv, long_options, 
+                                               POPT_CONTEXT_KEEP_FIRST);
+
+       while((opt = poptGetNextOpt(pc)) != -1);
+
+       setup_logging((char *)poptGetArg(pc), True);
+
+       if(poptPeekArg(pc))config_file = poptGetArg(pc);
+       cname = poptGetArg(pc);
+       caddr = poptGetArg(pc);
+
+       fstrcpy(local_machine,new_local_machine);
+
+       dbf = x_stdout;
+       DEBUGLEVEL = 2;
+       AllowDebugChange = False;
+
+       printf("Load smb config files from %s\n",config_file);
+
+       if (!lp_load(config_file,False,True,False)) {
+               printf("Error loading services.\n");
+               return(1);
+       }
 
+       printf("Loaded services file OK.\n");
 
-int main(int argc, char *argv[])
-{
-  extern char *optarg;
-  extern int optind;
-  extern fstring local_machine;
-  pstring configfile;
-  int opt;
-  int s;
-  BOOL silent_mode = False;
-  int ret = 0;
-  pstring term_code;
-
-  *term_code = 0;
-
-  setup_logging(argv[0],True);
-  
-  while ((opt = getopt(argc, argv,"shL:t:")) != EOF) {
-  switch (opt) {
-    case 's':
-      silent_mode = True;
-      break;
-    case 'L':
-      fstrcpy(local_machine,optarg);
-      break;
-    case 'h':
-      usage(argv[0]);
-      exit(0);
-      break;
-    case 't':
-      pstrcpy(term_code,optarg);
-      break;
-    default:
-      printf("Incorrect program usage\n");
-      usage(argv[0]);
-      exit(1);
-      break;
-    }
-  }
-
-  argc += (1 - optind);
-
-  if ((argc == 1) || (argc == 3))
-    pstrcpy(configfile, dyn_CONFIGFILE);
-  else if ((argc == 2) || (argc == 4))
-    pstrcpy(configfile,argv[optind]);
-
-  dbf = x_stdout;
-  DEBUGLEVEL = 2;
-  AllowDebugChange = False;
-
-  printf("Load smb config files from %s\n",configfile);
-
-  if (!lp_load(configfile,False,True,False)) {
-      printf("Error loading services.\n");
-      return(1);
-  }
-
-  printf("Loaded services file OK.\n");
-
-  ret = do_global_checks();
-
-  for (s=0;s<1000;s++) {
-    if (VALID_SNUM(s))
-      if (strlen(lp_servicename(s)) > 8) {
-        printf("WARNING: You have some share names that are longer than 8 chars\n");
-        printf("These may give errors while browsing or may not be accessible\nto 
some older clients\n");
-        break;
-      }
-  }
-
-  for (s=0;s<1000;s++) {
-    if (VALID_SNUM(s)) {
-      char **deny_list = lp_hostsdeny(s);
-      char **allow_list = lp_hostsallow(s);
-      int i;
-      if(deny_list) {
-        for (i=0; deny_list[i]; i++) {
-          char *hasstar = strchr_m(deny_list[i], '*');
-          char *hasquery = strchr_m(deny_list[i], '?');
-          if(hasstar || hasquery) {
-            printf("Invalid character %c in hosts deny list (%s) for service %s.\n",
-                 hasstar ? *hasstar : *hasquery, deny_list[i], lp_servicename(s) );
-         }
-        }
-      }
-
-      if(allow_list) {
-        for (i=0; allow_list[i]; i++) {
-          char *hasstar = strchr_m(allow_list[i], '*');
-          char *hasquery = strchr_m(allow_list[i], '?');
-          if(hasstar || hasquery) {
-            printf("Invalid character %c in hosts allow list (%s) for service %s.\n",
-                 hasstar ? *hasstar : *hasquery, allow_list[i], lp_servicename(s) );
-         }
-        }
-      }
-
-      if(lp_level2_oplocks(s) && !lp_oplocks(s)) {
-        printf("Invalid combination of parameters for service %s. \
-Level II oplocks can only be set if oplocks are also set.\n",
-               lp_servicename(s) );
-      }
-    }
-  }
-
-  if (argc < 3) {
-    if (!silent_mode) {
-      printf("Press enter to see a dump of your service definitions\n");
-      fflush(stdout);
-      getc(stdin);
-    }
-    lp_dump(stdout,True, lp_numservices());
-  }
-  
-  if (argc >= 3) {
-    char *cname;
-    char *caddr;
-      
-    if (argc == 3) {
-      cname = argv[optind];
-      caddr = argv[optind+1];
-    } else {
-      cname = argv[optind+1];
-      caddr = argv[optind+2];
-    }
-
-    /* this is totally ugly, a real `quick' hack */
-    for (s=0;s<1000;s++) {
-      if (VALID_SNUM(s)) {              
-        if (allow_access(lp_hostsdeny(s),lp_hostsallow(s),cname,caddr)) {
-          printf("Allow connection from %s (%s) to %s\n",
-                 cname,caddr,lp_servicename(s));
-        } else {
-          printf("Deny connection from %s (%s) to %s\n",
-                 cname,caddr,lp_servicename(s));
-        }
-      }
-    }
-  }
-  return(ret);
+       ret = do_global_checks();
+
+       for (s=0;s<1000;s++) {
+               if (VALID_SNUM(s))
+                       if (strlen(lp_servicename(s)) > 8) {
+                               printf("WARNING: You have some share names that are 
+longer than 8 chars\n");
+                               printf("These may give errors while browsing or may 
+not be accessible\nto some older clients\n");
+                               break;
+                       }
+       }
+
+       for (s=0;s<1000;s++) {
+               if (VALID_SNUM(s)) {
+                       char **deny_list = lp_hostsdeny(s);
+                       char **allow_list = lp_hostsallow(s);
+                       int i;
+                       if(deny_list) {
+                               for (i=0; deny_list[i]; i++) {
+                                       char *hasstar = strchr_m(deny_list[i], '*');
+                                       char *hasquery = strchr_m(deny_list[i], '?');
+                                       if(hasstar || hasquery) {
+                                               printf("Invalid character %c in hosts 
+deny list (%s) for service %s.\n",
+                                                          hasstar ? *hasstar : 
+*hasquery, deny_list[i], lp_servicename(s) );
+                                       }
+                               }
+                       }
+
+                       if(allow_list) {
+                               for (i=0; allow_list[i]; i++) {
+                                       char *hasstar = strchr_m(allow_list[i], '*');
+                                       char *hasquery = strchr_m(allow_list[i], '?');
+                                       if(hasstar || hasquery) {
+                                               printf("Invalid character %c in hosts 
+allow list (%s) for service %s.\n",
+                                                          hasstar ? *hasstar : 
+*hasquery, allow_list[i], lp_servicename(s) );
+                                       }
+                               }
+                       }
+
+                       if(lp_level2_oplocks(s) && !lp_oplocks(s)) {
+                               printf("Invalid combination of parameters for service 
+%s. \
+                                          Level II oplocks can only be set if oplocks 
+are also set.\n",
+                                          lp_servicename(s) );
+                       }
+               }
+       }
+
+       if (!cname) {
+               if (!silent_mode) {
+                       printf("Press enter to see a dump of your service 
+definitions\n");
+                       fflush(stdout);
+                       getc(stdin);
+               }
+               lp_dump(stdout,True, lp_numservices());
+       }
+
+       if(cname && caddr){
+               /* this is totally ugly, a real `quick' hack */
+               for (s=0;s<1000;s++) {
+                       if (VALID_SNUM(s)) {             
+                               if 
+(allow_access(lp_hostsdeny(s),lp_hostsallow(s),cname,caddr)) {
+                                       printf("Allow connection from %s (%s) to %s\n",
+                                                  cname,caddr,lp_servicename(s));
+                               } else {
+                                       printf("Deny connection from %s (%s) to %s\n",
+                                                  cname,caddr,lp_servicename(s));
+                               }
+                       }
+               }
+       }
+       return(ret);
 }
Index: examples/pdb/pdb_test.c
===================================================================
RCS file: /cvsroot/samba/examples/pdb/pdb_test.c,v
retrieving revision 1.1
diff -u -3 -p -r1.1 pdb_test.c
--- examples/pdb/pdb_test.c     22 Feb 2002 02:57:49 -0000      1.1
+++ examples/pdb/pdb_test.c     23 May 2002 18:56:15 -0000
@@ -17,11 +17,15 @@
  * Mass Ave, Cambridge, MA 02139, USA.
  */
 
+
 #include "includes.h"
+static int testsam_debug_level = DBGC_ALL;
+#undef DBGC_CLASS
+#define DBGC_CLASS testsam_debug_level
 
-static BOOL testsam_setsampwent(struct pdb_context *context, BOOL update)
+static BOOL testsam_setsampwent(struct pdb_methods *methods, BOOL update)
 {
-       DEBUG(0, ("testsam_setsampwent called\n"));
+       DEBUG(10, ("testsam_setsampwent called\n"));
        return True;
 }
 
@@ -29,18 +33,18 @@ static BOOL testsam_setsampwent(struct p
  End enumeration of the passwd list.
 ****************************************************************/
 
-static void testsam_endsampwent(struct pdb_context *context)
+static void testsam_endsampwent(struct pdb_methods *methods)
 {
-       DEBUG(0, ("testsam_endsampwent called\n"));
+       DEBUG(10, ("testsam_endsampwent called\n"));
 }
 
 /*****************************************************************
  Get one SAM_ACCOUNT from the list (next in line)
 *****************************************************************/
 
-static BOOL testsam_getsampwent(struct pdb_context *context, SAM_ACCOUNT *user)
+static BOOL testsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT *user)
 {
-       DEBUG(0, ("testsam_getsampwent called\n"));
+       DEBUG(10, ("testsam_getsampwent called\n"));
        return False;
 }
 
@@ -48,9 +52,9 @@ static BOOL testsam_getsampwent(struct p
  Lookup a name in the SAM database
 ******************************************************************/
 
-static BOOL testsam_getsampwnam (struct pdb_context *context, SAM_ACCOUNT *user, 
const char *sname)
+static BOOL testsam_getsampwnam (struct pdb_methods *methods, SAM_ACCOUNT *user, 
+const char *sname)
 {
-       DEBUG(0, ("testsam_getsampwnam called\n"));
+       DEBUG(10, ("testsam_getsampwnam called\n"));
        return False;
 }
 
@@ -58,9 +62,9 @@ static BOOL testsam_getsampwnam (struct 
  Search by rid
  **************************************************************************/
 
-static BOOL testsam_getsampwrid (struct pdb_context *context, SAM_ACCOUNT *user, 
uint32 rid)
+static BOOL testsam_getsampwrid (struct pdb_methods *methods, SAM_ACCOUNT *user, 
+uint32 rid)
 {
-       DEBUG(0, ("testsam_getsampwrid called\n"));
+       DEBUG(10, ("testsam_getsampwrid called\n"));
        return False;
 }
 
@@ -68,9 +72,9 @@ static BOOL testsam_getsampwrid (struct 
  Delete a SAM_ACCOUNT
 ****************************************************************************/
 
-static BOOL testsam_delete_sam_account(struct pdb_context *context, const SAM_ACCOUNT 
*sam_pass)
+static BOOL testsam_delete_sam_account(struct pdb_methods *methods, const SAM_ACCOUNT 
+*sam_pass)
 {
-       DEBUG(0, ("testsam_delete_sam_account called\n"));
+       DEBUG(10, ("testsam_delete_sam_account called\n"));
        return False;
 }
 
@@ -78,9 +82,9 @@ static BOOL testsam_delete_sam_account(s
  Modifies an existing SAM_ACCOUNT
 ****************************************************************************/
 
-static BOOL testsam_update_sam_account (struct pdb_context *context, const 
SAM_ACCOUNT *newpwd)
+static BOOL testsam_update_sam_account (struct pdb_methods *methods, const 
+SAM_ACCOUNT *newpwd)
 {
-       DEBUG(0, ("testsam_update_sam_account called\n"));
+       DEBUG(10, ("testsam_update_sam_account called\n"));
        return False;
 }
 
@@ -88,9 +92,9 @@ static BOOL testsam_update_sam_account (
  Adds an existing SAM_ACCOUNT
 ****************************************************************************/
 
-static BOOL testsam_add_sam_account (struct pdb_context *context, const SAM_ACCOUNT 
*newpwd)
+static BOOL testsam_add_sam_account (struct pdb_methods *methods, const SAM_ACCOUNT 
+*newpwd)
 {
-       DEBUG(0, ("testsam_add_sam_account called\n"));
+       DEBUG(10, ("testsam_add_sam_account called\n"));
        return False;
 }
 
@@ -112,10 +116,16 @@ NTSTATUS pdb_init(PDB_CONTEXT *pdb_conte
        (*pdb_method)->add_sam_account = testsam_add_sam_account;
        (*pdb_method)->update_sam_account = testsam_update_sam_account;
        (*pdb_method)->delete_sam_account = testsam_delete_sam_account;
+
+       testsam_debug_level = debug_add_class("testsam");
+       if(testsam_debug_level == -1) {
+               testsam_debug_level = DBGC_ALL;
+               DEBUG(0, ("testsam: Couldn't register custom debugging class!\n"));
+       }else DEBUG(0, ("testsam: Debug class number of 'testsam': %d\n", 
+testsam_debug_level));
     
        DEBUG(0, ("Initializing testsam\n"));
        if (location)
-               DEBUG(0, ("Location: %s\n", location));
+               DEBUG(10, ("Location: %s\n", location));
 
        return NT_STATUS_OK;
 }
Index: source/include/config.h.in
===================================================================
RCS file: /cvsroot/samba/source/include/config.h.in,v
retrieving revision 1.173
diff -u -3 -p -r1.173 config.h.in
--- source/include/config.h.in  17 May 2002 12:42:34 -0000      1.173
+++ source/include/config.h.in  23 May 2002 18:56:19 -0000
@@ -1,4 +1,4 @@
-/* include/config.h.in.  Generated automatically from configure.in by autoheader.  */
+/* include/config.h.in.  Generated automatically from configure.in by autoheader 
+2.13.  */
 
 /* Define if on AIX 3.
    System headers sometimes define this.
Index: source/passdb/pdb_interface.c
===================================================================
RCS file: /cvsroot/samba/source/passdb/pdb_interface.c,v
retrieving revision 1.14
diff -u -3 -p -r1.14 pdb_interface.c
--- source/passdb/pdb_interface.c       18 May 2002 15:09:21 -0000      1.14
+++ source/passdb/pdb_interface.c       23 May 2002 18:56:22 -0000
@@ -340,7 +340,7 @@ NTSTATUS make_pdb_context_name(struct pd
                if(!NT_STATUS_IS_OK(make_pdb_methods_name(&curmethods, *context, 
confcur))){
                        DEBUG(5, ("Loading %s failed!\n", confcur));
                        SAFE_FREE(curmethods);
-                       continue;
+                       return NT_STATUS_INVALID_PARAMETER;
                }
                curmethods->parent = *context;
                DLIST_ADD_END((*context)->pdb_methods, curmethods, tmpmethods);
@@ -350,9 +350,7 @@ NTSTATUS make_pdb_context_name(struct pd
        }
        SAFE_FREE(conf);
 
-       nt_status = NT_STATUS_OK;
-
-       return nt_status;
+       return NT_STATUS_OK;
 }
 
 /******************************************************************
Index: source/utils/net.c
===================================================================
RCS file: /cvsroot/samba/source/utils/net.c,v
retrieving revision 1.44
diff -u -3 -p -r1.44 net.c
--- source/utils/net.c  9 May 2002 23:49:40 -0000       1.44
+++ source/utils/net.c  23 May 2002 18:56:24 -0000
@@ -356,7 +356,7 @@ static struct functable net_func[] = {
        const char ** argv_new;
        poptContext pc;
        static char *servicesf = dyn_CONFIGFILE;
-       static int debuglevel = 0;
+       static char *debuglevel = NULL;
 
        struct poptOption long_options[] = {
                {"help",        'h', POPT_ARG_NONE,   0, 'h'},
@@ -367,8 +367,8 @@ static struct functable net_func[] = {
                {"port",        'p', POPT_ARG_INT,    &opt_port},
                {"myname",      'n', POPT_ARG_STRING, &opt_requester_name},
                {"conf",        's', POPT_ARG_STRING, &servicesf},
-               {"debug",       'd', POPT_ARG_INT,    &debuglevel},
-               {"debuglevel",  'd', POPT_ARG_INT,    &debuglevel},
+               {"debug",       'd', POPT_ARG_STRING,    &debuglevel},
+               {"debuglevel",  'd', POPT_ARG_STRING,    &debuglevel},
                {"server",      'S', POPT_ARG_STRING, &opt_host},
                {"comment",     'C', POPT_ARG_STRING, &opt_comment},
                {"maxusers",    'M', POPT_ARG_INT,    &opt_maxusers},
@@ -418,7 +418,9 @@ static struct functable net_func[] = {
 
        lp_load(servicesf,True,False,False);       
 
-       DEBUGLEVEL = debuglevel;
+       if(debuglevel){
+               debug_parse_levels(debuglevel);
+       }
 
        argv_new = (const char **)poptGetArgs(pc);
 
Index: source/utils/pdbedit.c
===================================================================
RCS file: /cvsroot/samba/source/utils/pdbedit.c,v
retrieving revision 1.45
diff -u -3 -p -r1.45 pdbedit.c
--- source/utils/pdbedit.c      18 May 2002 15:09:21 -0000      1.45
+++ source/utils/pdbedit.c      23 May 2002 18:56:24 -0000
@@ -411,7 +411,7 @@ int main (int argc, char **argv)
        static char *logon_script = NULL;
        static char *profile_path = NULL;
        static char *config_file = dyn_CONFIGFILE;
-       static int new_debuglevel = -1;
+       static char *new_debuglevel = NULL;
 
        struct pdb_context *in;
        poptContext pc;
@@ -431,22 +431,21 @@ int main (int argc, char **argv)
                {"delete",      'x',POPT_ARG_VAL,&delete_user,1,"delete user",NULL},
                {"import",      'i',POPT_ARG_STRING,&backend_in,0,"use different 
passdb backend",NULL},
                {"export",      'e',POPT_ARG_STRING,&backend_out,0,"export user 
accounts to backend", NULL},
-               {"debuglevel",'D', POPT_ARG_INT, &new_debuglevel,0,"set 
debuglevel",NULL},
+               {"debuglevel",'D', POPT_ARG_STRING, &new_debuglevel,0,"set 
+debuglevel",NULL},
                {"configfile",'c',POPT_ARG_STRING, &config_file,0,"use different 
configuration file",NULL},
                {0,0,0,0}
        };
 
-       DEBUGLEVEL = 1;
        setup_logging("pdbedit", True);
-       AllowDebugChange = False;
 
        pc = poptGetContext(NULL, argc, (const char **) argv, long_options,
                                                POPT_CONTEXT_KEEP_FIRST);
 
        while((opt = poptGetNextOpt(pc)) != -1);
 
-       if (new_debuglevel != -1) {
-               DEBUGLEVEL = new_debuglevel;
+       if(new_debuglevel){
+               debug_parse_levels(new_debuglevel);
+               AllowDebugChange = False;
        }
 
        if (!lp_load(config_file,True,False,False)) {
@@ -454,6 +453,7 @@ int main (int argc, char **argv)
                                config_file);
                exit(1);
        }
+
 
        if (!backend_in) {
                backend_in = lp_passdb_backend();
Index: source/utils/status.c
===================================================================
RCS file: /cvsroot/samba/source/utils/status.c,v
retrieving revision 1.74
diff -u -3 -p -r1.74 status.c
--- source/utils/status.c       22 May 2002 12:44:45 -0000      1.74
+++ source/utils/status.c       23 May 2002 18:56:26 -0000
@@ -546,7 +546,7 @@ static int traverse_sessionid(TDB_CONTEX
 {
        int c;
        static int profile_only = 0;
-       static int new_debuglevel = -1;
+       static char *new_debuglevel = NULL;
        TDB_CONTEXT *tdb;
        poptContext pc;
        struct poptOption long_options[] = {
@@ -559,7 +559,7 @@ static int traverse_sessionid(TDB_CONTEX
                {"brief",       'b', POPT_ARG_NONE,     &brief},
                {"profile",     'P', POPT_ARG_NONE,     &profile_only},
                {"byterange",   'B', POPT_ARG_NONE,     &show_brl},
-               {"debug",       'd', POPT_ARG_INT,      &new_debuglevel},
+               {"debug",       'd', POPT_ARG_STRING,   &new_debuglevel},
                { 0, 0, 0, 0}
        };
 
@@ -597,8 +597,8 @@ static int traverse_sessionid(TDB_CONTEX
                return (-1);
        }
        
-       if (new_debuglevel != -1) {
-               DEBUGLEVEL = new_debuglevel;
+       if (new_debuglevel) {
+               debug_parse_levels(new_debuglevel);
        }
 
        if (verbose) {

Attachment: msg00945/pgp00000.pgp
Description: PGP signature

Reply via email to