2 Unix SMB/CIFS implementation.
4 Winbind daemon for ntdom nss module
6 Copyright (C) by Tim Potter 2000-2002
7 Copyright (C) Andrew Tridgell 2002
8 Copyright (C) Jelmer Vernooij 2003
9 Copyright (C) Volker Lendecke 2004
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #define DBGC_CLASS DBGC_WINBIND
32 BOOL opt_nocache
= False
;
33 static BOOL interactive
= False
;
35 extern BOOL override_logfile
;
37 /* Reload configuration */
39 static BOOL
reload_services_file(void)
46 pstrcpy(fname
,lp_configfile());
47 if (file_exist(fname
,NULL
) && !strcsequal(fname
,dyn_CONFIGFILE
)) {
48 pstrcpy(dyn_CONFIGFILE
,fname
);
53 ret
= lp_load(dyn_CONFIGFILE
,False
,False
,True
,True
);
62 /**************************************************************************** **
64 **************************************************************************** */
66 static void fault_quit(void)
73 static void winbindd_status(void)
75 struct winbindd_cli_state
*tmp
;
77 DEBUG(0, ("winbindd status:\n"));
79 /* Print client state information */
81 DEBUG(0, ("\t%d clients currently active\n", winbindd_num_clients()));
83 if (DEBUGLEVEL
>= 2 && winbindd_num_clients()) {
84 DEBUG(2, ("\tclient list:\n"));
85 for(tmp
= winbindd_client_list(); tmp
; tmp
= tmp
->next
) {
86 DEBUGADD(2, ("\t\tpid %lu, sock %d\n",
87 (unsigned long)tmp
->pid
, tmp
->sock
));
92 /* Print winbindd status to log file */
94 static void print_winbindd_status(void)
99 /* Flush client cache */
101 static void flush_caches(void)
103 /* We need to invalidate cached user list entries on a SIGHUP
104 otherwise cached access denied errors due to restrict anonymous
105 hang around until the sequence number changes. */
107 wcache_invalidate_cache();
110 /* Handle the signal by unlinking socket and exiting */
112 static void terminate(void)
118 /* Remove socket file */
119 pstr_sprintf(path
, "%s/%s",
120 WINBINDD_SOCKET_DIR
, WINBINDD_SOCKET_NAME
);
125 TALLOC_CTX
*mem_ctx
= talloc_init("end_description");
126 char *description
= talloc_describe_all(mem_ctx
);
128 DEBUG(3, ("tallocs left:\n%s\n", description
));
129 talloc_destroy(mem_ctx
);
136 static BOOL do_sigterm
;
138 static void termination_handler(int signum
)
141 sys_select_signal(signum
);
144 static BOOL do_sigusr2
;
146 static void sigusr2_handler(int signum
)
149 sys_select_signal(SIGUSR2
);
152 static BOOL do_sighup
;
154 static void sighup_handler(int signum
)
157 sys_select_signal(SIGHUP
);
160 static BOOL do_sigchld
;
162 static void sigchld_handler(int signum
)
165 sys_select_signal(SIGCHLD
);
168 /* React on 'smbcontrol winbindd reload-config' in the same way as on SIGHUP*/
169 static void msg_reload_services(int msg_type
, struct process_id src
, void *buf
, size_t len
)
171 /* Flush various caches */
173 reload_services_file();
176 /* React on 'smbcontrol winbindd shutdown' in the same way as on SIGTERM*/
177 static void msg_shutdown(int msg_type
, struct process_id src
, void *buf
, size_t len
)
182 static struct winbindd_dispatch_table
{
183 enum winbindd_cmd cmd
;
184 void (*fn
)(struct winbindd_cli_state
*state
);
185 const char *winbindd_cmd_name
;
186 } dispatch_table
[] = {
190 { WINBINDD_GETPWNAM
, winbindd_getpwnam
, "GETPWNAM" },
191 { WINBINDD_GETPWUID
, winbindd_getpwuid
, "GETPWUID" },
193 { WINBINDD_SETPWENT
, winbindd_setpwent
, "SETPWENT" },
194 { WINBINDD_ENDPWENT
, winbindd_endpwent
, "ENDPWENT" },
195 { WINBINDD_GETPWENT
, winbindd_getpwent
, "GETPWENT" },
197 { WINBINDD_GETGROUPS
, winbindd_getgroups
, "GETGROUPS" },
198 { WINBINDD_GETUSERSIDS
, winbindd_getusersids
, "GETUSERSIDS" },
199 { WINBINDD_GETUSERDOMGROUPS
, winbindd_getuserdomgroups
,
200 "GETUSERDOMGROUPS" },
202 /* Group functions */
204 { WINBINDD_GETGRNAM
, winbindd_getgrnam
, "GETGRNAM" },
205 { WINBINDD_GETGRGID
, winbindd_getgrgid
, "GETGRGID" },
206 { WINBINDD_SETGRENT
, winbindd_setgrent
, "SETGRENT" },
207 { WINBINDD_ENDGRENT
, winbindd_endgrent
, "ENDGRENT" },
208 { WINBINDD_GETGRENT
, winbindd_getgrent
, "GETGRENT" },
209 { WINBINDD_GETGRLST
, winbindd_getgrent
, "GETGRLST" },
211 /* PAM auth functions */
213 { WINBINDD_PAM_AUTH
, winbindd_pam_auth
, "PAM_AUTH" },
214 { WINBINDD_PAM_AUTH_CRAP
, winbindd_pam_auth_crap
, "AUTH_CRAP" },
215 { WINBINDD_PAM_CHAUTHTOK
, winbindd_pam_chauthtok
, "CHAUTHTOK" },
216 { WINBINDD_PAM_LOGOFF
, winbindd_pam_logoff
, "PAM_LOGOFF" },
218 /* Enumeration functions */
220 { WINBINDD_LIST_USERS
, winbindd_list_users
, "LIST_USERS" },
221 { WINBINDD_LIST_GROUPS
, winbindd_list_groups
, "LIST_GROUPS" },
222 { WINBINDD_LIST_TRUSTDOM
, winbindd_list_trusted_domains
,
224 { WINBINDD_SHOW_SEQUENCE
, winbindd_show_sequence
, "SHOW_SEQUENCE" },
226 /* SID related functions */
228 { WINBINDD_LOOKUPSID
, winbindd_lookupsid
, "LOOKUPSID" },
229 { WINBINDD_LOOKUPNAME
, winbindd_lookupname
, "LOOKUPNAME" },
231 /* Lookup related functions */
233 { WINBINDD_SID_TO_UID
, winbindd_sid_to_uid
, "SID_TO_UID" },
234 { WINBINDD_SID_TO_GID
, winbindd_sid_to_gid
, "SID_TO_GID" },
235 { WINBINDD_UID_TO_SID
, winbindd_uid_to_sid
, "UID_TO_SID" },
236 { WINBINDD_GID_TO_SID
, winbindd_gid_to_sid
, "GID_TO_SID" },
237 { WINBINDD_ALLOCATE_UID
, winbindd_allocate_uid
, "ALLOCATE_UID" },
238 { WINBINDD_ALLOCATE_GID
, winbindd_allocate_uid
, "ALLOCATE_GID" },
242 { WINBINDD_CHECK_MACHACC
, winbindd_check_machine_acct
, "CHECK_MACHACC" },
243 { WINBINDD_PING
, winbindd_ping
, "PING" },
244 { WINBINDD_INFO
, winbindd_info
, "INFO" },
245 { WINBINDD_INTERFACE_VERSION
, winbindd_interface_version
,
246 "INTERFACE_VERSION" },
247 { WINBINDD_DOMAIN_NAME
, winbindd_domain_name
, "DOMAIN_NAME" },
248 { WINBINDD_DOMAIN_INFO
, winbindd_domain_info
, "DOMAIN_INFO" },
249 { WINBINDD_NETBIOS_NAME
, winbindd_netbios_name
, "NETBIOS_NAME" },
250 { WINBINDD_PRIV_PIPE_DIR
, winbindd_priv_pipe_dir
,
251 "WINBINDD_PRIV_PIPE_DIR" },
252 { WINBINDD_GETDCNAME
, winbindd_getdcname
, "GETDCNAME" },
256 { WINBINDD_WINS_BYNAME
, winbindd_wins_byname
, "WINS_BYNAME" },
257 { WINBINDD_WINS_BYIP
, winbindd_wins_byip
, "WINS_BYIP" },
261 { WINBINDD_NUM_CMDS
, NULL
, "NONE" }
264 static void process_request(struct winbindd_cli_state
*state
)
266 struct winbindd_dispatch_table
*table
= dispatch_table
;
268 /* Free response data - we may be interrupted and receive another
269 command before being able to send this data off. */
271 SAFE_FREE(state
->response
.extra_data
.data
);
273 ZERO_STRUCT(state
->response
);
275 state
->response
.result
= WINBINDD_PENDING
;
276 state
->response
.length
= sizeof(struct winbindd_response
);
278 state
->mem_ctx
= talloc_init("winbind request");
279 if (state
->mem_ctx
== NULL
)
282 /* Process command */
284 for (table
= dispatch_table
; table
->fn
; table
++) {
285 if (state
->request
.cmd
== table
->cmd
) {
286 DEBUG(10,("process_request: request fn %s\n",
287 table
->winbindd_cmd_name
));
294 DEBUG(10,("process_request: unknown request fn number %d\n",
295 (int)state
->request
.cmd
));
296 request_error(state
);
301 * A list of file descriptors being monitored by select in the main processing
302 * loop. fd_event->handler is called whenever the socket is readable/writable.
305 static struct fd_event
*fd_events
= NULL
;
307 void add_fd_event(struct fd_event
*ev
)
309 struct fd_event
*match
;
311 /* only add unique fd_event structs */
313 for (match
=fd_events
; match
; match
=match
->next
) {
315 SMB_ASSERT( match
!= ev
);
322 DLIST_ADD(fd_events
, ev
);
325 void remove_fd_event(struct fd_event
*ev
)
327 DLIST_REMOVE(fd_events
, ev
);
331 * Handler for fd_events to complete a read/write request, set up by
332 * setup_async_read/setup_async_write.
335 static void rw_callback(struct fd_event
*event
, int flags
)
340 todo
= event
->length
- event
->done
;
342 if (event
->flags
& EVENT_FD_WRITE
) {
343 SMB_ASSERT(flags
== EVENT_FD_WRITE
);
344 done
= sys_write(event
->fd
,
345 &((char *)event
->data
)[event
->done
],
350 event
->finished(event
->private_data
, False
);
355 if (event
->flags
& EVENT_FD_READ
) {
356 SMB_ASSERT(flags
== EVENT_FD_READ
);
357 done
= sys_read(event
->fd
, &((char *)event
->data
)[event
->done
],
362 event
->finished(event
->private_data
, False
);
369 if (event
->done
== event
->length
) {
371 event
->finished(event
->private_data
, True
);
376 * Request an async read/write on a fd_event structure. (*finished) is called
377 * when the request is completed or an error had occurred.
380 void setup_async_read(struct fd_event
*event
, void *data
, size_t length
,
381 void (*finished
)(void *private_data
, BOOL success
),
384 SMB_ASSERT(event
->flags
== 0);
386 event
->length
= length
;
388 event
->handler
= rw_callback
;
389 event
->finished
= finished
;
390 event
->private_data
= private_data
;
391 event
->flags
= EVENT_FD_READ
;
394 void setup_async_write(struct fd_event
*event
, void *data
, size_t length
,
395 void (*finished
)(void *private_data
, BOOL success
),
398 SMB_ASSERT(event
->flags
== 0);
400 event
->length
= length
;
402 event
->handler
= rw_callback
;
403 event
->finished
= finished
;
404 event
->private_data
= private_data
;
405 event
->flags
= EVENT_FD_WRITE
;
409 * This is the main event loop of winbind requests. It goes through a
410 * state-machine of 3 read/write requests, 4 if you have extra data to send.
412 * An idle winbind client has a read request of 4 bytes outstanding,
413 * finalizing function is request_len_recv, checking the length. request_recv
414 * then processes the packet. The processing function then at some point has
415 * to call request_finished which schedules sending the response.
418 static void request_len_recv(void *private_data
, BOOL success
);
419 static void request_recv(void *private_data
, BOOL success
);
420 static void request_main_recv(void *private_data
, BOOL success
);
421 static void request_finished(struct winbindd_cli_state
*state
);
422 void request_finished_cont(void *private_data
, BOOL success
);
423 static void response_main_sent(void *private_data
, BOOL success
);
424 static void response_extra_sent(void *private_data
, BOOL success
);
426 static void response_extra_sent(void *private_data
, BOOL success
)
428 struct winbindd_cli_state
*state
=
429 talloc_get_type_abort(private_data
, struct winbindd_cli_state
);
431 if (state
->mem_ctx
!= NULL
) {
432 talloc_destroy(state
->mem_ctx
);
433 state
->mem_ctx
= NULL
;
437 state
->finished
= True
;
441 SAFE_FREE(state
->request
.extra_data
.data
);
442 SAFE_FREE(state
->response
.extra_data
.data
);
444 setup_async_read(&state
->fd_event
, &state
->request
, sizeof(uint32
),
445 request_len_recv
, state
);
448 static void response_main_sent(void *private_data
, BOOL success
)
450 struct winbindd_cli_state
*state
=
451 talloc_get_type_abort(private_data
, struct winbindd_cli_state
);
454 state
->finished
= True
;
458 if (state
->response
.length
== sizeof(state
->response
)) {
459 if (state
->mem_ctx
!= NULL
) {
460 talloc_destroy(state
->mem_ctx
);
461 state
->mem_ctx
= NULL
;
464 setup_async_read(&state
->fd_event
, &state
->request
,
465 sizeof(uint32
), request_len_recv
, state
);
469 setup_async_write(&state
->fd_event
, state
->response
.extra_data
.data
,
470 state
->response
.length
- sizeof(state
->response
),
471 response_extra_sent
, state
);
474 static void request_finished(struct winbindd_cli_state
*state
)
476 setup_async_write(&state
->fd_event
, &state
->response
,
477 sizeof(state
->response
), response_main_sent
, state
);
480 void request_error(struct winbindd_cli_state
*state
)
482 SMB_ASSERT(state
->response
.result
== WINBINDD_PENDING
);
483 state
->response
.result
= WINBINDD_ERROR
;
484 request_finished(state
);
487 void request_ok(struct winbindd_cli_state
*state
)
489 SMB_ASSERT(state
->response
.result
== WINBINDD_PENDING
);
490 state
->response
.result
= WINBINDD_OK
;
491 request_finished(state
);
494 void request_finished_cont(void *private_data
, BOOL success
)
496 struct winbindd_cli_state
*state
=
497 talloc_get_type_abort(private_data
, struct winbindd_cli_state
);
502 request_error(state
);
505 static void request_len_recv(void *private_data
, BOOL success
)
507 struct winbindd_cli_state
*state
=
508 talloc_get_type_abort(private_data
, struct winbindd_cli_state
);
511 state
->finished
= True
;
515 if (*(uint32
*)(&state
->request
) != sizeof(state
->request
)) {
516 DEBUG(0,("request_len_recv: Invalid request size received: %d\n",
517 *(uint32
*)(&state
->request
)));
518 state
->finished
= True
;
522 setup_async_read(&state
->fd_event
, (uint32
*)(&state
->request
)+1,
523 sizeof(state
->request
) - sizeof(uint32
),
524 request_main_recv
, state
);
527 static void request_main_recv(void *private_data
, BOOL success
)
529 struct winbindd_cli_state
*state
=
530 talloc_get_type_abort(private_data
, struct winbindd_cli_state
);
533 state
->finished
= True
;
537 if (state
->request
.extra_len
== 0) {
538 state
->request
.extra_data
.data
= NULL
;
539 request_recv(state
, True
);
543 if ((!state
->privileged
) &&
544 (state
->request
.extra_len
> WINBINDD_MAX_EXTRA_DATA
)) {
545 DEBUG(3, ("Got request with %d bytes extra data on "
546 "unprivileged socket\n", (int)state
->request
.extra_len
));
547 state
->request
.extra_data
.data
= NULL
;
548 state
->finished
= True
;
552 state
->request
.extra_data
.data
=
553 SMB_MALLOC_ARRAY(char, state
->request
.extra_len
+ 1);
555 if (state
->request
.extra_data
.data
== NULL
) {
556 DEBUG(0, ("malloc failed\n"));
557 state
->finished
= True
;
561 /* Ensure null termination */
562 state
->request
.extra_data
.data
[state
->request
.extra_len
] = '\0';
564 setup_async_read(&state
->fd_event
, state
->request
.extra_data
.data
,
565 state
->request
.extra_len
, request_recv
, state
);
568 static void request_recv(void *private_data
, BOOL success
)
570 struct winbindd_cli_state
*state
=
571 talloc_get_type_abort(private_data
, struct winbindd_cli_state
);
574 state
->finished
= True
;
578 process_request(state
);
581 /* Process a new connection by adding it to the client connection list */
583 static void new_connection(int listen_sock
, BOOL privileged
)
585 struct sockaddr_un sunaddr
;
586 struct winbindd_cli_state
*state
;
590 /* Accept connection */
592 len
= sizeof(sunaddr
);
595 sock
= accept(listen_sock
, (struct sockaddr
*)&sunaddr
, &len
);
596 } while (sock
== -1 && errno
== EINTR
);
601 DEBUG(6,("accepted socket %d\n", sock
));
603 /* Create new connection structure */
605 if ((state
= TALLOC_ZERO_P(NULL
, struct winbindd_cli_state
)) == NULL
)
610 state
->last_access
= time(NULL
);
612 state
->privileged
= privileged
;
614 state
->fd_event
.fd
= state
->sock
;
615 state
->fd_event
.flags
= 0;
616 add_fd_event(&state
->fd_event
);
618 setup_async_read(&state
->fd_event
, &state
->request
, sizeof(uint32
),
619 request_len_recv
, state
);
621 /* Add to connection list */
623 winbindd_add_client(state
);
626 /* Remove a client connection from client connection list */
628 static void remove_client(struct winbindd_cli_state
*state
)
630 /* It's a dead client - hold a funeral */
638 /* Free any getent state */
640 free_getent_state(state
->getpwent_state
);
641 free_getent_state(state
->getgrent_state
);
643 /* We may have some extra data that was not freed if the
644 client was killed unexpectedly */
646 SAFE_FREE(state
->response
.extra_data
.data
);
648 if (state
->mem_ctx
!= NULL
) {
649 talloc_destroy(state
->mem_ctx
);
650 state
->mem_ctx
= NULL
;
653 remove_fd_event(&state
->fd_event
);
655 /* Remove from list and free */
657 winbindd_remove_client(state
);
663 /* Shutdown client connection which has been idle for the longest time */
665 static BOOL
remove_idle_client(void)
667 struct winbindd_cli_state
*state
, *remove_state
= NULL
;
668 time_t last_access
= 0;
671 for (state
= winbindd_client_list(); state
; state
= state
->next
) {
672 if (state
->response
.result
!= WINBINDD_PENDING
&&
673 !state
->getpwent_state
&& !state
->getgrent_state
) {
675 if (!last_access
|| state
->last_access
< last_access
) {
676 last_access
= state
->last_access
;
677 remove_state
= state
;
683 DEBUG(5,("Found %d idle client connections, shutting down sock %d, pid %u\n",
684 nidle
, remove_state
->sock
, (unsigned int)remove_state
->pid
));
685 remove_client(remove_state
);
692 /* Process incoming clients on listen_sock. We use a tricky non-blocking,
693 non-forking, non-threaded model which allows us to handle many
694 simultaneous connections while remaining impervious to many denial of
697 static void process_loop(void)
699 struct winbindd_cli_state
*state
;
702 int maxfd
, listen_sock
, listen_priv_sock
, selret
;
703 struct timeval timeout
;
705 /* We'll be doing this a lot */
707 /* Handle messages */
711 /* refresh the trusted domain cache */
713 rescan_trusted_domains();
715 /* Free up temporary memory */
718 main_loop_TALLOC_FREE();
720 /* Initialise fd lists for select() */
722 listen_sock
= open_winbindd_socket();
723 listen_priv_sock
= open_winbindd_priv_socket();
725 if (listen_sock
== -1 || listen_priv_sock
== -1) {
726 perror("open_winbind_socket");
730 maxfd
= MAX(listen_sock
, listen_priv_sock
);
734 FD_SET(listen_sock
, &r_fds
);
735 FD_SET(listen_priv_sock
, &r_fds
);
737 timeout
.tv_sec
= WINBINDD_ESTABLISH_LOOP
;
740 /* Set up client readers and writers */
742 state
= winbindd_client_list();
746 struct winbindd_cli_state
*next
= state
->next
;
748 /* Dispose of client connection if it is marked as
752 remove_client(state
);
757 for (ev
= fd_events
; ev
; ev
= ev
->next
) {
758 if (ev
->flags
& EVENT_FD_READ
) {
759 FD_SET(ev
->fd
, &r_fds
);
760 maxfd
= MAX(ev
->fd
, maxfd
);
762 if (ev
->flags
& EVENT_FD_WRITE
) {
763 FD_SET(ev
->fd
, &w_fds
);
764 maxfd
= MAX(ev
->fd
, maxfd
);
770 selret
= sys_select(maxfd
+ 1, &r_fds
, &w_fds
, NULL
, &timeout
);
777 if (errno
== EINTR
) {
781 /* Select error, something is badly wrong */
791 struct fd_event
*next
= ev
->next
;
793 if (FD_ISSET(ev
->fd
, &r_fds
))
794 flags
|= EVENT_FD_READ
;
795 if (FD_ISSET(ev
->fd
, &w_fds
))
796 flags
|= EVENT_FD_WRITE
;
798 ev
->handler(ev
, flags
);
802 if (FD_ISSET(listen_sock
, &r_fds
)) {
803 while (winbindd_num_clients() >
804 WINBINDD_MAX_SIMULTANEOUS_CLIENTS
- 1) {
805 DEBUG(5,("winbindd: Exceeding %d client "
806 "connections, removing idle "
808 WINBINDD_MAX_SIMULTANEOUS_CLIENTS
));
809 if (!remove_idle_client()) {
810 DEBUG(0,("winbindd: Exceeding %d "
811 "client connections, no idle "
812 "connection found\n",
813 WINBINDD_MAX_SIMULTANEOUS_CLIENTS
));
817 /* new, non-privileged connection */
818 new_connection(listen_sock
, False
);
821 if (FD_ISSET(listen_priv_sock
, &r_fds
)) {
822 while (winbindd_num_clients() >
823 WINBINDD_MAX_SIMULTANEOUS_CLIENTS
- 1) {
824 DEBUG(5,("winbindd: Exceeding %d client "
825 "connections, removing idle "
827 WINBINDD_MAX_SIMULTANEOUS_CLIENTS
));
828 if (!remove_idle_client()) {
829 DEBUG(0,("winbindd: Exceeding %d "
830 "client connections, no idle "
831 "connection found\n",
832 WINBINDD_MAX_SIMULTANEOUS_CLIENTS
));
836 /* new, privileged connection */
837 new_connection(listen_priv_sock
, True
);
843 winbindd_check_cache_size(time(NULL
));
846 /* Check signal handling things */
853 DEBUG(3, ("got SIGHUP\n"));
855 msg_reload_services(MSG_SMB_CONF_UPDATED
, pid_to_procid(0), NULL
, 0);
860 print_winbindd_status();
869 while ((pid
= sys_waitpid(-1, NULL
, WNOHANG
)) > 0) {
870 winbind_child_died(pid
);
877 struct winbindd_state server_state
; /* Server state information */
879 int main(int argc
, char **argv
)
882 static BOOL Fork
= True
;
883 static BOOL log_stdout
= False
;
884 static BOOL no_process_group
= False
;
885 struct poptOption long_options
[] = {
887 { "stdout", 'S', POPT_ARG_VAL
, &log_stdout
, True
, "Log to stdout" },
888 { "foreground", 'F', POPT_ARG_VAL
, &Fork
, False
, "Daemon in foreground mode" },
889 { "no-process-group", 0, POPT_ARG_VAL
, &no_process_group
, True
, "Don't create a new process group" },
890 { "interactive", 'i', POPT_ARG_NONE
, NULL
, 'i', "Interactive mode" },
891 { "no-caching", 'n', POPT_ARG_VAL
, &opt_nocache
, True
, "Disable caching" },
898 /* glibc (?) likes to print "User defined signal 1" and exit if a
899 SIGUSR[12] is received before a handler is installed */
901 CatchSignal(SIGUSR1
, SIG_IGN
);
902 CatchSignal(SIGUSR2
, SIG_IGN
);
904 fault_setup((void (*)(void *))fault_quit
);
905 dump_core_setup("winbindd");
909 /* Initialise for running in non-root mode */
913 set_remote_machine_name("winbindd", False
);
915 /* Set environment variable so we don't recursively call ourselves.
916 This may also be useful interactively. */
918 if ( !winbind_off() ) {
919 DEBUG(0,("Failed to disable recusive winbindd calls. Exiting.\n"));
923 /* Initialise samba/rpc client stuff */
925 pc
= poptGetContext("winbindd", argc
, (const char **)argv
, long_options
,
926 POPT_CONTEXT_KEEP_FIRST
);
928 while ((opt
= poptGetNextOpt(pc
)) != -1) {
930 /* Don't become a daemon */
940 if (log_stdout
&& Fork
) {
941 printf("Can't log to stdout (-S) unless daemon is in foreground +(-F) or interactive (-i)\n");
942 poptPrintUsage(pc
, stderr
, 0);
946 if (!override_logfile
) {
947 pstr_sprintf(logfile
, "%s/log.winbindd", dyn_LOGFILEBASE
);
948 lp_set_logfile(logfile
);
950 setup_logging("winbindd", log_stdout
);
953 DEBUG(1, ("winbindd version %s started.\n", SAMBA_VERSION_STRING
) );
954 DEBUGADD( 1, ( "Copyright The Samba Team 2000-2004\n" ) );
956 if (!reload_services_file()) {
957 DEBUG(0, ("error opening config file\n"));
968 if (!secrets_init()) {
970 DEBUG(0,("Could not initialize domain trust account secrets. Giving up\n"));
974 /* Enable netbios namecache */
978 /* Check winbindd parameters are valid */
980 ZERO_STRUCT(server_state
);
982 /* Winbind daemon initialisation */
984 if ( (!winbindd_param_init()) || (!winbindd_upgrade_idmap()) ||
985 (!idmap_init(lp_idmap_backend())) ) {
986 DEBUG(1, ("Could not init idmap -- netlogon proxy only\n"));
987 idmap_set_proxyonly();
990 /* Unblock all signals we are interested in as they may have been
991 blocked by the parent process. */
993 BlockSignals(False
, SIGINT
);
994 BlockSignals(False
, SIGQUIT
);
995 BlockSignals(False
, SIGTERM
);
996 BlockSignals(False
, SIGUSR1
);
997 BlockSignals(False
, SIGUSR2
);
998 BlockSignals(False
, SIGHUP
);
999 BlockSignals(False
, SIGCHLD
);
1001 /* Setup signal handlers */
1003 CatchSignal(SIGINT
, termination_handler
); /* Exit on these sigs */
1004 CatchSignal(SIGQUIT
, termination_handler
);
1005 CatchSignal(SIGTERM
, termination_handler
);
1006 CatchSignal(SIGCHLD
, sigchld_handler
);
1008 CatchSignal(SIGPIPE
, SIG_IGN
); /* Ignore sigpipe */
1010 CatchSignal(SIGUSR2
, sigusr2_handler
); /* Debugging sigs */
1011 CatchSignal(SIGHUP
, sighup_handler
);
1014 become_daemon(Fork
, no_process_group
);
1016 pidfile_create("winbindd");
1020 * If we're interactive we want to set our own process group for
1021 * signal management.
1023 if (interactive
&& !no_process_group
)
1024 setpgid( (pid_t
)0, (pid_t
)0);
1029 /* Initialise messaging system */
1031 if (!message_init()) {
1032 DEBUG(0, ("unable to initialize messaging system\n"));
1036 /* React on 'smbcontrol winbindd reload-config' in the same way
1037 as to SIGHUP signal */
1038 message_register(MSG_SMB_CONF_UPDATED
, msg_reload_services
);
1039 message_register(MSG_SHUTDOWN
, msg_shutdown
);
1041 /* Handle online/offline messages. */
1042 message_register(MSG_WINBIND_OFFLINE
,winbind_msg_offline
);
1043 message_register(MSG_WINBIND_ONLINE
,winbind_msg_online
);
1044 message_register(MSG_WINBIND_ONLINESTATUS
,winbind_msg_onlinestatus
);
1046 poptFreeContext(pc
);
1048 netsamlogon_cache_init(); /* Non-critical */
1050 if (!init_domain_list()) {
1051 DEBUG(0,("unable to initalize domain list\n"));
1057 winbindd_flush_nscd_cache();
1059 /* Loop waiting for requests */
1064 trustdom_cache_shutdown();