_PUBLIC_ char *reg_val_data_string(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, uint32_t type, const DATA_BLOB data) { char *ret = NULL; if (data.length == 0) return talloc_strdup(mem_ctx, ""); switch (type) { case REG_EXPAND_SZ: case REG_SZ: convert_string_talloc_convenience(mem_ctx, iconv_convenience, CH_UTF16, CH_UNIX, data.data, data.length, (void **)&ret, NULL, false); return ret; case REG_BINARY: ret = data_blob_hex_string(mem_ctx, &data); return ret; case REG_DWORD: if (*(int *)data.data == 0) return talloc_strdup(mem_ctx, "0"); return talloc_asprintf(mem_ctx, "0x%x", *(int *)data.data); case REG_MULTI_SZ: /* FIXME */ break; default: break; } return ret; }
static WERROR dsdb_syntax_DN_BINARY_drsuapi_to_ldb(struct ldb_context *ldb, const struct dsdb_schema *schema, const struct dsdb_attribute *attr, const struct drsuapi_DsReplicaAttribute *in, TALLOC_CTX *mem_ctx, struct ldb_message_element *out) { uint32_t i; out->flags = 0; out->name = talloc_strdup(mem_ctx, attr->lDAPDisplayName); W_ERROR_HAVE_NO_MEMORY(out->name); out->num_values = in->value_ctr.num_values; out->values = talloc_array(mem_ctx, struct ldb_val, out->num_values); W_ERROR_HAVE_NO_MEMORY(out->values); for (i=0; i < out->num_values; i++) { struct drsuapi_DsReplicaObjectIdentifier3Binary id3b; char *binary; char *str; enum ndr_err_code ndr_err; if (in->value_ctr.values[i].blob == NULL) { return WERR_FOOBAR; } if (in->value_ctr.values[i].blob->length == 0) { return WERR_FOOBAR; } ndr_err = ndr_pull_struct_blob_all(in->value_ctr.values[i].blob, out->values, schema->iconv_convenience, &id3b, (ndr_pull_flags_fn_t)ndr_pull_drsuapi_DsReplicaObjectIdentifier3Binary); if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { NTSTATUS status = ndr_map_error2ntstatus(ndr_err); return ntstatus_to_werror(status); } /* TODO: handle id3.guid and id3.sid */ binary = data_blob_hex_string(out->values, &id3b.binary); W_ERROR_HAVE_NO_MEMORY(binary); str = talloc_asprintf(out->values, "B:%u:%s:%s", (unsigned int)(id3b.binary.length * 2), /* because of 2 hex chars per byte */ binary, id3b.dn); W_ERROR_HAVE_NO_MEMORY(str); /* TODO: handle id3.guid and id3.sid */ out->values[i] = data_blob_string_const(str); } return WERR_OK; }
const char *epm_floor_string(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor) { struct dcerpc_syntax_id syntax; NTSTATUS status; switch(epm_floor->lhs.protocol) { case EPM_PROTOCOL_UUID: status = dcerpc_floor_get_lhs_data(epm_floor, &syntax); if (NT_STATUS_IS_OK(status)) { /* lhs is used: UUID */ char *uuidstr; if (GUID_equal(&syntax.uuid, &ndr_transfer_syntax.uuid)) { return "NDR"; } if (GUID_equal(&syntax.uuid, &ndr64_transfer_syntax.uuid)) { return "NDR64"; } uuidstr = GUID_string(mem_ctx, &syntax.uuid); return talloc_asprintf(mem_ctx, " uuid %s/0x%02x", uuidstr, syntax.if_version); } else { /* IPX */ return talloc_asprintf(mem_ctx, "IPX:%s", data_blob_hex_string(mem_ctx, &epm_floor->rhs.uuid.unknown)); } case EPM_PROTOCOL_NCACN: return "RPC-C"; case EPM_PROTOCOL_NCADG: return "RPC"; case EPM_PROTOCOL_NCALRPC: return "NCALRPC"; case EPM_PROTOCOL_DNET_NSP: return "DNET/NSP"; case EPM_PROTOCOL_IP: return talloc_asprintf(mem_ctx, "IP:%s", epm_floor->rhs.ip.ipaddr); case EPM_PROTOCOL_PIPE: return talloc_asprintf(mem_ctx, "PIPE:%s", epm_floor->rhs.pipe.path); case EPM_PROTOCOL_SMB: return talloc_asprintf(mem_ctx, "SMB:%s", epm_floor->rhs.smb.unc); case EPM_PROTOCOL_UNIX_DS: return talloc_asprintf(mem_ctx, "Unix:%s", epm_floor->rhs.unix_ds.path); case EPM_PROTOCOL_NETBIOS: return talloc_asprintf(mem_ctx, "NetBIOS:%s", epm_floor->rhs.netbios.name); case EPM_PROTOCOL_NETBEUI: return "NETBeui"; case EPM_PROTOCOL_SPX: return "SPX"; case EPM_PROTOCOL_NB_IPX: return "NB_IPX"; case EPM_PROTOCOL_HTTP: return talloc_asprintf(mem_ctx, "HTTP:%d", epm_floor->rhs.http.port); case EPM_PROTOCOL_TCP: return talloc_asprintf(mem_ctx, "TCP:%d", epm_floor->rhs.tcp.port); case EPM_PROTOCOL_UDP: return talloc_asprintf(mem_ctx, "UDP:%d", epm_floor->rhs.udp.port); default: return talloc_asprintf(mem_ctx, "UNK(%02x):", epm_floor->lhs.protocol); } }
static bool test_hex_string(struct torture_context *tctx) { DATA_BLOB a = data_blob_string_const("\xC\xA\xF\xE"); torture_assert_str_equal(tctx, data_blob_hex_string(tctx, &a), "0C0A0F0E", "hex string"); return true; }