From 2b7fe67f4d02f861c9a4bfe823e648f0a995e613 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 22 May 2005 10:23:01 +0000 Subject: r6933: Add a couple of helper functions for creating nbt names. (This used to be commit b896daf11c3efb1b3ca939575da9dab82b395777) --- source4/client/client.c | 4 +--- source4/libcli/composite/connect.c | 8 ++------ source4/libcli/dgram/netlogon.c | 4 +--- source4/libcli/dgram/ntlogon.c | 4 +--- source4/libcli/resolve/resolve.c | 23 +++++++++++++++++++++++ source4/libcli/wins/winsrepl.c | 4 +--- source4/libnet/libnet_rpc.c | 4 +--- source4/torture/ldap/cldapbench.c | 4 +--- source4/torture/nbt/dgram.c | 13 +++---------- source4/torture/nbt/query.c | 4 +--- source4/torture/nbt/register.c | 4 +--- source4/torture/nbt/wins.c | 4 +--- source4/torture/nbt/winsbench.c | 4 +--- source4/torture/nbt/winsreplication.c | 4 +--- source4/torture/rpc/xplogin.c | 4 +--- source4/torture/torture.c | 4 +--- 16 files changed, 41 insertions(+), 55 deletions(-) (limited to 'source4') diff --git a/source4/client/client.c b/source4/client/client.c index 5981812eb7..34d0fc20f1 100644 --- a/source4/client/client.c +++ b/source4/client/client.c @@ -3274,9 +3274,7 @@ static int do_message_op(void) struct nbt_name called, calling; const char *server_name; - calling.name = lp_netbios_name(); - calling.type = NBT_NAME_CLIENT; - calling.scope = NULL; + make_nbt_name_client(&calling, lp_netbios_name()); nbt_choose_called_name(NULL, &called, desthost, name_type); diff --git a/source4/libcli/composite/connect.c b/source4/libcli/composite/connect.c index 0da71df992..526eee8cb8 100644 --- a/source4/libcli/composite/connect.c +++ b/source4/libcli/composite/connect.c @@ -213,9 +213,7 @@ static NTSTATUS connect_socket(struct composite_context *c, state->transport = smbcli_transport_init(state->sock, state, True); NT_STATUS_HAVE_NO_MEMORY(state->transport); - calling.name = cli_credentials_get_workstation(io->in.credentials); - calling.type = NBT_NAME_CLIENT; - calling.scope = NULL; + make_nbt_name_client(&calling, cli_credentials_get_workstation(io->in.credentials)); nbt_choose_called_name(state, &called, io->in.called_name, NBT_NAME_SERVER); @@ -349,9 +347,7 @@ struct composite_context *smb_composite_connect_send(struct smb_composite_connec c->event_ctx = talloc_reference(c, state->sock->event.ctx); c->private = state; - name.name = io->in.dest_host; - name.type = NBT_NAME_SERVER; - name.scope = NULL; + make_nbt_name_server(&name, io->in.dest_host); state->creq = resolve_name_send(&name, c->event_ctx); if (state->creq == NULL) goto failed; diff --git a/source4/libcli/dgram/netlogon.c b/source4/libcli/dgram/netlogon.c index 6e939725d0..9d3a0dbed9 100644 --- a/source4/libcli/dgram/netlogon.c +++ b/source4/libcli/dgram/netlogon.c @@ -79,9 +79,7 @@ NTSTATUS dgram_mailslot_netlogon_reply(struct nbt_dgram_socket *dgmsock, return status; } - myname.name = lp_netbios_name(); - myname.type = NBT_NAME_CLIENT; - myname.scope = NULL; + make_nbt_name_client(&myname, lp_netbios_name()); status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE, mailslot_name, diff --git a/source4/libcli/dgram/ntlogon.c b/source4/libcli/dgram/ntlogon.c index 38651a4085..e4a24b0591 100644 --- a/source4/libcli/dgram/ntlogon.c +++ b/source4/libcli/dgram/ntlogon.c @@ -79,9 +79,7 @@ NTSTATUS dgram_mailslot_ntlogon_reply(struct nbt_dgram_socket *dgmsock, return status; } - myname.name = lp_netbios_name(); - myname.type = NBT_NAME_CLIENT; - myname.scope = NULL; + make_nbt_name_client(&myname, lp_netbios_name()); status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE, mailslot_name, diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index 82268dc953..a3bbd60920 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -181,3 +181,26 @@ NTSTATUS resolve_name(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **r struct composite_context *c = resolve_name_send(name, NULL); return resolve_name_recv(c, mem_ctx, reply_addr); } + +/* Initialise a struct nbt_name with a NULL scope */ + +void make_nbt_name(struct nbt_name *nbt, const char *name, int type) +{ + nbt->name = name; + nbt->scope = NULL; + nbt->type = type; +} + +/* Initialise a struct nbt_name with a NBT_NAME_CLIENT (0x00) name */ + +void make_nbt_name_client(struct nbt_name *nbt, const char *name) +{ + make_nbt_name(nbt, name, NBT_NAME_CLIENT); +} + +/* Initialise a struct nbt_name with a NBT_NAME_SERVER (0x20) name */ + +void make_nbt_name_server(struct nbt_name *nbt, const char *name) +{ + make_nbt_name(nbt, name, NBT_NAME_SERVER); +} diff --git a/source4/libcli/wins/winsrepl.c b/source4/libcli/wins/winsrepl.c index 7a3ce72b91..65b713202f 100644 --- a/source4/libcli/wins/winsrepl.c +++ b/source4/libcli/wins/winsrepl.c @@ -602,9 +602,7 @@ static NTSTATUS wrepl_extract_name(struct nbt_name *name, } if (len < 17) { - name->name = talloc_strndup(mem_ctx, namebuf, len); - name->type = NBT_NAME_CLIENT; - name->scope = NULL; + make_nbt_name_client(name, talloc_strndup(mem_ctx, namebuf, len)); return NT_STATUS_OK; } diff --git a/source4/libnet/libnet_rpc.c b/source4/libnet/libnet_rpc.c index 1f1812e261..82dc06a0f6 100644 --- a/source4/libnet/libnet_rpc.c +++ b/source4/libnet/libnet_rpc.c @@ -43,9 +43,7 @@ static NTSTATUS libnet_find_pdc_generic(struct libnet_context *ctx, TALLOC_CTX * return NT_STATUS_OK; } - name.name = r->generic.in.domain_name; - name.type = NBT_NAME_PDC; - name.scope = NULL; + make_nbt_name(&name, r->generic.in.domain_name, NBT_NAME_PDC); status = resolve_name(&name, mem_ctx, &address); if (!NT_STATUS_IS_OK(status)) { diff --git a/source4/torture/ldap/cldapbench.c b/source4/torture/ldap/cldapbench.c index 8eaddc78f9..0a021dacce 100644 --- a/source4/torture/ldap/cldapbench.c +++ b/source4/torture/ldap/cldapbench.c @@ -108,9 +108,7 @@ BOOL torture_bench_cldap(void) NTSTATUS status; BOOL ret = True; - name.name = lp_parm_string(-1, "torture", "host"); - name.type = NBT_NAME_SERVER; - name.scope = NULL; + make_nbt_name_server(&name, lp_parm_string(-1, "torture", "host")); /* do an initial name resolution to find its IP */ status = resolve_name(&name, mem_ctx, &address); diff --git a/source4/torture/nbt/dgram.c b/source4/torture/nbt/dgram.c index 5726e68471..d5fa014ce1 100644 --- a/source4/torture/nbt/dgram.c +++ b/source4/torture/nbt/dgram.c @@ -92,9 +92,7 @@ static BOOL nbt_test_netlogon(TALLOC_CTX *mem_ctx, logon.req.pdc.lmnt_token = 0xFFFF; logon.req.pdc.lm20_token = 0xFFFF; - myname.name = TEST_NAME; - myname.type = NBT_NAME_CLIENT; - myname.scope = NULL; + make_nbt_name_client(&myname, TEST_NAME); status = dgram_mailslot_netlogon_send(dgmsock, &name, address, 0, &myname, &logon); @@ -154,9 +152,7 @@ static BOOL nbt_test_netlogon2(TALLOC_CTX *mem_ctx, logon.req.pdc2.lmnt_token = 0xFFFF; logon.req.pdc2.lm20_token = 0xFFFF; - myname.name = TEST_NAME; - myname.type = NBT_NAME_CLIENT; - myname.scope = NULL; + make_nbt_name_client(&myname, TEST_NAME); status = dgram_mailslot_netlogon_send(dgmsock, &name, address, 0, &myname, &logon); @@ -257,10 +253,7 @@ static BOOL nbt_test_ntlogon(TALLOC_CTX *mem_ctx, logon.req.logon.lmnt_token = 0xFFFF; logon.req.logon.lm20_token = 0xFFFF; - - myname.name = TEST_NAME; - myname.type = NBT_NAME_CLIENT; - myname.scope = NULL; + make_nbt_name_client(&myname, TEST_NAME); status = dgram_mailslot_ntlogon_send(dgmsock, &name, address, 0, &myname, &logon); diff --git a/source4/torture/nbt/query.c b/source4/torture/nbt/query.c index a9141f4431..3764596f3f 100644 --- a/source4/torture/nbt/query.c +++ b/source4/torture/nbt/query.c @@ -110,9 +110,7 @@ BOOL torture_bench_nbt(void) NTSTATUS status; BOOL ret = True; - name.name = lp_parm_string(-1, "torture", "host"); - name.type = NBT_NAME_SERVER; - name.scope = NULL; + make_nbt_name_server(&name, lp_parm_string(-1, "torture", "host")); /* do an initial name resolution to find its IP */ status = resolve_name(&name, mem_ctx, &address); diff --git a/source4/torture/nbt/register.c b/source4/torture/nbt/register.c index e9b98663a5..463783e1c9 100644 --- a/source4/torture/nbt/register.c +++ b/source4/torture/nbt/register.c @@ -160,9 +160,7 @@ BOOL torture_nbt_register(void) NTSTATUS status; BOOL ret = True; - name.name = strupper_talloc(mem_ctx, lp_parm_string(-1, "torture", "host")); - name.type = NBT_NAME_SERVER; - name.scope = NULL; + make_nbt_name_server(&name, strupper_talloc(mem_ctx, lp_parm_string(-1, "torture", "host"))); /* do an initial name resolution to find its IP */ status = resolve_name(&name, mem_ctx, &address); diff --git a/source4/torture/nbt/wins.c b/source4/torture/nbt/wins.c index f92a23f732..b099f48476 100644 --- a/source4/torture/nbt/wins.c +++ b/source4/torture/nbt/wins.c @@ -345,9 +345,7 @@ BOOL torture_nbt_wins(void) NTSTATUS status; BOOL ret = True; - name.name = lp_parm_string(-1, "torture", "host"); - name.type = NBT_NAME_SERVER; - name.scope = NULL; + make_nbt_name_server(&name, lp_parm_string(-1, "torture", "host")); /* do an initial name resolution to find its IP */ status = resolve_name(&name, mem_ctx, &address); diff --git a/source4/torture/nbt/winsbench.c b/source4/torture/nbt/winsbench.c index 54f730ce84..76763d3bf0 100644 --- a/source4/torture/nbt/winsbench.c +++ b/source4/torture/nbt/winsbench.c @@ -276,9 +276,7 @@ BOOL torture_bench_wins(void) NTSTATUS status; BOOL ret = True; - name.name = lp_parm_string(-1, "torture", "host"); - name.type = NBT_NAME_SERVER; - name.scope = NULL; + make_nbt_name_server(&name, lp_parm_string(-1, "torture", "host")); /* do an initial name resolution to find its IP */ status = resolve_name(&name, mem_ctx, &address); diff --git a/source4/torture/nbt/winsreplication.c b/source4/torture/nbt/winsreplication.c index 5ba6003b78..4e91deb84a 100644 --- a/source4/torture/nbt/winsreplication.c +++ b/source4/torture/nbt/winsreplication.c @@ -124,9 +124,7 @@ BOOL torture_nbt_winsreplication(void) NTSTATUS status; BOOL ret = True; - name.name = lp_parm_string(-1, "torture", "host"); - name.type = NBT_NAME_SERVER; - name.scope = NULL; + make_nbt_name_server(&name, lp_parm_string(-1, "torture", "host")); /* do an initial name resolution to find its IP */ status = resolve_name(&name, mem_ctx, &address); diff --git a/source4/torture/rpc/xplogin.c b/source4/torture/rpc/xplogin.c index d54dfdf310..235ac02e38 100644 --- a/source4/torture/rpc/xplogin.c +++ b/source4/torture/rpc/xplogin.c @@ -56,9 +56,7 @@ static NTSTATUS after_negprot(struct smbcli_transport **dst_transport, struct nbt_name called; /* send a NBT session request, if applicable */ - calling.name = my_name; - calling.type = NBT_NAME_CLIENT; - calling.scope = NULL; + make_nbt_name_client(&calling, my_name); nbt_choose_called_name(transport, &called, dest_host, NBT_NAME_SERVER); diff --git a/source4/torture/torture.c b/source4/torture/torture.c index f5e52c5358..b7e2168319 100644 --- a/source4/torture/torture.c +++ b/source4/torture/torture.c @@ -49,9 +49,7 @@ static struct smbcli_state *open_nbt_connection(void) struct smbcli_state *cli; const char *host = lp_parm_string(-1, "torture", "host"); - calling.name = lp_netbios_name(); - calling.type = NBT_NAME_CLIENT; - calling.scope = NULL; + make_nbt_name_client(&calling, lp_netbios_name()); nbt_choose_called_name(NULL, &called, host, NBT_NAME_SERVER); -- cgit