Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/libgpo/gpo_util.c

    r746 r988  
    1717 *  along with this program; if not, see <http://www.gnu.org/licenses/>.
    1818 */
    19 #define TALLOC_DEPRECATED 1
     19
    2020#include "includes.h"
    2121#include "system/filesys.h"
     
    2424#include "../libgpo/gpo.h"
    2525#include "../libcli/security/security.h"
    26 #if _SAMBA_BUILD_ == 4
    27 #include "auth/auth.h"
    28 #include <talloc.h>
    29 #include "source4/libgpo/ads_convenience.h"
    30 #endif
    31 #undef strdup
     26#include "registry.h"
     27#include "libgpo/gpo_proto.h"
     28#include "libgpo/gpext/gpext.h"
    3229
    3330#if 0
     
    233230****************************************************************/
    234231
    235 void dump_gpo(ADS_STRUCT *ads,
    236               TALLOC_CTX *mem_ctx,
    237               struct GROUP_POLICY_OBJECT *gpo,
     232void dump_gpo(const struct GROUP_POLICY_OBJECT *gpo,
    238233              int debuglevel)
    239234{
    240235        int lvl = debuglevel;
     236        TALLOC_CTX *frame = talloc_stackframe();
    241237
    242238        if (gpo == NULL) {
    243                 return;
     239                goto out;
    244240        }
    245241
     
    305301                struct GP_EXT *gp_ext = NULL;
    306302
    307                 if (!ads_parse_gp_ext(mem_ctx, gpo->machine_extensions,
     303                if (!ads_parse_gp_ext(frame, gpo->machine_extensions,
    308304                                      &gp_ext)) {
    309                         return;
     305                        goto out;
    310306                }
    311307                dump_gp_ext(gp_ext, lvl);
     
    318314                struct GP_EXT *gp_ext = NULL;
    319315
    320                 if (!ads_parse_gp_ext(mem_ctx, gpo->user_extensions,
     316                if (!ads_parse_gp_ext(frame, gpo->user_extensions,
    321317                                      &gp_ext)) {
    322                         return;
     318                        goto out;
    323319                }
    324320                dump_gp_ext(gp_ext, lvl);
     
    329325                NDR_PRINT_DEBUG(security_descriptor, gpo->security_descriptor);
    330326        }
    331 }
    332 
    333 /****************************************************************
    334 ****************************************************************/
    335 
    336 void dump_gpo_list(ADS_STRUCT *ads,
    337                    TALLOC_CTX *mem_ctx,
    338                   struct GROUP_POLICY_OBJECT *gpo_list,
     327 out:
     328        talloc_free(frame);
     329}
     330
     331/****************************************************************
     332****************************************************************/
     333
     334void dump_gpo_list(const struct GROUP_POLICY_OBJECT *gpo_list,
    339335                   int debuglevel)
    340336{
    341         struct GROUP_POLICY_OBJECT *gpo = NULL;
     337        const struct GROUP_POLICY_OBJECT *gpo = NULL;
    342338
    343339        for (gpo = gpo_list; gpo; gpo = gpo->next) {
    344                 dump_gpo(ads, mem_ctx, gpo, debuglevel);
    345         }
    346 }
    347 
    348 /****************************************************************
    349 ****************************************************************/
    350 
    351 void dump_gplink(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, struct GP_LINK *gp_link)
    352 {
    353         ADS_STATUS status;
     340                dump_gpo(gpo, debuglevel);
     341        }
     342}
     343
     344/****************************************************************
     345****************************************************************/
     346
     347void dump_gplink(const struct GP_LINK *gp_link)
     348{
    354349        int i;
    355350        int lvl = 10;
     
    391386                }
    392387                DEBUGADD(lvl,("\n"));
    393 
    394                 if (ads != NULL && mem_ctx != NULL) {
    395 
    396                         struct GROUP_POLICY_OBJECT gpo;
    397 
    398                         status = ads_get_gpo(ads, mem_ctx,
    399                                              gp_link->link_names[i],
    400                                              NULL, NULL, &gpo);
    401                         if (!ADS_ERR_OK(status)) {
    402                                 DEBUG(lvl,("get gpo for %s failed: %s\n",
    403                                         gp_link->link_names[i],
    404                                         ads_errstr(status)));
    405                                 return;
    406                         }
    407                         dump_gpo(ads, mem_ctx, &gpo, lvl);
    408                 }
    409388        }
    410389}
     
    415394****************************************************************/
    416395
    417 static bool gpo_get_gp_ext_from_gpo(TALLOC_CTX *mem_ctx,
    418                                     uint32_t flags,
    419                                     struct GROUP_POLICY_OBJECT *gpo,
    420                                     struct GP_EXT **gp_ext)
     396bool gpo_get_gp_ext_from_gpo(TALLOC_CTX *mem_ctx,
     397                             uint32_t flags,
     398                             const struct GROUP_POLICY_OBJECT *gpo,
     399                             struct GP_EXT **gp_ext)
    421400{
    422401        ZERO_STRUCTP(*gp_ext);
     
    448427****************************************************************/
    449428
    450 ADS_STATUS gpo_process_a_gpo(ADS_STRUCT *ads,
    451                              TALLOC_CTX *mem_ctx,
    452                              const struct security_token *token,
    453                              struct registry_key *root_key,
    454                              struct GROUP_POLICY_OBJECT *gpo,
    455                              const char *extension_guid_filter,
    456                              uint32_t flags)
    457 {
    458         struct GP_EXT *gp_ext = NULL;
    459         int i;
    460 
    461         DEBUG(10,("gpo_process_a_gpo: processing gpo %s (%s)\n",
    462                 gpo->name, gpo->display_name));
    463         if (extension_guid_filter) {
    464                 DEBUGADD(10,("gpo_process_a_gpo: using filter %s (%s)\n",
    465                         extension_guid_filter,
    466                         cse_gpo_guid_string_to_name(extension_guid_filter)));
    467         }
    468 
    469         if (!gpo_get_gp_ext_from_gpo(mem_ctx, flags, gpo, &gp_ext)) {
    470                 return ADS_ERROR_NT(NT_STATUS_INVALID_PARAMETER);
    471         }
    472 
    473         if (!gp_ext || !gp_ext->num_exts) {
    474                 if (flags & GPO_INFO_FLAG_VERBOSE) {
    475                         DEBUG(0,("gpo_process_a_gpo: "
    476                                 "no policies in %s (%s) for this extension\n",
    477                                 gpo->name, gpo->display_name));
    478                 }
    479                 return ADS_SUCCESS;
    480         }
    481 
    482         for (i=0; i<gp_ext->num_exts; i++) {
    483 
    484                 NTSTATUS ntstatus;
    485 
    486                 if (extension_guid_filter &&
    487                     !strequal(extension_guid_filter,
    488                               gp_ext->extensions_guid[i])) {
    489                         continue;
    490                 }
    491 
    492                 ntstatus = gpext_process_extension(ads, mem_ctx,
    493                                                    flags, token, root_key, gpo,
    494                                                    gp_ext->extensions_guid[i],
    495                                                    gp_ext->snapins_guid[i]);
    496                 if (!NT_STATUS_IS_OK(ntstatus)) {
    497                         ADS_ERROR_NT(ntstatus);
    498                 }
    499         }
    500 
    501         return ADS_SUCCESS;
    502 }
    503 
    504 /****************************************************************
    505 ****************************************************************/
    506 
    507 static ADS_STATUS gpo_process_gpo_list_by_ext(ADS_STRUCT *ads,
    508                                               TALLOC_CTX *mem_ctx,
    509                                               const struct security_token *token,
    510                                               struct registry_key *root_key,
    511                                               struct GROUP_POLICY_OBJECT *gpo_list,
    512                                               const char *extensions_guid,
    513                                               uint32_t flags)
    514 {
    515         ADS_STATUS status;
    516         struct GROUP_POLICY_OBJECT *gpo;
    517 
    518         for (gpo = gpo_list; gpo; gpo = gpo->next) {
    519 
    520                 if (gpo->link_type == GP_LINK_LOCAL) {
    521                         continue;
    522                 }
    523 
    524 
    525                 /* FIXME: we need to pass down the *list* down to the
    526                  * extension, otherwise we cannot store the e.g. the *list* of
    527                  * logon-scripts correctly (for more then one GPO) */
    528 
    529                 status = gpo_process_a_gpo(ads, mem_ctx, token, root_key,
    530                                            gpo, extensions_guid, flags);
    531 
    532                 if (!ADS_ERR_OK(status)) {
    533                         DEBUG(0,("failed to process gpo by ext: %s\n",
    534                                 ads_errstr(status)));
    535                         return status;
    536                 }
    537         }
    538 
    539         return ADS_SUCCESS;
    540 }
    541 
    542 /****************************************************************
    543 ****************************************************************/
    544 
    545 ADS_STATUS gpo_process_gpo_list(ADS_STRUCT *ads,
    546                                 TALLOC_CTX *mem_ctx,
    547                                 const struct security_token *token,
    548                                 struct GROUP_POLICY_OBJECT *gpo_list,
    549                                 const char *extensions_guid_filter,
    550                                 uint32_t flags)
    551 {
    552         ADS_STATUS status = ADS_SUCCESS;
    553         struct gp_extension *gp_ext_list = NULL;
    554         struct gp_extension *gp_ext = NULL;
     429NTSTATUS gpo_process_gpo_list(TALLOC_CTX *mem_ctx,
     430                              const struct security_token *token,
     431                              const struct GROUP_POLICY_OBJECT *deleted_gpo_list,
     432                              const struct GROUP_POLICY_OBJECT *changed_gpo_list,
     433                              const char *extensions_guid_filter,
     434                              uint32_t flags)
     435{
     436        NTSTATUS status = NT_STATUS_OK;
    555437        struct registry_key *root_key = NULL;
    556438        struct gp_registry_context *reg_ctx = NULL;
    557 #if 0
    558439        WERROR werr;
    559 #endif
    560         status = ADS_ERROR_NT(init_gp_extensions(mem_ctx));
    561         if (!ADS_ERR_OK(status)) {
    562                 return status;
    563         }
    564 
    565         gp_ext_list = get_gp_extension_list();
    566         if (!gp_ext_list) {
    567                 return ADS_ERROR_NT(NT_STATUS_DLL_INIT_FAILED);
    568         }
    569 /* FIXME Needs to be replaced with new patchfile_preg calls */
    570 #if 0
     440
    571441        /* get the key here */
    572442        if (flags & GPO_LIST_FLAG_MACHINE) {
     
    581451        if (!W_ERROR_IS_OK(werr)) {
    582452                talloc_free(reg_ctx);
    583                 return ADS_ERROR_NT(werror_to_ntstatus(werr));
    584         }
    585 #endif
     453                return werror_to_ntstatus(werr);
     454        }
    586455
    587456        root_key = reg_ctx->curr_key;
    588457
    589         for (gp_ext = gp_ext_list; gp_ext; gp_ext = gp_ext->next) {
    590 
    591                 const char *guid_str = NULL;
    592 
    593                 guid_str = GUID_string(mem_ctx, gp_ext->guid);
    594                 if (!guid_str) {
    595                         status = ADS_ERROR_NT(NT_STATUS_NO_MEMORY);
    596                         goto done;
    597                 }
    598 
    599                 if (extensions_guid_filter &&
    600                     (!strequal(guid_str, extensions_guid_filter)))  {
    601                         continue;
    602                 }
    603 
    604                 DEBUG(0,("-------------------------------------------------\n"));
    605                 DEBUG(0,("gpo_process_gpo_list: processing ext: %s {%s}\n",
    606                         gp_ext->name, guid_str));
    607 
    608 
    609                 status = gpo_process_gpo_list_by_ext(ads, mem_ctx, token,
    610                                                      root_key, gpo_list,
    611                                                      guid_str, flags);
    612                 if (!ADS_ERR_OK(status)) {
    613                         goto done;
    614                 }
    615         }
    616 
    617  done:
     458        status = gpext_process_extension(mem_ctx,
     459                                         flags, token, root_key,
     460                                         deleted_gpo_list,
     461                                         changed_gpo_list,
     462                                         extensions_guid_filter);
    618463        talloc_free(reg_ctx);
    619464        talloc_free(root_key);
    620         free_gp_extensions();
     465        gpext_free_gp_extensions();
    621466
    622467        return status;
     
    632477                           TALLOC_CTX *mem_ctx,
    633478                           const char *cache_dir,
    634                            struct loadparm_context *lp_ctx,
    635479                           uint32_t flags,
    636                            struct GROUP_POLICY_OBJECT *gpo)
     480                           const struct GROUP_POLICY_OBJECT *gpo)
    637481{
    638482        NTSTATUS result;
     
    672516                DEBUG(1,("check_refresh_gpo: need to refresh GPO\n"));
    673517
    674                 result = gpo_fetch_files(mem_ctx, ads, lp_ctx, cache_dir, gpo);
     518                result = gpo_fetch_files(mem_ctx, ads, cache_dir, gpo);
    675519                if (!NT_STATUS_IS_OK(result)) {
    676520                        goto out;
     
    719563                                TALLOC_CTX *mem_ctx,
    720564                                const char *cache_dir,
    721                                 struct loadparm_context *lp_ctx,
    722565                                uint32_t flags,
    723                                 struct GROUP_POLICY_OBJECT *gpo_list)
     566                                const struct GROUP_POLICY_OBJECT *gpo_list)
    724567{
    725568        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
    726         struct GROUP_POLICY_OBJECT *gpo;
     569        const struct GROUP_POLICY_OBJECT *gpo;
    727570
    728571        if (!gpo_list) {
     
    732575        for (gpo = gpo_list; gpo; gpo = gpo->next) {
    733576
    734                 result = check_refresh_gpo(ads, mem_ctx, cache_dir, lp_ctx, flags, gpo);
     577                result = check_refresh_gpo(ads, mem_ctx, cache_dir, flags, gpo);
    735578                if (!NT_STATUS_IS_OK(result)) {
    736579                        goto out;
     
    751594NTSTATUS gpo_get_unix_path(TALLOC_CTX *mem_ctx,
    752595                           const char *cache_dir,
    753                            struct GROUP_POLICY_OBJECT *gpo,
     596                           const struct GROUP_POLICY_OBJECT *gpo,
    754597                           char **unix_path)
    755598{
     
    770613        }
    771614
     615        str = talloc_strdup(ctx, "");
     616        if (!str) {
     617                return NULL;
     618        }
     619
    772620        if (flags & GPO_INFO_FLAG_SLOWLINK)
    773                 str = talloc_append_string(ctx, str, "GPO_INFO_FLAG_SLOWLINK ");
     621                str = talloc_strdup_append(str, "GPO_INFO_FLAG_SLOWLINK ");
    774622        if (flags & GPO_INFO_FLAG_VERBOSE)
    775                 str = talloc_append_string(ctx, str, "GPO_INFO_FLAG_VERBOSE ");
     623                str = talloc_strdup_append(str, "GPO_INFO_FLAG_VERBOSE ");
    776624        if (flags & GPO_INFO_FLAG_SAFEMODE_BOOT)
    777                 str = talloc_append_string(ctx, str, "GPO_INFO_FLAG_SAFEMODE_BOOT ");
     625                str = talloc_strdup_append(str, "GPO_INFO_FLAG_SAFEMODE_BOOT ");
    778626        if (flags & GPO_INFO_FLAG_NOCHANGES)
    779                 str = talloc_append_string(ctx, str, "GPO_INFO_FLAG_NOCHANGES ");
     627                str = talloc_strdup_append(str, "GPO_INFO_FLAG_NOCHANGES ");
    780628        if (flags & GPO_INFO_FLAG_MACHINE)
    781                 str = talloc_append_string(ctx, str, "GPO_INFO_FLAG_MACHINE ");
     629                str = talloc_strdup_append(str, "GPO_INFO_FLAG_MACHINE ");
    782630        if (flags & GPO_INFO_FLAG_LOGRSOP_TRANSITION)
    783                 str = talloc_append_string(ctx, str, "GPO_INFO_FLAG_LOGRSOP_TRANSITION ");
     631                str = talloc_strdup_append(str, "GPO_INFO_FLAG_LOGRSOP_TRANSITION ");
    784632        if (flags & GPO_INFO_FLAG_LINKTRANSITION)
    785                 str = talloc_append_string(ctx, str, "GPO_INFO_FLAG_LINKTRANSITION ");
     633                str = talloc_strdup_append(str, "GPO_INFO_FLAG_LINKTRANSITION ");
    786634        if (flags & GPO_INFO_FLAG_FORCED_REFRESH)
    787                 str = talloc_append_string(ctx, str, "GPO_INFO_FLAG_FORCED_REFRESH ");
     635                str = talloc_strdup_append(str, "GPO_INFO_FLAG_FORCED_REFRESH ");
    788636        if (flags & GPO_INFO_FLAG_BACKGROUND)
    789                 str = talloc_append_string(ctx, str, "GPO_INFO_FLAG_BACKGROUND ");
     637                str = talloc_strdup_append(str, "GPO_INFO_FLAG_BACKGROUND ");
    790638
    791639        return str;
     
    840688ADS_STATUS gp_get_machine_token(ADS_STRUCT *ads,
    841689                                TALLOC_CTX *mem_ctx,
    842                                 struct loadparm_context *lp_ctx,
    843690                                const char *dn,
    844691                                struct security_token **token)
     
    847694        struct security_token *ad_token = NULL;
    848695        ADS_STATUS status;
    849 #if _SAMBA_BUILD_ == 4
    850         struct auth_session_info *info;
    851 #else
    852696        NTSTATUS ntstatus;
    853 #endif
    854697
    855698        status = ads_get_sid_token(ads, mem_ctx, dn, &ad_token);
     
    857700                return status;
    858701        }
    859 #if _SAMBA_BUILD_ == 4
    860         info = system_session(mem_ctx, lp_ctx);
    861         *token = info->security_token;
    862 #else
    863702        ntstatus = merge_nt_token(mem_ctx, ad_token, get_system_token(),
    864703                                  token);
     
    866705                return ADS_ERROR_NT(ntstatus);
    867706        }
    868 #endif
    869707        return ADS_SUCCESS;
    870708#else
     
    872710#endif
    873711}
     712
     713/****************************************************************
     714****************************************************************/
     715
     716NTSTATUS gpo_copy(TALLOC_CTX *mem_ctx,
     717                  const struct GROUP_POLICY_OBJECT *gpo_src,
     718                  struct GROUP_POLICY_OBJECT **gpo_dst)
     719{
     720        struct GROUP_POLICY_OBJECT *gpo;
     721
     722        gpo = talloc_zero(mem_ctx, struct GROUP_POLICY_OBJECT);
     723        NT_STATUS_HAVE_NO_MEMORY(gpo);
     724
     725        gpo->options            = gpo_src->options;
     726        gpo->version            = gpo_src->version;
     727
     728        gpo->ds_path            = talloc_strdup(gpo, gpo_src->ds_path);
     729        if (gpo->ds_path == NULL) {
     730                TALLOC_FREE(gpo);
     731                return NT_STATUS_NO_MEMORY;
     732        }
     733
     734        gpo->file_sys_path      = talloc_strdup(gpo, gpo_src->file_sys_path);
     735        if (gpo->file_sys_path == NULL) {
     736                TALLOC_FREE(gpo);
     737                return NT_STATUS_NO_MEMORY;
     738        }
     739
     740        gpo->display_name       = talloc_strdup(gpo, gpo_src->display_name);
     741        if (gpo->display_name == NULL) {
     742                TALLOC_FREE(gpo);
     743                return NT_STATUS_NO_MEMORY;
     744        }
     745
     746        gpo->name               = talloc_strdup(gpo, gpo_src->name);
     747        if (gpo->name == NULL) {
     748                TALLOC_FREE(gpo);
     749                return NT_STATUS_NO_MEMORY;
     750        }
     751
     752        gpo->link               = talloc_strdup(gpo, gpo_src->link);
     753        if (gpo->link == NULL) {
     754                TALLOC_FREE(gpo);
     755                return NT_STATUS_NO_MEMORY;
     756        }
     757
     758        gpo->link_type          = gpo_src->link_type;
     759
     760        if (gpo_src->user_extensions) {
     761                gpo->user_extensions = talloc_strdup(gpo, gpo_src->user_extensions);
     762                if (gpo->user_extensions == NULL) {
     763                        TALLOC_FREE(gpo);
     764                        return NT_STATUS_NO_MEMORY;
     765                }
     766        }
     767
     768        if (gpo_src->machine_extensions) {
     769                gpo->machine_extensions = talloc_strdup(gpo, gpo_src->machine_extensions);
     770                if (gpo->machine_extensions == NULL) {
     771                        TALLOC_FREE(gpo);
     772                        return NT_STATUS_NO_MEMORY;
     773                }
     774        }
     775
     776        if (gpo_src->security_descriptor == NULL) {
     777                /* existing SD assumed */
     778                TALLOC_FREE(gpo);
     779                return NT_STATUS_INVALID_PARAMETER;
     780        }
     781        gpo->security_descriptor = security_descriptor_copy(gpo,
     782                                                gpo_src->security_descriptor);
     783        if (gpo->security_descriptor == NULL) {
     784                TALLOC_FREE(gpo);
     785                return NT_STATUS_NO_MEMORY;
     786        }
     787
     788        gpo->next = gpo->prev = NULL;
     789
     790        *gpo_dst = gpo;
     791
     792        return NT_STATUS_OK;
     793}
Note: See TracChangeset for help on using the changeset viewer.