smbstatus: always initialize a messaing context
[samba.git] / source3 / utils / status.c
index afbba69126a0d3de91dfe11eed66b8eababe26e2..8d84537c4955c483b87a26e7525e14735f11528d 100644 (file)
@@ -45,6 +45,7 @@
 #include "lib/conn_tdb.h"
 #include "serverid.h"
 #include "status_profile.h"
+#include "smbd/notifyd/notifyd.h"
 
 #define SMB_MAXPIDS            2048
 static uid_t           Ucrit_uid = 0;               /* added by OH */
@@ -116,6 +117,7 @@ static bool Ucrit_addPid( struct server_id pid )
 static int print_share_mode(const struct share_mode_entry *e,
                            const char *sharepath,
                            const char *fname,
+                           const char *sname,
                            void *dummy)
 {
        static int count;
@@ -189,7 +191,10 @@ static int print_share_mode(const struct share_mode_entry *e,
                        d_printf("NONE            ");
                }
 
-               d_printf(" %s   %s   %s",sharepath, fname, time_to_asc((time_t)e->time.tv_sec));
+               d_printf(" %s   %s%s   %s",
+                        sharepath, fname,
+                        sname ? sname : "",
+                        time_to_asc((time_t)e->time.tv_sec));
        }
 
        return 0;
@@ -326,27 +331,17 @@ static int traverse_sessionid(const char *key, struct sessionid *session,
 }
 
 
-static void print_notify_recs(const char *path,
-                             struct notify_db_entry *entries,
-                             size_t num_entries,
-                             time_t deleted_time, void *private_data)
+static bool print_notify_rec(const char *path, struct server_id server,
+                            const struct notify_instance *instance,
+                            void *private_data)
 {
-       size_t i;
-       d_printf("%s\n", path);
+       struct server_id_buf idbuf;
 
-       if (num_entries == 0) {
-               d_printf("deleted %s\n", time_to_asc(deleted_time));
-       }
-
-       for (i=0; i<num_entries; i++) {
-               struct notify_db_entry *e = &entries[i];
-               struct server_id_buf idbuf;
+       d_printf("%s\\%s\\%x\\%x\n", path, server_id_str_buf(server, &idbuf),
+                (unsigned)instance->filter,
+                (unsigned)instance->subdir_filter);
 
-               printf("%s %x %x\n", server_id_str_buf(e->server, &idbuf),
-                      (unsigned)e->filter,
-                      (unsigned)e->subdir_filter);
-       }
-       printf("\n");
+       return true;
 }
 
 int main(int argc, const char *argv[])
@@ -375,7 +370,7 @@ int main(int argc, const char *argv[])
        };
        TALLOC_CTX *frame = talloc_stackframe();
        int ret = 0;
-       struct messaging_context *msg_ctx;
+       struct messaging_context *msg_ctx = NULL;
        char *db_path;
        bool ok;
 
@@ -383,6 +378,7 @@ int main(int argc, const char *argv[])
        smb_init_locale();
 
        setup_logging(argv[0], DEBUG_STDERR);
+       lp_set_cmdline("log level", "0");
 
        if (getuid() != geteuid()) {
                d_printf("smbstatus should not be run setuid\n");
@@ -460,18 +456,15 @@ int main(int argc, const char *argv[])
        }
 
 
-       if (lp_clustering()) {
-               /*
-                * This implicitly initializes the global ctdbd
-                * connection, usable by the db_open() calls further
-                * down.
-                */
-               msg_ctx = messaging_init(NULL, samba_tevent_context_init(NULL));
-               if (msg_ctx == NULL) {
-                       fprintf(stderr, "messaging_init failed\n");
-                       ret = -1;
-                       goto done;
-               }
+       /*
+        * This implicitly initializes the global ctdbd connection,
+        * usable by the db_open() calls further down.
+        */
+       msg_ctx = messaging_init(NULL, samba_tevent_context_init(NULL));
+       if (msg_ctx == NULL) {
+               fprintf(stderr, "messaging_init failed\n");
+               ret = -1;
+               goto done;
        }
 
        if (!lp_load_global(get_dyn_CONFIGFILE())) {
@@ -586,11 +579,12 @@ int main(int argc, const char *argv[])
        if (show_notify) {
                struct notify_context *n;
 
-               n = notify_init(talloc_tos(), NULL, NULL);
+               n = notify_init(talloc_tos(), msg_ctx,
+                               messaging_tevent_context(msg_ctx));
                if (n == NULL) {
                        goto done;
                }
-               notify_walk(n, print_notify_recs, NULL);
+               notify_walk(n, print_notify_rec, NULL);
                TALLOC_FREE(n);
        }