lib/param: Create a seperate server role for "active directory domain controller"
[Samba.git] / lib / param / loadparm_server_role.c
blob46515dadbdfb82657f3b420f1ffe115c12740e3f
1 /*
2 Unix SMB/CIFS implementation.
3 Parameter loading functions
4 Copyright (C) Karl Auer 1993-1998
6 Largely re-written by Andrew Tridgell, September 1994
8 Copyright (C) Simo Sorce 2001
9 Copyright (C) Alexander Bokovoy 2002
10 Copyright (C) Stefan (metze) Metzmacher 2002
11 Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2003
12 Copyright (C) Michael Adam 2008
13 Copyright (C) Andrew Bartlett 2010
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 3 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include "includes.h"
29 #include "lib/param/loadparm.h"
30 #include "libds/common/roles.h"
32 /*******************************************************************
33 Set the server type we will announce as via nmbd.
34 ********************************************************************/
36 static const struct srv_role_tab {
37 uint32_t role;
38 const char *role_str;
39 } srv_role_tab [] = {
40 { ROLE_STANDALONE, "ROLE_STANDALONE" },
41 { ROLE_DOMAIN_MEMBER, "ROLE_DOMAIN_MEMBER" },
42 { ROLE_DOMAIN_BDC, "ROLE_DOMAIN_BDC" },
43 { ROLE_DOMAIN_PDC, "ROLE_DOMAIN_PDC" },
44 { ROLE_ACTIVE_DIRECTORY_DC, "ROLE_ACTIVE_DIRECTORY_DC" },
45 { 0, NULL }
48 const char* server_role_str(uint32_t role)
50 int i = 0;
51 for (i=0; srv_role_tab[i].role_str; i++) {
52 if (role == srv_role_tab[i].role) {
53 return srv_role_tab[i].role_str;
56 return NULL;
59 /**
60 * Set the server role based on security, domain logons and domain master
62 int lp_find_server_role(int server_role, int security, int domain_logons, int domain_master)
64 int role;
66 if (server_role != ROLE_AUTO) {
67 if (lp_is_security_and_server_role_valid(server_role, security)) {
68 return server_role;
72 /* If server_role is set to ROLE_AUTO, or conflicted with the
73 * chosen security setting, figure out the correct role */
74 role = ROLE_STANDALONE;
76 switch (security) {
77 case SEC_DOMAIN:
78 if (domain_logons) {
79 DEBUG(1, ("Server's Role (logon server) NOT ADVISED with domain-level security\n"));
80 role = ROLE_DOMAIN_BDC;
81 break;
83 role = ROLE_DOMAIN_MEMBER;
84 break;
85 case SEC_ADS:
86 if (domain_logons) {
87 role = ROLE_DOMAIN_BDC;
88 break;
90 role = ROLE_DOMAIN_MEMBER;
91 break;
92 case SEC_AUTO:
93 case SEC_USER:
94 if (domain_logons) {
96 if (domain_master) {
97 role = ROLE_DOMAIN_PDC;
98 } else {
99 role = ROLE_DOMAIN_BDC;
102 break;
103 default:
104 DEBUG(0, ("Server's Role undefined due to unknown security mode\n"));
105 break;
108 return role;
112 * Set the server role based on security, domain logons and domain master
114 int lp_find_security(int server_role, int security)
116 if (security != SEC_AUTO) {
117 return security;
120 switch (server_role) {
121 case ROLE_DOMAIN_MEMBER:
122 #if (defined(HAVE_ADS) || _SAMBA_BUILD_ >= 4)
123 return SEC_ADS;
124 #else
125 return SEC_DOMAIN;
126 #endif
127 default:
128 return SEC_USER;
134 * Check if server role and security parameters are contradictory
136 bool lp_is_security_and_server_role_valid(int server_role, int security)
138 bool valid = false;
140 if (security == SEC_AUTO) {
141 return true;
144 switch (server_role) {
145 case ROLE_AUTO:
146 valid = true;
147 break;
148 case ROLE_STANDALONE:
149 if (security == SEC_USER) {
150 valid = true;
152 break;
154 case ROLE_DOMAIN_MEMBER:
155 if (security == SEC_ADS || security == SEC_DOMAIN) {
156 valid = true;
158 break;
160 case ROLE_DOMAIN_PDC:
161 case ROLE_DOMAIN_BDC:
162 case ROLE_ACTIVE_DIRECTORY_DC:
163 if (security == SEC_USER || security == SEC_ADS || security == SEC_DOMAIN) {
164 valid = true;
166 break;
168 default:
169 break;
172 return valid;