root/source3/registry/reg_init_smbconf.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. registry_create_admin_token
  2. registry_init_smbconf

   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 
  22 #undef DBGC_CLASS
  23 #define DBGC_CLASS DBGC_REGISTRY
  24 
  25 extern REGISTRY_OPS smbconf_reg_ops;
  26 
  27 /*
  28  * create a fake token just with enough rights to
  29  * locally access the registry:
  30  *
  31  * - builtin administrators sid
  32  * - disk operators privilege
  33  */
  34 NTSTATUS registry_create_admin_token(TALLOC_CTX *mem_ctx,
     /* [<][>][^][v][top][bottom][index][help] */
  35                                      NT_USER_TOKEN **ptoken)
  36 {
  37         NTSTATUS status;
  38         NT_USER_TOKEN *token = NULL;
  39 
  40         if (ptoken == NULL) {
  41                 return NT_STATUS_INVALID_PARAMETER;
  42         }
  43 
  44         token = TALLOC_ZERO_P(mem_ctx, NT_USER_TOKEN);
  45         if (token == NULL) {
  46                 DEBUG(1, ("talloc failed\n"));
  47                 status = NT_STATUS_NO_MEMORY;
  48                 goto done;
  49         }
  50         token->privileges = se_disk_operators;
  51         status = add_sid_to_array(token, &global_sid_Builtin_Administrators,
  52                                   &token->user_sids, &token->num_sids);
  53         if (!NT_STATUS_IS_OK(status)) {
  54                 DEBUG(1, ("Error adding builtin administrators sid "
  55                           "to fake token.\n"));
  56                 goto done;
  57         }
  58 
  59         *ptoken = token;
  60 
  61 done:
  62         return status;
  63 }
  64 
  65 /*
  66  * init the smbconf portion of the registry.
  67  * for use in places where not the whole registry is needed,
  68  * e.g. utils/net_conf.c and loadparm.c
  69  */
  70 WERROR registry_init_smbconf(const char *keyname)
     /* [<][>][^][v][top][bottom][index][help] */
  71 {
  72         WERROR werr;
  73 
  74         DEBUG(10, ("registry_init_smbconf called\n"));
  75 
  76         if (keyname == NULL) {
  77                 DEBUG(10, ("registry_init_smbconf: defaulting to key '%s'\n",
  78                            KEY_SMBCONF));
  79                 keyname = KEY_SMBCONF;
  80         }
  81 
  82         werr = registry_init_common();
  83         if (!W_ERROR_IS_OK(werr)) {
  84                 goto done;
  85         }
  86 
  87         werr = init_registry_key(keyname);
  88         if (!W_ERROR_IS_OK(werr)) {
  89                 DEBUG(1, ("Failed to initialize registry key '%s': %s\n",
  90                           keyname, win_errstr(werr)));
  91                 goto done;
  92         }
  93 
  94         werr = reghook_cache_add(keyname, &smbconf_reg_ops);
  95         if (!W_ERROR_IS_OK(werr)) {
  96                 DEBUG(1, ("Failed to add smbconf reghooks to reghook cache: "
  97                           "%s\n", win_errstr(werr)));
  98                 goto done;
  99         }
 100 
 101 done:
 102         regdb_close();
 103         return werr;
 104 }

/* [<][>][^][v][top][bottom][index][help] */