libgpo: remove ads reference from dump calls and make them take const structs.
[samba.git] / source3 / utils / net_ads_gpo.c
index 14bc3786335c3e6146fa326880f9bdd070bd366a..b9b0a1422967d0cc6117a87bb722f424dadc0ad7 100644 (file)
 
 #include "includes.h"
 #include "utils/net.h"
+#include "ads.h"
+#include "../libgpo/gpo.h"
+#include "libgpo/gpo_proto.h"
+#include "../libds/common/flags.h"
 
 #ifdef HAVE_ADS
 
@@ -34,7 +38,7 @@ static int net_ads_gpo_refresh(struct net_context *c, int argc, const char **arg
        uint32 flags = 0;
        struct GROUP_POLICY_OBJECT *gpo;
        NTSTATUS result;
-       struct nt_user_token *token = NULL;
+       struct security_token *token = NULL;
 
        if (argc < 1 || c->display_usage) {
                d_printf("%s\n%s\n%s",
@@ -74,7 +78,7 @@ static int net_ads_gpo_refresh(struct net_context *c, int argc, const char **arg
 
        d_printf(_("* fetching token "));
        if (uac & UF_WORKSTATION_TRUST_ACCOUNT) {
-               status = gp_get_machine_token(ads, mem_ctx, NULL, dn, &token);
+               status = gp_get_machine_token(ads, mem_ctx, dn, &token);
        } else {
                status = ads_get_sid_token(ads, mem_ctx, dn, &token);
        }
@@ -97,7 +101,6 @@ static int net_ads_gpo_refresh(struct net_context *c, int argc, const char **arg
        d_printf(_("* Refreshing Group Policy Data "));
        if (!NT_STATUS_IS_OK(result = check_refresh_gpo_list(ads, mem_ctx,
                                                             cache_path(GPO_CACHE_DIR),
-                                                            NULL,
                                                             flags,
                                                             gpo_list))) {
                d_printf(_("failed: %s\n"), nt_errstr(result));
@@ -124,7 +127,7 @@ static int net_ads_gpo_refresh(struct net_context *c, int argc, const char **arg
 
                for (gpo = gpo_list; gpo; gpo = gpo->next) {
 
-                       dump_gpo(ads, mem_ctx, gpo, 0);
+                       dump_gpo(gpo, 0);
 #if 0
                char *server, *share, *nt_path, *unix_path;
 
@@ -153,7 +156,7 @@ static int net_ads_gpo_refresh(struct net_context *c, int argc, const char **arg
 
        {
                WERROR werr = gp_reg_state_read(mem_ctx, flags,
-                                               &token->user_sids[0],
+                                               &token->sids[0],
                                                &read_list);
                if (!W_ERROR_IS_OK(werr)) {
                        d_printf(_("failed: %s\n"), win_errstr(werr));
@@ -169,7 +172,7 @@ static int net_ads_gpo_refresh(struct net_context *c, int argc, const char **arg
 
                for (gpo = read_list; gpo; gpo = gpo->next) {
 
-                       dump_gpo(ads, mem_ctx, gpo, 0);
+                       dump_gpo(gpo, 0);
 
 #if 0
                char *server, *share, *nt_path, *unix_path;
@@ -246,7 +249,7 @@ static int net_ads_gpo_list_all(struct net_context *c, int argc, const char **ar
                                            LDAP_SCOPE_SUBTREE,
                                            "(objectclass=groupPolicyContainer)",
                                            attrs,
-                                           DACL_SECURITY_INFORMATION,
+                                           SECINFO_DACL,
                                            &res);
 
        if (!ADS_ERR_OK(status)) {
@@ -275,7 +278,7 @@ static int net_ads_gpo_list_all(struct net_context *c, int argc, const char **ar
                        goto out;
                }
 
-               dump_gpo(ads, mem_ctx, &gpo, 0);
+               dump_gpo(&gpo, 0);
        }
 
 out:
@@ -289,7 +292,7 @@ out:
 
 static int net_ads_gpo_list(struct net_context *c, int argc, const char **argv)
 {
-       ADS_STRUCT *ads;
+       ADS_STRUCT *ads = NULL;
        ADS_STATUS status;
        LDAPMessage *res = NULL;
        TALLOC_CTX *mem_ctx;
@@ -297,7 +300,7 @@ static int net_ads_gpo_list(struct net_context *c, int argc, const char **argv)
        uint32 uac = 0;
        uint32 flags = 0;
        struct GROUP_POLICY_OBJECT *gpo_list;
-       struct nt_user_token *token = NULL;
+       struct security_token *token = NULL;
 
        if (argc < 1 || c->display_usage) {
                d_printf("%s\n%s\n%s",
@@ -333,7 +336,7 @@ static int net_ads_gpo_list(struct net_context *c, int argc, const char **argv)
                argv[0], dn);
 
        if (uac & UF_WORKSTATION_TRUST_ACCOUNT) {
-               status = gp_get_machine_token(ads, mem_ctx, NULL, dn, &token);
+               status = gp_get_machine_token(ads, mem_ctx, dn, &token);
        } else {
                status = ads_get_sid_token(ads, mem_ctx, dn, &token);
        }
@@ -347,7 +350,7 @@ static int net_ads_gpo_list(struct net_context *c, int argc, const char **argv)
                goto out;
        }
 
-       dump_gpo_list(ads, mem_ctx, gpo_list, 0);
+       dump_gpo_list(gpo_list, 0);
 
 out:
        ads_msgfree(ads, res);
@@ -358,7 +361,6 @@ out:
        return 0;
 }
 
-#if 0
 static int net_ads_gpo_apply(struct net_context *c, int argc, const char **argv)
 {
        TALLOC_CTX *mem_ctx;
@@ -368,7 +370,7 @@ static int net_ads_gpo_apply(struct net_context *c, int argc, const char **argv)
        struct GROUP_POLICY_OBJECT *gpo_list;
        uint32 uac = 0;
        uint32 flags = 0;
-       struct nt_user_token *token = NULL;
+       struct security_token *token = NULL;
        const char *filter = NULL;
 
        if (argc < 1 || c->display_usage) {
@@ -390,6 +392,8 @@ static int net_ads_gpo_apply(struct net_context *c, int argc, const char **argv)
        }
 
        status = ads_startup(c, false, &ads);
+       /* filter = cse_gpo_name_to_guid_string("Security"); */
+
        if (!ADS_ERR_OK(status)) {
                d_printf("got: %s\n", ads_errstr(status));
                goto out;
@@ -415,7 +419,7 @@ static int net_ads_gpo_apply(struct net_context *c, int argc, const char **argv)
                argv[0], dn);
 
        if (uac & UF_WORKSTATION_TRUST_ACCOUNT) {
-               status = gp_get_machine_token(ads, mem_ctx, NULL, dn, &token);
+               status = gp_get_machine_token(ads, mem_ctx, dn, &token);
        } else {
                status = ads_get_sid_token(ads, mem_ctx, dn, &token);
        }
@@ -429,8 +433,8 @@ static int net_ads_gpo_apply(struct net_context *c, int argc, const char **argv)
                goto out;
        }
 
-       status = gpo_process_gpo_list(ads, mem_ctx, token, gpo_list,
-                                     filter, flags);
+       status = ADS_ERROR_NT(gpo_process_gpo_list(mem_ctx, token, gpo_list,
+                                                  filter, flags));
        if (!ADS_ERR_OK(status)) {
                d_printf("failed to process gpo list: %s\n",
                        ads_errstr(status));
@@ -442,7 +446,6 @@ out:
        talloc_destroy(mem_ctx);
        return 0;
 }
-#endif
 
 static int net_ads_gpo_link_get(struct net_context *c, int argc, const char **argv)
 {
@@ -477,7 +480,7 @@ static int net_ads_gpo_link_get(struct net_context *c, int argc, const char **ar
                goto out;
        }
 
-       dump_gplink(ads, mem_ctx, &gp_link);
+       dump_gplink(&gp_link);
 
 out:
        talloc_destroy(mem_ctx);
@@ -612,7 +615,7 @@ static int net_ads_gpo_get_gpo(struct net_context *c, int argc, const char **arg
                goto out;
        }
 
-       dump_gpo(ads, mem_ctx, &gpo, 1);
+       dump_gpo(&gpo, 1);
 
 out:
        talloc_destroy(mem_ctx);
@@ -624,7 +627,6 @@ out:
 int net_ads_gpo(struct net_context *c, int argc, const char **argv)
 {
        struct functable func[] = {
-#if 0
                {
                        "apply",
                        net_ads_gpo_apply,
@@ -633,7 +635,6 @@ int net_ads_gpo(struct net_context *c, int argc, const char **argv)
                        "net ads gpo apply\n"
                        "    Apply GPO to container"
                },
-#endif
                {
                        "getgpo",
                        net_ads_gpo_get_gpo,