mount.cifs: check access of credential files before opening
[Samba.git] / source / rpc_server / srv_lsa_ds_nt.c
blob17543a38ef625772b0b725f1d66c2d095777be44
1 /*
2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-1997.
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997.
6 * Copyright (C) Paul Ashton 1997.
7 * Copyright (C) Jeremy Allison 2001.
8 * Copyright (C) Gerald Carter 2002.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 /* Implementation of registry functions. */
27 #include "includes.h"
29 #undef DBGC_CLASS
30 #define DBGC_CLASS DBGC_RPC_SRV
32 /********************************************************************
33 Fill in a DS_DOMINFO_CTR structure
34 ********************************************************************/
36 static NTSTATUS fill_dsrole_dominfo_basic(TALLOC_CTX *ctx, DSROLE_PRIMARY_DOMAIN_INFO_BASIC **info)
38 DSROLE_PRIMARY_DOMAIN_INFO_BASIC *basic;
39 const char *netbios_domain = "";
40 fstring dnsdomain;
42 DEBUG(10,("fill_dsrole_dominfo_basic: enter\n"));
44 if ( !(basic = TALLOC_ZERO_P(ctx, DSROLE_PRIMARY_DOMAIN_INFO_BASIC)) ) {
45 DEBUG(0,("fill_dsrole_dominfo_basic: FATAL error! talloc_xero() failed\n"));
46 return NT_STATUS_NO_MEMORY;
49 switch ( lp_server_role() ) {
50 case ROLE_STANDALONE:
51 basic->machine_role = DSROLE_STANDALONE_SRV;
52 basic->netbios_ptr = 1;
53 netbios_domain = get_global_sam_name();
54 break;
55 case ROLE_DOMAIN_MEMBER:
56 basic->netbios_ptr = 1;
57 netbios_domain = lp_workgroup();
58 basic->machine_role = DSROLE_DOMAIN_MEMBER_SRV;
59 break;
60 case ROLE_DOMAIN_BDC:
61 basic->netbios_ptr = 1;
62 netbios_domain = get_global_sam_name();
63 basic->machine_role = DSROLE_BDC;
64 break;
65 case ROLE_DOMAIN_PDC:
66 basic->netbios_ptr = 1;
67 netbios_domain = get_global_sam_name();
68 basic->machine_role = DSROLE_PDC;
69 break;
72 /* always set netbios name */
74 init_unistr2( &basic->netbios_domain, netbios_domain, UNI_STR_TERMINATE);
76 if ( secrets_fetch_domain_guid( lp_workgroup(), &basic->domain_guid ) )
77 basic->flags |= DSROLE_PRIMARY_DOMAIN_GUID_PRESENT;
79 /* fill in some additional fields if we are a member of an AD domain */
81 if ( lp_security() == SEC_ADS ) {
82 fstrcpy( dnsdomain, lp_realm() );
83 strlower_m( dnsdomain );
85 basic->dnsname_ptr = 1;
86 init_unistr2( &basic->dns_domain, dnsdomain, UNI_STR_TERMINATE);
88 /* FIXME!! We really should fill in the correct forest
89 name. Should get this information from winbindd. */
90 basic->forestname_ptr = 1;
91 init_unistr2( &basic->forest_domain, dnsdomain, UNI_STR_TERMINATE);
92 } else {
93 /* security = domain should not fill in the dns or
94 forest name */
95 basic->dnsname_ptr = 0;
96 basic->forestname_ptr = 0;
99 *info = basic;
101 return NT_STATUS_OK;
104 /********************************************************************
105 Implement the DsroleGetPrimaryDomainInfo() call
106 ********************************************************************/
108 NTSTATUS _dsrole_get_primary_dominfo(pipes_struct *p, DS_Q_GETPRIMDOMINFO *q_u, DS_R_GETPRIMDOMINFO *r_u)
110 NTSTATUS result = NT_STATUS_OK;
111 uint32 level = q_u->level;
113 switch ( level ) {
115 case DsRolePrimaryDomainInfoBasic:
116 r_u->level = DsRolePrimaryDomainInfoBasic;
117 r_u->ptr = 1;
118 result = fill_dsrole_dominfo_basic( p->mem_ctx, &r_u->info.basic );
119 break;
121 default:
122 DEBUG(0,("_dsrole_get_primary_dominfo: Unsupported info level [%d]!\n",
123 level));
124 result = NT_STATUS_INVALID_LEVEL;
127 return result;