libcli/smb/smbXcli: add smb2cli_session_application_key()
[Samba/gebeck_regimport.git] / lib / param / loadparm_server_role.c
blob36551593a81ca5cd911176a18f318c2588348e38
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 { 0, NULL }
47 const char* server_role_str(uint32_t role)
49 int i = 0;
50 for (i=0; srv_role_tab[i].role_str; i++) {
51 if (role == srv_role_tab[i].role) {
52 return srv_role_tab[i].role_str;
55 return NULL;
58 /**
59 * Set the server role based on security, domain logons and domain master
61 int lp_find_server_role(int server_role, int security, int domain_logons, int domain_master)
63 int role;
65 if (server_role != ROLE_AUTO) {
66 if (lp_is_security_and_server_role_valid(server_role, security)) {
67 return server_role;
71 /* If server_role is set to ROLE_AUTO, or conflicted with the
72 * chosen security setting, figure out the correct role */
73 role = ROLE_STANDALONE;
75 switch (security) {
76 case SEC_SHARE:
77 if (domain_logons) {
78 DEBUG(0, ("Server's Role (logon server) conflicts with share-level security\n"));
80 break;
81 case SEC_SERVER:
82 if (domain_logons) {
83 DEBUG(0, ("Server's Role (logon server) conflicts with server-level security\n"));
85 /* this used to be considered ROLE_DOMAIN_MEMBER but that's just wrong */
86 role = ROLE_STANDALONE;
87 break;
88 case SEC_DOMAIN:
89 if (domain_logons) {
90 DEBUG(1, ("Server's Role (logon server) NOT ADVISED with domain-level security\n"));
91 role = ROLE_DOMAIN_BDC;
92 break;
94 role = ROLE_DOMAIN_MEMBER;
95 break;
96 case SEC_ADS:
97 if (domain_logons) {
98 role = ROLE_DOMAIN_CONTROLLER;
99 break;
101 role = ROLE_DOMAIN_MEMBER;
102 break;
103 case SEC_AUTO:
104 case SEC_USER:
105 if (domain_logons) {
107 if (domain_master) {
108 role = ROLE_DOMAIN_PDC;
109 } else {
110 role = ROLE_DOMAIN_BDC;
113 break;
114 default:
115 DEBUG(0, ("Server's Role undefined due to unknown security mode\n"));
116 break;
119 return role;
123 * Set the server role based on security, domain logons and domain master
125 int lp_find_security(int server_role, int security)
127 if (security != SEC_AUTO) {
128 return security;
131 switch (server_role) {
132 case ROLE_AUTO:
133 case ROLE_STANDALONE:
134 return SEC_USER;
135 case ROLE_DOMAIN_MEMBER:
136 #if (defined(HAVE_ADS) || _SAMBA_BUILD_ >= 4)
137 return SEC_ADS;
138 #else
139 return SEC_DOMAIN;
140 #endif
141 case ROLE_DOMAIN_PDC:
142 case ROLE_DOMAIN_BDC:
143 default:
144 return SEC_USER;
150 * Check if server role and security parameters are contradictory
152 bool lp_is_security_and_server_role_valid(int server_role, int security)
154 bool valid = false;
156 if (security == SEC_AUTO) {
157 return true;
160 switch (server_role) {
161 case ROLE_AUTO:
162 valid = true;
163 break;
164 case ROLE_STANDALONE:
165 if (security == SEC_SHARE || security == SEC_SERVER || security == SEC_USER) {
166 valid = true;
168 break;
170 case ROLE_DOMAIN_MEMBER:
171 if (security == SEC_ADS || security == SEC_DOMAIN) {
172 valid = true;
174 break;
176 case ROLE_DOMAIN_PDC:
177 case ROLE_DOMAIN_BDC:
178 if (security == SEC_USER || security == SEC_ADS || security == SEC_DOMAIN) {
179 valid = true;
181 break;
183 default:
184 break;
187 return valid;