Esempio n. 1
0
/****************************************************************************
 display sec_ace object
 ****************************************************************************/
static void disp_sec_ace_object(struct security_ace_object *object)
{
	if (object->flags & SEC_ACE_OBJECT_TYPE_PRESENT) {
		printf("Object type: SEC_ACE_OBJECT_TYPE_PRESENT\n");
		printf("Object GUID: %s\n", GUID_string(talloc_tos(),
			&object->type.type));
	}
	if (object->flags & SEC_ACE_INHERITED_OBJECT_TYPE_PRESENT) {
		printf("Object type: SEC_ACE_INHERITED_OBJECT_TYPE_PRESENT\n");
		printf("Object GUID: %s\n", GUID_string(talloc_tos(), 
			&object->inherited_type.inherited_type));
	}
}
Esempio n. 2
0
/*
  encode an ACE in SDDL format
*/
static char *sddl_encode_ace(TALLOC_CTX *mem_ctx, const struct security_ace *ace,
			     const struct dom_sid *domain_sid)
{
	char *sddl = NULL;
	TALLOC_CTX *tmp_ctx;
	const char *s_type="", *s_flags="", *s_mask="", 
		*s_object="", *s_iobject="", *s_trustee="";

	tmp_ctx = talloc_new(mem_ctx);
	if (tmp_ctx == NULL) {
		DEBUG(0, ("talloc_new failed\n"));
		return NULL;
	}

	s_type = sddl_flags_to_string(tmp_ctx, ace_types, ace->type, True);
	if (s_type == NULL) goto failed;

	s_flags = sddl_flags_to_string(tmp_ctx, ace_flags, ace->flags, True);
	if (s_flags == NULL) goto failed;

	s_mask = sddl_flags_to_string(tmp_ctx, ace_access_mask, ace->access_mask, True);
	if (s_mask == NULL) {
		s_mask = talloc_asprintf(tmp_ctx, "0x%08x", ace->access_mask);
		if (s_mask == NULL) goto failed;
	}

	if (ace->type == SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT ||
	    ace->type == SEC_ACE_TYPE_ACCESS_DENIED_OBJECT ||
	    ace->type == SEC_ACE_TYPE_SYSTEM_AUDIT_OBJECT ||
	    ace->type == SEC_ACE_TYPE_SYSTEM_AUDIT_OBJECT) {
		if (ace->object.object.flags & SEC_ACE_OBJECT_TYPE_PRESENT) {
			s_object = GUID_string(tmp_ctx, &ace->object.object.type.type);
			if (s_object == NULL) goto failed;
		}

		if (ace->object.object.flags & SEC_ACE_INHERITED_OBJECT_TYPE_PRESENT) {
			s_iobject = GUID_string(tmp_ctx, &ace->object.object.inherited_type.inherited_type);
			if (s_iobject == NULL) goto failed;
		}
	}
	
	s_trustee = sddl_encode_sid(tmp_ctx, &ace->trustee, domain_sid);
	if (s_trustee == NULL) goto failed;

	sddl = talloc_asprintf(mem_ctx, "%s;%s;%s;%s;%s;%s",
			       s_type, s_flags, s_mask, s_object, s_iobject, s_trustee);

failed:
	talloc_free(tmp_ctx);
	return sddl;
}
static enum MAPISTATUS
parse_namedprop_cb (uint32_t proptag, struct MAPINAMEID nameid, void *closure)
{
	/* the next property is a named property, but cannot make it proptag, thus left it for later */
	EMapiFXParserClosure *data = closure;
	uint32_t lid = MAPI_E_RESERVED;
	char *guid;

	guid = GUID_string (data->mem_ctx, &(nameid.lpguid));

	if (nameid.ulKind == MNID_ID) {
		if (mapi_nameid_lid_lookup_canonical (nameid.kind.lid, guid, &lid) != MAPI_E_SUCCESS)
			lid = MAPI_E_RESERVED;
	} else if (nameid.ulKind == MNID_STRING) {
		if (mapi_nameid_string_lookup_canonical (nameid.kind.lpwstr.Name, guid, &lid) != MAPI_E_SUCCESS)
			lid = MAPI_E_RESERVED;
	}

	talloc_free (guid);

	if (lid != MAPI_E_RESERVED && (lid & 0xFFFF) == (proptag & 0xFFFF)) {
		data->next_proptag_is_nameid = proptag;
		data->next_nameid_proptag = lid;
	}

	return MAPI_E_SUCCESS;
}
Esempio n. 4
0
static PyObject *py_samdb_ntds_objectGUID(PyObject *self, PyObject *args)
{
	PyObject *py_ldb, *result;
	struct ldb_context *ldb;
	const struct GUID *guid;
	char *retstr;

	if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
		return NULL;
	}

	PyErr_LDB_OR_RAISE(py_ldb, ldb);

	guid = samdb_ntds_objectGUID(ldb);
	if (guid == NULL) {
		PyErr_SetString(PyExc_RuntimeError, "Failed to find NTDS GUID");
		return NULL;
	}

	retstr = GUID_string(NULL, guid);
	if (retstr == NULL) {
		PyErr_NoMemory();
		return NULL;
	}
	result = PyString_FromString(retstr);
	talloc_free(retstr);
	return result;
}
/*
  get the DN of the nTDSDSA object from the configuration partition
  whose invocationId is 'invocation_id'
  put the value on 'dn_str'
*/
static WERROR get_dn_from_invocation_id(TALLOC_CTX *mem_ctx,
					struct ldb_context *samdb,
					struct GUID *invocation_id,
					const char **dn_str)
{
	char *invocation_id_str;
	const char *attrs_invocation[] = { NULL };
	struct ldb_message *msg;
	int ret;

	invocation_id_str = GUID_string(mem_ctx, invocation_id);
	W_ERROR_HAVE_NO_MEMORY(invocation_id_str);

	ret = dsdb_search_one(samdb, invocation_id_str, &msg, ldb_get_config_basedn(samdb), LDB_SCOPE_SUBTREE,
			      attrs_invocation, 0, "(&(objectClass=nTDSDSA)(invocationId=%s))", invocation_id_str);
	if (ret != LDB_SUCCESS) {
		DEBUG(0, (__location__ ": Failed search for the object DN under %s whose invocationId is %s",
			  invocation_id_str, ldb_dn_get_linearized(ldb_get_config_basedn(samdb))));
		talloc_free(invocation_id_str);
		return WERR_INTERNAL_ERROR;
	}

	*dn_str = ldb_dn_alloc_linearized(mem_ctx, msg->dn);
	talloc_free(invocation_id_str);
	return WERR_OK;
}
Esempio n. 6
0
static struct IUnknown *get_com_class_so(TALLOC_CTX *mem_ctx, const struct GUID *clsid)
{
	char *module_name;
	char *clsid_str;
	void *mod;
	get_class_object_function f;

	clsid_str = GUID_string(mem_ctx, clsid);
	module_name = talloc_asprintf(mem_ctx, "%s.so", clsid_str);
	talloc_free(clsid_str);

	mod = dlopen(module_name, 0);

	if (!mod) {
		return NULL;
	}
	
	f = dlsym(mod, "get_class_object");

	if (!f) {
		dlclose(mod);
		return NULL;
	}

	return f(clsid);
}
Esempio n. 7
0
static bool test_Lookup_simple(struct torture_context *tctx,
			       struct dcerpc_pipe *p)
{
	NTSTATUS status;
	struct epm_Lookup r;
	struct policy_handle entry_handle;
	uint32_t num_ents = 0;
	struct dcerpc_binding_handle *h = p->binding_handle;

	ZERO_STRUCT(entry_handle);

	torture_comment(tctx, "Testing epm_Lookup\n");

	/* get all elements */
	r.in.inquiry_type = RPC_C_EP_ALL_ELTS;
	r.in.object = NULL;
	r.in.interface_id = NULL;
	r.in.vers_option = RPC_C_VERS_ALL;

	r.in.entry_handle = &entry_handle;
	r.in.max_ents = 10;

	r.out.entry_handle = &entry_handle;
	r.out.num_ents = &num_ents;

	do {
		int i;

		status = dcerpc_epm_Lookup_r(h, tctx, &r);
		if (!NT_STATUS_IS_OK(status) ||
		    r.out.result != EPMAPPER_STATUS_OK) {
			break;
		}

		torture_comment(tctx,
				"epm_Lookup returned %d events, entry_handle: %s\n",
				*r.out.num_ents,
				GUID_string(tctx, &entry_handle.uuid));

		for (i = 0; i < *r.out.num_ents; i++) {
			torture_comment(tctx,
					"\n  Found '%s'\n",
					r.out.entries[i].annotation);

			display_tower(tctx, &r.out.entries[i].tower->tower);
		}
	} while (NT_STATUS_IS_OK(status) &&
		 r.out.result == EPMAPPER_STATUS_OK &&
		 *r.out.num_ents == r.in.max_ents &&
		 !ndr_policy_handle_empty(&entry_handle));

	torture_assert_ntstatus_ok(tctx, status, "epm_Lookup failed");
	torture_assert(tctx, r.out.result == EPMAPPER_STATUS_NO_MORE_ENTRIES, "epm_Lookup failed");

	torture_assert(tctx,
		       ndr_policy_handle_empty(&entry_handle),
		       "epm_Lookup failed - The policy handle should be emtpy.");

	return true;
}
Esempio n. 8
0
_PUBLIC_ char *GUID_string2(TALLOC_CTX *mem_ctx, const struct GUID *guid)
{
	char *ret, *s = GUID_string(mem_ctx, guid);
	ret = talloc_asprintf(mem_ctx, "{%s}", s);
	talloc_free(s);
	return ret;
}
Esempio n. 9
0
static struct MprVar mprDomainSecrets(struct samba3_domainsecrets *ds)
{
	struct MprVar v, e = mprObject("domainsecrets");
	char *tmp;
	DATA_BLOB blob;

	mprSetVar(&e, "name", mprString(ds->name));

	tmp = dom_sid_string(NULL, &ds->sid);
	mprSetVar(&e, "sid", mprString(tmp));
	talloc_free(tmp);

	tmp = GUID_string(NULL, &ds->guid);
	mprSetVar(&e, "guid", mprString(tmp));
	talloc_free(tmp);

	mprSetVar(&e, "plaintext_pw", mprString(ds->plaintext_pw));

	mprSetVar(&e, "last_change_time", mprCreateIntegerVar(ds->last_change_time));
	mprSetVar(&e, "sec_channel_type", mprCreateIntegerVar(ds->sec_channel_type));

	v = mprObject("hash_pw");

	blob.data = ds->hash_pw.hash;
	blob.length = 16;
	mprSetVar(&v, "hash", mprDataBlob(blob));

	mprSetVar(&v, "mod_time", mprCreateIntegerVar(ds->hash_pw.mod_time));

	mprSetVar(&e, "hash_pw", v);

	return e;
}
Esempio n. 10
0
static void display_domain_controller_info_2(struct drsuapi_DsGetDCInfo2 *r)
{
	printf("netbios_name:\t%s\n", r->netbios_name);
	printf("dns_name:\t%s\n", r->dns_name);
	printf("site_name:\t%s\n", r->site_name);
	printf("site_dn:\t%s\n", r->site_dn);
	printf("computer_dn:\t%s\n", r->computer_dn);
	printf("server_dn:\t%s\n", r->server_dn);
	printf("ntds_dn:\t%s\n", r->ntds_dn);
	printf("is_pdc:\t\t%s\n", r->is_pdc ? "true" : "false");
	printf("is_enabled:\t%s\n", r->is_enabled ? "true" : "false");
	printf("is_gc:\t\t%s\n", r->is_gc ? "true" : "false");
	printf("site_guid:\t%s\n", GUID_string(talloc_tos(), &r->site_guid));
	printf("computer_guid:\t%s\n", GUID_string(talloc_tos(), &r->computer_guid));
	printf("server_guid:\t%s\n", GUID_string(talloc_tos(), &r->server_guid));
	printf("ntds_guid:\t%s\n", GUID_string(talloc_tos(), &r->ntds_guid));
}
Esempio n. 11
0
/*
  form a binding string from a binding structure
*/
_PUBLIC_ char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_binding *b)
{
	char *s = talloc_strdup(mem_ctx, "");
	int i;
	const char *t_name = NULL;

	if (b->transport != NCA_UNKNOWN) {
		t_name = derpc_transport_string_by_transport(b->transport);
		if (!t_name) {
			return NULL;
		}
	}

	if (!GUID_all_zero(&b->object.uuid)) { 
		s = talloc_asprintf(s, "%s@",
				    GUID_string(mem_ctx, &b->object.uuid));
	}

	if (t_name != NULL) {
		s = talloc_asprintf_append_buffer(s, "%s:", t_name);
		if (s == NULL) {
			return NULL;
		}
	}

	if (b->host) {
		s = talloc_asprintf_append_buffer(s, "%s", b->host);
	}

	if (!b->endpoint && !b->options && !b->flags) {
		return s;
	}

	s = talloc_asprintf_append_buffer(s, "[");

	if (b->endpoint) {
		s = talloc_asprintf_append_buffer(s, "%s", b->endpoint);
	}

	/* this is a *really* inefficent way of dealing with strings,
	   but this is rarely called and the strings are always short,
	   so I don't care */
	for (i=0;b->options && b->options[i];i++) {
		s = talloc_asprintf_append_buffer(s, ",%s", b->options[i]);
		if (!s) return NULL;
	}

	for (i=0;i<ARRAY_SIZE(ncacn_options);i++) {
		if (b->flags & ncacn_options[i].flag) {
			s = talloc_asprintf_append_buffer(s, ",%s", ncacn_options[i].name);
			if (!s) return NULL;
		}
	}

	s = talloc_asprintf_append_buffer(s, "]");

	return s;
}
Esempio n. 12
0
/****************************************************************************
 display sec_ace object
 ****************************************************************************/
static void disp_sec_ace_object(struct security_ace_object *object)
{
	char *str;
	if (object->flags & SEC_ACE_OBJECT_TYPE_PRESENT) {
		str = GUID_string(NULL, &object->type.type);
		if (str == NULL) return;
		printf("Object type: SEC_ACE_OBJECT_TYPE_PRESENT\n");
		printf("Object GUID: %s\n", str);
		talloc_free(str);
	}
	if (object->flags & SEC_ACE_INHERITED_OBJECT_TYPE_PRESENT) {
		str = GUID_string(NULL, &object->inherited_type.inherited_type);
		if (str == NULL) return;
		printf("Object type: SEC_ACE_INHERITED_OBJECT_TYPE_PRESENT\n");
		printf("Object GUID: %s\n", str);
		talloc_free(str);
	}
}
Esempio n. 13
0
static void display_query_info_12(struct lsa_DnsDomainInfo *r)
{
	d_printf("Domain NetBios Name: %s\n", r->name.string);
	d_printf("Domain DNS Name: %s\n", r->dns_domain.string);
	d_printf("Domain Forest Name: %s\n", r->dns_forest.string);
	d_printf("Domain Sid: %s\n", sid_string_tos(r->sid));
	d_printf("Domain GUID: %s\n", GUID_string(talloc_tos(),
						      &r->domain_guid));
}
Esempio n. 14
0
/*
  DsReplicaSync messages from the DRSUAPI server are forwarded here
 */
static NTSTATUS drepl_replica_sync(struct irpc_message *msg, 
				   struct drsuapi_DsReplicaSync *r)
{
	struct dreplsrv_service *service = talloc_get_type(msg->private_data,
							   struct dreplsrv_service);
	struct GUID *guid = &r->in.req.req1.naming_context->guid;

	r->out.result = dreplsrv_schedule_partition_pull_by_guid(service, msg, guid);
	if (W_ERROR_IS_OK(r->out.result)) {
		DEBUG(3,("drepl_replica_sync: forcing sync of partition %s\n",
			 GUID_string(msg, guid)));
		dreplsrv_run_pending_ops(service);
	} else {
		DEBUG(3,("drepl_replica_sync: failed setup of sync of partition %s - %s\n",
			 GUID_string(msg, guid), win_errstr(r->out.result)));
	}
	return NT_STATUS_OK;
}
Esempio n. 15
0
static enum winbindd_result dual_dsgetdcname(struct winbindd_domain *domain,
					     struct winbindd_cli_state *state)
{
	NTSTATUS result;
	struct netr_DsRGetDCNameInfo *info = NULL;
	uint32_t ds_flags = 0;
	struct GUID guid, *guid_ptr = NULL;
	const char *guid_str = NULL;

	state->request.data.dsgetdcname.domain_name
		[sizeof(state->request.data.dsgetdcname.domain_name)-1] = '\0';
	state->request.data.dsgetdcname.site_name
		[sizeof(state->request.data.dsgetdcname.site_name)-1] = '\0';
	state->request.data.dsgetdcname.domain_guid
		[sizeof(state->request.data.dsgetdcname.domain_guid)-1] = '\0';

	DEBUG(3, ("[%5lu]: dsgetdcname for %s\n", (unsigned long)state->pid,
		  state->request.data.dsgetdcname.domain_name));

	ds_flags = get_dsgetdc_flags(state->request.flags);

	result = GUID_from_string(state->request.data.dsgetdcname.domain_guid,
				  &guid);
	if (NT_STATUS_IS_OK(result) && !GUID_all_zero(&guid)) {
		guid_ptr = &guid;
	}

	result = dsgetdcname(state->mem_ctx,
			     winbind_messaging_context(),
			     state->request.data.dsgetdcname.domain_name,
			     guid_ptr,
			     state->request.data.dsgetdcname.site_name,
			     ds_flags,
			     &info);

	if (!NT_STATUS_IS_OK(result)) {
		return WINBINDD_ERROR;
	}

	guid_str = GUID_string(state->mem_ctx, &info->domain_guid);
	if (!guid_str) {
		return WINBINDD_ERROR;
	}

	fstrcpy(state->response.data.dsgetdcname.dc_unc, info->dc_unc);
	fstrcpy(state->response.data.dsgetdcname.dc_address, info->dc_address);
	state->response.data.dsgetdcname.dc_address_type = info->dc_address_type;
	fstrcpy(state->response.data.dsgetdcname.domain_guid, guid_str);
	fstrcpy(state->response.data.dsgetdcname.domain_name, info->domain_name);
	fstrcpy(state->response.data.dsgetdcname.forest_name, info->forest_name);
	state->response.data.dsgetdcname.dc_flags = info->dc_flags;
	fstrcpy(state->response.data.dsgetdcname.dc_site_name, info->dc_site_name);
	fstrcpy(state->response.data.dsgetdcname.client_site_name, info->client_site_name);

	return WINBINDD_OK;
}
Esempio n. 16
0
static void ads_disp_sec_ace_object(ADS_STRUCT *ads, 
				    TALLOC_CTX *mem_ctx, 
				    struct security_ace_object *object)
{
	if (object->flags & SEC_ACE_OBJECT_TYPE_PRESENT) {
		printf("Object type: SEC_ACE_OBJECT_TYPE_PRESENT\n");
		printf("Object GUID: %s (%s)\n", GUID_string(mem_ctx, 
			&object->type.type), 
			ads_interprete_guid_from_object(ads, mem_ctx, 
				&object->type.type));
	}
	if (object->flags & SEC_ACE_INHERITED_OBJECT_TYPE_PRESENT) {
		printf("Object type: SEC_ACE_INHERITED_OBJECT_TYPE_PRESENT\n");
		printf("Object GUID: %s (%s)\n", GUID_string(mem_ctx,
			&object->inherited_type.inherited_type),
			ads_interprete_guid_from_object(ads, mem_ctx, 
				&object->inherited_type.inherited_type));
	}
}
Esempio n. 17
0
/**
 * Helper to schedule a replication operation with a source DSA.
 * If 'data' is valid pointer, then a callback
 * for the operation is passed and 'data->msg' is
 * marked as 'deferred' - defer_reply = true
 */
static WERROR _drepl_schedule_replication(struct dreplsrv_service *service,
					  struct dreplsrv_partition_source_dsa *dsa,
					  struct drsuapi_DsReplicaObjectIdentifier *nc,
					  uint32_t rep_options,
					  struct drepl_replica_sync_cb_data *data,
					  TALLOC_CTX *mem_ctx)
{
	WERROR werr;
	dreplsrv_extended_callback_t fn_callback = NULL;

	if (data) {
		fn_callback = _drepl_replica_sync_done_cb;
	}

	/* schedule replication item */
	werr = dreplsrv_schedule_partition_pull_source(service, dsa, rep_options,
	                                               DRSUAPI_EXOP_NONE, 0,
	                                               fn_callback, data);
	if (!W_ERROR_IS_OK(werr)) {
		DEBUG(0,("%s: failed setup of sync of partition (%s, %s, %s) - %s\n",
			 __FUNCTION__,
			 GUID_string(mem_ctx, &nc->guid),
			 nc->dn,
			 dsa->repsFrom1->other_info->dns_name,
			 win_errstr(werr)));
		return werr;
	}
	/* log we've scheduled a replication item */
	DEBUG(3,("%s: forcing sync of partition (%s, %s, %s)\n",
		 __FUNCTION__,
		 GUID_string(mem_ctx, &nc->guid),
		 nc->dn,
		 dsa->repsFrom1->other_info->dns_name));

	/* mark IRPC message as deferred if necessary */
	if (data) {
		data->ops_count++;
		data->msg->defer_reply = true;
	}

	return WERR_OK;
}
Esempio n. 18
0
WERROR nt_printer_guid_store(struct messaging_context *msg_ctx,
			     const char *printer, struct GUID guid)
{
	TALLOC_CTX *tmp_ctx;
	const struct auth_session_info *session_info;
	const char *guid_str;
	DATA_BLOB blob;
	WERROR result;

	tmp_ctx = talloc_new(NULL);
	if (!tmp_ctx) {
		DEBUG(0, ("Out of memory?!\n"));
		return WERR_NOMEM;
	}

	session_info = get_session_info_system();
	if (session_info == NULL) {
		DEBUG(0, ("Could not get system session_info\n"));
		result = WERR_NOMEM;
		goto done;
	}

	guid_str = GUID_string(tmp_ctx, &guid);
	if (!guid_str) {
		DEBUG(0, ("Out of memory?!\n"));
		result = WERR_NOMEM;
		goto done;
	}

	/* We used to store this as a REG_BINARY but that causes
	   Vista to whine */

	if (!push_reg_sz(tmp_ctx, &blob, guid_str)) {
		DEBUG(0, ("Could not marshall string %s for objectGUID\n",
			  guid_str));
		result = WERR_NOMEM;
		goto done;
	}

	result = winreg_set_printer_dataex_internal(tmp_ctx, session_info, msg_ctx,
					   printer,
					   SPOOL_DSSPOOLER_KEY, "objectGUID",
					   REG_SZ, blob.data, blob.length);
	if (!W_ERROR_IS_OK(result)) {
		DEBUG(0, ("Failed to store GUID for printer %s\n", printer));
		goto done;
	}

	result = WERR_OK;
done:
	talloc_free(tmp_ctx);

	return result;
}
Esempio n. 19
0
static BOOL test_Lookup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
{
	NTSTATUS status;
	struct epm_Lookup r;
	struct GUID uuid;
	struct rpc_if_id_t iface;
	struct policy_handle handle;

	ZERO_STRUCT(handle);

	r.in.inquiry_type = 0;
	r.in.object = &uuid;
	r.in.interface_id = &iface;
	r.in.vers_option = 0;
	r.in.entry_handle = &handle;
	r.out.entry_handle = &handle;
	r.in.max_ents = 10;

	do {
		int i;

		ZERO_STRUCT(uuid);
		ZERO_STRUCT(iface);

		status = dcerpc_epm_Lookup(p, mem_ctx, &r);
		if (!NT_STATUS_IS_OK(status) || r.out.result != 0) {
			break;
		}

		printf("epm_Lookup returned %d events GUID %s\n", 
		       *r.out.num_ents, GUID_string(mem_ctx, &handle.uuid));

		for (i=0;i<*r.out.num_ents;i++) {
			printf("\nFound '%s'\n", r.out.entries[i].annotation);
			display_tower(mem_ctx, &r.out.entries[i].tower->tower);
			if (r.out.entries[i].tower->tower.num_floors == 5) {
				test_Map(p, mem_ctx, r.out.entries[i].tower);
			}
		}
	} while (NT_STATUS_IS_OK(status) && 
		 r.out.result == 0 && 
		 *r.out.num_ents == r.in.max_ents &&
		 !policy_handle_empty(&handle));

	if (!NT_STATUS_IS_OK(status)) {
		printf("Lookup failed - %s\n", nt_errstr(status));
		return False;
	}


	return True;
}
Esempio n. 20
0
static bool test_connect_service(struct torture_context *tctx,
				 struct libnet_context *ctx,
				 const struct ndr_interface_table *iface,
				 const char *binding_string,
				 const char *hostname,
				 const enum libnet_RpcConnect_level level,
				 bool badcreds, NTSTATUS expected_status)
{
	NTSTATUS status;
	struct libnet_RpcConnect connect_r;
	ZERO_STRUCT(connect_r);

	connect_r.level            = level;
	connect_r.in.binding       = binding_string;
	connect_r.in.name          = hostname;
	connect_r.in.dcerpc_iface  = iface;

	/* if bad credentials are needed, set baduser%badpassword instead
	   of default commandline-passed credentials */
	if (badcreds) {
		cli_credentials_set_username(ctx->cred, "baduser", CRED_SPECIFIED);
		cli_credentials_set_password(ctx->cred, "badpassword", CRED_SPECIFIED);
	}

	status = libnet_RpcConnect(ctx, ctx, &connect_r);

	if (!NT_STATUS_EQUAL(status, expected_status)) {
		torture_comment(tctx, "Connecting to rpc service %s on %s.\n\tFAILED. Expected: %s."
		       "Received: %s\n",
		       connect_r.in.dcerpc_iface->name, connect_r.in.binding, nt_errstr(expected_status),
		       nt_errstr(status));

		return false;
	}

	torture_comment(tctx, "PASSED. Expected: %s, received: %s\n", nt_errstr(expected_status),
	       nt_errstr(status));

	if (connect_r.level == LIBNET_RPC_CONNECT_DC_INFO && NT_STATUS_IS_OK(status)) {
		torture_comment(tctx, "Domain Controller Info:\n");
		torture_comment(tctx, "\tDomain Name:\t %s\n", connect_r.out.domain_name);
		torture_comment(tctx, "\tDomain SID:\t %s\n", dom_sid_string(ctx, connect_r.out.domain_sid));
		torture_comment(tctx, "\tRealm:\t\t %s\n", connect_r.out.realm);
		torture_comment(tctx, "\tGUID:\t\t %s\n", GUID_string(ctx, connect_r.out.guid));

	} else if (!NT_STATUS_IS_OK(status)) {
		torture_comment(tctx, "Error string: %s\n", connect_r.out.error_string);
	}

	return true;
}
Esempio n. 21
0
static void store_printer_guid(struct messaging_context *msg_ctx,
			       const char *printer, struct GUID guid)
{
	TALLOC_CTX *tmp_ctx;
	struct auth_serversupplied_info *session_info = NULL;
	const char *guid_str;
	DATA_BLOB blob;
	NTSTATUS status;
	WERROR result;

	tmp_ctx = talloc_new(NULL);
	if (!tmp_ctx) {
		DEBUG(0, ("store_printer_guid: Out of memory?!\n"));
		return;
	}

	status = make_session_info_system(tmp_ctx, &session_info);
	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(0, ("store_printer_guid: "
			  "Could not create system session_info\n"));
		goto done;
	}

	guid_str = GUID_string(tmp_ctx, &guid);
	if (!guid_str) {
		DEBUG(0, ("store_printer_guid: Out of memory?!\n"));
		goto done;
	}

	/* We used to store this as a REG_BINARY but that causes
	   Vista to whine */

	if (!push_reg_sz(tmp_ctx, &blob, guid_str)) {
		DEBUG(0, ("store_printer_guid: "
			  "Could not marshall string %s for objectGUID\n",
			  guid_str));
		goto done;
	}

	result = winreg_set_printer_dataex(tmp_ctx, session_info, msg_ctx,
					   printer,
					   SPOOL_DSSPOOLER_KEY, "objectGUID",
					   REG_SZ, blob.data, blob.length);
	if (!W_ERROR_IS_OK(result)) {
		DEBUG(0, ("store_printer_guid: "
			  "Failed to store GUID for printer %s\n", printer));
	}

done:
	talloc_free(tmp_ctx);
}
Esempio n. 22
0
/*
 * This test starts a epm_Lookup request, but doesn't finish the
 * call terminates the search. So it will call epm_LookupHandleFree.
 */
static bool test_Lookup_terminate_search(struct torture_context *tctx,
					 struct dcerpc_pipe *p)
{
	bool ok;
	NTSTATUS status;
	struct epm_Lookup r;
	struct policy_handle entry_handle;
	uint32_t i, num_ents = 0;
	struct dcerpc_binding_handle *h = p->binding_handle;

	ZERO_STRUCT(entry_handle);

	torture_comment(tctx, "Testing epm_Lookup and epm_LookupHandleFree\n");

	/* get all elements */
	r.in.inquiry_type = RPC_C_EP_ALL_ELTS;
	r.in.object = NULL;
	r.in.interface_id = NULL;
	r.in.vers_option = RPC_C_VERS_ALL;

	r.in.entry_handle = &entry_handle;
	r.in.max_ents = 2;

	r.out.entry_handle = &entry_handle;
	r.out.num_ents = &num_ents;

	status = dcerpc_epm_Lookup_r(h, tctx, &r);

	torture_assert_ntstatus_ok(tctx, status, "epm_Lookup failed");
	torture_assert(tctx, r.out.result == EPMAPPER_STATUS_OK, "epm_Lookup failed");

	torture_comment(tctx,
			"epm_Lookup returned %d events, entry_handle: %s\n",
			*r.out.num_ents,
			GUID_string(tctx, &entry_handle.uuid));

	for (i = 0; i < *r.out.num_ents; i++) {
		torture_comment(tctx,
				"\n  Found '%s'\n",
				r.out.entries[i].annotation);
	}

	ok = test_LookupHandleFree(tctx,
				   h,
				   &entry_handle);
	if (!ok) {
		return false;
	}

	return true;
}
Esempio n. 23
0
static bool test_Lookup(struct torture_context *tctx, 
						struct dcerpc_pipe *p)
{
	NTSTATUS status;
	struct epm_Lookup r;
	struct GUID uuid;
	struct rpc_if_id_t iface;
	struct policy_handle handle;
	uint32_t num_ents;

	ZERO_STRUCT(handle);

	r.in.inquiry_type = 0;
	r.in.object = &uuid;
	r.in.interface_id = &iface;
	r.in.vers_option = 0;
	r.in.entry_handle = &handle;
	r.out.entry_handle = &handle;
	r.in.max_ents = 10;
	r.out.num_ents = &num_ents;

	do {
		int i;

		ZERO_STRUCT(uuid);
		ZERO_STRUCT(iface);

		status = dcerpc_epm_Lookup(p, tctx, &r);
		if (!NT_STATUS_IS_OK(status) || r.out.result != 0) {
			break;
		}

		printf("epm_Lookup returned %d events GUID %s\n", 
		       *r.out.num_ents, GUID_string(tctx, &handle.uuid));

		for (i=0;i<*r.out.num_ents;i++) {
			printf("\nFound '%s'\n", r.out.entries[i].annotation);
			display_tower(tctx, &r.out.entries[i].tower->tower);
			if (r.out.entries[i].tower->tower.num_floors == 5) {
				test_Map(p, tctx, r.out.entries[i].tower);
			}
		}
	} while (NT_STATUS_IS_OK(status) && 
		 r.out.result == 0 && 
		 *r.out.num_ents == r.in.max_ents &&
		 !policy_handle_empty(&handle));

	torture_assert_ntstatus_ok(tctx, status, "Lookup failed");

	return true;
}
Esempio n. 24
0
/*
  ask the server what interface IDs are available on this endpoint
*/
bool test_inq_if_ids(struct torture_context *tctx, 
		     struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
		     bool (*per_id_test)(struct torture_context *,
					 const struct ndr_interface_table *iface,
					 TALLOC_CTX *mem_ctx,
					 struct ndr_syntax_id *id),
		     const void *priv)
{
	NTSTATUS status;
	struct mgmt_inq_if_ids r;
	struct rpc_if_id_vector_t *vector;
	int i;

	vector = talloc(mem_ctx, struct rpc_if_id_vector_t);
	r.out.if_id_vector = &vector;
	
	status = dcerpc_mgmt_inq_if_ids(p, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		printf("inq_if_ids failed - %s\n", nt_errstr(status));
		return false;
	}

	if (!W_ERROR_IS_OK(r.out.result)) {
		printf("inq_if_ids gave error code %s\n", win_errstr(r.out.result));
		return false;
	}

	if (!vector) {
		printf("inq_if_ids gave NULL if_id_vector\n");
		return false;
	}

	for (i=0;i<vector->count;i++) {
		struct ndr_syntax_id *id = vector->if_id[i].id;
		if (!id) continue;

		printf("\tuuid %s  version 0x%08x  '%s'\n",
		       GUID_string(mem_ctx, &id->uuid),
		       id->if_version,
		       ndr_interface_name(&id->uuid, id->if_version));

		if (per_id_test) {
			per_id_test(tctx, priv, mem_ctx, id);
		}
	}

	return true;
}
/**
   \details return the mapped property ID matching the nameid
   structure passed in parameter.

   \param ldb_ctx pointer to the namedprops ldb context
   \param nameid the MAPINAMEID structure to lookup
   \param propID pointer to the property ID the function returns

   \return MAPISTORE_SUCCESS on success, otherwise MAPISTORE_ERROR
 */
_PUBLIC_ enum mapistore_error mapistore_namedprops_create_id(struct ldb_context *ldb_ctx, struct MAPINAMEID nameid, uint16_t mapped_id)
{
	int ret;
	TALLOC_CTX *mem_ctx;
	char *ldif_record;
	struct ldb_ldif *ldif;
	char *hex_id, *dec_id, *dec_mappedid, *guid;
	struct ldb_message *normalized_msg;
	const char *ldif_records[] = { NULL, NULL };

	mem_ctx = talloc_zero(NULL, TALLOC_CTX);

	dec_mappedid = talloc_asprintf(mem_ctx, "%u", mapped_id);
	guid = GUID_string(mem_ctx, &nameid.lpguid);
	switch (nameid.ulKind) {
	case MNID_ID:
		hex_id = talloc_asprintf(mem_ctx, "%.4x", nameid.kind.lid);
		dec_id = talloc_asprintf(mem_ctx, "%u", nameid.kind.lid);
		ldif_record = talloc_asprintf(mem_ctx, "dn: CN=0x%s,CN=%s,CN=default\nobjectClass: MNID_ID\ncn: 0x%s\npropType: PT_NULL\noleguid: %s\nmappedId: %s\npropId: %s\n",
					      hex_id, guid, hex_id, guid, dec_mappedid, dec_id);
		break;
	case MNID_STRING:
		ldif_record = talloc_asprintf(mem_ctx, "dn: CN=%s,CN=%s,CN=default\nobjectClass: MNID_STRING\ncn: %s\npropType: PT_NULL\noleguid: %s\nmappedId: %s\npropName: %s\n",
					      nameid.kind.lpwstr.Name, guid, nameid.kind.lpwstr.Name, guid, dec_mappedid, nameid.kind.lpwstr.Name);
		break;
	default:
		abort();
	}

	DEBUG(5, ("inserting record:\n%s\n", ldif_record));
	ldif_records[0] = ldif_record;
	ldif = ldb_ldif_read_string(ldb_ctx, ldif_records);
	ret = ldb_msg_normalize(ldb_ctx, mem_ctx, ldif->msg, &normalized_msg);
	MAPISTORE_RETVAL_IF(ret, MAPISTORE_ERR_DATABASE_INIT, NULL);
	ret = ldb_add(ldb_ctx, normalized_msg);
	talloc_free(normalized_msg);
	if (ret != LDB_SUCCESS) {
		MAPISTORE_RETVAL_IF(ret, MAPISTORE_ERR_DATABASE_INIT, NULL);
	}

	/* we invalidate the cache, if present */
	if (nameids_cache) {
		talloc_free(nameids_cache);
		nameids_cache = NULL;
	}

	return ret;
}
Esempio n. 26
0
/*
  convert a NDR formatted blob to a ldif formatted objectGUID
*/
static int ldif_write_objectGUID(struct ldb_context *ldb, void *mem_ctx,
				 const struct ldb_val *in, struct ldb_val *out)
{
	struct GUID guid;
	NTSTATUS status;

	status = GUID_from_ndr_blob(in, &guid);
	if (!NT_STATUS_IS_OK(status)) {
		return -1;
	}
	out->data = (uint8_t *)GUID_string(mem_ctx, &guid);
	if (out->data == NULL) {
		return -1;
	}
	out->length = strlen((const char *)out->data);
	return 0;
}
Esempio n. 27
0
File: ndr.c Progetto: endisd/samba
static bool test_guid_string_valid(struct torture_context *tctx)
{
	struct GUID g;
	g.time_low = 1;
	g.time_mid = 2;
	g.time_hi_and_version = 3;
	g.clock_seq[0] = 4;
	g.clock_seq[1] = 5;
	g.node[0] = 6;
	g.node[1] = 7;
	g.node[2] = 8;
	g.node[3] = 9;
	g.node[4] = 10;
	g.node[5] = 11;
	torture_assert_str_equal(tctx, "00000001-0002-0003-0405-060708090a0b", GUID_string(tctx, &g), 
							 "parsing guid failed");
	return true;
}
Esempio n. 28
0
static struct fss_sc *sc_lookup(struct fss_sc *sc_head, struct GUID *sc_id)
{

	struct fss_sc *sc;
	char *guid_str;

	for (sc = sc_head; sc; sc = sc->next) {
		if (GUID_equal(&sc->id, sc_id)) {
			return sc;
		}
	}
	guid_str = GUID_string(sc_head, sc_id);
	DEBUG(4, ("shadow copy with GUID %s not found\n",
		  guid_str ? guid_str : "NO MEM"));
	talloc_free(guid_str);

	return NULL;
}
Esempio n. 29
0
static enum mapistore_error get_mapped_id(struct namedprops_context *self,
					  struct MAPINAMEID nameid,
					  uint16_t *mapped_id)
{
	TALLOC_CTX *mem_ctx = talloc_zero(NULL, TALLOC_CTX);
	int type = nameid.ulKind;
	char *guid = GUID_string(mem_ctx, &nameid.lpguid);
	MYSQL *conn = self->data;

	char *sql = NULL;
	if (type == MNID_ID) {
		uint32_t prop_id = nameid.kind.lid;
		sql = talloc_asprintf(mem_ctx,
			"SELECT mappedId FROM "NAMEDPROPS_MYSQL_TABLE" "
			"WHERE `type`=%d AND `oleguid`='%s' AND `propId`=%d",
			type, guid, prop_id);
	} else if (type == MNID_STRING) {
		const char *prop_name = nameid.kind.lpwstr.Name;
		sql = talloc_asprintf(mem_ctx,
			"SELECT mappedId FROM "NAMEDPROPS_MYSQL_TABLE" "
			"WHERE `type`=%d AND `oleguid`='%s' AND `propName`='%s'",
			type, guid, prop_name);
	} else {
		MAPISTORE_RETVAL_IF(true, MAPISTORE_ERROR, mem_ctx);
	}

	if (mysql_query(conn, sql) != 0) {
		MAPISTORE_RETVAL_IF(true, MAPISTORE_ERR_DATABASE_OPS, mem_ctx);
	}

	MYSQL_RES *res = mysql_store_result(conn);
	if (mysql_num_rows(res) == 0) {
		// Not found
		mysql_free_result(res);
		MAPISTORE_RETVAL_IF(true, MAPISTORE_ERR_NOT_FOUND, mem_ctx);
	}
	MYSQL_ROW row = mysql_fetch_row(res);
	*mapped_id = strtol(row[0], NULL, 10);
	mysql_free_result(res);

	talloc_free(mem_ctx);
	return MAPISTORE_SUCCESS;
}
Esempio n. 30
0
int main(int argc, char *argv[])
{
	TALLOC_CTX	*mem_ctx;
	DATA_BLOB	blob;
	struct GUID	*guid;
	char		*schemaIDGUID;

	if (argc != 2) {
		usage();
	}

	mem_ctx = talloc_named(NULL, 0, "SchemaIDGUID");

	blob = data_blob_talloc(mem_ctx, argv[1], strlen(argv[1])+1);
	blob.length = ldb_base64_decode((char *)blob.data);
	guid = (struct GUID *) blob.data;
	schemaIDGUID = GUID_string(mem_ctx, guid);
	printf("%s\n", schemaIDGUID);
	return (0);
}