-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcredutl_kernel.c
195 lines (155 loc) · 4.83 KB
/
credutl_kernel.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/* * (C) Copyright IBM Corporation 1991, 2008. */
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Author: IBM Corporation
This module is part of the IBM (R) Rational (R) ClearCase (R)
Multi-version file system (MVFS).
For support, please visit http://www.ibm.com/software/support
*/
/* credutl_kernel.c */
#include "mvfs_systm.h"
#include "mvfs.h"
#include <credutl_kernel.h>
#define CREDUTL_ASSERT ASSERT
#define CREDUTL_MEM_ZERO BZERO
/*
* UNIX platforms can only ever handle UNIX style SIDs
*/
#define CREDUTL_UNIX_SID_SUPPORT
/*
* Internal sanity number for UNIX SIDs to verify uids and gids
* are of the right type (not to be used for any exported routines).
*/
#define CREDUTL_SID_UNIX_UID 1
#define CREDUTL_SID_UNIX_GID 2
/*
* Setup "Nobody" and "DontCare" as special SIDs since we can not translate to
* an NT SID representation of nobody/dontcare.
*/
EXPORT_DATA
const
credutl_sid_t CREDUTL_SID_NOBODY = {
2,
CREDUTL_SID_TYPE_NOBODY
};
EXPORT_DATA
const
credutl_sid_t CREDUTL_SID_DONTCARE = {
2,
CREDUTL_SID_TYPE_DONTCARE
};
STATIC ks_uint32_t
get_int32(const char *s)
{
ks_uint32_t uid;
uid = (*s++ << 24) & 0xff000000;
uid |= (*s++ << 16) & 0x00ff0000;
uid |= (*s++ << 8) & 0x0000ff00;
uid |= *s++ & 0x000000ff;
return(uid);
}
/******************************************************************
* credutl_unix_id_to_sid
* Converts a 32-bit UNIX UID or GID to a credutl-style SID.
*/
STATIC
void
credutl_unix_id_to_sid(
uid_t id,
credutl_sid_t *sid_p,
char unix_id_type
)
{
int i = 0;
char *sp = &sid_p->sid[0];
sid_p->type = CREDUTL_SID_TYPE_UNIX;
sp[i++] = (char)((id >> 24) & 0xff);
sp[i++] = (char)((id >> 16) & 0xff);
sp[i++] = (char)((id >> 8) & 0xff);
sp[i++] = (char)(id & 0xff);
sp[i++] = unix_id_type;
sid_p->length = (char)(CREDUTL_SID_BASE_SIZE(sid_p) + i);
}
/******************************************************************
* credutl_unix_uid_to_sid
* Converts a 32-bit UNIX UID to a credutl-style SID.
*/
void
credutl_unix_uid_to_sid(
uid_t uid,
credutl_sid_t *sid_p
)
{
credutl_unix_id_to_sid(uid, sid_p, CREDUTL_SID_UNIX_UID);
}
/******************************************************************
* credutl_unix_gid_to_sid
* Converts a 32-bit UNIX GID to a credutl-style SID.
*/
void
credutl_unix_gid_to_sid(
gid_t gid,
credutl_sid_t *sid_p
)
{
credutl_unix_id_to_sid(gid, sid_p, CREDUTL_SID_UNIX_GID);
}
/******************************************************************
* credutl_sid_to_unix_uid
* Converts a credutl-style SID to a 32-bit UNIX UID.
*/
credutl_uid_t
credutl_sid_to_unix_uid(const credutl_sid_t *sid_p)
{
int i = 0;
const char *sp = &sid_p->sid[0];
uid_t uid;
char unix_id_type;
CREDUTL_ASSERT(sid_p->type == CREDUTL_SID_TYPE_UNIX);
uid = get_int32(&sp[i]);
i += 4; /* advance past the 4 bytes (32 bits) of the uid */
unix_id_type = sp[i++];
/* CREDUTL_ASSERT(unix_id_type == CREDUTL_SID_UNIX_UID); */
if (unix_id_type != CREDUTL_SID_UNIX_UID)
return KS_UID_NOBODY;
/* CREDUTL_ASSERT(sid_p->length == i + CREDUTL_SID_BASE_SIZE(sid_p)); */
if (sid_p->length != i + CREDUTL_SID_BASE_SIZE(sid_p))
return KS_UID_NOBODY;
return(uid);
}
/******************************************************************
* credutl_sid_to_unix_gid
* Converts a credutl-style SID to a 32-bit UNIX GID.
*/
credutl_gid_t
credutl_sid_to_unix_gid(const credutl_sid_t *sid_p)
{
int i = 0;
const char *sp = &sid_p->sid[0];
gid_t gid;
char unix_id_type;
CREDUTL_ASSERT(sid_p->type == CREDUTL_SID_TYPE_UNIX);
gid = (sp[i++] << 24) & 0xff000000;
gid |= (sp[i++] << 16) & 0x00ff0000;
gid |= (sp[i++] << 8) & 0x0000ff00;
gid |= sp[i++] & 0x000000ff;
unix_id_type = sp[i++];
/* CREDUTL_ASSERT(unix_id_type == CREDUTL_SID_UNIX_GID); */
if (unix_id_type != CREDUTL_SID_UNIX_GID)
return KS_GID_NOBODY;
/* CREDUTL_ASSERT(sid_p->length == i + CREDUTL_SID_BASE_SIZE(sid_p)); */
if (sid_p->length != i + CREDUTL_SID_BASE_SIZE(sid_p))
return KS_GID_NOBODY;
return(gid);
}
static const char vnode_verid_credutl_kernel_c[] = "$Id: e9ae0bf1.145d11d7.81b6.00:50:da:ba:19:c8 $";