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

« back to all changes in this revision

Viewing changes to source/lib/util_pw.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:
22
22
 
23
23
#include "includes.h"
24
24
 
25
 
static struct passwd *alloc_copy_passwd(const struct passwd *from) 
 
25
struct passwd *tcopy_passwd(TALLOC_CTX *mem_ctx, const struct passwd *from) 
26
26
{
27
 
        struct passwd *ret = SMB_XMALLOC_P(struct passwd);
28
 
        ZERO_STRUCTP(ret);
29
 
        ret->pw_name = smb_xstrdup(from->pw_name);
30
 
        ret->pw_passwd = smb_xstrdup(from->pw_passwd);
 
27
        struct passwd *ret = TALLOC_P(mem_ctx, struct passwd);
 
28
        if (!ret) {
 
29
                return NULL;
 
30
        }
 
31
        ret->pw_name = talloc_strdup(ret, from->pw_name);
 
32
        ret->pw_passwd = talloc_strdup(ret, from->pw_passwd);
31
33
        ret->pw_uid = from->pw_uid;
32
34
        ret->pw_gid = from->pw_gid;
33
 
        ret->pw_gecos = smb_xstrdup(from->pw_gecos);
34
 
        ret->pw_dir = smb_xstrdup(from->pw_dir);
35
 
        ret->pw_shell = smb_xstrdup(from->pw_shell);
 
35
        ret->pw_gecos = talloc_strdup(ret, from->pw_gecos);
 
36
        ret->pw_dir = talloc_strdup(ret, from->pw_dir);
 
37
        ret->pw_shell = talloc_strdup(ret, from->pw_shell);
36
38
        return ret;
37
39
}
38
40
 
39
 
void passwd_free (struct passwd **buf)
40
 
{
41
 
        if (!*buf) {
42
 
                DEBUG(0, ("attempted double-free of allocated passwd\n"));
43
 
                return;
44
 
        }
45
 
 
46
 
        SAFE_FREE((*buf)->pw_name);
47
 
        SAFE_FREE((*buf)->pw_passwd);
48
 
        SAFE_FREE((*buf)->pw_gecos);
49
 
        SAFE_FREE((*buf)->pw_dir);
50
 
        SAFE_FREE((*buf)->pw_shell);
51
 
 
52
 
        SAFE_FREE(*buf);
53
 
}
54
 
 
55
41
#define PWNAMCACHE_SIZE 4
56
 
static struct passwd *pwnam_cache[PWNAMCACHE_SIZE];
57
 
static BOOL pwnam_cache_initialized = False;
 
42
static struct passwd **pwnam_cache = NULL;
58
43
 
59
44
static void init_pwnam_cache(void)
60
45
{
61
 
        int i;
62
 
 
63
 
        if (pwnam_cache_initialized)
 
46
        if (pwnam_cache != NULL)
64
47
                return;
65
48
 
66
 
        for (i=0; i<PWNAMCACHE_SIZE; i++)
67
 
                pwnam_cache[i] = NULL;
 
49
        pwnam_cache = TALLOC_ZERO_ARRAY(NULL, struct passwd *,
 
50
                                        PWNAMCACHE_SIZE);
 
51
        if (pwnam_cache == NULL) {
 
52
                smb_panic("Could not init pwnam_cache\n");
 
53
        }
68
54
 
69
 
        pwnam_cache_initialized = True;
70
55
        return;
71
56
}
72
57
 
73
58
void flush_pwnam_cache(void)
74
59
{
75
 
        int i;
76
 
 
 
60
        TALLOC_FREE(pwnam_cache);
 
61
        pwnam_cache = NULL;
77
62
        init_pwnam_cache();
78
 
 
79
 
        for (i=0; i<PWNAMCACHE_SIZE; i++) {
80
 
                if (pwnam_cache[i] == NULL)
81
 
                        continue;
82
 
 
83
 
                passwd_free(&pwnam_cache[i]);
84
 
        }
85
63
}
86
64
 
87
 
struct passwd *getpwnam_alloc(const char *name) 
 
65
struct passwd *getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name)
88
66
{
89
67
        int i;
90
68
 
96
74
                if ((pwnam_cache[i] != NULL) && 
97
75
                    (strcmp(name, pwnam_cache[i]->pw_name) == 0)) {
98
76
                        DEBUG(10, ("Got %s from pwnam_cache\n", name));
99
 
                        return alloc_copy_passwd(pwnam_cache[i]);
 
77
                        return talloc_reference(mem_ctx, pwnam_cache[i]);
100
78
                }
101
79
        }
102
80
 
119
97
        if (i == PWNAMCACHE_SIZE)
120
98
                i = rand() % PWNAMCACHE_SIZE;
121
99
 
122
 
        if (pwnam_cache[i] != NULL)
123
 
                passwd_free(&pwnam_cache[i]);
124
 
 
125
 
        pwnam_cache[i] = alloc_copy_passwd(temp);
126
 
 
127
 
        return alloc_copy_passwd(temp);
 
100
        if (pwnam_cache[i] != NULL) {
 
101
                TALLOC_FREE(pwnam_cache[i]);
 
102
        }
 
103
 
 
104
        pwnam_cache[i] = tcopy_passwd(pwnam_cache, temp);
 
105
        if (pwnam_cache[i]!= NULL && mem_ctx != NULL) {
 
106
                return talloc_reference(mem_ctx, pwnam_cache[i]);
 
107
        }
 
108
 
 
109
        return tcopy_passwd(NULL, pwnam_cache[i]);
128
110
}
129
111
 
130
 
struct passwd *getpwuid_alloc(uid_t uid) 
 
112
struct passwd *getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid) 
131
113
{
132
114
        struct passwd *temp;
133
115
 
142
124
                return NULL;
143
125
        }
144
126
 
145
 
        return alloc_copy_passwd(temp);
 
127
        return tcopy_passwd(mem_ctx, temp);
146
128
}