2 * Unix SMB/Netbios implementation. Version 1.9. SMB parameters and setup
3 * Copyright (C) Andrew Tridgell 1992-1998 Modified by Jeremy Allison 1995.
4 * Copyright (C) Elrond 2000
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.
26 extern int DEBUGLEVEL
;
28 /***************************************************************
29 Start to enumerate the smbpasswd list. Returns a void pointer
30 to ensure no modification outside this module.
31 ****************************************************************/
33 static void *startsamfilepwent(BOOL update
)
35 return startsmbpwent(update
);
38 /***************************************************************
39 End enumeration of the smbpasswd list.
40 ****************************************************************/
42 static void endsamfilepwent(void *vp
)
47 /*************************************************************************
48 Return the current position in the smbpasswd list as an SMB_BIG_UINT.
49 This must be treated as an opaque token.
50 *************************************************************************/
52 static SMB_BIG_UINT
getsamfilepwpos(void *vp
)
54 return getsmbpwpos(vp
);
57 /*************************************************************************
58 Set the current position in the smbpasswd list from an SMB_BIG_UINT.
59 This must be treated as an opaque token.
60 *************************************************************************/
62 static BOOL
setsamfilepwpos(void *vp
, SMB_BIG_UINT tok
)
64 return setsmbpwpos(vp
, tok
);
67 static BOOL
string_empty (const char *str
)
69 return str
== NULL
|| *str
== '\0';
73 /*************************************************************************
74 Routine to return the next entry in the smbpasswd list.
75 this function is a nice, messy combination of reading:
77 - the unix password database
78 - smb.conf options (not done at present).
79 *************************************************************************/
81 static struct sam_passwd
*getsamfile21pwent(void *vp
)
83 struct sam_passwd
*user
;
84 user_struct bogus_user_struct
;
89 static pstring full_name
;
90 static pstring home_dir
;
91 static pstring home_drive
;
92 static pstring logon_script
;
93 static pstring profile_path
;
94 static pstring acct_desc
;
95 static pstring workstations
;
97 DEBUG(5,("getsamfile21pwent\n"));
99 ZERO_STRUCT(bogus_user_struct
);
101 user
= pwdb_smb_to_sam(pwdb_smb_map_names(getsmbfilepwent(vp
)));
108 * get all the other gubbins we need. substitute unix name for %U
112 vuser
= get_valid_user_struct(get_sec_ctx());
115 /* HACK to make %U work in substitutions below */
116 fstrcpy(bogus_user_struct
.requested_name
, user
->nt_name
);
117 fstrcpy(bogus_user_struct
.name
, user
->unix_name
);
118 DEBUG(7, ("getsamfile21pwent: nt_name=%s, unix_name=%s\n",
119 user
->nt_name
, user
->unix_name
));
121 pstrcpy(full_name
, "");
122 pstrcpy(logon_script
, lp_logon_script (&bogus_user_struct
));
123 pstrcpy(profile_path
, lp_logon_path (&bogus_user_struct
));
124 pstrcpy(home_drive
, lp_logon_drive (&bogus_user_struct
));
125 pstrcpy(home_dir
, lp_logon_home (&bogus_user_struct
));
126 pstrcpy(acct_desc
, "");
127 pstrcpy(workstations
, "");
130 vuid_free_user_struct(vuser
);
134 only overwrite values with defaults IIF specific backend
135 didn't filled the values
138 if (string_empty (user
->full_name
))
139 user
->full_name
= full_name
;
140 if (string_empty (user
->home_dir
))
141 user
->home_dir
= home_dir
;
142 if (string_empty (user
->dir_drive
))
143 user
->dir_drive
= home_drive
;
144 if (string_empty (user
->logon_script
))
145 user
->logon_script
= logon_script
;
146 if (string_empty (user
->profile_path
))
147 user
->profile_path
= profile_path
;
148 if (string_empty (user
->acct_desc
))
149 user
->acct_desc
= acct_desc
;
150 if (string_empty (user
->workstations
))
151 user
->workstations
= workstations
;
153 user
->unknown_str
= NULL
; /* don't know, yet! */
154 user
->munged_dial
= NULL
; /* "munged" dial-back telephone number */
156 user
->unknown_3
= 0xffffff; /* don't know */
157 user
->logon_divs
= 168; /* hours per week */
158 user
->hours_len
= 21; /* 21 times 8 bits = 168 */
159 memset(user
->hours
, 0xff, user
->hours_len
); /* available at all hours */
160 user
->unknown_5
= 0x00020000; /* don't know */
161 user
->unknown_6
= 0x000004ec; /* don't know */
166 /************************************************************************
167 search sam db by uid.
168 *************************************************************************/
169 static struct sam_passwd
*getsamfilepwuid(uid_t uid
)
171 struct sam_passwd
*pwd
= NULL
;
174 DEBUG(10, ("search by uid: %x\n", (int)uid
));
176 /* Open the smb password file - not for update. */
177 fp
= startsam21pwent(False
);
181 DEBUG(0, ("unable to open sam password database.\n"));
185 while ((pwd
= getsamfile21pwent(fp
)) != NULL
&& pwd
->unix_uid
!= uid
)
191 DEBUG(10, ("found by unix_uid: %x\n", (int)uid
));
199 /************************************************************************
200 search sam db by rid.
201 *************************************************************************/
202 static struct sam_passwd
*getsamfilepwrid(uint32 user_rid
)
206 sid_copy(&sid
, &global_sam_sid
);
207 sid_append_rid(&sid
, user_rid
);
209 if (!lookupsmbpwsid(&sid
, &gmep
))
214 return getsamfilepwuid((uid_t
)gmep
.unix_id
);
217 /************************************************************************
218 search sam db by nt name.
219 *************************************************************************/
220 static struct sam_passwd
*getsamfilepwntnam(const char *nt_name
)
224 if (!lookupsmbpwntnam(nt_name
, &gmep
))
229 return getsamfilepwuid((uid_t
)gmep
.unix_id
);
233 * Stub functions - implemented in terms of others.
236 static BOOL
mod_samfile21pwd_entry(struct sam_passwd
* pwd
, BOOL override
)
238 return mod_smbpwd_entry(pwdb_sam_to_smb(pwd
), override
);
241 static BOOL
add_samfile21pwd_entry(struct sam_passwd
*newpwd
)
243 return add_smbpwd_entry(pwdb_sam_to_smb(newpwd
));
246 static struct sam_disp_info
*getsamfiledispntnam(const char *ntname
)
248 return pwdb_sam_to_dispinfo(getsam21pwntnam(ntname
));
251 static struct sam_disp_info
*getsamfiledisprid(uint32 rid
)
253 return pwdb_sam_to_dispinfo(getsam21pwrid(rid
));
256 static struct sam_disp_info
*getsamfiledispent(void *vp
)
258 return pwdb_sam_to_dispinfo(getsam21pwent(vp
));
261 static struct sam_passdb_ops sam_file_ops
=
271 add_samfile21pwd_entry
,
272 mod_samfile21pwd_entry
,
278 struct sam_passdb_ops
*file_initialise_sam_password_db(void)
280 return &sam_file_ops
;
284 /* Do *NOT* make this function static. It breaks the compile on gcc. JRA */
285 void sampass_dummy_function(void) { } /* stop some compilers complaining */
286 #endif /* USE_SMBPASS_DB */