s3-param remove lp_domain_logons(), always use IS_DC
[gd/samba-autobuild/.git] / source3 / param / loadparm_server_role.c
1 /*
2    Unix SMB/CIFS implementation.
3    Parameter loading functions
4    Copyright (C) Karl Auer 1993-1998
5
6    Largely re-written by Andrew Tridgell, September 1994
7
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
14
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.
19
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.
24
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/>.
27 */
28 #include "includes.h"
29
30 /*******************************************************************
31  Set the server type we will announce as via nmbd.
32 ********************************************************************/
33
34 static const struct srv_role_tab {
35         uint32 role;
36         const char *role_str;
37 } srv_role_tab [] = {
38         { ROLE_STANDALONE, "ROLE_STANDALONE" },
39         { ROLE_DOMAIN_MEMBER, "ROLE_DOMAIN_MEMBER" },
40         { ROLE_DOMAIN_BDC, "ROLE_DOMAIN_BDC" },
41         { ROLE_DOMAIN_PDC, "ROLE_DOMAIN_PDC" },
42         { 0, NULL }
43 };
44
45 const char* server_role_str(uint32 role)
46 {
47         int i = 0;
48         for (i=0; srv_role_tab[i].role_str; i++) {
49                 if (role == srv_role_tab[i].role) {
50                         return srv_role_tab[i].role_str;
51                 }
52         }
53         return NULL;
54 }
55
56 void set_server_role(void)
57 {
58         int server_role = ROLE_STANDALONE;
59
60         switch (lp_security()) {
61                 case SEC_SHARE:
62                         if (lp_domain_logons())
63                                 DEBUG(0, ("Server's Role (logon server) conflicts with share-level security\n"));
64                         break;
65                 case SEC_SERVER:
66                         if (lp_domain_logons())
67                                 DEBUG(0, ("Server's Role (logon server) conflicts with server-level security\n"));
68                         /* this used to be considered ROLE_DOMAIN_MEMBER but that's just wrong */
69                         server_role = ROLE_STANDALONE;
70                         break;
71                 case SEC_DOMAIN:
72                         if (lp_domain_logons()) {
73                                 DEBUG(1, ("Server's Role (logon server) NOT ADVISED with domain-level security\n"));
74                                 server_role = ROLE_DOMAIN_BDC;
75                                 break;
76                         }
77                         server_role = ROLE_DOMAIN_MEMBER;
78                         break;
79                 case SEC_ADS:
80                         if (lp_domain_logons()) {
81                                 server_role = ROLE_DOMAIN_CONTROLLER;
82                                 break;
83                         }
84                         server_role = ROLE_DOMAIN_MEMBER;
85                         break;
86                 case SEC_USER:
87                         if (lp_domain_logons()) {
88
89                                 if (lp_domain_master_true_or_auto()) /* auto or yes */
90                                         server_role = ROLE_DOMAIN_PDC;
91                                 else
92                                         server_role = ROLE_DOMAIN_BDC;
93                         }
94                         break;
95                 default:
96                         DEBUG(0, ("Server's Role undefined due to unknown security mode\n"));
97                         break;
98         }
99
100         _lp_set_server_role(server_role);
101         DEBUG(10, ("set_server_role: role = %s\n", server_role_str(server_role)));
102 }
103