r16531: Add a function preparing argument for modify user routine.
authorRafal Szczesniak <mimir@samba.org>
Mon, 26 Jun 2006 21:18:45 +0000 (21:18 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:09:33 +0000 (14:09 -0500)
rafal
(This used to be commit d91cbec2644030a6e7978dd2e2c854e9d7a3d313)

source4/libnet/libnet_user.c

index 22cd44d81ad76d8ae2df59f9b74e78aa27b4c972..7f6c54bcca8d59abd9966201a9b69f2b0ee78bf5 100644 (file)
@@ -24,6 +24,7 @@
 #include "libcli/composite/composite.h"
 #include "auth/credentials/credentials.h"
 #include "librpc/ndr/libndr.h"
+#include "librpc/gen_ndr/samr.h"
 #include "librpc/gen_ndr/ndr_samr.h"
 
 
@@ -348,6 +349,8 @@ struct modify_user_state {
 
 static void continue_rpc_usermod(struct composite_context *ctx);
 static void continue_domain_open_modify(struct composite_context *ctx);
+static NTSTATUS set_user_changes(TALLOC_CTX *mem_ctx, struct usermod_change *mod,
+                                struct libnet_rpc_userinfo *info, struct libnet_ModifyUser *r);
 static void continue_rpc_userinfo(struct composite_context *ctx);
 
 
@@ -428,8 +431,10 @@ static void continue_rpc_userinfo(struct composite_context *ctx)
        c->status = libnet_rpc_userinfo_recv(ctx, c, &s->user_info);
        if (!composite_is_ok(c)) return;
 
-       /* TODO: prepare arguments based on requested changes
-          and received current user info */
+       s->user_mod.in.domain_handle = s->ctx->domain.handle;
+       s->user_mod.in.username      = s->r.in.user_name;
+
+       c->status = set_user_changes(c, &s->user_mod.in.change, &s->user_info, &s->r);
 
        usermod_req = libnet_rpc_usermod_send(s->ctx->samr_pipe, &s->user_mod, s->monitor_fn);
        if (composite_nomem(usermod_req, c)) return;
@@ -438,6 +443,40 @@ static void continue_rpc_userinfo(struct composite_context *ctx)
 }
 
 
+static NTSTATUS set_user_changes(TALLOC_CTX *mem_ctx, struct usermod_change *mod,
+                                struct libnet_rpc_userinfo *info, struct libnet_ModifyUser *r)
+{
+       struct samr_UserInfo21 *user;
+
+       if (mod == NULL || info == NULL || r == NULL || info->in.level != 21) {
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       user = &info->out.info.info21;
+       mod->fields = 0;        /* reset flag field before setting individual flags */
+
+       if (r->in.account_name != NULL &&
+           !strequal_w(user->account_name.string, r->in.account_name)) {
+
+               mod->account_name = talloc_strdup(mem_ctx, r->in.account_name);
+               if (mod->account_name == NULL) return NT_STATUS_NO_MEMORY;
+
+               mod->fields |= USERMOD_FIELD_ACCOUNT_NAME;
+       }
+
+       if (r->in.full_name != NULL &&
+           !strequal_w(user->full_name.string, r->in.full_name)) {
+               
+               mod->full_name = talloc_strdup(mem_ctx, r->in.full_name);
+               if (mod->full_name == NULL) return NT_STATUS_NO_MEMORY;
+
+               mod->fields |= USERMOD_FIELD_FULL_NAME;
+       }
+
+       return NT_STATUS_OK;
+}
+
+
 static void continue_rpc_usermod(struct composite_context *ctx)
 {
        struct composite_context *c;