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 NTSTATUS pdb_init_unixsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location)
96 DEBUG(0, ("invalid pdb_context specified\n"));
97 return NT_STATUS_UNSUCCESSFUL;
100 if (!NT_STATUS_IS_OK(nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) {
104 (*pdb_method)->name = "unixsam";
105 (*pdb_method)->getsampwnam = unixsam_getsampwnam;
106 (*pdb_method)->getsampwsid = unixsam_getsampwsid;
108 /* There's not very much to initialise here */