summaryrefslogtreecommitdiffstats
path: root/source/nsswitch/winbindd.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/nsswitch/winbindd.c')
-rw-r--r--source/nsswitch/winbindd.c215
1 files changed, 94 insertions, 121 deletions
diff --git a/source/nsswitch/winbindd.c b/source/nsswitch/winbindd.c
index bb4a1b78ec5..65361b571c4 100644
--- a/source/nsswitch/winbindd.c
+++ b/source/nsswitch/winbindd.c
@@ -4,7 +4,6 @@
Winbind daemon for ntdom nss module
Copyright (C) by Tim Potter 2000, 2001
- Copyright (C) Andrew Tridgell 2002
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -25,10 +24,11 @@
/* List of all connected clients */
-static struct winbindd_cli_state *client_list;
+struct winbindd_cli_state *client_list;
static int num_clients;
-BOOL opt_nocache = False;
-BOOL opt_dual_daemon = False;
+BOOL opt_nocache;
+
+pstring servicesf = CONFIGFILE;
/* Reload configuration */
@@ -41,22 +41,30 @@ static BOOL reload_services_file(BOOL test)
pstring fname;
pstrcpy(fname,lp_configfile());
- if (file_exist(fname,NULL) && !strcsequal(fname,dyn_CONFIGFILE)) {
- pstrcpy(dyn_CONFIGFILE,fname);
+ if (file_exist(fname,NULL) && !strcsequal(fname,servicesf)) {
+ pstrcpy(servicesf,fname);
test = False;
}
}
- snprintf(logfile, sizeof(logfile), "%s/log.winbindd", dyn_LOGFILEBASE);
+ snprintf(logfile, sizeof(logfile), "%s/log.winbindd", LOGFILEBASE);
lp_set_logfile(logfile);
- reopen_logs();
- ret = lp_load(dyn_CONFIGFILE,False,False,True);
+ if (!reopen_logs()) {
+ fprintf(stderr, "Could not open logfile: %s\n", logfile);
+ fprintf(stderr, "Continuing in the hope that that is OK\n");
+ }
+
+ ret = lp_load(servicesf,False,False,True);
- snprintf(logfile, sizeof(logfile), "%s/log.winbindd", dyn_LOGFILEBASE);
+ snprintf(logfile, sizeof(logfile), "%s/log.winbindd", LOGFILEBASE);
lp_set_logfile(logfile);
- reopen_logs();
+ if (!reopen_logs()) {
+ fprintf(stderr, "Could not open logfile: %s\n", logfile);
+ fprintf(stderr, "Continuing in the hope that that is OK\n");
+ }
+
load_interfaces();
return(ret);
@@ -223,12 +231,13 @@ static struct dispatch_table dispatch_table[] = {
{ WINBINDD_SETGRENT, winbindd_setgrent, "SETGRENT" },
{ WINBINDD_ENDGRENT, winbindd_endgrent, "ENDGRENT" },
{ WINBINDD_GETGRENT, winbindd_getgrent, "GETGRENT" },
- { WINBINDD_GETGRLST, winbindd_getgrent, "GETGRLST" },
/* PAM auth functions */
{ WINBINDD_PAM_AUTH, winbindd_pam_auth, "PAM_AUTH" },
+#ifdef WITH_WINBIND_AUTH_CRAP
{ WINBINDD_PAM_AUTH_CRAP, winbindd_pam_auth_crap, "AUTH_CRAP" },
+#endif
{ WINBINDD_PAM_CHAUTHTOK, winbindd_pam_chauthtok, "CHAUTHTOK" },
/* Enumeration functions */
@@ -368,16 +377,12 @@ static void remove_client(struct winbindd_cli_state *state)
}
}
-
/* Process a complete received packet from a client */
-void winbind_process_packet(struct winbindd_cli_state *state)
+static void process_packet(struct winbindd_cli_state *state)
{
/* Process request */
- /* Ensure null termination of entire request */
- state->request.domain[sizeof(state->request.domain)-1]='\0';
-
state->pid = state->request.pid;
process_request(state);
@@ -386,16 +391,11 @@ void winbind_process_packet(struct winbindd_cli_state *state)
state->read_buf_len = 0;
state->write_buf_len = sizeof(struct winbindd_response);
-
- /* we might need to send it to the dual daemon */
- if (opt_dual_daemon) {
- dual_send_request(state);
- }
}
/* Read some data from a client connection */
-void winbind_client_read(struct winbindd_cli_state *state)
+static void client_read(struct winbindd_cli_state *state)
{
int n;
@@ -409,11 +409,8 @@ void winbind_client_read(struct winbindd_cli_state *state)
} while (n == -1 && errno == EINTR);
- DEBUG(10,("client_read: read %d bytes. Need %d more for a full request.\n", n, sizeof(state->request) - n - state->read_buf_len ));
-
- /* Read failed, kill client */
-
if (n == -1 || n == 0) {
+ /* Read failed, kill client */
DEBUG(5,("read failed on sock %d, pid %d: %s\n",
state->sock, state->pid,
(n == -1) ? strerror(errno) : "EOF"));
@@ -422,6 +419,8 @@ void winbind_client_read(struct winbindd_cli_state *state)
return;
}
+ DEBUG(10,("client_read: read %d bytes. Need %d more for a full request.\n", n, sizeof(state->request) - n - state->read_buf_len ));
+
/* Update client state */
state->read_buf_len += n;
@@ -541,10 +540,6 @@ static void process_loop(int accept_sock)
timeout.tv_sec = WINBINDD_ESTABLISH_LOOP;
timeout.tv_usec = 0;
- if (opt_dual_daemon) {
- maxfd = dual_select_setup(&w_fds, maxfd);
- }
-
/* Set up client readers and writers */
state = client_list;
@@ -599,10 +594,6 @@ static void process_loop(int accept_sock)
if (selret > 0) {
- if (opt_dual_daemon) {
- dual_select(&w_fds);
- }
-
if (FD_ISSET(accept_sock, &r_fds))
new_connection(accept_sock);
@@ -616,7 +607,7 @@ static void process_loop(int accept_sock)
/* Read data */
- winbind_client_read(state);
+ client_read(state);
/*
* If we have the start of a
@@ -628,8 +619,8 @@ static void process_loop(int accept_sock)
if (state->read_buf_len >= sizeof(uint32)
&& *(uint32 *) &state->request != sizeof(state->request)) {
- DEBUG(0,("process_loop: Invalid request size from pid %d: %d bytes sent, should be %d\n",
- state->request.pid, *(uint32 *) &state->request, sizeof(state->request)));
+ DEBUG(0,("process_loop: Invalid request size (%d) send, should be (%d)\n",
+ *(uint32 *) &state->request, sizeof(state->request)));
remove_client(state);
break;
@@ -640,7 +631,7 @@ static void process_loop(int accept_sock)
if (state->read_buf_len ==
sizeof(state->request)) {
- winbind_process_packet(state);
+ process_packet(state);
}
}
@@ -676,64 +667,6 @@ static void process_loop(int accept_sock)
}
}
-
-/*
- these are split out from the main winbindd for use by the background daemon
- */
-int winbind_setup_common(void)
-{
- load_interfaces();
-
- if (!secrets_init()) {
-
- DEBUG(0,("Could not initialize domain trust account secrets. Giving up\n"));
- return 1;
-
- }
-
- namecache_enable(); /* Enable netbios namecache */
-
- /* Get list of domains we look up requests for. This includes the
- domain which we are a member of as well as any trusted
- domains. */
-
- init_domain_list();
-
- ZERO_STRUCT(server_state);
-
- /* Winbind daemon initialisation */
-
- if (!winbindd_param_init())
- return 1;
-
- if (!winbindd_idmap_init())
- return 1;
-
- /* Unblock all signals we are interested in as they may have been
- blocked by the parent process. */
-
- BlockSignals(False, SIGINT);
- BlockSignals(False, SIGQUIT);
- BlockSignals(False, SIGTERM);
- BlockSignals(False, SIGUSR1);
- BlockSignals(False, SIGUSR2);
- BlockSignals(False, SIGHUP);
-
- /* Setup signal handlers */
-
- CatchSignal(SIGINT, termination_handler); /* Exit on these sigs */
- CatchSignal(SIGQUIT, termination_handler);
- CatchSignal(SIGTERM, termination_handler);
-
- CatchSignal(SIGPIPE, SIG_IGN); /* Ignore sigpipe */
-
- CatchSignal(SIGUSR2, sigusr2_handler); /* Debugging sigs */
- CatchSignal(SIGHUP, sighup_handler);
-
- return 0;
-}
-
-
/* Main function */
struct winbindd_state server_state; /* Server state information */
@@ -743,14 +676,13 @@ static void usage(void)
{
printf("Usage: winbindd [options]\n");
printf("\t-i interactive mode\n");
- printf("\t-B dual daemon mode\n");
printf("\t-n disable cacheing\n");
printf("\t-d level set debug level\n");
printf("\t-s configfile choose smb.conf location\n");
printf("\t-h show this help message\n");
}
- int main(int argc, char **argv)
+int main(int argc, char **argv)
{
extern BOOL AllowDebugChange;
extern pstring global_myname;
@@ -767,15 +699,11 @@ static void usage(void)
CatchSignal(SIGUSR1, SIG_IGN);
CatchSignal(SIGUSR2, SIG_IGN);
- fault_setup((void (*)(void *))fault_quit );
+ TimeInit();
- /* Append to log file by default as we are a single process daemon
- program. */
-
- append_log = True;
+ charset_initialise(); /* For *&#^%'s sake don't remove this */
- snprintf(logfile, sizeof(logfile), "%s/log.winbindd", dyn_LOGFILEBASE);
- lp_set_logfile(logfile);
+ fault_setup((void (*)(void *))fault_quit );
/* Initialise for running in non-root mode */
@@ -788,7 +716,7 @@ static void usage(void)
/* Initialise samba/rpc client stuff */
- while ((opt = getopt(argc, argv, "id:s:nhB")) != EOF) {
+ while ((opt = getopt(argc, argv, "id:s:nh")) != EOF) {
switch (opt) {
/* Don't become a daemon */
@@ -796,11 +724,6 @@ static void usage(void)
interactive = True;
break;
- /* dual daemon system */
- case 'B':
- opt_dual_daemon = True;
- break;
-
/* disable cacheing */
case 'n':
opt_nocache = True;
@@ -814,7 +737,7 @@ static void usage(void)
/* Load a different smb.conf file */
case 's':
- pstrcpy(dyn_CONFIGFILE,optarg);
+ pstrcpy(servicesf,optarg);
break;
case 'h':
@@ -827,10 +750,19 @@ static void usage(void)
}
}
- snprintf(logfile, sizeof(logfile), "%s/log.winbindd", dyn_LOGFILEBASE);
+ /* Append to log file by default as we are a single process daemon
+ program. */
+
+ append_log = True;
+
+ snprintf(logfile, sizeof(logfile), "%s/log.winbindd", LOGFILEBASE);
lp_set_logfile(logfile);
+
setup_logging("winbindd", interactive);
- reopen_logs();
+ if (!reopen_logs()) {
+ fprintf(stderr, "Could not open logfile: %s\n", logfile);
+ fprintf(stderr, "Continuing in the hope that that is OK\n");
+ }
DEBUG(1, ("winbindd version %s started.\n", VERSION ) );
DEBUGADD( 1, ( "Copyright The Samba Team 2000-2001\n" ) );
@@ -840,6 +772,8 @@ static void usage(void)
exit(1);
}
+ codepage_initialise(lp_client_code_page());
+
/* Setup names. */
if (!*global_myname) {
@@ -868,14 +802,52 @@ static void usage(void)
setpgid( (pid_t)0, (pid_t)0);
#endif
- if (opt_dual_daemon) {
- do_dual_daemon();
- }
+ load_interfaces();
+
+ if (!secrets_init()) {
- if (winbind_setup_common() != 0) {
+ DEBUG(0,("Could not initialize domain trust account secrets. Giving up\n"));
return 1;
+
}
+ /* Get list of domains we look up requests for. This includes the
+ domain which we are a member of as well as any trusted
+ domains. */
+
+ init_domain_list();
+
+ ZERO_STRUCT(server_state);
+
+ /* Winbind daemon initialisation */
+
+ if (!winbindd_param_init())
+ return 1;
+
+ if (!winbindd_idmap_init())
+ return 1;
+
+ /* Unblock all signals we are interested in as they may have been
+ blocked by the parent process. */
+
+ BlockSignals(False, SIGINT);
+ BlockSignals(False, SIGQUIT);
+ BlockSignals(False, SIGTERM);
+ BlockSignals(False, SIGUSR1);
+ BlockSignals(False, SIGUSR2);
+ BlockSignals(False, SIGHUP);
+
+ /* Setup signal handlers */
+
+ CatchSignal(SIGINT, termination_handler); /* Exit on these sigs */
+ CatchSignal(SIGQUIT, termination_handler);
+ CatchSignal(SIGTERM, termination_handler);
+
+ CatchSignal(SIGPIPE, SIG_IGN); /* Ignore sigpipe */
+
+ CatchSignal(SIGUSR2, sigusr2_handler); /* Debugging sigs */
+ CatchSignal(SIGHUP, sighup_handler);
+
/* Initialise messaging system */
if (!message_init()) {
@@ -883,8 +855,6 @@ static void usage(void)
exit(1);
}
- register_msg_pool_usage();
-
/* Create UNIX domain socket */
if ((accept_sock = create_sock()) == -1) {
@@ -896,6 +866,9 @@ static void usage(void)
process_loop(accept_sock);
+#if 0
uni_group_cache_shutdown();
+#endif
+
return 0;
}