Ignore:
Timestamp:
Sep 30, 2007, 3:42:50 AM (18 years ago)
Author:
Paul Smedley
Message:

Update trunk to 3.2.0pre1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/samba/source/utils/smbcontrol.c

    r22 r77  
    1212   This program is free software; you can redistribute it and/or modify
    1313   it under the terms of the GNU General Public License as published by
    14    the Free Software Foundation; either version 2 of the License, or
     14   the Free Software Foundation; either version 3 of the License, or
    1515   (at your option) any later version.
    1616   
     
    2121   
    2222   You should have received a copy of the GNU General Public License
    23    along with this program; if not, write to the Free Software
    24    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     23   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    2524*/
    2625
     
    4847/* Send a message to a destination pid.  Zero means broadcast smbd. */
    4948
    50 static BOOL send_message(struct process_id pid, int msg_type,
    51                          const void *buf, int len,
    52                          BOOL duplicates)
    53 {
    54         TDB_CONTEXT *tdb;
     49static BOOL send_message(struct messaging_context *msg_ctx,
     50                         struct server_id pid, int msg_type,
     51                         const void *buf, int len)
     52{
    5553        BOOL ret;
    5654        int n_sent = 0;
    5755
    58         if (!message_init())
    59                 return False;
    60 
    6156        if (procid_to_pid(&pid) != 0)
    62                 return NT_STATUS_IS_OK(message_send_pid(pid, msg_type, buf, len,
    63                                                         duplicates));
    64 
    65         tdb = tdb_open_log(lock_path("connections.tdb"), 0,
    66                            TDB_DEFAULT, O_RDWR, 0);
    67         if (!tdb) {
    68                 fprintf(stderr,"Failed to open connections database"
    69                         ": %s\n", strerror(errno));
    70                 return False;
    71         }
    72        
    73         ret = message_send_all(tdb,msg_type, buf, len, duplicates,
    74                                &n_sent);
     57                return NT_STATUS_IS_OK(
     58                        messaging_send_buf(msg_ctx, pid, msg_type,
     59                                           (uint8 *)buf, len));
     60
     61        ret = message_send_all(msg_ctx, msg_type, buf, len, &n_sent);
    7562        DEBUG(10,("smbcontrol/send_message: broadcast message to "
    7663                  "%d processes\n", n_sent));
    7764       
    78         tdb_close(tdb);
    79        
    8065        return ret;
    8166}
    8267
     68static void timeout_handler(struct event_context *event_ctx,
     69                            struct timed_event *te,
     70                            const struct timeval *now,
     71                            void *private_data)
     72{
     73        BOOL *timed_out = (BOOL *)private_data;
     74        TALLOC_FREE(te);
     75        *timed_out = True;
     76}
     77
    8378/* Wait for one or more reply messages */
    8479
    85 static void wait_replies(BOOL multiple_replies)
    86 {
    87         time_t start_time = time(NULL);
    88 
    89         /* Wait around a bit.  This is pretty disgusting - we have to
    90            busy-wait here as there is no nicer way to do it. */
    91 
    92         do {
    93                 message_dispatch();
     80static void wait_replies(struct messaging_context *msg_ctx,
     81                         BOOL multiple_replies)
     82{
     83        struct timed_event *te;
     84        BOOL timed_out = False;
     85
     86        if (!(te = event_add_timed(messaging_event_context(msg_ctx), NULL,
     87                                   timeval_current_ofs(timeout, 0),
     88                                   "smbcontrol_timeout",
     89                                   timeout_handler, (void *)&timed_out))) {
     90                DEBUG(0, ("event_add_timed failed\n"));
     91                return;
     92        }
     93
     94        while (!timed_out) {
     95                message_dispatch(msg_ctx);
    9496                if (num_replies > 0 && !multiple_replies)
    9597                        break;
    96                 sleep(1);
    97         } while (timeout - (time(NULL) - start_time) > 0);
     98                event_loop_once(messaging_event_context(msg_ctx));
     99        }
    98100}
    99101
    100102/* Message handler callback that displays the PID and a string on stdout */
    101103
    102 static void print_pid_string_cb(int msg_type, struct process_id pid, void *buf,
    103                                 size_t len, void *private_data)
     104static void print_pid_string_cb(struct messaging_context *msg,
     105                                void *private_data,
     106                                uint32_t msg_type,
     107                                struct server_id pid,
     108                                DATA_BLOB *data)
    104109{
    105110        printf("PID %u: %.*s", (unsigned int)procid_to_pid(&pid),
    106                (int)len, (const char *)buf);
     111               (int)data->length, (const char *)data->data);
    107112        num_replies++;
    108113}
     
    110115/* Message handler callback that displays a string on stdout */
    111116
    112 static void print_string_cb(int msg_type, struct process_id pid,
    113                             void *buf, size_t len, void *private_data)
    114 {
    115         printf("%.*s", (int)len, (const char *)buf);
     117static void print_string_cb(struct messaging_context *msg,
     118                            void *private_data,
     119                            uint32_t msg_type,
     120                            struct server_id pid,
     121                            DATA_BLOB *data)
     122{
     123        printf("%.*s", (int)data->length, (const char *)data->data);
    116124        num_replies++;
    117125}
     
    119127/* Send no message.  Useful for testing. */
    120128
    121 static BOOL do_noop(const struct process_id pid,
     129static BOOL do_noop(struct messaging_context *msg_ctx,
     130                    const struct server_id pid,
    122131                    const int argc, const char **argv)
    123132{
     
    134143/* Send a debug string */
    135144
    136 static BOOL do_debug(const struct process_id pid,
     145static BOOL do_debug(struct messaging_context *msg_ctx,
     146                     const struct server_id pid,
    137147                     const int argc, const char **argv)
    138148{
     
    143153        }
    144154
    145         return send_message(
    146                 pid, MSG_DEBUG, argv[1], strlen(argv[1]) + 1, False);
     155        return send_message(msg_ctx, pid, MSG_DEBUG, argv[1],
     156                            strlen(argv[1]) + 1);
    147157}
    148158
     
    248258}
    249259
    250 static int stack_trace_connection(TDB_CONTEXT * tdb, TDB_DATA key,
    251         TDB_DATA data, void * priv)
    252 {
    253         struct connections_data conn;
    254 
    255         if (data.dsize != sizeof(conn))
    256                 return 0;
    257 
    258         memcpy(&conn, data.dptr, sizeof(conn));
    259         print_stack_trace(procid_to_pid(&conn.pid), (int *)priv);
     260static int stack_trace_connection(struct db_record *rec,
     261                                  const struct connections_key *key,
     262                                  const struct connections_data *crec,
     263                                  void *priv)
     264{
     265        print_stack_trace(procid_to_pid(&crec->pid), (int *)priv);
    260266
    261267        return 0;
    262268}
    263269
    264 static BOOL do_daemon_stack_trace(const struct process_id pid,
     270static BOOL do_daemon_stack_trace(struct messaging_context *msg_ctx,
     271                                  const struct server_id pid,
    265272                       const int argc, const char **argv)
    266273{
    267         fprintf(stderr,
    268                 "Daemon stack tracing is not supported on this platform\n");
    269         return False;
    270 
    271274        pid_t   dest;
    272275        int     count = 0;
     
    287290                print_stack_trace(dest, &count);
    288291        } else {
    289                 TDB_CONTEXT * tdb;
    290 
    291                 tdb = tdb_open_log(lock_path("connections.tdb"), 0,
    292                                    TDB_DEFAULT, O_RDONLY, 0);
    293                 if (!tdb) {
    294                         fprintf(stderr,
    295                                 "Failed to open connections database: %s\n",
    296                                 strerror(errno));
    297                         return False;
    298                 }
    299 
    300                 tdb_traverse(tdb, stack_trace_connection, &count);
    301                 tdb_close(tdb);
     292                connections_forall(stack_trace_connection, &count);
    302293        }
    303294
     
    307298#else /* defined(HAVE_LIBUNWIND_PTRACE) && defined(HAVE_LINUX_PTRACE) */
    308299
    309 static BOOL do_daemon_stack_trace(const struct process_id pid,
     300static BOOL do_daemon_stack_trace(struct messaging_context *msg_ctx,
     301                                  const struct server_id pid,
    310302                       const int argc, const char **argv)
    311303{
     
    319311/* Inject a fault (fatal signal) into a running smbd */
    320312
    321 static BOOL do_inject_fault(const struct process_id pid,
     313static BOOL do_inject_fault(struct messaging_context *msg_ctx,
     314                            const struct server_id pid,
    322315                       const int argc, const char **argv)
    323316{
     
    352345                }
    353346
    354                 return send_message(pid, MSG_SMB_INJECT_FAULT,
    355                                     &sig, sizeof(int), False);
     347                return send_message(msg_ctx, pid, MSG_SMB_INJECT_FAULT,
     348                                    &sig, sizeof(int));
    356349        }
    357350#endif /* DEVELOPER */
     
    360353/* Force a browser election */
    361354
    362 static BOOL do_election(const struct process_id pid,
     355static BOOL do_election(struct messaging_context *msg_ctx,
     356                        const struct server_id pid,
    363357                        const int argc, const char **argv)
    364358{
     
    368362        }
    369363
    370         return send_message(
    371                 pid, MSG_FORCE_ELECTION, NULL, 0, False);
     364        return send_message(msg_ctx, pid, MSG_FORCE_ELECTION, NULL, 0);
    372365}
    373366
    374367/* Ping a samba daemon process */
    375368
    376 static void pong_cb(int msg_type, struct process_id pid, void *buf,
    377                     size_t len, void *private_data)
     369static void pong_cb(struct messaging_context *msg,
     370                    void *private_data,
     371                    uint32_t msg_type,
     372                    struct server_id pid,
     373                    DATA_BLOB *data)
    378374{
    379375        char *src_string = procid_str(NULL, &pid);
     
    383379}
    384380
    385 static BOOL do_ping(const struct process_id pid, const int argc, const char **argv)
     381static BOOL do_ping(struct messaging_context *msg_ctx,
     382                    const struct server_id pid,
     383                    const int argc, const char **argv)
    386384{
    387385        if (argc != 1) {
     
    392390        /* Send a message and register our interest in a reply */
    393391
    394         if (!send_message(pid, MSG_PING, NULL, 0, False))
    395                 return False;
    396 
    397         message_register(MSG_PONG, pong_cb, NULL);
    398 
    399         wait_replies(procid_to_pid(&pid) == 0);
     392        if (!send_message(msg_ctx, pid, MSG_PING, NULL, 0))
     393                return False;
     394
     395        messaging_register(msg_ctx, NULL, MSG_PONG, pong_cb);
     396
     397        wait_replies(msg_ctx, procid_to_pid(&pid) == 0);
    400398
    401399        /* No replies were received within the timeout period */
     
    404402                printf("No replies received\n");
    405403
    406         message_deregister(MSG_PONG);
     404        messaging_deregister(msg_ctx, MSG_PONG, NULL);
    407405
    408406        return num_replies;
     
    411409/* Set profiling options */
    412410
    413 static BOOL do_profile(const struct process_id pid,
     411static BOOL do_profile(struct messaging_context *msg_ctx,
     412                       const struct server_id pid,
    414413                       const int argc, const char **argv)
    415414{
     
    435434        }
    436435
    437         return send_message(pid, MSG_PROFILE, &v, sizeof(int), False);
     436        return send_message(msg_ctx, pid, MSG_PROFILE, &v, sizeof(int));
    438437}
    439438
    440439/* Return the profiling level */
    441440
    442 static void profilelevel_cb(int msg_type, struct process_id pid, void *buf,
    443                             size_t len, void *private_data)
     441static void profilelevel_cb(struct messaging_context *msg_ctx,
     442                            void *private_data,
     443                            uint32_t msg_type,
     444                            struct server_id pid,
     445                            DATA_BLOB *data)
    444446{
    445447        int level;
     
    448450        num_replies++;
    449451
    450         if (len != sizeof(int)) {
     452        if (data->length != sizeof(int)) {
    451453                fprintf(stderr, "invalid message length %ld returned\n",
    452                         (unsigned long)len);
     454                        (unsigned long)data->length);
    453455                return;
    454456        }
    455457
    456         memcpy(&level, buf, sizeof(int));
     458        memcpy(&level, data->data, sizeof(int));
    457459
    458460        switch (level) {
     
    477479}
    478480
    479 static void profilelevel_rqst(int msg_type, struct process_id pid,
    480                               void *buf, size_t len, void *private_data)
     481static void profilelevel_rqst(struct messaging_context *msg_ctx,
     482                              void *private_data,
     483                              uint32_t msg_type,
     484                              struct server_id pid,
     485                              DATA_BLOB *data)
    481486{
    482487        int v = 0;
     
    484489        /* Send back a dummy reply */
    485490
    486         send_message(pid, MSG_PROFILELEVEL, &v, sizeof(int), False);
    487 }
    488 
    489 static BOOL do_profilelevel(const struct process_id pid,
     491        send_message(msg_ctx, pid, MSG_PROFILELEVEL, &v, sizeof(int));
     492}
     493
     494static BOOL do_profilelevel(struct messaging_context *msg_ctx,
     495                            const struct server_id pid,
    490496                            const int argc, const char **argv)
    491497{
     
    497503        /* Send a message and register our interest in a reply */
    498504
    499         if (!send_message(pid, MSG_REQ_PROFILELEVEL, NULL, 0, False))
    500                 return False;
    501 
    502         message_register(MSG_PROFILELEVEL, profilelevel_cb, NULL);
    503         message_register(MSG_REQ_PROFILELEVEL, profilelevel_rqst, NULL);
    504 
    505         wait_replies(procid_to_pid(&pid) == 0);
     505        if (!send_message(msg_ctx, pid, MSG_REQ_PROFILELEVEL, NULL, 0))
     506                return False;
     507
     508        messaging_register(msg_ctx, NULL, MSG_PROFILELEVEL, profilelevel_cb);
     509        messaging_register(msg_ctx, NULL, MSG_REQ_PROFILELEVEL,
     510                           profilelevel_rqst);
     511
     512        wait_replies(msg_ctx, procid_to_pid(&pid) == 0);
    506513
    507514        /* No replies were received within the timeout period */
     
    510517                printf("No replies received\n");
    511518
    512         message_deregister(MSG_PROFILE);
     519        messaging_deregister(msg_ctx, MSG_PROFILE, NULL);
    513520
    514521        return num_replies;
     
    517524/* Display debug level settings */
    518525
    519 static BOOL do_debuglevel(const struct process_id pid,
     526static BOOL do_debuglevel(struct messaging_context *msg_ctx,
     527                          const struct server_id pid,
    520528                          const int argc, const char **argv)
    521529{
     
    527535        /* Send a message and register our interest in a reply */
    528536
    529         if (!send_message(pid, MSG_REQ_DEBUGLEVEL, NULL, 0, False))
    530                 return False;
    531 
    532         message_register(MSG_DEBUGLEVEL, print_pid_string_cb, NULL);
    533 
    534         wait_replies(procid_to_pid(&pid) == 0);
     537        if (!send_message(msg_ctx, pid, MSG_REQ_DEBUGLEVEL, NULL, 0))
     538                return False;
     539
     540        messaging_register(msg_ctx, NULL, MSG_DEBUGLEVEL, print_pid_string_cb);
     541
     542        wait_replies(msg_ctx, procid_to_pid(&pid) == 0);
    535543
    536544        /* No replies were received within the timeout period */
     
    539547                printf("No replies received\n");
    540548
    541         message_deregister(MSG_DEBUGLEVEL);
     549        messaging_deregister(msg_ctx, MSG_DEBUGLEVEL, NULL);
    542550
    543551        return num_replies;
     
    546554/* Send a print notify message */
    547555
    548 static BOOL do_printnotify(const struct process_id pid,
     556static BOOL do_printnotify(struct messaging_context *msg_ctx,
     557                           const struct server_id pid,
    549558                           const int argc, const char **argv)
    550559{
     
    680689
    681690send:
    682         print_notify_send_messages(0);
     691        print_notify_send_messages(msg_ctx, 0);
    683692        return True;
    684693}
     
    686695/* Close a share */
    687696
    688 static BOOL do_closeshare(const struct process_id pid,
     697static BOOL do_closeshare(struct messaging_context *msg_ctx,
     698                          const struct server_id pid,
    689699                          const int argc, const char **argv)
    690700{
     
    695705        }
    696706
    697         return send_message(
    698                 pid, MSG_SMB_FORCE_TDIS, argv[1], strlen(argv[1]) + 1, False);
     707        return send_message(msg_ctx, pid, MSG_SMB_FORCE_TDIS, argv[1],
     708                            strlen(argv[1]) + 1);
     709}
     710
     711/* force a blocking lock retry */
     712
     713static BOOL do_lockretry(struct messaging_context *msg_ctx,
     714                         const struct server_id pid,
     715                         const int argc, const char **argv)
     716{
     717        if (argc != 1) {
     718                fprintf(stderr, "Usage: smbcontrol <dest> lockretry\n");
     719                return False;
     720        }
     721
     722        return send_message(msg_ctx, pid, MSG_SMB_UNLOCK, NULL, 0);
     723}
     724
     725/* force a validation of all brl entries, including re-sends. */
     726
     727static BOOL do_brl_revalidate(struct messaging_context *msg_ctx,
     728                              const struct server_id pid,
     729                              const int argc, const char **argv)
     730{
     731        if (argc != 1) {
     732                fprintf(stderr, "Usage: smbcontrol <dest> brl-revalidate\n");
     733                return False;
     734        }
     735
     736        return send_message(msg_ctx, pid, MSG_SMB_BRL_VALIDATE, NULL, 0);
    699737}
    700738
    701739/* Force a SAM synchronisation */
    702740
    703 static BOOL do_samsync(const struct process_id pid,
     741static BOOL do_samsync(struct messaging_context *msg_ctx,
     742                       const struct server_id pid,
    704743                       const int argc, const char **argv)
    705744{
     
    709748        }
    710749
    711         return send_message(
    712                 pid, MSG_SMB_SAM_SYNC, NULL, 0, False);
     750        return send_message(msg_ctx, pid, MSG_SMB_SAM_SYNC, NULL, 0);
    713751}
    714752
    715753/* Force a SAM replication */
    716754
    717 static BOOL do_samrepl(const struct process_id pid,
     755static BOOL do_samrepl(struct messaging_context *msg_ctx,
     756                       const struct server_id pid,
    718757                       const int argc, const char **argv)
    719758{
     
    723762        }
    724763
    725         return send_message(
    726                 pid, MSG_SMB_SAM_REPL, NULL, 0, False);
     764        return send_message(msg_ctx, pid, MSG_SMB_SAM_REPL, NULL, 0);
    727765}
    728766
    729767/* Display talloc pool usage */
    730768
    731 static BOOL do_poolusage(const struct process_id pid,
     769static BOOL do_poolusage(struct messaging_context *msg_ctx,
     770                         const struct server_id pid,
    732771                         const int argc, const char **argv)
    733772{
     
    737776        }
    738777
    739         message_register(MSG_POOL_USAGE, print_string_cb, NULL);
     778        messaging_register(msg_ctx, NULL, MSG_POOL_USAGE, print_string_cb);
    740779
    741780        /* Send a message and register our interest in a reply */
    742781
    743         if (!send_message(pid, MSG_REQ_POOL_USAGE, NULL, 0, False))
    744                 return False;
    745 
    746         wait_replies(procid_to_pid(&pid) == 0);
     782        if (!send_message(msg_ctx, pid, MSG_REQ_POOL_USAGE, NULL, 0))
     783                return False;
     784
     785        wait_replies(msg_ctx, procid_to_pid(&pid) == 0);
    747786
    748787        /* No replies were received within the timeout period */
     
    751790                printf("No replies received\n");
    752791
    753         message_deregister(MSG_POOL_USAGE);
     792        messaging_deregister(msg_ctx, MSG_POOL_USAGE, NULL);
    754793
    755794        return num_replies;
     
    758797/* Perform a dmalloc mark */
    759798
    760 static BOOL do_dmalloc_mark(const struct process_id pid,
     799static BOOL do_dmalloc_mark(struct messaging_context *msg_ctx,
     800                            const struct server_id pid,
    761801                            const int argc, const char **argv)
    762802{
     
    766806        }
    767807
    768         return send_message(
    769                 pid, MSG_REQ_DMALLOC_MARK, NULL, 0, False);
     808        return send_message(msg_ctx, pid, MSG_REQ_DMALLOC_MARK, NULL, 0);
    770809}
    771810
    772811/* Perform a dmalloc changed */
    773812
    774 static BOOL do_dmalloc_changed(const struct process_id pid,
     813static BOOL do_dmalloc_changed(struct messaging_context *msg_ctx,
     814                               const struct server_id pid,
    775815                               const int argc, const char **argv)
    776816{
     
    781821        }
    782822
    783         return send_message(
    784                 pid, MSG_REQ_DMALLOC_LOG_CHANGED, NULL, 0, False);
     823        return send_message(msg_ctx, pid, MSG_REQ_DMALLOC_LOG_CHANGED,
     824                            NULL, 0);
    785825}
    786826
    787827/* Shutdown a server process */
    788828
    789 static BOOL do_shutdown(const struct process_id pid,
     829static BOOL do_shutdown(struct messaging_context *msg_ctx,
     830                        const struct server_id pid,
    790831                        const int argc, const char **argv)
    791832{
     
    795836        }
    796837
    797         return send_message(pid, MSG_SHUTDOWN, NULL, 0, False);
     838        return send_message(msg_ctx, pid, MSG_SHUTDOWN, NULL, 0);
    798839}
    799840
    800841/* Notify a driver upgrade */
    801842
    802 static BOOL do_drvupgrade(const struct process_id pid,
     843static BOOL do_drvupgrade(struct messaging_context *msg_ctx,
     844                          const struct server_id pid,
    803845                          const int argc, const char **argv)
    804846{
     
    809851        }
    810852
    811         return send_message(
    812                 pid, MSG_DEBUG, argv[1], strlen(argv[1]) + 1, False);
    813 }
    814 
    815 static BOOL do_winbind_online(const struct process_id pid,
     853        return send_message(msg_ctx, pid, MSG_DEBUG, argv[1],
     854                            strlen(argv[1]) + 1);
     855}
     856
     857static BOOL do_winbind_online(struct messaging_context *msg_ctx,
     858                              const struct server_id pid,
    816859                             const int argc, const char **argv)
    817860{
     
    843886        tdb_close(tdb);
    844887
    845         return send_message(pid, MSG_WINBIND_ONLINE, NULL, 0, False);
    846 }
    847 
    848 static BOOL do_winbind_offline(const struct process_id pid,
     888        return send_message(msg_ctx, pid, MSG_WINBIND_ONLINE, NULL, 0);
     889}
     890
     891static BOOL do_winbind_offline(struct messaging_context *msg_ctx,
     892                               const struct server_id pid,
    849893                             const int argc, const char **argv)
    850894{
     
    888932        for (retry = 0; retry < 5; retry++) {
    889933                TDB_DATA d;
    890                 char buf[4];
     934                uint8 buf[4];
    891935
    892936                ZERO_STRUCT(d);
     
    898942                tdb_store_bystring(tdb, "WINBINDD_OFFLINE", d, TDB_INSERT);
    899943
    900                 ret = send_message(pid, MSG_WINBIND_OFFLINE, NULL, 0, False);
     944                ret = send_message(msg_ctx, pid, MSG_WINBIND_OFFLINE,
     945                                   NULL, 0);
    901946
    902947                /* Check that the entry "WINBINDD_OFFLINE" still exists. */
     
    916961}
    917962
    918 static BOOL do_winbind_onlinestatus(const struct process_id pid,
     963static BOOL do_winbind_onlinestatus(struct messaging_context *msg_ctx,
     964                                    const struct server_id pid,
    919965                                    const int argc, const char **argv)
    920966{
    921         struct process_id myid;
     967        struct server_id myid;
    922968
    923969        myid = pid_to_procid(sys_getpid());
     
    928974        }
    929975
    930         message_register(MSG_WINBIND_ONLINESTATUS, print_pid_string_cb, NULL);
    931 
    932         if (!send_message(pid, MSG_WINBIND_ONLINESTATUS, &myid, sizeof(myid), False))
    933                 return False;
    934 
    935         wait_replies(procid_to_pid(&pid) == 0);
     976        messaging_register(msg_ctx, NULL, MSG_WINBIND_ONLINESTATUS,
     977                           print_pid_string_cb);
     978
     979        if (!send_message(msg_ctx, pid, MSG_WINBIND_ONLINESTATUS, &myid,
     980                          sizeof(myid)))
     981                return False;
     982
     983        wait_replies(msg_ctx, procid_to_pid(&pid) == 0);
    936984
    937985        /* No replies were received within the timeout period */
     
    940988                printf("No replies received\n");
    941989
    942         message_deregister(MSG_WINBIND_ONLINESTATUS);
     990        messaging_deregister(msg_ctx, MSG_WINBIND_ONLINESTATUS, NULL);
    943991
    944992        return num_replies;
    945993}
    946994
    947 
    948 static BOOL do_reload_config(const struct process_id pid,
     995static BOOL do_dump_event_list(struct messaging_context *msg_ctx,
     996                               const struct server_id pid,
     997                               const int argc, const char **argv)
     998{
     999        struct server_id myid;
     1000
     1001        myid = pid_to_procid(sys_getpid());
     1002
     1003        if (argc != 1) {
     1004                fprintf(stderr, "Usage: smbcontrol <dest> dump-event-list\n");
     1005                return False;
     1006        }
     1007
     1008        return send_message(msg_ctx, pid, MSG_DUMP_EVENT_LIST, NULL, 0);
     1009}
     1010
     1011static void winbind_validate_cache_cb(struct messaging_context *msg,
     1012                                      void *private_data,
     1013                                      uint32_t msg_type,
     1014                                      struct server_id pid,
     1015                                      DATA_BLOB *data)
     1016{
     1017        char *src_string = procid_str(NULL, &pid);
     1018        printf("Winbindd cache is %svalid. (answer from pid %s)\n",
     1019               (*(data->data) == 0 ? "" : "NOT "), src_string);
     1020        TALLOC_FREE(src_string);
     1021        num_replies++;
     1022}
     1023
     1024static BOOL do_winbind_validate_cache(struct messaging_context *msg_ctx,
     1025                                      const struct server_id pid,
     1026                                      const int argc, const char **argv)
     1027{
     1028        struct server_id myid = pid_to_procid(sys_getpid());
     1029
     1030        if (argc != 1) {
     1031                fprintf(stderr, "Usage: smbcontrol winbindd validate-cache\n");
     1032                return False;
     1033        }
     1034
     1035        messaging_register(msg_ctx, NULL, MSG_WINBIND_VALIDATE_CACHE,
     1036                           winbind_validate_cache_cb);
     1037
     1038        if (!send_message(msg_ctx, pid, MSG_WINBIND_VALIDATE_CACHE, &myid,
     1039                          sizeof(myid))) {
     1040                return False;
     1041        }
     1042
     1043        wait_replies(msg_ctx, procid_to_pid(&pid) == 0);
     1044
     1045        if (num_replies == 0) {
     1046                printf("No replies received\n");
     1047        }
     1048
     1049        messaging_deregister(msg_ctx, MSG_WINBIND_VALIDATE_CACHE, NULL);
     1050
     1051        return num_replies;
     1052}
     1053
     1054static BOOL do_reload_config(struct messaging_context *msg_ctx,
     1055                             const struct server_id pid,
    9491056                             const int argc, const char **argv)
    9501057{
     
    9541061        }
    9551062
    956         return send_message(pid, MSG_SMB_CONF_UPDATED, NULL, 0, False);
     1063        return send_message(msg_ctx, pid, MSG_SMB_CONF_UPDATED, NULL, 0);
    9571064}
    9581065
     
    9681075}
    9691076
    970 static BOOL do_nodestatus(const struct process_id pid,
     1077static BOOL do_nodestatus(struct messaging_context *msg_ctx,
     1078                          const struct server_id pid,
    9711079                          const int argc, const char **argv)
    9721080{
     
    10011109        p.packet.nmb.question.question_class = 0x1;
    10021110
    1003         return send_message(pid, MSG_SEND_PACKET, &p, sizeof(p), False);
     1111        return send_message(msg_ctx, pid, MSG_SEND_PACKET, &p, sizeof(p));
    10041112}
    10051113
     
    10081116static const struct {
    10091117        const char *name;       /* Option name */
    1010         BOOL (*fn)(const struct process_id pid,
     1118        BOOL (*fn)(struct messaging_context *msg_ctx,
     1119                   const struct server_id pid,
    10111120                   const int argc, const char **argv);
    10121121        const char *help;       /* Short help text */
     
    10251134        { "printnotify", do_printnotify, "Send a print notify message" },
    10261135        { "close-share", do_closeshare, "Forcibly disconnect a share" },
     1136        { "lockretry", do_lockretry, "Force a blocking lock retry" },
     1137        { "brl-revalidate", do_brl_revalidate, "Revalidate all brl entries" },
    10271138        { "samsync", do_samsync, "Initiate SAM synchronisation" },
    10281139        { "samrepl", do_samrepl, "Initiate SAM replication" },
     
    10371148        { "offline", do_winbind_offline, "Ask winbind to go into offline state"},
    10381149        { "onlinestatus", do_winbind_onlinestatus, "Request winbind online status"},
     1150        { "dump-event-list", do_dump_event_list, "Dump event list"},
     1151        { "validate-cache" , do_winbind_validate_cache,
     1152          "Validate winbind's credential cache" },
    10391153        { "noop", do_noop, "Do nothing" },
    10401154        { NULL }
     
    10431157/* Display usage information */
    10441158
    1045 static void usage(poptContext *pc)
     1159static void usage(poptContext pc)
    10461160{
    10471161        int i;
    10481162
    1049         poptPrintHelp(*pc, stderr, 0);
     1163        poptPrintHelp(pc, stderr, 0);
    10501164
    10511165        fprintf(stderr, "\n");
     
    10671181/* Return the pid number for a string destination */
    10681182
    1069 static struct process_id parse_dest(const char *dest)
    1070 {
    1071         struct process_id result = {-1};
     1183static struct server_id parse_dest(const char *dest)
     1184{
     1185        struct server_id result = {-1};
    10721186        pid_t pid;
    10731187
     
    10751189
    10761190        if (strequal(dest, "smbd")) {
    1077                 return interpret_pid("0");
     1191                return interpret_pid(MSG_BROADCAST_PID_STR);
    10781192        }
    10791193
     
    11141228/* Execute smbcontrol command */
    11151229
    1116 static BOOL do_command(int argc, const char **argv)
     1230static BOOL do_command(struct messaging_context *msg_ctx,
     1231                       int argc, const char **argv)
    11171232{
    11181233        const char *dest = argv[0], *command = argv[1];
    1119         struct process_id pid;
     1234        struct server_id pid;
    11201235        int i;
    11211236
     
    11311246        for (i = 0; msg_types[i].name; i++) {
    11321247                if (strequal(command, msg_types[i].name))
    1133                         return msg_types[i].fn(pid, argc - 1, argv + 1);
     1248                        return msg_types[i].fn(msg_ctx, pid,
     1249                                               argc - 1, argv + 1);
    11341250        }
    11351251
     
    11381254        return False;
    11391255}
     1256
     1257static void smbcontrol_help(poptContext pc,
     1258                    enum poptCallbackReason preason,
     1259                    struct poptOption * poption,
     1260                    const char * parg,
     1261                    void * pdata)
     1262{
     1263        if (poption->shortName != '?') {
     1264                poptPrintUsage(pc, stdout, 0);
     1265        } else {
     1266                usage(pc);
     1267        }
     1268
     1269        exit(0);
     1270}
     1271
     1272struct poptOption help_options[] = {
     1273        { NULL, '\0', POPT_ARG_CALLBACK, (void *)&smbcontrol_help, '\0',
     1274          NULL, NULL },
     1275        { "help", '?', 0, NULL, '?', "Show this help message", NULL },
     1276        { "usage", '\0', 0, NULL, 'u', "Display brief usage message", NULL },
     1277        { NULL }
     1278} ;
    11401279
    11411280/* Main program */
     
    11451284        poptContext pc;
    11461285        int opt;
     1286        struct event_context *evt_ctx;
     1287        struct messaging_context *msg_ctx;
    11471288
    11481289        static struct poptOption long_options[] = {
    1149                 POPT_AUTOHELP
     1290                /* POPT_AUTOHELP */
     1291                { NULL, '\0', POPT_ARG_INCLUDE_TABLE, help_options,
     1292                                        0, "Help options:", NULL },
    11501293                { "timeout", 't', POPT_ARG_INT, &timeout, 't',
    11511294                  "Set timeout value in seconds", "TIMEOUT" },
     
    11541297                POPT_TABLEEND
    11551298        };
     1299        TALLOC_CTX *frame = talloc_stackframe();
     1300        int ret = 0;
    11561301
    11571302        load_case_tables();
     
    11681313
    11691314        if (argc == 1)
    1170                 usage(&pc);
     1315                usage(pc);
    11711316
    11721317        while ((opt = poptGetNextOpt(pc)) != -1) {
     
    11871332        argv = (const char **)poptGetArgs(pc);
    11881333        argc = 0;
    1189         while (argv[argc] != NULL) {
    1190                 argc++;
    1191         }
    1192 
    1193         if (argc == 1)
    1194                 usage(&pc);
     1334        if (argv != NULL) {
     1335                while (argv[argc] != NULL) {
     1336                        argc++;
     1337                }
     1338        }
     1339
     1340        if (argc <= 1)
     1341                usage(pc);
    11951342
    11961343        lp_load(dyn_CONFIGFILE,False,False,False,True);
     
    12001347         * shell needs 0. */
    12011348       
    1202         return !do_command(argc, argv);
    1203 }
     1349        if (!(evt_ctx = event_context_init(NULL)) ||
     1350            !(msg_ctx = messaging_init(NULL, server_id_self(), evt_ctx))) {
     1351                fprintf(stderr, "could not init messaging context\n");
     1352                TALLOC_FREE(frame);
     1353                exit(1);
     1354        }
     1355       
     1356        ret = !do_command(msg_ctx, argc, argv);
     1357        TALLOC_FREE(frame);
     1358        return ret;
     1359}
Note: See TracChangeset for help on using the changeset viewer.