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/winbindd/winbindd.c

    r860 r988  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33
     
    3232#include "../librpc/gen_ndr/srv_samr.h"
    3333#include "secrets.h"
     34#include "rpc_client/cli_netlogon.h"
    3435#include "idmap.h"
    3536#include "lib/addrchange.h"
     
    3738#include "auth.h"
    3839#include "messages.h"
     40#include "../lib/util/pidfile.h"
     41#include "util_cluster.h"
     42#include "source4/lib/messaging/irpc.h"
     43#include "source4/lib/messaging/messaging.h"
     44#include "lib/param/param.h"
     45#include "lib/async_req/async_sock.h"
    3946
    4047#undef DBGC_CLASS
    4148#define DBGC_CLASS DBGC_WINBIND
    4249
     50#define SCRUB_CLIENTS_INTERVAL 5
     51
    4352static bool client_is_idle(struct winbindd_cli_state *state);
    4453static void remove_client(struct winbindd_cli_state *state);
     54static void winbindd_setup_max_fds(void);
    4555
    4656static bool opt_nocache = False;
     
    4959extern bool override_logfile;
    5060
     61struct tevent_context *winbind_event_context(void)
     62{
     63        static struct tevent_context *ev = NULL;
     64
     65        if (ev != NULL) {
     66                return ev;
     67        }
     68
     69        /*
     70         * Note we MUST use the NULL context here, not the autofree context,
     71         * to avoid side effects in forked children exiting.
     72         */
     73        ev = samba_tevent_context_init(NULL);
     74        if (ev == NULL) {
     75                smb_panic("Could not init winbindd's messaging context.\n");
     76        }
     77        return ev;
     78}
     79
    5180struct messaging_context *winbind_messaging_context(void)
    5281{
    53         struct messaging_context *msg_ctx = server_messaging_context();
    54         if (likely(msg_ctx != NULL)) {
    55                 return msg_ctx;
    56         }
    57         smb_panic("Could not init winbindd's messaging context.\n");
    58         return NULL;
     82        static struct messaging_context *msg = NULL;
     83
     84        if (msg != NULL) {
     85                return msg;
     86        }
     87
     88        /*
     89         * Note we MUST use the NULL context here, not the autofree context,
     90         * to avoid side effects in forked children exiting.
     91         */
     92        msg = messaging_init(NULL, winbind_event_context());
     93        if (msg == NULL) {
     94                smb_panic("Could not init winbindd's messaging context.\n");
     95        }
     96        return msg;
     97}
     98
     99struct imessaging_context *winbind_imessaging_context(void)
     100{
     101        static struct imessaging_context *msg = NULL;
     102        struct messaging_context *msg_ctx;
     103        struct server_id myself;
     104        struct loadparm_context *lp_ctx;
     105
     106        if (msg != NULL) {
     107                return msg;
     108        }
     109
     110        msg_ctx = server_messaging_context();
     111        if (msg_ctx == NULL) {
     112                smb_panic("server_messaging_context failed\n");
     113        }
     114        myself = messaging_server_id(msg_ctx);
     115
     116        lp_ctx = loadparm_init_s3(NULL, loadparm_s3_helpers());
     117        if (lp_ctx == NULL) {
     118                smb_panic("Could not load smb.conf to init winbindd's imessaging context.\n");
     119        }
     120
     121        /*
     122         * Note we MUST use the NULL context here, not the autofree context,
     123         * to avoid side effects in forked children exiting.
     124         */
     125        msg = imessaging_init(NULL, lp_ctx, myself, winbind_event_context(),
     126                              false);
     127        talloc_unlink(NULL, lp_ctx);
     128
     129        if (msg == NULL) {
     130                smb_panic("Could not init winbindd's messaging context.\n");
     131        }
     132        return msg;
    59133}
    60134
     
    66140
    67141        if (lp_loaded()) {
    68                 char *fname = lp_configfile();
     142                char *fname = lp_next_configfile(talloc_tos());
    69143
    70144                if (file_exist(fname) && !strcsequal(fname,get_dyn_CONFIGFILE())) {
     
    81155
    82156        reopen_logs();
    83         ret = lp_load(get_dyn_CONFIGFILE(),False,False,True,True);
     157        ret = lp_load_global(get_dyn_CONFIGFILE());
    84158
    85159        reopen_logs();
    86160        load_interfaces();
     161        winbindd_setup_max_fds();
    87162
    88163        return(ret);
    89164}
    90165
    91 
    92 /**************************************************************************** **
    93  Handle a fault..
    94  **************************************************************************** */
    95 
    96 static void fault_quit(void)
    97 {
    98         dump_core();
    99 }
    100166
    101167static void winbindd_status(void)
     
    170236
    171237                if (asprintf(&path, "%s/%s",
    172                         get_winbind_pipe_dir(), WINBINDD_SOCKET_NAME) > 0) {
     238                        lp_winbindd_socket_directory(), WINBINDD_SOCKET_NAME) > 0) {
    173239                        unlink(path);
    174240                        SAFE_FREE(path);
     
    193259
    194260        if (is_parent) {
    195                 serverid_deregister(procid_self());
    196                 pidfile_unlink();
     261                struct messaging_context *msg = winbind_messaging_context();
     262                struct server_id self = messaging_server_id(msg);
     263                serverid_deregister(self);
     264                pidfile_unlink(lp_pid_directory(), "winbindd");
    197265        }
    198266
     
    212280                 signum, (int)*is_parent));
    213281        terminate(*is_parent);
     282}
     283
     284/*
     285  handle stdin becoming readable when we are in --foreground mode
     286 */
     287static void winbindd_stdin_handler(struct tevent_context *ev,
     288                               struct tevent_fd *fde,
     289                               uint16_t flags,
     290                               void *private_data)
     291{
     292        char c;
     293        if (read(0, &c, 1) != 1) {
     294                bool *is_parent = talloc_get_type_abort(private_data, bool);
     295
     296                /* we have reached EOF on stdin, which means the
     297                   parent has exited. Shutdown the server */
     298                DEBUG(0,("EOF on stdin (is_parent=%d)\n",
     299                         (int)*is_parent));
     300                terminate(*is_parent);
     301        }
    214302}
    215303
     
    262350}
    263351
     352bool winbindd_setup_stdin_handler(bool parent, bool foreground)
     353{
     354        bool *is_parent;
     355
     356        if (foreground) {
     357                struct stat st;
     358
     359                is_parent = talloc(winbind_event_context(), bool);
     360                if (!is_parent) {
     361                        return false;
     362                }
     363
     364                *is_parent = parent;
     365
     366                /* if we are running in the foreground then look for
     367                   EOF on stdin, and exit if it happens. This allows
     368                   us to die if the parent process dies
     369                   Only do this on a pipe or socket, no other device.
     370                */
     371                if (fstat(0, &st) != 0) {
     372                        return false;
     373                }
     374                if (S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode)) {
     375                        tevent_add_fd(winbind_event_context(),
     376                                        is_parent,
     377                                        0,
     378                                        TEVENT_FD_READ,
     379                                        winbindd_stdin_handler,
     380                                        is_parent);
     381                }
     382        }
     383
     384        return true;
     385}
     386
    264387static void winbindd_sig_hup_handler(struct tevent_context *ev,
    265388                                     struct tevent_signal *se,
     
    388511                                       DATA_BLOB *data)
    389512{
    390         uint8 ret;
     513        uint8_t ret;
    391514        pid_t child_pid;
    392515        NTSTATUS status;
     
    400523         * code can safely use fork/waitpid...
    401524         */
    402         child_pid = sys_fork();
     525        child_pid = fork();
    403526
    404527        if (child_pid == -1) {
     
    427550        CatchSignal(SIGCHLD, SIG_DFL);
    428551
    429         ret = (uint8)winbindd_validate_cache_nobackup();
     552        ret = (uint8_t)winbindd_validate_cache_nobackup();
    430553        DEBUG(10, ("winbindd_msg_validata_cache: got return value %d\n", ret));
    431554        messaging_send_buf(msg_ctx, server_id, MSG_WINBIND_VALIDATE_CACHE, &ret,
     
    460583        { WINBINDD_CCACHE_NTLMAUTH, winbindd_ccache_ntlm_auth, "NTLMAUTH" },
    461584        { WINBINDD_CCACHE_SAVE, winbindd_ccache_save, "CCACHE_SAVE" },
    462 
    463         /* WINS functions */
    464 
    465         { WINBINDD_WINS_BYNAME, winbindd_wins_byname, "WINS_BYNAME" },
    466         { WINBINDD_WINS_BYIP, winbindd_wins_byip, "WINS_BYIP" },
    467585
    468586        /* End of list */
     
    556674          winbindd_pam_chng_pswd_auth_crap_send,
    557675          winbindd_pam_chng_pswd_auth_crap_recv },
     676        { WINBINDD_WINS_BYIP, "WINS_BYIP",
     677          winbindd_wins_byip_send, winbindd_wins_byip_recv },
     678        { WINBINDD_WINS_BYNAME, "WINS_BYNAME",
     679          winbindd_wins_byname_send, winbindd_wins_byname_recv },
    558680
    559681        { 0, NULL, NULL, NULL }
     
    589711        state->cmd_name = "unknown request";
    590712        state->recv_fn = NULL;
    591         state->last_access = time(NULL);
     713        /* client is newest */
     714        winbindd_promote_client(state);
    592715
    593716        /* Process command */
     
    700823static void winbind_client_request_read(struct tevent_req *req);
    701824static void winbind_client_response_written(struct tevent_req *req);
     825static void winbind_client_activity(struct tevent_req *req);
    702826
    703827static void request_finished(struct winbindd_cli_state *state)
    704828{
    705829        struct tevent_req *req;
     830
     831        /* free client socket monitoring request */
     832        TALLOC_FREE(state->io_req);
    706833
    707834        TALLOC_FREE(state->request);
     
    717844        }
    718845        tevent_req_set_callback(req, winbind_client_response_written, state);
     846        state->io_req = req;
    719847}
    720848
     
    725853        ssize_t ret;
    726854        int err;
     855
     856        state->io_req = NULL;
    727857
    728858        ret = wb_resp_write_recv(req, &err);
     
    752882        }
    753883        tevent_req_set_callback(req, winbind_client_request_read, state);
     884        state->io_req = req;
    754885}
    755886
     
    786917        if (sock == -1) {
    787918                if (errno != EINTR) {
    788                         DEBUG(0, ("Faild to accept socket - %s\n",
     919                        DEBUG(0, ("Failed to accept socket - %s\n",
    789920                                  strerror(errno)));
    790921                }
     
    796927        /* Create new connection structure */
    797928
    798         if ((state = TALLOC_ZERO_P(NULL, struct winbindd_cli_state)) == NULL) {
     929        if ((state = talloc_zero(NULL, struct winbindd_cli_state)) == NULL) {
    799930                close(sock);
    800931                return;
     
    809940                return;
    810941        }
    811 
    812         state->last_access = time(NULL);       
    813942
    814943        state->privileged = privileged;
     
    822951        }
    823952        tevent_req_set_callback(req, winbind_client_request_read, state);
     953        state->io_req = req;
    824954
    825955        /* Add to connection list */
     
    834964        ssize_t ret;
    835965        int err;
     966
     967        state->io_req = NULL;
    836968
    837969        ret = wb_req_read_recv(req, state, &state->request, &err);
     
    850982                return;
    851983        }
     984
     985        req = wait_for_read_send(state, winbind_event_context(), state->sock,
     986                                 true);
     987        if (req == NULL) {
     988                DEBUG(0, ("winbind_client_request_read[%d:%s]:"
     989                          " wait_for_read_send failed - removing client\n",
     990                          (int)state->pid, state->cmd_name));
     991                remove_client(state);
     992                return;
     993        }
     994        tevent_req_set_callback(req, winbind_client_activity, state);
     995        state->io_req = req;
     996
    852997        process_request(state);
     998}
     999
     1000static void winbind_client_activity(struct tevent_req *req)
     1001{
     1002        struct winbindd_cli_state *state =
     1003            tevent_req_callback_data(req, struct winbindd_cli_state);
     1004        int err;
     1005        bool has_data;
     1006
     1007        has_data = wait_for_read_recv(req, &err);
     1008
     1009        if (has_data) {
     1010                DEBUG(0, ("winbind_client_activity[%d:%s]:"
     1011                          "unexpected data from client - removing client\n",
     1012                          (int)state->pid, state->cmd_name));
     1013        } else {
     1014                if (err == EPIPE) {
     1015                        DEBUG(6, ("winbind_client_activity[%d:%s]: "
     1016                                  "client has closed connection - removing "
     1017                                  "client\n",
     1018                                  (int)state->pid, state->cmd_name));
     1019                } else {
     1020                        DEBUG(2, ("winbind_client_activity[%d:%s]: "
     1021                                  "client socket error (%s) - removing "
     1022                                  "client\n",
     1023                                  (int)state->pid, state->cmd_name,
     1024                                  strerror(err)));
     1025                }
     1026        }
     1027
     1028        remove_client(state);
    8531029}
    8541030
     
    8651041                return;
    8661042        }
     1043
     1044        /*
     1045         * We need to remove a pending wb_req_read_*
     1046         * or wb_resp_write_* request before closing the
     1047         * socket.
     1048         *
     1049         * This is important as they might have used tevent_add_fd() and we
     1050         * use the epoll * backend on linux. So we must remove the tevent_fd
     1051         * before closing the fd.
     1052         *
     1053         * Otherwise we might hit a race with close_conns_after_fork() (via
     1054         * winbindd_reinit_after_fork()) where a file description
     1055         * is still open in a child, which means it's still active in
     1056         * the parents epoll queue, but the related tevent_fd is already
     1057         * already gone in the parent.
     1058         *
     1059         * See bug #11141.
     1060         */
     1061        TALLOC_FREE(state->io_req);
    8671062
    8681063        if (state->sock != -1) {
     
    9011096{
    9021097        struct winbindd_cli_state *state, *remove_state = NULL;
    903         time_t last_access = 0;
    9041098        int nidle = 0;
    9051099
     
    9071101                if (client_is_idle(state)) {
    9081102                        nidle++;
    909                         if (!last_access || state->last_access < last_access) {
    910                                 last_access = state->last_access;
    911                                 remove_state = state;
    912                         }
     1103                        /* list is sorted by access time */
     1104                        remove_state = state;
    9131105                }
    9141106        }
     
    9221114
    9231115        return False;
     1116}
     1117
     1118/*
     1119 * Terminate all clients whose requests have taken longer than
     1120 * "winbind request timeout" seconds to process, or have been
     1121 * idle for more than "winbind request timeout" seconds.
     1122 */
     1123
     1124static void remove_timed_out_clients(void)
     1125{
     1126        struct winbindd_cli_state *state, *prev = NULL;
     1127        time_t curr_time = time(NULL);
     1128        int timeout_val = lp_winbind_request_timeout();
     1129
     1130        for (state = winbindd_client_list_tail(); state; state = prev) {
     1131                time_t expiry_time;
     1132
     1133                prev = winbindd_client_list_prev(state);
     1134                expiry_time = state->last_access + timeout_val;
     1135
     1136                if (curr_time > expiry_time) {
     1137                        if (client_is_idle(state)) {
     1138                                DEBUG(5,("Idle client timed out, "
     1139                                        "shutting down sock %d, pid %u\n",
     1140                                        state->sock,
     1141                                        (unsigned int)state->pid));
     1142                        } else {
     1143                                DEBUG(5,("Client request timed out, "
     1144                                        "shutting down sock %d, pid %u\n",
     1145                                        state->sock,
     1146                                        (unsigned int)state->pid));
     1147                        }
     1148                        remove_client(state);
     1149                } else {
     1150                        /* list is sorted, previous clients in
     1151                           list are newer */
     1152                        break;
     1153                }
     1154        }
     1155}
     1156
     1157static void winbindd_scrub_clients_handler(struct tevent_context *ev,
     1158                                           struct tevent_timer *te,
     1159                                           struct timeval current_time,
     1160                                           void *private_data)
     1161{
     1162        remove_timed_out_clients();
     1163        if (tevent_add_timer(ev, ev,
     1164                             timeval_current_ofs(SCRUB_CLIENTS_INTERVAL, 0),
     1165                             winbindd_scrub_clients_handler, NULL) == NULL) {
     1166                DEBUG(0, ("winbindd: failed to reschedule client scrubber\n"));
     1167                exit(1);
     1168        }
    9241169}
    9251170
     
    9491194                }
    9501195        }
     1196        remove_timed_out_clients();
    9511197        new_connection(s->fd, s->privileged);
    9521198}
     
    9561202 */
    9571203
    958 const char *get_winbind_pipe_dir(void)
    959 {
    960         return lp_parm_const_string(-1, "winbindd", "socket dir", WINBINDD_SOCKET_DIR);
    961 }
    962 
    9631204char *get_winbind_priv_pipe_dir(void)
    9641205{
    965         return lock_path(WINBINDD_PRIV_SOCKET_SUBDIR);
     1206        return state_path(WINBINDD_PRIV_SOCKET_SUBDIR);
     1207}
     1208
     1209static void winbindd_setup_max_fds(void)
     1210{
     1211        int num_fds = MAX_OPEN_FUDGEFACTOR;
     1212        int actual_fds;
     1213
     1214        num_fds += lp_winbind_max_clients();
     1215        /* Add some more to account for 2 sockets open
     1216           when the client transitions from unprivileged
     1217           to privileged socket
     1218        */
     1219        num_fds += lp_winbind_max_clients() / 10;
     1220
     1221        /* Add one socket per child process
     1222           (yeah there are child processes other than the
     1223           domain children but only domain children can vary
     1224           with configuration
     1225        */
     1226        num_fds += lp_winbind_max_domain_connections() *
     1227                   (lp_allow_trusted_domains() ? WINBIND_MAX_DOMAINS_HINT : 1);
     1228
     1229        actual_fds = set_maxfiles(num_fds);
     1230
     1231        if (actual_fds < num_fds) {
     1232                DEBUG(1, ("winbindd_setup_max_fds: Information only: "
     1233                          "requested %d open files, %d are available.\n",
     1234                          num_fds, actual_fds));
     1235        }
    9661236}
    9671237
     
    9711241        struct winbindd_listen_state *priv_state = NULL;
    9721242        struct tevent_fd *fde;
     1243        int rc;
     1244        char *socket_path;
    9731245
    9741246        pub_state = talloc(winbind_event_context(),
     
    9801252        pub_state->privileged = false;
    9811253        pub_state->fd = create_pipe_sock(
    982                 get_winbind_pipe_dir(), WINBINDD_SOCKET_NAME, 0755);
     1254                lp_winbindd_socket_directory(), WINBINDD_SOCKET_NAME, 0755);
    9831255        if (pub_state->fd == -1) {
     1256                goto failed;
     1257        }
     1258        rc = listen(pub_state->fd, 5);
     1259        if (rc < 0) {
    9841260                goto failed;
    9851261        }
     
    10001276        }
    10011277
     1278        socket_path = get_winbind_priv_pipe_dir();
     1279        if (socket_path == NULL) {
     1280                goto failed;
     1281        }
     1282
    10021283        priv_state->privileged = true;
    10031284        priv_state->fd = create_pipe_sock(
    1004                 get_winbind_priv_pipe_dir(), WINBINDD_SOCKET_NAME, 0750);
     1285                socket_path, WINBINDD_SOCKET_NAME, 0750);
     1286        TALLOC_FREE(socket_path);
    10051287        if (priv_state->fd == -1) {
     1288                goto failed;
     1289        }
     1290        rc = listen(priv_state->fd, 5);
     1291        if (rc < 0) {
    10061292                goto failed;
    10071293        }
     
    10161302        tevent_fd_set_auto_close(fde);
    10171303
     1304        winbindd_scrub_clients_handler(winbind_event_context(), NULL,
     1305                                       timeval_current(), NULL);
    10181306        return true;
    10191307failed:
     
    10331321}
    10341322
    1035 void winbindd_register_handlers(void)
    1036 {
     1323static void winbindd_register_handlers(struct messaging_context *msg_ctx,
     1324                                       bool foreground)
     1325{
     1326        NTSTATUS status;
    10371327        /* Setup signal handlers */
    10381328
    10391329        if (!winbindd_setup_sig_term_handler(true))
     1330                exit(1);
     1331        if (!winbindd_setup_stdin_handler(true, foreground))
    10401332                exit(1);
    10411333        if (!winbindd_setup_sig_hup_handler(NULL))
     
    10581350        /* get broadcast messages */
    10591351
    1060         if (!serverid_register(procid_self(),
    1061                                FLAG_MSG_GENERAL|FLAG_MSG_DBWRAP)) {
     1352        if (!serverid_register(messaging_server_id(msg_ctx),
     1353                               FLAG_MSG_GENERAL |
     1354                               FLAG_MSG_WINBIND |
     1355                               FLAG_MSG_DBWRAP)) {
    10621356                DEBUG(1, ("Could not register myself in serverid.tdb\n"));
    10631357                exit(1);
     
    10661360        /* React on 'smbcontrol winbindd reload-config' in the same way
    10671361           as to SIGHUP signal */
    1068         messaging_register(winbind_messaging_context(), NULL,
     1362        messaging_register(msg_ctx, NULL,
    10691363                           MSG_SMB_CONF_UPDATED, msg_reload_services);
    1070         messaging_register(winbind_messaging_context(), NULL,
     1364        messaging_register(msg_ctx, NULL,
    10711365                           MSG_SHUTDOWN, msg_shutdown);
    10721366
    10731367        /* Handle online/offline messages. */
    1074         messaging_register(winbind_messaging_context(), NULL,
     1368        messaging_register(msg_ctx, NULL,
    10751369                           MSG_WINBIND_OFFLINE, winbind_msg_offline);
    1076         messaging_register(winbind_messaging_context(), NULL,
     1370        messaging_register(msg_ctx, NULL,
    10771371                           MSG_WINBIND_ONLINE, winbind_msg_online);
    1078         messaging_register(winbind_messaging_context(), NULL,
     1372        messaging_register(msg_ctx, NULL,
    10791373                           MSG_WINBIND_ONLINESTATUS, winbind_msg_onlinestatus);
    10801374
     
    10851379                           MSG_WINBIND_DOMAIN_ONLINE, winbind_msg_domain_online);
    10861380
    1087         messaging_register(winbind_messaging_context(), NULL,
     1381        messaging_register(msg_ctx, NULL,
    10881382                           MSG_DUMP_EVENT_LIST, winbind_msg_dump_event_list);
    10891383
    1090         messaging_register(winbind_messaging_context(), NULL,
     1384        messaging_register(msg_ctx, NULL,
    10911385                           MSG_WINBIND_VALIDATE_CACHE,
    10921386                           winbind_msg_validate_cache);
    10931387
    1094         messaging_register(winbind_messaging_context(), NULL,
     1388        messaging_register(msg_ctx, NULL,
    10951389                           MSG_WINBIND_DUMP_DOMAIN_LIST,
    10961390                           winbind_msg_dump_domain_list);
    10971391
    1098         messaging_register(winbind_messaging_context(), NULL,
     1392        messaging_register(msg_ctx, NULL,
    10991393                           MSG_WINBIND_IP_DROPPED,
    11001394                           winbind_msg_ip_dropped_parent);
    11011395
    11021396        /* Register handler for MSG_DEBUG. */
    1103         messaging_register(winbind_messaging_context(), NULL,
     1397        messaging_register(msg_ctx, NULL,
    11041398                           MSG_DEBUG,
    11051399                           winbind_msg_debug);
     
    11301424        }
    11311425
     1426        status = wb_irpc_register();
     1427
     1428        if (!NT_STATUS_IS_OK(status)) {
     1429                DEBUG(0, ("Could not register IRPC handlers\n"));
     1430                exit(1);
     1431        }
    11321432}
    11331433
     
    12181518/* Main function */
    12191519
    1220 int main(int argc, char **argv, char **envp)
     1520int main(int argc, const char **argv)
    12211521{
    12221522        static bool is_daemon = False;
     
    12451545        TALLOC_CTX *frame;
    12461546        NTSTATUS status;
     1547        bool ok;
    12471548
    12481549        /*
     
    12521553        frame = talloc_stackframe();
    12531554
     1555        /*
     1556         * We want total control over the permissions on created files,
     1557         * so set our umask to 0.
     1558         */
     1559        umask(0);
     1560
     1561        setup_logging("winbindd", DEBUG_DEFAULT_STDOUT);
     1562
    12541563        /* glibc (?) likes to print "User defined signal 1" and exit if a
    12551564           SIGUSR[12] is received before a handler is installed */
     
    12581567        CatchSignal(SIGUSR2, SIG_IGN);
    12591568
    1260         fault_setup((void (*)(void *))fault_quit );
    1261         dump_core_setup("winbindd");
    1262 
    1263         load_case_tables();
     1569        fault_setup();
     1570        dump_core_setup("winbindd", lp_logfile(talloc_tos()));
     1571
     1572        smb_init_locale();
    12641573
    12651574        /* Initialise for running in non-root mode */
     
    12791588        /* Initialise samba/rpc client stuff */
    12801589
    1281         pc = poptGetContext("winbindd", argc, (const char **)argv, long_options, 0);
     1590        pc = poptGetContext("winbindd", argc, argv, long_options, 0);
    12821591
    12831592        while ((opt = poptGetNextOpt(pc)) != -1) {
     
    13191628         * in production.
    13201629         */
    1321         dump_core_setup("winbindd");
    1322 
     1630        dump_core_setup("winbindd", lp_logfile(talloc_tos()));
    13231631        if (is_daemon && interactive) {
    13241632                d_fprintf(stderr,"\nERROR: "
     
    13451653                }
    13461654        }
     1655
    13471656        if (log_stdout) {
    13481657                setup_logging("winbindd", DEBUG_STDOUT);
     
    13561665
    13571666        if (!lp_load_initial_only(get_dyn_CONFIGFILE())) {
    1358                 DEBUG(0, ("error opening config file\n"));
     1667                DEBUG(0, ("error opening config file '%s'\n", get_dyn_CONFIGFILE()));
    13591668                exit(1);
    13601669        }
     
    13631672         * path is by default basename(lp_logfile()).
    13641673         */
    1365         dump_core_setup("winbindd");
     1674        dump_core_setup("winbindd", lp_logfile(talloc_tos()));
     1675
     1676        if (lp_server_role() == ROLE_ACTIVE_DIRECTORY_DC
     1677            && !lp_parm_bool(-1, "server role check", "inhibit", false)) {
     1678                DEBUG(0, ("server role = 'active directory domain controller' not compatible with running the winbindd binary. \n"));
     1679                DEBUGADD(0, ("You should start 'samba' instead, and it will control starting the internal AD DC winbindd implementation, which is not the same as this one\n"));
     1680                exit(1);
     1681        }
     1682
     1683        if (!cluster_probe_ok()) {
     1684                exit(1);
     1685        }
    13661686
    13671687        /* Initialise messaging system */
     
    13761696        }
    13771697
    1378         if (!directory_exist(lp_lockdir())) {
    1379                 mkdir(lp_lockdir(), 0755);
     1698        ok = directory_create_or_exist(lp_lock_directory(), 0755);
     1699        if (!ok) {
     1700                DEBUG(0, ("Failed to create directory %s for lock files - %s\n",
     1701                          lp_lock_directory(), strerror(errno)));
     1702                exit(1);
     1703        }
     1704
     1705        ok = directory_create_or_exist(lp_pid_directory(), 0755);
     1706        if (!ok) {
     1707                DEBUG(0, ("Failed to create directory %s for pid files - %s\n",
     1708                          lp_pid_directory(), strerror(errno)));
     1709                exit(1);
    13801710        }
    13811711
     
    13911721                DEBUG(0,("Could not initialize domain trust account secrets. Giving up\n"));
    13921722                return False;
     1723        }
     1724
     1725        status = rpccli_pre_open_netlogon_creds();
     1726        if (!NT_STATUS_IS_OK(status)) {
     1727                DEBUG(0, ("rpccli_pre_open_netlogon_creds() - %s\n",
     1728                          nt_errstr(status)));
     1729                exit(1);
    13931730        }
    13941731
     
    14071744                become_daemon(Fork, no_process_group, log_stdout);
    14081745
    1409         pidfile_create("winbindd");
     1746        pidfile_create(lp_pid_directory(), "winbindd");
    14101747
    14111748#if HAVE_SETPGID
     
    14271764        status = reinit_after_fork(winbind_messaging_context(),
    14281765                                   winbind_event_context(),
    1429                                    procid_self(), false);
     1766                                   false, NULL);
    14301767        if (!NT_STATUS_IS_OK(status)) {
    1431                 DEBUG(0,("reinit_after_fork() failed\n"));
    1432                 exit(1);
    1433         }
    1434 
    1435         winbindd_register_handlers();
    1436 
    1437         status = init_system_info();
     1768                exit_daemon("Winbindd reinit_after_fork() failed", map_errno_from_nt_status(status));
     1769        }
     1770
     1771        /*
     1772         * Do not initialize the parent-child-pipe before becoming
     1773         * a daemon: this is used to detect a died parent in the child
     1774         * process.
     1775         */
     1776        status = init_before_fork();
    14381777        if (!NT_STATUS_IS_OK(status)) {
    1439                 DEBUG(1, ("ERROR: failed to setup system user info: %s.\n",
    1440                           nt_errstr(status)));
    1441                 exit(1);
     1778                exit_daemon(nt_errstr(status), map_errno_from_nt_status(status));
     1779        }
     1780
     1781        winbindd_register_handlers(winbind_messaging_context(), !Fork);
     1782
     1783        if (!messaging_parent_dgm_cleanup_init(winbind_messaging_context())) {
     1784                exit(1);
     1785        }
     1786
     1787        status = init_system_session_info();
     1788        if (!NT_STATUS_IS_OK(status)) {
     1789                exit_daemon("Winbindd failed to setup system user info", map_errno_from_nt_status(status));
    14421790        }
    14431791
     
    14511799
    14521800        if (!winbindd_setup_listeners()) {
    1453                 DEBUG(0,("winbindd_setup_listeners() failed\n"));
    1454                 exit(1);
    1455         }
     1801                exit_daemon("Winbindd failed to setup listeners", EPIPE);
     1802        }
     1803
     1804        irpc_add_name(winbind_imessaging_context(), "winbind_server");
    14561805
    14571806        TALLOC_FREE(frame);
     1807
     1808        if (!interactive) {
     1809                daemon_ready("winbindd");
     1810        }
     1811
    14581812        /* Loop waiting for requests */
    14591813        while (1) {
Note: See TracChangeset for help on using the changeset viewer.