~lefteris-nikoltsios/+junk/samba-lp1016895

« back to all changes in this revision

Viewing changes to source3/nmbd/nmbd.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
   Copyright (C) Andrew Tridgell 1994-1998
5
5
   Copyright (C) Jeremy Allison 1997-2002
6
6
   Copyright (C) Jelmer Vernooij 2002,2003 (Conversion to popt)
7
 
   
 
7
 
8
8
   This program is free software; you can redistribute it and/or modify
9
9
   it under the terms of the GNU General Public License as published by
10
10
   the Free Software Foundation; either version 3 of the License, or
11
11
   (at your option) any later version.
12
 
   
 
12
 
13
13
   This program is distributed in the hope that it will be useful,
14
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
16
   GNU General Public License for more details.
17
 
   
 
17
 
18
18
   You should have received a copy of the GNU General Public License
19
19
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 
   
21
20
*/
22
21
 
23
22
#include "includes.h"
 
23
#include "system/filesys.h"
 
24
#include "popt_common.h"
 
25
#include "nmbd/nmbd.h"
 
26
#include "serverid.h"
 
27
#include "messages.h"
24
28
 
25
29
int ClientNMB       = -1;
26
30
int ClientDGRAM     = -1;
40
44
 
41
45
struct event_context *nmbd_event_context(void)
42
46
{
43
 
        static struct event_context *ctx;
44
 
 
45
 
        if (!ctx && !(ctx = event_context_init(NULL))) {
46
 
                smb_panic("Could not init nmbd event context");
47
 
        }
48
 
        return ctx;
 
47
        return server_event_context();
49
48
}
50
49
 
51
50
struct messaging_context *nmbd_messaging_context(void)
52
51
{
53
 
        static struct messaging_context *ctx;
54
 
 
55
 
        if (ctx == NULL) {
56
 
                ctx = messaging_init(NULL, server_id_self(),
57
 
                                     nmbd_event_context());
58
 
        }
59
 
        if (ctx == NULL) {
60
 
                DEBUG(0, ("Could not init nmbd messaging context.\n"));
61
 
        }
62
 
        return ctx;
 
52
        struct messaging_context *msg_ctx = server_messaging_context();
 
53
        if (likely(msg_ctx != NULL)) {
 
54
                return msg_ctx;
 
55
        }
 
56
        smb_panic("Could not init nmbd's messaging context.\n");
 
57
        return NULL;
63
58
}
64
59
 
65
60
/**************************************************************************** **
83
78
        kill_async_dns_child();
84
79
 
85
80
        gencache_stabilize();
 
81
        serverid_deregister(procid_self());
86
82
 
87
83
        pidfile_unlink();
88
84
 
253
249
                        continue;
254
250
                }
255
251
 
256
 
                ip = ((struct sockaddr_in *)&iface->ip)->sin_addr;
257
 
                nmask = ((struct sockaddr_in *)&iface->netmask)->sin_addr;
 
252
                ip = ((struct sockaddr_in *)(void *)&iface->ip)->sin_addr;
 
253
                nmask = ((struct sockaddr_in *)(void *)
 
254
                         &iface->netmask)->sin_addr;
258
255
 
259
256
                /*
260
257
                 * We don't want to add a loopback interface, in case
262
259
                 * ignore it here. JRA.
263
260
                 */
264
261
 
265
 
                if (is_loopback_addr((struct sockaddr *)&iface->ip)) {
 
262
                if (is_loopback_addr((struct sockaddr *)(void *)&iface->ip)) {
266
263
                        DEBUG(2,("reload_interfaces: Ignoring loopback "
267
264
                                "interface %s\n",
268
265
                                print_sockaddr(str, sizeof(str), &iface->ip) ));
301
298
                                        "ignoring non IPv4 interface.\n"));
302
299
                                continue;
303
300
                        }
304
 
                        ip = ((struct sockaddr_in *)&iface->ip)->sin_addr;
305
 
                        nmask = ((struct sockaddr_in *)&iface->netmask)->sin_addr;
 
301
                        ip = ((struct sockaddr_in *)(void *)
 
302
                              &iface->ip)->sin_addr;
 
303
                        nmask = ((struct sockaddr_in *)(void *)
 
304
                                 &iface->netmask)->sin_addr;
306
305
                        if (ip_equal_v4(ip, subrec->myip) &&
307
306
                            ip_equal_v4(nmask, subrec->mask_ip)) {
308
307
                                break;
337
336
                 * Whilst we're waiting for an interface, allow SIGTERM to
338
337
                 * cause us to exit.
339
338
                 */
340
 
                saved_handler = CatchSignal( SIGTERM, SIGNAL_CAST SIG_DFL );
 
339
                saved_handler = CatchSignal(SIGTERM, SIG_DFL);
341
340
 
342
341
                /* We only count IPv4, non-loopback interfaces here. */
343
342
                while (iface_count_v4_nl() == 0) {
345
344
                        load_interfaces();
346
345
                }
347
346
 
348
 
                CatchSignal( SIGTERM, SIGNAL_CAST saved_handler );
 
347
                CatchSignal(SIGTERM, saved_handler);
349
348
 
350
349
                /*
351
350
                 * We got an interface, go back to blocking term.
432
431
        }
433
432
 
434
433
        in_addr_to_sockaddr_storage(&ss, p->ip);
435
 
        pss = iface_ip((struct sockaddr *)&ss);
 
434
        pss = iface_ip((struct sockaddr *)(void *)&ss);
436
435
 
437
436
        if (pss == NULL) {
438
437
                DEBUG(2, ("Could not find ip for packet from %u\n",
658
657
                if (lp_enhanced_browsing())
659
658
                        sync_all_dmbs(t);
660
659
 
661
 
                /*
662
 
                 * clear the unexpected packet queue 
663
 
                 */
664
 
 
665
 
                clear_unexpected(t);
666
 
 
667
660
                /* check for new network interfaces */
668
661
 
669
662
                reload_interfaces(t);
773
766
        POPT_COMMON_SAMBA
774
767
        { NULL }
775
768
        };
776
 
        TALLOC_CTX *frame = talloc_stackframe(); /* Setup tos. */
 
769
        TALLOC_CTX *frame;
 
770
        NTSTATUS status;
 
771
 
 
772
        /*
 
773
         * Do this before any other talloc operation
 
774
         */
 
775
        talloc_enable_null_tracking();
 
776
        frame = talloc_stackframe();
777
777
 
778
778
        load_case_tables();
779
779
 
849
849
                DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n"));
850
850
                exit(1);
851
851
        }
852
 
 
853
 
        setup_logging( argv[0], log_stdout );
 
852
        if (log_stdout) {
 
853
                setup_logging( argv[0], DEBUG_STDOUT);
 
854
        } else {
 
855
                setup_logging( argv[0], DEBUG_FILE);
 
856
        }
854
857
 
855
858
        reopen_logs();
856
859
 
888
891
  
889
892
        if (is_daemon && !opt_interactive) {
890
893
                DEBUG( 2, ( "Becoming a daemon.\n" ) );
891
 
                become_daemon(Fork, no_process_group);
 
894
                become_daemon(Fork, no_process_group, log_stdout);
892
895
        }
893
896
 
894
897
#if HAVE_SETPGID
918
921
 
919
922
        pidfile_create("nmbd");
920
923
 
921
 
        if (!NT_STATUS_IS_OK(reinit_after_fork(nmbd_messaging_context(),
922
 
                                               nmbd_event_context(), false))) {
 
924
        status = reinit_after_fork(nmbd_messaging_context(),
 
925
                                   nmbd_event_context(),
 
926
                                   procid_self(), false);
 
927
 
 
928
        if (!NT_STATUS_IS_OK(status)) {
923
929
                DEBUG(0,("reinit_after_fork() failed\n"));
924
930
                exit(1);
925
931
        }
930
936
                exit(1);
931
937
 
932
938
        /* get broadcast messages */
933
 
        claim_connection(NULL,"",FLAG_MSG_GENERAL|FLAG_MSG_DBWRAP);
 
939
 
 
940
        if (!serverid_register(procid_self(),
 
941
                               FLAG_MSG_GENERAL|FLAG_MSG_DBWRAP)) {
 
942
                DEBUG(1, ("Could not register myself in serverid.tdb\n"));
 
943
                exit(1);
 
944
        }
934
945
 
935
946
        messaging_register(nmbd_messaging_context(), NULL,
936
947
                           MSG_FORCE_ELECTION, nmbd_message_election);
999
1010
                exit(1);
1000
1011
        }
1001
1012
 
 
1013
        if (!nmbd_init_packet_server()) {
 
1014
                kill_async_dns_child();
 
1015
                exit(1);
 
1016
        }
 
1017
 
1002
1018
        TALLOC_FREE(frame);
1003
1019
        process();
1004
1020
 
1005
 
        if (dbf)
1006
 
                x_fclose(dbf);
1007
1021
        kill_async_dns_child();
1008
1022
        return(0);
1009
1023
}