2 * Unix SMB/Netbios implementation.
4 * Samba MYSQL SAM Database, by Benjamin Kuit.
5 * Copyright (C) Benjamin Kuit 1999,
6 * Copyright (C) Andrew Tridgell 1992-1999,
7 * Copyright (C) Luke Kenneth Casson Leighton 1996-1998,
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #if defined(HAVE_MYSQL_H) && defined(WITH_MYSQLSAM)
28 extern int DEBUGLEVEL;
30 extern pstring samlogon_user;
31 extern BOOL sam_logon_in_ssb;
33 void *mysql_fill_sam_passwd( MYSQL_ROW *row )
35 static struct sam_passwd *user;
37 static pstring full_name;
38 static pstring home_dir;
39 static pstring home_drive;
40 static pstring logon_script;
41 static pstring profile_path;
42 static pstring acct_desc;
43 static pstring workstations;
45 DEBUG(5,("%s\n",FUNCTION_MACRO));
47 user = pwdb_smb_to_sam((struct smb_passwd *)mysql_fill_smb_passwd(row));
53 /* 'Researched' from sampass.c =) */
55 pstrcpy(samlogon_user, user->unix_name);
57 if (samlogon_user[strlen(samlogon_user)-1] == '$' &&
58 user->group_rid != DOMAIN_GROUP_RID_USERS)
60 DEBUG(0,("trust account %s should be in DOMAIN_GROUP_RID_USERS\n", samlogon_user));
63 /* XXXX hack to get standard_sub_basic() to use sam logon username */
64 /* possibly a better way would be to do a become_user() call */
65 sam_logon_in_ssb = True;
67 pstrcpy(full_name , "");
68 pstrcpy(logon_script , lp_logon_script ());
69 pstrcpy(profile_path , lp_logon_path ());
70 pstrcpy(home_drive , lp_logon_drive ());
71 pstrcpy(home_dir , lp_logon_home ());
72 pstrcpy(acct_desc , "");
73 pstrcpy(workstations , "");
75 sam_logon_in_ssb = False;
77 user->full_name = full_name;
78 user->home_dir = home_dir;
79 user->dir_drive = home_drive;
80 user->logon_script = logon_script;
81 user->profile_path = profile_path;
82 user->acct_desc = acct_desc;
83 user->workstations = workstations;
85 user->unknown_str = NULL; /* don't know, yet! */
86 user->munged_dial = NULL; /* "munged" dial-back telephone number */
88 user->unknown_3 = 0xffffff; /* don't know */
89 user->logon_divs = 168; /* hours per week */
90 user->hours_len = 21; /* 21 times 8 bits = 168 */
91 memset(user->hours, 0xff, user->hours_len); /* available at all hours */
92 user->unknown_5 = 0x00020000; /* don't know */
93 user->unknown_6 = 0x000004ec; /* don't know */
98 struct sam_passwd *mysql_getsampwent(void *vp)
101 DEBUG(5,("%s\n",FUNCTION_MACRO));
103 return (struct sam_passwd*)mysql_fill_sam_passwd( mysql_getpwent(vp) );
106 struct sam_passwd *mysql_getsampwrid(uint32 rid)
110 DEBUG(5,("%s\n",FUNCTION_MACRO));
112 slprintf( where, sizeof(where), "user_rid=%lu", (long unsigned)rid);
114 return (struct sam_passwd *)mysql_fetch_passwd( mysql_fill_sam_passwd, where );
117 struct sam_passwd *mysql_getsampwuid(uid_t uid)
120 DEBUG(5,("%s\n",FUNCTION_MACRO));
122 return (struct sam_passwd *)mysql_getpwuid( mysql_fill_sam_passwd, uid );
125 struct sam_passwd *mysql_getsampwntnam(const char *nt_name)
128 DEBUG(5,("%s\n",FUNCTION_MACRO));
130 return (struct sam_passwd *)mysql_getpwnam( mysql_fill_sam_passwd, "nt_name", nt_name);
133 struct sam_disp_info *mysql_getsamdispntnam(const char *nt_name)
136 DEBUG(5,("%s\n",FUNCTION_MACRO));
138 return pwdb_sam_to_dispinfo(mysql_getsampwntnam(nt_name));
141 struct sam_disp_info *mysql_getsamdisprid(uint32 rid)
144 DEBUG(5,("%s\n",FUNCTION_MACRO));
146 return pwdb_sam_to_dispinfo(mysql_getsampwrid(rid));
149 struct sam_disp_info *mysql_getsamdispent(void *vp)
152 DEBUG(5,("%s\n",FUNCTION_MACRO));
154 return pwdb_sam_to_dispinfo(mysql_getsampwent(vp));
157 static BOOL mysql_mod_sam( MYSQL *handle, struct sam_passwd *sam, BOOL override )
160 DEBUG(5,("%s\n",FUNCTION_MACRO));
165 BOOL mysql_add_sampwd_entry(struct sam_passwd *sam)
168 struct smb_passwd *smb;
170 DEBUG(5,("%s\n",FUNCTION_MACRO));
172 smb = pwdb_sam_to_smb( sam );
178 if ( mysql_db_lock_connect( &handle ) ) {
182 if ( !mysql_add_smb( &handle, smb ) ) {
183 mysql_close(&handle);
187 if ( !mysql_mod_smb( &handle, smb, True ) ) {
188 mysql_del_smb( &handle, smb->unix_name );
189 mysql_close(&handle);
193 if ( !mysql_mod_sam( &handle, sam, True ) ) {
194 mysql_del_smb( &handle, smb->unix_name );
195 mysql_close(&handle);
199 mysql_close(&handle);
203 BOOL mysql_mod_sampwd_entry(struct sam_passwd *sam, BOOL override)
206 struct smb_passwd *smb;
208 DEBUG(5,("%s\n",FUNCTION_MACRO));
210 smb = pwdb_sam_to_smb(sam);
216 if ( mysql_db_lock_connect( &handle ) ) {
220 if ( !mysql_mod_smb( &handle, smb, override ) ) {
221 mysql_close(&handle);
225 if ( !mysql_mod_sam( &handle, sam, override ) ) {
226 mysql_close(&handle);
230 mysql_close(&handle);
234 static struct sam_passdb_ops sam_mysql_ops =
244 mysql_add_sampwd_entry,
245 mysql_mod_sampwd_entry,
246 mysql_getsamdispntnam,
251 struct sam_passdb_ops *mysql_initialise_sam_password_db(void)
253 return &sam_mysql_ops;
257 void mysql_dummy_sam_function(void) { }