source: trunk/server/source3/rpc_server/srv_access_check.c@ 751

Last change on this file since 751 was 751, checked in by Silvan Scherrer, 13 years ago

Samba Server: updated trunk to 3.6.9

File size: 5.1 KB
Line 
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) Marc Jacobsen 1999,
8 * Copyright (C) Jeremy Allison 2001-2008,
9 * Copyright (C) Jean François Micouleau 1998-2001,
10 * Copyright (C) Jim McDonough <[email protected]> 2002,
11 * Copyright (C) Gerald (Jerry) Carter 2003-2004,
12 * Copyright (C) Simo Sorce 2003.
13 * Copyright (C) Volker Lendecke 2005.
14 * Copyright (C) Guenther Deschner 2008.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28 */
29
30#include "includes.h"
31#include "rpc_server/srv_access_check.h"
32#include "../libcli/security/security.h"
33#include "passdb/machine_sid.h"
34
35/*******************************************************************
36 Checks if access to an object should be granted, and returns that
37 level of access for further checks.
38
39 If the user has either of needed_priv_1 or needed_priv_2 then they
40 get the rights in rights_mask in addition to any calulated rights.
41
42 This handles the unusual case where we need to allow two different
43 privileges to obtain exactly the same rights, which occours only in
44 SAMR.
45********************************************************************/
46
47NTSTATUS access_check_object( struct security_descriptor *psd, struct security_token *token,
48 enum sec_privilege needed_priv_1, enum sec_privilege needed_priv_2,
49 uint32 rights_mask,
50 uint32 des_access, uint32 *acc_granted,
51 const char *debug )
52{
53 NTSTATUS status = NT_STATUS_ACCESS_DENIED;
54 uint32 saved_mask = 0;
55 bool priv_granted = false;
56
57 /* check privileges; certain SAM access bits should be overridden
58 by privileges (mostly having to do with creating/modifying/deleting
59 users and groups) */
60
61 if ((needed_priv_1 != SEC_PRIV_INVALID && security_token_has_privilege(token, needed_priv_1)) ||
62 (needed_priv_2 != SEC_PRIV_INVALID && security_token_has_privilege(token, needed_priv_2))) {
63 priv_granted = true;
64 saved_mask = (des_access & rights_mask);
65 des_access &= ~saved_mask;
66
67 DEBUG(4,("access_check_object: user rights access mask [0x%x]\n",
68 rights_mask));
69 }
70
71
72 /* check the security descriptor first */
73
74 status = se_access_check(psd, token, des_access, acc_granted);
75 if (NT_STATUS_IS_OK(status)) {
76 goto done;
77 }
78
79 /* give root a free pass */
80
81 if ( geteuid() == sec_initial_uid() ) {
82
83 DEBUG(4,("%s: ACCESS should be DENIED (requested: %#010x)\n", debug, des_access));
84 DEBUGADD(4,("but overritten by euid == sec_initial_uid()\n"));
85
86 priv_granted = true;
87 *acc_granted = des_access;
88
89 status = NT_STATUS_OK;
90 goto done;
91 }
92
93
94done:
95 if (priv_granted) {
96 /* add in any bits saved during the privilege check (only
97 matters if status is ok) */
98
99 *acc_granted |= rights_mask;
100 }
101
102 DEBUG(4,("%s: access %s (requested: 0x%08x, granted: 0x%08x)\n",
103 debug, NT_STATUS_IS_OK(status) ? "GRANTED" : "DENIED",
104 des_access, *acc_granted));
105
106 return status;
107}
108
109
110/*******************************************************************
111 Map any MAXIMUM_ALLOWED_ACCESS request to a valid access set.
112********************************************************************/
113
114void map_max_allowed_access(const struct security_token *nt_token,
115 const struct security_unix_token *unix_token,
116 uint32_t *pacc_requested)
117{
118 if (!((*pacc_requested) & MAXIMUM_ALLOWED_ACCESS)) {
119 return;
120 }
121 *pacc_requested &= ~MAXIMUM_ALLOWED_ACCESS;
122
123 /* At least try for generic read|execute - Everyone gets that. */
124 *pacc_requested = GENERIC_READ_ACCESS|GENERIC_EXECUTE_ACCESS;
125
126 /* root gets anything. */
127 if (unix_token->uid == sec_initial_uid()) {
128 *pacc_requested |= GENERIC_ALL_ACCESS;
129 return;
130 }
131
132 /* Full Access for 'BUILTIN\Administrators' and 'BUILTIN\Account Operators */
133
134 if (security_token_has_sid(nt_token, &global_sid_Builtin_Administrators) ||
135 security_token_has_sid(nt_token, &global_sid_Builtin_Account_Operators)) {
136 *pacc_requested |= GENERIC_ALL_ACCESS;
137 return;
138 }
139
140 /* Full access for DOMAIN\Domain Admins. */
141 if ( IS_DC ) {
142 struct dom_sid domadmin_sid;
143 sid_compose(&domadmin_sid, get_global_sam_sid(),
144 DOMAIN_RID_ADMINS);
145 if (security_token_has_sid(nt_token, &domadmin_sid)) {
146 *pacc_requested |= GENERIC_ALL_ACCESS;
147 return;
148 }
149 }
150 /* TODO ! Check privileges. */
151}
Note: See TracBrowser for help on using the repository browser.