Changeset 745 for trunk/server/source3/passdb/pdb_smbpasswd.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source3/passdb/pdb_smbpasswd.c
r596 r745 22 22 23 23 #include "includes.h" 24 #include "passdb.h" 25 #include "system/passwd.h" 26 #include "system/filesys.h" 27 #include "../librpc/gen_ndr/samr.h" 28 #include "../libcli/security/security.h" 24 29 25 30 #undef DBGC_CLASS … … 31 36 stored by an smbpasswd entry 32 37 */ 33 38 34 39 struct smb_passwd 35 40 { … … 40 45 const unsigned char *smb_nt_passwd; /* Null if no password */ 41 46 42 uint16 acct_ctrl; /* account info (ACB_xxxx bit-mask) */47 uint16_t acct_ctrl; /* account info (ACB_xxxx bit-mask) */ 43 48 time_t pass_last_set_time; /* password last set time */ 44 49 }; … … 48 53 /* used for maintain locks on the smbpasswd file */ 49 54 int pw_file_lock_depth; 50 55 51 56 /* Global File pointer */ 52 57 FILE *pw_file; 53 58 54 59 /* formerly static variables */ 55 60 struct smb_passwd pw_buf; … … 70 75 ****************************************************************/ 71 76 72 static void gotalarm_sig( void)77 static void gotalarm_sig(int signum) 73 78 { 74 79 gotalarm = 1; … … 87 92 88 93 gotalarm = 0; 89 oldsig_handler = CatchSignal(SIGALRM, SIGNAL_CASTgotalarm_sig);94 oldsig_handler = CatchSignal(SIGALRM, gotalarm_sig); 90 95 91 96 lock.l_type = type; … … 99 104 ret = fcntl(fd, SMB_F_SETLKW, &lock); 100 105 alarm(0); 101 CatchSignal(SIGALRM, SIGNAL_CASToldsig_handler);106 CatchSignal(SIGALRM, oldsig_handler); 102 107 103 108 if (gotalarm && ret == -1) { … … 169 174 return; 170 175 ZERO_STRUCTP (user); 171 176 172 177 user->pass_last_set_time = (time_t)0; 173 178 } … … 224 229 break; 225 230 } 226 } 227 231 default: 232 DEBUG(10, ("Invalid open mode: %d\n", type)); 233 return NULL; 234 } 235 228 236 for(race_loop = 0; race_loop < 5; race_loop++) { 229 237 DEBUG(10, ("startsmbfilepwent_internal: opening file %s\n", pfile)); … … 621 629 slprintf((char *)p, new_entry_length - 1 - (p - new_entry), "%s:LCT-%08X:\n", 622 630 pdb_encode_acct_ctrl(newpwd->acct_ctrl, NEW_PW_FORMAT_SPACE_PADDED_LEN), 623 (uint32 )newpwd->pass_last_set_time);631 (uint32_t)newpwd->pass_last_set_time); 624 632 625 633 return new_entry; … … 1010 1018 sizeof(ascii_p16)-(strlen(ascii_p16)+1), 1011 1019 "%s:LCT-%08X:", 1012 encode_bits, (uint32 )pwd->pass_last_set_time );1020 encode_bits, (uint32_t)pwd->pass_last_set_time ); 1013 1021 wr_len = strlen(ascii_p16); 1014 1022 } … … 1174 1182 * Do an atomic rename - then release the locks. 1175 1183 */ 1184 1176 1185 #ifdef __OS2__ 1177 1186 endsmbfilepwent(fp, &smbpasswd_state->pw_file_lock_depth); 1178 1187 endsmbfilepwent(fp_write,&pfile2_lockdepth); 1179 1188 #endif 1180 1181 1189 if(rename(pfile2,pfile) != 0) { 1182 1190 unlink(pfile2); … … 1198 1206 static bool build_smb_pass (struct smb_passwd *smb_pw, const struct samu *sampass) 1199 1207 { 1200 uint32 rid;1208 uint32_t rid; 1201 1209 1202 1210 if (sampass == NULL) … … 1206 1214 if (!IS_SAM_DEFAULT(sampass, PDB_USERSID)) { 1207 1215 rid = pdb_get_user_rid(sampass); 1208 1216 1209 1217 /* If the user specified a RID, make sure its able to be both stored and retreived */ 1210 if (rid == DOMAIN_ USER_RID_GUEST) {1218 if (rid == DOMAIN_RID_GUEST) { 1211 1219 struct passwd *passwd = Get_Pwnam_alloc(NULL, lp_guestaccount()); 1212 1220 if (!passwd) { 1213 DEBUG(0, ("Could not find guest account via getpwnam()! (%s)\n", lp_guestaccount()));1221 DEBUG(0, ("Could not find guest account via Get_Pwnam_alloc()! (%s)\n", lp_guestaccount())); 1214 1222 return False; 1215 1223 } … … 1243 1251 { 1244 1252 struct passwd *pwfile; 1245 1253 1246 1254 if ( !sam_pass ) { 1247 1255 DEBUG(5,("build_sam_account: struct samu is NULL\n")); … … 1256 1264 return False; 1257 1265 } 1258 1266 1259 1267 if ( !NT_STATUS_IS_OK( samu_set_unix(sam_pass, pwfile )) ) 1260 1268 return False; 1261 1269 1262 1270 TALLOC_FREE(pwfile); 1263 1271 1264 1272 /* set remaining fields */ 1265 1273 1266 1274 if (!pdb_set_nt_passwd (sam_pass, pw_buf->smb_nt_passwd, PDB_SET)) 1267 1275 return False; … … 1271 1279 pdb_set_pass_last_set_time (sam_pass, pw_buf->pass_last_set_time, PDB_SET); 1272 1280 pdb_set_pass_can_change_time (sam_pass, pw_buf->pass_last_set_time, PDB_SET); 1273 1281 1274 1282 return True; 1275 1283 } … … 1307 1315 while ( ((smb_pw=getsmbfilepwent(smbpasswd_state, fp)) != NULL)&& (!strequal(smb_pw->smb_name, username)) ) 1308 1316 /* do nothing....another loop */ ; 1309 1317 1310 1318 endsmbfilepwent(fp, &(smbpasswd_state->pw_file_lock_depth)); 1311 1319 … … 1314 1322 if (smb_pw == NULL) 1315 1323 return nt_status; 1316 1324 1317 1325 DEBUG(10, ("getsampwnam (smbpasswd): found by name: %s\n", smb_pw->smb_name)); 1318 1326 … … 1321 1329 return nt_status; 1322 1330 } 1323 1331 1324 1332 /* now build the struct samu */ 1325 1333 if (!build_sam_account(smbpasswd_state, sam_acct, smb_pw)) … … 1330 1338 } 1331 1339 1332 static NTSTATUS smbpasswd_getsampwsid(struct pdb_methods *my_methods, struct samu *sam_acct, const DOM_SID*sid)1340 static NTSTATUS smbpasswd_getsampwsid(struct pdb_methods *my_methods, struct samu *sam_acct, const struct dom_sid *sid) 1333 1341 { 1334 1342 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; … … 1336 1344 struct smb_passwd *smb_pw; 1337 1345 FILE *fp = NULL; 1338 uint32 rid;1339 1346 uint32_t rid; 1347 1340 1348 DEBUG(10, ("smbpasswd_getsampwrid: search by sid: %s\n", 1341 1349 sid_string_dbg(sid))); … … 1345 1353 1346 1354 /* More special case 'guest account' hacks... */ 1347 if (rid == DOMAIN_ USER_RID_GUEST) {1355 if (rid == DOMAIN_RID_GUEST) { 1348 1356 const char *guest_account = lp_guestaccount(); 1349 1357 if (!(guest_account && *guest_account)) { … … 1371 1379 if (smb_pw == NULL) 1372 1380 return nt_status; 1373 1381 1374 1382 DEBUG(10, ("getsampwrid (smbpasswd): found by name: %s\n", smb_pw->smb_name)); 1375 1383 1376 1384 if (!sam_acct) { 1377 1385 DEBUG(10,("getsampwrid: (smbpasswd) struct samu is NULL\n")); … … 1384 1392 1385 1393 /* build_sam_account might change the SID on us, if the name was for the guest account */ 1386 if (NT_STATUS_IS_OK(nt_status) && ! sid_equal(pdb_get_user_sid(sam_acct), sid)) {1394 if (NT_STATUS_IS_OK(nt_status) && !dom_sid_equal(pdb_get_user_sid(sam_acct), sid)) { 1387 1395 DEBUG(1, ("looking for user with sid %s instead returned %s " 1388 1396 "for account %s!?!\n", sid_string_dbg(sid), … … 1400 1408 struct smbpasswd_privates *smbpasswd_state = (struct smbpasswd_privates*)my_methods->private_data; 1401 1409 struct smb_passwd smb_pw; 1402 1410 1403 1411 /* convert the struct samu */ 1404 1412 if (!build_smb_pass(&smb_pw, sampass)) { 1405 1413 return NT_STATUS_UNSUCCESSFUL; 1406 1414 } 1407 1415 1408 1416 /* add the entry */ 1409 1417 return add_smbfilepwd_entry(smbpasswd_state, &smb_pw); … … 1414 1422 struct smbpasswd_privates *smbpasswd_state = (struct smbpasswd_privates*)my_methods->private_data; 1415 1423 struct smb_passwd smb_pw; 1416 1424 1417 1425 /* convert the struct samu */ 1418 1426 if (!build_smb_pass(&smb_pw, sampass)) { … … 1420 1428 return NT_STATUS_UNSUCCESSFUL; 1421 1429 } 1422 1430 1423 1431 /* update the entry */ 1424 1432 if(!mod_smbfilepwd_entry(smbpasswd_state, &smb_pw)) { … … 1426 1434 return NT_STATUS_UNSUCCESSFUL; 1427 1435 } 1428 1436 1429 1437 return NT_STATUS_OK; 1430 1438 } … … 1458 1466 return NT_STATUS_NO_MEMORY; 1459 1467 } 1460 1468 1461 1469 if ( !pdb_copy_sam_account( new_acct, old_acct ) 1462 1470 || !pdb_set_username(new_acct, newname, PDB_CHANGED)) … … 1529 1537 if (new_acct) 1530 1538 TALLOC_FREE(new_acct); 1531 1539 1532 1540 return (ret); 1533 1541 } … … 1541 1549 { 1542 1550 struct smbpasswd_privates **privates = (struct smbpasswd_privates**)vp; 1543 1551 1544 1552 endsmbfilepwent((*privates)->pw_file, &((*privates)->pw_file_lock_depth)); 1545 1553 1546 1554 *privates = NULL; 1547 1555 /* No need to free any further, as it is talloc()ed */ … … 1711 1719 privates->smbpasswd_file = talloc_strdup(*pdb_method, lp_smb_passwd_file()); 1712 1720 } 1713 1721 1714 1722 if (!privates->smbpasswd_file) { 1715 1723 DEBUG(0, ("talloc_strdp() failed for storing smbpasswd location!\n"));
Note:
See TracChangeset
for help on using the changeset viewer.