~ubuntu-branches/ubuntu/gutsy/samba/gutsy-updates

« back to all changes in this revision

Viewing changes to source/smbd/server.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2006-11-28 20:14:37 UTC
  • mfrom: (0.10.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061128201437-a6x4lzlhempazocp
Tags: 3.0.23d-1ubuntu1
* Merge from debian unstable.
* Drop python2.4-samba, replace with python-samba. Added Conflicts/Replaces
  on python2.4-samba
* Drop track-connection-dos.patch, ubuntu-winbind-panic.patch, 
  ubuntu-fix-ldap.patch, ubuntu-setlocale.patch, ubuntu-setlocale-fixes.patch
* Remaining Ubuntu changes:
  - Revert Debian's installation of mount.cifs and umount.cifs as suid
  - Comment out the default [homes] shares and add more verbose comments to
    explain what they do and how they work (closes: launchpad.net/27608)
  - Add a "valid users = %S" stanza to the commented-out [homes] section, to
    show users how to restrict access to \\server\username to only username.
  - Change the (commented-out) "printer admin" example to use "@lpadmin"
    instead of "@ntadmin", since the lpadmin group is used for spool admin.
  - Alter the panic-action script to encourage users to report their
    bugs in Ubuntu packages to Ubuntu, rather than reporting to Debian.
    Modify text to more closely match the Debian script
  - Munge our init script to deal with the fact that our implementation
    (or lack thereof) of log_daemon_msg and log_progress_msg differs
    from Debian's implementation of the same (Ubuntu #19691)
  - Kept ubuntu-auxsrc.patch: some auxilliary sources (undocumented in 
    previous changelogs)
  - Set default workgroup to MSHOME

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
#include "includes.h"
24
24
 
25
 
#ifdef HAVE_SYS_PRCTL_H
26
 
#include <sys/prctl.h>
27
 
#endif
 
25
static_decl_rpc;
28
26
 
29
27
static int am_parent = 1;
30
28
 
62
60
        client_setfd(fd);
63
61
}
64
62
 
 
63
/*******************************************************************
 
64
 What to do when smb.conf is updated.
 
65
 ********************************************************************/
 
66
 
 
67
static void smb_conf_updated(int msg_type, struct process_id src,
 
68
                             void *buf, size_t len)
 
69
{
 
70
        DEBUG(10,("smb_conf_updated: Got message saying smb.conf was updated. Reloading.\n"));
 
71
        reload_services(False);
 
72
}
 
73
 
 
74
 
65
75
/****************************************************************************
66
76
 Terminate signal.
67
77
****************************************************************************/
144
154
static void msg_exit_server(int msg_type, struct process_id src,
145
155
                            void *buf, size_t len)
146
156
{
147
 
        exit_server("Got a SHUTDOWN message");
148
 
}
 
157
        DEBUG(3, ("got a SHUTDOWN message\n"));
 
158
        exit_server_cleanly(NULL);
 
159
}
 
160
 
 
161
#ifdef DEVELOPER
 
162
static void msg_inject_fault(int msg_type, struct process_id src,
 
163
                            void *buf, size_t len)
 
164
{
 
165
        int sig;
 
166
 
 
167
        if (len != sizeof(int)) {
 
168
                
 
169
                DEBUG(0, ("Process %llu sent bogus signal injection request\n",
 
170
                        (unsigned long long)src.pid));
 
171
                return;
 
172
        }
 
173
 
 
174
        sig = *(int *)buf;
 
175
        if (sig == -1) {
 
176
                exit_server("internal error injected");
 
177
                return;
 
178
        }
 
179
 
 
180
#if HAVE_STRSIGNAL
 
181
        DEBUG(0, ("Process %llu requested injection of signal %d (%s)\n",
 
182
                    (unsigned long long)src.pid, sig, strsignal(sig)));
 
183
#else
 
184
        DEBUG(0, ("Process %llu requested injection of signal %d\n",
 
185
                    (unsigned long long)src.pid, sig));
 
186
#endif
 
187
 
 
188
        kill(sys_getpid(), sig);
 
189
}
 
190
#endif /* DEVELOPER */
149
191
 
150
192
 
151
193
/****************************************************************************
330
372
        message_register(MSG_SMB_SAM_SYNC, msg_sam_sync);
331
373
        message_register(MSG_SMB_SAM_REPL, msg_sam_repl);
332
374
        message_register(MSG_SHUTDOWN, msg_exit_server);
 
375
        message_register(MSG_SMB_FILE_RENAME, msg_file_was_renamed);
 
376
        message_register(MSG_SMB_CONF_UPDATED, smb_conf_updated); 
 
377
 
 
378
#ifdef DEVELOPER
 
379
        message_register(MSG_SMB_INJECT_FAULT, msg_inject_fault); 
 
380
#endif
333
381
 
334
382
        /* now accept incoming connections - forking a new process
335
383
           for each incoming connection */
339
387
                int num;
340
388
                
341
389
                /* Free up temporary memory from the main smbd. */
342
 
                lp_talloc_free();
 
390
                lp_TALLOC_FREE();
343
391
 
344
392
                /* Ensure we respond to PING and DEBUG messages from the main smbd. */
345
393
                message_dispatch();
351
399
                
352
400
                if (num == -1 && errno == EINTR) {
353
401
                        if (got_sig_term) {
354
 
                                exit_server("Caught TERM signal");
 
402
                                exit_server_cleanly(NULL);
355
403
                        }
356
404
 
357
405
                        /* check for sighup processing */
428
476
 
429
477
                                set_need_random_reseed();
430
478
                                /* tdb needs special fork handling - remove CLEAR_IF_FIRST flags */
431
 
                                if (tdb_reopen_all() == -1) {
 
479
                                if (tdb_reopen_all(1) == -1) {
432
480
                                        DEBUG(0,("tdb_reopen_all failed.\n"));
433
481
                                        smb_panic("tdb_reopen_all failed.");
434
482
                                }
528
576
 
529
577
        lp_killunused(conn_snum_used);
530
578
 
531
 
        ret = lp_load(dyn_CONFIGFILE, False, False, True);
 
579
        ret = lp_load(dyn_CONFIGFILE, False, False, True, True);
532
580
 
533
581
        reload_printers();
534
582
 
554
602
        return(ret);
555
603
}
556
604
 
557
 
 
558
 
#if DUMP_CORE
559
 
/*******************************************************************
560
 
prepare to dump a core file - carefully!
561
 
********************************************************************/
562
 
static BOOL dump_core(void)
563
 
{
564
 
        char *p;
565
 
        pstring dname;
566
 
        
567
 
        pstrcpy(dname,lp_logfile());
568
 
        if ((p=strrchr_m(dname,'/'))) *p=0;
569
 
        pstrcat(dname,"/corefiles");
570
 
        mkdir(dname,0700);
571
 
        sys_chown(dname,getuid(),getgid());
572
 
        chmod(dname,0700);
573
 
        if (chdir(dname)) return(False);
574
 
        umask(~(0700));
575
 
 
576
 
#ifdef HAVE_GETRLIMIT
577
 
#ifdef RLIMIT_CORE
578
 
        {
579
 
                struct rlimit rlp;
580
 
                getrlimit(RLIMIT_CORE, &rlp);
581
 
                rlp.rlim_cur = MAX(4*1024*1024,rlp.rlim_cur);
582
 
                setrlimit(RLIMIT_CORE, &rlp);
583
 
                getrlimit(RLIMIT_CORE, &rlp);
584
 
                DEBUG(3,("Core limits now %d %d\n",
585
 
                         (int)rlp.rlim_cur,(int)rlp.rlim_max));
586
 
        }
587
 
#endif
588
 
#endif
589
 
 
590
 
 
591
 
        DEBUG(0,("Dumping core in %s\n", dname));
592
 
        /* Ensure we don't have a signal handler for abort. */
593
 
#ifdef SIGABRT
594
 
        CatchSignal(SIGABRT,SIGNAL_CAST SIG_DFL);
595
 
#endif
596
 
        abort();
597
 
        return(True);
598
 
}
599
 
#endif
600
 
 
601
605
/****************************************************************************
602
606
 Exit the server.
603
607
****************************************************************************/
604
608
 
605
 
void exit_server(const char *reason)
 
609
/* Reasons for shutting down a server process. */
 
610
enum server_exit_reason { SERVER_EXIT_NORMAL, SERVER_EXIT_ABNORMAL };
 
611
 
 
612
static void exit_server_common(enum server_exit_reason how,
 
613
        const char *const reason) NORETURN_ATTRIBUTE;
 
614
 
 
615
static void exit_server_common(enum server_exit_reason how,
 
616
        const char *const reason)
606
617
{
607
618
        static int firsttime=1;
608
619
 
611
622
        firsttime = 0;
612
623
 
613
624
        change_to_root_user();
614
 
        DEBUG(2,("Closing connections\n"));
615
625
 
616
626
        if (negprot_global_auth_context) {
617
627
                (negprot_global_auth_context->free)(&negprot_global_auth_context);
635
645
        }
636
646
#endif
637
647
 
638
 
        if (!reason) {   
 
648
        locking_end();
 
649
        printing_end();
 
650
 
 
651
        if (how != SERVER_EXIT_NORMAL) {
639
652
                int oldlevel = DEBUGLEVEL;
640
653
                char *last_inbuf = get_InBuffer();
 
654
 
641
655
                DEBUGLEVEL = 10;
642
 
                DEBUG(0,("Last message was %s\n",smb_fn_name(last_message)));
643
 
                if (last_inbuf)
 
656
 
 
657
                DEBUGSEP(0);
 
658
                DEBUG(0,("Abnormal server exit: %s\n",
 
659
                        reason ? reason : "no explanation provided"));
 
660
                DEBUGSEP(0);
 
661
 
 
662
                log_stack_trace();
 
663
                if (last_inbuf) {
 
664
                        DEBUG(0,("Last message was %s\n", LAST_MESSAGE()));
644
665
                        show_msg(last_inbuf);
 
666
                }
 
667
 
645
668
                DEBUGLEVEL = oldlevel;
646
 
                DEBUG(0,("===============================================================\n"));
647
669
#if DUMP_CORE
648
 
                if (dump_core()) return;
 
670
                dump_core();
649
671
#endif
650
 
        }    
651
 
 
652
 
        locking_end();
653
 
        printing_end();
654
 
 
655
 
        DEBUG(3,("Server exit (%s)\n", (reason ? reason : "")));
 
672
 
 
673
        } else {    
 
674
                DEBUG(3,("Server exit (%s)\n",
 
675
                        (reason ? reason : "normal exit")));
 
676
        }
 
677
 
656
678
        exit(0);
657
679
}
658
680
 
 
681
void exit_server(const char *const explanation)
 
682
{
 
683
        exit_server_common(SERVER_EXIT_ABNORMAL, explanation);
 
684
}
 
685
 
 
686
void exit_server_cleanly(const char *const explanation)
 
687
{
 
688
        exit_server_common(SERVER_EXIT_NORMAL, explanation);
 
689
}
 
690
 
 
691
void exit_server_fault(void)
 
692
{
 
693
        exit_server("critical server fault");
 
694
}
 
695
 
659
696
/****************************************************************************
660
697
 Initialise connect, service and file structs.
661
698
****************************************************************************/
700
737
        static BOOL is_daemon = False;
701
738
        static BOOL interactive = False;
702
739
        static BOOL Fork = True;
 
740
        static BOOL no_process_group = False;
703
741
        static BOOL log_stdout = False;
704
742
        static char *ports = NULL;
705
743
        int opt;
706
744
        poptContext pc;
707
745
 
708
746
        struct poptOption long_options[] = {
709
 
                POPT_AUTOHELP
 
747
        POPT_AUTOHELP
710
748
        {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon (default)" },
711
749
        {"interactive", 'i', POPT_ARG_VAL, &interactive, True, "Run interactive (not a daemon)"},
712
 
        {"foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools & etc)" },
 
750
        {"foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools, etc.)" },
 
751
        {"no-process-group", '\0', POPT_ARG_VAL, &no_process_group, True, "Don't create a new process group" },
713
752
        {"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" },
714
753
        {"build-options", 'b', POPT_ARG_NONE, NULL, 'b', "Print build options" },
715
754
        {"port", 'p', POPT_ARG_STRING, &ports, 0, "Listen on the specified ports"},
716
755
        POPT_COMMON_SAMBA
717
 
        { NULL }
 
756
        POPT_COMMON_DYNCONFIG
 
757
        POPT_TABLEEND
718
758
        };
719
759
 
720
760
        load_case_tables();
771
811
        gain_root_privilege();
772
812
        gain_root_group_privilege();
773
813
 
774
 
        fault_setup((void (*)(void *))exit_server);
 
814
        fault_setup((void (*)(void *))exit_server_fault);
 
815
        dump_core_setup("smbd");
 
816
 
775
817
        CatchSignal(SIGTERM , SIGNAL_CAST sig_term);
776
818
        CatchSignal(SIGHUP,SIGNAL_CAST sig_hup);
777
819
        
825
867
 
826
868
        init_structs();
827
869
 
828
 
        if (!init_guest_info()) {
829
 
                DEBUG(0,("ERROR: failed to setup guest info.\n"));
830
 
                return -1;
831
 
        }
832
 
 
833
870
#ifdef WITH_PROFILE
834
871
        if (!profile_setup(False)) {
835
872
                DEBUG(0,("ERROR: failed to setup profiling\n"));
853
890
 
854
891
        if (is_daemon && !interactive) {
855
892
                DEBUG( 3, ( "Becoming a daemon.\n" ) );
856
 
                become_daemon(Fork);
 
893
                become_daemon(Fork, no_process_group);
857
894
        }
858
895
 
859
896
#if HAVE_SETPGID
861
898
         * If we're interactive we want to set our own process group for
862
899
         * signal management.
863
900
         */
864
 
        if (interactive)
 
901
        if (interactive && !no_process_group)
865
902
                setpgid( (pid_t)0, (pid_t)0);
866
903
#endif
867
904
 
875
912
        if (!message_init())
876
913
                exit(1);
877
914
 
 
915
        /* Initialize our global sam sid first -- quite a lot of the other
 
916
         * initialization routines further down depend on it.
 
917
         */
 
918
 
 
919
        /* Initialise the password backed before the global_sam_sid
 
920
           to ensure that we fetch from ldap before we make a domain sid up */
 
921
 
 
922
        if(!initialize_password_db(False))
 
923
                exit(1);
 
924
 
 
925
        /* Fail gracefully if we can't open secrets.tdb */
 
926
 
 
927
        if (!secrets_init()) {
 
928
                DEBUG(0, ("ERROR: smbd can not open secrets.tdb\n"));
 
929
                exit(1);
 
930
        }
 
931
 
 
932
        if(!get_global_sam_sid()) {
 
933
                DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n"));
 
934
                exit(1);
 
935
        }
 
936
 
878
937
        if (!session_init())
879
938
                exit(1);
880
939
 
884
943
        if (!locking_init(0))
885
944
                exit(1);
886
945
 
887
 
        if (!share_info_db_init())
888
 
                exit(1);
889
 
 
890
946
        namecache_enable();
891
947
 
892
948
        if (!init_registry())
900
956
        if (!print_backend_init())
901
957
                exit(1);
902
958
 
 
959
        if (!init_guest_info()) {
 
960
                DEBUG(0,("ERROR: failed to setup guest info.\n"));
 
961
                return -1;
 
962
        }
 
963
 
903
964
        /* Setup the main smbd so that we can get messages. */
904
965
        /* don't worry about general printing messages here */
905
966
 
913
974
        if ( is_daemon && !interactive )
914
975
                start_background_queue(); 
915
976
 
 
977
        /* Always attempt to initialize DMAPI. We will only use it later if
 
978
         * lp_dmapi_support is set on the share, but we need a single global
 
979
         * session to work with.
 
980
         */
 
981
        dmapi_init_session();
 
982
 
916
983
        if (!open_sockets_smbd(is_daemon, interactive, ports))
917
984
                exit(1);
918
985
 
920
987
         * everything after this point is run after the fork()
921
988
         */ 
922
989
 
923
 
#if defined(HAVE_PRCTL) && defined(PR_SET_DUMPABLE)
924
 
        /* On Linux we lose the ability to dump core when we change our user
925
 
         * ID. We know how to dump core safely, so let's make sure we have our
926
 
         * dumpable flag set.
927
 
         */
928
 
        prctl(PR_SET_DUMPABLE, 1);
929
 
#endif
930
 
 
931
 
        /* Initialise the password backed before the global_sam_sid
932
 
           to ensure that we fetch from ldap before we make a domain sid up */
933
 
 
934
 
        if(!initialize_password_db(False))
935
 
                exit(1);
936
 
 
937
 
        if(!get_global_sam_sid()) {
938
 
                DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n"));
939
 
                exit(1);
940
 
        }
941
 
 
942
990
        static_init_rpc;
943
991
 
944
992
        init_modules();
974
1022
        message_register(MSG_SMB_FORCE_TDIS, msg_force_tdis);
975
1023
 
976
1024
        smbd_process();
977
 
        
 
1025
 
978
1026
        namecache_shutdown();
979
1027
 
980
 
        exit_server("normal exit");
 
1028
        exit_server_cleanly(NULL);
981
1029
        return(0);
982
1030
}