~lefteris-nikoltsios/+junk/samba-lp1016895

« back to all changes in this revision

Viewing changes to source4/dsdb/repl/drepl_fsmo.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:
 
1
/*
 
2
   Unix SMB/CIFS mplementation.
 
3
 
 
4
   DSDB replication service - FSMO role change
 
5
 
 
6
   Copyright (C) Nadezhda Ivanova 2010
 
7
   Copyright (C) Andrew Tridgell 2010
 
8
   Copyright (C) Andrew Bartlett 2010
 
9
   Copyright (C) Anatoliy Atanasov 2010
 
10
 
 
11
   based on drepl_ridalloc.c
 
12
 
 
13
   This program is free software; you can redistribute it and/or modify
 
14
   it under the terms of the GNU General Public License as published by
 
15
   the Free Software Foundation; either version 3 of the License, or
 
16
   (at your option) any later version.
 
17
 
 
18
   This program is distributed in the hope that it will be useful,
 
19
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
   GNU General Public License for more details.
 
22
 
 
23
   You should have received a copy of the GNU General Public License
 
24
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
25
 
 
26
*/
 
27
 
 
28
#include "includes.h"
 
29
#include "dsdb/samdb/samdb.h"
 
30
#include "smbd/service.h"
 
31
#include "dsdb/repl/drepl_service.h"
 
32
#include "param/param.h"
 
33
 
 
34
static void drepl_role_callback(struct dreplsrv_service *service,
 
35
                                WERROR werr,
 
36
                                enum drsuapi_DsExtendedError ext_err,
 
37
                                void *cb_data)
 
38
{
 
39
        if (!W_ERROR_IS_OK(werr)) {
 
40
                DEBUG(0,(__location__ ": Failed role transfer - %s - extended_ret[0x%X]\n",
 
41
                         win_errstr(werr), ext_err));
 
42
        } else {
 
43
                DEBUG(0,(__location__ ": Successful role transfer\n"));
 
44
        }
 
45
}
 
46
 
 
47
static bool fsmo_master_cmp(struct ldb_dn *ntds_dn, struct ldb_dn *role_owner_dn)
 
48
{
 
49
        if (ldb_dn_compare(ntds_dn, role_owner_dn) == 0) {
 
50
                DEBUG(0,("\nWe are the FSMO master.\n"));
 
51
                return true;
 
52
        }
 
53
        return false;
 
54
}
 
55
 
 
56
/*
 
57
  see which role is we are asked to assume, initialize data and send request
 
58
 */
 
59
WERROR dreplsrv_fsmo_role_check(struct dreplsrv_service *service,
 
60
                                enum drepl_role_master role)
 
61
{
 
62
        struct ldb_dn *role_owner_dn, *fsmo_role_dn, *ntds_dn;
 
63
        TALLOC_CTX *tmp_ctx = talloc_new(service);
 
64
        uint64_t fsmo_info = 0;
 
65
        enum drsuapi_DsExtendedOperation extended_op = DRSUAPI_EXOP_NONE;
 
66
        WERROR werr;
 
67
 
 
68
        ntds_dn = samdb_ntds_settings_dn(service->samdb);
 
69
        if (!ntds_dn) {
 
70
                return WERR_DS_DRA_INTERNAL_ERROR;
 
71
        }
 
72
 
 
73
        werr = dsdb_get_fsmo_role_info(tmp_ctx, service->samdb, role,
 
74
                                       &fsmo_role_dn, &role_owner_dn);
 
75
        if (!W_ERROR_IS_OK(werr)) {
 
76
                return werr;
 
77
        }
 
78
 
 
79
        switch (role) {
 
80
        case DREPL_NAMING_MASTER:
 
81
        case DREPL_INFRASTRUCTURE_MASTER:
 
82
        case DREPL_SCHEMA_MASTER:
 
83
                extended_op = DRSUAPI_EXOP_FSMO_REQ_ROLE;
 
84
                break;
 
85
        case DREPL_RID_MASTER:
 
86
                extended_op = DRSUAPI_EXOP_FSMO_RID_REQ_ROLE;
 
87
                break;
 
88
        case DREPL_PDC_MASTER:
 
89
                extended_op = DRSUAPI_EXOP_FSMO_REQ_PDC;
 
90
                break;
 
91
        default:
 
92
                return WERR_DS_DRA_INTERNAL_ERROR;
 
93
        }
 
94
 
 
95
        if (fsmo_master_cmp(ntds_dn, role_owner_dn) ||
 
96
            (extended_op == DRSUAPI_EXOP_NONE)) {
 
97
                DEBUG(0,("FSMO role check failed for DN %s and owner %s ",
 
98
                         ldb_dn_get_linearized(fsmo_role_dn),
 
99
                         ldb_dn_get_linearized(role_owner_dn)));
 
100
                return WERR_OK;
 
101
        }
 
102
 
 
103
        werr = drepl_request_extended_op(service,
 
104
                                         fsmo_role_dn,
 
105
                                         role_owner_dn,
 
106
                                         extended_op,
 
107
                                         fsmo_info,
 
108
                                         0,
 
109
                                         drepl_role_callback,
 
110
                                         NULL);
 
111
        if (W_ERROR_IS_OK(werr)) {
 
112
                dreplsrv_run_pending_ops(service);
 
113
        } else {
 
114
                DEBUG(0,("%s: drepl_request_extended_op() failed with %s",
 
115
                         __FUNCTION__, win_errstr(werr)));
 
116
        }
 
117
        return werr;
 
118
}