データ構造 | |
struct | child_pid |
列挙型 | |
enum | server_exit_reason { SERVER_EXIT_NORMAL, SERVER_EXIT_ABNORMAL } |
関数 | |
int | smbd_server_fd (void) |
static void | smbd_set_server_fd (int fd) |
event_context * | smbd_event_context (void) |
messaging_context * | smbd_messaging_context (void) |
static void | smb_conf_updated (int msg_type, struct process_id src, void *buf, size_t len, void *private_data) |
static void | smb_stat_cache_delete (int msg_type, struct process_id src, void *buf, size_t len, void *private_data) |
static void | sig_term (void) |
static void | sig_hup (int sig) |
static void | sig_cld (int sig) |
static void | killkids (void) |
static void | msg_sam_sync (int UNUSED(msg_type), struct process_id UNUSED(pid), void *UNUSED(buf), size_t UNUSED(len), void *private_data) |
static void | msg_sam_repl (int msg_type, struct process_id pid, void *buf, size_t len, void *private_data) |
static BOOL | open_sockets_inetd (void) |
static void | msg_exit_server (int msg_type, struct process_id src, void *buf, size_t len, void *private_data) |
static void | msg_inject_fault (int msg_type, struct process_id src, void *buf, size_t len, void *private_data) |
static void | add_child_pid (pid_t pid) |
static void | remove_child_pid (pid_t pid) |
static BOOL | allowable_number_of_smbd_processes (void) |
static BOOL | open_sockets_smbd (BOOL is_daemon, BOOL interactive, const char *smb_ports) |
void | reload_printers (void) |
BOOL | reload_services (BOOL test) |
static void | exit_server_common (enum server_exit_reason how, const char *const reason) NORETURN_ATTRIBUTE |
void | exit_server (const char *const explanation) |
void | exit_server_cleanly (const char *const explanation) |
void | exit_server_fault (void) |
static BOOL | init_structs (void) |
void | build_options (BOOL screen) |
int | main (int argc, const char *argv[]) |
変数 | |
static_decl_rpc | |
static int | am_parent = 1 |
int | last_message = -1 |
auth_context * | negprot_global_auth_context |
pstring | user_socket_options |
SIG_ATOMIC_T | got_sig_term |
SIG_ATOMIC_T | reload_after_sighup |
static SIG_ATOMIC_T | got_sig_cld |
int | dcelogin_atmost_once |
static int | server_fd = -1 |
static struct child_pid * | children |
static int | num_children |
enum server_exit_reason |
int smbd_server_fd | ( | void | ) |
参照先 server_fd.
参照元 _spoolss_open_printer_ex()・blocking_lock_reply_error()・change_notify_reply_packet()・fake_sendfile()・generic_blocking_lock_error()・handle_aio_read_complete()・handle_aio_write_complete()・open_sockets_inetd()・open_sockets_smbd()・process_kernel_oplock_break()・process_oplock_async_level2_break_message()・process_oplock_break_message()・process_smb()・receive_message_or_smb()・reload_services()・reply_echo()・reply_readbmpx()・reply_readbraw()・reply_sesssetup_blob()・reply_writebmpx()・reply_writebraw()・schedule_aio_write_and_X()・send_blocking_reply()・send_file_readbraw()・send_file_readX()・send_nt_replies()・send_trans2_replies()・send_trans_reply()・share_sanity_checks()・switch_message()・timeout_processing().
00054 { 00055 return server_fd; 00056 }
static void smbd_set_server_fd | ( | int | fd | ) | [static] |
参照先 client_setfd()・server_fd.
参照元 open_sockets_inetd()・open_sockets_smbd().
00059 { 00060 server_fd = fd; 00061 client_setfd(fd); 00062 }
struct event_context* smbd_event_context | ( | void | ) |
参照先 ctx・event_context_init()・smb_panic().
参照元 add_idle_event()・add_oplock_timeout_handler()・idle_event_handler()・receive_message_or_smb()・smbd_messaging_context()・smbd_process().
00065 { 00066 static struct event_context *ctx; 00067 00068 if (!ctx && !(ctx = event_context_init(NULL))) { 00069 smb_panic("Could not init smbd event context\n"); 00070 } 00071 return ctx; 00072 }
struct messaging_context* smbd_messaging_context | ( | void | ) |
参照先 ctx・messaging_init()・server_id_self()・smb_panic()・smbd_event_context().
00075 { 00076 static struct messaging_context *ctx; 00077 00078 if (!ctx && !(ctx = messaging_init(NULL, server_id_self(), 00079 smbd_event_context()))) { 00080 smb_panic("Could not init smbd messaging context\n"); 00081 } 00082 return ctx; 00083 }
static void smb_conf_updated | ( | int | msg_type, | |
struct process_id | src, | |||
void * | buf, | |||
size_t | len, | |||
void * | private_data | |||
) | [static] |
参照先 reload_services().
参照元 open_sockets_smbd().
00091 { 00092 DEBUG(10,("smb_conf_updated: Got message saying smb.conf was updated. Reloading.\n")); 00093 reload_services(False); 00094 }
static void smb_stat_cache_delete | ( | int | msg_type, | |
struct process_id | src, | |||
void * | buf, | |||
size_t | len, | |||
void * | private_data | |||
) | [static] |
参照先 name・stat_cache_delete().
参照元 open_sockets_smbd().
00103 { 00104 const char *name = (const char *)buf; 00105 DEBUG(10,("smb_stat_cache_delete: delete name %s\n", name)); 00106 stat_cache_delete(name); 00107 }
static void sig_term | ( | void | ) | [static] |
参照先 got_sig_term・sys_select_signal().
00114 { 00115 got_sig_term = 1; 00116 sys_select_signal(SIGTERM); 00117 }
static void sig_hup | ( | int | sig | ) | [static] |
参照先 reload_after_sighup・sys_select_signal().
00124 { 00125 reload_after_sighup = 1; 00126 sys_select_signal(SIGHUP); 00127 }
static void sig_cld | ( | int | sig | ) | [static] |
参照先 got_sig_cld・sys_select_signal().
00133 { 00134 got_sig_cld = 1; 00135 sys_select_signal(SIGCLD); 00136 }
static void killkids | ( | void | ) | [static] |
static void msg_sam_sync | ( | int | UNUSED(msg_type), | |
struct process_id | UNUSED(pid), | |||
void * | UNUSED(buf), | |||
size_t | UNUSED(len), | |||
void * | private_data | |||
) | [static] |
static void msg_sam_repl | ( | int | msg_type, | |
struct process_id | pid, | |||
void * | buf, | |||
size_t | len, | |||
void * | private_data | |||
) | [static] |
参照元 open_sockets_smbd().
00166 { 00167 uint32 low_serial; 00168 00169 if (len != sizeof(uint32)) 00170 return; 00171 00172 low_serial = *((uint32 *)buf); 00173 00174 DEBUG(3, ("received sam replication message, serial = 0x%04x\n", 00175 low_serial)); 00176 }
static BOOL open_sockets_inetd | ( | void | ) | [static] |
参照先 close_low_fds()・set_socket_options()・smbd_server_fd()・smbd_set_server_fd()・user_socket_options.
参照元 open_sockets_smbd().
00183 { 00184 /* Started from inetd. fd 0 is the socket. */ 00185 /* We will abort gracefully when the client or remote system 00186 goes away */ 00187 smbd_set_server_fd(dup(0)); 00188 00189 /* close our standard file descriptors */ 00190 close_low_fds(False); /* Don't close stderr */ 00191 00192 set_socket_options(smbd_server_fd(),"SO_KEEPALIVE"); 00193 set_socket_options(smbd_server_fd(), user_socket_options); 00194 00195 return True; 00196 }
static void msg_exit_server | ( | int | msg_type, | |
struct process_id | src, | |||
void * | buf, | |||
size_t | len, | |||
void * | private_data | |||
) | [static] |
参照元 open_sockets_smbd().
00200 { 00201 DEBUG(3, ("got a SHUTDOWN message\n")); 00202 exit_server_cleanly(NULL); 00203 }
static void msg_inject_fault | ( | int | msg_type, | |
struct process_id | src, | |||
void * | buf, | |||
size_t | len, | |||
void * | private_data | |||
) | [static] |
参照先 exit_server()・process_id::pid・sys_getpid().
参照元 open_sockets_smbd().
00208 { 00209 int sig; 00210 00211 if (len != sizeof(int)) { 00212 00213 DEBUG(0, ("Process %llu sent bogus signal injection request\n", 00214 (unsigned long long)src.pid)); 00215 return; 00216 } 00217 00218 sig = *(int *)buf; 00219 if (sig == -1) { 00220 exit_server("internal error injected"); 00221 return; 00222 } 00223 00224 #if HAVE_STRSIGNAL 00225 DEBUG(0, ("Process %llu requested injection of signal %d (%s)\n", 00226 (unsigned long long)src.pid, sig, strsignal(sig))); 00227 #else 00228 DEBUG(0, ("Process %llu requested injection of signal %d\n", 00229 (unsigned long long)src.pid, sig)); 00230 #endif 00231 00232 kill(sys_getpid(), sig); 00233 }
static void add_child_pid | ( | pid_t | pid | ) | [static] |
参照先 children・child_pid::pid.
参照元 open_sockets_smbd().
00245 { 00246 struct child_pid *child; 00247 00248 if (lp_max_smbd_processes() == 0) { 00249 /* Don't bother with the child list if we don't care anyway */ 00250 return; 00251 } 00252 00253 child = SMB_MALLOC_P(struct child_pid); 00254 if (child == NULL) { 00255 DEBUG(0, ("Could not add child struct -- malloc failed\n")); 00256 return; 00257 } 00258 child->pid = pid; 00259 DLIST_ADD(children, child); 00260 num_children += 1; 00261 }
static void remove_child_pid | ( | pid_t | pid | ) | [static] |
参照先 children・child_pid::next・child_pid::pid.
参照元 open_sockets_smbd().
00264 { 00265 struct child_pid *child; 00266 00267 if (lp_max_smbd_processes() == 0) { 00268 /* Don't bother with the child list if we don't care anyway */ 00269 return; 00270 } 00271 00272 for (child = children; child != NULL; child = child->next) { 00273 if (child->pid == pid) { 00274 struct child_pid *tmp = child; 00275 DLIST_REMOVE(children, child); 00276 SAFE_FREE(tmp); 00277 num_children -= 1; 00278 return; 00279 } 00280 } 00281 00282 DEBUG(0, ("Could not find child %d -- ignoring\n", (int)pid)); 00283 }
static BOOL allowable_number_of_smbd_processes | ( | void | ) | [static] |
参照元 open_sockets_smbd().
00290 { 00291 int max_processes = lp_max_smbd_processes(); 00292 00293 if (!max_processes) 00294 return True; 00295 00296 return num_children < max_processes; 00297 }
参照先 add_child_pid()・allowable_number_of_smbd_processes()・am_parent・CatchChild()・CatchSignal()・change_to_root_user()・check_reload()・close_low_fds()・errno・exit_server_cleanly()・force_check_log_size()・get_peer_addr()・got_sig_cld・got_sig_term・iface_count()・iface_n_ip()・interpret_addr()・killkids()・lp_TALLOC_FREE()・message_dispatch()・message_register()・msg_exit_server()・msg_file_was_renamed()・msg_inject_fault()・msg_sam_repl()・msg_sam_sync()・next_token()・open_socket_in()・open_sockets_inetd()・child_pid::pid・port・reload_after_sighup・reload_services()・remove_child_pid()・set_blocking()・set_need_random_reseed()・set_remote_machine_name()・set_socket_options()・sig_cld()・smb_conf_updated()・smb_panic()・smb_stat_cache_delete()・smb_xstrdup()・smbd_server_fd()・smbd_set_server_fd()・strerror()・sys_fork()・sys_select()・sys_waitpid()・tdb_reopen_all()・user_socket_options.
参照元 main().
00304 { 00305 int num_interfaces = iface_count(); 00306 int num_sockets = 0; 00307 int fd_listenset[FD_SETSIZE]; 00308 fd_set listen_set; 00309 int s; 00310 int maxfd = 0; 00311 int i; 00312 char *ports; 00313 00314 if (!is_daemon) { 00315 return open_sockets_inetd(); 00316 } 00317 00318 00319 #ifdef HAVE_ATEXIT 00320 { 00321 static int atexit_set; 00322 if(atexit_set == 0) { 00323 atexit_set=1; 00324 atexit(killkids); 00325 } 00326 } 00327 #endif 00328 00329 /* Stop zombies */ 00330 CatchSignal(SIGCLD, sig_cld); 00331 00332 FD_ZERO(&listen_set); 00333 00334 /* use a reasonable default set of ports - listing on 445 and 139 */ 00335 if (!smb_ports) { 00336 ports = lp_smb_ports(); 00337 if (!ports || !*ports) { 00338 ports = smb_xstrdup(SMB_PORTS); 00339 } else { 00340 ports = smb_xstrdup(ports); 00341 } 00342 } else { 00343 ports = smb_xstrdup(smb_ports); 00344 } 00345 00346 if (lp_interfaces() && lp_bind_interfaces_only()) { 00347 /* We have been given an interfaces line, and been 00348 told to only bind to those interfaces. Create a 00349 socket per interface and bind to only these. 00350 */ 00351 00352 /* Now open a listen socket for each of the 00353 interfaces. */ 00354 for(i = 0; i < num_interfaces; i++) { 00355 struct in_addr *ifip = iface_n_ip(i); 00356 fstring tok; 00357 const char *ptr; 00358 00359 if(ifip == NULL) { 00360 DEBUG(0,("open_sockets_smbd: interface %d has NULL IP address !\n", i)); 00361 continue; 00362 } 00363 00364 for (ptr=ports; next_token(&ptr, tok, " \t,", sizeof(tok)); ) { 00365 unsigned port = atoi(tok); 00366 if (port == 0 || port > 0xffff) { 00367 continue; 00368 } 00369 s = fd_listenset[num_sockets] = open_socket_in(SOCK_STREAM, port, 0, ifip->s_addr, True); 00370 if(s == -1) 00371 return False; 00372 00373 /* ready to listen */ 00374 set_socket_options(s,"SO_KEEPALIVE"); 00375 set_socket_options(s,user_socket_options); 00376 00377 /* Set server socket to non-blocking for the accept. */ 00378 set_blocking(s,False); 00379 00380 if (listen(s, SMBD_LISTEN_BACKLOG) == -1) { 00381 DEBUG(0,("listen: %s\n",strerror(errno))); 00382 close(s); 00383 return False; 00384 } 00385 FD_SET(s,&listen_set); 00386 maxfd = MAX( maxfd, s); 00387 00388 num_sockets++; 00389 if (num_sockets >= FD_SETSIZE) { 00390 DEBUG(0,("open_sockets_smbd: Too many sockets to bind to\n")); 00391 return False; 00392 } 00393 } 00394 } 00395 } else { 00396 /* Just bind to 0.0.0.0 - accept connections 00397 from anywhere. */ 00398 00399 fstring tok; 00400 const char *ptr; 00401 00402 num_interfaces = 1; 00403 00404 for (ptr=ports; next_token(&ptr, tok, " \t,", sizeof(tok)); ) { 00405 unsigned port = atoi(tok); 00406 if (port == 0 || port > 0xffff) continue; 00407 /* open an incoming socket */ 00408 s = open_socket_in(SOCK_STREAM, port, 0, 00409 interpret_addr(lp_socket_address()),True); 00410 if (s == -1) 00411 return(False); 00412 00413 /* ready to listen */ 00414 set_socket_options(s,"SO_KEEPALIVE"); 00415 set_socket_options(s,user_socket_options); 00416 00417 /* Set server socket to non-blocking for the accept. */ 00418 set_blocking(s,False); 00419 00420 if (listen(s, SMBD_LISTEN_BACKLOG) == -1) { 00421 DEBUG(0,("open_sockets_smbd: listen: %s\n", 00422 strerror(errno))); 00423 close(s); 00424 return False; 00425 } 00426 00427 fd_listenset[num_sockets] = s; 00428 FD_SET(s,&listen_set); 00429 maxfd = MAX( maxfd, s); 00430 00431 num_sockets++; 00432 00433 if (num_sockets >= FD_SETSIZE) { 00434 DEBUG(0,("open_sockets_smbd: Too many sockets to bind to\n")); 00435 return False; 00436 } 00437 } 00438 } 00439 00440 SAFE_FREE(ports); 00441 00442 /* Listen to messages */ 00443 00444 message_register(MSG_SMB_SAM_SYNC, msg_sam_sync, NULL); 00445 message_register(MSG_SMB_SAM_REPL, msg_sam_repl, NULL); 00446 message_register(MSG_SHUTDOWN, msg_exit_server, NULL); 00447 message_register(MSG_SMB_FILE_RENAME, msg_file_was_renamed, NULL); 00448 message_register(MSG_SMB_CONF_UPDATED, smb_conf_updated, NULL); 00449 message_register(MSG_SMB_STAT_CACHE_DELETE, smb_stat_cache_delete, 00450 NULL); 00451 00452 #ifdef DEVELOPER 00453 message_register(MSG_SMB_INJECT_FAULT, msg_inject_fault, NULL); 00454 #endif 00455 00456 /* now accept incoming connections - forking a new process 00457 for each incoming connection */ 00458 DEBUG(2,("waiting for a connection\n")); 00459 while (1) { 00460 fd_set lfds; 00461 int num; 00462 00463 /* Free up temporary memory from the main smbd. */ 00464 lp_TALLOC_FREE(); 00465 00466 /* Ensure we respond to PING and DEBUG messages from the main smbd. */ 00467 message_dispatch(); 00468 00469 if (got_sig_cld) { 00470 pid_t pid; 00471 got_sig_cld = False; 00472 00473 while ((pid = sys_waitpid(-1, NULL, WNOHANG)) > 0) { 00474 remove_child_pid(pid); 00475 } 00476 } 00477 00478 memcpy((char *)&lfds, (char *)&listen_set, 00479 sizeof(listen_set)); 00480 00481 num = sys_select(maxfd+1,&lfds,NULL,NULL,NULL); 00482 00483 if (num == -1 && errno == EINTR) { 00484 if (got_sig_term) { 00485 exit_server_cleanly(NULL); 00486 } 00487 00488 /* check for sighup processing */ 00489 if (reload_after_sighup) { 00490 change_to_root_user(); 00491 DEBUG(1,("Reloading services after SIGHUP\n")); 00492 reload_services(False); 00493 reload_after_sighup = 0; 00494 } 00495 00496 continue; 00497 } 00498 00499 /* check if we need to reload services */ 00500 check_reload(time(NULL)); 00501 00502 /* Find the sockets that are read-ready - 00503 accept on these. */ 00504 for( ; num > 0; num--) { 00505 struct sockaddr addr; 00506 socklen_t in_addrlen = sizeof(addr); 00507 pid_t child = 0; 00508 00509 s = -1; 00510 for(i = 0; i < num_sockets; i++) { 00511 if(FD_ISSET(fd_listenset[i],&lfds)) { 00512 s = fd_listenset[i]; 00513 /* Clear this so we don't look 00514 at it again. */ 00515 FD_CLR(fd_listenset[i],&lfds); 00516 break; 00517 } 00518 } 00519 00520 smbd_set_server_fd(accept(s,&addr,&in_addrlen)); 00521 00522 if (smbd_server_fd() == -1 && errno == EINTR) 00523 continue; 00524 00525 if (smbd_server_fd() == -1) { 00526 DEBUG(0,("open_sockets_smbd: accept: %s\n", 00527 strerror(errno))); 00528 continue; 00529 } 00530 00531 /* Ensure child is set to blocking mode */ 00532 set_blocking(smbd_server_fd(),True); 00533 00534 if (smbd_server_fd() != -1 && interactive) 00535 return True; 00536 00537 if (allowable_number_of_smbd_processes() && 00538 smbd_server_fd() != -1 && 00539 ((child = sys_fork())==0)) { 00540 /* Child code ... */ 00541 00542 /* Stop zombies, the parent explicitly handles 00543 * them, counting worker smbds. */ 00544 CatchChild(); 00545 00546 /* close the listening socket(s) */ 00547 for(i = 0; i < num_sockets; i++) 00548 close(fd_listenset[i]); 00549 00550 /* close our standard file 00551 descriptors */ 00552 close_low_fds(False); 00553 am_parent = 0; 00554 00555 set_socket_options(smbd_server_fd(),"SO_KEEPALIVE"); 00556 set_socket_options(smbd_server_fd(),user_socket_options); 00557 00558 /* this is needed so that we get decent entries 00559 in smbstatus for port 445 connects */ 00560 set_remote_machine_name(get_peer_addr(smbd_server_fd()), 00561 False); 00562 00563 /* Reset the state of the random 00564 * number generation system, so 00565 * children do not get the same random 00566 * numbers as each other */ 00567 00568 set_need_random_reseed(); 00569 /* tdb needs special fork handling - remove 00570 * CLEAR_IF_FIRST flags */ 00571 if (tdb_reopen_all(1) == -1) { 00572 DEBUG(0,("tdb_reopen_all failed.\n")); 00573 smb_panic("tdb_reopen_all failed."); 00574 } 00575 00576 return True; 00577 } 00578 /* The parent doesn't need this socket */ 00579 close(smbd_server_fd()); 00580 00581 /* Sun May 6 18:56:14 2001 ackley@cs.unm.edu: 00582 Clear the closed fd info out of server_fd -- 00583 and more importantly, out of client_fd in 00584 util_sock.c, to avoid a possible 00585 getpeername failure if we reopen the logs 00586 and use %I in the filename. 00587 */ 00588 00589 smbd_set_server_fd(-1); 00590 00591 if (child != 0) { 00592 add_child_pid(child); 00593 } 00594 00595 /* Force parent to check log size after 00596 * spawning child. Fix from 00597 * klausr@ITAP.Physik.Uni-Stuttgart.De. The 00598 * parent smbd will log to logserver.smb. It 00599 * writes only two messages for each child 00600 * started/finished. But each child writes, 00601 * say, 50 messages also in logserver.smb, 00602 * begining with the debug_count of the 00603 * parent, before the child opens its own log 00604 * file logserver.client. In a worst case 00605 * scenario the size of logserver.smb would be 00606 * checked after about 50*50=2500 messages 00607 * (ca. 100kb). 00608 * */ 00609 force_check_log_size(); 00610 00611 } /* end for num */ 00612 } /* end while 1 */ 00613 00614 /* NOTREACHED return True; */ 00615 }
void reload_printers | ( | void | ) |
参照先 del_a_printer()・is_printer_published()・load_printers()・lp_killservice()・lp_snum_ok()・nt_printer_publish()・pcap_cache_reload()・pcap_printername_ok().
参照元 check_reload()・reload_services().
00621 { 00622 int snum; 00623 int n_services = lp_numservices(); 00624 int pnum = lp_servicenumber(PRINTERS_NAME); 00625 const char *pname; 00626 00627 pcap_cache_reload(); 00628 00629 /* remove stale printers */ 00630 for (snum = 0; snum < n_services; snum++) { 00631 /* avoid removing PRINTERS_NAME or non-autoloaded printers */ 00632 if (snum == pnum || !(lp_snum_ok(snum) && lp_print_ok(snum) && 00633 lp_autoloaded(snum))) 00634 continue; 00635 00636 pname = lp_printername(snum); 00637 if (!pcap_printername_ok(pname)) { 00638 DEBUG(3, ("removing stale printer %s\n", pname)); 00639 00640 if (is_printer_published(NULL, snum, NULL)) 00641 nt_printer_publish(NULL, snum, SPOOL_DS_UNPUBLISH); 00642 del_a_printer(pname); 00643 lp_killservice(snum); 00644 } 00645 } 00646 00647 load_printers(); 00648 }
参照先 conn_snum_used()・dyn_CONFIGFILE・file_exist()・load_interfaces()・lp_file_list_changed()・lp_killunused()・lp_loaded()・mangle_reset_cache()・reload_printers()・reopen_logs()・reset_stat_cache()・set_current_service()・set_socket_options()・smbd_server_fd()・strcsequal()・user_socket_options.
参照元 add_printer_hook()・async_processing()・auth_ntlmssp_check_password()・check_reload()・delete_printer_hook()・main()・open_sockets_smbd()・reload_services()・reply_negprot()・reply_sesssetup_and_X()・reply_special()・reply_spnego_kerberos()・reply_spnego_ntlmssp()・smb_conf_updated()・start_background_queue().
00655 { 00656 BOOL ret; 00657 00658 if (lp_loaded()) { 00659 pstring fname; 00660 pstrcpy(fname,lp_configfile()); 00661 if (file_exist(fname, NULL) && 00662 !strcsequal(fname, dyn_CONFIGFILE)) { 00663 pstrcpy(dyn_CONFIGFILE, fname); 00664 test = False; 00665 } 00666 } 00667 00668 reopen_logs(); 00669 00670 if (test && !lp_file_list_changed()) 00671 return(True); 00672 00673 lp_killunused(conn_snum_used); 00674 00675 ret = lp_load(dyn_CONFIGFILE, False, False, True, True); 00676 00677 reload_printers(); 00678 00679 /* perhaps the config filename is now set */ 00680 if (!test) 00681 reload_services(True); 00682 00683 reopen_logs(); 00684 00685 load_interfaces(); 00686 00687 if (smbd_server_fd() != -1) { 00688 set_socket_options(smbd_server_fd(),"SO_KEEPALIVE"); 00689 set_socket_options(smbd_server_fd(), user_socket_options); 00690 } 00691 00692 mangle_reset_cache(); 00693 reset_stat_cache(); 00694 00695 /* this forces service parameters to be flushed */ 00696 set_current_service(NULL,0,True); 00697 00698 return(ret); 00699 }
static void exit_server_common | ( | enum server_exit_reason | how, | |
const char *const | reason | |||
) | [static] |
参照先 change_to_root_user()・conn_close_all()・dcelogin_atmost_once・DEBUGLEVEL・dfs_unlogin()・dump_core()・auth_context::free・get_InBuffer()・invalidate_all_vuids()・locking_end()・log_stack_trace()・negprot_global_auth_context・print_notify_send_messages()・printing_end()・respond_to_all_remaining_local_messages()・SERVER_EXIT_NORMAL・show_msg()・yield_connection().
参照元 exit_server()・exit_server_cleanly().
00713 { 00714 static int firsttime=1; 00715 00716 if (!firsttime) 00717 exit(0); 00718 firsttime = 0; 00719 00720 change_to_root_user(); 00721 00722 if (negprot_global_auth_context) { 00723 (negprot_global_auth_context->free)(&negprot_global_auth_context); 00724 } 00725 00726 conn_close_all(); 00727 00728 invalidate_all_vuids(); 00729 00730 print_notify_send_messages(3); /* 3 second timeout. */ 00731 00732 /* delete our entry in the connections database. */ 00733 yield_connection(NULL,""); 00734 00735 respond_to_all_remaining_local_messages(); 00736 00737 #ifdef WITH_DFS 00738 if (dcelogin_atmost_once) { 00739 dfs_unlogin(); 00740 } 00741 #endif 00742 00743 locking_end(); 00744 printing_end(); 00745 00746 if (how != SERVER_EXIT_NORMAL) { 00747 int oldlevel = DEBUGLEVEL; 00748 char *last_inbuf = get_InBuffer(); 00749 00750 DEBUGLEVEL = 10; 00751 00752 DEBUGSEP(0); 00753 DEBUG(0,("Abnormal server exit: %s\n", 00754 reason ? reason : "no explanation provided")); 00755 DEBUGSEP(0); 00756 00757 log_stack_trace(); 00758 if (last_inbuf) { 00759 DEBUG(0,("Last message was %s\n", LAST_MESSAGE())); 00760 show_msg(last_inbuf); 00761 } 00762 00763 DEBUGLEVEL = oldlevel; 00764 dump_core(); 00765 00766 } else { 00767 DEBUG(3,("Server exit (%s)\n", 00768 (reason ? reason : "normal exit"))); 00769 } 00770 00771 exit(0); 00772 }
void exit_server | ( | const char *const | explanation | ) |
参照先 exit_server_common().
参照元 blocking_lock_record_process()・blocking_lock_reply_error()・change_notify_reply()・defer_open()・exit_server_cleanly()・exit_server_fault()・file_init()・init_dptrs()・init_rpc_pipe_hnd()・mangle_init()・msg_inject_fault()・process_kernel_oplock_break()・process_oplock_async_level2_break_message()・process_oplock_break_message().
00775 { 00776 exit_server_common(SERVER_EXIT_ABNORMAL, explanation); 00777 }
void exit_server_cleanly | ( | const char *const | explanation | ) |
参照先 exit_server_common()・SERVER_EXIT_NORMAL.
参照元 async_processing()・blocking_lock_reply_error()・chain_reply()・change_notify_reply_packet()・fail_readraw()・generic_blocking_lock_error()・handle_aio_read_complete()・handle_aio_write_complete()・main()・msg_exit_server()・open_sockets_smbd()・process_kernel_oplock_break()・process_oplock_async_level2_break_message()・process_oplock_break_message()・process_smb()・reply_echo()・reply_negprot()・reply_nt1()・reply_readbmpx()・reply_readbraw()・reply_special()・reply_writebmpx()・reply_writebraw()・schedule_aio_write_and_X()・send_blocking_reply()・send_file_readbraw()・send_file_readX()・send_nt_replies()・send_trans2_replies()・send_trans_reply()・server_cryptkey()・start_background_queue()・switch_message().
00780 { 00781 exit_server_common(SERVER_EXIT_NORMAL, explanation); 00782 }
void exit_server_fault | ( | void | ) |
static BOOL init_structs | ( | void | ) | [static] |
参照先 conn_init()・file_init()・init_dptrs()・init_names()・init_rpc_pipe_hnd()・secrets_init().
参照元 main().
00794 { 00795 /* 00796 * Set the machine NETBIOS name if not already 00797 * set from the config file. 00798 */ 00799 00800 if (!init_names()) 00801 return False; 00802 00803 conn_init(); 00804 00805 file_init(); 00806 00807 /* for RPC pipes */ 00808 init_rpc_pipe_hnd(); 00809 00810 init_dptrs(); 00811 00812 secrets_init(); 00813 00814 return True; 00815 }
int main | ( | int | argc, | |
const char * | argv[] | |||
) |
参照先 become_daemon()・BlockSignals()・build_options()・CatchSignal()・claim_connection()・conn_tdb_ctx()・DEBUGLEVEL・directory_exist()・dmapi_init_session()・dump_core_setup()・exit_server_cleanly()・exit_server_fault()・fault_setup()・Fork・gain_root_group_privilege()・gain_root_privilege()・generate_random_buffer()・get_global_sam_sid()・init_account_policy()・init_guest_info()・init_modules()・init_oplocks()・init_registry()・init_sec_ctx()・init_structs()・initialize_async_io_handler()・initialize_password_db()・interactive・is_a_socket()・is_daemon・load_case_tables()・locking_init()・log_stdout・message_init()・message_register()・msg_force_tdis()・namecache_enable()・namecache_shutdown()・open_sockets_smbd()・process_id::pid・pidfile_create()・poptFreeContext()・poptGetContext()・poptGetNextOpt()・print_backend_init()・profile_setup()・reload_services()・reopen_logs()・sec_init()・secrets_init()・session_init()・set_profile_level()・set_remote_machine_name()・setup_logging()・sig_hup()・sig_term()・smbd_process()・start_background_queue()・sys_chroot()・talloc_enable_leak_report()・TimeInit().
00828 { 00829 /* shall I run as a daemon */ 00830 static BOOL is_daemon = False; 00831 static BOOL interactive = False; 00832 static BOOL Fork = True; 00833 static BOOL no_process_group = False; 00834 static BOOL log_stdout = False; 00835 static char *ports = NULL; 00836 static char *profile_level = NULL; 00837 int opt; 00838 poptContext pc; 00839 00840 struct poptOption long_options[] = { 00841 POPT_AUTOHELP 00842 {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon (default)" }, 00843 {"interactive", 'i', POPT_ARG_VAL, &interactive, True, "Run interactive (not a daemon)"}, 00844 {"foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools, etc.)" }, 00845 {"no-process-group", '\0', POPT_ARG_VAL, &no_process_group, True, "Don't create a new process group" }, 00846 {"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" }, 00847 {"build-options", 'b', POPT_ARG_NONE, NULL, 'b', "Print build options" }, 00848 {"port", 'p', POPT_ARG_STRING, &ports, 0, "Listen on the specified ports"}, 00849 {"profiling-level", 'P', POPT_ARG_STRING, &profile_level, 0, "Set profiling level","PROFILE_LEVEL"}, 00850 POPT_COMMON_SAMBA 00851 POPT_COMMON_DYNCONFIG 00852 POPT_TABLEEND 00853 }; 00854 00855 load_case_tables(); 00856 00857 TimeInit(); 00858 00859 #ifdef HAVE_SET_AUTH_PARAMETERS 00860 set_auth_parameters(argc,argv); 00861 #endif 00862 00863 pc = poptGetContext("smbd", argc, argv, long_options, 0); 00864 00865 while((opt = poptGetNextOpt(pc)) != -1) { 00866 switch (opt) { 00867 case 'b': 00868 build_options(True); /* Display output to screen as well as debug */ 00869 exit(0); 00870 break; 00871 } 00872 } 00873 00874 poptFreeContext(pc); 00875 00876 #ifdef HAVE_SETLUID 00877 /* needed for SecureWare on SCO */ 00878 setluid(0); 00879 #endif 00880 00881 sec_init(); 00882 00883 set_remote_machine_name("smbd", False); 00884 00885 if (interactive) { 00886 Fork = False; 00887 log_stdout = True; 00888 } 00889 00890 if (interactive && (DEBUGLEVEL >= 9)) { 00891 talloc_enable_leak_report(); 00892 } 00893 00894 if (log_stdout && Fork) { 00895 DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n")); 00896 exit(1); 00897 } 00898 00899 setup_logging(argv[0],log_stdout); 00900 00901 /* we want to re-seed early to prevent time delays causing 00902 client problems at a later date. (tridge) */ 00903 generate_random_buffer(NULL, 0); 00904 00905 /* make absolutely sure we run as root - to handle cases where people 00906 are crazy enough to have it setuid */ 00907 00908 gain_root_privilege(); 00909 gain_root_group_privilege(); 00910 00911 fault_setup((void (*)(void *))exit_server_fault); 00912 dump_core_setup("smbd"); 00913 00914 CatchSignal(SIGTERM , SIGNAL_CAST sig_term); 00915 CatchSignal(SIGHUP,SIGNAL_CAST sig_hup); 00916 00917 /* we are never interested in SIGPIPE */ 00918 BlockSignals(True,SIGPIPE); 00919 00920 #if defined(SIGFPE) 00921 /* we are never interested in SIGFPE */ 00922 BlockSignals(True,SIGFPE); 00923 #endif 00924 00925 #if defined(SIGUSR2) 00926 /* We are no longer interested in USR2 */ 00927 BlockSignals(True,SIGUSR2); 00928 #endif 00929 00930 /* POSIX demands that signals are inherited. If the invoking process has 00931 * these signals masked, we will have problems, as we won't recieve them. */ 00932 BlockSignals(False, SIGHUP); 00933 BlockSignals(False, SIGUSR1); 00934 BlockSignals(False, SIGTERM); 00935 00936 /* we want total control over the permissions on created files, 00937 so set our umask to 0 */ 00938 umask(0); 00939 00940 init_sec_ctx(); 00941 00942 reopen_logs(); 00943 00944 DEBUG(0,( "smbd version %s started.\n", SAMBA_VERSION_STRING)); 00945 DEBUGADD( 0, ( "%s\n", COPYRIGHT_STARTUP_MESSAGE ) ); 00946 00947 DEBUG(2,("uid=%d gid=%d euid=%d egid=%d\n", 00948 (int)getuid(),(int)getgid(),(int)geteuid(),(int)getegid())); 00949 00950 /* Output the build options to the debug log */ 00951 build_options(False); 00952 00953 if (sizeof(uint16) < 2 || sizeof(uint32) < 4) { 00954 DEBUG(0,("ERROR: Samba is not configured correctly for the word size on your machine\n")); 00955 exit(1); 00956 } 00957 00958 /* 00959 * Do this before reload_services. 00960 */ 00961 00962 if (!reload_services(False)) 00963 return(-1); 00964 00965 init_structs(); 00966 00967 #ifdef WITH_PROFILE 00968 if (!profile_setup(False)) { 00969 DEBUG(0,("ERROR: failed to setup profiling\n")); 00970 return -1; 00971 } 00972 if (profile_level != NULL) { 00973 int pl = atoi(profile_level); 00974 struct process_id src; 00975 00976 DEBUG(1, ("setting profiling level: %s\n",profile_level)); 00977 src.pid = getpid(); 00978 set_profile_level(pl, src); 00979 } 00980 #endif 00981 00982 DEBUG(3,( "loaded services\n")); 00983 00984 if (!is_daemon && !is_a_socket(0)) { 00985 if (!interactive) 00986 DEBUG(0,("standard input is not a socket, assuming -D option\n")); 00987 00988 /* 00989 * Setting is_daemon here prevents us from eventually calling 00990 * the open_sockets_inetd() 00991 */ 00992 00993 is_daemon = True; 00994 } 00995 00996 if (is_daemon && !interactive) { 00997 DEBUG( 3, ( "Becoming a daemon.\n" ) ); 00998 become_daemon(Fork, no_process_group); 00999 } 01000 01001 #if HAVE_SETPGID 01002 /* 01003 * If we're interactive we want to set our own process group for 01004 * signal management. 01005 */ 01006 if (interactive && !no_process_group) 01007 setpgid( (pid_t)0, (pid_t)0); 01008 #endif 01009 01010 if (!directory_exist(lp_lockdir(), NULL)) 01011 mkdir(lp_lockdir(), 0755); 01012 01013 if (is_daemon) 01014 pidfile_create("smbd"); 01015 01016 /* Setup all the TDB's - including CLEAR_IF_FIRST tdb's. */ 01017 if (!message_init()) 01018 exit(1); 01019 01020 /* Initialise the password backed before the global_sam_sid 01021 to ensure that we fetch from ldap before we make a domain sid up */ 01022 01023 if(!initialize_password_db(False)) 01024 exit(1); 01025 01026 if (!secrets_init()) { 01027 DEBUG(0, ("ERROR: smbd can not open secrets.tdb\n")); 01028 exit(1); 01029 } 01030 01031 if(!get_global_sam_sid()) { 01032 DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n")); 01033 exit(1); 01034 } 01035 01036 if (!session_init()) 01037 exit(1); 01038 01039 if (conn_tdb_ctx() == NULL) 01040 exit(1); 01041 01042 if (!locking_init(0)) 01043 exit(1); 01044 01045 namecache_enable(); 01046 01047 if (!init_registry()) 01048 exit(1); 01049 01050 #if 0 01051 if (!init_svcctl_db()) 01052 exit(1); 01053 #endif 01054 01055 if (!print_backend_init()) 01056 exit(1); 01057 01058 if (!init_guest_info()) { 01059 DEBUG(0,("ERROR: failed to setup guest info.\n")); 01060 return -1; 01061 } 01062 01063 /* Setup the main smbd so that we can get messages. */ 01064 /* don't worry about general printing messages here */ 01065 01066 claim_connection(NULL,"",0,True,FLAG_MSG_GENERAL|FLAG_MSG_SMBD); 01067 01068 /* only start the background queue daemon if we are 01069 running as a daemon -- bad things will happen if 01070 smbd is launched via inetd and we fork a copy of 01071 ourselves here */ 01072 01073 if ( is_daemon && !interactive ) 01074 start_background_queue(); 01075 01076 /* Always attempt to initialize DMAPI. We will only use it later if 01077 * lp_dmapi_support is set on the share, but we need a single global 01078 * session to work with. 01079 */ 01080 dmapi_init_session(); 01081 01082 if (!open_sockets_smbd(is_daemon, interactive, ports)) 01083 exit(1); 01084 01085 /* 01086 * everything after this point is run after the fork() 01087 */ 01088 01089 static_init_rpc; 01090 01091 init_modules(); 01092 01093 /* Possibly reload the services file. Only worth doing in 01094 * daemon mode. In inetd mode, we know we only just loaded this. 01095 */ 01096 if (is_daemon) { 01097 reload_services(True); 01098 } 01099 01100 if (!init_account_policy()) { 01101 DEBUG(0,("Could not open account policy tdb.\n")); 01102 exit(1); 01103 } 01104 01105 if (*lp_rootdir()) { 01106 if (sys_chroot(lp_rootdir()) == 0) 01107 DEBUG(2,("Changed root to %s\n", lp_rootdir())); 01108 } 01109 01110 /* Setup oplocks */ 01111 if (!init_oplocks()) 01112 exit(1); 01113 01114 /* Setup aio signal handler. */ 01115 initialize_async_io_handler(); 01116 01117 /* register our message handlers */ 01118 message_register(MSG_SMB_FORCE_TDIS, msg_force_tdis, NULL); 01119 01120 smbd_process(); 01121 01122 namecache_shutdown(); 01123 01124 exit_server_cleanly(NULL); 01125 return(0); 01126 }
int am_parent = 1 [static] |
int last_message = -1 |
SIG_ATOMIC_T got_sig_term |
SIG_ATOMIC_T reload_after_sighup |
SIG_ATOMIC_T got_sig_cld [static] |
int server_fd = -1 [static] |
int num_children [static] |