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

« back to all changes in this revision

Viewing changes to source/rpc_server/srv_lsa_nt.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:
4
4
 *  Copyright (C) Andrew Tridgell              1992-1997,
5
5
 *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
6
6
 *  Copyright (C) Paul Ashton                       1997,
7
 
 *  Copyright (C) Jeremy Allison                    2001,
 
7
 *  Copyright (C) Jeremy Allison                    2001, 2006.
8
8
 *  Copyright (C) Rafal Szczesniak                  2002,
9
9
 *  Copyright (C) Jim McDonough <jmcd@us.ibm.com>   2002,
10
10
 *  Copyright (C) Simo Sorce                        2003.
11
11
 *  Copyright (C) Gerald (Jerry) Carter             2005.
 
12
 *  Copyright (C) Volker Lendecke                   2005.
12
13
 *
13
14
 *  This program is free software; you can redistribute it and/or modify
14
15
 *  it under the terms of the GNU General Public License as published by
61
62
Init dom_query
62
63
 ***************************************************************************/
63
64
 
64
 
static void init_dom_query(DOM_QUERY *d_q, const char *dom_name, DOM_SID *dom_sid)
 
65
static void init_dom_query_3(DOM_QUERY_3 *d_q, const char *dom_name, DOM_SID *dom_sid)
65
66
{
66
67
        d_q->buffer_dom_name = (dom_name != NULL) ? 1 : 0; /* domain buffer pointer */
67
68
        d_q->buffer_dom_sid = (dom_sid != NULL) ? 1 : 0;  /* domain sid pointer */
93
94
}
94
95
 
95
96
/***************************************************************************
 
97
Init dom_query
 
98
 ***************************************************************************/
 
99
 
 
100
static void init_dom_query_5(DOM_QUERY_5 *d_q, const char *dom_name, DOM_SID *dom_sid)
 
101
{
 
102
        init_dom_query_3(d_q, dom_name, dom_sid);
 
103
}
 
104
 
 
105
/***************************************************************************
96
106
 init_dom_ref - adds a domain if it's not already in, returns the index.
97
107
***************************************************************************/
98
108
 
99
 
static int init_dom_ref(DOM_R_REF *ref, char *dom_name, DOM_SID *dom_sid)
 
109
static int init_dom_ref(DOM_R_REF *ref, const char *dom_name, DOM_SID *dom_sid)
100
110
{
101
111
        int num = 0;
102
112
 
103
113
        if (dom_name != NULL) {
104
114
                for (num = 0; num < ref->num_ref_doms_1; num++) {
105
 
                        fstring domname;
106
 
                        rpcstr_pull(domname, ref->ref_dom[num].uni_dom_name.buffer, sizeof(domname), -1, 0);
107
 
                        if (strequal(domname, dom_name))
 
115
                        if (sid_equal(dom_sid, &ref->ref_dom[num].ref_dom.sid))
108
116
                                return num;
109
117
                }
110
118
        } else {
121
129
        ref->max_entries = MAX_REF_DOMAINS;
122
130
        ref->num_ref_doms_2 = num+1;
123
131
 
124
 
        ref->hdr_ref_dom[num].ptr_dom_sid = dom_sid != NULL ? 1 : 0;
 
132
        ref->hdr_ref_dom[num].ptr_dom_sid = 1; /* dom sid cannot be NULL. */
125
133
 
126
134
        init_unistr2(&ref->ref_dom[num].uni_dom_name, dom_name, UNI_FLAGS_NONE);
127
135
        init_uni_hdr(&ref->hdr_ref_dom[num].hdr_dom_name, &ref->ref_dom[num].uni_dom_name);
132
140
}
133
141
 
134
142
/***************************************************************************
135
 
 init_lsa_rid2s
 
143
 lookup_lsa_rids. Must be called as root for lookup_name to work.
136
144
 ***************************************************************************/
137
145
 
138
 
static void init_lsa_rid2s(DOM_R_REF *ref, DOM_RID2 *rid2,
139
 
                                int num_entries, UNISTR2 *name,
140
 
                                uint32 *mapped_count, BOOL endian)
 
146
static NTSTATUS lookup_lsa_rids(TALLOC_CTX *mem_ctx,
 
147
                        DOM_R_REF *ref,
 
148
                        DOM_RID *prid,
 
149
                        uint32 num_entries,
 
150
                        const UNISTR2 *name,
 
151
                        int flags,
 
152
                        uint32 *pmapped_count)
141
153
{
142
 
        int i;
143
 
        int total = 0;
144
 
        *mapped_count = 0;
 
154
        uint32 mapped_count, i;
145
155
 
146
156
        SMB_ASSERT(num_entries <= MAX_LOOKUP_SIDS);
147
157
 
148
 
        become_root(); /* lookup_name can require root privs */
 
158
        mapped_count = 0;
 
159
        *pmapped_count = 0;
149
160
 
150
161
        for (i = 0; i < num_entries; i++) {
151
 
                BOOL status = False;
152
162
                DOM_SID sid;
153
 
                uint32 rid = 0xffffffff;
154
 
                int dom_idx = -1;
155
 
                pstring full_name;
156
 
                fstring dom_name, user;
157
 
                enum SID_NAME_USE name_type = SID_NAME_UNKNOWN;
 
163
                uint32 rid;
 
164
                int dom_idx;
 
165
                char *full_name;
 
166
                const char *domain;
 
167
                enum SID_NAME_USE type = SID_NAME_UNKNOWN;
158
168
 
159
169
                /* Split name into domain and user component */
160
170
 
161
 
                unistr2_to_ascii(full_name, &name[i], sizeof(full_name));
162
 
                split_domain_name(full_name, dom_name, user);
163
 
 
164
 
                /* Lookup name */
165
 
 
166
 
                DEBUG(5, ("init_lsa_rid2s: looking up name %s\n", full_name));
167
 
 
168
 
                status = lookup_name(dom_name, user, &sid, &name_type);
169
 
 
170
 
                if((name_type == SID_NAME_UNKNOWN) && (lp_server_role() == ROLE_DOMAIN_MEMBER)  && (strncmp(dom_name, full_name, strlen(dom_name)) != 0)) {
171
 
                        DEBUG(5, ("init_lsa_rid2s: domain name not provided and local account not found, using member domain\n"));
172
 
                        fstrcpy(dom_name, lp_workgroup());
173
 
                        status = lookup_name(dom_name, user, &sid, &name_type);
174
 
                }
175
 
 
176
 
                if (name_type == SID_NAME_WKN_GRP) {
177
 
                        /* BUILTIN aliases are still aliases :-) */
178
 
                        name_type = SID_NAME_ALIAS;
179
 
                }
180
 
 
181
 
                DEBUG(5, ("init_lsa_rid2s: %s\n", status ? "found" : 
182
 
                          "not found"));
183
 
 
184
 
                if (status && name_type != SID_NAME_UNKNOWN) {
 
171
                full_name = rpcstr_pull_unistr2_talloc(mem_ctx, &name[i]);
 
172
                if (full_name == NULL) {
 
173
                        DEBUG(0, ("pull_ucs2_talloc failed\n"));
 
174
                        return NT_STATUS_NO_MEMORY;
 
175
                }
 
176
 
 
177
                DEBUG(5, ("lookup_lsa_rids: looking up name %s\n", full_name));
 
178
 
 
179
                /* We can ignore the result of lookup_name, it will not touch
 
180
                   "type" if it's not successful */
 
181
 
 
182
                lookup_name(mem_ctx, full_name, flags, &domain, NULL,
 
183
                            &sid, &type);
 
184
 
 
185
                switch (type) {
 
186
                case SID_NAME_USER:
 
187
                case SID_NAME_DOM_GRP:
 
188
                case SID_NAME_DOMAIN:
 
189
                case SID_NAME_ALIAS:
 
190
                case SID_NAME_WKN_GRP:
 
191
                        DEBUG(5, ("init_lsa_rids: %s found\n", full_name));
 
192
                        /* Leave these unchanged */
 
193
                        break;
 
194
                default:
 
195
                        /* Don't hand out anything but the list above */
 
196
                        DEBUG(5, ("init_lsa_rids: %s not found\n", full_name));
 
197
                        type = SID_NAME_UNKNOWN;
 
198
                        break;
 
199
                }
 
200
 
 
201
                rid = 0;
 
202
                dom_idx = -1;
 
203
 
 
204
                if (type != SID_NAME_UNKNOWN) {
185
205
                        sid_split_rid(&sid, &rid);
186
 
                        dom_idx = init_dom_ref(ref, dom_name, &sid);
187
 
                        (*mapped_count)++;
188
 
                } else {
189
 
                        dom_idx = -1;
190
 
                        rid = 0;
191
 
                        name_type = SID_NAME_UNKNOWN;
192
 
                }
193
 
 
194
 
                init_dom_rid2(&rid2[total], rid, name_type, dom_idx);
195
 
                total++;
196
 
        }
197
 
 
198
 
        unbecome_root();
 
206
                        dom_idx = init_dom_ref(ref, domain, &sid);
 
207
                        mapped_count++;
 
208
                }
 
209
 
 
210
                init_dom_rid(&prid[i], rid, type, dom_idx);
 
211
        }
 
212
 
 
213
        *pmapped_count = mapped_count;
 
214
        return NT_STATUS_OK;
 
215
}
 
216
 
 
217
/***************************************************************************
 
218
 lookup_lsa_sids. Must be called as root for lookup_name to work.
 
219
 ***************************************************************************/
 
220
 
 
221
static NTSTATUS lookup_lsa_sids(TALLOC_CTX *mem_ctx,
 
222
                        DOM_R_REF *ref,
 
223
                        LSA_TRANSLATED_SID3 *trans_sids,
 
224
                        uint32 num_entries,
 
225
                        const UNISTR2 *name,
 
226
                        int flags,
 
227
                        uint32 *pmapped_count)
 
228
{
 
229
        uint32 mapped_count, i;
 
230
 
 
231
        SMB_ASSERT(num_entries <= MAX_LOOKUP_SIDS);
 
232
 
 
233
        mapped_count = 0;
 
234
        *pmapped_count = 0;
 
235
 
 
236
        for (i = 0; i < num_entries; i++) {
 
237
                DOM_SID sid;
 
238
                uint32 rid;
 
239
                int dom_idx;
 
240
                char *full_name;
 
241
                const char *domain;
 
242
                enum SID_NAME_USE type = SID_NAME_UNKNOWN;
 
243
 
 
244
                /* Split name into domain and user component */
 
245
 
 
246
                full_name = rpcstr_pull_unistr2_talloc(mem_ctx, &name[i]);
 
247
                if (full_name == NULL) {
 
248
                        DEBUG(0, ("pull_ucs2_talloc failed\n"));
 
249
                        return NT_STATUS_NO_MEMORY;
 
250
                }
 
251
 
 
252
                DEBUG(5, ("init_lsa_sids: looking up name %s\n", full_name));
 
253
 
 
254
                /* We can ignore the result of lookup_name, it will not touch
 
255
                   "type" if it's not successful */
 
256
 
 
257
                lookup_name(mem_ctx, full_name, flags, &domain, NULL,
 
258
                            &sid, &type);
 
259
 
 
260
                switch (type) {
 
261
                case SID_NAME_USER:
 
262
                case SID_NAME_DOM_GRP:
 
263
                case SID_NAME_DOMAIN:
 
264
                case SID_NAME_ALIAS:
 
265
                case SID_NAME_WKN_GRP:
 
266
                        DEBUG(5, ("init_lsa_sids: %s found\n", full_name));
 
267
                        /* Leave these unchanged */
 
268
                        break;
 
269
                default:
 
270
                        /* Don't hand out anything but the list above */
 
271
                        DEBUG(5, ("init_lsa_sids: %s not found\n", full_name));
 
272
                        type = SID_NAME_UNKNOWN;
 
273
                        break;
 
274
                }
 
275
 
 
276
                rid = 0;
 
277
                dom_idx = -1;
 
278
 
 
279
                if (type != SID_NAME_UNKNOWN) {
 
280
                        DOM_SID domain_sid;
 
281
                        sid_copy(&domain_sid, &sid);
 
282
                        sid_split_rid(&domain_sid, &rid);
 
283
                        dom_idx = init_dom_ref(ref, domain, &domain_sid);
 
284
                        mapped_count++;
 
285
                }
 
286
 
 
287
                /* Initialize the LSA_TRANSLATED_SID3 return. */
 
288
                trans_sids[i].sid_type = type;
 
289
                trans_sids[i].sid2 = TALLOC_P(mem_ctx, DOM_SID2);
 
290
                if (trans_sids[i].sid2 == NULL) {
 
291
                        return NT_STATUS_NO_MEMORY;
 
292
                }
 
293
                init_dom_sid2(trans_sids[i].sid2, &sid);
 
294
                trans_sids[i].sid_idx = dom_idx;
 
295
        }
 
296
 
 
297
        *pmapped_count = mapped_count;
 
298
        return NT_STATUS_OK;
199
299
}
200
300
 
201
301
/***************************************************************************
204
304
 
205
305
static void init_reply_lookup_names(LSA_R_LOOKUP_NAMES *r_l,
206
306
                DOM_R_REF *ref, uint32 num_entries,
207
 
                DOM_RID2 *rid2, uint32 mapped_count)
208
 
{
209
 
        r_l->ptr_dom_ref  = 1;
210
 
        r_l->dom_ref      = ref;
211
 
 
212
 
        r_l->num_entries  = num_entries;
213
 
        r_l->ptr_entries  = 1;
214
 
        r_l->num_entries2 = num_entries;
215
 
        r_l->dom_rid      = rid2;
216
 
 
217
 
        r_l->mapped_count = mapped_count;
218
 
}
219
 
 
220
 
/***************************************************************************
221
 
 Init lsa_trans_names.
222
 
 ***************************************************************************/
223
 
 
224
 
static void init_lsa_trans_names(TALLOC_CTX *ctx, DOM_R_REF *ref, LSA_TRANS_NAME_ENUM *trn,
225
 
                                 int num_entries, DOM_SID2 *sid,
226
 
                                 uint32 *mapped_count)
227
 
{
228
 
        int i;
229
 
        int total = 0;
230
 
        *mapped_count = 0;
231
 
 
232
 
        /* Allocate memory for list of names */
233
 
 
234
 
        if (num_entries > 0) {
235
 
                if (!(trn->name = TALLOC_ARRAY(ctx, LSA_TRANS_NAME, num_entries))) {
236
 
                        DEBUG(0, ("init_lsa_trans_names(): out of memory\n"));
237
 
                        return;
238
 
                }
239
 
 
240
 
                if (!(trn->uni_name = TALLOC_ARRAY(ctx, UNISTR2, num_entries))) {
241
 
                        DEBUG(0, ("init_lsa_trans_names(): out of memory\n"));
242
 
                        return;
243
 
                }
244
 
        }
245
 
 
246
 
        become_root(); /* Need root to get to passdb to for local sids */
247
 
 
248
 
        for (i = 0; i < num_entries; i++) {
249
 
                BOOL status = False;
250
 
                DOM_SID find_sid = sid[i].sid;
251
 
                uint32 rid = 0xffffffff;
252
 
                int dom_idx = -1;
253
 
                fstring name, dom_name;
254
 
                enum SID_NAME_USE sid_name_use = (enum SID_NAME_USE)0;
255
 
 
256
 
                sid_to_string(name, &find_sid);
257
 
                DEBUG(5, ("init_lsa_trans_names: looking up sid %s\n", name));
258
 
 
259
 
                /* Lookup sid from winbindd */
260
 
 
261
 
                status = lookup_sid(&find_sid, dom_name, name, &sid_name_use);
262
 
 
263
 
                DEBUG(5, ("init_lsa_trans_names: %s\n", status ? "found" : 
264
 
                          "not found"));
265
 
 
266
 
                if (!status) {
267
 
                        sid_name_use = SID_NAME_UNKNOWN;
268
 
                        memset(dom_name, '\0', sizeof(dom_name));
269
 
                        sid_to_string(name, &find_sid);
270
 
                        dom_idx = -1;
271
 
 
272
 
                        DEBUG(10,("init_lsa_trans_names: added unknown user '%s' to "
273
 
                                  "referenced list.\n", name ));
274
 
                } else {
275
 
                        (*mapped_count)++;
276
 
                        /* Store domain sid in ref array */
277
 
                        if (find_sid.num_auths == 5) {
278
 
                                sid_split_rid(&find_sid, &rid);
279
 
                        }
280
 
                        dom_idx = init_dom_ref(ref, dom_name, &find_sid);
281
 
 
282
 
                        DEBUG(10,("init_lsa_trans_names: added %s '%s\\%s' (%d) to referenced list.\n", 
283
 
                                sid_type_lookup(sid_name_use), dom_name, name, sid_name_use ));
284
 
 
285
 
                }
286
 
 
287
 
                init_lsa_trans_name(&trn->name[total], &trn->uni_name[total],
288
 
                                        sid_name_use, name, dom_idx);
289
 
                total++;
290
 
        }
291
 
 
292
 
        unbecome_root();
293
 
 
294
 
        trn->num_entries = total;
295
 
        trn->ptr_trans_names = 1;
296
 
        trn->num_entries2 = total;
297
 
}
298
 
 
299
 
/***************************************************************************
300
 
 Init_reply_lookup_sids.
301
 
 ***************************************************************************/
302
 
 
303
 
static void init_reply_lookup_sids(LSA_R_LOOKUP_SIDS *r_l,
304
 
                DOM_R_REF *ref, LSA_TRANS_NAME_ENUM *names,
305
 
                uint32 mapped_count)
306
 
{
307
 
        r_l->ptr_dom_ref  = 1;
308
 
        r_l->dom_ref      = ref;
309
 
        r_l->names        = names;
310
 
        r_l->mapped_count = mapped_count;
 
307
                DOM_RID *rid, uint32 mapped_count)
 
308
{
 
309
        r_l->ptr_dom_ref  = 1;
 
310
        r_l->dom_ref      = ref;
 
311
 
 
312
        r_l->num_entries  = num_entries;
 
313
        r_l->ptr_entries  = 1;
 
314
        r_l->num_entries2 = num_entries;
 
315
        r_l->dom_rid      = rid;
 
316
 
 
317
        r_l->mapped_count = mapped_count;
 
318
}
 
319
 
 
320
/***************************************************************************
 
321
 init_reply_lookup_names2
 
322
 ***************************************************************************/
 
323
 
 
324
static void init_reply_lookup_names2(LSA_R_LOOKUP_NAMES2 *r_l,
 
325
                DOM_R_REF *ref, uint32 num_entries,
 
326
                DOM_RID2 *rid, uint32 mapped_count)
 
327
{
 
328
        r_l->ptr_dom_ref  = 1;
 
329
        r_l->dom_ref      = ref;
 
330
 
 
331
        r_l->num_entries  = num_entries;
 
332
        r_l->ptr_entries  = 1;
 
333
        r_l->num_entries2 = num_entries;
 
334
        r_l->dom_rid      = rid;
 
335
 
 
336
        r_l->mapped_count = mapped_count;
 
337
}
 
338
 
 
339
/***************************************************************************
 
340
 init_reply_lookup_names3
 
341
 ***************************************************************************/
 
342
 
 
343
static void init_reply_lookup_names3(LSA_R_LOOKUP_NAMES3 *r_l,
 
344
                DOM_R_REF *ref, uint32 num_entries,
 
345
                LSA_TRANSLATED_SID3 *trans_sids, uint32 mapped_count)
 
346
{
 
347
        r_l->ptr_dom_ref  = 1;
 
348
        r_l->dom_ref      = ref;
 
349
 
 
350
        r_l->num_entries  = num_entries;
 
351
        r_l->ptr_entries  = 1;
 
352
        r_l->num_entries2 = num_entries;
 
353
        r_l->trans_sids   = trans_sids;
 
354
 
 
355
        r_l->mapped_count = mapped_count;
 
356
}
 
357
 
 
358
/***************************************************************************
 
359
 init_reply_lookup_names4
 
360
 ***************************************************************************/
 
361
 
 
362
static void init_reply_lookup_names4(LSA_R_LOOKUP_NAMES4 *r_l,
 
363
                DOM_R_REF *ref, uint32 num_entries,
 
364
                LSA_TRANSLATED_SID3 *trans_sids, uint32 mapped_count)
 
365
{
 
366
        r_l->ptr_dom_ref  = 1;
 
367
        r_l->dom_ref      = ref;
 
368
 
 
369
        r_l->num_entries  = num_entries;
 
370
        r_l->ptr_entries  = 1;
 
371
        r_l->num_entries2 = num_entries;
 
372
        r_l->trans_sids   = trans_sids;
 
373
 
 
374
        r_l->mapped_count = mapped_count;
 
375
}
 
376
 
 
377
/***************************************************************************
 
378
 Init_reply_lookup_sids.
 
379
 ***************************************************************************/
 
380
 
 
381
static void init_reply_lookup_sids2(LSA_R_LOOKUP_SIDS2 *r_l,
 
382
                                DOM_R_REF *ref,
 
383
                                LSA_TRANS_NAME_ENUM2 *names,
 
384
                                uint32 mapped_count)
 
385
{
 
386
        r_l->ptr_dom_ref  = ref ? 1 : 0;
 
387
        r_l->dom_ref      = ref;
 
388
        r_l->names        = names;
 
389
        r_l->mapped_count = mapped_count;
 
390
}
 
391
 
 
392
/***************************************************************************
 
393
 Init_reply_lookup_sids.
 
394
 ***************************************************************************/
 
395
 
 
396
static void init_reply_lookup_sids3(LSA_R_LOOKUP_SIDS3 *r_l,
 
397
                                DOM_R_REF *ref,
 
398
                                LSA_TRANS_NAME_ENUM2 *names,
 
399
                                uint32 mapped_count)
 
400
{
 
401
        r_l->ptr_dom_ref  = ref ? 1 : 0;
 
402
        r_l->dom_ref      = ref;
 
403
        r_l->names        = names;
 
404
        r_l->mapped_count = mapped_count;
 
405
}
 
406
 
 
407
/***************************************************************************
 
408
 Init_reply_lookup_sids.
 
409
 ***************************************************************************/
 
410
 
 
411
static NTSTATUS init_reply_lookup_sids(TALLOC_CTX *mem_ctx,
 
412
                                LSA_R_LOOKUP_SIDS *r_l,
 
413
                                DOM_R_REF *ref,
 
414
                                LSA_TRANS_NAME_ENUM2 *names,
 
415
                                uint32 mapped_count)
 
416
{
 
417
        LSA_TRANS_NAME_ENUM *oldnames = TALLOC_ZERO_P(mem_ctx, LSA_TRANS_NAME_ENUM);
 
418
 
 
419
        if (!oldnames) {
 
420
                return NT_STATUS_NO_MEMORY;
 
421
        }
 
422
 
 
423
        oldnames->num_entries = names->num_entries;
 
424
        oldnames->ptr_trans_names = names->ptr_trans_names;
 
425
        oldnames->num_entries2 = names->num_entries2;
 
426
        oldnames->uni_name = names->uni_name;
 
427
 
 
428
        if (names->num_entries) {
 
429
                int i;
 
430
 
 
431
                oldnames->name = TALLOC_ARRAY(oldnames, LSA_TRANS_NAME, names->num_entries);
 
432
 
 
433
                if (!oldnames->name) {
 
434
                        return NT_STATUS_NO_MEMORY;
 
435
                }
 
436
                for (i = 0; i < names->num_entries; i++) {
 
437
                        oldnames->name[i].sid_name_use = names->name[i].sid_name_use;
 
438
                        oldnames->name[i].hdr_name = names->name[i].hdr_name;
 
439
                        oldnames->name[i].domain_idx = names->name[i].domain_idx;
 
440
                }
 
441
        }
 
442
 
 
443
        r_l->ptr_dom_ref  = ref ? 1 : 0;
 
444
        r_l->dom_ref      = ref;
 
445
        r_l->names        = oldnames;
 
446
        r_l->mapped_count = mapped_count;
 
447
        return NT_STATUS_OK;
311
448
}
312
449
 
313
450
static NTSTATUS lsa_get_generic_sd(TALLOC_CTX *mem_ctx, SEC_DESC **sd, size_t *sd_size)
485
622
 ufff, done :)  mimir
486
623
 ***************************************************************************/
487
624
 
488
 
NTSTATUS _lsa_enum_trust_dom(pipes_struct *p, LSA_Q_ENUM_TRUST_DOM *q_u, LSA_R_ENUM_TRUST_DOM *r_u)
 
625
NTSTATUS _lsa_enum_trust_dom(pipes_struct *p, LSA_Q_ENUM_TRUST_DOM *q_u,
 
626
                             LSA_R_ENUM_TRUST_DOM *r_u)
489
627
{
490
628
        struct lsa_info *info;
491
 
        uint32 enum_context = q_u->enum_context;
 
629
        uint32 next_idx;
 
630
        struct trustdom_info **domains;
492
631
 
493
632
        /*
494
633
         * preferred length is set to 5 as a "our" preferred length
496
635
         * update (20.08.2002): it's not preferred length, but preferred size!
497
636
         * it needs further investigation how to optimally choose this value
498
637
         */
499
 
        uint32 max_num_domains = q_u->preferred_len < 5 ? q_u->preferred_len : 10;
500
 
        TRUSTDOM **trust_doms;
 
638
        uint32 max_num_domains =
 
639
                q_u->preferred_len < 5 ? q_u->preferred_len : 10;
501
640
        uint32 num_domains;
502
641
        NTSTATUS nt_status;
 
642
        uint32 num_thistime;
503
643
 
504
644
        if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info))
505
645
                return NT_STATUS_INVALID_HANDLE;
508
648
        if (!(info->access & POLICY_VIEW_LOCAL_INFORMATION))
509
649
                return NT_STATUS_ACCESS_DENIED;
510
650
 
511
 
        nt_status = secrets_get_trusted_domains(p->mem_ctx, (int *)&enum_context, max_num_domains, (int *)&num_domains, &trust_doms);
 
651
        nt_status = secrets_trusted_domains(p->mem_ctx, &num_domains,
 
652
                                            &domains);
512
653
 
513
 
        if (!NT_STATUS_IS_OK(nt_status) &&
514
 
            !NT_STATUS_EQUAL(nt_status, STATUS_MORE_ENTRIES) &&
515
 
            !NT_STATUS_EQUAL(nt_status, NT_STATUS_NO_MORE_ENTRIES)) {
 
654
        if (!NT_STATUS_IS_OK(nt_status)) {
516
655
                return nt_status;
 
656
        }
 
657
 
 
658
        if (q_u->enum_context < num_domains) {
 
659
                num_thistime = MIN(num_domains, max_num_domains);
 
660
 
 
661
                r_u->status = STATUS_MORE_ENTRIES;
 
662
 
 
663
                if (q_u->enum_context + num_thistime > num_domains) {
 
664
                        num_thistime = num_domains - q_u->enum_context;
 
665
                        r_u->status = NT_STATUS_OK;
 
666
                }
 
667
 
 
668
                next_idx = q_u->enum_context + num_thistime;
517
669
        } else {
518
 
                r_u->status = nt_status;
 
670
                num_thistime = 0;
 
671
                next_idx = 0xffffffff;
 
672
                r_u->status = NT_STATUS_NO_MORE_ENTRIES;
519
673
        }
520
 
 
 
674
                
521
675
        /* set up the lsa_enum_trust_dom response */
522
676
 
523
 
        init_r_enum_trust_dom(p->mem_ctx, r_u, enum_context, max_num_domains, num_domains, trust_doms);
 
677
        init_r_enum_trust_dom(p->mem_ctx, r_u, next_idx,
 
678
                              num_thistime, domains+q_u->enum_context);
524
679
 
525
680
        return r_u->status;
526
681
}
532
687
NTSTATUS _lsa_query_info(pipes_struct *p, LSA_Q_QUERY_INFO *q_u, LSA_R_QUERY_INFO *r_u)
533
688
{
534
689
        struct lsa_info *handle;
535
 
        LSA_INFO_UNION *info = &r_u->dom;
 
690
        LSA_INFO_CTR *ctr = &r_u->ctr;
536
691
        DOM_SID domain_sid;
537
692
        const char *name;
538
693
        DOM_SID *sid = NULL;
545
700
        switch (q_u->info_class) {
546
701
        case 0x02:
547
702
                {
548
 
                unsigned int i;
 
703
 
 
704
                uint32 policy_def = LSA_AUDIT_POLICY_ALL;
 
705
                
549
706
                /* check if the user have enough rights */
550
 
                if (!(handle->access & POLICY_VIEW_AUDIT_INFORMATION))
 
707
                if (!(handle->access & POLICY_VIEW_AUDIT_INFORMATION)) {
 
708
                        DEBUG(10,("_lsa_query_info: insufficient access rights\n"));
551
709
                        return NT_STATUS_ACCESS_DENIED;
 
710
                }
552
711
 
553
712
                /* fake info: We audit everything. ;) */
554
 
                info->id2.auditing_enabled = 1;
555
 
                info->id2.count1 = 7;
556
 
                info->id2.count2 = 7;
557
 
                if ((info->id2.auditsettings = TALLOC_ARRAY(p->mem_ctx,uint32, 7)) == NULL)
 
713
                ctr->info.id2.ptr = 1;
 
714
                ctr->info.id2.auditing_enabled = True;
 
715
                ctr->info.id2.count1 = ctr->info.id2.count2 = LSA_AUDIT_NUM_CATEGORIES;
 
716
 
 
717
                if ((ctr->info.id2.auditsettings = TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, LSA_AUDIT_NUM_CATEGORIES)) == NULL)
558
718
                        return NT_STATUS_NO_MEMORY;
559
 
                for (i = 0; i < 7; i++)
560
 
                        info->id2.auditsettings[i] = 3;
 
719
 
 
720
                ctr->info.id2.auditsettings[LSA_AUDIT_CATEGORY_ACCOUNT_MANAGEMENT] = policy_def;
 
721
                ctr->info.id2.auditsettings[LSA_AUDIT_CATEGORY_FILE_AND_OBJECT_ACCESS] = policy_def; 
 
722
                ctr->info.id2.auditsettings[LSA_AUDIT_CATEGORY_LOGON] = policy_def; 
 
723
                ctr->info.id2.auditsettings[LSA_AUDIT_CATEGORY_PROCCESS_TRACKING] = policy_def; 
 
724
                ctr->info.id2.auditsettings[LSA_AUDIT_CATEGORY_SECURITY_POLICY_CHANGES] = policy_def;
 
725
                ctr->info.id2.auditsettings[LSA_AUDIT_CATEGORY_SYSTEM] = policy_def;
 
726
                ctr->info.id2.auditsettings[LSA_AUDIT_CATEGORY_USE_OF_USER_RIGHTS] = policy_def; 
 
727
 
561
728
                break;
562
729
                }
563
730
        case 0x03:
587
754
                        default:
588
755
                                return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
589
756
                }
590
 
                init_dom_query(&r_u->dom.id3, name, sid);
 
757
                init_dom_query_3(&r_u->ctr.info.id3, name, sid);
591
758
                break;
592
759
        case 0x05:
593
760
                /* check if the user have enough rights */
597
764
                /* Request PolicyAccountDomainInformation. */
598
765
                name = get_global_sam_name();
599
766
                sid = get_global_sam_sid();
600
 
                init_dom_query(&r_u->dom.id5, name, sid);
 
767
                init_dom_query_5(&r_u->ctr.info.id5, name, sid);
601
768
                break;
602
769
        case 0x06:
603
770
                /* check if the user have enough rights */
610
777
                                 * only a BDC is a backup controller
611
778
                                 * of the domain, it controls.
612
779
                                 */
613
 
                                info->id6.server_role = 2;
 
780
                                ctr->info.id6.server_role = 2;
614
781
                                break;
615
782
                        default:
616
783
                                /*
617
784
                                 * any other role is a primary
618
785
                                 * of the domain, it controls.
619
786
                                 */
620
 
                                info->id6.server_role = 3;
 
787
                                ctr->info.id6.server_role = 3;
621
788
                                break; 
622
789
                }
623
790
                break;
628
795
        }
629
796
 
630
797
        if (NT_STATUS_IS_OK(r_u->status)) {
631
 
                r_u->undoc_buffer = 0x22000000; /* bizarre */
632
 
                r_u->info_class = q_u->info_class;
 
798
                r_u->dom_ptr = 0x22000000; /* bizarre */
 
799
                ctr->info_class = q_u->info_class;
633
800
        }
634
801
 
635
802
        return r_u->status;
636
803
}
637
804
 
638
805
/***************************************************************************
 
806
 _lsa_lookup_sids_internal
 
807
 ***************************************************************************/
 
808
 
 
809
static NTSTATUS _lsa_lookup_sids_internal(pipes_struct *p,
 
810
                                uint16 level,                           /* input */
 
811
                                int num_sids,                           /* input */
 
812
                                const DOM_SID2 *sid,                    /* input */
 
813
                                DOM_R_REF **pp_ref,                     /* output */
 
814
                                LSA_TRANS_NAME_ENUM2 **pp_names,        /* output */
 
815
                                uint32 *pp_mapped_count)
 
816
{
 
817
        NTSTATUS status;
 
818
        int i;
 
819
        const DOM_SID **sids = NULL;
 
820
        LSA_TRANS_NAME_ENUM2 *names = NULL;
 
821
        DOM_R_REF *ref = NULL;
 
822
        uint32 mapped_count = 0;
 
823
        struct lsa_dom_info *dom_infos = NULL;
 
824
        struct lsa_name_info *name_infos = NULL;
 
825
 
 
826
        *pp_mapped_count = 0;
 
827
        *pp_ref = NULL;
 
828
        *pp_names = NULL;
 
829
        
 
830
        names = TALLOC_ZERO_P(p->mem_ctx, LSA_TRANS_NAME_ENUM2);
 
831
        sids = TALLOC_ARRAY(p->mem_ctx, const DOM_SID *, num_sids);
 
832
        ref = TALLOC_ZERO_P(p->mem_ctx, DOM_R_REF);
 
833
 
 
834
        if (sids == NULL || names == NULL || ref == NULL) {
 
835
                return NT_STATUS_NO_MEMORY;
 
836
        }
 
837
 
 
838
        for (i=0; i<num_sids; i++) {
 
839
                sids[i] = &sid[i].sid;
 
840
        }
 
841
 
 
842
        status = lookup_sids(p->mem_ctx, num_sids, sids, level,
 
843
                                  &dom_infos, &name_infos);
 
844
 
 
845
        if (!NT_STATUS_IS_OK(status)) {
 
846
                return status;
 
847
        }
 
848
 
 
849
        if (num_sids > 0) {
 
850
                names->name = TALLOC_ARRAY(names, LSA_TRANS_NAME2, num_sids);
 
851
                names->uni_name = TALLOC_ARRAY(names, UNISTR2, num_sids);
 
852
                if ((names->name == NULL) || (names->uni_name == NULL)) {
 
853
                        return NT_STATUS_NO_MEMORY;
 
854
                }
 
855
        }
 
856
 
 
857
        for (i=0; i<MAX_REF_DOMAINS; i++) {
 
858
 
 
859
                if (!dom_infos[i].valid) {
 
860
                        break;
 
861
                }
 
862
 
 
863
                if (init_dom_ref(ref, dom_infos[i].name,
 
864
                                 &dom_infos[i].sid) != i) {
 
865
                        DEBUG(0, ("Domain %s mentioned twice??\n",
 
866
                                  dom_infos[i].name));
 
867
                        return NT_STATUS_INTERNAL_ERROR;
 
868
                }
 
869
        }
 
870
 
 
871
        for (i=0; i<num_sids; i++) {
 
872
                struct lsa_name_info *name = &name_infos[i];
 
873
 
 
874
                if (name->type == SID_NAME_UNKNOWN) {
 
875
                        name->dom_idx = -1;
 
876
                        /* unknown sids should return the string representation of the SID */
 
877
                        name->name = talloc_asprintf(p->mem_ctx, "%s", 
 
878
                                                     sid_string_static(sids[i]));
 
879
                        if (name->name == NULL) {
 
880
                                return NT_STATUS_NO_MEMORY;
 
881
                        }
 
882
                } else {
 
883
                        mapped_count += 1;
 
884
                }
 
885
                init_lsa_trans_name2(&names->name[i], &names->uni_name[i],
 
886
                                    name->type, name->name, name->dom_idx);
 
887
        }
 
888
 
 
889
        names->num_entries = num_sids;
 
890
        names->ptr_trans_names = 1;
 
891
        names->num_entries2 = num_sids;
 
892
 
 
893
        status = NT_STATUS_NONE_MAPPED;
 
894
        if (mapped_count > 0) {
 
895
                status = (mapped_count < num_sids) ?
 
896
                        STATUS_SOME_UNMAPPED : NT_STATUS_OK;
 
897
        }
 
898
 
 
899
        DEBUG(10, ("num_sids %d, mapped_count %d, status %s\n",
 
900
                   num_sids, mapped_count, nt_errstr(status)));
 
901
 
 
902
        *pp_mapped_count = mapped_count;
 
903
        *pp_ref = ref;
 
904
        *pp_names = names;
 
905
 
 
906
        return status;
 
907
}
 
908
 
 
909
/***************************************************************************
639
910
 _lsa_lookup_sids
640
911
 ***************************************************************************/
641
912
 
642
 
NTSTATUS _lsa_lookup_sids(pipes_struct *p, LSA_Q_LOOKUP_SIDS *q_u, LSA_R_LOOKUP_SIDS *r_u)
643
 
{
644
 
        struct lsa_info *handle;
645
 
        DOM_SID2 *sid = q_u->sids.sid;
646
 
        int num_entries = q_u->sids.num_entries;
647
 
        DOM_R_REF *ref = NULL;
648
 
        LSA_TRANS_NAME_ENUM *names = NULL;
649
 
        uint32 mapped_count = 0;
650
 
 
651
 
        if (num_entries >  MAX_LOOKUP_SIDS) {
652
 
                num_entries = 0;
653
 
                DEBUG(5,("_lsa_lookup_sids: limit of %d exceeded, truncating SID lookup list to %d\n", MAX_LOOKUP_SIDS, num_entries));
654
 
                r_u->status = NT_STATUS_NONE_MAPPED;
655
 
        }
656
 
 
657
 
        ref = TALLOC_ZERO_P(p->mem_ctx, DOM_R_REF);
658
 
        names = TALLOC_ZERO_P(p->mem_ctx, LSA_TRANS_NAME_ENUM);
659
 
 
660
 
        if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle)) {
661
 
                r_u->status = NT_STATUS_INVALID_HANDLE;
662
 
                goto done;
 
913
NTSTATUS _lsa_lookup_sids(pipes_struct *p,
 
914
                          LSA_Q_LOOKUP_SIDS *q_u,
 
915
                          LSA_R_LOOKUP_SIDS *r_u)
 
916
{
 
917
        struct lsa_info *handle;
 
918
        int num_sids = q_u->sids.num_entries;
 
919
        uint32 mapped_count = 0;
 
920
        DOM_R_REF *ref = NULL;
 
921
        LSA_TRANS_NAME_ENUM2 *names = NULL;
 
922
        NTSTATUS status;
 
923
 
 
924
        if ((q_u->level < 1) || (q_u->level > 6)) {
 
925
                return NT_STATUS_INVALID_PARAMETER;
 
926
        }
 
927
 
 
928
        if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle)) {
 
929
                return NT_STATUS_INVALID_HANDLE;
 
930
        }
 
931
 
 
932
        /* check if the user has enough rights */
 
933
        if (!(handle->access & POLICY_LOOKUP_NAMES)) {
 
934
                return NT_STATUS_ACCESS_DENIED;
 
935
        }
 
936
 
 
937
        if (num_sids >  MAX_LOOKUP_SIDS) {
 
938
                DEBUG(5,("_lsa_lookup_sids: limit of %d exceeded, requested %d\n",
 
939
                         MAX_LOOKUP_SIDS, num_sids));
 
940
                return NT_STATUS_NONE_MAPPED;
 
941
        }
 
942
 
 
943
        r_u->status = _lsa_lookup_sids_internal(p,
 
944
                                                q_u->level,
 
945
                                                num_sids, 
 
946
                                                q_u->sids.sid,
 
947
                                                &ref,
 
948
                                                &names,
 
949
                                                &mapped_count);
 
950
 
 
951
        /* Convert from LSA_TRANS_NAME_ENUM2 to LSA_TRANS_NAME_ENUM */
 
952
 
 
953
        status = init_reply_lookup_sids(p->mem_ctx, r_u, ref, names, mapped_count);
 
954
        if (!NT_STATUS_IS_OK(status)) {
 
955
                return status;
 
956
        }
 
957
        return r_u->status;
 
958
}
 
959
 
 
960
/***************************************************************************
 
961
 _lsa_lookup_sids2
 
962
 ***************************************************************************/
 
963
 
 
964
NTSTATUS _lsa_lookup_sids2(pipes_struct *p,
 
965
                          LSA_Q_LOOKUP_SIDS2 *q_u,
 
966
                          LSA_R_LOOKUP_SIDS2 *r_u)
 
967
{
 
968
        struct lsa_info *handle;
 
969
        int num_sids = q_u->sids.num_entries;
 
970
        uint32 mapped_count = 0;
 
971
        DOM_R_REF *ref = NULL;
 
972
        LSA_TRANS_NAME_ENUM2 *names = NULL;
 
973
 
 
974
        if ((q_u->level < 1) || (q_u->level > 6)) {
 
975
                return NT_STATUS_INVALID_PARAMETER;
 
976
        }
 
977
 
 
978
        if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle)) {
 
979
                return NT_STATUS_INVALID_HANDLE;
663
980
        }
664
981
 
665
982
        /* check if the user have enough rights */
666
983
        if (!(handle->access & POLICY_LOOKUP_NAMES)) {
667
 
                r_u->status = NT_STATUS_ACCESS_DENIED;
668
 
                goto done;
669
 
        }
670
 
        if (!ref || !names)
671
 
                return NT_STATUS_NO_MEMORY;
672
 
 
673
 
done:
674
 
 
675
 
        /* set up the LSA Lookup SIDs response */
676
 
        init_lsa_trans_names(p->mem_ctx, ref, names, num_entries, sid, &mapped_count);
677
 
        if (NT_STATUS_IS_OK(r_u->status)) {
678
 
                if (mapped_count == 0)
679
 
                        r_u->status = NT_STATUS_NONE_MAPPED;
680
 
                else if (mapped_count != num_entries)
681
 
                        r_u->status = STATUS_SOME_UNMAPPED;
682
 
        }
683
 
        init_reply_lookup_sids(r_u, ref, names, mapped_count);
684
 
 
 
984
                return NT_STATUS_ACCESS_DENIED;
 
985
        }
 
986
 
 
987
        if (num_sids >  MAX_LOOKUP_SIDS) {
 
988
                DEBUG(5,("_lsa_lookup_sids2: limit of %d exceeded, requested %d\n",
 
989
                         MAX_LOOKUP_SIDS, num_sids));
 
990
                return NT_STATUS_NONE_MAPPED;
 
991
        }
 
992
 
 
993
        r_u->status = _lsa_lookup_sids_internal(p,
 
994
                                                q_u->level,
 
995
                                                num_sids, 
 
996
                                                q_u->sids.sid,
 
997
                                                &ref,
 
998
                                                &names,
 
999
                                                &mapped_count);
 
1000
 
 
1001
        init_reply_lookup_sids2(r_u, ref, names, mapped_count);
 
1002
        return r_u->status;
 
1003
}
 
1004
 
 
1005
/***************************************************************************
 
1006
 _lsa_lookup_sida3
 
1007
 ***************************************************************************/
 
1008
 
 
1009
NTSTATUS _lsa_lookup_sids3(pipes_struct *p,
 
1010
                          LSA_Q_LOOKUP_SIDS3 *q_u,
 
1011
                          LSA_R_LOOKUP_SIDS3 *r_u)
 
1012
{
 
1013
        int num_sids = q_u->sids.num_entries;
 
1014
        uint32 mapped_count = 0;
 
1015
        DOM_R_REF *ref = NULL;
 
1016
        LSA_TRANS_NAME_ENUM2 *names = NULL;
 
1017
 
 
1018
        if ((q_u->level < 1) || (q_u->level > 6)) {
 
1019
                return NT_STATUS_INVALID_PARAMETER;
 
1020
        }
 
1021
 
 
1022
        /* No policy handle on this call. Restrict to crypto connections. */
 
1023
        if (p->auth.auth_type != PIPE_AUTH_TYPE_SCHANNEL) {
 
1024
                DEBUG(0,("_lsa_lookup_sids3: client %s not using schannel for netlogon\n",
 
1025
                        get_remote_machine_name() ));
 
1026
                return NT_STATUS_INVALID_PARAMETER;
 
1027
        }
 
1028
 
 
1029
        if (num_sids >  MAX_LOOKUP_SIDS) {
 
1030
                DEBUG(5,("_lsa_lookup_sids3: limit of %d exceeded, requested %d\n",
 
1031
                         MAX_LOOKUP_SIDS, num_sids));
 
1032
                return NT_STATUS_NONE_MAPPED;
 
1033
        }
 
1034
 
 
1035
        r_u->status = _lsa_lookup_sids_internal(p,
 
1036
                                                q_u->level,
 
1037
                                                num_sids, 
 
1038
                                                q_u->sids.sid,
 
1039
                                                &ref,
 
1040
                                                &names,
 
1041
                                                &mapped_count);
 
1042
 
 
1043
        init_reply_lookup_sids3(r_u, ref, names, mapped_count);
685
1044
        return r_u->status;
686
1045
}
687
1046
 
693
1052
{
694
1053
        struct lsa_info *handle;
695
1054
        UNISTR2 *names = q_u->uni_name;
696
 
        int num_entries = q_u->num_entries;
 
1055
        uint32 num_entries = q_u->num_entries;
697
1056
        DOM_R_REF *ref;
698
 
        DOM_RID2 *rids;
 
1057
        DOM_RID *rids;
699
1058
        uint32 mapped_count = 0;
 
1059
        int flags = 0;
700
1060
 
701
1061
        if (num_entries >  MAX_LOOKUP_SIDS) {
702
1062
                num_entries = MAX_LOOKUP_SIDS;
703
1063
                DEBUG(5,("_lsa_lookup_names: truncating name lookup list to %d\n", num_entries));
704
1064
        }
705
1065
                
 
1066
        /* Probably the lookup_level is some sort of bitmask. */
 
1067
        if (q_u->lookup_level == 1) {
 
1068
                flags = LOOKUP_NAME_ALL;
 
1069
        }
 
1070
 
706
1071
        ref = TALLOC_ZERO_P(p->mem_ctx, DOM_R_REF);
707
 
        rids = TALLOC_ZERO_ARRAY(p->mem_ctx, DOM_RID2, num_entries);
 
1072
        rids = TALLOC_ZERO_ARRAY(p->mem_ctx, DOM_RID, num_entries);
708
1073
 
709
1074
        if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle)) {
710
1075
                r_u->status = NT_STATUS_INVALID_HANDLE;
720
1085
        if (!ref || !rids)
721
1086
                return NT_STATUS_NO_MEMORY;
722
1087
 
 
1088
        /* set up the LSA Lookup RIDs response */
 
1089
        become_root(); /* lookup_name can require root privs */
 
1090
        r_u->status = lookup_lsa_rids(p->mem_ctx, ref, rids, num_entries,
 
1091
                                      names, flags, &mapped_count);
 
1092
        unbecome_root();
 
1093
 
723
1094
done:
724
1095
 
725
 
        /* set up the LSA Lookup RIDs response */
726
 
        init_lsa_rid2s(ref, rids, num_entries, names, &mapped_count, p->endian);
727
 
        if (NT_STATUS_IS_OK(r_u->status)) {
 
1096
        if (NT_STATUS_IS_OK(r_u->status) && (num_entries != 0) ) {
728
1097
                if (mapped_count == 0)
729
1098
                        r_u->status = NT_STATUS_NONE_MAPPED;
730
1099
                else if (mapped_count != num_entries)
731
1100
                        r_u->status = STATUS_SOME_UNMAPPED;
732
1101
        }
 
1102
 
733
1103
        init_reply_lookup_names(r_u, ref, num_entries, rids, mapped_count);
734
 
 
 
1104
        return r_u->status;
 
1105
}
 
1106
 
 
1107
/***************************************************************************
 
1108
lsa_reply_lookup_names2
 
1109
 ***************************************************************************/
 
1110
 
 
1111
NTSTATUS _lsa_lookup_names2(pipes_struct *p, LSA_Q_LOOKUP_NAMES2 *q_u, LSA_R_LOOKUP_NAMES2 *r_u)
 
1112
{
 
1113
        struct lsa_info *handle;
 
1114
        UNISTR2 *names = q_u->uni_name;
 
1115
        uint32 num_entries = q_u->num_entries;
 
1116
        DOM_R_REF *ref;
 
1117
        DOM_RID *rids;
 
1118
        DOM_RID2 *rids2;
 
1119
        int i;
 
1120
        uint32 mapped_count = 0;
 
1121
        int flags = 0;
 
1122
 
 
1123
        if (num_entries >  MAX_LOOKUP_SIDS) {
 
1124
                num_entries = MAX_LOOKUP_SIDS;
 
1125
                DEBUG(5,("_lsa_lookup_names2: truncating name lookup list to %d\n", num_entries));
 
1126
        }
 
1127
                
 
1128
        /* Probably the lookup_level is some sort of bitmask. */
 
1129
        if (q_u->lookup_level == 1) {
 
1130
                flags = LOOKUP_NAME_ALL;
 
1131
        }
 
1132
 
 
1133
        ref = TALLOC_ZERO_P(p->mem_ctx, DOM_R_REF);
 
1134
        rids = TALLOC_ZERO_ARRAY(p->mem_ctx, DOM_RID, num_entries);
 
1135
        rids2 = TALLOC_ZERO_ARRAY(p->mem_ctx, DOM_RID2, num_entries);
 
1136
 
 
1137
        if ((ref == NULL) || (rids == NULL) || (rids2 == NULL)) {
 
1138
                r_u->status = NT_STATUS_NO_MEMORY;
 
1139
                return NT_STATUS_NO_MEMORY;
 
1140
        }
 
1141
 
 
1142
        if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle)) {
 
1143
                r_u->status = NT_STATUS_INVALID_HANDLE;
 
1144
                goto done;
 
1145
        }
 
1146
 
 
1147
        /* check if the user have enough rights */
 
1148
        if (!(handle->access & POLICY_LOOKUP_NAMES)) {
 
1149
                r_u->status = NT_STATUS_ACCESS_DENIED;
 
1150
                goto done;
 
1151
        }
 
1152
 
 
1153
        /* set up the LSA Lookup RIDs response */
 
1154
        become_root(); /* lookup_name can require root privs */
 
1155
        r_u->status = lookup_lsa_rids(p->mem_ctx, ref, rids, num_entries,
 
1156
                                      names, flags, &mapped_count);
 
1157
        unbecome_root();
 
1158
 
 
1159
done:
 
1160
 
 
1161
        if (NT_STATUS_IS_OK(r_u->status)) {
 
1162
                if (mapped_count == 0) {
 
1163
                        r_u->status = NT_STATUS_NONE_MAPPED;
 
1164
                } else if (mapped_count != num_entries) {
 
1165
                        r_u->status = STATUS_SOME_UNMAPPED;
 
1166
                }
 
1167
        }
 
1168
 
 
1169
        /* Convert the rids array to rids2. */
 
1170
        for (i = 0; i < num_entries; i++) {
 
1171
                rids2[i].type = rids[i].type;
 
1172
                rids2[i].rid = rids[i].rid;
 
1173
                rids2[i].rid_idx = rids[i].rid_idx;
 
1174
                rids2[i].unknown = 0;
 
1175
        }
 
1176
 
 
1177
        init_reply_lookup_names2(r_u, ref, num_entries, rids2, mapped_count);
 
1178
        return r_u->status;
 
1179
}
 
1180
 
 
1181
/***************************************************************************
 
1182
lsa_reply_lookup_names3.
 
1183
 ***************************************************************************/
 
1184
 
 
1185
NTSTATUS _lsa_lookup_names3(pipes_struct *p, LSA_Q_LOOKUP_NAMES3 *q_u, LSA_R_LOOKUP_NAMES3 *r_u)
 
1186
{
 
1187
        struct lsa_info *handle;
 
1188
        UNISTR2 *names = q_u->uni_name;
 
1189
        uint32 num_entries = q_u->num_entries;
 
1190
        DOM_R_REF *ref = NULL;
 
1191
        LSA_TRANSLATED_SID3 *trans_sids = NULL;
 
1192
        uint32 mapped_count = 0;
 
1193
        int flags = 0;
 
1194
 
 
1195
        if (num_entries >  MAX_LOOKUP_SIDS) {
 
1196
                num_entries = MAX_LOOKUP_SIDS;
 
1197
                DEBUG(5,("_lsa_lookup_names3: truncating name lookup list to %d\n", num_entries));
 
1198
        }
 
1199
                
 
1200
        /* Probably the lookup_level is some sort of bitmask. */
 
1201
        if (q_u->lookup_level == 1) {
 
1202
                flags = LOOKUP_NAME_ALL;
 
1203
        }
 
1204
 
 
1205
        ref = TALLOC_ZERO_P(p->mem_ctx, DOM_R_REF);
 
1206
        trans_sids = TALLOC_ZERO_ARRAY(p->mem_ctx, LSA_TRANSLATED_SID3, num_entries);
 
1207
 
 
1208
        if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle)) {
 
1209
                r_u->status = NT_STATUS_INVALID_HANDLE;
 
1210
                goto done;
 
1211
        }
 
1212
 
 
1213
        /* check if the user have enough rights */
 
1214
        if (!(handle->access & POLICY_LOOKUP_NAMES)) {
 
1215
                r_u->status = NT_STATUS_ACCESS_DENIED;
 
1216
                goto done;
 
1217
        }
 
1218
 
 
1219
        if (!ref || !trans_sids) {
 
1220
                return NT_STATUS_NO_MEMORY;
 
1221
        }
 
1222
 
 
1223
        /* set up the LSA Lookup SIDs response */
 
1224
        become_root(); /* lookup_name can require root privs */
 
1225
        r_u->status = lookup_lsa_sids(p->mem_ctx, ref, trans_sids, num_entries,
 
1226
                                      names, flags, &mapped_count);
 
1227
        unbecome_root();
 
1228
 
 
1229
done:
 
1230
 
 
1231
        if (NT_STATUS_IS_OK(r_u->status)) {
 
1232
                if (mapped_count == 0) {
 
1233
                        r_u->status = NT_STATUS_NONE_MAPPED;
 
1234
                } else if (mapped_count != num_entries) {
 
1235
                        r_u->status = STATUS_SOME_UNMAPPED;
 
1236
                }
 
1237
        }
 
1238
 
 
1239
        init_reply_lookup_names3(r_u, ref, num_entries, trans_sids, mapped_count);
 
1240
        return r_u->status;
 
1241
}
 
1242
 
 
1243
/***************************************************************************
 
1244
lsa_reply_lookup_names4.
 
1245
 ***************************************************************************/
 
1246
 
 
1247
NTSTATUS _lsa_lookup_names4(pipes_struct *p, LSA_Q_LOOKUP_NAMES4 *q_u, LSA_R_LOOKUP_NAMES4 *r_u)
 
1248
{
 
1249
        UNISTR2 *names = q_u->uni_name;
 
1250
        uint32 num_entries = q_u->num_entries;
 
1251
        DOM_R_REF *ref = NULL;
 
1252
        LSA_TRANSLATED_SID3 *trans_sids = NULL;
 
1253
        uint32 mapped_count = 0;
 
1254
        int flags = 0;
 
1255
 
 
1256
        if (num_entries >  MAX_LOOKUP_SIDS) {
 
1257
                num_entries = MAX_LOOKUP_SIDS;
 
1258
                DEBUG(5,("_lsa_lookup_names4: truncating name lookup list to %d\n", num_entries));
 
1259
        }
 
1260
                
 
1261
        /* Probably the lookup_level is some sort of bitmask. */
 
1262
        if (q_u->lookup_level == 1) {
 
1263
                flags = LOOKUP_NAME_ALL;
 
1264
        }
 
1265
 
 
1266
        /* No policy handle on this call. Restrict to crypto connections. */
 
1267
        if (p->auth.auth_type != PIPE_AUTH_TYPE_SCHANNEL) {
 
1268
                DEBUG(0,("_lsa_lookup_names4: client %s not using schannel for netlogon\n",
 
1269
                        get_remote_machine_name() ));
 
1270
                return NT_STATUS_INVALID_PARAMETER;
 
1271
        }
 
1272
 
 
1273
        ref = TALLOC_ZERO_P(p->mem_ctx, DOM_R_REF);
 
1274
        trans_sids = TALLOC_ZERO_ARRAY(p->mem_ctx, LSA_TRANSLATED_SID3, num_entries);
 
1275
 
 
1276
        if (!ref || !trans_sids) {
 
1277
                return NT_STATUS_NO_MEMORY;
 
1278
        }
 
1279
 
 
1280
        /* set up the LSA Lookup SIDs response */
 
1281
        become_root(); /* lookup_name can require root privs */
 
1282
        r_u->status = lookup_lsa_sids(p->mem_ctx, ref, trans_sids, num_entries,
 
1283
                                      names, flags, &mapped_count);
 
1284
        unbecome_root();
 
1285
 
 
1286
        if (NT_STATUS_IS_OK(r_u->status)) {
 
1287
                if (mapped_count == 0) {
 
1288
                        r_u->status = NT_STATUS_NONE_MAPPED;
 
1289
                } else if (mapped_count != num_entries) {
 
1290
                        r_u->status = STATUS_SOME_UNMAPPED;
 
1291
                }
 
1292
        }
 
1293
 
 
1294
        init_reply_lookup_names4(r_u, ref, num_entries, trans_sids, mapped_count);
735
1295
        return r_u->status;
736
1296
}
737
1297
 
741
1301
 
742
1302
NTSTATUS _lsa_close(pipes_struct *p, LSA_Q_CLOSE *q_u, LSA_R_CLOSE *r_u)
743
1303
{
744
 
        if (!find_policy_by_hnd(p, &q_u->pol, NULL))
 
1304
        if (!find_policy_by_hnd(p, &q_u->pol, NULL)) {
745
1305
                return NT_STATUS_INVALID_HANDLE;
 
1306
        }
746
1307
 
747
1308
        close_policy_hnd(p, &q_u->pol);
748
1309
        return NT_STATUS_OK;
1109
1670
NTSTATUS _lsa_getsystemaccount(pipes_struct *p, LSA_Q_GETSYSTEMACCOUNT *q_u, LSA_R_GETSYSTEMACCOUNT *r_u)
1110
1671
{
1111
1672
        struct lsa_info *info=NULL;
1112
 
        fstring name, dom_name;
1113
 
        enum SID_NAME_USE type;
1114
1673
 
1115
1674
        /* find the connection policy handle. */
1116
1675
 
1117
1676
        if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info))
1118
1677
                return NT_STATUS_INVALID_HANDLE;
1119
1678
 
1120
 
        if (!lookup_sid(&info->sid, dom_name, name, &type))
 
1679
        if (!lookup_sid(p->mem_ctx, &info->sid, NULL, NULL, NULL))
1121
1680
                return NT_STATUS_ACCESS_DENIED;
1122
1681
 
1123
1682
        /*
1157
1716
        if (!pdb_getgrsid(&map, info->sid))
1158
1717
                return NT_STATUS_NO_SUCH_GROUP;
1159
1718
 
1160
 
        if(!pdb_update_group_mapping_entry(&map))
1161
 
                return NT_STATUS_NO_SUCH_GROUP;
1162
 
 
1163
 
        return r_u->status;
 
1719
        return pdb_update_group_mapping_entry(&map);
1164
1720
}
1165
1721
 
1166
1722
/***************************************************************************
1182
1738
           account_pol.tdb was already opened as root, this is all we have */
1183
1739
           
1184
1740
        get_current_user( &user, p );
1185
 
        if ( user.uid != sec_initial_uid() 
 
1741
        if ( user.ut.uid != sec_initial_uid() 
1186
1742
                && !nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS ) )
1187
1743
        {
1188
1744
                return NT_STATUS_ACCESS_DENIED;
1223
1779
           account_pol.tdb was already opened as root, this is all we have */
1224
1780
           
1225
1781
        get_current_user( &user, p );
1226
 
        if ( user.uid != sec_initial_uid()
 
1782
        if ( user.ut.uid != sec_initial_uid()
1227
1783
                && !nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS ) ) 
1228
1784
        {
1229
1785
                return NT_STATUS_ACCESS_DENIED;
1385
1941
           account_pol.tdb was already opened as root, this is all we have */
1386
1942
           
1387
1943
        get_current_user( &user, p );
1388
 
        if ( user.uid != sec_initial_uid()
 
1944
        if ( user.ut.uid != sec_initial_uid()
1389
1945
                && !nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS ) ) 
1390
1946
        {
1391
1947
                return NT_STATUS_ACCESS_DENIED;
1443
1999
           account_pol.tdb was already opened as root, this is all we have */
1444
2000
           
1445
2001
        get_current_user( &user, p );
1446
 
        if ( user.uid != sec_initial_uid()
 
2002
        if ( user.ut.uid != sec_initial_uid()
1447
2003
                && !nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS ) )
1448
2004
        {
1449
2005
                return NT_STATUS_ACCESS_DENIED;
1557
2113
 
1558
2114
        return NT_STATUS_OK;
1559
2115
}
1560