Changeset 988 for vendor/current/source3/nmbd/nmbd.c
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/nmbd/nmbd.c
r746 r988 26 26 #include "serverid.h" 27 27 #include "messages.h" 28 #include "../lib/util/pidfile.h" 29 #include "util_cluster.h" 28 30 29 31 int ClientNMB = -1; … … 43 45 time_t StartupTime = 0; 44 46 45 struct event_context *nmbd_event_context(void)47 struct tevent_context *nmbd_event_context(void) 46 48 { 47 49 return server_event_context(); 48 }49 50 struct messaging_context *nmbd_messaging_context(void)51 {52 struct messaging_context *msg_ctx = server_messaging_context();53 if (likely(msg_ctx != NULL)) {54 return msg_ctx;55 }56 smb_panic("Could not init nmbd's messaging context.\n");57 return NULL;58 50 } 59 51 … … 62 54 **************************************************************************** */ 63 55 64 static void terminate( void)56 static void terminate(struct messaging_context *msg) 65 57 { 66 58 DEBUG(0,("Got SIGTERM: going down...\n")); 67 59 68 60 /* Write out wins.dat file if samba is a WINS server */ 69 61 wins_write_database(0,False); 70 62 71 63 /* Remove all SELF registered names from WINS */ 72 64 release_wins_names(); 73 65 74 66 /* Announce all server entries as 0 time-to-live, 0 type. */ 75 67 announce_my_servers_removed(); … … 79 71 80 72 gencache_stabilize(); 81 serverid_deregister( procid_self());82 83 pidfile_unlink( );73 serverid_deregister(messaging_server_id(msg)); 74 75 pidfile_unlink(lp_pid_directory(), "nmbd"); 84 76 85 77 exit(0); … … 93 85 void *private_data) 94 86 { 95 terminate(); 96 } 97 98 static bool nmbd_setup_sig_term_handler(void) 87 struct messaging_context *msg = talloc_get_type_abort( 88 private_data, struct messaging_context); 89 90 terminate(msg); 91 } 92 93 /* 94 handle stdin becoming readable when we are in --foreground mode 95 */ 96 static void nmbd_stdin_handler(struct tevent_context *ev, 97 struct tevent_fd *fde, 98 uint16_t flags, 99 void *private_data) 100 { 101 char c; 102 if (read(0, &c, 1) != 1) { 103 struct messaging_context *msg = talloc_get_type_abort( 104 private_data, struct messaging_context); 105 106 DEBUG(0,("EOF on stdin\n")); 107 terminate(msg); 108 } 109 } 110 111 static bool nmbd_setup_sig_term_handler(struct messaging_context *msg) 99 112 { 100 113 struct tevent_signal *se; … … 104 117 SIGTERM, 0, 105 118 nmbd_sig_term_handler, 106 NULL);119 msg); 107 120 if (!se) { 108 121 DEBUG(0,("failed to setup SIGTERM handler")); 109 122 return false; 123 } 124 125 return true; 126 } 127 128 static bool nmbd_setup_stdin_handler(struct messaging_context *msg, bool foreground) 129 { 130 if (foreground) { 131 /* if we are running in the foreground then look for 132 EOF on stdin, and exit if it happens. This allows 133 us to die if the parent process dies 134 Only do this on a pipe or socket, no other device. 135 */ 136 struct stat st; 137 if (fstat(0, &st) != 0) { 138 return false; 139 } 140 if (S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode)) { 141 tevent_add_fd(nmbd_event_context(), 142 nmbd_event_context(), 143 0, 144 TEVENT_FD_READ, 145 nmbd_stdin_handler, 146 msg); 147 } 110 148 } 111 149 … … 126 164 void *private_data) 127 165 { 166 struct messaging_context *msg = talloc_get_type_abort( 167 private_data, struct messaging_context); 168 128 169 DEBUG(0,("Got SIGHUP dumping debug info.\n")); 129 msg_reload_nmbd_services(nmbd_messaging_context(), 130 NULL, MSG_SMB_CONF_UPDATED, 131 procid_self(), NULL); 132 } 133 134 static bool nmbd_setup_sig_hup_handler(void) 170 msg_reload_nmbd_services(msg, NULL, MSG_SMB_CONF_UPDATED, 171 messaging_server_id(msg), NULL); 172 } 173 174 static bool nmbd_setup_sig_hup_handler(struct messaging_context *msg) 135 175 { 136 176 struct tevent_signal *se; … … 140 180 SIGHUP, 0, 141 181 nmbd_sig_hup_handler, 142 NULL);182 msg); 143 183 if (!se) { 144 184 DEBUG(0,("failed to setup SIGHUP handler")); … … 159 199 DATA_BLOB *data) 160 200 { 161 terminate(); 162 } 163 164 /**************************************************************************** ** 165 Possibly continue after a fault. 166 **************************************************************************** */ 167 168 static void fault_continue(void) 169 { 170 dump_core(); 201 terminate(msg); 171 202 } 172 203 … … 178 209 { 179 210 static time_t lastrun = 0; 180 211 181 212 if ( !lastrun ) 182 213 lastrun = t; … … 250 281 } 251 282 252 ip = (( struct sockaddr_in *)(void *)&iface->ip)->sin_addr;253 nmask = (( struct sockaddr_in *)(void *)283 ip = ((const struct sockaddr_in *)(const void *)&iface->ip)->sin_addr; 284 nmask = ((const struct sockaddr_in *)(const void *) 254 285 &iface->netmask)->sin_addr; 255 286 … … 260 291 */ 261 292 262 if (is_loopback_addr(( struct sockaddr *)(void *)&iface->ip)) {293 if (is_loopback_addr((const struct sockaddr *)(const void *)&iface->ip)) { 263 294 DEBUG(2,("reload_interfaces: Ignoring loopback " 264 295 "interface %s\n", … … 366 397 367 398 if ( lp_loaded() ) { 368 char *fname = lp_ configfile();399 char *fname = lp_next_configfile(talloc_tos()); 369 400 if (file_exist(fname) && !strcsequal(fname,get_dyn_CONFIGFILE())) { 370 401 set_dyn_CONFIGFILE(fname); … … 377 408 return(True); 378 409 379 ret = lp_load (get_dyn_CONFIGFILE(), True , False, False, True);410 ret = lp_load_global(get_dyn_CONFIGFILE()); 380 411 381 412 /* perhaps the config filename is now set */ … … 384 415 reload_nmbd_services( True ); 385 416 } 417 418 reopen_logs(); 386 419 387 420 return(ret); … … 470 503 **************************************************************************** */ 471 504 472 static void process( void)505 static void process(struct messaging_context *msg) 473 506 { 474 507 bool run_election; … … 491 524 */ 492 525 493 if (listen_for_packets(run_election)) {526 if (listen_for_packets(msg, run_election)) { 494 527 TALLOC_FREE(frame); 495 528 return; … … 675 708 { 676 709 struct sockaddr_storage ss; 677 const char *sock_addr = lp_ socket_address();710 const char *sock_addr = lp_nbt_client_socket_address(); 678 711 679 712 /* … … 741 774 int main(int argc, const char *argv[]) 742 775 { 743 static bool is_daemon;744 static bool opt_interactive;745 staticbool Fork = true;746 static bool no_process_group;747 static bool log_stdout;776 bool is_daemon = false; 777 bool opt_interactive = false; 778 bool Fork = true; 779 bool no_process_group = false; 780 bool log_stdout = false; 748 781 poptContext pc; 749 782 char *p_lmhosts = NULL; 750 783 int opt; 784 struct messaging_context *msg; 751 785 enum { 752 786 OPT_DAEMON = 1000, … … 770 804 TALLOC_CTX *frame; 771 805 NTSTATUS status; 806 bool ok; 772 807 773 808 /* … … 777 812 frame = talloc_stackframe(); 778 813 779 load_case_tables(); 814 /* 815 * We want total control over the permissions on created files, 816 * so set our umask to 0. 817 */ 818 umask(0); 819 820 setup_logging(argv[0], DEBUG_DEFAULT_STDOUT); 821 822 smb_init_locale(); 780 823 781 824 global_nmb_port = NMB_PORT; … … 809 852 810 853 global_in_nmbd = true; 811 854 812 855 StartupTime = time(NULL); 813 814 sys_srandom(time(NULL) ^ sys_getpid());815 856 857 sys_srandom(time(NULL) ^ getpid()); 858 816 859 if (!override_logfile) { 817 860 char *lfile = NULL; … … 822 865 SAFE_FREE(lfile); 823 866 } 824 825 fault_setup( (void (*)(void *))fault_continue);826 dump_core_setup("nmbd" );827 867 868 fault_setup(); 869 dump_core_setup("nmbd", lp_logfile(talloc_tos())); 870 828 871 /* POSIX demands that signals are inherited. If the invoking process has 829 872 * these signals masked, we will have problems, as we won't receive them. */ … … 842 885 #endif 843 886 887 /* Ignore children - no zombies. */ 888 CatchChild(); 889 844 890 if ( opt_interactive ) { 845 891 Fork = False; … … 851 897 exit(1); 852 898 } 899 853 900 if (log_stdout) { 854 setup_logging( 901 setup_logging(argv[0], DEBUG_STDOUT); 855 902 } else { 856 903 setup_logging( argv[0], DEBUG_FILE); … … 863 910 864 911 if (!lp_load_initial_only(get_dyn_CONFIGFILE())) { 865 DEBUG(0, ("error opening config file \n"));912 DEBUG(0, ("error opening config file '%s'\n", get_dyn_CONFIGFILE())); 866 913 exit(1); 867 914 } 868 915 869 if (nmbd_messaging_context() == NULL) { 916 reopen_logs(); 917 918 if (lp_server_role() == ROLE_ACTIVE_DIRECTORY_DC 919 && !lp_parm_bool(-1, "server role check", "inhibit", false)) { 920 /* TODO: when we have a merged set of defaults for 921 * loadparm, we could possibly check if the internal 922 * nbt server is in the list, and allow a startup if disabled */ 923 DEBUG(0, ("server role = 'active directory domain controller' not compatible with running nmbd standalone. \n")); 924 DEBUGADD(0, ("You should start 'samba' instead, and it will control starting the internal nbt server\n")); 925 exit(1); 926 } 927 928 if (!cluster_probe_ok()) { 929 exit(1); 930 } 931 932 msg = messaging_init(NULL, server_event_context()); 933 if (msg == NULL) { 870 934 return 1; 871 935 } … … 887 951 888 952 if (!is_daemon && !is_a_socket(0)) { 889 DEBUG( 0,("standard input is not a socket, assuming -D option\n"));953 DEBUG(3, ("standard input is not a socket, assuming -D option\n")); 890 954 is_daemon = True; 891 955 } 892 956 893 957 if (is_daemon && !opt_interactive) { 894 DEBUG( 2, ( "Becoming a daemon.\n" ));958 DEBUG(3, ("Becoming a daemon.\n")); 895 959 become_daemon(Fork, no_process_group, log_stdout); 896 960 } … … 905 969 #endif 906 970 907 if (nmbd_messaging_context() == NULL) {908 return 1;909 }910 911 971 #ifndef SYNC_DNS 912 972 /* Setup the async dns. We do it here so it doesn't have all the other 913 973 stuff initialised and thus chewing memory and sockets */ 914 if(lp_we_are_a_wins_server() && lp_ dns_proxy()) {915 start_async_dns( );974 if(lp_we_are_a_wins_server() && lp_wins_dns_proxy()) { 975 start_async_dns(msg); 916 976 } 917 977 #endif 918 978 919 if (!directory_exist(lp_lockdir())) { 920 mkdir(lp_lockdir(), 0755); 921 } 922 923 pidfile_create("nmbd"); 924 925 status = reinit_after_fork(nmbd_messaging_context(), 926 nmbd_event_context(), 927 procid_self(), false); 979 ok = directory_create_or_exist(lp_lock_directory(), 0755); 980 if (!ok) { 981 exit_daemon("Failed to create directory for lock files, check 'lock directory'", errno); 982 } 983 984 ok = directory_create_or_exist(lp_pid_directory(), 0755); 985 if (!ok) { 986 exit_daemon("Failed to create directory for pid files, check 'pid directory'", errno); 987 } 988 989 pidfile_create(lp_pid_directory(), "nmbd"); 990 991 status = reinit_after_fork(msg, nmbd_event_context(), false, NULL); 928 992 929 993 if (!NT_STATUS_IS_OK(status)) { 930 DEBUG(0,("reinit_after_fork() failed\n")); 994 exit_daemon("reinit_after_fork() failed", map_errno_from_nt_status(status)); 995 } 996 997 /* 998 * Do not initialize the parent-child-pipe before becoming 999 * a daemon: this is used to detect a died parent in the child 1000 * process. 1001 */ 1002 status = init_before_fork(); 1003 if (!NT_STATUS_IS_OK(status)) { 1004 exit_daemon(nt_errstr(status), map_errno_from_nt_status(status)); 1005 } 1006 1007 if (!nmbd_setup_sig_term_handler(msg)) 1008 exit_daemon("NMBD failed to setup signal handler", EINVAL); 1009 if (!nmbd_setup_stdin_handler(msg, !Fork)) 1010 exit_daemon("NMBD failed to setup stdin handler", EINVAL); 1011 if (!nmbd_setup_sig_hup_handler(msg)) 1012 exit_daemon("NMBD failed to setup SIGHUP handler", EINVAL); 1013 1014 if (!messaging_parent_dgm_cleanup_init(msg)) { 931 1015 exit(1); 932 1016 } 933 1017 934 if (!nmbd_setup_sig_term_handler())935 exit(1);936 if (!nmbd_setup_sig_hup_handler())937 exit(1);938 939 1018 /* get broadcast messages */ 940 1019 941 if (!serverid_register(procid_self(), 942 FLAG_MSG_GENERAL|FLAG_MSG_DBWRAP)) { 943 DEBUG(1, ("Could not register myself in serverid.tdb\n")); 944 exit(1); 945 } 946 947 messaging_register(nmbd_messaging_context(), NULL, 948 MSG_FORCE_ELECTION, nmbd_message_election); 1020 if (!serverid_register(messaging_server_id(msg), 1021 FLAG_MSG_GENERAL | 1022 FLAG_MSG_NMBD | 1023 FLAG_MSG_DBWRAP)) { 1024 exit_daemon("Could not register NMBD process in serverid.tdb", EACCES); 1025 } 1026 1027 messaging_register(msg, NULL, MSG_FORCE_ELECTION, 1028 nmbd_message_election); 949 1029 #if 0 950 1030 /* Until winsrepl is done. */ 951 messaging_register( nmbd_messaging_context(), NULL,952 MSG_WINS_NEW_ENTRY,nmbd_wins_new_entry);1031 messaging_register(msg, NULL, MSG_WINS_NEW_ENTRY, 1032 nmbd_wins_new_entry); 953 1033 #endif 954 messaging_register( nmbd_messaging_context(), NULL,955 MSG_SHUTDOWN,nmbd_terminate);956 messaging_register( nmbd_messaging_context(), NULL,957 MSG_SMB_CONF_UPDATED,msg_reload_nmbd_services);958 messaging_register( nmbd_messaging_context(), NULL,959 MSG_SEND_PACKET,msg_nmbd_send_packet);1034 messaging_register(msg, NULL, MSG_SHUTDOWN, 1035 nmbd_terminate); 1036 messaging_register(msg, NULL, MSG_SMB_CONF_UPDATED, 1037 msg_reload_nmbd_services); 1038 messaging_register(msg, NULL, MSG_SEND_PACKET, 1039 msg_nmbd_send_packet); 960 1040 961 1041 TimeInit(); … … 973 1053 /* Create an nmbd subnet record for each of the above. */ 974 1054 if( False == create_subnets() ) { 975 DEBUG(0,("ERROR: Failed when creating subnet lists. Exiting.\n"));976 1055 kill_async_dns_child(); 977 exit (1);1056 exit_daemon("NMBD failed when creating subnet lists", EACCES); 978 1057 } 979 1058 … … 987 1066 /* If we are acting as a WINS server, initialise data structures. */ 988 1067 if( !initialise_wins() ) { 989 DEBUG( 0, ( "nmbd: Failed when initialising WINS server.\n" ) );990 1068 kill_async_dns_child(); 991 exit (1);1069 exit_daemon( "NMBD failed when initialising WINS server.", EACCES); 992 1070 } 993 1071 … … 1001 1079 1002 1080 if( False == register_my_workgroup_and_names() ) { 1003 DEBUG(0,("ERROR: Failed when creating my my workgroup. Exiting.\n"));1004 1081 kill_async_dns_child(); 1005 exit (1);1082 exit_daemon( "NMBD failed when creating my workgroup.", EACCES); 1006 1083 } 1007 1084 1008 1085 if (!initialize_nmbd_proxy_logon()) { 1009 DEBUG(0,("ERROR: Failed setup nmbd_proxy_logon.\n"));1010 1086 kill_async_dns_child(); 1011 exit (1);1087 exit_daemon( "NMBD failed to setup nmbd_proxy_logon.", EACCES); 1012 1088 } 1013 1089 1014 1090 if (!nmbd_init_packet_server()) { 1015 1091 kill_async_dns_child(); 1016 exit(1); 1017 } 1092 exit_daemon( "NMBD failed to setup packet server.", EACCES); 1093 } 1094 1095 if (is_daemon && !opt_interactive) { 1096 daemon_ready("nmbd"); 1097 } 1018 1098 1019 1099 TALLOC_FREE(frame); 1020 process( );1100 process(msg); 1021 1101 1022 1102 kill_async_dns_child();
Note:
See TracChangeset
for help on using the changeset viewer.