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 MYSQL_ROW *mysql_getpwent(void *vp);
30 extern int DEBUGLEVEL;
32 extern pstring samlogon_user;
33 extern BOOL sam_logon_in_ssb;
35 void *mysql_fill_sam_passwd( MYSQL_ROW *row )
37 static struct sam_passwd *user;
39 static pstring full_name;
40 static pstring home_dir;
41 static pstring home_drive;
42 static pstring logon_script;
43 static pstring profile_path;
44 static pstring acct_desc;
45 static pstring workstations;
47 DEBUG(5,("%s\n",FUNCTION_MACRO));
49 user = pwdb_smb_to_sam((struct smb_passwd *)mysql_fill_smb_passwd(row));
55 /* 'Researched' from sampass.c =) */
57 pstrcpy(samlogon_user, user->unix_name);
59 if (samlogon_user[strlen(samlogon_user)-1] == '$' &&
60 user->group_rid != DOMAIN_GROUP_RID_USERS)
62 DEBUG(0,("trust account %s should be in DOMAIN_GROUP_RID_USERS\n", samlogon_user));
65 /* XXXX hack to get standard_sub_basic() to use sam logon username */
66 /* possibly a better way would be to do a become_user() call */
67 sam_logon_in_ssb = True;
69 pstrcpy(full_name , "");
70 pstrcpy(logon_script , lp_logon_script ());
71 pstrcpy(profile_path , lp_logon_path ());
72 pstrcpy(home_drive , lp_logon_drive ());
73 pstrcpy(home_dir , lp_logon_home ());
74 pstrcpy(acct_desc , "");
75 pstrcpy(workstations , "");
77 sam_logon_in_ssb = False;
79 user->full_name = full_name;
80 user->home_dir = home_dir;
81 user->dir_drive = home_drive;
82 user->logon_script = logon_script;
83 user->profile_path = profile_path;
84 user->acct_desc = acct_desc;
85 user->workstations = workstations;
87 user->unknown_str = NULL; /* don't know, yet! */
88 user->munged_dial = NULL; /* "munged" dial-back telephone number */
90 user->unknown_3 = 0xffffff; /* don't know */
91 user->logon_divs = 168; /* hours per week */
92 user->hours_len = 21; /* 21 times 8 bits = 168 */
93 memset(user->hours, 0xff, user->hours_len); /* available at all hours */
94 user->unknown_5 = 0x00020000; /* don't know */
95 user->unknown_6 = 0x000004ec; /* don't know */
100 struct sam_passwd *mysql_getsampwent(void *vp)
103 DEBUG(5,("%s\n",FUNCTION_MACRO));
105 return (struct sam_passwd*)mysql_fill_sam_passwd( mysql_getpwent(vp) );
108 struct sam_passwd *mysql_getsampwrid(uint32 rid)
112 DEBUG(5,("%s\n",FUNCTION_MACRO));
114 slprintf( where, sizeof(where), "user_rid=%lu", (long unsigned)rid);
116 return (struct sam_passwd *)mysql_fetch_passwd( mysql_fill_sam_passwd, where );
119 struct sam_passwd *mysql_getsampwuid(uid_t uid)
122 DEBUG(5,("%s\n",FUNCTION_MACRO));
124 return (struct sam_passwd *)mysql_getpwuid( mysql_fill_sam_passwd, uid );
127 struct sam_passwd *mysql_getsampwntnam(const char *nt_name)
130 DEBUG(5,("%s\n",FUNCTION_MACRO));
132 return (struct sam_passwd *)mysql_getpwnam( mysql_fill_sam_passwd, "nt_name", nt_name);
135 struct sam_disp_info *mysql_getsamdispntnam(const char *nt_name)
138 DEBUG(5,("%s\n",FUNCTION_MACRO));
140 return pwdb_sam_to_dispinfo(mysql_getsampwntnam(nt_name));
143 struct sam_disp_info *mysql_getsamdisprid(uint32 rid)
146 DEBUG(5,("%s\n",FUNCTION_MACRO));
148 return pwdb_sam_to_dispinfo(mysql_getsampwrid(rid));
151 struct sam_disp_info *mysql_getsamdispent(void *vp)
154 DEBUG(5,("%s\n",FUNCTION_MACRO));
156 return pwdb_sam_to_dispinfo(mysql_getsampwent(vp));
159 static BOOL mysql_mod_sam( MYSQL *handle, struct sam_passwd *sam, BOOL override )
162 DEBUG(5,("%s\n",FUNCTION_MACRO));
167 BOOL mysql_add_sampwd_entry(struct sam_passwd *sam)
170 struct smb_passwd *smb;
172 DEBUG(5,("%s\n",FUNCTION_MACRO));
174 smb = pwdb_sam_to_smb( sam );
180 if ( mysql_db_lock_connect( &handle ) ) {
184 if ( !mysql_add_smb( &handle, smb ) ) {
185 mysql_close(&handle);
189 if ( !mysql_mod_smb( &handle, smb, True ) ) {
190 mysql_del_smb( &handle, smb->unix_name );
191 mysql_close(&handle);
195 if ( !mysql_mod_sam( &handle, sam, True ) ) {
196 mysql_del_smb( &handle, smb->unix_name );
197 mysql_close(&handle);
201 mysql_close(&handle);
205 BOOL mysql_mod_sampwd_entry(struct sam_passwd *sam, BOOL override)
208 struct smb_passwd *smb;
210 DEBUG(5,("%s\n",FUNCTION_MACRO));
212 smb = pwdb_sam_to_smb(sam);
218 if ( mysql_db_lock_connect( &handle ) ) {
222 if ( !mysql_mod_smb( &handle, smb, override ) ) {
223 mysql_close(&handle);
227 if ( !mysql_mod_sam( &handle, sam, override ) ) {
228 mysql_close(&handle);
232 mysql_close(&handle);
236 static struct sam_passdb_ops sam_mysql_ops =
246 mysql_add_sampwd_entry,
247 mysql_mod_sampwd_entry,
248 mysql_getsamdispntnam,
253 struct sam_passdb_ops *mysql_initialise_sam_password_db(void)
255 return &sam_mysql_ops;
259 void mysql_dummy_sam_function(void) { }