#include "includes.h"
#include "librpc/gen_ndr/ndr_samr.h"
#include "libnet/composite.h"
+#include "libnet/userinfo.h"
+#include "libcli/composite/monitor.h"
#define TEST_USERNAME "libnetuserinfotest"
static BOOL test_opendomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
- struct policy_handle *handle, struct samr_String *domname,
+ struct policy_handle *handle, struct lsa_String *domname,
struct dom_sid2 *sid)
{
NTSTATUS status;
struct samr_LookupNames r1;
struct samr_OpenUser r2;
struct samr_DeleteUser r3;
- struct samr_String names[2];
+ struct lsa_String names[2];
uint32_t rid;
struct policy_handle user_handle;
struct policy_handle *handle, const char *name, uint32_t *rid)
{
NTSTATUS status;
- struct samr_String username;
+ struct lsa_String username;
struct samr_CreateUser r;
struct policy_handle user_handle;
uint32_t *rid)
{
NTSTATUS status;
- struct rpc_composite_userinfo user;
+ struct libnet_rpc_userinfo user;
+ struct dom_sid *user_sid;
+
+ user_sid = dom_sid_add_rid(mem_ctx, domain_sid, *rid);
+
+ user.in.domain_handle = *domain_handle;
+ user.in.sid = dom_sid_string(mem_ctx, user_sid);
+ user.in.level = 5; /* this should be extended */
+
+ printf("Testing sync libnet_rpc_userinfo\n");
+ status = libnet_rpc_userinfo(p, mem_ctx, &user);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("Failed to call sync libnet_rpc_userinfo - %s\n", nt_errstr(status));
+ return False;
+ }
+
+ return True;
+}
+
+
+static void msg_handler(struct monitor_msg *m)
+{
+ struct msg_rpc_open_user *msg_open;
+ struct msg_rpc_query_user *msg_query;
+ struct msg_rpc_close_user *msg_close;
+
+ switch (m->type) {
+ case rpc_open_user:
+ msg_open = (struct msg_rpc_open_user*)m->data;
+ printf("monitor_msg: user opened (rid=%d, access_mask=0x%08x)\n",
+ msg_open->rid, msg_open->access_mask);
+ break;
+ case rpc_query_user:
+ msg_query = (struct msg_rpc_query_user*)m->data;
+ printf("monitor_msg: user queried (level=%d)\n", msg_query->level);
+ break;
+ case rpc_close_user:
+ msg_close = (struct msg_rpc_close_user*)m->data;
+ printf("monitor_msg: user closed (rid=%d)\n", msg_close->rid);
+ break;
+ }
+}
+
+
+static BOOL test_userinfo_async(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
+ struct policy_handle *domain_handle,
+ struct dom_sid2 *domain_sid, const char* user_name,
+ uint32_t *rid)
+{
+ NTSTATUS status;
+ struct composite_context *c;
+ struct libnet_rpc_userinfo user;
struct dom_sid *user_sid;
user_sid = dom_sid_add_rid(mem_ctx, domain_sid, *rid);
user.in.domain_handle = *domain_handle;
user.in.sid = dom_sid_string(mem_ctx, user_sid);
- user.in.level = 5; /* this should be extended */
+ user.in.level = 10; /* this should be extended */
- printf("Testing sync rpc_composite_userinfo\n");
- status = rpc_composite_userinfo(p, mem_ctx, &user);
+ printf("Testing async libnet_rpc_userinfo\n");
+
+ c = libnet_rpc_userinfo_send(p, &user, msg_handler);
+ if (!c) {
+ printf("Failed to call sync libnet_rpc_userinfo_send\n");
+ return False;
+ }
+
+ status = libnet_rpc_userinfo_recv(c, mem_ctx, &user);
if (!NT_STATUS_IS_OK(status)) {
- printf("Failed to call sync rpc_composite_userinfo - %s\n", nt_errstr(status));
+ printf("Calling async libnet_rpc_userinfo failed - %s\n", nt_errstr(status));
return False;
}
NTSTATUS status;
const char *binding;
struct dcerpc_pipe *p;
- struct dcerpc_binding *b;
TALLOC_CTX *mem_ctx;
BOOL ret = True;
struct policy_handle h;
- struct samr_String name;
+ struct lsa_String name;
struct dom_sid2 sid;
uint32_t rid;
name.string = lp_workgroup();
+ /*
+ * Testing synchronous version
+ */
if (!test_opendomain(p, mem_ctx, &h, &name, &sid)) {
ret = False;
goto done;
ret = False;
goto done;
}
+
+ /*
+ * Testing asynchronous version and monitor messages
+ */
+ if (!test_opendomain(p, mem_ctx, &h, &name, &sid)) {
+ ret = False;
+ goto done;
+ }
+
+ if (!test_create(p, mem_ctx, &h, TEST_USERNAME, &rid)) {
+ ret = False;
+ goto done;
+ }
+
+ if (!test_userinfo_async(p, mem_ctx, &h, &sid, TEST_USERNAME, &rid)) {
+ ret = False;
+ goto done;
+ }
+
+ if (!test_cleanup(p, mem_ctx, &h, TEST_USERNAME)) {
+ ret = False;
+ goto done;
+ }
+
done:
talloc_free(mem_ctx);