2 * 'Guest' password backend for samba
3 * Copyright (C) Jelmer Vernooij 2002
4 * Copyright (C) Andrew Bartlett 2003
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 675
18 * Mass Ave, Cambridge, MA 02139, USA.
23 /******************************************************************
24 Lookup a name in the SAM database
25 ******************************************************************/
27 static NTSTATUS
guestsam_getsampwnam (struct pdb_methods
*methods
, SAM_ACCOUNT
*sam_account
, const char *sname
)
30 const char *guest_account
= lp_guestaccount();
32 if (!sam_account
|| !sname
) {
33 DEBUG(0,("invalid name specified"));
34 return NT_STATUS_UNSUCCESSFUL
;
37 if (!(guest_account
&& *guest_account
)) {
38 DEBUG(1, ("NULL guest account!?!?\n"));
39 return NT_STATUS_UNSUCCESSFUL
;
43 DEBUG(0,("invalid methods\n"));
44 return NT_STATUS_UNSUCCESSFUL
;
46 if (!strequal(guest_account
, sname
)) {
47 return NT_STATUS_NO_SUCH_USER
;
50 pdb_fill_default_sam(sam_account
);
52 if (!pdb_set_username(sam_account
, guest_account
, PDB_SET
))
53 return NT_STATUS_UNSUCCESSFUL
;
55 if (!pdb_set_fullname(sam_account
, guest_account
, PDB_SET
))
56 return NT_STATUS_UNSUCCESSFUL
;
58 if (!pdb_set_domain(sam_account
, lp_workgroup(), PDB_DEFAULT
))
59 return NT_STATUS_UNSUCCESSFUL
;
61 if (!pdb_set_acct_ctrl(sam_account
, ACB_NORMAL
, PDB_DEFAULT
))
62 return NT_STATUS_UNSUCCESSFUL
;
64 if (!pdb_set_user_sid_from_rid(sam_account
, DOMAIN_USER_RID_GUEST
, PDB_DEFAULT
))
65 return NT_STATUS_UNSUCCESSFUL
;
67 if (!pdb_set_group_sid_from_rid(sam_account
, DOMAIN_GROUP_RID_GUESTS
, PDB_DEFAULT
))
68 return NT_STATUS_UNSUCCESSFUL
;
74 /***************************************************************************
76 **************************************************************************/
78 static NTSTATUS
guestsam_getsampwrid (struct pdb_methods
*methods
,
79 SAM_ACCOUNT
*sam_account
, uint32 rid
)
81 if (rid
!= DOMAIN_USER_RID_GUEST
) {
82 return NT_STATUS_NO_SUCH_USER
;
86 return NT_STATUS_INVALID_PARAMETER
;
89 return guestsam_getsampwnam (methods
, sam_account
, lp_guestaccount());
92 static NTSTATUS
guestsam_getsampwsid(struct pdb_methods
*my_methods
, SAM_ACCOUNT
* user
, const DOM_SID
*sid
)
95 if (!sid_peek_check_rid(get_global_sam_sid(), sid
, &rid
))
96 return NT_STATUS_NO_SUCH_USER
;
98 return guestsam_getsampwrid(my_methods
, user
, rid
);
102 NTSTATUS
pdb_init_guestsam(PDB_CONTEXT
*pdb_context
, PDB_METHODS
**pdb_method
, const char *location
)
107 DEBUG(0, ("invalid pdb_context specified\n"));
108 return NT_STATUS_UNSUCCESSFUL
;
111 if (!NT_STATUS_IS_OK(nt_status
= make_pdb_methods(pdb_context
->mem_ctx
, pdb_method
))) {
115 (*pdb_method
)->name
= "guestsam";
117 (*pdb_method
)->getsampwnam
= guestsam_getsampwnam
;
118 (*pdb_method
)->getsampwsid
= guestsam_getsampwsid
;
120 /* we should do no group mapping here */
121 (*pdb_method
)->getgrsid
= pdb_nop_getgrsid
;
122 (*pdb_method
)->getgrgid
= pdb_nop_getgrgid
;
123 (*pdb_method
)->getgrnam
= pdb_nop_getgrnam
;
124 (*pdb_method
)->add_group_mapping_entry
= pdb_nop_add_group_mapping_entry
;
125 (*pdb_method
)->update_group_mapping_entry
= pdb_nop_update_group_mapping_entry
;
126 (*pdb_method
)->delete_group_mapping_entry
= pdb_nop_delete_group_mapping_entry
;
127 (*pdb_method
)->enum_group_mapping
= pdb_nop_enum_group_mapping
;
130 /* There's not very much to initialise here */
134 NTSTATUS
pdb_guest_init(void)
136 return smb_register_passdb(PASSDB_INTERFACE_VERSION
, "guest", pdb_init_guestsam
);