Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/passdb/pdb_smbpasswd.c

    r596 r745  
    2222
    2323#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"
    2429
    2530#undef DBGC_CLASS
     
    3136   stored by an smbpasswd entry
    3237 */
    33  
     38
    3439struct smb_passwd
    3540{
     
    4045        const unsigned char *smb_nt_passwd; /* Null if no password */
    4146
    42         uint16 acct_ctrl;             /* account info (ACB_xxxx bit-mask) */
     47        uint16_t acct_ctrl;             /* account info (ACB_xxxx bit-mask) */
    4348        time_t pass_last_set_time;    /* password last set time */
    4449};
     
    4853        /* used for maintain locks on the smbpasswd file */
    4954        int     pw_file_lock_depth;
    50        
     55
    5156        /* Global File pointer */
    5257        FILE    *pw_file;
    53        
     58
    5459        /* formerly static variables */
    5560        struct smb_passwd pw_buf;
     
    7075****************************************************************/
    7176
    72 static void gotalarm_sig(void)
     77static void gotalarm_sig(int signum)
    7378{
    7479        gotalarm = 1;
     
    8792
    8893        gotalarm = 0;
    89         oldsig_handler = CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig);
     94        oldsig_handler = CatchSignal(SIGALRM, gotalarm_sig);
    9095
    9196        lock.l_type = type;
     
    99104        ret = fcntl(fd, SMB_F_SETLKW, &lock);
    100105        alarm(0);
    101         CatchSignal(SIGALRM, SIGNAL_CAST oldsig_handler);
     106        CatchSignal(SIGALRM, oldsig_handler);
    102107
    103108        if (gotalarm && ret == -1) {
     
    169174                return;
    170175        ZERO_STRUCTP (user);
    171        
     176
    172177        user->pass_last_set_time = (time_t)0;
    173178}
     
    224229                                break;
    225230                        }
    226         }
    227                        
     231                default:
     232                        DEBUG(10, ("Invalid open mode: %d\n", type));
     233                        return NULL;
     234        }
     235
    228236        for(race_loop = 0; race_loop < 5; race_loop++) {
    229237                DEBUG(10, ("startsmbfilepwent_internal: opening file %s\n", pfile));
     
    621629        slprintf((char *)p, new_entry_length - 1 - (p - new_entry),  "%s:LCT-%08X:\n",
    622630                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);
    624632
    625633        return new_entry;
     
    10101018                        sizeof(ascii_p16)-(strlen(ascii_p16)+1),
    10111019                        "%s:LCT-%08X:",
    1012                         encode_bits, (uint32)pwd->pass_last_set_time );
     1020                        encode_bits, (uint32_t)pwd->pass_last_set_time );
    10131021                wr_len = strlen(ascii_p16);
    10141022        }
     
    11741182         * Do an atomic rename - then release the locks.
    11751183         */
     1184
    11761185#ifdef __OS2__
    11771186        endsmbfilepwent(fp, &smbpasswd_state->pw_file_lock_depth);
    11781187        endsmbfilepwent(fp_write,&pfile2_lockdepth);
    11791188#endif
    1180 
    11811189        if(rename(pfile2,pfile) != 0) {
    11821190                unlink(pfile2);
     
    11981206static bool build_smb_pass (struct smb_passwd *smb_pw, const struct samu *sampass)
    11991207{
    1200         uint32 rid;
     1208        uint32_t rid;
    12011209
    12021210        if (sampass == NULL)
     
    12061214        if (!IS_SAM_DEFAULT(sampass, PDB_USERSID)) {
    12071215                rid = pdb_get_user_rid(sampass);
    1208                
     1216
    12091217                /* 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) {
    12111219                        struct passwd *passwd = Get_Pwnam_alloc(NULL, lp_guestaccount());
    12121220                        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()));
    12141222                                return False;
    12151223                        }
     
    12431251{
    12441252        struct passwd *pwfile;
    1245        
     1253
    12461254        if ( !sam_pass ) {
    12471255                DEBUG(5,("build_sam_account: struct samu is NULL\n"));
     
    12561264                        return False;
    12571265        }
    1258        
     1266
    12591267        if ( !NT_STATUS_IS_OK( samu_set_unix(sam_pass, pwfile )) )
    12601268                return False;
    1261                
     1269
    12621270        TALLOC_FREE(pwfile);
    12631271
    12641272        /* set remaining fields */
    1265                
     1273
    12661274        if (!pdb_set_nt_passwd (sam_pass, pw_buf->smb_nt_passwd, PDB_SET))
    12671275                return False;
     
    12711279        pdb_set_pass_last_set_time (sam_pass, pw_buf->pass_last_set_time, PDB_SET);
    12721280        pdb_set_pass_can_change_time (sam_pass, pw_buf->pass_last_set_time, PDB_SET);
    1273        
     1281
    12741282        return True;
    12751283}
     
    13071315        while ( ((smb_pw=getsmbfilepwent(smbpasswd_state, fp)) != NULL)&& (!strequal(smb_pw->smb_name, username)) )
    13081316                /* do nothing....another loop */ ;
    1309        
     1317
    13101318        endsmbfilepwent(fp, &(smbpasswd_state->pw_file_lock_depth));
    13111319
     
    13141322        if (smb_pw == NULL)
    13151323                return nt_status;
    1316        
     1324
    13171325        DEBUG(10, ("getsampwnam (smbpasswd): found by name: %s\n", smb_pw->smb_name));
    13181326
     
    13211329                return nt_status;
    13221330        }
    1323                
     1331
    13241332        /* now build the struct samu */
    13251333        if (!build_sam_account(smbpasswd_state, sam_acct, smb_pw))
     
    13301338}
    13311339
    1332 static NTSTATUS smbpasswd_getsampwsid(struct pdb_methods *my_methods, struct samu *sam_acct, const DOM_SID *sid)
     1340static NTSTATUS smbpasswd_getsampwsid(struct pdb_methods *my_methods, struct samu *sam_acct, const struct dom_sid *sid)
    13331341{
    13341342        NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
     
    13361344        struct smb_passwd *smb_pw;
    13371345        FILE *fp = NULL;
    1338         uint32 rid;
    1339        
     1346        uint32_t rid;
     1347
    13401348        DEBUG(10, ("smbpasswd_getsampwrid: search by sid: %s\n",
    13411349                   sid_string_dbg(sid)));
     
    13451353
    13461354        /* More special case 'guest account' hacks... */
    1347         if (rid == DOMAIN_USER_RID_GUEST) {
     1355        if (rid == DOMAIN_RID_GUEST) {
    13481356                const char *guest_account = lp_guestaccount();
    13491357                if (!(guest_account && *guest_account)) {
     
    13711379        if (smb_pw == NULL)
    13721380                return nt_status;
    1373        
     1381
    13741382        DEBUG(10, ("getsampwrid (smbpasswd): found by name: %s\n", smb_pw->smb_name));
    1375                
     1383
    13761384        if (!sam_acct) {
    13771385                DEBUG(10,("getsampwrid: (smbpasswd) struct samu is NULL\n"));
     
    13841392
    13851393        /* 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)) {
    13871395                DEBUG(1, ("looking for user with sid %s instead returned %s "
    13881396                          "for account %s!?!\n", sid_string_dbg(sid),
     
    14001408        struct smbpasswd_privates *smbpasswd_state = (struct smbpasswd_privates*)my_methods->private_data;
    14011409        struct smb_passwd smb_pw;
    1402        
     1410
    14031411        /* convert the struct samu */
    14041412        if (!build_smb_pass(&smb_pw, sampass)) {
    14051413                return NT_STATUS_UNSUCCESSFUL;
    14061414        }
    1407        
     1415
    14081416        /* add the entry */
    14091417        return add_smbfilepwd_entry(smbpasswd_state, &smb_pw);
     
    14141422        struct smbpasswd_privates *smbpasswd_state = (struct smbpasswd_privates*)my_methods->private_data;
    14151423        struct smb_passwd smb_pw;
    1416        
     1424
    14171425        /* convert the struct samu */
    14181426        if (!build_smb_pass(&smb_pw, sampass)) {
     
    14201428                return NT_STATUS_UNSUCCESSFUL;
    14211429        }
    1422        
     1430
    14231431        /* update the entry */
    14241432        if(!mod_smbfilepwd_entry(smbpasswd_state, &smb_pw)) {
     
    14261434                return NT_STATUS_UNSUCCESSFUL;
    14271435        }
    1428        
     1436
    14291437        return NT_STATUS_OK;
    14301438}
     
    14581466                return NT_STATUS_NO_MEMORY;
    14591467        }
    1460        
     1468
    14611469        if ( !pdb_copy_sam_account( new_acct, old_acct )
    14621470                || !pdb_set_username(new_acct, newname, PDB_CHANGED))
     
    15291537        if (new_acct)
    15301538                TALLOC_FREE(new_acct);
    1531        
     1539
    15321540        return (ret);   
    15331541}
     
    15411549{
    15421550        struct smbpasswd_privates **privates = (struct smbpasswd_privates**)vp;
    1543        
     1551
    15441552        endsmbfilepwent((*privates)->pw_file, &((*privates)->pw_file_lock_depth));
    1545        
     1553
    15461554        *privates = NULL;
    15471555        /* No need to free any further, as it is talloc()ed */
     
    17111719                privates->smbpasswd_file = talloc_strdup(*pdb_method, lp_smb_passwd_file());
    17121720        }
    1713        
     1721
    17141722        if (!privates->smbpasswd_file) {
    17151723                DEBUG(0, ("talloc_strdp() failed for storing smbpasswd location!\n"));
Note: See TracChangeset for help on using the changeset viewer.