summaryrefslogtreecommitdiff
path: root/source3/groupdb/builtinunix.c
blob: dc70ffb3dcb0d9fe6a4bd4cecb4b0efdb09a1dde (plain)
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*
 * Unix SMB/Netbios implementation. Version 1.9. SMB parameters and setup
 * Copyright (C) Andrew Tridgell 1992-1998 Modified by Jeremy Allison 1995.
 * 
 * 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 of the License, 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., 675
 * Mass Ave, Cambridge, MA 02139, USA.
 */

#include "includes.h"

#ifdef USE_SMBUNIX_DB

extern int DEBUGLEVEL;


extern DOM_SID global_sid_S_1_5_20;
extern DOM_SID global_sam_sid;
extern fstring global_sam_name;

/***************************************************************
 Start to enumerate the bltpasswd list. Returns a void pointer
 to ensure no modification outside this module.
****************************************************************/

static void *startbltunixpwent(BOOL update)
{
	setgrent();
	return (void*)(-1);
}

/***************************************************************
 End enumeration of the bltpasswd list.
****************************************************************/

static void endbltunixpwent(void *vp)
{
	endgrent();
}

/*************************************************************************
 Return the current position in the bltpasswd list as an SMB_BIG_UINT.
 This must be treated as an opaque token.
*************************************************************************/
static SMB_BIG_UINT getbltunixpwpos(void *vp)
{
	return (SMB_BIG_UINT)0;
}

/*************************************************************************
 Set the current position in the bltpasswd list from an SMB_BIG_UINT.
 This must be treated as an opaque token.
*************************************************************************/
static BOOL setbltunixpwpos(void *vp, SMB_BIG_UINT tok)
{
	return False;
}

/*************************************************************************
 Routine to return the next entry in the smbdomainbuiltin list.
 *************************************************************************/
BOOL get_unixbuiltin_members(struct group *grp,
				int *num_mem, LOCAL_GRP_MEMBER **members)
{
	int i;
	char *unix_name;

	if (num_mem == NULL || members == NULL)
	{
		return False;
	}

	(*num_mem) = 0;
	(*members) = NULL;

	for (i = 0; (unix_name = grp->gr_mem[i]) != NULL; i++)
	{
		fstring name;
		DOM_NAME_MAP gmep;
		LOCAL_GRP_MEMBER *mem;

		fstrcpy(name, unix_name);

		if (!lookupsmbgrpnam(name, &gmep) &&
		    !lookupsmbpwnam (name, &gmep))
		{
			continue;
		}

		if (!sid_front_equal(&global_sam_sid, &gmep.sid))
		{
			DEBUG(0,("builtin database: could not resolve name %s (wrong Domain SID)\n",
			          name));
			continue;
		}

		(*num_mem)++;
		(*members) = Realloc((*members), (*num_mem) * sizeof(LOCAL_GRP_MEMBER));
		if ((*members) == NULL)
		{
			DEBUG(0,("get_unixbuiltin_members: could not realloc LOCAL_GRP_MEMBERs\n"));
			return False;
		}

		mem = &(*members)[(*num_mem)-1];
		slprintf(mem->name, sizeof(mem->name)-1, "%s\\%s",
		         gmep.nt_domain, gmep.nt_name);
		sid_copy(&mem->sid, &gmep.sid);
		mem->sid_use = gmep.type;

		DEBUG(10,("get_unixbuiltin_members: adding to builtin alias %s\n",
		           mem->name));
	}
	return True;
}

/*************************************************************************
 Routine to return the next entry in the domain builtin list.

 when we are a PDC or BDC, then unix groups that are explicitly NOT mapped
 to builtin aliases are treated as DOMAIN groups (see groupunix.c).

 when we are a member of a domain (not a PDC or BDC) then unix groups
 that are explicitly NOT mapped to builtin aliases are treated
 as LOCAL groups.

 the reasoning behind this is to make it as simple as possible (not an easy
 task) for people to set up a domain-aware samba server, in each role that
 the server can take.

 *************************************************************************/
static LOCAL_GRP *getbltunixpwent(void *vp, LOCAL_GRP_MEMBER **mem, int *num_mem)
{
	/* Static buffers we will return. */
	static LOCAL_GRP gp_buf;
	struct group *unix_grp;

	if (lp_server_role() == ROLE_DOMAIN_NONE)
	{
		/*
		 * no domain role, no domain builtin aliases (or domain groups,
		 * but that's dealt with by groupdb...).
		 */

		return NULL;
	}

	bidb_init_blt(&gp_buf);

	/* cycle through unix groups */
	while ((unix_grp = getgrent()) != NULL)
	{
		DOM_NAME_MAP gmep;
		fstring sid_str;
		DEBUG(10,("getbltunixpwent: enum unix group entry %s\n",
		           unix_grp->gr_name));
			
		if (!lookupsmbgrpgid(unix_grp->gr_gid, &gmep))
		{
			continue;
		}

		sid_to_string(sid_str, &gmep.sid);
		DEBUG(10,("group %s found, sid %s type %d\n",
			gmep.nt_name, sid_str, gmep.type));

		if (gmep.type != SID_NAME_ALIAS)
		{
			continue;
		}

		sid_split_rid(&gmep.sid, &gp_buf.rid);
		if (!sid_equal(&global_sid_S_1_5_20, &gmep.sid))
		{
			continue;
		}

		fstrcpy(gp_buf.name, gmep.nt_name);
		break;
	}

	if (unix_grp == NULL)
	{
		return NULL;
	}

	/* get the user's domain builtin aliases.  there are a maximum of 32 */

	if (mem != NULL && num_mem != NULL)
	{
		(*mem) = NULL;
		(*num_mem) = 0;

		get_unixbuiltin_members(unix_grp, num_mem, mem);
	}

	{
		pstring linebuf;
		make_builtin_line(linebuf, sizeof(linebuf), &gp_buf, mem, num_mem);
		DEBUG(10,("line: '%s'\n", linebuf));
	}

	return &gp_buf;
}

/************************************************************************
 Routine to add an entry to the bltpasswd file.
*************************************************************************/

static BOOL add_bltunixgrp_entry(LOCAL_GRP *newblt)
{
	DEBUG(0, ("add_bltunixgrp_entry: NOT IMPLEMENTED\n"));
	return False;
}

/************************************************************************
 Routine to search the bltpasswd file for an entry matching the builtinname.
 and then modify its builtin entry. We can't use the startbltpwent()/
 getbltpwent()/endbltpwent() interfaces here as we depend on looking
 in the actual file to decide how much room we have to write data.
 override = False, normal
 override = True, override XXXXXXXX'd out builtin or NO PASS
************************************************************************/

static BOOL mod_bltunixgrp_entry(LOCAL_GRP* blt)
{
	DEBUG(0, ("mod_bltunixgrp_entry: NOT IMPLEMENTED\n"));
	return False;
}


static struct aliasdb_ops unix_ops =
{
	startbltunixpwent,
	endbltunixpwent,
	getbltunixpwpos,
	setbltunixpwpos,

	iterate_getbuiltinntnam,          /* In builtindb.c */
	iterate_getbuiltingid,          /* In builtindb.c */
	iterate_getbuiltinrid,          /* In builtindb.c */
	getbltunixpwent,

	add_bltunixgrp_entry,
	mod_bltunixgrp_entry,

	iterate_getuserbuiltinntnam      /* in builtindb.c */
};

struct aliasdb_ops *unix_initialise_builtin_db(void)
{    
	return &unix_ops;
}

#else
 /* Do *NOT* make this function static. It breaks the compile on gcc. JRA */
 void unix_bltpass_dummy_function(void) { } /* stop some compilers complaining */
#endif /* USE_SMBPASS_DB */