2 * Unix password backend for samba
3 * Copyright (C) Jelmer Vernooij 2002
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)
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
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.
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
)
30 DEBUG(0,("invalid methods\n"));
31 return NT_STATUS_UNSUCCESSFUL
;
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 /***************************************************************************
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"));
59 DEBUG(0,("invalid methods\n"));
63 if (rid
== DOMAIN_USER_RID_GUEST
) {
64 pass
= getpwnam_alloc(guest_account
);
66 DEBUG(1, ("guest account %s does not seem to exist...\n", guest_account
));
69 } else if (pdb_rid_is_user(rid
)) {
70 pass
= getpwuid_alloc(fallback_pdb_user_rid_to_uid (rid
));
77 nt_status
= pdb_fill_sam_pw(user
, pass
);
83 static NTSTATUS
unixsam_getsampwsid(struct pdb_methods
*my_methods
, SAM_ACCOUNT
* user
, const DOM_SID
*sid
)
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 /***************************************************************************
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
)
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
))) {
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 */
128 int pdb_unix_init(void)
130 return smb_register_passdb("unixsam", pdb_init_unixsam
, PASSDB_INTERFACE_VERSION
);