More code to store ACEs and SIDs. I have almost enough to start testing
[Samba/gebeck_regimport.git] / source3 / passdb / pdb_unix.c
blobed830242489dfb91290f17eea56b4e9ef8e1094c
1 /*
2 * Unix password backend for samba
3 * Copyright (C) Jelmer Vernooij 2002
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 675
17 * Mass Ave, Cambridge, MA 02139, USA.
20 #include "includes.h"
22 /******************************************************************
23 Lookup a name in the SAM database
24 ******************************************************************/
26 static NTSTATUS unixsam_getsampwnam (struct pdb_methods *methods, SAM_ACCOUNT *user, const char *sname)
28 struct passwd *pass;
29 if (!methods) {
30 DEBUG(0,("invalid methods\n"));
31 return NT_STATUS_UNSUCCESSFUL;
33 if (!sname) {
34 DEBUG(0,("invalid name specified"));
35 return NT_STATUS_UNSUCCESSFUL;
37 pass = Get_Pwnam(sname);
39 return pdb_fill_sam_pw(user, pass);
43 /***************************************************************************
44 Search by rid
45 **************************************************************************/
47 static NTSTATUS unixsam_getsampwrid (struct pdb_methods *methods,
48 SAM_ACCOUNT *user, uint32 rid)
50 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
51 struct passwd *pass = NULL;
52 const char *guest_account = lp_guestaccount();
53 if (!(guest_account && *guest_account)) {
54 DEBUG(1, ("NULL guest account!?!?\n"));
55 return nt_status;
58 if (!methods) {
59 DEBUG(0,("invalid methods\n"));
60 return nt_status;
63 if (rid == DOMAIN_USER_RID_GUEST) {
64 pass = getpwnam_alloc(guest_account);
65 if (!pass) {
66 DEBUG(1, ("guest account %s does not seem to exist...\n", guest_account));
67 return nt_status;
69 } else if (pdb_rid_is_user(rid)) {
70 pass = getpwuid_alloc(fallback_pdb_user_rid_to_uid (rid));
73 if (pass == NULL) {
74 return nt_status;
77 nt_status = pdb_fill_sam_pw(user, pass);
78 passwd_free(&pass);
80 return nt_status;
83 static NTSTATUS unixsam_getsampwsid(struct pdb_methods *my_methods, SAM_ACCOUNT * user, const DOM_SID *sid)
85 uint32 rid;
86 if (!sid_peek_check_rid(get_global_sam_sid(), sid, &rid))
87 return NT_STATUS_UNSUCCESSFUL;
88 return unixsam_getsampwrid(my_methods, user, rid);
91 /***************************************************************************
92 Updates a SAM_ACCOUNT
94 This isn't a particulary practical option for pdb_unix. We certainly don't
95 want to twidde the filesystem, so what should we do?
97 Current plan is to transparently add the account. It should appear
98 as if the pdb_unix version was modified, but its actually stored somehwere.
99 ****************************************************************************/
101 static NTSTATUS unixsam_update_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd)
103 return methods->parent->pdb_add_sam_account(methods->parent, newpwd);
106 NTSTATUS pdb_init_unixsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location)
108 NTSTATUS nt_status;
110 if (!pdb_context) {
111 DEBUG(0, ("invalid pdb_context specified\n"));
112 return NT_STATUS_UNSUCCESSFUL;
115 if (!NT_STATUS_IS_OK(nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) {
116 return nt_status;
119 (*pdb_method)->name = "unixsam";
120 (*pdb_method)->update_sam_account = unixsam_update_sam_account;
121 (*pdb_method)->getsampwnam = unixsam_getsampwnam;
122 (*pdb_method)->getsampwsid = unixsam_getsampwsid;
124 /* There's not very much to initialise here */
125 return NT_STATUS_OK;
128 int pdb_unix_init(void)
130 return smb_register_passdb("unixsam", pdb_init_unixsam, PASSDB_INTERFACE_VERSION);