1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-24 13:57:43 +03:00

r3972: use GUID_* naming context and move GUID_* functions to one place

metze
(This used to be commit 523e6acf4fec5d4946fa7c0c89f40d7d712c9f3a)
This commit is contained in:
Stefan Metzmacher 2004-11-25 20:03:46 +00:00 committed by Gerald (Jerry) Carter
parent 3308087bae
commit e900618654
13 changed files with 158 additions and 161 deletions

View File

@ -51,7 +51,6 @@ ADD_OBJ_FILES = \
lib/wins_srv.o \
lib/util_str.o \
lib/util_strlist.o \
lib/util_uuid.o \
lib/util_unistr.o \
lib/util_file.o \
lib/data_blob.o \

View File

@ -162,7 +162,7 @@ static WERROR dcom_create_object_remote(struct dcom_context *ctx, struct GUID *c
ZERO_STRUCT(r.in);
r.in.this.version.MajorVersion = COM_MAJOR_VERSION;
r.in.this.version.MinorVersion = COM_MINOR_VERSION;
uuid_generate_random(&r.in.this.cid);
r.in.this.cid = GUID_random();
r.in.Clsid = *clsid;
r.in.ClientImpLevel = RPC_C_IMP_LEVEL_IDENTIFY;
r.in.num_protseqs = ARRAY_SIZE(protseq);
@ -279,7 +279,7 @@ WERROR dcom_get_class_object_remote(struct dcom_context *ctx, struct GUID *clsid
ZERO_STRUCT(r.in);
r.in.this.version.MajorVersion = COM_MAJOR_VERSION;
r.in.this.version.MinorVersion = COM_MINOR_VERSION;
uuid_generate_random(&r.in.this.cid);
r.in.this.cid = GUID_random();
r.in.Clsid = *clsid;
r.in.ClientImpLevel = RPC_C_IMP_LEVEL_IDENTIFY;
r.in.num_protseqs = ARRAY_SIZE(protseq);
@ -355,7 +355,7 @@ NTSTATUS dcom_get_pipe (struct dcom_interface_p *iface, struct dcerpc_pipe **p)
iid = iface->interface->iid;
if (iface->ox->pipe) {
if (!uuid_equal(&iface->ox->pipe->syntax.uuid, &iid)) {
if (!GUID_equal(&iface->ox->pipe->syntax.uuid, &iid)) {
iface->ox->pipe->syntax.uuid = iid;
status = dcerpc_alter(iface->ox->pipe, iface->ctx);
if (NT_STATUS_IS_ERR(status)) {
@ -538,7 +538,7 @@ struct dcom_interface_p *dcom_new_local_ifacep(struct dcom_context *ctx, const s
ip->ctx = ctx;
ip->interface = iface;
ip->vtable = vtable;
uuid_generate_random(&ip->ipid);
ip->ipid = GUID_random();
ip->object = object;
ip->objref_flags = 0;
ip->orpc_flags = 0;

View File

@ -37,7 +37,7 @@ const struct dcom_interface *dcom_interface_by_iid(const struct GUID *iid)
while(l) {
if (uuid_equal(iid, &l->interface.iid))
if (GUID_equal(iid, &l->interface.iid))
return &l->interface;
l = l->next;
@ -52,7 +52,7 @@ const struct dcom_class *dcom_class_by_clsid(const struct GUID *clsid)
while(c) {
if (uuid_equal(clsid, &c->class.clsid)) {
if (GUID_equal(clsid, &c->class.clsid)) {
return &c->class;
}

View File

@ -1,62 +0,0 @@
/*
* Unix SMB/CIFS implementation.
* UUID server routines
* Copyright (C) Theodore Ts'o 1996, 1997,
* Copyright (C) Jim McDonough 2002.
* Copyright (C) Andrew Tridgell 2003.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
void uuid_generate_random(struct GUID *out)
{
generate_random_buffer((unsigned char *)out, sizeof(struct GUID));
out->clock_seq[0] = (out->clock_seq[0] & 0x3F) | 0x80;
out->time_hi_and_version = (out->time_hi_and_version & 0x0FFF) | 0x4000;
}
BOOL uuid_all_zero(const struct GUID *u)
{
if (u->time_low != 0 ||
u->time_mid != 0 ||
u->time_hi_and_version != 0 ||
u->clock_seq[0] != 0 ||
u->clock_seq[1] != 0 ||
!all_zero(u->node, 6)) {
return False;
}
return True;
}
BOOL uuid_equal(const struct GUID *u1, const struct GUID *u2)
{
if (u1->time_low != u2->time_low ||
u1->time_mid != u2->time_mid ||
u1->time_hi_and_version != u2->time_hi_and_version ||
u1->clock_seq[0] != u2->clock_seq[0] ||
u1->clock_seq[1] != u2->clock_seq[1] ||
memcmp(u1->node, u2->node, 6) != 0) {
return False;
}
return True;
}
BOOL policy_handle_empty(struct policy_handle *h)
{
return (h->handle_type == 0 && uuid_all_zero(&h->uuid));
}

View File

@ -4,7 +4,8 @@
INIT_OBJ_FILES = \
librpc/ndr/ndr.o
ADD_OBJ_FILES = \
librpc/ndr/ndr_basic.o
librpc/ndr/ndr_basic.o \
librpc/ndr/ndr_misc.o
REQUIRED_SUBSYSTEMS = LIBCLI_UTILS
# End SUBSYSTEM LIBNDR_RAW
################################################

View File

@ -1183,90 +1183,6 @@ void ndr_print_array_uint8(struct ndr_print *ndr, const char *name,
ndr->depth--;
}
/*
build a GUID from a string
*/
NTSTATUS GUID_from_string(const char *s, struct GUID *guid)
{
NTSTATUS status = NT_STATUS_INVALID_PARAMETER;
uint32_t time_low;
uint32_t time_mid, time_hi_and_version;
uint32_t clock_seq[2];
uint32_t node[6];
int i;
if (11 == sscanf(s, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
&time_low, &time_mid, &time_hi_and_version,
&clock_seq[0], &clock_seq[1],
&node[0], &node[1], &node[2], &node[3], &node[4], &node[5])) {
status = NT_STATUS_OK;
} else if (11 == sscanf(s, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
&time_low, &time_mid, &time_hi_and_version,
&clock_seq[0], &clock_seq[1],
&node[0], &node[1], &node[2], &node[3], &node[4], &node[5])) {
status = NT_STATUS_OK;
}
if (!NT_STATUS_IS_OK(status)) {
return status;
}
guid->time_low = time_low;
guid->time_mid = time_mid;
guid->time_hi_and_version = time_hi_and_version;
guid->clock_seq[0] = clock_seq[0];
guid->clock_seq[1] = clock_seq[1];
for (i=0;i<6;i++) {
guid->node[i] = node[i];
}
return NT_STATUS_OK;
}
/* generate a random GUID */
struct GUID GUID_random(void)
{
struct GUID guid;
generate_random_buffer((uint8_t *)&guid, sizeof(guid));
return guid;
}
/*
its useful to be able to display these in debugging messages
*/
char *GUID_string(TALLOC_CTX *mem_ctx, const struct GUID *guid)
{
return talloc_asprintf(mem_ctx,
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
guid->time_low, guid->time_mid,
guid->time_hi_and_version,
guid->clock_seq[0],
guid->clock_seq[1],
guid->node[0], guid->node[1],
guid->node[2], guid->node[3],
guid->node[4], guid->node[5]);
}
char *GUID_string2(TALLOC_CTX *mem_ctx, const struct GUID *guid)
{
return talloc_asprintf(mem_ctx,
"{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
guid->time_low, guid->time_mid,
guid->time_hi_and_version,
guid->clock_seq[0],
guid->clock_seq[1],
guid->node[0], guid->node[1],
guid->node[2], guid->node[3],
guid->node[4], guid->node[5]);
}
void ndr_print_GUID(struct ndr_print *ndr, const char *name, const struct GUID *guid)
{
ndr->print(ndr, "%-25s: %s", name, GUID_string(ndr, guid));
}
void ndr_print_DATA_BLOB(struct ndr_print *ndr, const char *name, DATA_BLOB r)
{
ndr->print(ndr, "%-25s: DATA_BLOB length=%u", name, r.length);

View File

@ -0,0 +1,143 @@
/*
Unix SMB/CIFS implementation.
UUID/GUID/policy_handle functions
Copyright (C) Theodore Ts'o 1996, 1997,
Copyright (C) Jim McDonough 2002.
Copyright (C) Andrew Tridgell 2003.
Copyright (C) Stefan (metze) Metzmacher 2004.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
/*
build a GUID from a string
*/
NTSTATUS GUID_from_string(const char *s, struct GUID *guid)
{
NTSTATUS status = NT_STATUS_INVALID_PARAMETER;
uint32_t time_low;
uint32_t time_mid, time_hi_and_version;
uint32_t clock_seq[2];
uint32_t node[6];
int i;
if (11 == sscanf(s, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
&time_low, &time_mid, &time_hi_and_version,
&clock_seq[0], &clock_seq[1],
&node[0], &node[1], &node[2], &node[3], &node[4], &node[5])) {
status = NT_STATUS_OK;
} else if (11 == sscanf(s, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
&time_low, &time_mid, &time_hi_and_version,
&clock_seq[0], &clock_seq[1],
&node[0], &node[1], &node[2], &node[3], &node[4], &node[5])) {
status = NT_STATUS_OK;
}
if (!NT_STATUS_IS_OK(status)) {
return status;
}
guid->time_low = time_low;
guid->time_mid = time_mid;
guid->time_hi_and_version = time_hi_and_version;
guid->clock_seq[0] = clock_seq[0];
guid->clock_seq[1] = clock_seq[1];
for (i=0;i<6;i++) {
guid->node[i] = node[i];
}
return NT_STATUS_OK;
}
/* generate a random GUID */
struct GUID GUID_random(void)
{
struct GUID guid;
generate_random_buffer((uint8_t *)&guid, sizeof(guid));
guid.clock_seq[0] = (guid.clock_seq[0] & 0x3F) | 0x80;
guid.time_hi_and_version = (guid.time_hi_and_version & 0x0FFF) | 0x4000;
return guid;
}
BOOL GUID_all_zero(const struct GUID *u)
{
if (u->time_low != 0 ||
u->time_mid != 0 ||
u->time_hi_and_version != 0 ||
u->clock_seq[0] != 0 ||
u->clock_seq[1] != 0 ||
!all_zero(u->node, 6)) {
return False;
}
return True;
}
BOOL GUID_equal(const struct GUID *u1, const struct GUID *u2)
{
if (u1->time_low != u2->time_low ||
u1->time_mid != u2->time_mid ||
u1->time_hi_and_version != u2->time_hi_and_version ||
u1->clock_seq[0] != u2->clock_seq[0] ||
u1->clock_seq[1] != u2->clock_seq[1] ||
memcmp(u1->node, u2->node, 6) != 0) {
return False;
}
return True;
}
/*
its useful to be able to display these in debugging messages
*/
char *GUID_string(TALLOC_CTX *mem_ctx, const struct GUID *guid)
{
return talloc_asprintf(mem_ctx,
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
guid->time_low, guid->time_mid,
guid->time_hi_and_version,
guid->clock_seq[0],
guid->clock_seq[1],
guid->node[0], guid->node[1],
guid->node[2], guid->node[3],
guid->node[4], guid->node[5]);
}
char *GUID_string2(TALLOC_CTX *mem_ctx, const struct GUID *guid)
{
return talloc_asprintf(mem_ctx,
"{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
guid->time_low, guid->time_mid,
guid->time_hi_and_version,
guid->clock_seq[0],
guid->clock_seq[1],
guid->node[0], guid->node[1],
guid->node[2], guid->node[3],
guid->node[4], guid->node[5]);
}
void ndr_print_GUID(struct ndr_print *ndr, const char *name, const struct GUID *guid)
{
ndr->print(ndr, "%-25s: %s", name, GUID_string(ndr, guid));
}
BOOL policy_handle_empty(struct policy_handle *h)
{
return (h->handle_type == 0 && GUID_all_zero(&h->uuid));
}

View File

@ -202,7 +202,7 @@ const char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_bindi
return NULL;
}
if (!uuid_all_zero(&b->object)) {
if (!GUID_all_zero(&b->object)) {
s = talloc_asprintf(s, "%s@",
GUID_string(mem_ctx, &b->object));
}

View File

@ -227,7 +227,7 @@ static error_status_t epm_Map(struct dcesrv_call_state *dce_call, TALLOC_CTX *me
for (i=0;i<count;i++) {
struct epm_tower t;
if (!uuid_equal(&floors[0].lhs.info.uuid.uuid, &eps[i].ep_description.object) ||
if (!GUID_equal(&floors[0].lhs.info.uuid.uuid, &eps[i].ep_description.object) ||
floors[0].lhs.info.uuid.version != eps[i].ep_description.object_version) {
continue;
}

View File

@ -40,7 +40,7 @@ struct dcesrv_handle *dcesrv_handle_new(struct dcesrv_connection *dce_conn,
h->destroy = NULL;
h->wire_handle.handle_type = handle_type;
uuid_generate_random(&h->wire_handle.uuid);
h->wire_handle.uuid = GUID_random();
DLIST_ADD(dce_conn->handles, h);
@ -77,7 +77,7 @@ struct dcesrv_handle *dcesrv_handle_fetch(struct dcesrv_connection *dce_conn,
for (h=dce_conn->handles; h; h=h->next) {
if (h->wire_handle.handle_type == p->handle_type &&
uuid_equal(&p->uuid, &h->wire_handle.uuid)) {
GUID_equal(&p->uuid, &h->wire_handle.uuid)) {
if (handle_type != DCESRV_HANDLE_ANY &&
p->handle_type != handle_type) {
DEBUG(0,("client gave us the wrong handle type (%d should be %d)\n",

View File

@ -38,7 +38,7 @@ static int test_RemoteActivation(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, HYP
ZERO_STRUCT(r.in);
r.in.this.version.MajorVersion = 5;
r.in.this.version.MinorVersion = 1;
uuid_generate_random(&r.in.this.cid);
r.in.this.cid = GUID_random();
GUID_from_string(CLSID_SIMPLE, &r.in.Clsid);
r.in.ClientImpLevel = RPC_C_IMP_LEVEL_IDENTIFY;
r.in.num_protseqs = 3;

View File

@ -37,7 +37,7 @@ static int test_RemoteActivation(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
ZERO_STRUCT(r.in);
r.in.this.version.MajorVersion = 5;
r.in.this.version.MinorVersion = 1;
uuid_generate_random(&r.in.this.cid);
r.in.this.cid = GUID_random();
GUID_from_string(CLSID_SIMPLE, &r.in.Clsid);
r.in.ClientImpLevel = RPC_C_IMP_LEVEL_IDENTIFY;
r.in.num_protseqs = 3;

View File

@ -259,7 +259,7 @@ void torture_leave_domain(struct test_join *join)
struct samr_DeleteUser d;
NTSTATUS status;
if (!uuid_all_zero(&join->user_handle.uuid)) {
if (!GUID_all_zero(&join->user_handle.uuid)) {
d.in.user_handle = &join->user_handle;
d.out.user_handle = &join->user_handle;