2 Unix SMB/CIFS implementation.
3 Check access based on valid users, read list and friends
4 Copyright (C) Volker Lendecke 2005
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "smbd/smbd.h"
22 #include "smbd/globals.h"
23 #include "../libcli/security/security.h"
26 * Check whether a user is contained in the list provided.
28 * Please note that the user name and share names passed in here mainly for
29 * the substitution routines that expand the parameter values, the decision
30 * whether a user is in the list is done after a lookup_name on the expanded
31 * parameter value, solely based on comparing the SIDs in token.
33 * The other use is the netgroup check when using @group or &group.
36 bool token_contains_name_in_list(const char *username
,
38 const char *sharename
,
39 const struct security_token
*token
,
47 while (*list
!= NULL
) {
48 TALLOC_CTX
*frame
= talloc_stackframe();
51 ok
= token_contains_name(frame
, username
, domain
, sharename
,
66 * Check whether the user described by "token" has access to share snum.
68 * This looks at "invalid users" and "valid users".
70 * Please note that the user name and share names passed in here mainly for
71 * the substitution routines that expand the parameter values, the decision
72 * whether a user is in the list is done after a lookup_name on the expanded
73 * parameter value, solely based on comparing the SIDs in token.
75 * The other use is the netgroup check when using @group or &group.
78 bool user_ok_token(const char *username
, const char *domain
,
79 const struct security_token
*token
, int snum
)
81 const struct loadparm_substitution
*lp_sub
=
82 loadparm_s3_global_substitution();
86 if (lp_invalid_users(snum
) != NULL
) {
87 ok
= token_contains_name_in_list(username
, domain
,
88 lp_servicename(talloc_tos(), lp_sub
, snum
),
90 lp_invalid_users(snum
),
96 DEBUG(10, ("User %s in 'invalid users'\n", username
));
101 if (lp_valid_users(snum
) != NULL
) {
102 ok
= token_contains_name_in_list(username
, domain
,
103 lp_servicename(talloc_tos(), lp_sub
, snum
),
105 lp_valid_users(snum
),
111 DEBUG(10, ("User %s not in 'valid users'\n",
117 DEBUG(10, ("user_ok_token: share %s is ok for unix user %s\n",
118 lp_servicename(talloc_tos(), lp_sub
, snum
), username
));
124 * Check whether the user described by "token" is restricted to read-only
125 * access on share snum.
127 * This looks at "read list", "write list" and "read only".
129 * Please note that the user name and share names passed in here mainly for
130 * the substitution routines that expand the parameter values, the decision
131 * whether a user is in the list is done after a lookup_name on the expanded
132 * parameter value, solely based on comparing the SIDs in token.
134 * The other use is the netgroup check when using @group or &group.
137 bool is_share_read_only_for_token(const char *username
,
139 const struct security_token
*token
,
140 connection_struct
*conn
,
143 const struct loadparm_substitution
*lp_sub
=
144 loadparm_s3_global_substitution();
145 int snum
= SNUM(conn
);
146 bool read_only
= conn
->read_only
;
150 if (lp_read_list(snum
) != NULL
) {
151 ok
= token_contains_name_in_list(username
, domain
,
152 lp_servicename(talloc_tos(), lp_sub
, snum
),
164 if (lp_write_list(snum
) != NULL
) {
165 ok
= token_contains_name_in_list(username
, domain
,
166 lp_servicename(talloc_tos(), lp_sub
, snum
),
178 DEBUG(10,("is_share_read_only_for_user: share %s is %s for unix user "
179 "%s\n", lp_servicename(talloc_tos(), lp_sub
, snum
),
180 read_only
? "read-only" : "read-write", username
));
182 *_read_only
= read_only
;