~ubuntu-branches/ubuntu/gutsy/samba/gutsy-updates

« back to all changes in this revision

Viewing changes to source/passdb/pdb_get_set.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2006-11-28 20:14:37 UTC
  • mfrom: (0.10.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061128201437-a6x4lzlhempazocp
Tags: 3.0.23d-1ubuntu1
* Merge from debian unstable.
* Drop python2.4-samba, replace with python-samba. Added Conflicts/Replaces
  on python2.4-samba
* Drop track-connection-dos.patch, ubuntu-winbind-panic.patch, 
  ubuntu-fix-ldap.patch, ubuntu-setlocale.patch, ubuntu-setlocale-fixes.patch
* Remaining Ubuntu changes:
  - Revert Debian's installation of mount.cifs and umount.cifs as suid
  - Comment out the default [homes] shares and add more verbose comments to
    explain what they do and how they work (closes: launchpad.net/27608)
  - Add a "valid users = %S" stanza to the commented-out [homes] section, to
    show users how to restrict access to \\server\username to only username.
  - Change the (commented-out) "printer admin" example to use "@lpadmin"
    instead of "@ntadmin", since the lpadmin group is used for spool admin.
  - Alter the panic-action script to encourage users to report their
    bugs in Ubuntu packages to Ubuntu, rather than reporting to Debian.
    Modify text to more closely match the Debian script
  - Munge our init script to deal with the fact that our implementation
    (or lack thereof) of log_daemon_msg and log_progress_msg differs
    from Debian's implementation of the same (Ubuntu #19691)
  - Kept ubuntu-auxsrc.patch: some auxilliary sources (undocumented in 
    previous changelogs)
  - Set default workgroup to MSHOME

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* 
2
2
   Unix SMB/CIFS implementation.
3
 
   SAM_ACCOUNT access routines
 
3
   struct samu access routines
4
4
   Copyright (C) Jeremy Allison                 1996-2001
5
5
   Copyright (C) Luke Kenneth Casson Leighton   1996-1998
6
 
   Copyright (C) Gerald (Jerry) Carter          2000-2001
 
6
   Copyright (C) Gerald (Jerry) Carter          2000-2006
7
7
   Copyright (C) Andrew Bartlett                2001-2002
8
8
   Copyright (C) Stefan (metze) Metzmacher      2002
9
9
      
37
37
#define PDB_NOT_QUITE_NULL ""
38
38
 
39
39
/*********************************************************************
40
 
 Collection of get...() functions for SAM_ACCOUNT.
 
40
 Collection of get...() functions for struct samu.
41
41
 ********************************************************************/
42
42
 
43
 
uint16 pdb_get_acct_ctrl (const SAM_ACCOUNT *sampass)
44
 
{
45
 
        if (sampass)
46
 
                return (sampass->private_u.acct_ctrl);
47
 
        else
48
 
                return (ACB_DISABLED);
49
 
}
50
 
 
51
 
time_t pdb_get_logon_time (const SAM_ACCOUNT *sampass)
52
 
{
53
 
        if (sampass)
54
 
                return (sampass->private_u.logon_time);
55
 
        else
56
 
                return (0);
57
 
}
58
 
 
59
 
time_t pdb_get_logoff_time (const SAM_ACCOUNT *sampass)
60
 
{
61
 
        if (sampass)
62
 
                return (sampass->private_u.logoff_time);
63
 
        else
64
 
                return (-1);
65
 
}
66
 
 
67
 
time_t pdb_get_kickoff_time (const SAM_ACCOUNT *sampass)
68
 
{
69
 
        if (sampass)
70
 
                return (sampass->private_u.kickoff_time);
71
 
        else
72
 
                return (-1);
73
 
}
74
 
 
75
 
time_t pdb_get_bad_password_time (const SAM_ACCOUNT *sampass)
76
 
{
77
 
        if (sampass)
78
 
                return (sampass->private_u.bad_password_time);
79
 
        else
80
 
                return (-1);
81
 
}
82
 
 
83
 
time_t pdb_get_pass_last_set_time (const SAM_ACCOUNT *sampass)
84
 
{
85
 
        if (sampass)
86
 
                return (sampass->private_u.pass_last_set_time);
87
 
        else
88
 
                return (-1);
89
 
}
90
 
 
91
 
time_t pdb_get_pass_can_change_time (const SAM_ACCOUNT *sampass)
92
 
{
93
 
        if (sampass)
94
 
                return (sampass->private_u.pass_can_change_time);
95
 
        else
96
 
                return (-1);
97
 
}
98
 
 
99
 
time_t pdb_get_pass_must_change_time (const SAM_ACCOUNT *sampass)
100
 
{
101
 
        if (sampass)
102
 
                return (sampass->private_u.pass_must_change_time);
103
 
        else
104
 
                return (-1);
105
 
}
106
 
 
107
 
uint16 pdb_get_logon_divs (const SAM_ACCOUNT *sampass)
108
 
{
109
 
        if (sampass)
110
 
                return (sampass->private_u.logon_divs);
111
 
        else
112
 
                return (-1);
113
 
}
114
 
 
115
 
uint32 pdb_get_hours_len (const SAM_ACCOUNT *sampass)
116
 
{
117
 
        if (sampass)
118
 
                return (sampass->private_u.hours_len);
119
 
        else
120
 
                return (-1);
121
 
}
122
 
 
123
 
const uint8* pdb_get_hours (const SAM_ACCOUNT *sampass)
124
 
{
125
 
        if (sampass)
126
 
                return (sampass->private_u.hours);
127
 
        else
128
 
                return (NULL);
129
 
}
130
 
 
131
 
const uint8* pdb_get_nt_passwd (const SAM_ACCOUNT *sampass)
132
 
{
133
 
        if (sampass) {
134
 
                SMB_ASSERT((!sampass->private_u.nt_pw.data) 
135
 
                           || sampass->private_u.nt_pw.length == NT_HASH_LEN);
136
 
                return ((uint8*)sampass->private_u.nt_pw.data);
137
 
        }
138
 
        else
139
 
                return (NULL);
140
 
}
141
 
 
142
 
const uint8* pdb_get_lanman_passwd (const SAM_ACCOUNT *sampass)
143
 
{
144
 
        if (sampass) {
145
 
                SMB_ASSERT((!sampass->private_u.lm_pw.data) 
146
 
                           || sampass->private_u.lm_pw.length == LM_HASH_LEN);
147
 
                return ((uint8*)sampass->private_u.lm_pw.data);
148
 
        }
149
 
        else
150
 
                return (NULL);
151
 
}
152
 
 
153
 
const uint8* pdb_get_pw_history (const SAM_ACCOUNT *sampass, uint32 *current_hist_len)
154
 
{
155
 
        if (sampass) {
156
 
                SMB_ASSERT((!sampass->private_u.nt_pw_his.data) 
157
 
                   || ((sampass->private_u.nt_pw_his.length % PW_HISTORY_ENTRY_LEN) == 0));
158
 
                *current_hist_len = sampass->private_u.nt_pw_his.length / PW_HISTORY_ENTRY_LEN;
159
 
                return ((uint8*)sampass->private_u.nt_pw_his.data);
160
 
        } else {
161
 
                *current_hist_len = 0;
162
 
                return (NULL);
163
 
        }
 
43
uint32 pdb_get_acct_ctrl(const struct samu *sampass)
 
44
{
 
45
        return sampass->acct_ctrl;
 
46
}
 
47
 
 
48
time_t pdb_get_logon_time(const struct samu *sampass)
 
49
{
 
50
        return sampass->logon_time;
 
51
}
 
52
 
 
53
time_t pdb_get_logoff_time(const struct samu *sampass)
 
54
{
 
55
        return sampass->logoff_time;
 
56
}
 
57
 
 
58
time_t pdb_get_kickoff_time(const struct samu *sampass)
 
59
{
 
60
        return sampass->kickoff_time;
 
61
}
 
62
 
 
63
time_t pdb_get_bad_password_time(const struct samu *sampass)
 
64
{
 
65
        return sampass->bad_password_time;
 
66
}
 
67
 
 
68
time_t pdb_get_pass_last_set_time(const struct samu *sampass)
 
69
{
 
70
        return sampass->pass_last_set_time;
 
71
}
 
72
 
 
73
time_t pdb_get_pass_can_change_time(const struct samu *sampass)
 
74
{
 
75
        return sampass->pass_can_change_time;
 
76
}
 
77
 
 
78
time_t pdb_get_pass_must_change_time(const struct samu *sampass)
 
79
{
 
80
        return sampass->pass_must_change_time;
 
81
}
 
82
 
 
83
uint16 pdb_get_logon_divs(const struct samu *sampass)
 
84
{
 
85
        return sampass->logon_divs;
 
86
}
 
87
 
 
88
uint32 pdb_get_hours_len(const struct samu *sampass)
 
89
{
 
90
        return sampass->hours_len;
 
91
}
 
92
 
 
93
const uint8 *pdb_get_hours(const struct samu *sampass)
 
94
{
 
95
        return (sampass->hours);
 
96
}
 
97
 
 
98
const uint8 *pdb_get_nt_passwd(const struct samu *sampass)
 
99
{
 
100
        SMB_ASSERT((!sampass->nt_pw.data) 
 
101
                   || sampass->nt_pw.length == NT_HASH_LEN);
 
102
        return (uint8 *)sampass->nt_pw.data;
 
103
}
 
104
 
 
105
const uint8 *pdb_get_lanman_passwd(const struct samu *sampass)
 
106
{
 
107
        SMB_ASSERT((!sampass->lm_pw.data) 
 
108
                   || sampass->lm_pw.length == LM_HASH_LEN);
 
109
        return (uint8 *)sampass->lm_pw.data;
 
110
}
 
111
 
 
112
const uint8 *pdb_get_pw_history(const struct samu *sampass, uint32 *current_hist_len)
 
113
{
 
114
        SMB_ASSERT((!sampass->nt_pw_his.data) 
 
115
           || ((sampass->nt_pw_his.length % PW_HISTORY_ENTRY_LEN) == 0));
 
116
        *current_hist_len = sampass->nt_pw_his.length / PW_HISTORY_ENTRY_LEN;
 
117
        return (uint8 *)sampass->nt_pw_his.data;
164
118
}
165
119
 
166
120
/* Return the plaintext password if known.  Most of the time
169
123
   Used to pass the plaintext to passdb backends that might 
170
124
   want to store more than just the NTLM hashes.
171
125
*/
172
 
const char* pdb_get_plaintext_passwd (const SAM_ACCOUNT *sampass)
173
 
{
174
 
        if (sampass) {
175
 
                return (sampass->private_u.plaintext_pw);
176
 
        }
177
 
        else
178
 
                return (NULL);
179
 
}
180
 
const DOM_SID *pdb_get_user_sid(const SAM_ACCOUNT *sampass)
181
 
{
182
 
        if (sampass) 
183
 
                return &sampass->private_u.user_sid;
184
 
        else
185
 
                return (NULL);
186
 
}
187
 
 
188
 
const DOM_SID *pdb_get_group_sid(const SAM_ACCOUNT *sampass)
189
 
{
190
 
        if (sampass)
191
 
                return &sampass->private_u.group_sid;
192
 
        else    
193
 
                return (NULL);
 
126
const char *pdb_get_plaintext_passwd(const struct samu *sampass)
 
127
{
 
128
        return sampass->plaintext_pw;
 
129
}
 
130
 
 
131
const DOM_SID *pdb_get_user_sid(const struct samu *sampass)
 
132
{
 
133
        return &sampass->user_sid;
 
134
}
 
135
 
 
136
const DOM_SID *pdb_get_group_sid(struct samu *sampass)
 
137
{
 
138
        DOM_SID *gsid;
 
139
        struct passwd *pwd;
 
140
        
 
141
        /* Return the cached group SID if we have that */
 
142
        if ( sampass->group_sid ) {
 
143
                return sampass->group_sid;
 
144
        }
 
145
                
 
146
        /* generate the group SID from the user's primary Unix group */
 
147
        
 
148
        if ( !(gsid  = TALLOC_P( sampass, DOM_SID )) ) {
 
149
                return NULL;
 
150
        }
 
151
        
 
152
        /* No algorithmic mapping, meaning that we have to figure out the
 
153
           primary group SID according to group mapping and the user SID must
 
154
           be a newly allocated one.  We rely on the user's Unix primary gid.
 
155
           We have no choice but to fail if we can't find it. */
 
156
 
 
157
        if ( sampass->unix_pw ) {
 
158
                pwd = sampass->unix_pw;
 
159
        } else {
 
160
                pwd = Get_Pwnam_alloc( sampass, pdb_get_username(sampass) );
 
161
        }
 
162
 
 
163
        if ( !pwd ) {
 
164
                DEBUG(0,("pdb_get_group_sid: Failed to find Unix account for %s\n", pdb_get_username(sampass) ));
 
165
                return NULL;
 
166
        }
 
167
        
 
168
        if ( pdb_gid_to_sid(pwd->pw_gid, gsid) ) {
 
169
                enum SID_NAME_USE type = SID_NAME_UNKNOWN;
 
170
                TALLOC_CTX *mem_ctx = talloc_init("pdb_get_group_sid");
 
171
                BOOL lookup_ret;
 
172
                
 
173
                if (!mem_ctx) {
 
174
                        return NULL;
 
175
                }
 
176
 
 
177
                /* Now check that it's actually a domain group and not something else */
 
178
 
 
179
                lookup_ret = lookup_sid(mem_ctx, gsid, NULL, NULL, &type);
 
180
 
 
181
                TALLOC_FREE( mem_ctx );
 
182
 
 
183
                if ( lookup_ret && (type == SID_NAME_DOM_GRP) ) {
 
184
                        sampass->group_sid = gsid;
 
185
                        return sampass->group_sid;
 
186
                }
 
187
 
 
188
                DEBUG(3, ("Primary group for user %s is a %s and not a domain group\n", 
 
189
                        pwd->pw_name, sid_type_lookup(type)));
 
190
        }
 
191
 
 
192
        /* Just set it to the 'Domain Users' RID of 512 which will 
 
193
           always resolve to a name */
 
194
                   
 
195
        sid_copy( gsid, get_global_sam_sid() );
 
196
        sid_append_rid( gsid, DOMAIN_GROUP_RID_USERS );
 
197
                
 
198
        sampass->group_sid = gsid;
 
199
                
 
200
        return sampass->group_sid;
194
201
}       
195
202
 
196
203
/**
197
 
 * Get flags showing what is initalised in the SAM_ACCOUNT
198
 
 * @param sampass the SAM_ACCOUNT in question
 
204
 * Get flags showing what is initalised in the struct samu
 
205
 * @param sampass the struct samu in question
199
206
 * @return the flags indicating the members initialised in the struct.
200
207
 **/
201
208
 
202
 
enum pdb_value_state pdb_get_init_flags (const SAM_ACCOUNT *sampass, enum pdb_elements element)
 
209
enum pdb_value_state pdb_get_init_flags(const struct samu *sampass, enum pdb_elements element)
203
210
{
204
211
        enum pdb_value_state ret = PDB_DEFAULT;
205
212
        
206
 
        if (!sampass || !sampass->private_u.change_flags || !sampass->private_u.set_flags)
 
213
        if (!sampass->change_flags || !sampass->set_flags)
207
214
                return ret;
208
215
                
209
 
        if (bitmap_query(sampass->private_u.set_flags, element)) {
 
216
        if (bitmap_query(sampass->set_flags, element)) {
210
217
                DEBUG(11, ("element %d: SET\n", element)); 
211
218
                ret = PDB_SET;
212
219
        }
213
220
                
214
 
        if (bitmap_query(sampass->private_u.change_flags, element)) {
 
221
        if (bitmap_query(sampass->change_flags, element)) {
215
222
                DEBUG(11, ("element %d: CHANGED\n", element)); 
216
223
                ret = PDB_CHANGED;
217
224
        }
223
230
        return ret;
224
231
}
225
232
 
226
 
const char* pdb_get_username (const SAM_ACCOUNT *sampass)
227
 
{
228
 
        if (sampass)
229
 
                return (sampass->private_u.username);
230
 
        else
231
 
                return (NULL);
232
 
}
233
 
 
234
 
const char* pdb_get_domain (const SAM_ACCOUNT *sampass)
235
 
{
236
 
        if (sampass)
237
 
                return (sampass->private_u.domain);
238
 
        else
239
 
                return (NULL);
240
 
}
241
 
 
242
 
const char* pdb_get_nt_username (const SAM_ACCOUNT *sampass)
243
 
{
244
 
        if (sampass)
245
 
                return (sampass->private_u.nt_username);
246
 
        else
247
 
                return (NULL);
248
 
}
249
 
 
250
 
const char* pdb_get_fullname (const SAM_ACCOUNT *sampass)
251
 
{
252
 
        if (sampass)
253
 
                return (sampass->private_u.full_name);
254
 
        else
255
 
                return (NULL);
256
 
}
257
 
 
258
 
const char* pdb_get_homedir (const SAM_ACCOUNT *sampass)
259
 
{
260
 
        if (sampass)
261
 
                return (sampass->private_u.home_dir);
262
 
        else
263
 
                return (NULL);
264
 
}
265
 
 
266
 
const char* pdb_get_unix_homedir (const SAM_ACCOUNT *sampass)
267
 
{
268
 
        if (sampass)
269
 
                return (sampass->private_u.unix_home_dir);
270
 
        else
271
 
                return (NULL);
272
 
}
273
 
 
274
 
const char* pdb_get_dir_drive (const SAM_ACCOUNT *sampass)
275
 
{
276
 
        if (sampass)
277
 
                return (sampass->private_u.dir_drive);
278
 
        else
279
 
                return (NULL);
280
 
}
281
 
 
282
 
const char* pdb_get_logon_script (const SAM_ACCOUNT *sampass)
283
 
{
284
 
        if (sampass)
285
 
                return (sampass->private_u.logon_script);
286
 
        else
287
 
                return (NULL);
288
 
}
289
 
 
290
 
const char* pdb_get_profile_path (const SAM_ACCOUNT *sampass)
291
 
{
292
 
        if (sampass)
293
 
                return (sampass->private_u.profile_path);
294
 
        else
295
 
                return (NULL);
296
 
}
297
 
 
298
 
const char* pdb_get_acct_desc (const SAM_ACCOUNT *sampass)
299
 
{
300
 
        if (sampass)
301
 
                return (sampass->private_u.acct_desc);
302
 
        else
303
 
                return (NULL);
304
 
}
305
 
 
306
 
const char* pdb_get_workstations (const SAM_ACCOUNT *sampass)
307
 
{
308
 
        if (sampass)
309
 
                return (sampass->private_u.workstations);
310
 
        else
311
 
                return (NULL);
312
 
}
313
 
 
314
 
const char* pdb_get_unknown_str (const SAM_ACCOUNT *sampass)
315
 
{
316
 
        if (sampass)
317
 
                return (sampass->private_u.unknown_str);
318
 
        else
319
 
                return (NULL);
320
 
}
321
 
 
322
 
const char* pdb_get_munged_dial (const SAM_ACCOUNT *sampass)
323
 
{
324
 
        if (sampass)
325
 
                return (sampass->private_u.munged_dial);
326
 
        else
327
 
                return (NULL);
328
 
}
329
 
 
330
 
uint16 pdb_get_bad_password_count(const SAM_ACCOUNT *sampass)
331
 
{
332
 
        if (sampass)
333
 
                return (sampass->private_u.bad_password_count);
334
 
        else
335
 
                return 0;
336
 
}
337
 
 
338
 
uint16 pdb_get_logon_count(const SAM_ACCOUNT *sampass)
339
 
{
340
 
        if (sampass)
341
 
                return (sampass->private_u.logon_count);
342
 
        else
343
 
                return 0;
344
 
}
345
 
 
346
 
uint32 pdb_get_unknown_6 (const SAM_ACCOUNT *sampass)
347
 
{
348
 
        if (sampass)
349
 
                return (sampass->private_u.unknown_6);
350
 
        else
351
 
                return (-1);
352
 
}
353
 
 
354
 
void *pdb_get_backend_private_data (const SAM_ACCOUNT *sampass, const struct pdb_methods *my_methods)
355
 
{
356
 
        if (sampass && my_methods == sampass->private_u.backend_private_methods)
357
 
                return sampass->private_u.backend_private_data;
358
 
        else
 
233
const char *pdb_get_username(const struct samu *sampass)
 
234
{
 
235
        return sampass->username;
 
236
}
 
237
 
 
238
const char *pdb_get_domain(const struct samu *sampass)
 
239
{
 
240
        return sampass->domain;
 
241
}
 
242
 
 
243
const char *pdb_get_nt_username(const struct samu *sampass)
 
244
{
 
245
        return sampass->nt_username;
 
246
}
 
247
 
 
248
const char *pdb_get_fullname(const struct samu *sampass)
 
249
{
 
250
        return sampass->full_name;
 
251
}
 
252
 
 
253
const char *pdb_get_homedir(const struct samu *sampass)
 
254
{
 
255
        return sampass->home_dir;
 
256
}
 
257
 
 
258
const char *pdb_get_unix_homedir(const struct samu *sampass)
 
259
{
 
260
        if (sampass->unix_pw ) {
 
261
                return sampass->unix_pw->pw_dir;
 
262
        }
 
263
        return NULL;
 
264
}
 
265
 
 
266
const char *pdb_get_dir_drive(const struct samu *sampass)
 
267
{
 
268
        return sampass->dir_drive;
 
269
}
 
270
 
 
271
const char *pdb_get_logon_script(const struct samu *sampass)
 
272
{
 
273
        return sampass->logon_script;
 
274
}
 
275
 
 
276
const char *pdb_get_profile_path(const struct samu *sampass)
 
277
{
 
278
        return sampass->profile_path;
 
279
}
 
280
 
 
281
const char *pdb_get_acct_desc(const struct samu *sampass)
 
282
{
 
283
        return sampass->acct_desc;
 
284
}
 
285
 
 
286
const char *pdb_get_workstations(const struct samu *sampass)
 
287
{
 
288
        return sampass->workstations;
 
289
}
 
290
 
 
291
const char *pdb_get_unknown_str(const struct samu *sampass)
 
292
{
 
293
        return sampass->unknown_str;
 
294
}
 
295
 
 
296
const char *pdb_get_munged_dial(const struct samu *sampass)
 
297
{
 
298
        return sampass->munged_dial;
 
299
}
 
300
 
 
301
uint16 pdb_get_bad_password_count(const struct samu *sampass)
 
302
{
 
303
        return sampass->bad_password_count;
 
304
}
 
305
 
 
306
uint16 pdb_get_logon_count(const struct samu *sampass)
 
307
{
 
308
        return sampass->logon_count;
 
309
}
 
310
 
 
311
uint32 pdb_get_unknown_6(const struct samu *sampass)
 
312
{
 
313
        return sampass->unknown_6;
 
314
}
 
315
 
 
316
void *pdb_get_backend_private_data(const struct samu *sampass, const struct pdb_methods *my_methods)
 
317
{
 
318
        if (my_methods == sampass->backend_private_methods) {
 
319
                return sampass->backend_private_data;
 
320
        } else {
359
321
                return NULL;
 
322
        }
360
323
}
361
324
 
362
325
/*********************************************************************
363
 
 Collection of set...() functions for SAM_ACCOUNT.
 
326
 Collection of set...() functions for struct samu.
364
327
 ********************************************************************/
365
328
 
366
 
BOOL pdb_set_acct_ctrl (SAM_ACCOUNT *sampass, uint16 acct_ctrl, enum pdb_value_state flag)
 
329
BOOL pdb_set_acct_ctrl(struct samu *sampass, uint32 acct_ctrl, enum pdb_value_state flag)
367
330
{
368
 
        if (!sampass)
369
 
                return False;
370
 
                
371
 
        sampass->private_u.acct_ctrl = acct_ctrl;
372
 
 
 
331
        sampass->acct_ctrl = acct_ctrl;
373
332
        return pdb_set_init_flags(sampass, PDB_ACCTCTRL, flag);
374
333
}
375
334
 
376
 
BOOL pdb_set_logon_time (SAM_ACCOUNT *sampass, time_t mytime, enum pdb_value_state flag)
 
335
BOOL pdb_set_logon_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag)
377
336
{
378
 
        if (!sampass)
379
 
                return False;
380
 
 
381
 
        sampass->private_u.logon_time = mytime;
382
 
 
 
337
        sampass->logon_time = mytime;
383
338
        return pdb_set_init_flags(sampass, PDB_LOGONTIME, flag);
384
339
}
385
340
 
386
 
BOOL pdb_set_logoff_time (SAM_ACCOUNT *sampass, time_t mytime, enum pdb_value_state flag)
 
341
BOOL pdb_set_logoff_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag)
387
342
{
388
 
        if (!sampass)
389
 
                return False;
390
 
 
391
 
        sampass->private_u.logoff_time = mytime;
392
 
 
 
343
        sampass->logoff_time = mytime;
393
344
        return pdb_set_init_flags(sampass, PDB_LOGOFFTIME, flag);
394
345
}
395
346
 
396
 
BOOL pdb_set_kickoff_time (SAM_ACCOUNT *sampass, time_t mytime, enum pdb_value_state flag)
 
347
BOOL pdb_set_kickoff_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag)
397
348
{
398
 
        if (!sampass)
399
 
                return False;
400
 
 
401
 
        sampass->private_u.kickoff_time = mytime;
402
 
 
 
349
        sampass->kickoff_time = mytime;
403
350
        return pdb_set_init_flags(sampass, PDB_KICKOFFTIME, flag);
404
351
}
405
352
 
406
 
BOOL pdb_set_bad_password_time (SAM_ACCOUNT *sampass, time_t mytime, 
407
 
                                enum pdb_value_state flag)
 
353
BOOL pdb_set_bad_password_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag)
408
354
{
409
 
        if (!sampass)
410
 
                return False;
411
 
 
412
 
        sampass->private_u.bad_password_time = mytime;
413
 
 
 
355
        sampass->bad_password_time = mytime;
414
356
        return pdb_set_init_flags(sampass, PDB_BAD_PASSWORD_TIME, flag);
415
357
}
416
358
 
417
 
BOOL pdb_set_pass_can_change_time (SAM_ACCOUNT *sampass, time_t mytime, enum pdb_value_state flag)
 
359
BOOL pdb_set_pass_can_change_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag)
418
360
{
419
 
        if (!sampass)
420
 
                return False;
421
 
 
422
 
        sampass->private_u.pass_can_change_time = mytime;
423
 
 
 
361
        sampass->pass_can_change_time = mytime;
424
362
        return pdb_set_init_flags(sampass, PDB_CANCHANGETIME, flag);
425
363
}
426
364
 
427
 
BOOL pdb_set_pass_must_change_time (SAM_ACCOUNT *sampass, time_t mytime, enum pdb_value_state flag)
 
365
BOOL pdb_set_pass_must_change_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag)
428
366
{
429
 
        if (!sampass)
430
 
                return False;
431
 
 
432
 
        sampass->private_u.pass_must_change_time = mytime;
433
 
 
 
367
        sampass->pass_must_change_time = mytime;
434
368
        return pdb_set_init_flags(sampass, PDB_MUSTCHANGETIME, flag);
435
369
}
436
370
 
437
 
BOOL pdb_set_pass_last_set_time (SAM_ACCOUNT *sampass, time_t mytime, enum pdb_value_state flag)
 
371
BOOL pdb_set_pass_last_set_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag)
438
372
{
439
 
        if (!sampass)
440
 
                return False;
441
 
 
442
 
        sampass->private_u.pass_last_set_time = mytime;
443
 
 
 
373
        sampass->pass_last_set_time = mytime;
444
374
        return pdb_set_init_flags(sampass, PDB_PASSLASTSET, flag);
445
375
}
446
376
 
447
 
BOOL pdb_set_hours_len (SAM_ACCOUNT *sampass, uint32 len, enum pdb_value_state flag)
 
377
BOOL pdb_set_hours_len(struct samu *sampass, uint32 len, enum pdb_value_state flag)
448
378
{
449
 
        if (!sampass)
450
 
                return False;
451
 
 
452
 
        sampass->private_u.hours_len = len;
453
 
 
 
379
        sampass->hours_len = len;
454
380
        return pdb_set_init_flags(sampass, PDB_HOURSLEN, flag);
455
381
}
456
382
 
457
 
BOOL pdb_set_logon_divs (SAM_ACCOUNT *sampass, uint16 hours, enum pdb_value_state flag)
 
383
BOOL pdb_set_logon_divs(struct samu *sampass, uint16 hours, enum pdb_value_state flag)
458
384
{
459
 
        if (!sampass)
460
 
                return False;
461
 
 
462
 
        sampass->private_u.logon_divs = hours;
463
 
 
 
385
        sampass->logon_divs = hours;
464
386
        return pdb_set_init_flags(sampass, PDB_LOGONDIVS, flag);
465
387
}
466
388
 
467
389
/**
468
 
 * Set flags showing what is initalised in the SAM_ACCOUNT
469
 
 * @param sampass the SAM_ACCOUNT in question
 
390
 * Set flags showing what is initalised in the struct samu
 
391
 * @param sampass the struct samu in question
470
392
 * @param flag The *new* flag to be set.  Old flags preserved
471
393
 *             this flag is only added.  
472
394
 **/
473
395
 
474
 
BOOL pdb_set_init_flags (SAM_ACCOUNT *sampass, enum pdb_elements element, enum pdb_value_state value_flag)
 
396
BOOL pdb_set_init_flags(struct samu *sampass, enum pdb_elements element, enum pdb_value_state value_flag)
475
397
{
476
 
        if (!sampass || !sampass->mem_ctx)
477
 
                return False;
478
 
 
479
 
        if (!sampass->private_u.set_flags) {
480
 
                if ((sampass->private_u.set_flags = 
481
 
                        bitmap_talloc(sampass->mem_ctx, 
 
398
        if (!sampass->set_flags) {
 
399
                if ((sampass->set_flags = 
 
400
                        bitmap_talloc(sampass, 
482
401
                                        PDB_COUNT))==NULL) {
483
402
                        DEBUG(0,("bitmap_talloc failed\n"));
484
403
                        return False;
485
404
                }
486
405
        }
487
 
        if (!sampass->private_u.change_flags) {
488
 
                if ((sampass->private_u.change_flags = 
489
 
                        bitmap_talloc(sampass->mem_ctx, 
 
406
        if (!sampass->change_flags) {
 
407
                if ((sampass->change_flags = 
 
408
                        bitmap_talloc(sampass, 
490
409
                                        PDB_COUNT))==NULL) {
491
410
                        DEBUG(0,("bitmap_talloc failed\n"));
492
411
                        return False;
495
414
        
496
415
        switch(value_flag) {
497
416
                case PDB_CHANGED:
498
 
                        if (!bitmap_set(sampass->private_u.change_flags, element)) {
 
417
                        if (!bitmap_set(sampass->change_flags, element)) {
499
418
                                DEBUG(0,("Can't set flag: %d in change_flags.\n",element));
500
419
                                return False;
501
420
                        }
502
 
                        if (!bitmap_set(sampass->private_u.set_flags, element)) {
 
421
                        if (!bitmap_set(sampass->set_flags, element)) {
503
422
                                DEBUG(0,("Can't set flag: %d in set_flags.\n",element));
504
423
                                return False;
505
424
                        }
506
425
                        DEBUG(11, ("element %d -> now CHANGED\n", element)); 
507
426
                        break;
508
427
                case PDB_SET:
509
 
                        if (!bitmap_clear(sampass->private_u.change_flags, element)) {
 
428
                        if (!bitmap_clear(sampass->change_flags, element)) {
510
429
                                DEBUG(0,("Can't set flag: %d in change_flags.\n",element));
511
430
                                return False;
512
431
                        }
513
 
                        if (!bitmap_set(sampass->private_u.set_flags, element)) {
 
432
                        if (!bitmap_set(sampass->set_flags, element)) {
514
433
                                DEBUG(0,("Can't set flag: %d in set_flags.\n",element));
515
434
                                return False;
516
435
                        }
518
437
                        break;
519
438
                case PDB_DEFAULT:
520
439
                default:
521
 
                        if (!bitmap_clear(sampass->private_u.change_flags, element)) {
 
440
                        if (!bitmap_clear(sampass->change_flags, element)) {
522
441
                                DEBUG(0,("Can't set flag: %d in change_flags.\n",element));
523
442
                                return False;
524
443
                        }
525
 
                        if (!bitmap_clear(sampass->private_u.set_flags, element)) {
 
444
                        if (!bitmap_clear(sampass->set_flags, element)) {
526
445
                                DEBUG(0,("Can't set flag: %d in set_flags.\n",element));
527
446
                                return False;
528
447
                        }
533
452
        return True;
534
453
}
535
454
 
536
 
BOOL pdb_set_user_sid (SAM_ACCOUNT *sampass, const DOM_SID *u_sid, enum pdb_value_state flag)
 
455
BOOL pdb_set_user_sid(struct samu *sampass, const DOM_SID *u_sid, enum pdb_value_state flag)
537
456
{
538
 
        if (!sampass || !u_sid)
 
457
        if (!u_sid)
539
458
                return False;
540
459
        
541
 
        sid_copy(&sampass->private_u.user_sid, u_sid);
 
460
        sid_copy(&sampass->user_sid, u_sid);
542
461
 
543
462
        DEBUG(10, ("pdb_set_user_sid: setting user sid %s\n", 
544
 
                    sid_string_static(&sampass->private_u.user_sid)));
 
463
                    sid_string_static(&sampass->user_sid)));
545
464
 
546
465
        return pdb_set_init_flags(sampass, PDB_USERSID, flag);
547
466
}
548
467
 
549
 
BOOL pdb_set_user_sid_from_string (SAM_ACCOUNT *sampass, fstring u_sid, enum pdb_value_state flag)
 
468
BOOL pdb_set_user_sid_from_string(struct samu *sampass, fstring u_sid, enum pdb_value_state flag)
550
469
{
551
470
        DOM_SID new_sid;
552
471
        
553
 
        if (!sampass || !u_sid)
 
472
        if (!u_sid)
554
473
                return False;
555
474
 
556
475
        DEBUG(10, ("pdb_set_user_sid_from_string: setting user sid %s\n",
562
481
        }
563
482
         
564
483
        if (!pdb_set_user_sid(sampass, &new_sid, flag)) {
565
 
                DEBUG(1, ("pdb_set_user_sid_from_string: could not set sid %s on SAM_ACCOUNT!\n", u_sid));
 
484
                DEBUG(1, ("pdb_set_user_sid_from_string: could not set sid %s on struct samu!\n", u_sid));
566
485
                return False;
567
486
        }
568
487
 
569
488
        return True;
570
489
}
571
490
 
572
 
BOOL pdb_set_group_sid (SAM_ACCOUNT *sampass, const DOM_SID *g_sid, enum pdb_value_state flag)
 
491
/********************************************************************
 
492
 We never fill this in from a passdb backend but rather set is 
 
493
 based on the user's primary group membership.  However, the 
 
494
 struct samu* is overloaded and reused in domain memship code 
 
495
 as well and built from the NET_USER_INFO_3 or PAC so we 
 
496
 have to allow the explicitly setting of a group SID here.
 
497
********************************************************************/
 
498
 
 
499
BOOL pdb_set_group_sid(struct samu *sampass, const DOM_SID *g_sid, enum pdb_value_state flag)
573
500
{
574
 
        if (!sampass || !g_sid)
575
 
                return False;
576
 
 
577
 
        sid_copy(&sampass->private_u.group_sid, g_sid);
 
501
        gid_t gid;
 
502
 
 
503
        if (!g_sid)
 
504
                return False;
 
505
 
 
506
        if ( !(sampass->group_sid = TALLOC_P( sampass, DOM_SID )) ) {
 
507
                return False;
 
508
        }
 
509
 
 
510
        /* if we cannot resolve the SID to gid, then just ignore it and 
 
511
           store DOMAIN_USERS as the primary groupSID */
 
512
 
 
513
        if ( sid_to_gid( g_sid, &gid ) ) {
 
514
                sid_copy(sampass->group_sid, g_sid);
 
515
        } else {
 
516
                sid_copy( sampass->group_sid, get_global_sam_sid() );
 
517
                sid_append_rid( sampass->group_sid, DOMAIN_GROUP_RID_USERS );
 
518
        }
578
519
 
579
520
        DEBUG(10, ("pdb_set_group_sid: setting group sid %s\n", 
580
 
                    sid_string_static(&sampass->private_u.group_sid)));
 
521
                sid_string_static(sampass->group_sid)));
581
522
 
582
523
        return pdb_set_init_flags(sampass, PDB_GROUPSID, flag);
583
524
}
584
525
 
585
 
BOOL pdb_set_group_sid_from_string (SAM_ACCOUNT *sampass, fstring g_sid, enum pdb_value_state flag)
586
 
{
587
 
        DOM_SID new_sid;
588
 
        if (!sampass || !g_sid)
589
 
                return False;
590
 
 
591
 
        DEBUG(10, ("pdb_set_group_sid_from_string: setting group sid %s\n",
592
 
                   g_sid));
593
 
 
594
 
        if (!string_to_sid(&new_sid, g_sid)) { 
595
 
                DEBUG(1, ("pdb_set_group_sid_from_string: %s isn't a valid SID!\n", g_sid));
596
 
                return False;
597
 
        }
598
 
         
599
 
        if (!pdb_set_group_sid(sampass, &new_sid, flag)) {
600
 
                DEBUG(1, ("pdb_set_group_sid_from_string: could not set sid %s on SAM_ACCOUNT!\n", g_sid));
601
 
                return False;
602
 
        }
603
 
        return True;
604
 
}
605
 
 
606
526
/*********************************************************************
607
527
 Set the user's UNIX name.
608
528
 ********************************************************************/
609
529
 
610
 
BOOL pdb_set_username(SAM_ACCOUNT *sampass, const char *username, enum pdb_value_state flag)
 
530
BOOL pdb_set_username(struct samu *sampass, const char *username, enum pdb_value_state flag)
611
531
{
612
 
        if (!sampass)
613
 
                return False;
614
 
 
615
532
        if (username) { 
616
533
                DEBUG(10, ("pdb_set_username: setting username %s, was %s\n", username,
617
 
                        (sampass->private_u.username)?(sampass->private_u.username):"NULL"));
618
 
 
619
 
                sampass->private_u.username = talloc_strdup(sampass->mem_ctx, username);
620
 
 
621
 
                if (!sampass->private_u.username) {
 
534
                        (sampass->username)?(sampass->username):"NULL"));
 
535
 
 
536
                sampass->username = talloc_strdup(sampass, username);
 
537
 
 
538
                if (!sampass->username) {
622
539
                        DEBUG(0, ("pdb_set_username: talloc_strdup() failed!\n"));
623
540
                        return False;
624
541
                }
625
 
 
626
542
        } else {
627
 
                sampass->private_u.username = PDB_NOT_QUITE_NULL;
 
543
                sampass->username = PDB_NOT_QUITE_NULL;
628
544
        }
629
545
        
630
546
        return pdb_set_init_flags(sampass, PDB_USERNAME, flag);
634
550
 Set the domain name.
635
551
 ********************************************************************/
636
552
 
637
 
BOOL pdb_set_domain(SAM_ACCOUNT *sampass, const char *domain, enum pdb_value_state flag)
 
553
BOOL pdb_set_domain(struct samu *sampass, const char *domain, enum pdb_value_state flag)
638
554
{
639
 
        if (!sampass)
640
 
                return False;
641
 
 
642
555
        if (domain) { 
643
556
                DEBUG(10, ("pdb_set_domain: setting domain %s, was %s\n", domain,
644
 
                        (sampass->private_u.domain)?(sampass->private_u.domain):"NULL"));
645
 
 
646
 
                sampass->private_u.domain = talloc_strdup(sampass->mem_ctx, domain);
647
 
 
648
 
                if (!sampass->private_u.domain) {
 
557
                        (sampass->domain)?(sampass->domain):"NULL"));
 
558
 
 
559
                sampass->domain = talloc_strdup(sampass, domain);
 
560
 
 
561
                if (!sampass->domain) {
649
562
                        DEBUG(0, ("pdb_set_domain: talloc_strdup() failed!\n"));
650
563
                        return False;
651
564
                }
652
 
 
653
565
        } else {
654
 
                sampass->private_u.domain = PDB_NOT_QUITE_NULL;
 
566
                sampass->domain = PDB_NOT_QUITE_NULL;
655
567
        }
656
568
 
657
569
        return pdb_set_init_flags(sampass, PDB_DOMAIN, flag);
661
573
 Set the user's NT name.
662
574
 ********************************************************************/
663
575
 
664
 
BOOL pdb_set_nt_username(SAM_ACCOUNT *sampass, const char *nt_username, enum pdb_value_state flag)
 
576
BOOL pdb_set_nt_username(struct samu *sampass, const char *nt_username, enum pdb_value_state flag)
665
577
{
666
 
        if (!sampass)
667
 
                return False;
668
 
 
669
578
        if (nt_username) { 
670
579
                DEBUG(10, ("pdb_set_nt_username: setting nt username %s, was %s\n", nt_username,
671
 
                        (sampass->private_u.nt_username)?(sampass->private_u.nt_username):"NULL"));
 
580
                        (sampass->nt_username)?(sampass->nt_username):"NULL"));
672
581
 
673
 
                sampass->private_u.nt_username = talloc_strdup(sampass->mem_ctx, nt_username);
 
582
                sampass->nt_username = talloc_strdup(sampass, nt_username);
674
583
                
675
 
                if (!sampass->private_u.nt_username) {
 
584
                if (!sampass->nt_username) {
676
585
                        DEBUG(0, ("pdb_set_nt_username: talloc_strdup() failed!\n"));
677
586
                        return False;
678
587
                }
679
 
 
680
588
        } else {
681
 
                sampass->private_u.nt_username = PDB_NOT_QUITE_NULL;
 
589
                sampass->nt_username = PDB_NOT_QUITE_NULL;
682
590
        }
683
591
 
684
592
        return pdb_set_init_flags(sampass, PDB_NTUSERNAME, flag);
688
596
 Set the user's full name.
689
597
 ********************************************************************/
690
598
 
691
 
BOOL pdb_set_fullname(SAM_ACCOUNT *sampass, const char *full_name, enum pdb_value_state flag)
 
599
BOOL pdb_set_fullname(struct samu *sampass, const char *full_name, enum pdb_value_state flag)
692
600
{
693
 
        if (!sampass)
694
 
                return False;
695
 
 
696
601
        if (full_name) { 
697
602
                DEBUG(10, ("pdb_set_full_name: setting full name %s, was %s\n", full_name,
698
 
                        (sampass->private_u.full_name)?(sampass->private_u.full_name):"NULL"));
 
603
                        (sampass->full_name)?(sampass->full_name):"NULL"));
699
604
        
700
 
                sampass->private_u.full_name = talloc_strdup(sampass->mem_ctx, full_name);
 
605
                sampass->full_name = talloc_strdup(sampass, full_name);
701
606
 
702
 
                if (!sampass->private_u.full_name) {
 
607
                if (!sampass->full_name) {
703
608
                        DEBUG(0, ("pdb_set_fullname: talloc_strdup() failed!\n"));
704
609
                        return False;
705
610
                }
706
 
 
707
611
        } else {
708
 
                sampass->private_u.full_name = PDB_NOT_QUITE_NULL;
 
612
                sampass->full_name = PDB_NOT_QUITE_NULL;
709
613
        }
710
614
 
711
615
        return pdb_set_init_flags(sampass, PDB_FULLNAME, flag);
715
619
 Set the user's logon script.
716
620
 ********************************************************************/
717
621
 
718
 
BOOL pdb_set_logon_script(SAM_ACCOUNT *sampass, const char *logon_script, enum pdb_value_state flag)
 
622
BOOL pdb_set_logon_script(struct samu *sampass, const char *logon_script, enum pdb_value_state flag)
719
623
{
720
 
        if (!sampass)
721
 
                return False;
722
 
 
723
624
        if (logon_script) { 
724
625
                DEBUG(10, ("pdb_set_logon_script: setting logon script %s, was %s\n", logon_script,
725
 
                        (sampass->private_u.logon_script)?(sampass->private_u.logon_script):"NULL"));
 
626
                        (sampass->logon_script)?(sampass->logon_script):"NULL"));
726
627
 
727
 
                sampass->private_u.logon_script = talloc_strdup(sampass->mem_ctx, logon_script);
 
628
                sampass->logon_script = talloc_strdup(sampass, logon_script);
728
629
 
729
 
                if (!sampass->private_u.logon_script) {
 
630
                if (!sampass->logon_script) {
730
631
                        DEBUG(0, ("pdb_set_logon_script: talloc_strdup() failed!\n"));
731
632
                        return False;
732
633
                }
733
 
 
734
634
        } else {
735
 
                sampass->private_u.logon_script = PDB_NOT_QUITE_NULL;
 
635
                sampass->logon_script = PDB_NOT_QUITE_NULL;
736
636
        }
737
637
        
738
638
        return pdb_set_init_flags(sampass, PDB_LOGONSCRIPT, flag);
742
642
 Set the user's profile path.
743
643
 ********************************************************************/
744
644
 
745
 
BOOL pdb_set_profile_path (SAM_ACCOUNT *sampass, const char *profile_path, enum pdb_value_state flag)
 
645
BOOL pdb_set_profile_path(struct samu *sampass, const char *profile_path, enum pdb_value_state flag)
746
646
{
747
 
        if (!sampass)
748
 
                return False;
749
 
 
750
647
        if (profile_path) { 
751
648
                DEBUG(10, ("pdb_set_profile_path: setting profile path %s, was %s\n", profile_path,
752
 
                        (sampass->private_u.profile_path)?(sampass->private_u.profile_path):"NULL"));
 
649
                        (sampass->profile_path)?(sampass->profile_path):"NULL"));
753
650
 
754
 
                sampass->private_u.profile_path = talloc_strdup(sampass->mem_ctx, profile_path);
 
651
                sampass->profile_path = talloc_strdup(sampass, profile_path);
755
652
                
756
 
                if (!sampass->private_u.profile_path) {
 
653
                if (!sampass->profile_path) {
757
654
                        DEBUG(0, ("pdb_set_profile_path: talloc_strdup() failed!\n"));
758
655
                        return False;
759
656
                }
760
 
 
761
657
        } else {
762
 
                sampass->private_u.profile_path = PDB_NOT_QUITE_NULL;
 
658
                sampass->profile_path = PDB_NOT_QUITE_NULL;
763
659
        }
764
660
 
765
661
        return pdb_set_init_flags(sampass, PDB_PROFILE, flag);
769
665
 Set the user's directory drive.
770
666
 ********************************************************************/
771
667
 
772
 
BOOL pdb_set_dir_drive (SAM_ACCOUNT *sampass, const char *dir_drive, enum pdb_value_state flag)
 
668
BOOL pdb_set_dir_drive(struct samu *sampass, const char *dir_drive, enum pdb_value_state flag)
773
669
{
774
 
        if (!sampass)
775
 
                return False;
776
 
 
777
670
        if (dir_drive) { 
778
671
                DEBUG(10, ("pdb_set_dir_drive: setting dir drive %s, was %s\n", dir_drive,
779
 
                        (sampass->private_u.dir_drive)?(sampass->private_u.dir_drive):"NULL"));
 
672
                        (sampass->dir_drive)?(sampass->dir_drive):"NULL"));
780
673
 
781
 
                sampass->private_u.dir_drive = talloc_strdup(sampass->mem_ctx, dir_drive);
 
674
                sampass->dir_drive = talloc_strdup(sampass, dir_drive);
782
675
                
783
 
                if (!sampass->private_u.dir_drive) {
 
676
                if (!sampass->dir_drive) {
784
677
                        DEBUG(0, ("pdb_set_dir_drive: talloc_strdup() failed!\n"));
785
678
                        return False;
786
679
                }
787
680
 
788
681
        } else {
789
 
                sampass->private_u.dir_drive = PDB_NOT_QUITE_NULL;
 
682
                sampass->dir_drive = PDB_NOT_QUITE_NULL;
790
683
        }
791
684
        
792
685
        return pdb_set_init_flags(sampass, PDB_DRIVE, flag);
796
689
 Set the user's home directory.
797
690
 ********************************************************************/
798
691
 
799
 
BOOL pdb_set_homedir (SAM_ACCOUNT *sampass, const char *home_dir, enum pdb_value_state flag)
 
692
BOOL pdb_set_homedir(struct samu *sampass, const char *home_dir, enum pdb_value_state flag)
800
693
{
801
 
        if (!sampass)
802
 
                return False;
803
 
 
804
694
        if (home_dir) { 
805
695
                DEBUG(10, ("pdb_set_homedir: setting home dir %s, was %s\n", home_dir,
806
 
                        (sampass->private_u.home_dir)?(sampass->private_u.home_dir):"NULL"));
 
696
                        (sampass->home_dir)?(sampass->home_dir):"NULL"));
807
697
 
808
 
                sampass->private_u.home_dir = talloc_strdup(sampass->mem_ctx, home_dir);
 
698
                sampass->home_dir = talloc_strdup(sampass, home_dir);
809
699
                
810
 
                if (!sampass->private_u.home_dir) {
 
700
                if (!sampass->home_dir) {
811
701
                        DEBUG(0, ("pdb_set_home_dir: talloc_strdup() failed!\n"));
812
702
                        return False;
813
703
                }
814
 
 
815
704
        } else {
816
 
                sampass->private_u.home_dir = PDB_NOT_QUITE_NULL;
 
705
                sampass->home_dir = PDB_NOT_QUITE_NULL;
817
706
        }
818
707
 
819
708
        return pdb_set_init_flags(sampass, PDB_SMBHOME, flag);
820
709
}
821
710
 
822
711
/*********************************************************************
823
 
 Set the user's unix home directory.
824
 
 ********************************************************************/
825
 
 
826
 
BOOL pdb_set_unix_homedir (SAM_ACCOUNT *sampass, const char *unix_home_dir, enum pdb_value_state flag)
827
 
{
828
 
        if (!sampass)
829
 
                return False;
830
 
 
831
 
        if (unix_home_dir) { 
832
 
                DEBUG(10, ("pdb_set_unix_homedir: setting home dir %s, was %s\n", unix_home_dir,
833
 
                        (sampass->private_u.unix_home_dir)?(sampass->private_u.unix_home_dir):"NULL"));
834
 
 
835
 
                sampass->private_u.unix_home_dir = talloc_strdup(sampass->mem_ctx, 
836
 
                                                          unix_home_dir);
837
 
                
838
 
                if (!sampass->private_u.unix_home_dir) {
839
 
                        DEBUG(0, ("pdb_set_unix_home_dir: talloc_strdup() failed!\n"));
840
 
                        return False;
841
 
                }
842
 
 
843
 
        } else {
844
 
                sampass->private_u.unix_home_dir = PDB_NOT_QUITE_NULL;
845
 
        }
846
 
 
847
 
        return pdb_set_init_flags(sampass, PDB_UNIXHOMEDIR, flag);
848
 
}
849
 
 
850
 
/*********************************************************************
851
712
 Set the user's account description.
852
713
 ********************************************************************/
853
714
 
854
 
BOOL pdb_set_acct_desc (SAM_ACCOUNT *sampass, const char *acct_desc, enum pdb_value_state flag)
 
715
BOOL pdb_set_acct_desc(struct samu *sampass, const char *acct_desc, enum pdb_value_state flag)
855
716
{
856
 
        if (!sampass)
857
 
                return False;
858
 
 
859
717
        if (acct_desc) { 
860
 
                sampass->private_u.acct_desc = talloc_strdup(sampass->mem_ctx, acct_desc);
 
718
                sampass->acct_desc = talloc_strdup(sampass, acct_desc);
861
719
 
862
 
                if (!sampass->private_u.acct_desc) {
 
720
                if (!sampass->acct_desc) {
863
721
                        DEBUG(0, ("pdb_set_acct_desc: talloc_strdup() failed!\n"));
864
722
                        return False;
865
723
                }
866
 
 
867
724
        } else {
868
 
                sampass->private_u.acct_desc = PDB_NOT_QUITE_NULL;
 
725
                sampass->acct_desc = PDB_NOT_QUITE_NULL;
869
726
        }
870
727
 
871
728
        return pdb_set_init_flags(sampass, PDB_ACCTDESC, flag);
875
732
 Set the user's workstation allowed list.
876
733
 ********************************************************************/
877
734
 
878
 
BOOL pdb_set_workstations (SAM_ACCOUNT *sampass, const char *workstations, enum pdb_value_state flag)
 
735
BOOL pdb_set_workstations(struct samu *sampass, const char *workstations, enum pdb_value_state flag)
879
736
{
880
 
        if (!sampass)
881
 
                return False;
882
 
 
883
737
        if (workstations) { 
884
738
                DEBUG(10, ("pdb_set_workstations: setting workstations %s, was %s\n", workstations,
885
 
                        (sampass->private_u.workstations)?(sampass->private_u.workstations):"NULL"));
 
739
                        (sampass->workstations)?(sampass->workstations):"NULL"));
886
740
 
887
 
                sampass->private_u.workstations = talloc_strdup(sampass->mem_ctx, workstations);
 
741
                sampass->workstations = talloc_strdup(sampass, workstations);
888
742
 
889
 
                if (!sampass->private_u.workstations) {
 
743
                if (!sampass->workstations) {
890
744
                        DEBUG(0, ("pdb_set_workstations: talloc_strdup() failed!\n"));
891
745
                        return False;
892
746
                }
893
 
 
894
747
        } else {
895
 
                sampass->private_u.workstations = PDB_NOT_QUITE_NULL;
 
748
                sampass->workstations = PDB_NOT_QUITE_NULL;
896
749
        }
897
750
 
898
751
        return pdb_set_init_flags(sampass, PDB_WORKSTATIONS, flag);
902
755
 Set the user's 'unknown_str', whatever the heck this actually is...
903
756
 ********************************************************************/
904
757
 
905
 
BOOL pdb_set_unknown_str (SAM_ACCOUNT *sampass, const char *unknown_str, enum pdb_value_state flag)
 
758
BOOL pdb_set_unknown_str(struct samu *sampass, const char *unknown_str, enum pdb_value_state flag)
906
759
{
907
 
        if (!sampass)
908
 
                return False;
909
 
 
910
760
        if (unknown_str) { 
911
 
                sampass->private_u.unknown_str = talloc_strdup(sampass->mem_ctx, unknown_str);
 
761
                sampass->unknown_str = talloc_strdup(sampass, unknown_str);
912
762
                
913
 
                if (!sampass->private_u.unknown_str) {
 
763
                if (!sampass->unknown_str) {
914
764
                        DEBUG(0, ("pdb_set_unknown_str: talloc_strdup() failed!\n"));
915
765
                        return False;
916
766
                }
917
 
 
918
767
        } else {
919
 
                sampass->private_u.unknown_str = PDB_NOT_QUITE_NULL;
 
768
                sampass->unknown_str = PDB_NOT_QUITE_NULL;
920
769
        }
921
770
 
922
771
        return pdb_set_init_flags(sampass, PDB_UNKNOWNSTR, flag);
926
775
 Set the user's dial string.
927
776
 ********************************************************************/
928
777
 
929
 
BOOL pdb_set_munged_dial (SAM_ACCOUNT *sampass, const char *munged_dial, enum pdb_value_state flag)
 
778
BOOL pdb_set_munged_dial(struct samu *sampass, const char *munged_dial, enum pdb_value_state flag)
930
779
{
931
 
        if (!sampass)
932
 
                return False;
933
 
 
934
780
        if (munged_dial) { 
935
 
                sampass->private_u.munged_dial = talloc_strdup(sampass->mem_ctx, munged_dial);
 
781
                sampass->munged_dial = talloc_strdup(sampass, munged_dial);
936
782
                
937
 
                if (!sampass->private_u.munged_dial) {
 
783
                if (!sampass->munged_dial) {
938
784
                        DEBUG(0, ("pdb_set_munged_dial: talloc_strdup() failed!\n"));
939
785
                        return False;
940
786
                }
941
 
 
942
787
        } else {
943
 
                sampass->private_u.munged_dial = PDB_NOT_QUITE_NULL;
 
788
                sampass->munged_dial = PDB_NOT_QUITE_NULL;
944
789
        }
945
790
 
946
791
        return pdb_set_init_flags(sampass, PDB_MUNGEDDIAL, flag);
950
795
 Set the user's NT hash.
951
796
 ********************************************************************/
952
797
 
953
 
BOOL pdb_set_nt_passwd (SAM_ACCOUNT *sampass, const uint8 pwd[NT_HASH_LEN], enum pdb_value_state flag)
 
798
BOOL pdb_set_nt_passwd(struct samu *sampass, const uint8 pwd[NT_HASH_LEN], enum pdb_value_state flag)
954
799
{
955
 
        if (!sampass)
956
 
                return False;
957
 
 
958
 
        data_blob_clear_free(&sampass->private_u.nt_pw);
 
800
        data_blob_clear_free(&sampass->nt_pw);
959
801
        
960
802
       if (pwd) {
961
 
               sampass->private_u.nt_pw = data_blob(pwd, NT_HASH_LEN);
 
803
               sampass->nt_pw =
 
804
                       data_blob_talloc(sampass, pwd, NT_HASH_LEN);
962
805
       } else {
963
 
               sampass->private_u.nt_pw = data_blob(NULL, 0);
 
806
               sampass->nt_pw = data_blob(NULL, 0);
964
807
       }
965
808
 
966
809
        return pdb_set_init_flags(sampass, PDB_NTPASSWD, flag);
970
813
 Set the user's LM hash.
971
814
 ********************************************************************/
972
815
 
973
 
BOOL pdb_set_lanman_passwd (SAM_ACCOUNT *sampass, const uint8 pwd[LM_HASH_LEN], enum pdb_value_state flag)
 
816
BOOL pdb_set_lanman_passwd(struct samu *sampass, const uint8 pwd[LM_HASH_LEN], enum pdb_value_state flag)
974
817
{
975
 
        if (!sampass)
976
 
                return False;
977
 
 
978
 
        data_blob_clear_free(&sampass->private_u.lm_pw);
 
818
        data_blob_clear_free(&sampass->lm_pw);
979
819
        
980
 
       if (pwd) {
981
 
               sampass->private_u.lm_pw = data_blob(pwd, LM_HASH_LEN);
982
 
       } else {
983
 
               sampass->private_u.lm_pw = data_blob(NULL, 0);
984
 
       }
 
820
        /* on keep the password if we are allowing LANMAN authentication */
 
821
 
 
822
        if (pwd && lp_lanman_auth() ) {
 
823
                sampass->lm_pw = data_blob_talloc(sampass, pwd, LM_HASH_LEN);
 
824
        } else {
 
825
                sampass->lm_pw = data_blob(NULL, 0);
 
826
        }
985
827
 
986
828
        return pdb_set_init_flags(sampass, PDB_LMPASSWD, flag);
987
829
}
993
835
 in pwd.
994
836
********************************************************************/
995
837
 
996
 
BOOL pdb_set_pw_history (SAM_ACCOUNT *sampass, const uint8 *pwd, uint32 historyLen, enum pdb_value_state flag)
 
838
BOOL pdb_set_pw_history(struct samu *sampass, const uint8 *pwd, uint32 historyLen, enum pdb_value_state flag)
997
839
{
998
 
        if (!sampass)
999
 
                return False;
1000
 
 
1001
840
        if (historyLen && pwd){
1002
 
                sampass->private_u.nt_pw_his = data_blob_talloc(sampass->mem_ctx,
 
841
                sampass->nt_pw_his = data_blob_talloc(sampass,
1003
842
                                                pwd, historyLen*PW_HISTORY_ENTRY_LEN);
1004
 
                if (!sampass->private_u.nt_pw_his.length) {
 
843
                if (!sampass->nt_pw_his.length) {
1005
844
                        DEBUG(0, ("pdb_set_pw_history: data_blob_talloc() failed!\n"));
1006
845
                        return False;
1007
846
                }
1008
847
        } else {
1009
 
                sampass->private_u.nt_pw_his = data_blob_talloc(sampass->mem_ctx, NULL, 0);
 
848
                sampass->nt_pw_his = data_blob_talloc(sampass, NULL, 0);
1010
849
        }
1011
850
 
1012
851
        return pdb_set_init_flags(sampass, PDB_PWHISTORY, flag);
1017
856
 below)
1018
857
 ********************************************************************/
1019
858
 
1020
 
BOOL pdb_set_plaintext_pw_only (SAM_ACCOUNT *sampass, const char *password, enum pdb_value_state flag)
 
859
BOOL pdb_set_plaintext_pw_only(struct samu *sampass, const char *password, enum pdb_value_state flag)
1021
860
{
1022
 
        if (!sampass)
1023
 
                return False;
1024
 
 
1025
861
        if (password) { 
1026
 
                if (sampass->private_u.plaintext_pw!=NULL) 
1027
 
                        memset(sampass->private_u.plaintext_pw,'\0',strlen(sampass->private_u.plaintext_pw)+1);
 
862
                if (sampass->plaintext_pw!=NULL) 
 
863
                        memset(sampass->plaintext_pw,'\0',strlen(sampass->plaintext_pw)+1);
1028
864
 
1029
 
                sampass->private_u.plaintext_pw = talloc_strdup(sampass->mem_ctx, password);
 
865
                sampass->plaintext_pw = talloc_strdup(sampass, password);
1030
866
                
1031
 
                if (!sampass->private_u.plaintext_pw) {
 
867
                if (!sampass->plaintext_pw) {
1032
868
                        DEBUG(0, ("pdb_set_unknown_str: talloc_strdup() failed!\n"));
1033
869
                        return False;
1034
870
                }
1035
 
 
1036
871
        } else {
1037
 
                sampass->private_u.plaintext_pw = NULL;
 
872
                sampass->plaintext_pw = NULL;
1038
873
        }
1039
874
 
1040
875
        return pdb_set_init_flags(sampass, PDB_PLAINTEXT_PW, flag);
1041
876
}
1042
877
 
1043
 
BOOL pdb_set_bad_password_count(SAM_ACCOUNT *sampass, uint16 bad_password_count, enum pdb_value_state flag)
 
878
BOOL pdb_set_bad_password_count(struct samu *sampass, uint16 bad_password_count, enum pdb_value_state flag)
1044
879
{
1045
 
        if (!sampass)
1046
 
                return False;
1047
 
 
1048
 
        sampass->private_u.bad_password_count = bad_password_count;
1049
 
 
 
880
        sampass->bad_password_count = bad_password_count;
1050
881
        return pdb_set_init_flags(sampass, PDB_BAD_PASSWORD_COUNT, flag);
1051
882
}
1052
883
 
1053
 
BOOL pdb_set_logon_count(SAM_ACCOUNT *sampass, uint16 logon_count, enum pdb_value_state flag)
 
884
BOOL pdb_set_logon_count(struct samu *sampass, uint16 logon_count, enum pdb_value_state flag)
1054
885
{
1055
 
        if (!sampass)
1056
 
                return False;
1057
 
 
1058
 
        sampass->private_u.logon_count = logon_count;
1059
 
 
 
886
        sampass->logon_count = logon_count;
1060
887
        return pdb_set_init_flags(sampass, PDB_LOGON_COUNT, flag);
1061
888
}
1062
889
 
1063
 
BOOL pdb_set_unknown_6 (SAM_ACCOUNT *sampass, uint32 unkn, enum pdb_value_state flag)
 
890
BOOL pdb_set_unknown_6(struct samu *sampass, uint32 unkn, enum pdb_value_state flag)
1064
891
{
1065
 
        if (!sampass)
1066
 
                return False;
1067
 
 
1068
 
        sampass->private_u.unknown_6 = unkn;
1069
 
 
 
892
        sampass->unknown_6 = unkn;
1070
893
        return pdb_set_init_flags(sampass, PDB_UNKNOWN6, flag);
1071
894
}
1072
895
 
1073
 
BOOL pdb_set_hours (SAM_ACCOUNT *sampass, const uint8 *hours, enum pdb_value_state flag)
 
896
BOOL pdb_set_hours(struct samu *sampass, const uint8 *hours, enum pdb_value_state flag)
1074
897
{
1075
 
        if (!sampass)
1076
 
                return False;
1077
 
 
1078
898
        if (!hours) {
1079
 
                memset ((char *)sampass->private_u.hours, 0, MAX_HOURS_LEN);
1080
 
                return True;
 
899
                memset ((char *)sampass->hours, 0, MAX_HOURS_LEN);
 
900
        } else {
 
901
                memcpy (sampass->hours, hours, MAX_HOURS_LEN);
1081
902
        }
1082
 
        
1083
 
        memcpy (sampass->private_u.hours, hours, MAX_HOURS_LEN);
1084
903
 
1085
904
        return pdb_set_init_flags(sampass, PDB_HOURS, flag);
1086
905
}
1087
906
 
1088
 
BOOL pdb_set_backend_private_data (SAM_ACCOUNT *sampass, void *private_data, 
 
907
BOOL pdb_set_backend_private_data(struct samu *sampass, void *private_data, 
1089
908
                                   void (*free_fn)(void **), 
1090
909
                                   const struct pdb_methods *my_methods, 
1091
910
                                   enum pdb_value_state flag)
1092
911
{
1093
 
        if (!sampass)
1094
 
                return False;
1095
 
 
1096
 
        if (sampass->private_u.backend_private_data && sampass->private_u.backend_private_data_free_fn) {
1097
 
                sampass->private_u.backend_private_data_free_fn(&sampass->private_u.backend_private_data);
 
912
        if (sampass->backend_private_data &&
 
913
            sampass->backend_private_data_free_fn) {
 
914
                sampass->backend_private_data_free_fn(
 
915
                        &sampass->backend_private_data);
1098
916
        }
1099
917
 
1100
 
        sampass->private_u.backend_private_data = private_data;
1101
 
        sampass->private_u.backend_private_data_free_fn = free_fn;
1102
 
        sampass->private_u.backend_private_methods = my_methods;
 
918
        sampass->backend_private_data = private_data;
 
919
        sampass->backend_private_data_free_fn = free_fn;
 
920
        sampass->backend_private_methods = my_methods;
1103
921
 
1104
922
        return pdb_set_init_flags(sampass, PDB_BACKEND_PRIVATE_DATA, flag);
1105
923
}
1112
930
 password change.
1113
931
 ********************************************************************/
1114
932
 
1115
 
BOOL pdb_set_pass_changed_now (SAM_ACCOUNT *sampass)
 
933
BOOL pdb_set_pass_changed_now(struct samu *sampass)
1116
934
{
1117
935
        uint32 expire;
1118
936
        uint32 min_age;
1119
937
 
1120
 
        if (!sampass)
1121
 
                return False;
1122
 
        
1123
938
        if (!pdb_set_pass_last_set_time (sampass, time(NULL), PDB_CHANGED))
1124
939
                return False;
1125
940
 
1152
967
 Also sets the last change time to NOW.
1153
968
 ********************************************************************/
1154
969
 
1155
 
BOOL pdb_set_plaintext_passwd (SAM_ACCOUNT *sampass, const char *plaintext)
 
970
BOOL pdb_set_plaintext_passwd(struct samu *sampass, const char *plaintext)
1156
971
{
1157
972
        uchar new_lanman_p16[LM_HASH_LEN];
1158
973
        uchar new_nt_p16[NT_HASH_LEN];
1159
974
 
1160
 
        if (!sampass || !plaintext)
 
975
        if (!plaintext)
1161
976
                return False;
1162
977
 
1163
978
        /* Calculate the MD4 hash (NT compatible) of the password */
1194
1009
                        uint32 current_history_len;
1195
1010
                        /* We need to make sure we don't have a race condition here - the
1196
1011
                           account policy history length can change between when the pw_history
1197
 
                           was first loaded into the SAM_ACCOUNT struct and now.... JRA. */
 
1012
                           was first loaded into the struct samu struct and now.... JRA. */
1198
1013
                        pwhistory = (uchar *)pdb_get_pw_history(sampass, &current_history_len);
1199
1014
 
1200
1015
                        if (current_history_len != pwHistLen) {
1201
 
                                /* After closing and reopening SAM_ACCOUNT the history
 
1016
                                /* After closing and reopening struct samu the history
1202
1017
                                        values will sync up. We can't do this here. */
1203
1018
 
1204
1019
                                /* current_history_len > pwHistLen is not a problem - we
1206
1021
 
1207
1022
                                if (current_history_len < pwHistLen) {
1208
1023
                                        /* Ensure we have space for the needed history. */
1209
 
                                        uchar *new_history = TALLOC(sampass->mem_ctx,
 
1024
                                        uchar *new_history = TALLOC(sampass,
1210
1025
                                                                pwHistLen*PW_HISTORY_ENTRY_LEN);
 
1026
                                        if (!new_history) {
 
1027
                                                return False;
 
1028
                                        }
 
1029
 
1211
1030
                                        /* And copy it into the new buffer. */
1212
1031
                                        if (current_history_len) {
1213
1032
                                                memcpy(new_history, pwhistory,
1247
1066
}
1248
1067
 
1249
1068
/* check for any PDB_SET/CHANGED field and fill the appropriate mask bit */
1250
 
uint32 pdb_build_fields_present (SAM_ACCOUNT *sampass)
 
1069
uint32 pdb_build_fields_present(struct samu *sampass)
1251
1070
{
1252
1071
        /* value set to all for testing */
1253
1072
        return 0x00ffffff;