Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/lib/username.c

    r414 r740  
    44   Copyright (C) Andrew Tridgell 1992-1998
    55   Copyright (C) Jeremy Allison 1997-2001.
    6    
     6   Copyright (C) Andrew Bartlett 2002
     7
    78   This program is free software; you can redistribute it and/or modify
    89   it under the terms of the GNU General Public License as published by
    910   the Free Software Foundation; either version 3 of the License, or
    1011   (at your option) any later version.
    11    
     12
    1213   This program is distributed in the hope that it will be useful,
    1314   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1415   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1516   GNU General Public License for more details.
    16    
     17
    1718   You should have received a copy of the GNU General Public License
    1819   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2021
    2122#include "includes.h"
     23#include "system/passwd.h"
     24#include "memcache.h"
     25#include "../lib/util/util_pw.h"
    2226
    2327/* internal functions */
     
    2933                                                 int N);
    3034
     35static struct passwd *getpwnam_alloc_cached(TALLOC_CTX *mem_ctx, const char *name)
     36{
     37        struct passwd *pw, *for_cache;
     38
     39        pw = (struct passwd *)memcache_lookup_talloc(
     40                NULL, GETPWNAM_CACHE, data_blob_string_const_null(name));
     41        if (pw != NULL) {
     42                return tcopy_passwd(mem_ctx, pw);
     43        }
     44
     45        pw = sys_getpwnam(name);
     46        if (pw == NULL) {
     47                return NULL;
     48        }
     49
     50        for_cache = tcopy_passwd(talloc_tos(), pw);
     51        if (for_cache == NULL) {
     52                return NULL;
     53        }
     54
     55        memcache_add_talloc(NULL, GETPWNAM_CACHE,
     56                        data_blob_string_const_null(name), &for_cache);
     57
     58        return tcopy_passwd(mem_ctx, pw);
     59}
     60
     61/****************************************************************************
     62 Flush all cached passwd structs.
     63****************************************************************************/
     64
     65void flush_pwnam_cache(void)
     66{
     67        memcache_flush(NULL, GETPWNAM_CACHE);
     68}
     69
    3170/****************************************************************************
    3271 Get a users home directory.
     
    76115        strlower_m(user2);
    77116        DEBUG(5,("Trying _Get_Pwnam(), username as lowercase is %s\n",user2));
    78         ret = getpwnam_alloc(mem_ctx, user2);
     117        ret = getpwnam_alloc_cached(mem_ctx, user2);
    79118        if(ret)
    80119                goto done;
     
    84123                DEBUG(5,("Trying _Get_Pwnam(), username as given is %s\n",
    85124                         user));
    86                 ret = getpwnam_alloc(mem_ctx, user);
     125                ret = getpwnam_alloc_cached(mem_ctx, user);
    87126                if(ret)
    88127                        goto done;
     
    94133                DEBUG(5,("Trying _Get_Pwnam(), username as uppercase is %s\n",
    95134                         user2));
    96                 ret = getpwnam_alloc(mem_ctx, user2);
     135                ret = getpwnam_alloc_cached(mem_ctx, user2);
    97136                if(ret)
    98137                        goto done;
     
    103142        DEBUG(5,("Checking combinations of %d uppercase letters in %s\n",
    104143                 lp_usernamelevel(), user2));
    105         ret = uname_string_combinations(user2, mem_ctx, getpwnam_alloc,
     144        ret = uname_string_combinations(user2, mem_ctx, getpwnam_alloc_cached,
    106145                                        lp_usernamelevel());
    107146
     
    122161{
    123162        fstring user2;
    124         struct passwd *ret;
    125163
    126164        if ( *user == '\0' ) {
     
    133171        DEBUG(5,("Finding user %s\n", user));
    134172
    135         ret = Get_Pwnam_internals(mem_ctx, user, user2);
    136        
    137         return ret; 
     173        return Get_Pwnam_internals(mem_ctx, user, user2);
    138174}
    139175
     
    161197        for (i=offset;i<(len-(N-1));i++) {
    162198                char c = s[i];
    163                 if (!islower_ascii((int)c))
     199                if (!islower_m((int)c))
    164200                        continue;
    165                 s[i] = toupper_ascii(c);
     201                s[i] = toupper_m(c);
    166202                ret = uname_string_combinations2(s, mem_ctx, i+1, fn, N-1);
    167203                if(ret)
Note: See TracChangeset for help on using the changeset viewer.