| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 |
|
|---|
| 4 | Password and authentication handling by wbclient
|
|---|
| 5 |
|
|---|
| 6 | Copyright (C) Andrew Bartlett 2002
|
|---|
| 7 | Copyright (C) Jelmer Vernooij 2002
|
|---|
| 8 | Copyright (C) Simo Sorce 2003
|
|---|
| 9 | Copyright (C) Volker Lendecke 2006
|
|---|
| 10 | Copyright (C) Dan Sledz 2009
|
|---|
| 11 |
|
|---|
| 12 | This program is free software; you can redistribute it and/or modify
|
|---|
| 13 | it under the terms of the GNU General Public License as published by
|
|---|
| 14 | the Free Software Foundation; either version 3 of the License, or
|
|---|
| 15 | (at your option) any later version.
|
|---|
| 16 |
|
|---|
| 17 | This program is distributed in the hope that it will be useful,
|
|---|
| 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 20 | GNU General Public License for more details.
|
|---|
| 21 |
|
|---|
| 22 | You should have received a copy of the GNU General Public License
|
|---|
| 23 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 24 | */
|
|---|
| 25 |
|
|---|
| 26 | /* This passdb module retrieves full passdb information for local users and
|
|---|
| 27 | * groups from a wbclient compatible daemon.
|
|---|
| 28 | *
|
|---|
| 29 | * The purpose of this module is to defer all SAM authorization information
|
|---|
| 30 | * storage and retrieval to a wbc compatible daemon.
|
|---|
| 31 | *
|
|---|
| 32 | * This passdb backend is most useful when used in conjunction with auth_wbc.
|
|---|
| 33 | *
|
|---|
| 34 | * A few current limitations of this module are:
|
|---|
| 35 | * - read only interface
|
|---|
| 36 | * - no privileges
|
|---|
| 37 | */
|
|---|
| 38 |
|
|---|
| 39 | #include "includes.h"
|
|---|
| 40 | #include "passdb.h"
|
|---|
| 41 | #include "lib/winbind_util.h"
|
|---|
| 42 |
|
|---|
| 43 | /***************************************************************************
|
|---|
| 44 | Default implementations of some functions.
|
|---|
| 45 | ****************************************************************************/
|
|---|
| 46 | static NTSTATUS _pdb_wbc_sam_getsampw(struct pdb_methods *methods,
|
|---|
| 47 | struct samu *user,
|
|---|
| 48 | const struct passwd *pwd)
|
|---|
| 49 | {
|
|---|
| 50 | NTSTATUS result = NT_STATUS_OK;
|
|---|
| 51 |
|
|---|
| 52 | if (pwd == NULL)
|
|---|
| 53 | return NT_STATUS_NO_SUCH_USER;
|
|---|
| 54 |
|
|---|
| 55 | ZERO_STRUCTP(user);
|
|---|
| 56 |
|
|---|
| 57 | /* Can we really get away with this little of information */
|
|---|
| 58 | user->methods = methods;
|
|---|
| 59 | result = samu_set_unix(user, pwd);
|
|---|
| 60 |
|
|---|
| 61 | return result;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | static NTSTATUS pdb_wbc_sam_getsampwnam(struct pdb_methods *methods, struct samu *user, const char *sname)
|
|---|
| 65 | {
|
|---|
| 66 | return _pdb_wbc_sam_getsampw(methods, user, winbind_getpwnam(sname));
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | static NTSTATUS pdb_wbc_sam_getsampwsid(struct pdb_methods *methods, struct samu *user, const struct dom_sid *sid)
|
|---|
| 70 | {
|
|---|
| 71 | return _pdb_wbc_sam_getsampw(methods, user, winbind_getpwsid(sid));
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | static bool pdb_wbc_sam_uid_to_sid(struct pdb_methods *methods, uid_t uid,
|
|---|
| 75 | struct dom_sid *sid)
|
|---|
| 76 | {
|
|---|
| 77 | return winbind_uid_to_sid(sid, uid);
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | static bool pdb_wbc_sam_gid_to_sid(struct pdb_methods *methods, gid_t gid,
|
|---|
| 81 | struct dom_sid *sid)
|
|---|
| 82 | {
|
|---|
| 83 | return winbind_gid_to_sid(sid, gid);
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | static NTSTATUS pdb_wbc_sam_enum_group_members(struct pdb_methods *methods,
|
|---|
| 87 | TALLOC_CTX *mem_ctx,
|
|---|
| 88 | const struct dom_sid *group,
|
|---|
| 89 | uint32 **pp_member_rids,
|
|---|
| 90 | size_t *p_num_members)
|
|---|
| 91 | {
|
|---|
| 92 | return NT_STATUS_NOT_IMPLEMENTED;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | static NTSTATUS pdb_wbc_sam_enum_group_memberships(struct pdb_methods *methods,
|
|---|
| 96 | TALLOC_CTX *mem_ctx,
|
|---|
| 97 | struct samu *user,
|
|---|
| 98 | struct dom_sid **pp_sids,
|
|---|
| 99 | gid_t **pp_gids,
|
|---|
| 100 | uint32_t *p_num_groups)
|
|---|
| 101 | {
|
|---|
| 102 | size_t i;
|
|---|
| 103 | const char *username = pdb_get_username(user);
|
|---|
| 104 | uint32_t num_groups;
|
|---|
| 105 |
|
|---|
| 106 | if (!winbind_get_groups(mem_ctx, username, &num_groups, pp_gids)) {
|
|---|
| 107 | return NT_STATUS_NO_SUCH_USER;
|
|---|
| 108 | }
|
|---|
| 109 | *p_num_groups = num_groups;
|
|---|
| 110 |
|
|---|
| 111 | if (*p_num_groups == 0) {
|
|---|
| 112 | smb_panic("primary group missing");
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | *pp_sids = TALLOC_ARRAY(mem_ctx, struct dom_sid, *p_num_groups);
|
|---|
| 116 |
|
|---|
| 117 | if (*pp_sids == NULL) {
|
|---|
| 118 | TALLOC_FREE(*pp_gids);
|
|---|
| 119 | return NT_STATUS_NO_MEMORY;
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | for (i=0; i < *p_num_groups; i++) {
|
|---|
| 123 | gid_to_sid(&(*pp_sids)[i], (*pp_gids)[i]);
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | return NT_STATUS_OK;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | static NTSTATUS pdb_wbc_sam_lookup_rids(struct pdb_methods *methods,
|
|---|
| 130 | const struct dom_sid *domain_sid,
|
|---|
| 131 | int num_rids,
|
|---|
| 132 | uint32 *rids,
|
|---|
| 133 | const char **names,
|
|---|
| 134 | enum lsa_SidType *attrs)
|
|---|
| 135 | {
|
|---|
| 136 | NTSTATUS result = NT_STATUS_OK;
|
|---|
| 137 | char *domain = NULL;
|
|---|
| 138 | char **account_names = NULL;
|
|---|
| 139 | enum lsa_SidType *attr_list = NULL;
|
|---|
| 140 | int i;
|
|---|
| 141 |
|
|---|
| 142 | if (!winbind_lookup_rids(talloc_tos(), domain_sid, num_rids, rids,
|
|---|
| 143 | (const char **)&domain,
|
|---|
| 144 | (const char ***)&account_names, &attr_list))
|
|---|
| 145 | {
|
|---|
| 146 | result = NT_STATUS_NONE_MAPPED;
|
|---|
| 147 | goto done;
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | memcpy(attrs, attr_list, num_rids * sizeof(enum lsa_SidType));
|
|---|
| 151 |
|
|---|
| 152 | for (i=0; i<num_rids; i++) {
|
|---|
| 153 | if (attrs[i] == SID_NAME_UNKNOWN) {
|
|---|
| 154 | names[i] = NULL;
|
|---|
| 155 | } else {
|
|---|
| 156 | names[i] = talloc_strdup(names, account_names[i]);
|
|---|
| 157 | if (names[i] == NULL) {
|
|---|
| 158 | result = NT_STATUS_NO_MEMORY;
|
|---|
| 159 | goto done;
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | }
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | done:
|
|---|
| 166 | TALLOC_FREE(account_names);
|
|---|
| 167 | TALLOC_FREE(domain);
|
|---|
| 168 | TALLOC_FREE(attr_list);
|
|---|
| 169 | return result;
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | static NTSTATUS pdb_wbc_sam_get_account_policy(struct pdb_methods *methods, enum pdb_policy_type type, uint32_t *value)
|
|---|
| 173 | {
|
|---|
| 174 | return NT_STATUS_UNSUCCESSFUL;
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | static NTSTATUS pdb_wbc_sam_set_account_policy(struct pdb_methods *methods, enum pdb_policy_type type, uint32_t value)
|
|---|
| 178 | {
|
|---|
| 179 | return NT_STATUS_UNSUCCESSFUL;
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | static bool pdb_wbc_sam_search_groups(struct pdb_methods *methods,
|
|---|
| 183 | struct pdb_search *search)
|
|---|
| 184 | {
|
|---|
| 185 | return false;
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | static bool pdb_wbc_sam_search_aliases(struct pdb_methods *methods,
|
|---|
| 189 | struct pdb_search *search,
|
|---|
| 190 | const struct dom_sid *sid)
|
|---|
| 191 | {
|
|---|
| 192 |
|
|---|
| 193 | return false;
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | static bool pdb_wbc_sam_get_trusteddom_pw(struct pdb_methods *methods,
|
|---|
| 197 | const char *domain,
|
|---|
| 198 | char **pwd,
|
|---|
| 199 | struct dom_sid *sid,
|
|---|
| 200 | time_t *pass_last_set_time)
|
|---|
| 201 | {
|
|---|
| 202 | return false;
|
|---|
| 203 |
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | static bool pdb_wbc_sam_set_trusteddom_pw(struct pdb_methods *methods,
|
|---|
| 207 | const char *domain,
|
|---|
| 208 | const char *pwd,
|
|---|
| 209 | const struct dom_sid *sid)
|
|---|
| 210 | {
|
|---|
| 211 | return false;
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | static bool pdb_wbc_sam_del_trusteddom_pw(struct pdb_methods *methods,
|
|---|
| 215 | const char *domain)
|
|---|
| 216 | {
|
|---|
| 217 | return false;
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | static NTSTATUS pdb_wbc_sam_enum_trusteddoms(struct pdb_methods *methods,
|
|---|
| 221 | TALLOC_CTX *mem_ctx,
|
|---|
| 222 | uint32 *num_domains,
|
|---|
| 223 | struct trustdom_info ***domains)
|
|---|
| 224 | {
|
|---|
| 225 | return NT_STATUS_NOT_IMPLEMENTED;
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | static bool _make_group_map(struct pdb_methods *methods, const char *domain, const char *name, enum lsa_SidType name_type, gid_t gid, struct dom_sid *sid, GROUP_MAP *map)
|
|---|
| 229 | {
|
|---|
| 230 | snprintf(map->nt_name, sizeof(map->nt_name), "%s%c%s",
|
|---|
| 231 | domain, *lp_winbind_separator(), name);
|
|---|
| 232 | map->sid_name_use = name_type;
|
|---|
| 233 | map->sid = *sid;
|
|---|
| 234 | map->gid = gid;
|
|---|
| 235 | return true;
|
|---|
| 236 | }
|
|---|
| 237 |
|
|---|
| 238 | static NTSTATUS pdb_wbc_sam_getgrsid(struct pdb_methods *methods, GROUP_MAP *map,
|
|---|
| 239 | struct dom_sid sid)
|
|---|
| 240 | {
|
|---|
| 241 | NTSTATUS result = NT_STATUS_OK;
|
|---|
| 242 | char *name = NULL;
|
|---|
| 243 | char *domain = NULL;
|
|---|
| 244 | enum lsa_SidType name_type;
|
|---|
| 245 | gid_t gid;
|
|---|
| 246 |
|
|---|
| 247 | if (!winbind_lookup_sid(talloc_tos(), &sid, (const char **)&domain,
|
|---|
| 248 | (const char **) &name, &name_type)) {
|
|---|
| 249 | result = NT_STATUS_NO_SUCH_GROUP;
|
|---|
| 250 | goto done;
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | if ((name_type != SID_NAME_DOM_GRP) &&
|
|---|
| 254 | (name_type != SID_NAME_DOMAIN) &&
|
|---|
| 255 | (name_type != SID_NAME_ALIAS) &&
|
|---|
| 256 | (name_type != SID_NAME_WKN_GRP)) {
|
|---|
| 257 | result = NT_STATUS_NO_SUCH_GROUP;
|
|---|
| 258 | goto done;
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | if (!winbind_sid_to_gid(&gid, &sid)) {
|
|---|
| 262 | result = NT_STATUS_NO_SUCH_GROUP;
|
|---|
| 263 | goto done;
|
|---|
| 264 | }
|
|---|
| 265 |
|
|---|
| 266 | if (!_make_group_map(methods, domain, name, name_type, gid, &sid, map)) {
|
|---|
| 267 | result = NT_STATUS_NO_SUCH_GROUP;
|
|---|
| 268 | goto done;
|
|---|
| 269 | }
|
|---|
| 270 |
|
|---|
| 271 | done:
|
|---|
| 272 | TALLOC_FREE(name);
|
|---|
| 273 | TALLOC_FREE(domain);
|
|---|
| 274 | return result;
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | static NTSTATUS pdb_wbc_sam_getgrgid(struct pdb_methods *methods, GROUP_MAP *map,
|
|---|
| 278 | gid_t gid)
|
|---|
| 279 | {
|
|---|
| 280 | NTSTATUS result = NT_STATUS_OK;
|
|---|
| 281 | char *name = NULL;
|
|---|
| 282 | char *domain = NULL;
|
|---|
| 283 | struct dom_sid sid;
|
|---|
| 284 | enum lsa_SidType name_type;
|
|---|
| 285 |
|
|---|
| 286 | if (!winbind_gid_to_sid(&sid, gid)) {
|
|---|
| 287 | result = NT_STATUS_NO_SUCH_GROUP;
|
|---|
| 288 | goto done;
|
|---|
| 289 | }
|
|---|
| 290 |
|
|---|
| 291 | if (!winbind_lookup_sid(talloc_tos(), &sid, (const char **)&domain,
|
|---|
| 292 | (const char **)&name, &name_type)) {
|
|---|
| 293 | result = NT_STATUS_NO_SUCH_GROUP;
|
|---|
| 294 | goto done;
|
|---|
| 295 | }
|
|---|
| 296 |
|
|---|
| 297 | if ((name_type != SID_NAME_DOM_GRP) &&
|
|---|
| 298 | (name_type != SID_NAME_DOMAIN) &&
|
|---|
| 299 | (name_type != SID_NAME_ALIAS) &&
|
|---|
| 300 | (name_type != SID_NAME_WKN_GRP)) {
|
|---|
| 301 | result = NT_STATUS_NO_SUCH_GROUP;
|
|---|
| 302 | goto done;
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| 305 | if (!_make_group_map(methods, domain, name, name_type, gid, &sid, map)) {
|
|---|
| 306 | result = NT_STATUS_NO_SUCH_GROUP;
|
|---|
| 307 | goto done;
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| 310 | done:
|
|---|
| 311 | TALLOC_FREE(name);
|
|---|
| 312 | TALLOC_FREE(domain);
|
|---|
| 313 |
|
|---|
| 314 | return result;
|
|---|
| 315 | }
|
|---|
| 316 |
|
|---|
| 317 | static NTSTATUS pdb_wbc_sam_getgrnam(struct pdb_methods *methods, GROUP_MAP *map,
|
|---|
| 318 | const char *name)
|
|---|
| 319 | {
|
|---|
| 320 | NTSTATUS result = NT_STATUS_OK;
|
|---|
| 321 | const char *domain = "";
|
|---|
| 322 | struct dom_sid sid;
|
|---|
| 323 | gid_t gid;
|
|---|
| 324 | enum lsa_SidType name_type;
|
|---|
| 325 |
|
|---|
| 326 | if (!winbind_lookup_name(domain, name, &sid, &name_type)) {
|
|---|
|
|---|