Changeset 77 for trunk/samba/source/utils/smbcontrol.c
- Timestamp:
- Sep 30, 2007, 3:42:50 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/samba/source/utils/smbcontrol.c
r22 r77 12 12 This program is free software; you can redistribute it and/or modify 13 13 it under the terms of the GNU General Public License as published by 14 the Free Software Foundation; either version 2of the License, or14 the Free Software Foundation; either version 3 of the License, or 15 15 (at your option) any later version. 16 16 … … 21 21 22 22 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/>. 25 24 */ 26 25 … … 48 47 /* Send a message to a destination pid. Zero means broadcast smbd. */ 49 48 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; 49 static BOOL send_message(struct messaging_context *msg_ctx, 50 struct server_id pid, int msg_type, 51 const void *buf, int len) 52 { 55 53 BOOL ret; 56 54 int n_sent = 0; 57 55 58 if (!message_init())59 return False;60 61 56 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); 75 62 DEBUG(10,("smbcontrol/send_message: broadcast message to " 76 63 "%d processes\n", n_sent)); 77 64 78 tdb_close(tdb);79 80 65 return ret; 81 66 } 82 67 68 static 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 83 78 /* Wait for one or more reply messages */ 84 79 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(); 80 static 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); 94 96 if (num_replies > 0 && !multiple_replies) 95 97 break; 96 sleep(1);97 } while (timeout - (time(NULL) - start_time) > 0);98 event_loop_once(messaging_event_context(msg_ctx)); 99 } 98 100 } 99 101 100 102 /* Message handler callback that displays the PID and a string on stdout */ 101 103 102 static void print_pid_string_cb(int msg_type, struct process_id pid, void *buf, 103 size_t len, void *private_data) 104 static 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) 104 109 { 105 110 printf("PID %u: %.*s", (unsigned int)procid_to_pid(&pid), 106 (int) len, (const char *)buf);111 (int)data->length, (const char *)data->data); 107 112 num_replies++; 108 113 } … … 110 115 /* Message handler callback that displays a string on stdout */ 111 116 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); 117 static 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); 116 124 num_replies++; 117 125 } … … 119 127 /* Send no message. Useful for testing. */ 120 128 121 static BOOL do_noop(const struct process_id pid, 129 static BOOL do_noop(struct messaging_context *msg_ctx, 130 const struct server_id pid, 122 131 const int argc, const char **argv) 123 132 { … … 134 143 /* Send a debug string */ 135 144 136 static BOOL do_debug(const struct process_id pid, 145 static BOOL do_debug(struct messaging_context *msg_ctx, 146 const struct server_id pid, 137 147 const int argc, const char **argv) 138 148 { … … 143 153 } 144 154 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); 147 157 } 148 158 … … 248 258 } 249 259 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); 260 static 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); 260 266 261 267 return 0; 262 268 } 263 269 264 static BOOL do_daemon_stack_trace(const struct process_id pid, 270 static BOOL do_daemon_stack_trace(struct messaging_context *msg_ctx, 271 const struct server_id pid, 265 272 const int argc, const char **argv) 266 273 { 267 fprintf(stderr,268 "Daemon stack tracing is not supported on this platform\n");269 return False;270 271 274 pid_t dest; 272 275 int count = 0; … … 287 290 print_stack_trace(dest, &count); 288 291 } 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); 302 293 } 303 294 … … 307 298 #else /* defined(HAVE_LIBUNWIND_PTRACE) && defined(HAVE_LINUX_PTRACE) */ 308 299 309 static BOOL do_daemon_stack_trace(const struct process_id pid, 300 static BOOL do_daemon_stack_trace(struct messaging_context *msg_ctx, 301 const struct server_id pid, 310 302 const int argc, const char **argv) 311 303 { … … 319 311 /* Inject a fault (fatal signal) into a running smbd */ 320 312 321 static BOOL do_inject_fault(const struct process_id pid, 313 static BOOL do_inject_fault(struct messaging_context *msg_ctx, 314 const struct server_id pid, 322 315 const int argc, const char **argv) 323 316 { … … 352 345 } 353 346 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)); 356 349 } 357 350 #endif /* DEVELOPER */ … … 360 353 /* Force a browser election */ 361 354 362 static BOOL do_election(const struct process_id pid, 355 static BOOL do_election(struct messaging_context *msg_ctx, 356 const struct server_id pid, 363 357 const int argc, const char **argv) 364 358 { … … 368 362 } 369 363 370 return send_message( 371 pid, MSG_FORCE_ELECTION, NULL, 0, False); 364 return send_message(msg_ctx, pid, MSG_FORCE_ELECTION, NULL, 0); 372 365 } 373 366 374 367 /* Ping a samba daemon process */ 375 368 376 static void pong_cb(int msg_type, struct process_id pid, void *buf, 377 size_t len, void *private_data) 369 static 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) 378 374 { 379 375 char *src_string = procid_str(NULL, &pid); … … 383 379 } 384 380 385 static BOOL do_ping(const struct process_id pid, const int argc, const char **argv) 381 static BOOL do_ping(struct messaging_context *msg_ctx, 382 const struct server_id pid, 383 const int argc, const char **argv) 386 384 { 387 385 if (argc != 1) { … … 392 390 /* Send a message and register our interest in a reply */ 393 391 394 if (!send_message( pid, MSG_PING, NULL, 0, False))395 return False; 396 397 messag e_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); 400 398 401 399 /* No replies were received within the timeout period */ … … 404 402 printf("No replies received\n"); 405 403 406 messag e_deregister(MSG_PONG);404 messaging_deregister(msg_ctx, MSG_PONG, NULL); 407 405 408 406 return num_replies; … … 411 409 /* Set profiling options */ 412 410 413 static BOOL do_profile(const struct process_id pid, 411 static BOOL do_profile(struct messaging_context *msg_ctx, 412 const struct server_id pid, 414 413 const int argc, const char **argv) 415 414 { … … 435 434 } 436 435 437 return send_message( pid, MSG_PROFILE, &v, sizeof(int), False);436 return send_message(msg_ctx, pid, MSG_PROFILE, &v, sizeof(int)); 438 437 } 439 438 440 439 /* Return the profiling level */ 441 440 442 static void profilelevel_cb(int msg_type, struct process_id pid, void *buf, 443 size_t len, void *private_data) 441 static 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) 444 446 { 445 447 int level; … … 448 450 num_replies++; 449 451 450 if ( len!= sizeof(int)) {452 if (data->length != sizeof(int)) { 451 453 fprintf(stderr, "invalid message length %ld returned\n", 452 (unsigned long) len);454 (unsigned long)data->length); 453 455 return; 454 456 } 455 457 456 memcpy(&level, buf, sizeof(int));458 memcpy(&level, data->data, sizeof(int)); 457 459 458 460 switch (level) { … … 477 479 } 478 480 479 static void profilelevel_rqst(int msg_type, struct process_id pid, 480 void *buf, size_t len, void *private_data) 481 static 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) 481 486 { 482 487 int v = 0; … … 484 489 /* Send back a dummy reply */ 485 490 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 494 static BOOL do_profilelevel(struct messaging_context *msg_ctx, 495 const struct server_id pid, 490 496 const int argc, const char **argv) 491 497 { … … 497 503 /* Send a message and register our interest in a reply */ 498 504 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); 506 513 507 514 /* No replies were received within the timeout period */ … … 510 517 printf("No replies received\n"); 511 518 512 messag e_deregister(MSG_PROFILE);519 messaging_deregister(msg_ctx, MSG_PROFILE, NULL); 513 520 514 521 return num_replies; … … 517 524 /* Display debug level settings */ 518 525 519 static BOOL do_debuglevel(const struct process_id pid, 526 static BOOL do_debuglevel(struct messaging_context *msg_ctx, 527 const struct server_id pid, 520 528 const int argc, const char **argv) 521 529 { … … 527 535 /* Send a message and register our interest in a reply */ 528 536 529 if (!send_message( pid, MSG_REQ_DEBUGLEVEL, NULL, 0, False))530 return False; 531 532 messag e_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); 535 543 536 544 /* No replies were received within the timeout period */ … … 539 547 printf("No replies received\n"); 540 548 541 messag e_deregister(MSG_DEBUGLEVEL);549 messaging_deregister(msg_ctx, MSG_DEBUGLEVEL, NULL); 542 550 543 551 return num_replies; … … 546 554 /* Send a print notify message */ 547 555 548 static BOOL do_printnotify(const struct process_id pid, 556 static BOOL do_printnotify(struct messaging_context *msg_ctx, 557 const struct server_id pid, 549 558 const int argc, const char **argv) 550 559 { … … 680 689 681 690 send: 682 print_notify_send_messages( 0);691 print_notify_send_messages(msg_ctx, 0); 683 692 return True; 684 693 } … … 686 695 /* Close a share */ 687 696 688 static BOOL do_closeshare(const struct process_id pid, 697 static BOOL do_closeshare(struct messaging_context *msg_ctx, 698 const struct server_id pid, 689 699 const int argc, const char **argv) 690 700 { … … 695 705 } 696 706 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 713 static 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 727 static 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); 699 737 } 700 738 701 739 /* Force a SAM synchronisation */ 702 740 703 static BOOL do_samsync(const struct process_id pid, 741 static BOOL do_samsync(struct messaging_context *msg_ctx, 742 const struct server_id pid, 704 743 const int argc, const char **argv) 705 744 { … … 709 748 } 710 749 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); 713 751 } 714 752 715 753 /* Force a SAM replication */ 716 754 717 static BOOL do_samrepl(const struct process_id pid, 755 static BOOL do_samrepl(struct messaging_context *msg_ctx, 756 const struct server_id pid, 718 757 const int argc, const char **argv) 719 758 { … … 723 762 } 724 763 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); 727 765 } 728 766 729 767 /* Display talloc pool usage */ 730 768 731 static BOOL do_poolusage(const struct process_id pid, 769 static BOOL do_poolusage(struct messaging_context *msg_ctx, 770 const struct server_id pid, 732 771 const int argc, const char **argv) 733 772 { … … 737 776 } 738 777 739 messag e_register(MSG_POOL_USAGE, print_string_cb, NULL);778 messaging_register(msg_ctx, NULL, MSG_POOL_USAGE, print_string_cb); 740 779 741 780 /* Send a message and register our interest in a reply */ 742 781 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); 747 786 748 787 /* No replies were received within the timeout period */ … … 751 790 printf("No replies received\n"); 752 791 753 messag e_deregister(MSG_POOL_USAGE);792 messaging_deregister(msg_ctx, MSG_POOL_USAGE, NULL); 754 793 755 794 return num_replies; … … 758 797 /* Perform a dmalloc mark */ 759 798 760 static BOOL do_dmalloc_mark(const struct process_id pid, 799 static BOOL do_dmalloc_mark(struct messaging_context *msg_ctx, 800 const struct server_id pid, 761 801 const int argc, const char **argv) 762 802 { … … 766 806 } 767 807 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); 770 809 } 771 810 772 811 /* Perform a dmalloc changed */ 773 812 774 static BOOL do_dmalloc_changed(const struct process_id pid, 813 static BOOL do_dmalloc_changed(struct messaging_context *msg_ctx, 814 const struct server_id pid, 775 815 const int argc, const char **argv) 776 816 { … … 781 821 } 782 822 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); 785 825 } 786 826 787 827 /* Shutdown a server process */ 788 828 789 static BOOL do_shutdown(const struct process_id pid, 829 static BOOL do_shutdown(struct messaging_context *msg_ctx, 830 const struct server_id pid, 790 831 const int argc, const char **argv) 791 832 { … … 795 836 } 796 837 797 return send_message( pid, MSG_SHUTDOWN, NULL, 0, False);838 return send_message(msg_ctx, pid, MSG_SHUTDOWN, NULL, 0); 798 839 } 799 840 800 841 /* Notify a driver upgrade */ 801 842 802 static BOOL do_drvupgrade(const struct process_id pid, 843 static BOOL do_drvupgrade(struct messaging_context *msg_ctx, 844 const struct server_id pid, 803 845 const int argc, const char **argv) 804 846 { … … 809 851 } 810 852 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 857 static BOOL do_winbind_online(struct messaging_context *msg_ctx, 858 const struct server_id pid, 816 859 const int argc, const char **argv) 817 860 { … … 843 886 tdb_close(tdb); 844 887 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 891 static BOOL do_winbind_offline(struct messaging_context *msg_ctx, 892 const struct server_id pid, 849 893 const int argc, const char **argv) 850 894 { … … 888 932 for (retry = 0; retry < 5; retry++) { 889 933 TDB_DATA d; 890 charbuf[4];934 uint8 buf[4]; 891 935 892 936 ZERO_STRUCT(d); … … 898 942 tdb_store_bystring(tdb, "WINBINDD_OFFLINE", d, TDB_INSERT); 899 943 900 ret = send_message(pid, MSG_WINBIND_OFFLINE, NULL, 0, False); 944 ret = send_message(msg_ctx, pid, MSG_WINBIND_OFFLINE, 945 NULL, 0); 901 946 902 947 /* Check that the entry "WINBINDD_OFFLINE" still exists. */ … … 916 961 } 917 962 918 static BOOL do_winbind_onlinestatus(const struct process_id pid, 963 static BOOL do_winbind_onlinestatus(struct messaging_context *msg_ctx, 964 const struct server_id pid, 919 965 const int argc, const char **argv) 920 966 { 921 struct process_id myid;967 struct server_id myid; 922 968 923 969 myid = pid_to_procid(sys_getpid()); … … 928 974 } 929 975 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); 936 984 937 985 /* No replies were received within the timeout period */ … … 940 988 printf("No replies received\n"); 941 989 942 messag e_deregister(MSG_WINBIND_ONLINESTATUS);990 messaging_deregister(msg_ctx, MSG_WINBIND_ONLINESTATUS, NULL); 943 991 944 992 return num_replies; 945 993 } 946 994 947 948 static BOOL do_reload_config(const struct process_id pid, 995 static 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 1011 static 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 1024 static 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 1054 static BOOL do_reload_config(struct messaging_context *msg_ctx, 1055 const struct server_id pid, 949 1056 const int argc, const char **argv) 950 1057 { … … 954 1061 } 955 1062 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); 957 1064 } 958 1065 … … 968 1075 } 969 1076 970 static BOOL do_nodestatus(const struct process_id pid, 1077 static BOOL do_nodestatus(struct messaging_context *msg_ctx, 1078 const struct server_id pid, 971 1079 const int argc, const char **argv) 972 1080 { … … 1001 1109 p.packet.nmb.question.question_class = 0x1; 1002 1110 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)); 1004 1112 } 1005 1113 … … 1008 1116 static const struct { 1009 1117 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, 1011 1120 const int argc, const char **argv); 1012 1121 const char *help; /* Short help text */ … … 1025 1134 { "printnotify", do_printnotify, "Send a print notify message" }, 1026 1135 { "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" }, 1027 1138 { "samsync", do_samsync, "Initiate SAM synchronisation" }, 1028 1139 { "samrepl", do_samrepl, "Initiate SAM replication" }, … … 1037 1148 { "offline", do_winbind_offline, "Ask winbind to go into offline state"}, 1038 1149 { "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" }, 1039 1153 { "noop", do_noop, "Do nothing" }, 1040 1154 { NULL } … … 1043 1157 /* Display usage information */ 1044 1158 1045 static void usage(poptContext *pc)1159 static void usage(poptContext pc) 1046 1160 { 1047 1161 int i; 1048 1162 1049 poptPrintHelp( *pc, stderr, 0);1163 poptPrintHelp(pc, stderr, 0); 1050 1164 1051 1165 fprintf(stderr, "\n"); … … 1067 1181 /* Return the pid number for a string destination */ 1068 1182 1069 static struct process_id parse_dest(const char *dest)1070 { 1071 struct process_id result = {-1};1183 static struct server_id parse_dest(const char *dest) 1184 { 1185 struct server_id result = {-1}; 1072 1186 pid_t pid; 1073 1187 … … 1075 1189 1076 1190 if (strequal(dest, "smbd")) { 1077 return interpret_pid( "0");1191 return interpret_pid(MSG_BROADCAST_PID_STR); 1078 1192 } 1079 1193 … … 1114 1228 /* Execute smbcontrol command */ 1115 1229 1116 static BOOL do_command(int argc, const char **argv) 1230 static BOOL do_command(struct messaging_context *msg_ctx, 1231 int argc, const char **argv) 1117 1232 { 1118 1233 const char *dest = argv[0], *command = argv[1]; 1119 struct process_id pid;1234 struct server_id pid; 1120 1235 int i; 1121 1236 … … 1131 1246 for (i = 0; msg_types[i].name; i++) { 1132 1247 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); 1134 1250 } 1135 1251 … … 1138 1254 return False; 1139 1255 } 1256 1257 static 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 1272 struct 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 } ; 1140 1279 1141 1280 /* Main program */ … … 1145 1284 poptContext pc; 1146 1285 int opt; 1286 struct event_context *evt_ctx; 1287 struct messaging_context *msg_ctx; 1147 1288 1148 1289 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 }, 1150 1293 { "timeout", 't', POPT_ARG_INT, &timeout, 't', 1151 1294 "Set timeout value in seconds", "TIMEOUT" }, … … 1154 1297 POPT_TABLEEND 1155 1298 }; 1299 TALLOC_CTX *frame = talloc_stackframe(); 1300 int ret = 0; 1156 1301 1157 1302 load_case_tables(); … … 1168 1313 1169 1314 if (argc == 1) 1170 usage( &pc);1315 usage(pc); 1171 1316 1172 1317 while ((opt = poptGetNextOpt(pc)) != -1) { … … 1187 1332 argv = (const char **)poptGetArgs(pc); 1188 1333 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); 1195 1342 1196 1343 lp_load(dyn_CONFIGFILE,False,False,False,True); … … 1200 1347 * shell needs 0. */ 1201 1348 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.