s3-auth Rename NT_USER_TOKEN user_sids -> sids
[kai/samba.git] / source3 / registry / reg_util_token.c
1 /*
2  * Unix SMB/CIFS implementation.
3  * Registry helper routines
4  * Copyright (C) Michael Adam 2007
5  * 
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation; either version 3 of the License, or (at your option)
9  * any later version.
10  * 
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with
17  * this program; if not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include "includes.h"
21 #include "reg_util_token.h"
22
23 /*
24  * create a fake token just with enough rights to
25  * locally access the registry:
26  *
27  * - builtin administrators sid
28  * - disk operators privilege
29  */
30 NTSTATUS registry_create_admin_token(TALLOC_CTX *mem_ctx,
31                                      NT_USER_TOKEN **ptoken)
32 {
33         NTSTATUS status;
34         NT_USER_TOKEN *token = NULL;
35
36         if (ptoken == NULL) {
37                 return NT_STATUS_INVALID_PARAMETER;
38         }
39
40         token = TALLOC_ZERO_P(mem_ctx, NT_USER_TOKEN);
41         if (token == NULL) {
42                 DEBUG(1, ("talloc failed\n"));
43                 status = NT_STATUS_NO_MEMORY;
44                 goto done;
45         }
46         token->privileges = se_disk_operators;
47         status = add_sid_to_array(token, &global_sid_Builtin_Administrators,
48                                   &token->sids, &token->num_sids);
49         if (!NT_STATUS_IS_OK(status)) {
50                 DEBUG(1, ("Error adding builtin administrators sid "
51                           "to fake token.\n"));
52                 goto done;
53         }
54
55         *ptoken = token;
56
57 done:
58         return status;
59 }