From 6f33f3e4c26564602d5d13c7459938955b56a16e Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=BCnther=20Deschner?= Date: Tue, 23 Sep 2008 06:58:17 +0200 Subject: [PATCH] s4-nbt: move libcli/nbt up one level. Guenther --- {source4/libcli => libcli}/nbt/libnbt.h | 36 +++++++------- {source4/libcli => libcli}/nbt/namequery.c | 36 +++++++------- {source4/libcli => libcli}/nbt/namerefresh.c | 36 +++++++------- {source4/libcli => libcli}/nbt/nameregister.c | 38 +++++++-------- {source4/libcli => libcli}/nbt/namerelease.c | 26 +++++----- {source4/libcli => libcli}/nbt/nbtname.c | 0 {source4/libcli => libcli}/nbt/nbtsocket.c | 70 +++++++++++++-------------- {source4/libcli => libcli}/nbt/pynbt.c | 56 ++++++++++----------- 8 files changed, 149 insertions(+), 149 deletions(-) rename {source4/libcli => libcli}/nbt/libnbt.h (92%) rename {source4/libcli => libcli}/nbt/namequery.c (96%) rename {source4/libcli => libcli}/nbt/namerefresh.c (95%) rename {source4/libcli => libcli}/nbt/nameregister.c (97%) rename {source4/libcli => libcli}/nbt/namerelease.c (94%) rename {source4/libcli => libcli}/nbt/nbtname.c (100%) rename {source4/libcli => libcli}/nbt/nbtsocket.c (91%) rename {source4/libcli => libcli}/nbt/pynbt.c (94%) diff --git a/source4/libcli/nbt/libnbt.h b/libcli/nbt/libnbt.h similarity index 92% rename from source4/libcli/nbt/libnbt.h rename to libcli/nbt/libnbt.h index 8529ec362b4..4ef4e9d60d1 100644 --- a/source4/libcli/nbt/libnbt.h +++ b/libcli/nbt/libnbt.h @@ -28,8 +28,8 @@ /* possible states for pending requests */ -enum nbt_request_state {NBT_REQUEST_SEND, - NBT_REQUEST_WAIT, +enum nbt_request_state {NBT_REQUEST_SEND, + NBT_REQUEST_WAIT, NBT_REQUEST_DONE, NBT_REQUEST_TIMEOUT, NBT_REQUEST_ERROR}; @@ -67,7 +67,7 @@ struct nbt_name_request { /* is it a reply? */ bool is_reply; - + /* the encoded request */ DATA_BLOB encoded; @@ -111,14 +111,14 @@ struct nbt_name_socket { /* what to do with incoming request packets */ struct { - void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *, + void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *, struct socket_address *); void *private_data; } incoming; /* what to do with unexpected replies */ struct { - void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *, + void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *, struct socket_address *); void *private_data; } unexpected; @@ -274,20 +274,20 @@ struct nbt_name_release { } out; }; -struct nbt_name_socket *nbt_name_socket_init(TALLOC_CTX *mem_ctx, +struct nbt_name_socket *nbt_name_socket_init(TALLOC_CTX *mem_ctx, struct event_context *event_ctx, struct smb_iconv_convenience *iconv_convenience); struct nbt_name_request *nbt_name_query_send(struct nbt_name_socket *nbtsock, struct nbt_name_query *io); -NTSTATUS nbt_name_query_recv(struct nbt_name_request *req, +NTSTATUS nbt_name_query_recv(struct nbt_name_request *req, TALLOC_CTX *mem_ctx, struct nbt_name_query *io); -NTSTATUS nbt_name_query(struct nbt_name_socket *nbtsock, +NTSTATUS nbt_name_query(struct nbt_name_socket *nbtsock, TALLOC_CTX *mem_ctx, struct nbt_name_query *io); struct nbt_name_request *nbt_name_status_send(struct nbt_name_socket *nbtsock, struct nbt_name_status *io); -NTSTATUS nbt_name_status_recv(struct nbt_name_request *req, +NTSTATUS nbt_name_status_recv(struct nbt_name_request *req, TALLOC_CTX *mem_ctx, struct nbt_name_status *io); -NTSTATUS nbt_name_status(struct nbt_name_socket *nbtsock, +NTSTATUS nbt_name_status(struct nbt_name_socket *nbtsock, TALLOC_CTX *mem_ctx, struct nbt_name_status *io); NTSTATUS nbt_name_dup(TALLOC_CTX *mem_ctx, struct nbt_name *name, struct nbt_name *newname); @@ -295,11 +295,11 @@ NTSTATUS nbt_name_to_blob(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *ico NTSTATUS nbt_name_from_blob(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, struct nbt_name *name); void nbt_choose_called_name(TALLOC_CTX *mem_ctx, struct nbt_name *n, const char *name, int type); char *nbt_name_string(TALLOC_CTX *mem_ctx, const struct nbt_name *name); -NTSTATUS nbt_name_register(struct nbt_name_socket *nbtsock, +NTSTATUS nbt_name_register(struct nbt_name_socket *nbtsock, TALLOC_CTX *mem_ctx, struct nbt_name_register *io); -NTSTATUS nbt_name_refresh(struct nbt_name_socket *nbtsock, +NTSTATUS nbt_name_refresh(struct nbt_name_socket *nbtsock, TALLOC_CTX *mem_ctx, struct nbt_name_refresh *io); -NTSTATUS nbt_name_release(struct nbt_name_socket *nbtsock, +NTSTATUS nbt_name_release(struct nbt_name_socket *nbtsock, TALLOC_CTX *mem_ctx, struct nbt_name_release *io); NTSTATUS nbt_name_register_wins(struct nbt_name_socket *nbtsock, TALLOC_CTX *mem_ctx, @@ -307,24 +307,24 @@ NTSTATUS nbt_name_register_wins(struct nbt_name_socket *nbtsock, NTSTATUS nbt_name_refresh_wins(struct nbt_name_socket *nbtsock, TALLOC_CTX *mem_ctx, struct nbt_name_refresh_wins *io); -NTSTATUS nbt_name_register_recv(struct nbt_name_request *req, +NTSTATUS nbt_name_register_recv(struct nbt_name_request *req, TALLOC_CTX *mem_ctx, struct nbt_name_register *io); struct nbt_name_request *nbt_name_register_send(struct nbt_name_socket *nbtsock, struct nbt_name_register *io); -NTSTATUS nbt_name_release_recv(struct nbt_name_request *req, +NTSTATUS nbt_name_release_recv(struct nbt_name_request *req, TALLOC_CTX *mem_ctx, struct nbt_name_release *io); struct nbt_name_request *nbt_name_release_send(struct nbt_name_socket *nbtsock, struct nbt_name_release *io); -NTSTATUS nbt_name_refresh_recv(struct nbt_name_request *req, +NTSTATUS nbt_name_refresh_recv(struct nbt_name_request *req, TALLOC_CTX *mem_ctx, struct nbt_name_refresh *io); NTSTATUS nbt_set_incoming_handler(struct nbt_name_socket *nbtsock, - void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *, + void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *, struct socket_address *), void *private_data); -NTSTATUS nbt_name_reply_send(struct nbt_name_socket *nbtsock, +NTSTATUS nbt_name_reply_send(struct nbt_name_socket *nbtsock, struct socket_address *dest, struct nbt_name_packet *request); diff --git a/source4/libcli/nbt/namequery.c b/libcli/nbt/namequery.c similarity index 96% rename from source4/libcli/nbt/namequery.c rename to libcli/nbt/namequery.c index 2e1bcd818be..ed3d8a24925 100644 --- a/source4/libcli/nbt/namequery.c +++ b/libcli/nbt/namequery.c @@ -1,27 +1,27 @@ -/* +/* Unix SMB/CIFS implementation. make nbt name query requests Copyright (C) Andrew Tridgell 2005 - + 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 3 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, see . */ #include "includes.h" -#include "libcli/nbt/libnbt.h" -#include "libcli/nbt/nbt_proto.h" +#include "../libcli/nbt/libnbt.h" +#include "../libcli/nbt/nbt_proto.h" #include "lib/socket/socket.h" #include "param/param.h" @@ -66,13 +66,13 @@ _PUBLIC_ struct nbt_name_request *nbt_name_query_send(struct nbt_name_socket *nb failed: talloc_free(packet); - return NULL; + return NULL; } /** wait for a name query reply */ -_PUBLIC_ NTSTATUS nbt_name_query_recv(struct nbt_name_request *req, +_PUBLIC_ NTSTATUS nbt_name_query_recv(struct nbt_name_request *req, TALLOC_CTX *mem_ctx, struct nbt_name_query *io) { NTSTATUS status; @@ -85,7 +85,7 @@ _PUBLIC_ NTSTATUS nbt_name_query_recv(struct nbt_name_request *req, talloc_free(req); return status; } - + packet = req->replies[0].packet; io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].dest->addr); @@ -109,16 +109,16 @@ _PUBLIC_ NTSTATUS nbt_name_query_recv(struct nbt_name_request *req, talloc_free(req); return NT_STATUS_NO_MEMORY; } - + for (i=0;iout.num_addrs;i++) { - io->out.reply_addrs[i] = talloc_steal(io->out.reply_addrs, + io->out.reply_addrs[i] = talloc_steal(io->out.reply_addrs, packet->answers[0].rdata.netbios.addresses[i].ipaddr); } io->out.reply_addrs[i] = NULL; talloc_steal(mem_ctx, io->out.name.name); talloc_steal(mem_ctx, io->out.name.scope); - + talloc_free(req); return NT_STATUS_OK; @@ -127,7 +127,7 @@ _PUBLIC_ NTSTATUS nbt_name_query_recv(struct nbt_name_request *req, /** wait for a name query reply */ -_PUBLIC_ NTSTATUS nbt_name_query(struct nbt_name_socket *nbtsock, +_PUBLIC_ NTSTATUS nbt_name_query(struct nbt_name_socket *nbtsock, TALLOC_CTX *mem_ctx, struct nbt_name_query *io) { struct nbt_name_request *req = nbt_name_query_send(nbtsock, io); @@ -170,13 +170,13 @@ _PUBLIC_ struct nbt_name_request *nbt_name_status_send(struct nbt_name_socket *n failed: talloc_free(packet); - return NULL; + return NULL; } /** wait for a name status reply */ -_PUBLIC_ NTSTATUS nbt_name_status_recv(struct nbt_name_request *req, +_PUBLIC_ NTSTATUS nbt_name_status_recv(struct nbt_name_request *req, TALLOC_CTX *mem_ctx, struct nbt_name_status *io) { NTSTATUS status; @@ -189,7 +189,7 @@ _PUBLIC_ NTSTATUS nbt_name_status_recv(struct nbt_name_request *req, talloc_free(req); return status; } - + packet = req->replies[0].packet; io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].dest->addr); @@ -216,7 +216,7 @@ _PUBLIC_ NTSTATUS nbt_name_status_recv(struct nbt_name_request *req, talloc_steal(io->out.status.names, io->out.status.names[i].name); } - + talloc_free(req); return NT_STATUS_OK; @@ -225,7 +225,7 @@ _PUBLIC_ NTSTATUS nbt_name_status_recv(struct nbt_name_request *req, /** wait for a name status reply */ -_PUBLIC_ NTSTATUS nbt_name_status(struct nbt_name_socket *nbtsock, +_PUBLIC_ NTSTATUS nbt_name_status(struct nbt_name_socket *nbtsock, TALLOC_CTX *mem_ctx, struct nbt_name_status *io) { struct nbt_name_request *req = nbt_name_status_send(nbtsock, io); diff --git a/source4/libcli/nbt/namerefresh.c b/libcli/nbt/namerefresh.c similarity index 95% rename from source4/libcli/nbt/namerefresh.c rename to libcli/nbt/namerefresh.c index b939c977403..37bf0fc8f12 100644 --- a/source4/libcli/nbt/namerefresh.c +++ b/libcli/nbt/namerefresh.c @@ -1,27 +1,27 @@ -/* +/* Unix SMB/CIFS implementation. send out a name refresh request Copyright (C) Andrew Tridgell 2005 - + 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 3 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, see . */ #include "includes.h" -#include "libcli/nbt/libnbt.h" -#include "libcli/nbt/nbt_proto.h" +#include "../libcli/nbt/libnbt.h" +#include "../libcli/nbt/nbt_proto.h" #include "libcli/composite/composite.h" #include "lib/socket/socket.h" #include "param/param.h" @@ -65,11 +65,11 @@ struct nbt_name_request *nbt_name_refresh_send(struct nbt_name_socket *nbtsock, struct nbt_rdata_address, 1); if (packet->additional[0].rdata.netbios.addresses == NULL) goto failed; packet->additional[0].rdata.netbios.addresses[0].nb_flags = io->in.nb_flags; - packet->additional[0].rdata.netbios.addresses[0].ipaddr = + packet->additional[0].rdata.netbios.addresses[0].ipaddr = talloc_strdup(packet->additional, io->in.address); - dest = socket_address_from_strings(nbtsock, - nbtsock->sock->backend_name, + dest = socket_address_from_strings(nbtsock, + nbtsock->sock->backend_name, io->in.dest_addr, io->in.dest_port); if (dest == NULL) goto failed; req = nbt_name_request_send(nbtsock, dest, packet, @@ -81,13 +81,13 @@ struct nbt_name_request *nbt_name_refresh_send(struct nbt_name_socket *nbtsock, failed: talloc_free(packet); - return NULL; + return NULL; } /* wait for a refresh reply */ -_PUBLIC_ NTSTATUS nbt_name_refresh_recv(struct nbt_name_request *req, +_PUBLIC_ NTSTATUS nbt_name_refresh_recv(struct nbt_name_request *req, TALLOC_CTX *mem_ctx, struct nbt_name_refresh *io) { NTSTATUS status; @@ -99,7 +99,7 @@ _PUBLIC_ NTSTATUS nbt_name_refresh_recv(struct nbt_name_request *req, talloc_free(req); return status; } - + packet = req->replies[0].packet; io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].dest->addr); @@ -116,7 +116,7 @@ _PUBLIC_ NTSTATUS nbt_name_refresh_recv(struct nbt_name_request *req, talloc_free(req); return NT_STATUS_INVALID_NETWORK_RESPONSE; } - io->out.reply_addr = talloc_steal(mem_ctx, + io->out.reply_addr = talloc_steal(mem_ctx, packet->answers[0].rdata.netbios.addresses[0].ipaddr); talloc_steal(mem_ctx, io->out.name.name); talloc_steal(mem_ctx, io->out.name.scope); @@ -129,7 +129,7 @@ _PUBLIC_ NTSTATUS nbt_name_refresh_recv(struct nbt_name_request *req, /* synchronous name refresh request */ -_PUBLIC_ NTSTATUS nbt_name_refresh(struct nbt_name_socket *nbtsock, +_PUBLIC_ NTSTATUS nbt_name_refresh(struct nbt_name_socket *nbtsock, TALLOC_CTX *mem_ctx, struct nbt_name_refresh *io) { struct nbt_name_request *req = nbt_name_refresh_send(nbtsock, io); @@ -161,7 +161,7 @@ static void name_refresh_wins_handler(struct nbt_name_request *req) { struct composite_context *c = talloc_get_type(req->async.private_data, struct composite_context); - struct refresh_wins_state *state = talloc_get_type(c->private_data, + struct refresh_wins_state *state = talloc_get_type(c->private_data, struct refresh_wins_state); NTSTATUS status; @@ -235,11 +235,11 @@ _PUBLIC_ struct composite_context *nbt_name_refresh_wins_send(struct nbt_name_so state->wins_port = io->in.wins_port; state->wins_servers = str_list_copy(state, io->in.wins_servers); - if (state->wins_servers == NULL || + if (state->wins_servers == NULL || state->wins_servers[0] == NULL) goto failed; state->addresses = str_list_copy(state, io->in.addresses); - if (state->addresses == NULL || + if (state->addresses == NULL || state->addresses[0] == NULL) goto failed; state->io->in.name = io->in.name; @@ -281,7 +281,7 @@ _PUBLIC_ NTSTATUS nbt_name_refresh_wins_recv(struct composite_context *c, TALLOC NTSTATUS status; status = composite_wait(c); if (NT_STATUS_IS_OK(status)) { - struct refresh_wins_state *state = + struct refresh_wins_state *state = talloc_get_type(c->private_data, struct refresh_wins_state); io->out.wins_server = talloc_steal(mem_ctx, state->wins_servers[0]); io->out.rcode = state->io->out.rcode; diff --git a/source4/libcli/nbt/nameregister.c b/libcli/nbt/nameregister.c similarity index 97% rename from source4/libcli/nbt/nameregister.c rename to libcli/nbt/nameregister.c index c50f9b3b3aa..d4728a8e021 100644 --- a/source4/libcli/nbt/nameregister.c +++ b/libcli/nbt/nameregister.c @@ -1,27 +1,27 @@ -/* +/* Unix SMB/CIFS implementation. send out a name registration request Copyright (C) Andrew Tridgell 2005 - + 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 3 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, see . */ #include "includes.h" -#include "libcli/nbt/libnbt.h" -#include "libcli/nbt/nbt_proto.h" +#include "../libcli/nbt/libnbt.h" +#include "../libcli/nbt/nbt_proto.h" #include "libcli/composite/composite.h" #include "lib/socket/socket.h" #include "librpc/gen_ndr/ndr_nbt.h" @@ -73,11 +73,11 @@ struct nbt_name_request *nbt_name_register_send(struct nbt_name_socket *nbtsock, struct nbt_rdata_address, 1); if (packet->additional[0].rdata.netbios.addresses == NULL) goto failed; packet->additional[0].rdata.netbios.addresses[0].nb_flags = io->in.nb_flags; - packet->additional[0].rdata.netbios.addresses[0].ipaddr = + packet->additional[0].rdata.netbios.addresses[0].ipaddr = talloc_strdup(packet->additional, io->in.address); if (packet->additional[0].rdata.netbios.addresses[0].ipaddr == NULL) goto failed; - dest = socket_address_from_strings(packet, nbtsock->sock->backend_name, + dest = socket_address_from_strings(packet, nbtsock->sock->backend_name, io->in.dest_addr, io->in.dest_port); if (dest == NULL) goto failed; req = nbt_name_request_send(nbtsock, dest, packet, @@ -89,13 +89,13 @@ struct nbt_name_request *nbt_name_register_send(struct nbt_name_socket *nbtsock, failed: talloc_free(packet); - return NULL; + return NULL; } /* wait for a registration reply */ -_PUBLIC_ NTSTATUS nbt_name_register_recv(struct nbt_name_request *req, +_PUBLIC_ NTSTATUS nbt_name_register_recv(struct nbt_name_request *req, TALLOC_CTX *mem_ctx, struct nbt_name_register *io) { NTSTATUS status; @@ -107,7 +107,7 @@ _PUBLIC_ NTSTATUS nbt_name_register_recv(struct nbt_name_request *req, talloc_free(req); return status; } - + packet = req->replies[0].packet; io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].dest->addr); @@ -124,11 +124,11 @@ _PUBLIC_ NTSTATUS nbt_name_register_recv(struct nbt_name_request *req, talloc_free(req); return NT_STATUS_INVALID_NETWORK_RESPONSE; } - io->out.reply_addr = talloc_steal(mem_ctx, + io->out.reply_addr = talloc_steal(mem_ctx, packet->answers[0].rdata.netbios.addresses[0].ipaddr); talloc_steal(mem_ctx, io->out.name.name); talloc_steal(mem_ctx, io->out.name.scope); - + talloc_free(req); return NT_STATUS_OK; @@ -137,7 +137,7 @@ _PUBLIC_ NTSTATUS nbt_name_register_recv(struct nbt_name_request *req, /* synchronous name registration request */ -_PUBLIC_ NTSTATUS nbt_name_register(struct nbt_name_socket *nbtsock, +_PUBLIC_ NTSTATUS nbt_name_register(struct nbt_name_socket *nbtsock, TALLOC_CTX *mem_ctx, struct nbt_name_register *io) { struct nbt_name_request *req = nbt_name_register_send(nbtsock, io); @@ -192,7 +192,7 @@ static void name_register_bcast_handler(struct nbt_name_request *req) c->state = COMPOSITE_STATE_ERROR; c->status = NT_STATUS_CONFLICTING_ADDRESSES; DEBUG(3,("Name registration conflict from %s for %s with ip %s - rcode %d\n", - state->io->out.reply_from, + state->io->out.reply_from, nbt_name_string(state, &state->io->out.name), state->io->out.reply_addr, state->io->out.rcode)); @@ -299,7 +299,7 @@ static void name_register_wins_handler(struct nbt_name_request *req) { struct composite_context *c = talloc_get_type(req->async.private_data, struct composite_context); - struct register_wins_state *state = talloc_get_type(c->private_data, + struct register_wins_state *state = talloc_get_type(c->private_data, struct register_wins_state); NTSTATUS status; @@ -373,11 +373,11 @@ _PUBLIC_ struct composite_context *nbt_name_register_wins_send(struct nbt_name_s state->wins_port = io->in.wins_port; state->wins_servers = str_list_copy(state, io->in.wins_servers); - if (state->wins_servers == NULL || + if (state->wins_servers == NULL || state->wins_servers[0] == NULL) goto failed; state->addresses = str_list_copy(state, io->in.addresses); - if (state->addresses == NULL || + if (state->addresses == NULL || state->addresses[0] == NULL) goto failed; state->io->in.name = io->in.name; @@ -421,7 +421,7 @@ _PUBLIC_ NTSTATUS nbt_name_register_wins_recv(struct composite_context *c, TALLO NTSTATUS status; status = composite_wait(c); if (NT_STATUS_IS_OK(status)) { - struct register_wins_state *state = + struct register_wins_state *state = talloc_get_type(c->private_data, struct register_wins_state); io->out.wins_server = talloc_steal(mem_ctx, state->wins_servers[0]); io->out.rcode = state->io->out.rcode; diff --git a/source4/libcli/nbt/namerelease.c b/libcli/nbt/namerelease.c similarity index 94% rename from source4/libcli/nbt/namerelease.c rename to libcli/nbt/namerelease.c index ba3af417529..e57a2f396e8 100644 --- a/source4/libcli/nbt/namerelease.c +++ b/libcli/nbt/namerelease.c @@ -1,27 +1,27 @@ -/* +/* Unix SMB/CIFS implementation. send out a name release request Copyright (C) Andrew Tridgell 2005 - + 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 3 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, see . */ #include "includes.h" -#include "libcli/nbt/libnbt.h" -#include "libcli/nbt/nbt_proto.h" +#include "../libcli/nbt/libnbt.h" +#include "../libcli/nbt/nbt_proto.h" #include "lib/socket/socket.h" #include "param/param.h" @@ -64,10 +64,10 @@ _PUBLIC_ struct nbt_name_request *nbt_name_release_send(struct nbt_name_socket * struct nbt_rdata_address, 1); if (packet->additional[0].rdata.netbios.addresses == NULL) goto failed; packet->additional[0].rdata.netbios.addresses[0].nb_flags = io->in.nb_flags; - packet->additional[0].rdata.netbios.addresses[0].ipaddr = + packet->additional[0].rdata.netbios.addresses[0].ipaddr = talloc_strdup(packet->additional, io->in.address); - dest = socket_address_from_strings(packet, nbtsock->sock->backend_name, + dest = socket_address_from_strings(packet, nbtsock->sock->backend_name, io->in.dest_addr, io->in.dest_port); if (dest == NULL) goto failed; req = nbt_name_request_send(nbtsock, dest, packet, @@ -79,13 +79,13 @@ _PUBLIC_ struct nbt_name_request *nbt_name_release_send(struct nbt_name_socket * failed: talloc_free(packet); - return NULL; + return NULL; } /* wait for a release reply */ -_PUBLIC_ NTSTATUS nbt_name_release_recv(struct nbt_name_request *req, +_PUBLIC_ NTSTATUS nbt_name_release_recv(struct nbt_name_request *req, TALLOC_CTX *mem_ctx, struct nbt_name_release *io) { NTSTATUS status; @@ -97,7 +97,7 @@ _PUBLIC_ NTSTATUS nbt_name_release_recv(struct nbt_name_request *req, talloc_free(req); return status; } - + packet = req->replies[0].packet; io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].dest->addr); @@ -114,7 +114,7 @@ _PUBLIC_ NTSTATUS nbt_name_release_recv(struct nbt_name_request *req, talloc_free(req); return NT_STATUS_INVALID_NETWORK_RESPONSE; } - io->out.reply_addr = talloc_steal(mem_ctx, + io->out.reply_addr = talloc_steal(mem_ctx, packet->answers[0].rdata.netbios.addresses[0].ipaddr); talloc_steal(mem_ctx, io->out.name.name); talloc_steal(mem_ctx, io->out.name.scope); @@ -127,7 +127,7 @@ _PUBLIC_ NTSTATUS nbt_name_release_recv(struct nbt_name_request *req, /* synchronous name release request */ -_PUBLIC_ NTSTATUS nbt_name_release(struct nbt_name_socket *nbtsock, +_PUBLIC_ NTSTATUS nbt_name_release(struct nbt_name_socket *nbtsock, TALLOC_CTX *mem_ctx, struct nbt_name_release *io) { struct nbt_name_request *req = nbt_name_release_send(nbtsock, io); diff --git a/source4/libcli/nbt/nbtname.c b/libcli/nbt/nbtname.c similarity index 100% rename from source4/libcli/nbt/nbtname.c rename to libcli/nbt/nbtname.c diff --git a/source4/libcli/nbt/nbtsocket.c b/libcli/nbt/nbtsocket.c similarity index 91% rename from source4/libcli/nbt/nbtsocket.c rename to libcli/nbt/nbtsocket.c index 49f175b8a32..57531d2e7b4 100644 --- a/source4/libcli/nbt/nbtsocket.c +++ b/libcli/nbt/nbtsocket.c @@ -1,20 +1,20 @@ -/* +/* Unix SMB/CIFS implementation. low level socket handling for nbt requests Copyright (C) Andrew Tridgell 2005 - + 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 3 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, see . */ @@ -22,7 +22,7 @@ #include "includes.h" #include "lib/events/events.h" #include "lib/util/dlinklist.h" -#include "libcli/nbt/libnbt.h" +#include "../libcli/nbt/libnbt.h" #include "lib/socket/socket.h" #include "librpc/gen_ndr/ndr_nbt.h" #include "param/param.h" @@ -33,7 +33,7 @@ destroy a pending request */ static int nbt_name_request_destructor(struct nbt_name_request *req) -{ +{ if (req->state == NBT_REQUEST_SEND) { DLIST_REMOVE(req->nbtsock->send_queue, req); } @@ -51,7 +51,7 @@ static int nbt_name_request_destructor(struct nbt_name_request *req) if (req->nbtsock->send_queue == NULL) { EVENT_FD_NOT_WRITEABLE(req->nbtsock->fde); } - if (req->nbtsock->num_pending == 0 && + if (req->nbtsock->num_pending == 0 && req->nbtsock->incoming.handler == NULL) { EVENT_FD_NOT_READABLE(req->nbtsock->fde); } @@ -70,11 +70,11 @@ static void nbt_name_socket_send(struct nbt_name_socket *nbtsock) while ((req = nbtsock->send_queue)) { size_t len; - + len = req->encoded.length; - status = socket_sendto(nbtsock->sock, &req->encoded, &len, + status = socket_sendto(nbtsock->sock, &req->encoded, &len, req->dest); - if (NT_STATUS_IS_ERR(status)) goto failed; + if (NT_STATUS_IS_ERR(status)) goto failed; if (!NT_STATUS_IS_OK(status)) { talloc_free(tmp_ctx); @@ -116,17 +116,17 @@ failed: static void nbt_name_socket_timeout(struct event_context *ev, struct timed_event *te, struct timeval t, void *private) { - struct nbt_name_request *req = talloc_get_type(private, + struct nbt_name_request *req = talloc_get_type(private, struct nbt_name_request); if (req->num_retries != 0) { req->num_retries--; - req->te = event_add_timed(req->nbtsock->event_ctx, req, + req->te = event_add_timed(req->nbtsock->event_ctx, req, timeval_add(&t, req->timeout, 0), nbt_name_socket_timeout, req); if (req->state != NBT_REQUEST_SEND) { req->state = NBT_REQUEST_SEND; - DLIST_ADD_END(req->nbtsock->send_queue, req, + DLIST_ADD_END(req->nbtsock->send_queue, req, struct nbt_name_request *); } EVENT_FD_WRITEABLE(req->nbtsock->fde); @@ -201,7 +201,7 @@ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock) } if (DEBUGLVL(10)) { - DEBUG(10,("Received nbt packet of length %d from %s:%d\n", + DEBUG(10,("Received nbt packet of length %d from %s:%d\n", (int)blob.length, src->addr, src->port)); NDR_PRINT_DEBUG(nbt_name_packet, packet); } @@ -217,7 +217,7 @@ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock) } /* find the matching request */ - req = (struct nbt_name_request *)idr_find(nbtsock->idr, + req = (struct nbt_name_request *)idr_find(nbtsock->idr, packet->name_trn_id); if (req == NULL) { if (nbtsock->unexpected.handler) { @@ -245,15 +245,15 @@ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock) req->num_retries = 0; req->received_wack = true; /* although there can be a timeout in the packet, w2k3 screws it up, - so better to set it ourselves */ + so better to set it ourselves */ req->timeout = lp_parm_int(global_loadparm, NULL, "nbt", "wack_timeout", 30); - req->te = event_add_timed(req->nbtsock->event_ctx, req, + req->te = event_add_timed(req->nbtsock->event_ctx, req, timeval_current_ofs(req->timeout, 0), nbt_name_socket_timeout, req); talloc_free(tmp_ctx); return; } - + req->replies = talloc_realloc(req, req->replies, struct nbt_name_reply, req->num_replies+1); if (req->replies == NULL) { @@ -293,11 +293,11 @@ done: static void nbt_name_socket_handler(struct event_context *ev, struct fd_event *fde, uint16_t flags, void *private) { - struct nbt_name_socket *nbtsock = talloc_get_type(private, + struct nbt_name_socket *nbtsock = talloc_get_type(private, struct nbt_name_socket); if (flags & EVENT_FD_WRITE) { nbt_name_socket_send(nbtsock); - } + } if (flags & EVENT_FD_READ) { nbt_name_socket_recv(nbtsock); } @@ -308,7 +308,7 @@ static void nbt_name_socket_handler(struct event_context *ev, struct fd_event *f initialise a nbt_name_socket. The event_ctx is optional, if provided then operations will use that event context */ -_PUBLIC_ struct nbt_name_socket *nbt_name_socket_init(TALLOC_CTX *mem_ctx, +_PUBLIC_ struct nbt_name_socket *nbt_name_socket_init(TALLOC_CTX *mem_ctx, struct event_context *event_ctx, struct smb_iconv_convenience *iconv_convenience) { @@ -337,10 +337,10 @@ _PUBLIC_ struct nbt_name_socket *nbt_name_socket_init(TALLOC_CTX *mem_ctx, nbtsock->unexpected.handler = NULL; nbtsock->iconv_convenience = iconv_convenience; - nbtsock->fde = event_add_fd(nbtsock->event_ctx, nbtsock, + nbtsock->fde = event_add_fd(nbtsock->event_ctx, nbtsock, socket_get_fd(nbtsock->sock), 0, nbt_name_socket_handler, nbtsock); - + return nbtsock; failed: @@ -351,7 +351,7 @@ failed: /* send off a nbt name request */ -struct nbt_name_request *nbt_name_request_send(struct nbt_name_socket *nbtsock, +struct nbt_name_request *nbt_name_request_send(struct nbt_name_socket *nbtsock, struct socket_address *dest, struct nbt_name_packet *request, int timeout, int retries, @@ -378,7 +378,7 @@ struct nbt_name_request *nbt_name_request_send(struct nbt_name_socket *nbtsock, id = idr_get_new_random(req->nbtsock->idr, req, UINT16_MAX); } else { if (idr_find(req->nbtsock->idr, request->name_trn_id)) goto failed; - id = idr_get_new_above(req->nbtsock->idr, req, request->name_trn_id, + id = idr_get_new_above(req->nbtsock->idr, req, request->name_trn_id, UINT16_MAX); } if (id == -1) goto failed; @@ -386,13 +386,13 @@ struct nbt_name_request *nbt_name_request_send(struct nbt_name_socket *nbtsock, request->name_trn_id = id; req->name_trn_id = id; - req->te = event_add_timed(nbtsock->event_ctx, req, + req->te = event_add_timed(nbtsock->event_ctx, req, timeval_current_ofs(req->timeout, 0), nbt_name_socket_timeout, req); - - talloc_set_destructor(req, nbt_name_request_destructor); - ndr_err = ndr_push_struct_blob(&req->encoded, req, + talloc_set_destructor(req, nbt_name_request_destructor); + + ndr_err = ndr_push_struct_blob(&req->encoded, req, req->nbtsock->iconv_convenience, request, (ndr_push_flags_fn_t)ndr_push_nbt_name_packet); @@ -401,7 +401,7 @@ struct nbt_name_request *nbt_name_request_send(struct nbt_name_socket *nbtsock, DLIST_ADD_END(nbtsock->send_queue, req, struct nbt_name_request *); if (DEBUGLVL(10)) { - DEBUG(10,("Queueing nbt packet to %s:%d\n", + DEBUG(10,("Queueing nbt packet to %s:%d\n", req->dest->addr, req->dest->port)); NDR_PRINT_DEBUG(nbt_name_packet, request); } @@ -419,7 +419,7 @@ failed: /* send off a nbt name reply */ -_PUBLIC_ NTSTATUS nbt_name_reply_send(struct nbt_name_socket *nbtsock, +_PUBLIC_ NTSTATUS nbt_name_reply_send(struct nbt_name_socket *nbtsock, struct socket_address *dest, struct nbt_name_packet *request) { @@ -435,13 +435,13 @@ _PUBLIC_ NTSTATUS nbt_name_reply_send(struct nbt_name_socket *nbtsock, req->state = NBT_REQUEST_SEND; req->is_reply = true; - talloc_set_destructor(req, nbt_name_request_destructor); + talloc_set_destructor(req, nbt_name_request_destructor); if (DEBUGLVL(10)) { - NDR_PRINT_DEBUG(nbt_name_packet, request); + NDR_PRINT_DEBUG(nbt_name_packet, request); } - ndr_err = ndr_push_struct_blob(&req->encoded, req, + ndr_err = ndr_push_struct_blob(&req->encoded, req, req->nbtsock->iconv_convenience, request, (ndr_push_flags_fn_t)ndr_push_nbt_name_packet); @@ -483,7 +483,7 @@ NTSTATUS nbt_name_request_recv(struct nbt_name_request *req) setup a handler for incoming requests */ _PUBLIC_ NTSTATUS nbt_set_incoming_handler(struct nbt_name_socket *nbtsock, - void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *, + void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *, struct socket_address *), void *private) { diff --git a/source4/libcli/nbt/pynbt.c b/libcli/nbt/pynbt.c similarity index 94% rename from source4/libcli/nbt/pynbt.c rename to libcli/nbt/pynbt.c index e91096630a2..e49c1776a33 100644 --- a/source4/libcli/nbt/pynbt.c +++ b/libcli/nbt/pynbt.c @@ -1,18 +1,18 @@ -/* +/* Unix SMB/CIFS implementation. Samba utility functions Copyright © Jelmer Vernooij 2008 - + 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 3 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, see . */ @@ -20,7 +20,7 @@ #include "includes.h" #include #include "libcli/util/pyerrors.h" -#include "libcli/nbt/libnbt.h" +#include "../libcli/nbt/libnbt.h" #include "lib/events/events.h" #include "param/param.h" @@ -48,7 +48,7 @@ static PyObject *py_nbt_node_init(PyTypeObject *self, PyObject *args, PyObject * return NULL; ev = s4_event_context_init(ret->mem_ctx); - ret->socket = nbt_name_socket_init(ret->mem_ctx, ev, lp_iconv_convenience(global_loadparm)); + ret->socket = nbt_name_socket_init(ret->mem_ctx, ev, lp_iconv_convenience(global_loadparm)); return (PyObject *)ret; } @@ -58,14 +58,14 @@ static bool PyObject_AsDestinationTuple(PyObject *obj, const char **dest_addr, u *dest_addr = PyString_AsString(obj); *dest_port = NBT_NAME_SERVICE_PORT; return true; - } + } if (PyTuple_Check(obj)) { if (PyTuple_Size(obj) < 1) { PyErr_SetString(PyExc_TypeError, "Destination tuple size invalid"); return false; } - + if (!PyString_Check(PyTuple_GetItem(obj, 0))) { PyErr_SetString(PyExc_TypeError, "Destination tuple first element not string"); return false; @@ -120,7 +120,7 @@ static bool PyObject_AsNBTName(PyObject *obj, struct nbt_name_socket *socket, st return false; } -static PyObject *PyObject_FromNBTName(struct nbt_name_socket *socket, struct smb_iconv_convenience *ic, +static PyObject *PyObject_FromNBTName(struct nbt_name_socket *socket, struct smb_iconv_convenience *ic, struct nbt_name *name) { if (name->scope) { @@ -145,10 +145,10 @@ static PyObject *py_nbt_name_query(PyObject *self, PyObject *args, PyObject *kwa io.in.timeout = 0; io.in.retries = 3; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|bbii:query_name", + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|bbii:query_name", discard_const_p(char *, kwnames), - &py_name, &py_dest, - &io.in.broadcast, &io.in.wins_lookup, + &py_name, &py_dest, + &io.in.broadcast, &io.in.wins_lookup, &io.in.timeout, &io.in.retries)) { return NULL; } @@ -182,7 +182,7 @@ static PyObject *py_nbt_name_query(PyObject *self, PyObject *args, PyObject *kwa Py_DECREF(ret); return NULL; } - + for (i = 0; i < io.out.num_addrs; i++) { PyList_SetItem(reply_addrs, i, PyString_FromString(io.out.reply_addrs[i])); } @@ -204,9 +204,9 @@ static PyObject *py_nbt_name_status(PyObject *self, PyObject *args, PyObject *kw io.in.timeout = 0; io.in.retries = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|ii:name_status", + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|ii:name_status", discard_const_p(char *, kwnames), - &py_name, &py_dest, + &py_name, &py_dest, &io.in.timeout, &io.in.retries)) { return NULL; } @@ -238,9 +238,9 @@ static PyObject *py_nbt_name_status(PyObject *self, PyObject *args, PyObject *kw py_names = PyList_New(io.out.status.num_names); for (i = 0; i < io.out.status.num_names; i++) { - PyList_SetItem(py_names, i, Py_BuildValue("(sii)", + PyList_SetItem(py_names, i, Py_BuildValue("(sii)", io.out.status.names[i].name, - io.out.status.names[i].nb_flags, + io.out.status.names[i].nb_flags, io.out.status.names[i].type)); } @@ -256,7 +256,7 @@ static PyObject *py_nbt_name_register(PyObject *self, PyObject *args, PyObject * struct nbt_name_register io; NTSTATUS status; - const char *kwnames[] = { "name", "address", "dest", "register_demand", "broadcast", + const char *kwnames[] = { "name", "address", "dest", "register_demand", "broadcast", "multi_homed", "ttl", "timeout", "retries", NULL }; io.in.broadcast = true; @@ -265,11 +265,11 @@ static PyObject *py_nbt_name_register(PyObject *self, PyObject *args, PyObject * io.in.timeout = 0; io.in.retries = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OsO|bbbiii:query_name", + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OsO|bbbiii:query_name", discard_const_p(char *, kwnames), - &py_name, &io.in.address, &py_dest, - &io.in.register_demand, - &io.in.broadcast, &io.in.multi_homed, + &py_name, &io.in.address, &py_dest, + &io.in.register_demand, + &io.in.broadcast, &io.in.multi_homed, &io.in.ttl, &io.in.timeout, &io.in.retries)) { return NULL; } @@ -312,7 +312,7 @@ static PyObject *py_nbt_name_refresh(PyObject *self, PyObject *args, PyObject *k struct nbt_name_refresh io; NTSTATUS status; - const char *kwnames[] = { "name", "address", "dest", "nb_flags", "broadcast", + const char *kwnames[] = { "name", "address", "dest", "nb_flags", "broadcast", "ttl", "timeout", "retries", NULL }; io.in.broadcast = true; @@ -320,11 +320,11 @@ static PyObject *py_nbt_name_refresh(PyObject *self, PyObject *args, PyObject *k io.in.timeout = 0; io.in.retries = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OsO|ibiii:query_name", + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OsO|ibiii:query_name", discard_const_p(char *, kwnames), - &py_name, &io.in.address, &py_dest, - &io.in.nb_flags, - &io.in.broadcast, + &py_name, &io.in.address, &py_dest, + &io.in.nb_flags, + &io.in.broadcast, &io.in.ttl, &io.in.timeout, &io.in.retries)) { return NULL; } @@ -366,7 +366,7 @@ static PyObject *py_nbt_name_release(PyObject *self, PyObject *args, PyObject *k } static PyMethodDef py_nbt_methods[] = { - { "query_name", (PyCFunction)py_nbt_name_query, METH_VARARGS|METH_KEYWORDS, + { "query_name", (PyCFunction)py_nbt_name_query, METH_VARARGS|METH_KEYWORDS, "S.query_name(name, dest, broadcast=True, wins=False, timeout=0, retries=3) -> (reply_from, name, reply_addr)\n" "Query for a NetBIOS name" }, { "register_name", (PyCFunction)py_nbt_name_register, METH_VARARGS|METH_KEYWORDS, -- 2.11.4.GIT