s3:utils: let smbstatus report anonymous signing/encryption explicitly
[samba.git] / source3 / lib / util_names.c
1 /*
2    Unix SMB/CIFS implementation.
3    Samba utility functions
4    Copyright (C) Andrew Tridgell 1992-1998
5    Copyright (C) Jeremy Allison 2001-2007
6    Copyright (C) Simo Sorce 2001
7    Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2003
8    Copyright (C) James Peach 2006
9    Copyright (C) Andrew Bartlett 2010-2011
10
11    This program is free software; you can redistribute it and/or modify
12    it under the terms of the GNU General Public License as published by
13    the Free Software Foundation; either version 3 of the License, or
14    (at your option) any later version.
15
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19    GNU General Public License for more details.
20
21    You should have received a copy of the GNU General Public License
22    along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 */
24
25 #include "includes.h"
26
27 /******************************************************************
28  get the default domain/netbios name to be used when dealing
29  with our passdb list of accounts
30 ******************************************************************/
31
32 const char *get_global_sam_name(void)
33 {
34         if (IS_DC) {
35                 return lp_workgroup();
36         }
37         return lp_netbios_name();
38 }
39
40
41 /******************************************************************
42  Get the default domain/netbios name to be used when
43  testing authentication.
44 ******************************************************************/
45
46 const char *my_sam_name(void)
47 {
48         if (lp_server_role() == ROLE_STANDALONE) {
49                 return lp_netbios_name();
50         }
51
52         return lp_workgroup();
53 }
54
55 bool is_allowed_domain(const char *domain_name)
56 {
57         const char **ignored_domains = NULL;
58         const char **dom = NULL;
59
60         ignored_domains = lp_parm_string_list(-1,
61                                               "winbind",
62                                               "ignore domains",
63                                               NULL);
64
65         for (dom = ignored_domains; dom != NULL && *dom != NULL; dom++) {
66                 if (gen_fnmatch(*dom, domain_name) == 0) {
67                         DBG_NOTICE("Ignoring domain '%s'\n", domain_name);
68                         return false;
69                 }
70         }
71
72         if (lp_allow_trusted_domains()) {
73                 return true;
74         }
75
76         if (strequal(lp_workgroup(), domain_name)) {
77                 return true;
78         }
79
80         if (is_myname(domain_name)) {
81                 return true;
82         }
83
84         DBG_NOTICE("Not trusted domain '%s'\n", domain_name);
85         return false;
86 }