Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/libgpo/gpo_reg.c

    r414 r745  
    1919
    2020#include "includes.h"
    21 
    22 
    23 /****************************************************************
    24 ****************************************************************/
    25 
    26 struct nt_user_token *registry_create_system_token(TALLOC_CTX *mem_ctx)
    27 {
    28         struct nt_user_token *token = NULL;
    29 
    30         token = TALLOC_ZERO_P(mem_ctx, struct nt_user_token);
     21#include "../libgpo/gpo.h"
     22#include "libgpo/gpo_proto.h"
     23#include "registry.h"
     24#include "registry/reg_api.h"
     25#include "registry/reg_backend_db.h"
     26#include "registry/reg_api_util.h"
     27#include "registry/reg_init_basic.h"
     28#include "../libcli/security/security.h"
     29#include "../libcli/registry/util_reg.h"
     30
     31
     32/****************************************************************
     33****************************************************************/
     34
     35struct security_token *registry_create_system_token(TALLOC_CTX *mem_ctx)
     36{
     37        struct security_token *token = NULL;
     38
     39        token = TALLOC_ZERO_P(mem_ctx, struct security_token);
    3140        if (!token) {
    3241                DEBUG(1,("talloc failed\n"));
     
    3443        }
    3544
    36         token->privileges = se_priv_all;
     45        token->privilege_mask = SE_ALL_PRIVS;
    3746
    3847        if (!NT_STATUS_IS_OK(add_sid_to_array(token, &global_sid_System,
    39                          &token->user_sids, &token->num_sids))) {
     48                         &token->sids, &token->num_sids))) {
    4049                DEBUG(1,("Error adding nt-authority system sid to token\n"));
    4150                return NULL;
     
    5160                       const char *initial_path,
    5261                       uint32_t desired_access,
    53                        const struct nt_user_token *token,
     62                       const struct security_token *token,
    5463                       struct gp_registry_context **reg_ctx)
    5564{
     
    162171{
    163172        struct registry_value reg_val;
    164         ZERO_STRUCT(reg_val);
    165 
    166         /* FIXME: hack */
    167         val = val ? val : " ";
    168173
    169174        reg_val.type = REG_SZ;
    170         reg_val.v.sz.len = strlen(val);
    171         reg_val.v.sz.str = talloc_strdup(mem_ctx, val);
    172         W_ERROR_HAVE_NO_MEMORY(reg_val.v.sz.str);
     175        if (!push_reg_sz(mem_ctx, &reg_val.data, val)) {
     176                return WERR_NOMEM;
     177        }
    173178
    174179        return reg_setvalue(key, val_name, &reg_val);
     
    184189{
    185190        struct registry_value reg_val;
    186         ZERO_STRUCT(reg_val);
    187191
    188192        reg_val.type = REG_DWORD;
    189         reg_val.v.dword = val;
     193        reg_val.data = data_blob_talloc(mem_ctx, NULL, 4);
     194        SIVAL(reg_val.data.data, 0, val);
    190195
    191196        return reg_setvalue(key, val_name, &reg_val);
     
    210215        }
    211216
    212         *val = talloc_strdup(mem_ctx, reg_val->v.sz.str);
    213         W_ERROR_HAVE_NO_MEMORY(*val);
     217        if (!pull_reg_sz(mem_ctx, &reg_val->data, val)) {
     218                return WERR_NOMEM;
     219        }
    214220
    215221        return WERR_OK;
     
    234240        }
    235241
    236         *val = reg_val->v.dword;
     242        if (reg_val->data.length < 4) {
     243                return WERR_INSUFFICIENT_BUFFER;
     244        }
     245        *val = IVAL(reg_val->data.data, 0);
    237246
    238247        return WERR_OK;
     
    295304
    296305static const char *gp_reg_groupmembership_path(TALLOC_CTX *mem_ctx,
    297                                                const DOM_SID *sid,
     306                                               const struct dom_sid *sid,
    298307                                               uint32_t flags)
    299308{
     
    311320static WERROR gp_reg_del_groupmembership(TALLOC_CTX *mem_ctx,
    312321                                         struct registry_key *key,
    313                                          const struct nt_user_token *token,
     322                                         const struct security_token *token,
    314323                                         uint32_t flags)
    315324{
    316325        const char *path = NULL;
    317326
    318         path = gp_reg_groupmembership_path(mem_ctx, &token->user_sids[0],
     327        path = gp_reg_groupmembership_path(mem_ctx, &token->sids[0],
    319328                                           flags);
    320329        W_ERROR_HAVE_NO_MEMORY(path);
    321330
    322         return reg_deletekey_recursive(mem_ctx, key, path);
     331        return reg_deletekey_recursive(key, path);
    323332
    324333}
     
    329338static WERROR gp_reg_store_groupmembership(TALLOC_CTX *mem_ctx,
    330339                                           struct gp_registry_context *reg_ctx,
    331                                            const struct nt_user_token *token,
     340                                           const struct security_token *token,
    332341                                           uint32_t flags)
    333342{
     
    340349        int count = 0;
    341350
    342         path = gp_reg_groupmembership_path(mem_ctx, &token->user_sids[0],
     351        path = gp_reg_groupmembership_path(mem_ctx, &token->sids[0],
    343352                                           flags);
    344353        W_ERROR_HAVE_NO_MEMORY(path);
     
    355364                W_ERROR_HAVE_NO_MEMORY(valname);
    356365
    357                 val = sid_string_talloc(mem_ctx, &token->user_sids[i]);
     366                val = sid_string_talloc(mem_ctx, &token->sids[i]);
    358367                W_ERROR_HAVE_NO_MEMORY(val);
    359368                werr = gp_store_reg_val_sz(mem_ctx, key, valname, val);
     
    373382static WERROR gp_reg_read_groupmembership(TALLOC_CTX *mem_ctx,
    374383                                          struct gp_registry_context *reg_ctx,
    375                                           const DOM_SID *object_sid,
    376                                           struct nt_user_token **token,
     384                                          const struct dom_sid *object_sid,
     385                                          struct security_token **token,
    377386                                          uint32_t flags)
    378387{
     
    385394        uint32_t count = 0;
    386395        int num_token_sids = 0;
    387         struct nt_user_token *tmp_token = NULL;
    388 
    389         tmp_token = TALLOC_ZERO_P(mem_ctx, struct nt_user_token);
     396        struct security_token *tmp_token = NULL;
     397
     398        tmp_token = TALLOC_ZERO_P(mem_ctx, struct security_token);
    390399        W_ERROR_HAVE_NO_MEMORY(tmp_token);
    391400
     
    407416                W_ERROR_NOT_OK_RETURN(werr);
    408417
    409                 if (!string_to_sid(&tmp_token->user_sids[num_token_sids++],
     418                if (!string_to_sid(&tmp_token->sids[num_token_sids++],
    410419                                   val)) {
    411420                        return WERR_INSUFFICIENT_BUFFER;
     
    424433
    425434static const char *gp_req_state_path(TALLOC_CTX *mem_ctx,
    426                                      const DOM_SID *sid,
     435                                     const struct dom_sid *sid,
    427436                                     uint32_t flags)
    428437{
     
    441450                               const char *path)
    442451{
    443         return reg_deletesubkeys_recursive(mem_ctx, key, path);
     452        return reg_deletesubkeys_recursive(key, path);
    444453}
    445454
     
    450459                          uint32_t flags,
    451460                          const char *dn,
    452                           const struct nt_user_token *token,
     461                          const struct security_token *token,
    453462                          struct GROUP_POLICY_OBJECT *gpo_list)
    454463{
     
    465474
    466475        werr = gp_secure_key(mem_ctx, flags, reg_ctx->curr_key,
    467                              &token->user_sids[0]);
     476                             &token->sids[0]);
    468477        if (!W_ERROR_IS_OK(werr)) {
    469478                DEBUG(0,("failed to secure key: %s\n", win_errstr(werr)));
     
    477486        }
    478487
    479         subkeyname = gp_req_state_path(mem_ctx, &token->user_sids[0], flags);
     488        subkeyname = gp_req_state_path(mem_ctx, &token->sids[0], flags);
    480489        if (!subkeyname) {
    481490                werr = WERR_NOMEM;
     
    610619WERROR gp_reg_state_read(TALLOC_CTX *mem_ctx,
    611620                         uint32_t flags,
    612                          const DOM_SID *sid,
     621                         const struct dom_sid *sid,
    613622                         struct GROUP_POLICY_OBJECT **gpo_list)
    614623{
     
    685694
    686695static WERROR gp_reg_generate_sd(TALLOC_CTX *mem_ctx,
    687                                  const DOM_SID *sid,
     696                                 const struct dom_sid *sid,
    688697                                 struct security_descriptor **sd,
    689698                                 size_t *sd_size)
    690699{
    691         SEC_ACE ace[6];
     700        struct security_ace ace[6];
    692701        uint32_t mask;
    693702
    694         SEC_ACL *theacl = NULL;
     703        struct security_acl *theacl = NULL;
    695704
    696705        uint8_t inherit_flags;
     
    739748        W_ERROR_HAVE_NO_MEMORY(theacl);
    740749
    741         *sd = make_sec_desc(mem_ctx, SEC_DESC_REVISION,
     750        *sd = make_sec_desc(mem_ctx, SD_REVISION,
    742751                            SEC_DESC_SELF_RELATIVE |
    743752                            SEC_DESC_DACL_AUTO_INHERITED | /* really ? */
     
    756765                     uint32_t flags,
    757766                     struct registry_key *key,
    758                      const DOM_SID *sid)
     767                     const struct dom_sid *sid)
    759768{
    760769        struct security_descriptor *sd = NULL;
    761770        size_t sd_size = 0;
    762         const DOM_SID *sd_sid = NULL;
     771        const struct dom_sid *sd_sid = NULL;
    763772        WERROR werr;
    764773
     
    788797        }
    789798
    790         type_str = reg_type_lookup(val->type);
     799        type_str = str_regtype(val->type);
    791800
    792801        DEBUG(lvl,("\tdump_reg_val:\t%s '%s'\n\t\t\t'%s' %s: ",
     
    794803
    795804        switch (val->type) {
    796                 case REG_DWORD:
     805                case REG_DWORD: {
     806                        uint32_t v;
     807                        if (val->data.length < 4) {
     808                                break;
     809                        }
     810                        v = IVAL(val->data.data, 0);
    797811                        DEBUG(lvl,("%d (0x%08x)\n",
    798                                 (int)val->v.dword, val->v.dword));
    799                         break;
    800                 case REG_QWORD:
     812                                (int)v, v));
     813                        break;
     814                }
     815                case REG_QWORD: {
     816                        uint64_t v;
     817                        if (val->data.length < 8) {
     818                                break;
     819                        }
     820                        v = BVAL(val->data.data, 0);
    801821                        DEBUG(lvl,("%d (0x%016llx)\n",
    802                                 (int)val->v.qword,
    803                                 (unsigned long long)val->v.qword));
    804                         break;
    805                 case REG_SZ:
     822                                (int)v,
     823                                (unsigned long long)v));
     824                        break;
     825                }
     826                case REG_SZ: {
     827                        const char *s;
     828                        if (!pull_reg_sz(talloc_tos(), &val->data, &s)) {
     829                                break;
     830                        }
    806831                        DEBUG(lvl,("%s (length: %d)\n",
    807                                    val->v.sz.str,
    808                                    (int)val->v.sz.len));
    809                         break;
    810                 case REG_MULTI_SZ:
    811                         DEBUG(lvl,("(num_strings: %d)\n",
    812                                    val->v.multi_sz.num_strings));
    813                         for (i=0; i < val->v.multi_sz.num_strings; i++) {
    814                                 DEBUGADD(lvl,("\t%s\n",
    815                                         val->v.multi_sz.strings[i]));
     832                                   s, (int)strlen_m(s)));
     833                        break;
     834                }
     835                case REG_MULTI_SZ: {
     836                        const char **a;
     837                        if (!pull_reg_multi_sz(talloc_tos(), &val->data, &a)) {
     838                                break;
    816839                        }
    817                         break;
     840                        for (i=0; a[i] != NULL; i++) {
     841                                ;;
     842                        }
     843                        DEBUG(lvl,("(num_strings: %d)\n", i));
     844                        for (i=0; a[i] != NULL; i++) {
     845                                DEBUGADD(lvl,("\t%s\n", a[i]));
     846                        }
     847                        break;
     848                }
    818849                case REG_NONE:
    819850                        DEBUG(lvl,("\n"));
    820851                        break;
    821852                case REG_BINARY:
    822                         dump_data(lvl, val->v.binary.data,
    823                                   val->v.binary.length);
     853                        dump_data(lvl, val->data.data,
     854                                  val->data.length);
    824855                        break;
    825856                default:
     
    925956                                struct gp_registry_context *reg_ctx,
    926957                                struct gp_registry_entry *entry,
    927                                 const struct nt_user_token *token,
     958                                const struct security_token *token,
    928959                                uint32_t flags)
    929960{
     
    934965                printf("about to store key:    [%s]\n", entry->key);
    935966                printf("               value:  [%s]\n", entry->value);
    936                 printf("               data:   [%s]\n", reg_type_lookup(entry->data->type));
     967                printf("               data:   [%s]\n", str_regtype(entry->data->type));
    937968                printf("               action: [%s]\n", gp_reg_action_str(entry->action));
    938969        }
     
    954985                        werr = gp_secure_key(mem_ctx, flags,
    955986                                             key,
    956                                              &token->user_sids[0]);
     987                                             &token->sids[0]);
    957988                        if (!W_ERROR_IS_OK(werr)) {
    958989                                DEBUG(0,("reg_apply_registry_entry: "
Note: See TracChangeset for help on using the changeset viewer.