Fix a bunch of compiler warnings about wrong format types.
[ira/wip.git] / source3 / utils / status.c
index 96f4ae68886bfca3ba8b687dfd7e1a489e3e4870..cbf0dcb2b5a283270256ef021fec5435f31d6f9e 100644 (file)
@@ -38,17 +38,17 @@ static struct server_id     Ucrit_pid[SMB_MAXPIDS];  /* Ugly !!! */   /* added by OH
 static int             Ucrit_MaxPid=0;                    /* added by OH */
 static unsigned int    Ucrit_IsActive = 0;                /* added by OH */
 
-static int verbose, brief;
-static int            shares_only = 0;            /* Added by RJS */
-static int            locks_only  = 0;            /* Added by RJS */
-static BOOL processes_only=False;
-static int show_brl;
-static BOOL numeric_only = False;
+static bool verbose, brief;
+static bool shares_only;            /* Added by RJS */
+static bool locks_only;            /* Added by RJS */
+static bool processes_only;
+static bool show_brl;
+static bool numeric_only;
 
 const char *username = NULL;
 
-extern BOOL status_profile_dump(BOOL be_verbose);
-extern BOOL status_profile_rates(BOOL be_verbose);
+extern bool status_profile_dump(bool be_verbose);
+extern bool status_profile_rates(bool be_verbose);
 
 /* added by OH */
 static void Ucrit_addUid(uid_t uid)
@@ -83,7 +83,7 @@ static unsigned int Ucrit_checkPid(struct server_id pid)
        return 0;
 }
 
-static BOOL Ucrit_addPid( struct server_id pid )
+static bool Ucrit_addPid( struct server_id pid )
 {
        if ( !Ucrit_IsActive )
                return True;
@@ -258,8 +258,8 @@ static int traverse_sessionid(struct db_record *db, void *state)
 
        Ucrit_addPid( sessionid.pid );
 
-       fstr_sprintf(uid_str, "%d", sessionid.uid);
-       fstr_sprintf(gid_str, "%d", sessionid.gid);
+       fstr_sprintf(uid_str, "%u", (unsigned int)sessionid.uid);
+       fstr_sprintf(gid_str, "%u", (unsigned int)sessionid.gid);
 
        d_printf("%-7s   %-12s  %-12s  %-12s (%s)\n",
                 procid_str_static(&sessionid.pid),
@@ -277,25 +277,26 @@ static int traverse_sessionid(struct db_record *db, void *state)
 {
        int c;
        int profile_only = 0;
-       BOOL show_processes, show_locks, show_shares;
+       bool show_processes, show_locks, show_shares;
        poptContext pc;
        struct poptOption long_options[] = {
                POPT_AUTOHELP
-               {"processes",   'p', POPT_ARG_NONE,     &processes_only, 'p', "Show processes only" },
-               {"verbose",     'v', POPT_ARG_NONE, &verbose, 'v', "Be verbose" },
-               {"locks",       'L', POPT_ARG_NONE,     &locks_only, 'L', "Show locks only" },
-               {"shares",      'S', POPT_ARG_NONE,     &shares_only, 'S', "Show shares only" },
+               {"processes",   'p', POPT_ARG_NONE,     NULL, 'p', "Show processes only" },
+               {"verbose",     'v', POPT_ARG_NONE,     NULL, 'v', "Be verbose" },
+               {"locks",       'L', POPT_ARG_NONE,     NULL, 'L', "Show locks only" },
+               {"shares",      'S', POPT_ARG_NONE,     NULL, 'S', "Show shares only" },
                {"user",        'u', POPT_ARG_STRING,   &username, 'u', "Switch to user" },
-               {"brief",       'b', POPT_ARG_NONE,     &brief, 'b', "Be brief" },
+               {"brief",       'b', POPT_ARG_NONE,     NULL, 'b', "Be brief" },
                {"profile",     'P', POPT_ARG_NONE, NULL, 'P', "Do profiling" },
                {"profile-rates", 'R', POPT_ARG_NONE, NULL, 'R', "Show call rates" },
-               {"byterange",   'B', POPT_ARG_NONE,     &show_brl, 'B', "Include byte range locks"},
-               {"numeric",     'n', POPT_ARG_NONE,     &numeric_only, 'n', "Numeric uid/gid"},
+               {"byterange",   'B', POPT_ARG_NONE,     NULL, 'B', "Include byte range locks"},
+               {"numeric",     'n', POPT_ARG_NONE,     NULL, 'n', "Numeric uid/gid"},
                POPT_COMMON_SAMBA
                POPT_TABLEEND
        };
        TALLOC_CTX *frame = talloc_stackframe();
        int ret = 0;
+       struct messaging_context *msg_ctx;
 
        sec_init();
        load_case_tables();
@@ -315,12 +316,34 @@ static int traverse_sessionid(struct db_record *db, void *state)
        
        while ((c = poptGetNextOpt(pc)) != -1) {
                switch (c) {
-               case 'u':                                      
+               case 'p':
+                       processes_only = true;
+                       break;
+               case 'v':
+                       verbose = true;
+                       break;
+               case 'L':
+                       locks_only = true;
+                       break;
+               case 'S':
+                       shares_only = true;
+                       break;
+               case 'b':
+                       brief = true;
+                       break;
+               case 'u':
                        Ucrit_addUid(nametouid(poptGetOptArg(pc)));
                        break;
                case 'P':
                case 'R':
                        profile_only = c;
+                       break;
+               case 'B':
+                       show_brl = true;
+                       break;
+               case 'n':
+                       numeric_only = true;
+                       break;
                }
        }
 
@@ -334,11 +357,12 @@ static int traverse_sessionid(struct db_record *db, void *state)
                Ucrit_addUid( nametouid(username) );
 
        if (verbose) {
-               d_printf("using configfile = %s\n", dyn_CONFIGFILE);
+               d_printf("using configfile = %s\n", get_dyn_CONFIGFILE());
        }
 
-       if (!lp_load(dyn_CONFIGFILE,False,False,False,True)) {
-               fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE);
+       if (!lp_load_initial_only(get_dyn_CONFIGFILE())) {
+               fprintf(stderr, "Can't load %s - run testparm to debug it\n",
+                       get_dyn_CONFIGFILE());
                ret = -1;
                goto done;
        }
@@ -348,8 +372,22 @@ static int traverse_sessionid(struct db_record *db, void *state)
         * the db_open() calls further down.
         */
 
-       messaging_init(NULL, procid_self(), event_context_init(NULL));
-       
+       msg_ctx = messaging_init(NULL, procid_self(),
+                                event_context_init(NULL));
+
+       if (msg_ctx == NULL) {
+               fprintf(stderr, "messaging_init failed\n");
+               ret = -1;
+               goto done;
+       }
+
+       if (!lp_load(get_dyn_CONFIGFILE(),False,False,False,True)) {
+               fprintf(stderr, "Can't load %s - run testparm to debug it\n",
+                       get_dyn_CONFIGFILE());
+               ret = -1;
+               goto done;
+       }
+
        switch (profile_only) {
                case 'P':
                        /* Dump profile data */
@@ -364,13 +402,17 @@ static int traverse_sessionid(struct db_record *db, void *state)
        if ( show_processes ) {
                struct db_context *db;
                db = db_open(NULL, lock_path("sessionid.tdb"), 0,
-                            TDB_DEFAULT, O_RDWR, 0644);
+                            TDB_CLEAR_IF_FIRST, O_RDONLY, 0644);
                if (!db) {
                        d_printf("sessionid.tdb not initialised\n");
                } else {
-                       d_printf("\nSamba version %s\n",SAMBA_VERSION_STRING);
+                       d_printf("\nSamba version %s\n",samba_version_string());
                        d_printf("PID     Username      Group         Machine                        \n");
                        d_printf("-------------------------------------------------------------------\n");
+                       if (lp_security() == SEC_SHARE) {
+                               d_printf(" <processes do not show up in "
+                                   "anonymous mode>\n");
+                       }
 
                        db->traverse_read(db, traverse_sessionid, NULL);
                        TALLOC_FREE(db);
@@ -404,8 +446,21 @@ static int traverse_sessionid(struct db_record *db, void *state)
 
        if ( show_locks ) {
                int result;
+               struct db_context *db;
+               db = db_open(NULL, lock_path("locking.tdb"), 0,
+                            TDB_CLEAR_IF_FIRST, O_RDONLY, 0);
+
+               if (!db) {
+                       d_printf("%s not initialised\n",
+                                lock_path("locking.tdb"));
+                       d_printf("This is normal if an SMB client has never "
+                                "connected to your server.\n");
+                       exit(0);
+               } else {
+                       TALLOC_FREE(db);
+               }
 
-               if (!locking_init(1)) {
+               if (!locking_init_readonly()) {
                        d_printf("Can't initialise locking module - exiting\n");
                        ret = 1;
                        goto done;