~vcs-imports/samba/main

« back to all changes in this revision

Viewing changes to source/passdb/util_unixsids.c

  • Committer: jerry
  • Date: 2006-07-14 21:48:39 UTC
  • Revision ID: vcs-imports@canonical.com-20060714214839-586d8c489a8fcead
gutting trunk to move to svn:externals

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
2
 
   Unix SMB/CIFS implementation.
3
 
   Translate unix-defined names to SIDs and vice versa
4
 
   Copyright (C) Volker Lendecke 2005
5
 
      
6
 
   This program is free software; you can redistribute it and/or modify
7
 
   it under the terms of the GNU General Public License as published by
8
 
   the Free Software Foundation; either version 2 of the License, or
9
 
   (at your option) any later version.
10
 
   
11
 
   This program is distributed in the hope that it will be useful,
12
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
   GNU General Public License for more details.
15
 
   
16
 
   You should have received a copy of the GNU General Public License
17
 
   along with this program; if not, write to the Free Software
18
 
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
 
*/
20
 
 
21
 
#include "includes.h"
22
 
 
23
 
BOOL sid_check_is_unix_users(const DOM_SID *sid)
24
 
{
25
 
        return sid_equal(sid, &global_sid_Unix_Users);
26
 
}
27
 
 
28
 
BOOL sid_check_is_in_unix_users(const DOM_SID *sid)
29
 
{
30
 
        DOM_SID dom_sid;
31
 
        uint32 rid;
32
 
 
33
 
        sid_copy(&dom_sid, sid);
34
 
        sid_split_rid(&dom_sid, &rid);
35
 
        
36
 
        return sid_check_is_unix_users(&dom_sid);
37
 
}
38
 
 
39
 
BOOL uid_to_unix_users_sid(uid_t uid, DOM_SID *sid)
40
 
{
41
 
        sid_copy(sid, &global_sid_Unix_Users);
42
 
        return sid_append_rid(sid, uid);
43
 
}
44
 
 
45
 
const char *unix_users_domain_name(void)
46
 
{
47
 
        return "Unix User";
48
 
}
49
 
 
50
 
BOOL lookup_unix_user_name(const char *name, DOM_SID *sid)
51
 
{
52
 
        struct passwd *pwd;
53
 
 
54
 
        pwd = getpwnam_alloc(NULL, name);
55
 
        if (pwd == NULL) {
56
 
                return False;
57
 
        }
58
 
 
59
 
        sid_copy(sid, &global_sid_Unix_Users);
60
 
        sid_append_rid(sid, pwd->pw_uid); /* For 64-bit uid's we have enough
61
 
                                          * space ... */
62
 
        TALLOC_FREE(pwd);
63
 
        return True;
64
 
}
65
 
 
66
 
BOOL sid_check_is_unix_groups(const DOM_SID *sid)
67
 
{
68
 
        return sid_equal(sid, &global_sid_Unix_Groups);
69
 
}
70
 
 
71
 
BOOL sid_check_is_in_unix_groups(const DOM_SID *sid)
72
 
{
73
 
        DOM_SID dom_sid;
74
 
        uint32 rid;
75
 
 
76
 
        sid_copy(&dom_sid, sid);
77
 
        sid_split_rid(&dom_sid, &rid);
78
 
        
79
 
        return sid_check_is_unix_groups(&dom_sid);
80
 
}
81
 
 
82
 
const char *unix_groups_domain_name(void)
83
 
{
84
 
        return "Unix Group";
85
 
}
86
 
 
87
 
BOOL lookup_unix_group_name(const char *name, DOM_SID *sid)
88
 
{
89
 
        struct group *grp;
90
 
 
91
 
        grp = getgrnam(name);
92
 
        if (grp == NULL) {
93
 
                return False;
94
 
        }
95
 
 
96
 
        sid_copy(sid, &global_sid_Unix_Groups);
97
 
        sid_append_rid(sid, grp->gr_gid); /* For 64-bit uid's we have enough
98
 
                                           * space ... */
99
 
        return True;
100
 
}