Changed add_gplink to set_gplink, so we can change gPLink options as well.
authorWilco Baan Hofman <wilco@baanhofman.nl>
Fri, 23 Apr 2010 16:10:43 +0000 (18:10 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Sun, 20 Jun 2010 15:19:11 +0000 (17:19 +0200)
Signed-off-by: Jelmer Vernooij <jelmer@samba.org>
source4/lib/policy/gp_ldap.c
source4/lib/policy/policy.h
source4/utils/net/net_gpo.c

index 8f44adcc6d16fd6f6a1ea8d189cb7952d0ba1def..e1faed13622ddd6d87eb92c1f9a4ebe044ebe759 100644 (file)
@@ -541,7 +541,7 @@ NTSTATUS gp_list_gpos(struct gp_context *gp_ctx, struct security_token *token, c
        return NT_STATUS_OK;
 }
 
-NTSTATUS gp_add_gplink(struct gp_context *gp_ctx, const char *dn_str, struct gp_link *gplink)
+NTSTATUS gp_set_gplink(struct gp_context *gp_ctx, const char *dn_str, struct gp_link *gplink)
 {
        TALLOC_CTX *mem_ctx;
        struct ldb_result *result;
@@ -550,6 +550,7 @@ NTSTATUS gp_add_gplink(struct gp_context *gp_ctx, const char *dn_str, struct gp_
        const char *attrs[] = { "gPLink", NULL };
        const char *gplink_str;
        int rv;
+       char *start;
 
        /* Create a forked memory context, as a base for everything here */
        mem_ctx = talloc_new(gp_ctx);
@@ -570,14 +571,22 @@ NTSTATUS gp_add_gplink(struct gp_context *gp_ctx, const char *dn_str, struct gp_
 
        gplink_str = ldb_msg_find_attr_as_string(result->msgs[0], "gPLink", "");
 
-       if (strstr(gplink_str, gplink->dn) != NULL) {
-               talloc_free(mem_ctx);
-               return NT_STATUS_OBJECT_NAME_COLLISION;
+       /* If this GPO link already exists, alter the options, else add it */
+       if ((start = strcasestr(gplink_str, gplink->dn)) != NULL) {
+               start += strlen(gplink->dn);
+               *start = '\0';
+               start++;
+               while (*start != ']' && *start != '\0') {
+                       start++;
+               }
+               gplink_str = talloc_asprintf(mem_ctx, "%s;%d%s\n", gplink_str, gplink->options, start);
+
+       } else {
+               /* Prepend the new GPO link to the string. This list is backwards in priority. */
+               gplink_str = talloc_asprintf(mem_ctx, "[LDAP://%s;%d]%s", gplink->dn, gplink->options, gplink_str);
        }
 
 
-       /* Prepend the new GPO link to the string. This list is backwards in priority. */
-       gplink_str = talloc_asprintf(mem_ctx, "[LDAP://%s;%d]%s", gplink->dn, gplink->options, gplink_str);
 
        msg = ldb_msg_new(mem_ctx);
        msg->dn = dn;
index 0f78b0f8b83f369ab0c58197b46d840fbdee618a..05a28159890908c91747c7993ad88b0316f16d44 100644 (file)
@@ -80,7 +80,7 @@ NTSTATUS gp_del_gpo(struct gp_context *gp_ctx, const char *dn_str);
 NTSTATUS gp_get_gplink_options(TALLOC_CTX *mem_ctx, uint32_t flags, const char ***ret);
 NTSTATUS gp_get_gpo_flags(TALLOC_CTX *mem_ctx, uint32_t flags, const char ***ret);
 
-NTSTATUS gp_add_gplink(struct gp_context *gp_ctx, const char *dn_str, struct gp_link *gplink);
+NTSTATUS gp_set_gplink(struct gp_context *gp_ctx, const char *dn_str, struct gp_link *gplink);
 NTSTATUS gp_del_gplink(struct gp_context *gp_ctx, const char *dn_str, const char *gp_dn);
 
 #endif
index e828899cac1ce5a0717b2d9c4fc5069856b7de53..ca85bb4f5880ae5f3f2858d27e21e3ebcf65d37d 100644 (file)
@@ -272,14 +272,14 @@ static int net_gpo_list(struct net_context *ctx, int argc, const char **argv)
        return 0;
 }
 
-static int net_gpo_link_add_usage(struct net_context *ctx, int argc, const char **argv)
+static int net_gpo_link_set_usage(struct net_context *ctx, int argc, const char **argv)
 {
-       d_printf("Syntax: net gpo linkadd <container> <gpo> ['disable'] ['enforce'] [options]\n");
-       d_printf("For a list of available options, please type net gpo linkadd --help\n");
+       d_printf("Syntax: net gpo linkset <container> <gpo> ['disable'] ['enforce'] [options]\n");
+       d_printf("For a list of available options, please type net gpo linkset --help\n");
        return 0;
 }
 
-static int net_gpo_link_add(struct net_context *ctx, int argc, const char **argv)
+static int net_gpo_link_set(struct net_context *ctx, int argc, const char **argv)
 {
        struct gp_link *gplink = talloc_zero(ctx, struct gp_link);
        struct gp_context *gp_ctx;
@@ -287,7 +287,7 @@ static int net_gpo_link_add(struct net_context *ctx, int argc, const char **argv
        NTSTATUS status;
 
        if (argc < 2) {
-               return net_gpo_link_add_usage(ctx, argc, argv);
+               return net_gpo_link_set_usage(ctx, argc, argv);
        }
 
        if (argc >= 3) {
@@ -308,9 +308,9 @@ static int net_gpo_link_add(struct net_context *ctx, int argc, const char **argv
                return 1;
        }
 
-       status = gp_add_gplink(gp_ctx, argv[0], gplink);
+       status = gp_set_gplink(gp_ctx, argv[0], gplink);
        if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("Failed to add GPO link to container: %s\n", get_friendly_nt_error_msg(status)));
+               DEBUG(0, ("Failed to set GPO link on container: %s\n", get_friendly_nt_error_msg(status)));
                return 1;
        }
        d_printf("Added link to container.\n");
@@ -326,7 +326,7 @@ static const struct net_functable net_gpo_functable[] = {
        { "listall", "List all GPO's on a DC\n", net_gpo_list_all, net_gpo_list_all_usage },
        { "getgpo", "List specificied GPO\n", net_gpo_get_gpo, net_gpo_get_gpo_usage },
        { "linkget", "List gPLink of container\n", net_gpo_link_get, net_gpo_link_get_usage },
-       { "linkadd", "Link a GPO to a container\n", net_gpo_link_add, net_gpo_link_add_usage },
+       { "linkset", "Link a GPO to a container\n", net_gpo_link_set, net_gpo_link_set_usage },
 /*     { "linkdelete", "Delete GPO link from a container\n", net_gpo_link_delete, net_gpo_usage }, */
        { "list", "List all GPO's for a machine/user\n", net_gpo_list, net_gpo_list_usage },
 /*     { "apply", "Apply GPO to container\n", net_gpo_apply, net_gpo_usage }, */