Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/nmbd/nmbd.c

    r746 r988  
    2626#include "serverid.h"
    2727#include "messages.h"
     28#include "../lib/util/pidfile.h"
     29#include "util_cluster.h"
    2830
    2931int ClientNMB       = -1;
     
    4345time_t StartupTime = 0;
    4446
    45 struct event_context *nmbd_event_context(void)
     47struct tevent_context *nmbd_event_context(void)
    4648{
    4749        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;
    5850}
    5951
     
    6254 **************************************************************************** */
    6355
    64 static void terminate(void)
     56static void terminate(struct messaging_context *msg)
    6557{
    6658        DEBUG(0,("Got SIGTERM: going down...\n"));
    67  
     59
    6860        /* Write out wins.dat file if samba is a WINS server */
    6961        wins_write_database(0,False);
    70  
     62
    7163        /* Remove all SELF registered names from WINS */
    7264        release_wins_names();
    73  
     65
    7466        /* Announce all server entries as 0 time-to-live, 0 type. */
    7567        announce_my_servers_removed();
     
    7971
    8072        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");
    8476
    8577        exit(0);
     
    9385                                  void *private_data)
    9486{
    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 */
     96static 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
     111static bool nmbd_setup_sig_term_handler(struct messaging_context *msg)
    99112{
    100113        struct tevent_signal *se;
     
    104117                               SIGTERM, 0,
    105118                               nmbd_sig_term_handler,
    106                                NULL);
     119                               msg);
    107120        if (!se) {
    108121                DEBUG(0,("failed to setup SIGTERM handler"));
    109122                return false;
     123        }
     124
     125        return true;
     126}
     127
     128static 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                }
    110148        }
    111149
     
    126164                                 void *private_data)
    127165{
     166        struct messaging_context *msg = talloc_get_type_abort(
     167                private_data, struct messaging_context);
     168
    128169        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
     174static bool nmbd_setup_sig_hup_handler(struct messaging_context *msg)
    135175{
    136176        struct tevent_signal *se;
     
    140180                               SIGHUP, 0,
    141181                               nmbd_sig_hup_handler,
    142                                NULL);
     182                               msg);
    143183        if (!se) {
    144184                DEBUG(0,("failed to setup SIGHUP handler"));
     
    159199                           DATA_BLOB *data)
    160200{
    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);
    171202}
    172203
     
    178209{
    179210        static time_t lastrun = 0;
    180  
     211
    181212        if ( !lastrun )
    182213                lastrun = t;
     
    250281                }
    251282
    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 *)
    254285                         &iface->netmask)->sin_addr;
    255286
     
    260291                 */
    261292
    262                 if (is_loopback_addr((struct sockaddr *)(void *)&iface->ip)) {
     293                if (is_loopback_addr((const struct sockaddr *)(const void *)&iface->ip)) {
    263294                        DEBUG(2,("reload_interfaces: Ignoring loopback "
    264295                                "interface %s\n",
     
    366397
    367398        if ( lp_loaded() ) {
    368                 char *fname = lp_configfile();
     399                char *fname = lp_next_configfile(talloc_tos());
    369400                if (file_exist(fname) && !strcsequal(fname,get_dyn_CONFIGFILE())) {
    370401                        set_dyn_CONFIGFILE(fname);
     
    377408                return(True);
    378409
    379         ret = lp_load(get_dyn_CONFIGFILE(), True , False, False, True);
     410        ret = lp_load_global(get_dyn_CONFIGFILE());
    380411
    381412        /* perhaps the config filename is now set */
     
    384415                reload_nmbd_services( True );
    385416        }
     417
     418        reopen_logs();
    386419
    387420        return(ret);
     
    470503 **************************************************************************** */
    471504
    472 static void process(void)
     505static void process(struct messaging_context *msg)
    473506{
    474507        bool run_election;
     
    491524                 */
    492525
    493                 if(listen_for_packets(run_election)) {
     526                if (listen_for_packets(msg, run_election)) {
    494527                        TALLOC_FREE(frame);
    495528                        return;
     
    675708{
    676709        struct sockaddr_storage ss;
    677         const char *sock_addr = lp_socket_address();
     710        const char *sock_addr = lp_nbt_client_socket_address();
    678711
    679712        /*
     
    741774 int main(int argc, const char *argv[])
    742775{
    743         static bool is_daemon;
    744         static bool opt_interactive;
    745         static bool 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;
    748781        poptContext pc;
    749782        char *p_lmhosts = NULL;
    750783        int opt;
     784        struct messaging_context *msg;
    751785        enum {
    752786                OPT_DAEMON = 1000,
     
    770804        TALLOC_CTX *frame;
    771805        NTSTATUS status;
     806        bool ok;
    772807
    773808        /*
     
    777812        frame = talloc_stackframe();
    778813
    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();
    780823
    781824        global_nmb_port = NMB_PORT;
     
    809852
    810853        global_in_nmbd = true;
    811        
     854
    812855        StartupTime = time(NULL);
    813        
    814         sys_srandom(time(NULL) ^ sys_getpid());
    815        
     856
     857        sys_srandom(time(NULL) ^ getpid());
     858
    816859        if (!override_logfile) {
    817860                char *lfile = NULL;
     
    822865                SAFE_FREE(lfile);
    823866        }
    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
    828871        /* POSIX demands that signals are inherited. If the invoking process has
    829872         * these signals masked, we will have problems, as we won't receive them. */
     
    842885#endif
    843886
     887        /* Ignore children - no zombies. */
     888        CatchChild();
     889
    844890        if ( opt_interactive ) {
    845891                Fork = False;
     
    851897                exit(1);
    852898        }
     899
    853900        if (log_stdout) {
    854                 setup_logging( argv[0], DEBUG_STDOUT);
     901                setup_logging(argv[0], DEBUG_STDOUT);
    855902        } else {
    856903                setup_logging( argv[0], DEBUG_FILE);
     
    863910
    864911        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()));
    866913                exit(1);
    867914        }
    868915
    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) {
    870934                return 1;
    871935        }
     
    887951
    888952        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"));
    890954                is_daemon = True;
    891955        }
    892  
     956
    893957        if (is_daemon && !opt_interactive) {
    894                 DEBUG( 2, ( "Becoming a daemon.\n" ) );
     958                DEBUG(3, ("Becoming a daemon.\n"));
    895959                become_daemon(Fork, no_process_group, log_stdout);
    896960        }
     
    905969#endif
    906970
    907         if (nmbd_messaging_context() == NULL) {
    908                 return 1;
    909         }
    910 
    911971#ifndef SYNC_DNS
    912972        /* Setup the async dns. We do it here so it doesn't have all the other
    913973                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);
    916976        }
    917977#endif
    918978
    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);
    928992
    929993        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)) {
    9311015                exit(1);
    9321016        }
    9331017
    934         if (!nmbd_setup_sig_term_handler())
    935                 exit(1);
    936         if (!nmbd_setup_sig_hup_handler())
    937                 exit(1);
    938 
    9391018        /* get broadcast messages */
    9401019
    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);
    9491029#if 0
    9501030        /* 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);
    9531033#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);
    9601040
    9611041        TimeInit();
     
    9731053        /* Create an nmbd subnet record for each of the above. */
    9741054        if( False == create_subnets() ) {
    975                 DEBUG(0,("ERROR: Failed when creating subnet lists. Exiting.\n"));
    9761055                kill_async_dns_child();
    977                 exit(1);
     1056                exit_daemon("NMBD failed when creating subnet lists", EACCES);
    9781057        }
    9791058
     
    9871066        /* If we are acting as a WINS server, initialise data structures. */
    9881067        if( !initialise_wins() ) {
    989                 DEBUG( 0, ( "nmbd: Failed when initialising WINS server.\n" ) );
    9901068                kill_async_dns_child();
    991                 exit(1);
     1069                exit_daemon( "NMBD failed when initialising WINS server.", EACCES);
    9921070        }
    9931071
     
    10011079
    10021080        if( False == register_my_workgroup_and_names() ) {
    1003                 DEBUG(0,("ERROR: Failed when creating my my workgroup. Exiting.\n"));
    10041081                kill_async_dns_child();
    1005                 exit(1);
     1082                exit_daemon( "NMBD failed when creating my workgroup.", EACCES);
    10061083        }
    10071084
    10081085        if (!initialize_nmbd_proxy_logon()) {
    1009                 DEBUG(0,("ERROR: Failed setup nmbd_proxy_logon.\n"));
    10101086                kill_async_dns_child();
    1011                 exit(1);
     1087                exit_daemon( "NMBD failed to setup nmbd_proxy_logon.", EACCES);
    10121088        }
    10131089
    10141090        if (!nmbd_init_packet_server()) {
    10151091                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        }
    10181098
    10191099        TALLOC_FREE(frame);
    1020         process();
     1100        process(msg);
    10211101
    10221102        kill_async_dns_child();
Note: See TracChangeset for help on using the changeset viewer.