diff options
Diffstat (limited to 'source/lib')
140 files changed, 2988 insertions, 26702 deletions
diff --git a/source/lib/access.c b/source/lib/access.c index 6a445f8139..db5d007deb 100644 --- a/source/lib/access.c +++ b/source/lib/access.c @@ -175,7 +175,7 @@ static bool string_match(const char *tok,const char *s) } /* client_match - match host name and address against token */ -bool client_match(const char *tok, const void *item) +static bool client_match(const char *tok, const void *item) { const char **client = (const char **)item; @@ -211,7 +211,7 @@ bool client_match(const char *tok, const void *item) } /* list_match - match an item against a list of tokens with exceptions */ -bool list_match(const char **list,const void *item, +static bool list_match(const char **list,const void *item, bool (*match_fn)(const char *, const void *)) { bool match = false; diff --git a/source/lib/account_pol.c b/source/lib/account_pol.c index 1e435ca53e..e415d10d8e 100644 --- a/source/lib/account_pol.c +++ b/source/lib/account_pol.c @@ -212,12 +212,12 @@ bool init_account_policy(void) return True; } - db = db_open(NULL, state_path("account_policy.tdb"), 0, TDB_DEFAULT, + db = db_open_trans(NULL, state_path("account_policy.tdb"), 0, TDB_DEFAULT, O_RDWR, 0600); if (db == NULL) { /* the account policies files does not exist or open * failed, try to create a new one */ - db = db_open(NULL, state_path("account_policy.tdb"), 0, + db = db_open_trans(NULL, state_path("account_policy.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600); if (db == NULL) { DEBUG(0,("Failed to open account policy database\n")); @@ -283,8 +283,7 @@ bool init_account_policy(void) if (db->transaction_commit(db) != 0) { DEBUG(0, ("transaction_commit failed\n")); - TALLOC_FREE(db); - return false; + goto cancel; } return True; diff --git a/source/lib/afs.c b/source/lib/afs.c index 7193f0e46d..9f5d81f442 100644 --- a/source/lib/afs.c +++ b/source/lib/afs.c @@ -213,6 +213,8 @@ char *afs_createtoken_str(const char *username, const char *cell) bool afs_login(connection_struct *conn) { + extern userdom_struct current_user_info; + extern struct current_user current_user; DATA_BLOB ticket; char *afs_username = NULL; char *cell = NULL; @@ -232,14 +234,14 @@ bool afs_login(connection_struct *conn) afs_username = talloc_sub_advanced(ctx, SNUM(conn), conn->user, conn->connectpath, conn->gid, - conn->server_info->sanitized_username, - pdb_get_domain(conn->server_info->sam_account), + get_current_username(), + current_user_info.domain, afs_username); if (!afs_username) { return false; } - user_sid = &conn->server_info->ptok->user_sids[0]; + user_sid = ¤t_user.nt_user_token->user_sids[0]; afs_username = talloc_string_sub(talloc_tos(), afs_username, "%s", @@ -292,7 +294,7 @@ bool afs_login(connection_struct *conn) char *afs_createtoken_str(const char *username, const char *cell) { - return NULL; + return False; } #endif /* WITH_FAKE_KASERVER */ diff --git a/source/lib/async_req.c b/source/lib/async_req.c index 501a6b5524..2e85d9a38d 100644 --- a/source/lib/async_req.c +++ b/source/lib/async_req.c @@ -19,20 +19,6 @@ #include "includes.h" -/** - * @brief Print an async_req structure - * @param[in] mem_ctx The memory context for the result - * @param[in] req The request to be printed - * @retval Text representation of req - * - * This is a default print function for async requests. Implementations should - * override this with more specific information. - * - * This function should not be used by async API users, this is non-static - * only to allow implementations to easily provide default information in - * their specific functions. - */ - char *async_req_print(TALLOC_CTX *mem_ctx, struct async_req *req) { return talloc_asprintf(mem_ctx, "async_req: state=%d, status=%s, " @@ -40,15 +26,6 @@ char *async_req_print(TALLOC_CTX *mem_ctx, struct async_req *req) talloc_get_name(req->private_data)); } -/** - * @brief Create an async request - * @param[in] mem_ctx The memory context for the result - * @param[in] ev The event context this async request will be driven by - * @retval A new async request - * - * The new async request will be initialized in state ASYNC_REQ_IN_PROGRESS - */ - struct async_req *async_req_new(TALLOC_CTX *mem_ctx, struct event_context *ev) { struct async_req *result; @@ -63,15 +40,6 @@ struct async_req *async_req_new(TALLOC_CTX *mem_ctx, struct event_context *ev) return result; } -/** - * @brief An async request has successfully finished - * @param[in] req The finished request - * - * async_req_done is to be used by implementors of async requests. When a - * request is successfully finished, this function calls the user's completion - * function. - */ - void async_req_done(struct async_req *req) { req->status = NT_STATUS_OK; @@ -81,16 +49,6 @@ void async_req_done(struct async_req *req) } } -/** - * @brief An async request has seen an error - * @param[in] req The request with an error - * @param[in] status The error code - * - * async_req_done is to be used by implementors of async requests. When a - * request can not successfully completed, the implementation should call this - * function with the appropriate status code. - */ - void async_req_error(struct async_req *req, NTSTATUS status) { req->status = status; @@ -100,14 +58,6 @@ void async_req_error(struct async_req *req, NTSTATUS status) } } -/** - * @brief Timed event callback - * @param[in] ev Event context - * @param[in] te The timed event - * @param[in] now current time - * @param[in] priv The async request to be finished - */ - static void async_trigger(struct event_context *ev, struct timed_event *te, const struct timeval *now, void *priv) { @@ -122,21 +72,12 @@ static void async_trigger(struct event_context *ev, struct timed_event *te, } } -/** - * @brief Finish a request before it started processing - * @param[in] req The finished request - * @param[in] status The success code - * - * An implementation of an async request might find that it can either finish - * the request without waiting for an external event, or it can't even start - * the engine. To present the illusion of a callback to the user of the API, - * the implementation can call this helper function which triggers an - * immediate timed event. This way the caller can use the same calling - * conventions, independent of whether the request was actually deferred. - */ - bool async_post_status(struct async_req *req, NTSTATUS status) { + /* + * Used if a request is finished before it even started + */ + req->status = status; if (event_add_timed(req->event_ctx, req, timeval_zero(), @@ -147,23 +88,6 @@ bool async_post_status(struct async_req *req, NTSTATUS status) return true; } -/** - * @brief Helper function for nomem check - * @param[in] p The pointer to be checked - * @param[in] req The request being processed - * - * Convenience helper to easily check alloc failure within a callback - * implementing the next step of an async request. - * - * Call pattern would be - * \code - * p = talloc(mem_ctx, bla); - * if (async_req_nomem(p, req)) { - * return; - * } - * \endcode - */ - bool async_req_nomem(const void *p, struct async_req *req) { if (p != NULL) { diff --git a/source/lib/async_sock.c b/source/lib/async_sock.c deleted file mode 100644 index 1a4c27ba20..0000000000 --- a/source/lib/async_sock.c +++ /dev/null @@ -1,674 +0,0 @@ -/* - Unix SMB/CIFS implementation. - async socket syscalls - Copyright (C) Volker Lendecke 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 <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" - -/** - * Discriminator for async_syscall_state - */ -enum async_syscall_type { - ASYNC_SYSCALL_SEND, - ASYNC_SYSCALL_SENDALL, - ASYNC_SYSCALL_RECV, - ASYNC_SYSCALL_RECVALL, - ASYNC_SYSCALL_CONNECT -}; - -/** - * Holder for syscall arguments and the result - */ - -struct async_syscall_state { - enum async_syscall_type syscall_type; - struct fd_event *fde; - - union { - struct param_send { - int fd; - const void *buffer; - size_t length; - int flags; - } param_send; - struct param_sendall { - int fd; - const void *buffer; - size_t length; - int flags; - size_t sent; - } param_sendall; - struct param_recv { - int fd; - void *buffer; - size_t length; - int flags; - } param_recv; - struct param_recvall { - int fd; - void *buffer; - size_t length; - int flags; - size_t received; - } param_recvall; - struct param_connect { - /** - * connect needs to be done on a nonblocking - * socket. Keep the old flags around - */ - long old_sockflags; - int fd; - const struct sockaddr *address; - socklen_t address_len; - } param_connect; - } param; - - union { - ssize_t result_ssize_t; - size_t result_size_t; - int result_int; - } result; - int sys_errno; -}; - -/** - * @brief Create a new async syscall req - * @param[in] mem_ctx The memory context to hang the result off - * @param[in] ev The event context to work from - * @param[in] type Which syscall will this be - * @param[in] pstate Where to put the newly created private_data state - * @retval The new request - * - * This is a helper function to prepare a new struct async_req with an - * associated struct async_syscall_state. The async_syscall_state will be put - * into the async_req as private_data. - */ - -static struct async_req *async_syscall_new(TALLOC_CTX *mem_ctx, - struct event_context *ev, - enum async_syscall_type type, - struct async_syscall_state **pstate) -{ - struct async_req *result; - struct async_syscall_state *state; - - result = async_req_new(mem_ctx, ev); - if (result == NULL) { - return NULL; - } - - state = talloc(result, struct async_syscall_state); - if (state == NULL) { - TALLOC_FREE(result); - return NULL; - } - - state->syscall_type = type; - - result->private_data = state; - - *pstate = state; - - return result; -} - -/** - * @brief Create a new async syscall req based on a fd - * @param[in] mem_ctx The memory context to hang the result off - * @param[in] ev The event context to work from - * @param[in] type Which syscall will this be - * @param[in] fd The file descriptor we work on - * @param[in] fde_flags EVENT_FD_READ/WRITE -- what are we interested in? - * @param[in] fde_cb The callback function for the file descriptor event - * @param[in] pstate Where to put the newly created private_data state - * @retval The new request - * - * This is a helper function to prepare a new struct async_req with an - * associated struct async_syscall_state and an associated file descriptor - * event. - */ - -static struct async_req *async_fde_syscall_new( - TALLOC_CTX *mem_ctx, - struct event_context *ev, - enum async_syscall_type type, - int fd, - uint16_t fde_flags, - void (*fde_cb)(struct event_context *ev, - struct fd_event *fde, uint16_t flags, - void *priv), - struct async_syscall_state **pstate) -{ - struct async_req *result; - struct async_syscall_state *state; - - result = async_syscall_new(mem_ctx, ev, type, &state); - if (result == NULL) { - return NULL; - } - - state->fde = event_add_fd(ev, state, fd, fde_flags, fde_cb, result); - if (state->fde == NULL) { - TALLOC_FREE(result); - return NULL; - } - *pstate = state; - return result; -} - -/** - * Retrieve a ssize_t typed result from an async syscall - * @param[in] req The syscall that has just finished - * @param[out] perrno Where to put the syscall's errno - * @retval The return value from the asynchronously called syscall - */ - -ssize_t async_syscall_result_ssize_t(struct async_req **req, int *perrno) -{ - struct async_syscall_state *state = talloc_get_type_abort( - (*req)->private_data, struct async_syscall_state); - - int sys_errno = state->sys_errno; - ssize_t result = state->result.result_ssize_t; - - TALLOC_FREE(*req); - - *perrno = sys_errno; - return result; -} - -/** - * Retrieve a size_t typed result from an async syscall - * @param[in] req The syscall that has just finished - * @param[out] perrno Where to put the syscall's errno - * @retval The return value from the asynchronously called syscall - */ - -size_t async_syscall_result_size_t(struct async_req **req, int *perrno) -{ - struct async_syscall_state *state = talloc_get_type_abort( - (*req)->private_data, struct async_syscall_state); - - int sys_errno = state->sys_errno; - size_t result = state->result.result_ssize_t; - - TALLOC_FREE(*req); - - *perrno = sys_errno; - return result; -} - -/** - * Retrieve a int typed result from an async syscall - * @param[in] req The syscall that has just finished - * @param[out] perrno Where to put the syscall's errno - * @retval The return value from the asynchronously called syscall - */ - -ssize_t async_syscall_result_int(struct async_req **req, int *perrno) -{ - struct async_syscall_state *state = talloc_get_type_abort( - (*req)->private_data, struct async_syscall_state); - - int sys_errno = state->sys_errno; - int result = state->result.result_ssize_t; - - TALLOC_FREE(*req); - - *perrno = sys_errno; - return result; -} - -/** - * fde event handler for the "send" syscall - * @param[in] ev The event context that sent us here - * @param[in] fde The file descriptor event associated with the send - * @param[in] flags Can only be EVENT_FD_WRITE here - * @param[in] priv private data, "struct async_req *" in this case - */ - -static void async_send_callback(struct event_context *ev, - struct fd_event *fde, uint16_t flags, - void *priv) -{ - struct async_req *req = talloc_get_type_abort( - priv, struct async_req); - struct async_syscall_state *state = talloc_get_type_abort( - req->private_data, struct async_syscall_state); - struct param_send *p = &state->param.param_send; - - SMB_ASSERT(state->syscall_type == ASYNC_SYSCALL_SEND); - - state->result.result_ssize_t = send(p->fd, p->buffer, p->length, - p->flags); - state->sys_errno = errno; - - TALLOC_FREE(state->fde); - - async_req_done(req); -} - -/** - * Async version of send(2) - * @param[in] mem_ctx The memory context to hang the result off - * @param[in] ev The event context to work from - * @param[in] fd The socket to send to - * @param[in] buffer The buffer to send - * @param[in] length How many bytes to send - * @param[in] flags flags passed to send(2) - * - * This function is a direct counterpart of send(2) - */ - -struct async_req *async_send(TALLOC_CTX *mem_ctx, struct event_context *ev, - int fd, const void *buffer, size_t length, - int flags) -{ - struct async_req *result; - struct async_syscall_state *state; - - result = async_fde_syscall_new( - mem_ctx, ev, ASYNC_SYSCALL_SEND, - fd, EVENT_FD_WRITE, async_send_callback, - &state); - if (result == NULL) { - return NULL; - } - - state->param.param_send.fd = fd; - state->param.param_send.buffer = buffer; - state->param.param_send.length = length; - state->param.param_send.flags = flags; - - return result; -} - -/** - * fde event handler for the "sendall" syscall group - * @param[in] ev The event context that sent us here - * @param[in] fde The file descriptor event associated with the send - * @param[in] flags Can only be EVENT_FD_WRITE here - * @param[in] priv private data, "struct async_req *" in this case - */ - -static void async_sendall_callback(struct event_context *ev, - struct fd_event *fde, uint16_t flags, - void *priv) -{ - struct async_req *req = talloc_get_type_abort( - priv, struct async_req); - struct async_syscall_state *state = talloc_get_type_abort( - req->private_data, struct async_syscall_state); - struct param_sendall *p = &state->param.param_sendall; - - SMB_ASSERT(state->syscall_type == ASYNC_SYSCALL_SENDALL); - - state->result.result_ssize_t = send(p->fd, (char *)p->buffer + p->sent, - p->length - p->sent, p->flags); - state->sys_errno = errno; - - if (state->result.result_ssize_t == -1) { - async_req_error(req, map_nt_error_from_unix(state->sys_errno)); - return; - } - - if (state->result.result_ssize_t == 0) { - async_req_error(req, NT_STATUS_END_OF_FILE); - return; - } - - p->sent += state->result.result_ssize_t; - SMB_ASSERT(p->sent <= p->length); - - if (p->sent == p->length) { - TALLOC_FREE(state->fde); - async_req_done(req); - } -} - -/** - * @brief Send all bytes to a socket - * @param[in] mem_ctx The memory context to hang the result off - * @param[in] ev The event context to work from - * @param[in] fd The socket to send to - * @param[in] buffer The buffer to send - * @param[in] length How many bytes to send - * @param[in] flags flags passed to send(2) - * - * async_sendall calls send(2) as long as it is necessary to send all of the - * "length" bytes - */ - -struct async_req *async_sendall(TALLOC_CTX *mem_ctx, struct event_context *ev, - int fd, const void *buffer, size_t length, - int flags) -{ - struct async_req *result; - struct async_syscall_state *state; - - result = async_fde_syscall_new( - mem_ctx, ev, ASYNC_SYSCALL_SENDALL, - fd, EVENT_FD_WRITE, async_sendall_callback, - &state); - if (result == NULL) { - return NULL; - } - - state->param.param_sendall.fd = fd; - state->param.param_sendall.buffer = buffer; - state->param.param_sendall.length = length; - state->param.param_sendall.flags = flags; - state->param.param_sendall.sent = 0; - - return result; -} - -/** - * fde event handler for the "recv" syscall - * @param[in] ev The event context that sent us here - * @param[in] fde The file descriptor event associated with the recv - * @param[in] flags Can only be EVENT_FD_READ here - * @param[in] priv private data, "struct async_req *" in this case - */ - -static void async_recv_callback(struct event_context *ev, - struct fd_event *fde, uint16_t flags, - void *priv) -{ - struct async_req *req = talloc_get_type_abort( - priv, struct async_req); - struct async_syscall_state *state = talloc_get_type_abort( - req->private_data, struct async_syscall_state); - struct param_recv *p = &state->param.param_recv; - - SMB_ASSERT(state->syscall_type == ASYNC_SYSCALL_RECV); - - state->result.result_ssize_t = recv(p->fd, p->buffer, p->length, - p->flags); - state->sys_errno = errno; - - TALLOC_FREE(state->fde); - - async_req_done(req); -} - -/** - * Async version of recv(2) - * @param[in] mem_ctx The memory context to hang the result off - * @param[in] ev The event context to work from - * @param[in] fd The socket to recv from - * @param[in] buffer The buffer to recv into - * @param[in] length How many bytes to recv - * @param[in] flags flags passed to recv(2) - * - * This function is a direct counterpart of recv(2) - */ - -struct async_req *async_recv(TALLOC_CTX *mem_ctx, struct event_context *ev, - int fd, void *buffer, size_t length, - int flags) -{ - struct async_req *result; - struct async_syscall_state *state; - - result = async_fde_syscall_new( - mem_ctx, ev, ASYNC_SYSCALL_RECV, - fd, EVENT_FD_READ, async_recv_callback, - &state); - - if (result == NULL) { - return NULL; - } - - state->param.param_recv.fd = fd; - state->param.param_recv.buffer = buffer; - state->param.param_recv.length = length; - state->param.param_recv.flags = flags; - - return result; -} - -/** - * fde event handler for the "recvall" syscall group - * @param[in] ev The event context that sent us here - * @param[in] fde The file descriptor event associated with the recv - * @param[in] flags Can only be EVENT_FD_READ here - * @param[in] priv private data, "struct async_req *" in this case - */ - -static void async_recvall_callback(struct event_context *ev, - struct fd_event *fde, uint16_t flags, - void *priv) -{ - struct async_req *req = talloc_get_type_abort( - priv, struct async_req); - struct async_syscall_state *state = talloc_get_type_abort( - req->private_data, struct async_syscall_state); - struct param_recvall *p = &state->param.param_recvall; - - SMB_ASSERT(state->syscall_type == ASYNC_SYSCALL_RECVALL); - - state->result.result_ssize_t = recv(p->fd, - (char *)p->buffer + p->received, - p->length - p->received, p->flags); - state->sys_errno = errno; - - if (state->result.result_ssize_t == -1) { - async_req_error(req, map_nt_error_from_unix(state->sys_errno)); - return; - } - - if (state->result.result_ssize_t == 0) { - async_req_error(req, NT_STATUS_END_OF_FILE); - return; - } - - p->received += state->result.result_ssize_t; - SMB_ASSERT(p->received <= p->length); - - if (p->received == p->length) { - TALLOC_FREE(state->fde); - async_req_done(req); - } -} - -/** - * Receive a specified number of bytes from a socket - * @param[in] mem_ctx The memory context to hang the result off - * @param[in] ev The event context to work from - * @param[in] fd The socket to recv from - * @param[in] buffer The buffer to recv into - * @param[in] length How many bytes to recv - * @param[in] flags flags passed to recv(2) - * - * async_recvall will call recv(2) until "length" bytes are received - */ - -struct async_req *async_recvall(TALLOC_CTX *mem_ctx, struct event_context *ev, - int fd, void *buffer, size_t length, - int flags) -{ - struct async_req *result; - struct async_syscall_state *state; - - result = async_fde_syscall_new( - mem_ctx, ev, ASYNC_SYSCALL_RECVALL, - fd, EVENT_FD_READ, async_recvall_callback, - &state); - if (result == NULL) { - return NULL; - } - - state->param.param_recvall.fd = fd; - state->param.param_recvall.buffer = buffer; - state->param.param_recvall.length = length; - state->param.param_recvall.flags = flags; - state->param.param_recvall.received = 0; - - return result; -} - -/** - * fde event handler for connect(2) - * @param[in] ev The event context that sent us here - * @param[in] fde The file descriptor event associated with the connect - * @param[in] flags Indicate read/writeability of the socket - * @param[in] priv private data, "struct async_req *" in this case - */ - -static void async_connect_callback(struct event_context *ev, - struct fd_event *fde, uint16_t flags, - void *priv) -{ - struct async_req *req = talloc_get_type_abort( - priv, struct async_req); - struct async_syscall_state *state = talloc_get_type_abort( - req->private_data, struct async_syscall_state); - struct param_connect *p = &state->param.param_connect; - - SMB_ASSERT(state->syscall_type == ASYNC_SYSCALL_CONNECT); - - TALLOC_FREE(state->fde); - - /* - * Stevens, Network Programming says that if there's a - * successful connect, the socket is only writable. Upon an - * error, it's both readable and writable. - */ - if ((flags & (EVENT_FD_READ|EVENT_FD_WRITE)) - == (EVENT_FD_READ|EVENT_FD_WRITE)) { - int sockerr; - socklen_t err_len = sizeof(sockerr); - - if (getsockopt(p->fd, SOL_SOCKET, SO_ERROR, - (void *)&sockerr, &err_len) == 0) { - errno = sockerr; - } - - state->sys_errno = errno; - - DEBUG(10, ("connect returned %s\n", strerror(errno))); - - sys_fcntl_long(p->fd, F_SETFL, p->old_sockflags); - - async_req_error(req, map_nt_error_from_unix(state->sys_errno)); - return; - } - - sys_fcntl_long(p->fd, F_SETFL, p->old_sockflags); - - state->result.result_int = 0; - state->sys_errno = 0; - - async_req_done(req); -} - -/** - * @brief async version of connect(2) - * @param[in] mem_ctx The memory context to hang the result off - * @param[in] ev The event context to work from - * @param[in] fd The socket to recv from - * @param[in] address Where to connect? - * @param[in] address_len Length of *address - * @retval The async request - * - * This function sets the socket into non-blocking state to be able to call - * connect in an async state. This will be reset when the request is finished. - */ - -struct async_req *async_connect(TALLOC_CTX *mem_ctx, struct event_context *ev, - int fd, const struct sockaddr *address, - socklen_t address_len) -{ - struct async_req *result; - struct async_syscall_state *state; - struct param_connect *p; - - result = async_syscall_new(mem_ctx, ev, ASYNC_SYSCALL_CONNECT, &state); - if (result == NULL) { - return NULL; - } - p = &state->param.param_connect; - - /** - * We have to set the socket to nonblocking for async connect(2). Keep - * the old sockflags around. - */ - - p->old_sockflags = sys_fcntl_long(fd, F_GETFL, 0); - - if (p->old_sockflags == -1) { - if (async_post_status(result, map_nt_error_from_unix(errno))) { - return result; - } - TALLOC_FREE(result); - return NULL; - } - - set_blocking(fd, true); - - state->result.result_int = connect(fd, address, address_len); - - if (state->result.result_int == 0) { - state->sys_errno = 0; - if (async_post_status(result, NT_STATUS_OK)) { - return result; - } - sys_fcntl_long(fd, F_SETFL, p->old_sockflags); - TALLOC_FREE(result); - return NULL; - } - - /** - * A number of error messages show that something good is progressing - * and that we have to wait for readability. - * - * If none of them are present, bail out. - */ - - if (!(errno == EINPROGRESS || errno == EALREADY || -#ifdef EISCONN - errno == EISCONN || -#endif - errno == EAGAIN || errno == EINTR)) { - - state->sys_errno = errno; - - if (async_post_status(result, map_nt_error_from_unix(errno))) { - return result; - } - sys_fcntl_long(fd, F_SETFL, p->old_sockflags); - TALLOC_FREE(result); - return NULL; - } - - state->fde = event_add_fd(ev, state, fd, - EVENT_FD_READ | EVENT_FD_WRITE, - async_connect_callback, state); - if (state->fde == NULL) { - sys_fcntl_long(fd, F_SETFL, p->old_sockflags); - TALLOC_FREE(result); - return NULL; - } - - state->param.param_connect.fd = fd; - state->param.param_connect.address = address; - state->param.param_connect.address_len = address_len; - - return result; -} - diff --git a/source/lib/charcnv.c b/source/lib/charcnv.c index 485212b100..cea234fadd 100644 --- a/source/lib/charcnv.c +++ b/source/lib/charcnv.c @@ -515,7 +515,7 @@ size_t convert_string(charset_t from, charset_t to, * true * @note -1 is not accepted for srclen. * - * @return true if new buffer was correctly allocated, and string was + * @return True if new buffer was correctly allocated, and string was * converted. * * Ensure the srclen contains the terminating zero. @@ -749,22 +749,24 @@ bool convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, * * @param srclen length of source buffer. * @param dest always set at least to NULL - * @parm converted_size set to the number of bytes occupied by the string in - * the destination on success. * @note -1 is not accepted for srclen. * - * @return true if new buffer was correctly allocated, and string was - * converted. - */ -bool convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, - void const *src, size_t srclen, void *dst, - size_t *converted_size, bool allow_bad_conv) + * @returns Size in bytes of the converted string; or -1 in case of error. + **/ +size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, + void const *src, size_t srclen, void *dst, + bool allow_bad_conv) { void **dest = (void **)dst; + size_t dest_len; *dest = NULL; - return convert_string_allocate(ctx, from, to, src, srclen, dest, - converted_size, allow_bad_conv); + if (!convert_string_allocate(ctx, from, to, src, srclen, dest, + &dest_len, allow_bad_conv)) + return (size_t)-1; + if (*dest == NULL) + return (size_t)-1; + return dest_len; } size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) @@ -772,10 +774,10 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) size_t size; smb_ucs2_t *buffer; - if (!push_ucs2_allocate(&buffer, src, &size)) { + size = push_ucs2_allocate(&buffer, src); + if (size == (size_t)-1) { return (size_t)-1; } - if (!strupper_w(buffer) && (dest == src)) { free(buffer); return srclen; @@ -814,25 +816,20 @@ char *strdup_upper(const char *s) if (*p) { /* MB case. */ - size_t converted_size, converted_size2; + size_t size, size2; smb_ucs2_t *buffer = NULL; SAFE_FREE(out_buffer); if (!convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, s, - strlen(s) + 1, - (void **)(void *)&buffer, - &converted_size, True)) - { + strlen(s) + 1, (void **)(void *)&buffer, &size, + True)) { return NULL; } strupper_w(buffer); if (!convert_string_allocate(NULL, CH_UTF16LE, CH_UNIX, buffer, - converted_size, - (void **)(void *)&out_buffer, - &converted_size2, True)) - { + size, (void **)(void *)&out_buffer, &size2, True)) { TALLOC_FREE(buffer); return NULL; } @@ -874,33 +871,36 @@ char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *s) if (*p) { /* MB case. */ - size_t converted_size, converted_size2; + size_t size; smb_ucs2_t *ubuf = NULL; /* We're not using the ascii buffer above. */ TALLOC_FREE(out_buffer); - if (!convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, s, - strlen(s)+1, (void *)&ubuf, - &converted_size, True)) - { + size = convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, + s, strlen(s)+1, + (void *)&ubuf, + True); + if (size == (size_t)-1) { return NULL; } strupper_w(ubuf); - if (!convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, ubuf, - converted_size, (void *)&out_buffer, - &converted_size2, True)) - { - TALLOC_FREE(ubuf); - return NULL; - } + size = convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, + ubuf, size, + (void *)&out_buffer, + True); /* Don't need the intermediate buffer * anymore. */ + TALLOC_FREE(ubuf); + + if (size == (size_t)-1) { + return NULL; + } } return out_buffer; @@ -912,9 +912,7 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) smb_ucs2_t *buffer = NULL; if (!convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, srclen, - (void **)(void *)&buffer, &size, - True)) - { + (void **)(void *)&buffer, &size, True)) { smb_panic("failed to create UCS2 buffer"); } if (!strlower_w(buffer) && (dest == src)) { @@ -932,45 +930,49 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) char *strdup_lower(const char *s) { - size_t converted_size; + size_t size; smb_ucs2_t *buffer = NULL; char *out_buffer; - if (!push_ucs2_allocate(&buffer, s, &converted_size)) { + size = push_ucs2_allocate(&buffer, s); + if (size == -1 || !buffer) { return NULL; } strlower_w(buffer); - if (!pull_ucs2_allocate(&out_buffer, buffer, &converted_size)) { - SAFE_FREE(buffer); + size = pull_ucs2_allocate(&out_buffer, buffer); + SAFE_FREE(buffer); + + if (size == (size_t)-1) { return NULL; } - SAFE_FREE(buffer); - return out_buffer; } char *talloc_strdup_lower(TALLOC_CTX *ctx, const char *s) { - size_t converted_size; + size_t size; smb_ucs2_t *buffer = NULL; char *out_buffer; - if (!push_ucs2_talloc(ctx, &buffer, s, &converted_size)) { + size = push_ucs2_talloc(ctx, &buffer, s); + if (size == -1 || !buffer) { + TALLOC_FREE(buffer); return NULL; } strlower_w(buffer); - if (!pull_ucs2_talloc(ctx, &out_buffer, buffer, &converted_size)) { - TALLOC_FREE(buffer); + size = pull_ucs2_talloc(ctx, &out_buffer, buffer); + TALLOC_FREE(buffer); + + if (size == (size_t)-1) { + TALLOC_FREE(out_buffer); return NULL; } - TALLOC_FREE(buffer); - return out_buffer; } @@ -1047,7 +1049,8 @@ size_t push_ascii_nstring(void *dest, const char *src) smb_ucs2_t *buffer; conv_silent = True; - if (!push_ucs2_allocate(&buffer, src, &buffer_len)) { + buffer_len = push_ucs2_allocate(&buffer, src); + if (buffer_len == (size_t)-1) { smb_panic("failed to create UCS2 buffer"); } @@ -1078,13 +1081,16 @@ size_t push_ascii_nstring(void *dest, const char *src) Push and malloc an ascii string. src and dest null terminated. ********************************************************************/ -bool push_ascii_allocate(char **dest, const char *src, size_t *converted_size) +size_t push_ascii_allocate(char **dest, const char *src) { - size_t src_len = strlen(src)+1; + size_t dest_len, src_len = strlen(src)+1; *dest = NULL; - return convert_string_allocate(NULL, CH_UNIX, CH_DOS, src, src_len, - (void **)dest, converted_size, True); + if (!convert_string_allocate(NULL, CH_UNIX, CH_DOS, src, src_len, + (void **)dest, &dest_len, True)) + return (size_t)-1; + else + return dest_len; } /** @@ -1166,7 +1172,7 @@ static size_t pull_ascii_base_talloc(TALLOC_CTX *ctx, int flags) { char *dest = NULL; - size_t converted_size; + size_t dest_len = 0; #ifdef DEVELOPER /* Ensure we never use the braindead "malloc" varient. */ @@ -1197,15 +1203,13 @@ static size_t pull_ascii_base_talloc(TALLOC_CTX *ctx, } if (!convert_string_allocate(ctx, CH_DOS, CH_UNIX, src, src_len, &dest, - &converted_size, True)) - { - converted_size = 0; - } + &dest_len, True)) + dest_len = 0; - if (converted_size && dest) { + if (dest_len && dest) { /* Did we already process the terminating zero ? */ - if (dest[converted_size - 1] != 0) { - dest[converted_size - 1] = 0; + if (dest[dest_len-1] != 0) { + dest[dest_len-1] = 0; } } else if (dest) { dest[0] = 0; @@ -1307,20 +1311,16 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_ * allocating a buffer using talloc(). * * @param dest always set at least to NULL - * @parm converted_size set to the number of bytes occupied by the string in - * the destination on success. * - * @return true if new buffer was correctly allocated, and string was - * converted. + * @returns The number of bytes occupied by the string in the destination + * or -1 in case of error. **/ -bool push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src, - size_t *converted_size) +size_t push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src) { size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, src, src_len, - (void **)dest, converted_size, True); + return convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, src, src_len, (void **)dest, True); } @@ -1328,21 +1328,21 @@ bool push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src, * Copy a string from a unix char* src to a UCS2 destination, allocating a buffer * * @param dest always set at least to NULL - * @parm converted_size set to the number of bytes occupied by the string in - * the destination on success. * - * @return true if new buffer was correctly allocated, and string was - * converted. + * @returns The number of bytes occupied by the string in the destination + * or -1 in case of error. **/ -bool push_ucs2_allocate(smb_ucs2_t **dest, const char *src, - size_t *converted_size) +size_t push_ucs2_allocate(smb_ucs2_t **dest, const char *src) { - size_t src_len = strlen(src)+1; + size_t dest_len, src_len = strlen(src)+1; *dest = NULL; - return convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, src_len, - (void **)dest, converted_size, True); + if (!convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, src_len, + (void **)dest, &dest_len, True)) + return (size_t)-1; + else + return dest_len; } /** @@ -1394,41 +1394,36 @@ size_t push_utf8_fstring(void *dest, const char *src) * Copy a string from a unix char* src to a UTF-8 destination, allocating a buffer using talloc * * @param dest always set at least to NULL - * @parm converted_size set to the number of bytes occupied by the string in - * the destination on success. * - * @return true if new buffer was correctly allocated, and string was - * converted. + * @returns The number of bytes occupied by the string in the destination **/ -bool push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src, - size_t *converted_size) +size_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) { size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, - (void**)dest, converted_size, True); + return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void**)dest, True); } /** * Copy a string from a unix char* src to a UTF-8 destination, allocating a buffer * * @param dest always set at least to NULL - * @parm converted_size set to the number of bytes occupied by the string in - * the destination on success. * - * @return true if new buffer was correctly allocated, and string was - * converted. + * @returns The number of bytes occupied by the string in the destination **/ -bool push_utf8_allocate(char **dest, const char *src, size_t *converted_size) +size_t push_utf8_allocate(char **dest, const char *src) { - size_t src_len = strlen(src)+1; + size_t dest_len, src_len = strlen(src)+1; *dest = NULL; - return convert_string_allocate(NULL, CH_UNIX, CH_UTF8, src, src_len, - (void **)dest, converted_size, True); + if (!convert_string_allocate(NULL, CH_UNIX, CH_UTF8, src, src_len, + (void **)dest, &dest_len, True)) + return (size_t)-1; + else + return dest_len; } /** @@ -1569,8 +1564,14 @@ size_t pull_ucs2_base_talloc(TALLOC_CTX *ctx, src_len &= ~1; } - if (!convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, src, src_len, - (void *)&dest, &dest_len, True)) { + dest_len = convert_string_talloc(ctx, + CH_UTF16LE, + CH_UNIX, + src, + src_len, + (void *)&dest, + True); + if (dest_len == (size_t)-1) { dest_len = 0; } @@ -1613,103 +1614,83 @@ size_t pull_ucs2_fstring(char *dest, const void *src) * Copy a string from a UCS2 src to a unix char * destination, allocating a buffer using talloc * * @param dest always set at least to NULL - * @parm converted_size set to the number of bytes occupied by the string in - * the destination on success. * - * @return true if new buffer was correctly allocated, and string was - * converted. + * @returns The number of bytes occupied by the string in the destination **/ -bool pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src, - size_t *converted_size) +size_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src) { size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t); - *dest = NULL; - return convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, src, src_len, - (void **)dest, converted_size, True); + return convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, src, src_len, (void **)dest, True); } /** * Copy a string from a UCS2 src to a unix char * destination, allocating a buffer * * @param dest always set at least to NULL - * @parm converted_size set to the number of bytes occupied by the string in - * the destination on success. - * @return true if new buffer was correctly allocated, and string was - * converted. + * + * @returns The number of bytes occupied by the string in the destination **/ -bool pull_ucs2_allocate(char **dest, const smb_ucs2_t *src, - size_t *converted_size) +size_t pull_ucs2_allocate(char **dest, const smb_ucs2_t *src) { - size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t); - + size_t dest_len, src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t); *dest = NULL; - return convert_string_allocate(NULL, CH_UTF16LE, CH_UNIX, src, src_len, - (void **)dest, converted_size, True); + if (!convert_string_allocate(NULL, CH_UTF16LE, CH_UNIX, src, src_len, + (void **)dest, &dest_len, True)) + return (size_t)-1; + else + return dest_len; } /** * Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer using talloc * * @param dest always set at least to NULL - * @parm converted_size set to the number of bytes occupied by the string in - * the destination on success. * - * @return true if new buffer was correctly allocated, and string was - * converted. + * @returns The number of bytes occupied by the string in the destination **/ -bool pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src, - size_t *converted_size) +size_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) { size_t src_len = strlen(src)+1; - *dest = NULL; - return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, - (void **)dest, converted_size, True); + return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, (void **)dest, True); } /** * Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer * * @param dest always set at least to NULL - * @parm converted_size set to the number of bytes occupied by the string in - * the destination on success. * - * @return true if new buffer was correctly allocated, and string was - * converted. + * @returns The number of bytes occupied by the string in the destination **/ -bool pull_utf8_allocate(char **dest, const char *src, size_t *converted_size) +size_t pull_utf8_allocate(char **dest, const char *src) { - size_t src_len = strlen(src)+1; - + size_t dest_len, src_len = strlen(src)+1; *dest = NULL; - return convert_string_allocate(NULL, CH_UTF8, CH_UNIX, src, src_len, - (void **)dest, converted_size, True); + if (!convert_string_allocate(NULL, CH_UTF8, CH_UNIX, src, src_len, + (void **)dest, &dest_len, True)) + return (size_t)-1; + else + return dest_len; } /** * Copy a string from a DOS src to a unix char * destination, allocating a buffer using talloc * * @param dest always set at least to NULL - * @parm converted_size set to the number of bytes occupied by the string in - * the destination on success. * - * @return true if new buffer was correctly allocated, and string was - * converted. + * @returns The number of bytes occupied by the string in the destination **/ -bool pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src, - size_t *converted_size) +size_t pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src) { size_t src_len = strlen(src)+1; - *dest = NULL; - return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, - (void **)dest, converted_size, True); + return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, (void **)dest, True); } /** diff --git a/source/lib/compression/mszip.c b/source/lib/compression/mszip.c deleted file mode 100644 index aeeb2d8afd..0000000000 --- a/source/lib/compression/mszip.c +++ /dev/null @@ -1,676 +0,0 @@ -/* mszip decompression - based on cabextract.c code from - * Stuart Caie - * - * adapted for Samba by Andrew Tridgell and Stefan Metzmacher 2005 - * - * (C) 2000-2001 Stuart Caie <kyzer@4u.net> - * reaktivate-specifics by Malte Starostik <malte@kde.org> - * - * 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 <http://www.gnu.org/licenses/>. - */ - -#include "includes.h" -#include "lib/compression/mszip.h" - -/*--------------------------------------------------------------------------*/ -/* our archiver information / state */ - -/* MSZIP stuff */ -#define ZIPWSIZE 0x8000 /* window size */ -#define ZIPLBITS 9 /* bits in base literal/length lookup table */ -#define ZIPDBITS 6 /* bits in base distance lookup table */ -#define ZIPBMAX 16 /* maximum bit length of any code */ -#define ZIPN_MAX 288 /* maximum number of codes in any set */ - -struct Ziphuft { - uint8_t e; /* number of extra bits or operation */ - uint8_t b; /* number of bits in this code or subcode */ - union { - uint16_t n; /* literal, length base, or distance base */ - struct Ziphuft *t; /* pointer to next level of table */ - } v; -}; - -struct ZIPstate { - uint32_t window_posn; /* current offset within the window */ - uint32_t bb; /* bit buffer */ - uint32_t bk; /* bits in bit buffer */ - uint32_t ll[288+32]; /* literal/length and distance code lengths */ - uint32_t c[ZIPBMAX+1]; /* bit length count table */ - int32_t lx[ZIPBMAX+1]; /* memory for l[-1..ZIPBMAX-1] */ - struct Ziphuft *u[ZIPBMAX]; /* table stack */ - uint32_t v[ZIPN_MAX]; /* values in order of bit length */ - uint32_t x[ZIPBMAX+1]; /* bit offsets, then code stack */ - uint8_t *inpos; -}; - -/* generic stuff */ -#define CAB(x) (decomp_state->x) -#define ZIP(x) (decomp_state->methods.zip.x) - -/* CAB data blocks are <= 32768 bytes in uncompressed form. Uncompressed - * blocks have zero growth. MSZIP guarantees that it won't grow above - * uncompressed size by more than 12 bytes. LZX guarantees it won't grow - * more than 6144 bytes. - */ -#define CAB_BLOCKMAX (32768) -#define CAB_INPUTMAX (CAB_BLOCKMAX+6144) - -struct decomp_state { - struct folder *current; /* current folder we're extracting from */ - uint32_t offset; /* uncompressed offset within folder */ - uint8_t *outpos; /* (high level) start of data to use up */ - uint16_t outlen; /* (high level) amount of data to use up */ - uint16_t split; /* at which split in current folder? */ - int (*decompress)(int, int); /* the chosen compression func */ - uint8_t inbuf[CAB_INPUTMAX+2]; /* +2 for lzx bitbuffer overflows! */ - uint8_t outbuf[CAB_BLOCKMAX]; - union { - struct ZIPstate zip; - } methods; -}; - - -/* MSZIP decruncher */ - -/* Dirk Stoecker wrote the ZIP decoder, based on the InfoZip deflate code */ - -/* Tables for deflate from PKZIP's appnote.txt. */ -static const uint8_t Zipborder[] = /* Order of the bit length code lengths */ -{ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; -static const uint16_t Zipcplens[] = /* Copy lengths for literal codes 257..285 */ -{ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, - 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; -static const uint16_t Zipcplext[] = /* Extra bits for literal codes 257..285 */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, - 4, 5, 5, 5, 5, 0, 99, 99}; /* 99==invalid */ -static const uint16_t Zipcpdist[] = /* Copy offsets for distance codes 0..29 */ -{ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, -513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577}; -static const uint16_t Zipcpdext[] = /* Extra bits for distance codes */ -{ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, -10, 11, 11, 12, 12, 13, 13}; - -/* And'ing with Zipmask[n] masks the lower n bits */ -static const uint16_t Zipmask[17] = { - 0x0000, 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, - 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff -}; - -#define ZIPNEEDBITS(n) {while(k<(n)){int32_t c=*(ZIP(inpos)++);\ - b|=((uint32_t)c)<<k;k+=8;}} -#define ZIPDUMPBITS(n) {b>>=(n);k-=(n);} - -static void Ziphuft_free(struct Ziphuft *t) -{ - register struct Ziphuft *p, *q; - - /* Go through linked list, freeing from the allocated (t[-1]) address. */ - p = t; - while (p != (struct Ziphuft *)NULL) - { - q = (--p)->v.t; - free(p); - p = q; - } -} - -static int32_t Ziphuft_build(struct decomp_state *decomp_state, - uint32_t *b, uint32_t n, uint32_t s, const uint16_t *d, const uint16_t *e, - struct Ziphuft **t, int32_t *m) -{ - uint32_t a; /* counter for codes of length k */ - uint32_t el; /* length of EOB code (value 256) */ - uint32_t f; /* i repeats in table every f entries */ - int32_t g; /* maximum code length */ - int32_t h; /* table level */ - register uint32_t i; /* counter, current code */ - register uint32_t j; /* counter */ - register int32_t k; /* number of bits in current code */ - int32_t *l; /* stack of bits per table */ - register uint32_t *p; /* pointer into ZIP(c)[],ZIP(b)[],ZIP(v)[] */ - register struct Ziphuft *q; /* points to current table */ - struct Ziphuft r; /* table entry for structure assignment */ - register int32_t w; /* bits before this table == (l * h) */ - uint32_t *xp; /* pointer into x */ - int32_t y; /* number of dummy codes added */ - uint32_t z; /* number of entries in current table */ - - l = ZIP(lx)+1; - - /* Generate counts for each bit length */ - el = n > 256 ? b[256] : ZIPBMAX; /* set length of EOB code, if any */ - - for(i = 0; i < ZIPBMAX+1; ++i) - ZIP(c)[i] = 0; - p = b; i = n; - do - { - ZIP(c)[*p]++; p++; /* assume all entries <= ZIPBMAX */ - } while (--i); - if (ZIP(c)[0] == n) /* null input--all zero length codes */ - { - *t = (struct Ziphuft *)NULL; - *m = 0; - return 0; - } - - /* Find minimum and maximum length, bound *m by those */ - for (j = 1; j <= ZIPBMAX; j++) - if (ZIP(c)[j]) - break; - k = j; /* minimum code length */ - if ((uint32_t)*m < j) - *m = j; - for (i = ZIPBMAX; i; i--) - if (ZIP(c)[i]) - break; - g = i; /* maximum code length */ - if ((uint32_t)*m > i) - *m = i; - - /* Adjust last length count to fill out codes, if needed */ - for (y = 1 << j; j < i; j++, y <<= 1) - if ((y -= ZIP(c)[j]) < 0) - return 2; /* bad input: more codes than bits */ - if ((y -= ZIP(c)[i]) < 0) - return 2; - ZIP(c)[i] += y; - - /* Generate starting offsets int32_to the value table for each length */ - ZIP(x)[1] = j = 0; - p = ZIP(c) + 1; xp = ZIP(x) + 2; - while (--i) - { /* note that i == g from above */ - *xp++ = (j += *p++); - } - - /* Make a table of values in order of bit lengths */ - p = b; i = 0; - do{ - if ((j = *p++) != 0) - ZIP(v)[ZIP(x)[j]++] = i; - } while (++i < n); - - - /* Generate the Huffman codes and for each, make the table entries */ - ZIP(x)[0] = i = 0; /* first Huffman code is zero */ - p = ZIP(v); /* grab values in bit order */ - h = -1; /* no tables yet--level -1 */ - w = l[-1] = 0; /* no bits decoded yet */ - ZIP(u)[0] = (struct Ziphuft *)NULL; /* just to keep compilers happy */ - q = (struct Ziphuft *)NULL; /* ditto */ - z = 0; /* ditto */ - - /* go through the bit lengths (k already is bits in shortest code) */ - for (; k <= g; k++) - { - a = ZIP(c)[k]; - while (a--) - { - /* here i is the Huffman code of length k bits for value *p */ - /* make tables up to required level */ - while (k > w + l[h]) - { - w += l[h++]; /* add bits already decoded */ - - /* compute minimum size table less than or equal to *m bits */ - z = (z = g - w) > (uint32_t)*m ? *m : z; /* upper limit */ - if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */ - { /* too few codes for k-w bit table */ - f -= a + 1; /* deduct codes from patterns left */ - xp = ZIP(c) + k; - while (++j < z) /* try smaller tables up to z bits */ - { - if ((f <<= 1) <= *++xp) - break; /* enough codes to use up j bits */ - f -= *xp; /* else deduct codes from patterns */ - } - } - if ((uint32_t)w + j > el && (uint32_t)w < el) - j = el - w; /* make EOB code end at table */ - z = 1 << j; /* table entries for j-bit table */ - l[h] = j; /* set table size in stack */ - - /* allocate and link in new table */ - if (!(q = (struct Ziphuft *)SMB_MALLOC((z + 1)*sizeof(struct Ziphuft)))) - { - if(h) - Ziphuft_free(ZIP(u)[0]); - return 3; /* not enough memory */ - } - *t = q + 1; /* link to list for Ziphuft_free() */ - *(t = &(q->v.t)) = (struct Ziphuft *)NULL; - ZIP(u)[h] = ++q; /* table starts after link */ - - /* connect to last table, if there is one */ - if (h) - { - ZIP(x)[h] = i; /* save pattern for backing up */ - r.b = (uint8_t)l[h-1]; /* bits to dump before this table */ - r.e = (uint8_t)(16 + j); /* bits in this table */ - r.v.t = q; /* pointer to this table */ - j = (i & ((1 << w) - 1)) >> (w - l[h-1]); - ZIP(u)[h-1][j] = r; /* connect to last table */ - } - } - - /* set up table entry in r */ - r.b = (uint8_t)(k - w); - if (p >= ZIP(v) + n) - r.e = 99; /* out of values--invalid code */ - else if (*p < s) - { - r.e = (uint8_t)(*p < 256 ? 16 : 15); /* 256 is end-of-block code */ - r.v.n = *p++; /* simple code is just the value */ - } - else - { - r.e = (uint8_t)e[*p - s]; /* non-simple--look up in lists */ - r.v.n = d[*p++ - s]; - } - - /* fill code-like entries with r */ - f = 1 << (k - w); - for (j = i >> w; j < z; j += f) - q[j] = r; - - /* backwards increment the k-bit code i */ - for (j = 1 << (k - 1); i & j; j >>= 1) - i ^= j; - i ^= j; - - /* backup over finished tables */ - while ((i & ((1 << w) - 1)) != ZIP(x)[h]) - w -= l[--h]; /* don't need to update q */ - } - } - - /* return actual size of base table */ - *m = l[0]; - - /* Return true (1) if we were given an incomplete table */ - return y != 0 && g != 1; -} - -static int32_t Zipinflate_codes(struct decomp_state *decomp_state, - struct Ziphuft *tl, struct Ziphuft *td, - int32_t bl, int32_t bd) -{ - register uint32_t e; /* table entry flag/number of extra bits */ - uint32_t n, d; /* length and index for copy */ - uint32_t w; /* current window position */ - struct Ziphuft *t; /* pointer to table entry */ - uint32_t ml, md; /* masks for bl and bd bits */ - register uint32_t b; /* bit buffer */ - register uint32_t k; /* number of bits in bit buffer */ - - DEBUG(10,("Zipinflate_codes\n")); - - /* make local copies of globals */ - b = ZIP(bb); /* initialize bit buffer */ - k = ZIP(bk); - w = ZIP(window_posn); /* initialize window position */ - - /* inflate the coded data */ - ml = Zipmask[bl]; /* precompute masks for speed */ - md = Zipmask[bd]; - - for(;;) - { - ZIPNEEDBITS((uint32_t)bl) - if((e = (t = tl + ((uint32_t)b & ml))->e) > 16) - do - { - if (e == 99) - return 1; - ZIPDUMPBITS(t->b) - e -= 16; - ZIPNEEDBITS(e) - } while ((e = (t = t->v.t + ((uint32_t)b & Zipmask[e]))->e) > 16); - ZIPDUMPBITS(t->b) - if (w >= CAB_BLOCKMAX) break; - if (e == 16) /* then it's a literal */ - CAB(outbuf)[w++] = (uint8_t)t->v.n; - else /* it's an EOB or a length */ - { - /* exit if end of block */ - if(e == 15) - break; - - /* get length of block to copy */ - ZIPNEEDBITS(e) - n = t->v.n + ((uint32_t)b & Zipmask[e]); - ZIPDUMPBITS(e); - - /* decode distance of block to copy */ - ZIPNEEDBITS((uint32_t)bd) - if ((e = (t = td + ((uint32_t)b & md))->e) > 16) - do { - if (e == 99) - return 1; - ZIPDUMPBITS(t->b) - e -= 16; - ZIPNEEDBITS(e) - } while ((e = (t = t->v.t + ((uint32_t)b & Zipmask[e]))->e) > 16); - ZIPDUMPBITS(t->b) - ZIPNEEDBITS(e) - d = w - t->v.n - ((uint32_t)b & Zipmask[e]); - ZIPDUMPBITS(e) - do - { - n -= (e = (e = ZIPWSIZE - ((d &= ZIPWSIZE-1) > w ? d : w)) > n ?n:e); - do - { - CAB(outbuf)[w++] = CAB(outbuf)[d++]; - } while (--e); - } while (n); - } - } - - /* restore the globals from the locals */ - ZIP(window_posn) = w; /* restore global window pointer */ - ZIP(bb) = b; /* restore global bit buffer */ - ZIP(bk) = k; - - /* done */ - return 0; -} - -/* "decompress" an inflated type 0 (stored) block. */ -static int32_t Zipinflate_stored(struct decomp_state *decomp_state) -{ - uint32_t n; /* number of bytes in block */ - uint32_t w; /* current window position */ - register uint32_t b; /* bit buffer */ - register uint32_t k; /* number of bits in bit buffer */ - - /* make local copies of globals */ - b = ZIP(bb); /* initialize bit buffer */ - k = ZIP(bk); - w = ZIP(window_posn); /* initialize window position */ - - /* go to byte boundary */ - n = k & 7; - ZIPDUMPBITS(n); - - /* get the length and its complement */ - ZIPNEEDBITS(16) - n = ((uint32_t)b & 0xffff); - ZIPDUMPBITS(16) - ZIPNEEDBITS(16) - if (n != (uint32_t)((~b) & 0xffff)) - return 1; /* error in compressed data */ - ZIPDUMPBITS(16) - - /* read and output the compressed data */ - while(n--) - { - ZIPNEEDBITS(8) - CAB(outbuf)[w++] = (uint8_t)b; - ZIPDUMPBITS(8) - } - - /* restore the globals from the locals */ - ZIP(window_posn) = w; /* restore global window pointer */ - ZIP(bb) = b; /* restore global bit buffer */ - ZIP(bk) = k; - return 0; -} - -static int32_t Zipinflate_fixed(struct decomp_state *decomp_state) -{ - struct Ziphuft *fixed_tl; - struct Ziphuft *fixed_td; - int32_t fixed_bl, fixed_bd; - int32_t i; /* temporary variable */ - uint32_t *l; - - l = ZIP(ll); - - /* literal table */ - for(i = 0; i < 144; i++) - l[i] = 8; - for(; i < 256; i++) - l[i] = 9; - for(; i < 280; i++) - l[i] = 7; - for(; i < 288; i++) /* make a complete, but wrong code set */ - l[i] = 8; - fixed_bl = 7; - if((i = Ziphuft_build(decomp_state, l, 288, 257, Zipcplens, Zipcplext, &fixed_tl, &fixed_bl))) - return i; - - /* distance table */ - for(i = 0; i < 30; i++) /* make an incomplete code set */ - l[i] = 5; - fixed_bd = 5; - if((i = Ziphuft_build(decomp_state, l, 30, 0, Zipcpdist, Zipcpdext, &fixed_td, &fixed_bd)) > 1) - { - Ziphuft_free(fixed_tl); - return i; - } - - /* decompress until an end-of-block code */ - i = Zipinflate_codes(decomp_state, fixed_tl, fixed_td, fixed_bl, fixed_bd); - - Ziphuft_free(fixed_td); - Ziphuft_free(fixed_tl); - return i; -} - -/* decompress an inflated type 2 (dynamic Huffman codes) block. */ -static int32_t Zipinflate_dynamic(struct decomp_state *decomp_state) -{ - int32_t i; /* temporary variables */ - uint32_t j; - uint32_t *ll; - uint32_t l; /* last length */ - uint32_t m; /* mask for bit lengths table */ - uint32_t n; /* number of lengths to get */ - struct Ziphuft *tl; /* literal/length code table */ - struct Ziphuft *td; /* distance code table */ - int32_t bl; /* lookup bits for tl */ - int32_t bd; /* lookup bits for td */ - uint32_t nb; /* number of bit length codes */ - uint32_t nl; /* number of literal/length codes */ - uint32_t nd; /* number of distance codes */ - register uint32_t b; /* bit buffer */ - register uint32_t k; /* number of bits in bit buffer */ - - /* make local bit buffer */ - b = ZIP(bb); - k = ZIP(bk); - ll = ZIP(ll); - - /* read in table lengths */ - ZIPNEEDBITS(5) - nl = 257 + ((uint32_t)b & 0x1f); /* number of literal/length codes */ - ZIPDUMPBITS(5) - ZIPNEEDBITS(5) - nd = 1 + ((uint32_t)b & 0x1f); /* number of distance codes */ - ZIPDUMPBITS(5) - ZIPNEEDBITS(4) - nb = 4 + ((uint32_t)b & 0xf); /* number of bit length codes */ - ZIPDUMPBITS(4) - if(nl > 288 || nd > 32) - return 1; /* bad lengths */ - - /* read in bit-length-code lengths */ - for(j = 0; j < nb; j++) - { - ZIPNEEDBITS(3) - ll[Zipborder[j]] = (uint32_t)b & 7; - ZIPDUMPBITS(3) - } - for(; j < 19; j++) - ll[Zipborder[j]] = 0; - - /* build decoding table for trees--single level, 7 bit lookup */ - bl = 7; - if((i = Ziphuft_build(decomp_state, ll, 19, 19, NULL, NULL, &tl, &bl)) != 0) - { - if(i == 1) - Ziphuft_free(tl); - return i; /* incomplete code set */ - } - - /* read in literal and distance code lengths */ - n = nl + nd; - m = Zipmask[bl]; - i = l = 0; - while((uint32_t)i < n) - { - ZIPNEEDBITS((uint32_t)bl) - j = (td = tl + ((uint32_t)b & m))->b; - ZIPDUMPBITS(j) - j = td->v.n; - if (j < 16) /* length of code in bits (0..15) */ - ll[i++] = l = j; /* save last length in l */ - else if (j == 16) /* repeat last length 3 to 6 times */ - { - ZIPNEEDBITS(2) - j = 3 + ((uint32_t)b & 3); - ZIPDUMPBITS(2) - if((uint32_t)i + j > n) - return 1; - while (j--) - ll[i++] = l; - } - else if (j == 17) /* 3 to 10 zero length codes */ - { - ZIPNEEDBITS(3) - j = 3 + ((uint32_t)b & 7); - ZIPDUMPBITS(3) - if ((uint32_t)i + j > n) - return 1; - while (j--) - ll[i++] = 0; - l = 0; - } - else /* j == 18: 11 to 138 zero length codes */ - { - ZIPNEEDBITS(7) - j = 11 + ((uint32_t)b & 0x7f); - ZIPDUMPBITS(7) - if ((uint32_t)i + j > n) - return 1; - while (j--) - ll[i++] = 0; - l = 0; - } - } - - /* free decoding table for trees */ - Ziphuft_free(tl); - - /* restore the global bit buffer */ - ZIP(bb) = b; - ZIP(bk) = k; - - /* build the decoding tables for literal/length and distance codes */ - bl = ZIPLBITS; - if((i = Ziphuft_build(decomp_state, ll, nl, 257, Zipcplens, Zipcplext, &tl, &bl)) != 0) - { - if(i == 1) - Ziphuft_free(tl); - return i; /* incomplete code set */ - } - bd = ZIPDBITS; - Ziphuft_build(decomp_state, ll + nl, nd, 0, Zipcpdist, Zipcpdext, &td, &bd); - - /* decompress until an end-of-block code */ - if(Zipinflate_codes(decomp_state, tl, td, bl, bd)) - return 1; - - /* free the decoding tables, return */ - Ziphuft_free(tl); - Ziphuft_free(td); - return 0; -} - -/* e == last block flag */ -static int32_t Zipinflate_block(struct decomp_state *decomp_state, int32_t *e) -{ /* decompress an inflated block */ - uint32_t t; /* block type */ - register uint32_t b; /* bit buffer */ - register uint32_t k; /* number of bits in bit buffer */ - - DEBUG(10,("Zipinflate_block\n")); - - /* make local bit buffer */ - b = ZIP(bb); - k = ZIP(bk); - - /* read in last block bit */ - ZIPNEEDBITS(1) - *e = (int32_t)b & 1; - ZIPDUMPBITS(1) - - /* read in block type */ - ZIPNEEDBITS(2) - t = (uint32_t)b & 3; - ZIPDUMPBITS(2) - - /* restore the global bit buffer */ - ZIP(bb) = b; - ZIP(bk) = k; - - DEBUG(10,("inflate type %d\n", t)); - - /* inflate that block type */ - if(t == 2) - return Zipinflate_dynamic(decomp_state); - if(t == 0) - return Zipinflate_stored(decomp_state); - if(t == 1) - return Zipinflate_fixed(decomp_state); - /* bad block type */ - return 2; -} - -_PUBLIC_ struct decomp_state *ZIPdecomp_state(TALLOC_CTX *mem_ctx) -{ - return talloc_zero(mem_ctx, struct decomp_state); -} - -int ZIPdecompress(struct decomp_state *decomp_state, DATA_BLOB *inbuf, DATA_BLOB *outbuf) -{ - int32_t e = 0;/* last block flag */ - - ZIP(inpos) = CAB(inbuf); - ZIP(bb) = ZIP(bk) = ZIP(window_posn) = 0; - - if (inbuf->length > sizeof(decomp_state->inbuf)) return DECR_INPUT; - - if (outbuf->length > sizeof(decomp_state->outbuf)) return DECR_OUTPUT; - - if (outbuf->length > ZIPWSIZE) return DECR_DATAFORMAT; - - memcpy(decomp_state->inbuf, inbuf->data, inbuf->length); - - /* CK = Chris Kirmse, official Microsoft purloiner */ - if (ZIP(inpos)[0] != 'C' || ZIP(inpos)[1] != 'K') return DECR_ILLEGALDATA; - ZIP(inpos) += 2; - - while (!e) { - if (Zipinflate_block(decomp_state, &e)) { - return DECR_ILLEGALDATA; - } - } - - memcpy(outbuf->data, decomp_state->outbuf, outbuf->length); - - return DECR_OK; -} diff --git a/source/lib/compression/mszip.h b/source/lib/compression/mszip.h deleted file mode 100644 index bb835f2595..0000000000 --- a/source/lib/compression/mszip.h +++ /dev/null @@ -1,33 +0,0 @@ -/* mszip decompression - based on cabextract.c code from - * Stuart Caie - * - * adapted for Samba by Andrew Tridgell and Stefan Metzmacher 2005 - * - * (C) 2000-2001 Stuart Caie <kyzer@4u.net> - * reaktivate-specifics by Malte Starostik <malte@kde.org> - * - * 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 <http://www.gnu.org/licenses/>. - */ - -struct decomp_state; -struct decomp_state *ZIPdecomp_state(TALLOC_CTX *mem_ctx); - -#define DECR_OK (0) -#define DECR_DATAFORMAT (1) -#define DECR_ILLEGALDATA (2) -#define DECR_NOMEMORY (3) -#define DECR_CHECKSUM (4) -#define DECR_INPUT (5) -#define DECR_OUTPUT (6) -int ZIPdecompress(struct decomp_state *decomp_state, DATA_BLOB *inbuf, DATA_BLOB *outbuf); diff --git a/source/lib/ctdbd_conn.c b/source/lib/ctdbd_conn.c index 1ae23bcf82..46936c5f39 100644 --- a/source/lib/ctdbd_conn.c +++ b/source/lib/ctdbd_conn.c @@ -43,7 +43,7 @@ struct ctdbd_connection { static NTSTATUS ctdbd_control(struct ctdbd_connection *conn, uint32_t vnn, uint32 opcode, - uint64_t srvid, uint32_t flags, TDB_DATA data, + uint64_t srvid, TDB_DATA data, TALLOC_CTX *mem_ctx, TDB_DATA *outdata, int *cstatus); @@ -83,7 +83,7 @@ static NTSTATUS register_with_ctdbd(struct ctdbd_connection *conn, int cstatus; return ctdbd_control(conn, CTDB_CURRENT_NODE, - CTDB_CONTROL_REGISTER_SRVID, srvid, 0, + CTDB_CONTROL_REGISTER_SRVID, srvid, tdb_null, NULL, NULL, &cstatus); } @@ -95,7 +95,7 @@ static NTSTATUS get_cluster_vnn(struct ctdbd_connection *conn, uint32 *vnn) int32_t cstatus=-1; NTSTATUS status; status = ctdbd_control(conn, - CTDB_CURRENT_NODE, CTDB_CONTROL_GET_PNN, 0, 0, + CTDB_CURRENT_NODE, CTDB_CONTROL_GET_PNN, 0, tdb_null, NULL, NULL, &cstatus); if (!NT_STATUS_IS_OK(status)) { cluster_fatal("ctdbd_control failed\n"); @@ -136,7 +136,7 @@ static NTSTATUS ctdbd_connect(TALLOC_CTX *mem_ctx, strncpy(addr.sun_path, sockname, sizeof(addr.sun_path)); if (sys_connect(fd, (struct sockaddr *)&addr) == -1) { - DEBUG(1, ("connect(%s) failed: %s\n", sockname, + DEBUG(0, ("connect(%s) failed: %s\n", sockname, strerror(errno))); close(fd); return map_nt_error_from_unix(errno); @@ -353,14 +353,6 @@ static NTSTATUS ctdb_read_req(struct ctdbd_connection *conn, uint32 reqid, goto next_pkt; } - if (msg->srvid == CTDB_SRVID_RECONFIGURE) { - DEBUG(0,("Got cluster reconfigure message in ctdb_read_req\n")); - messaging_send(conn->msg_ctx, procid_self(), - MSG_SMB_BRL_VALIDATE, &data_blob_null); - TALLOC_FREE(hdr); - goto next_pkt; - } - if (!(msg_state = TALLOC_P(NULL, struct deferred_msg_state))) { DEBUG(0, ("talloc failed\n")); TALLOC_FREE(hdr); @@ -688,8 +680,7 @@ NTSTATUS ctdbd_messaging_send(struct ctdbd_connection *conn, */ static NTSTATUS ctdbd_control(struct ctdbd_connection *conn, uint32_t vnn, uint32 opcode, - uint64_t srvid, uint32_t flags, - TDB_DATA data, + uint64_t srvid, TDB_DATA data, TALLOC_CTX *mem_ctx, TDB_DATA *outdata, int *cstatus) { @@ -698,9 +689,6 @@ static NTSTATUS ctdbd_control(struct ctdbd_connection *conn, struct ctdbd_connection *new_conn = NULL; NTSTATUS status; - /* the samba3 ctdb code can't handle NOREPLY yet */ - flags &= ~CTDB_CTRL_FLAG_NOREPLY; - if (conn == NULL) { status = ctdbd_init_connection(NULL, &new_conn); @@ -744,11 +732,6 @@ static NTSTATUS ctdbd_control(struct ctdbd_connection *conn, cluster_fatal("cluster dispatch daemon control write error\n"); } - if (flags & CTDB_CTRL_FLAG_NOREPLY) { - TALLOC_FREE(new_conn); - return NT_STATUS_OK; - } - status = ctdb_read_req(conn, req.hdr.reqid, NULL, (void *)&reply); if (!NT_STATUS_IS_OK(status)) { @@ -793,7 +776,7 @@ bool ctdbd_process_exists(struct ctdbd_connection *conn, uint32 vnn, pid_t pid) data.dptr = (uint8_t*)&pid; data.dsize = sizeof(pid); - status = ctdbd_control(conn, vnn, CTDB_CONTROL_PROCESS_EXISTS, 0, 0, + status = ctdbd_control(conn, vnn, CTDB_CONTROL_PROCESS_EXISTS, 0, data, NULL, NULL, &cstatus); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, (__location__ " ctdb_control for process_exists " @@ -818,7 +801,7 @@ char *ctdbd_dbpath(struct ctdbd_connection *conn, data.dsize = sizeof(db_id); status = ctdbd_control(conn, CTDB_CURRENT_NODE, - CTDB_CONTROL_GETDBPATH, 0, 0, data, + CTDB_CONTROL_GETDBPATH, 0, data, mem_ctx, &data, &cstatus); if (!NT_STATUS_IS_OK(status) || cstatus != 0) { DEBUG(0,(__location__ " ctdb_control for getdbpath failed\n")); @@ -846,7 +829,7 @@ NTSTATUS ctdbd_db_attach(struct ctdbd_connection *conn, persistent ? CTDB_CONTROL_DB_ATTACH_PERSISTENT : CTDB_CONTROL_DB_ATTACH, - 0, 0, data, NULL, &data, &cstatus); + 0, data, NULL, &data, &cstatus); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, (__location__ " ctdb_control for db_attach " "failed: %s\n", nt_errstr(status))); @@ -869,7 +852,7 @@ NTSTATUS ctdbd_db_attach(struct ctdbd_connection *conn, data.dsize = sizeof(*db_id); status = ctdbd_control(conn, CTDB_CURRENT_NODE, - CTDB_CONTROL_ENABLE_SEQNUM, 0, 0, data, + CTDB_CONTROL_ENABLE_SEQNUM, 0, data, NULL, NULL, &cstatus); if (!NT_STATUS_IS_OK(status) || cstatus != 0) { DEBUG(0,(__location__ " ctdb_control for enable seqnum " @@ -1104,7 +1087,7 @@ NTSTATUS ctdbd_traverse(uint32 db_id, data.dsize = sizeof(t); status = ctdbd_control(conn, CTDB_CURRENT_NODE, - CTDB_CONTROL_TRAVERSE_START, conn->rand_srvid, 0, + CTDB_CONTROL_TRAVERSE_START, conn->rand_srvid, data, NULL, NULL, &cstatus); if (!NT_STATUS_IS_OK(status) || (cstatus != 0)) { @@ -1190,8 +1173,6 @@ NTSTATUS ctdbd_register_ips(struct ctdbd_connection *conn, */ SMB_ASSERT(conn->release_ip_handler == NULL); - conn->release_ip_handler = release_ip_handler; - /* * We want to be told about IP releases */ @@ -1213,7 +1194,7 @@ NTSTATUS ctdbd_register_ips(struct ctdbd_connection *conn, data.dsize = sizeof(p); return ctdbd_control(conn, CTDB_CURRENT_NODE, - CTDB_CONTROL_TCP_CLIENT, 0, + CTDB_CONTROL_TCP_CLIENT, CTDB_CTRL_FLAG_NOREPLY, data, NULL, NULL, NULL); } @@ -1226,16 +1207,41 @@ NTSTATUS ctdbd_register_reconfigure(struct ctdbd_connection *conn) } /* - call a control on the local node + persstent store. Used when we update a record in a persistent database */ -NTSTATUS ctdbd_control_local(struct ctdbd_connection *conn, uint32 opcode, - uint64_t srvid, uint32_t flags, TDB_DATA data, - TALLOC_CTX *mem_ctx, TDB_DATA *outdata, - int *cstatus) +NTSTATUS ctdbd_persistent_store(struct ctdbd_connection *conn, uint32_t db_id, TDB_DATA key, TDB_DATA data) { - return ctdbd_control(conn, CTDB_CURRENT_NODE, opcode, srvid, flags, data, mem_ctx, outdata, cstatus); + int cstatus=0; + struct ctdb_rec_data *rec; + TDB_DATA recdata; + size_t length; + NTSTATUS status; + + length = offsetof(struct ctdb_rec_data, data) + key.dsize + data.dsize; + + rec = (struct ctdb_rec_data *)talloc_size(conn, length); + NT_STATUS_HAVE_NO_MEMORY(rec); + + rec->length = length; + rec->reqid = db_id; + rec->keylen = key.dsize; + rec->datalen= data.dsize; + memcpy(&rec->data[0], key.dptr, key.dsize); + memcpy(&rec->data[key.dsize], data.dptr, data.dsize); + + recdata.dptr = (uint8_t *)rec; + recdata.dsize = length; + + status = ctdbd_control(conn, CTDB_CURRENT_NODE, + CTDB_CONTROL_PERSISTENT_STORE, + 0, recdata, NULL, NULL, &cstatus); + if (cstatus != 0) { + return NT_STATUS_INTERNAL_DB_CORRUPTION; + } + return status; } + #else NTSTATUS ctdbd_init_connection(TALLOC_CTX *mem_ctx, diff --git a/source/lib/data_blob.c b/source/lib/data_blob.c index 66c5daf363..daba17df14 100644 --- a/source/lib/data_blob.c +++ b/source/lib/data_blob.c @@ -156,25 +156,3 @@ DATA_BLOB data_blob_talloc_zero(TALLOC_CTX *mem_ctx, size_t length) data_blob_clear(&blob); return blob; } - -/** -print the data_blob as hex string -**/ -_PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob) -{ - int i; - char *hex_string; - - hex_string = talloc_array(mem_ctx, char, (blob->length*2)+1); - if (!hex_string) { - return NULL; - } - - for (i = 0; i < blob->length; i++) - slprintf(&hex_string[i*2], 3, "%02X", blob->data[i]); - - hex_string[(blob->length*2)] = '\0'; - return hex_string; -} - - diff --git a/source/lib/dbwrap.c b/source/lib/dbwrap.c index 73c2761a1b..7fe1631bff 100644 --- a/source/lib/dbwrap.c +++ b/source/lib/dbwrap.c @@ -43,7 +43,7 @@ static int dbwrap_fallback_fetch(struct db_context *db, TALLOC_CTX *mem_ctx, } /** - * open a database + * If you need transaction support use db_open_trans() */ struct db_context *db_open(TALLOC_CTX *mem_ctx, const char *name, @@ -60,15 +60,8 @@ struct db_context *db_open(TALLOC_CTX *mem_ctx, sockname = CTDB_PATH; } - if (lp_clustering()) { + if (lp_clustering() && socket_exist(sockname)) { const char *partname; - - if (!socket_exist(sockname)) { - DEBUG(1, ("ctdb socket does not exist - is ctdb not " - "running?\n")); - return NULL; - } - /* ctdb only wants the file part of the name */ partname = strrchr(name, '/'); if (partname) { @@ -83,10 +76,8 @@ struct db_context *db_open(TALLOC_CTX *mem_ctx, if (result == NULL) { DEBUG(0,("failed to attach to ctdb %s\n", partname)); - if (errno == 0) { - errno = EIO; - } - return NULL; + smb_panic("failed to attach to a ctdb " + "database"); } } } @@ -105,6 +96,75 @@ struct db_context *db_open(TALLOC_CTX *mem_ctx, return result; } +/** + * If you use this you can only modify with a transaction + */ +struct db_context *db_open_trans(TALLOC_CTX *mem_ctx, + const char *name, + int hash_size, int tdb_flags, + int open_flags, mode_t mode) +{ + bool use_tdb2 = lp_parm_bool(-1, "dbwrap", "use_tdb2", false); +#ifdef CLUSTER_SUPPORT + const char *sockname = lp_ctdbd_socket(); +#endif + + if (tdb_flags & TDB_CLEAR_IF_FIRST) { + DEBUG(0,("db_open_trans: called with TDB_CLEAR_IF_FIRST: %s\n", + name)); + smb_panic("db_open_trans: called with TDB_CLEAR_IF_FIRST"); + } + +#ifdef CLUSTER_SUPPORT + if(!sockname || !*sockname) { + sockname = CTDB_PATH; + } + + if (lp_clustering() && socket_exist(sockname)) { + const char *partname; + /* ctdb only wants the file part of the name */ + partname = strrchr(name, '/'); + if (partname) { + partname++; + } else { + partname = name; + } + /* allow ctdb for individual databases to be disabled */ + if (lp_parm_bool(-1, "ctdb", partname, true)) { + struct db_context *result = NULL; + result = db_open_ctdb(mem_ctx, partname, hash_size, + tdb_flags, open_flags, mode); + if (result == NULL) { + DEBUG(0,("failed to attach to ctdb %s\n", + partname)); + smb_panic("failed to attach to a ctdb " + "database"); + } + return result; + } + } +#endif + + if (use_tdb2) { + const char *partname; + /* tdb2 only wants the file part of the name */ + partname = strrchr(name, '/'); + if (partname) { + partname++; + } else { + partname = name; + } + /* allow ctdb for individual databases to be disabled */ + if (lp_parm_bool(-1, "tdb2", partname, true)) { + return db_open_tdb2(mem_ctx, partname, hash_size, + tdb_flags, open_flags, mode); + } + } + + return db_open_tdb(mem_ctx, name, hash_size, + tdb_flags, open_flags, mode); +} + NTSTATUS dbwrap_delete_bystring(struct db_context *db, const char *key) { struct db_record *rec; diff --git a/source/lib/dbwrap_ctdb.c b/source/lib/dbwrap_ctdb.c index 1e3a97f065..cb4c573eb0 100644 --- a/source/lib/dbwrap_ctdb.c +++ b/source/lib/dbwrap_ctdb.c @@ -23,23 +23,9 @@ #include "ctdb_private.h" #include "ctdbd_conn.h" -struct db_ctdb_transaction_handle { - struct db_ctdb_ctx *ctx; - bool in_replay; - /* we store the reads and writes done under a transaction one - list stores both reads and writes, the other just writes - */ - struct ctdb_marshall_buffer *m_all; - struct ctdb_marshall_buffer *m_write; - uint32_t nesting; - bool nested_cancel; -}; - struct db_ctdb_ctx { - struct db_context *db; struct tdb_wrap *wtdb; uint32 db_id; - struct db_ctdb_transaction_handle *transaction; }; struct db_ctdb_rec { @@ -47,734 +33,40 @@ struct db_ctdb_rec { struct ctdb_ltdb_header header; }; -static struct db_record *fetch_locked_internal(struct db_ctdb_ctx *ctx, - TALLOC_CTX *mem_ctx, - TDB_DATA key, - bool persistent); - -static NTSTATUS tdb_error_to_ntstatus(struct tdb_context *tdb) -{ - NTSTATUS status; - enum TDB_ERROR tret = tdb_error(tdb); - - switch (tret) { - case TDB_ERR_EXISTS: - status = NT_STATUS_OBJECT_NAME_COLLISION; - break; - case TDB_ERR_NOEXIST: - status = NT_STATUS_OBJECT_NAME_NOT_FOUND; - break; - default: - status = NT_STATUS_INTERNAL_DB_CORRUPTION; - break; - } - - return status; -} - - - -/* - form a ctdb_rec_data record from a key/data pair - - note that header may be NULL. If not NULL then it is included in the data portion - of the record - */ -static struct ctdb_rec_data *db_ctdb_marshall_record(TALLOC_CTX *mem_ctx, uint32_t reqid, - TDB_DATA key, - struct ctdb_ltdb_header *header, - TDB_DATA data) -{ - size_t length; - struct ctdb_rec_data *d; - - length = offsetof(struct ctdb_rec_data, data) + key.dsize + - data.dsize + (header?sizeof(*header):0); - d = (struct ctdb_rec_data *)talloc_size(mem_ctx, length); - if (d == NULL) { - return NULL; - } - d->length = length; - d->reqid = reqid; - d->keylen = key.dsize; - memcpy(&d->data[0], key.dptr, key.dsize); - if (header) { - d->datalen = data.dsize + sizeof(*header); - memcpy(&d->data[key.dsize], header, sizeof(*header)); - memcpy(&d->data[key.dsize+sizeof(*header)], data.dptr, data.dsize); - } else { - d->datalen = data.dsize; - memcpy(&d->data[key.dsize], data.dptr, data.dsize); - } - return d; -} - - -/* helper function for marshalling multiple records */ -static struct ctdb_marshall_buffer *db_ctdb_marshall_add(TALLOC_CTX *mem_ctx, - struct ctdb_marshall_buffer *m, - uint64_t db_id, - uint32_t reqid, - TDB_DATA key, - struct ctdb_ltdb_header *header, - TDB_DATA data) -{ - struct ctdb_rec_data *r; - size_t m_size, r_size; - struct ctdb_marshall_buffer *m2; - - r = db_ctdb_marshall_record(mem_ctx, reqid, key, header, data); - if (r == NULL) { - talloc_free(m); - return NULL; - } - - if (m == NULL) { - m = talloc_zero_size(mem_ctx, offsetof(struct ctdb_marshall_buffer, data)); - if (m == NULL) { - return NULL; - } - m->db_id = db_id; - } - - m_size = talloc_get_size(m); - r_size = talloc_get_size(r); - - m2 = talloc_realloc_size(mem_ctx, m, m_size + r_size); - if (m2 == NULL) { - talloc_free(m); - return NULL; - } - - memcpy(m_size + (uint8_t *)m2, r, r_size); - - talloc_free(r); - - m2->count++; - - return m2; -} - -/* we've finished marshalling, return a data blob with the marshalled records */ -static TDB_DATA db_ctdb_marshall_finish(struct ctdb_marshall_buffer *m) -{ - TDB_DATA data; - data.dptr = (uint8_t *)m; - data.dsize = talloc_get_size(m); - return data; -} - -/* - loop over a marshalling buffer - - - pass r==NULL to start - - loop the number of times indicated by m->count -*/ -static struct ctdb_rec_data *db_ctdb_marshall_loop_next(struct ctdb_marshall_buffer *m, struct ctdb_rec_data *r, - uint32_t *reqid, - struct ctdb_ltdb_header *header, - TDB_DATA *key, TDB_DATA *data) -{ - if (r == NULL) { - r = (struct ctdb_rec_data *)&m->data[0]; - } else { - r = (struct ctdb_rec_data *)(r->length + (uint8_t *)r); - } - - if (reqid != NULL) { - *reqid = r->reqid; - } - - if (key != NULL) { - key->dptr = &r->data[0]; - key->dsize = r->keylen; - } - if (data != NULL) { - data->dptr = &r->data[r->keylen]; - data->dsize = r->datalen; - if (header != NULL) { - data->dptr += sizeof(*header); - data->dsize -= sizeof(*header); - } - } - - if (header != NULL) { - if (r->datalen < sizeof(*header)) { - return NULL; - } - *header = *(struct ctdb_ltdb_header *)&r->data[r->keylen]; - } - - return r; -} - - - -/* start a transaction on a database */ -static int db_ctdb_transaction_destructor(struct db_ctdb_transaction_handle *h) -{ - tdb_transaction_cancel(h->ctx->wtdb->tdb); - return 0; -} - -/* start a transaction on a database */ -static int db_ctdb_transaction_fetch_start(struct db_ctdb_transaction_handle *h) -{ - struct db_record *rh; - TDB_DATA key; - TALLOC_CTX *tmp_ctx; - const char *keyname = CTDB_TRANSACTION_LOCK_KEY; - int ret; - struct db_ctdb_ctx *ctx = h->ctx; - TDB_DATA data; - - key.dptr = discard_const(keyname); - key.dsize = strlen(keyname); - -again: - tmp_ctx = talloc_new(h); - - rh = fetch_locked_internal(ctx, tmp_ctx, key, true); - if (rh == NULL) { - DEBUG(0,(__location__ " Failed to fetch_lock database\n")); - talloc_free(tmp_ctx); - return -1; - } - talloc_free(rh); - - ret = tdb_transaction_start(ctx->wtdb->tdb); - if (ret != 0) { - DEBUG(0,(__location__ " Failed to start tdb transaction\n")); - talloc_free(tmp_ctx); - return -1; - } - - data = tdb_fetch(ctx->wtdb->tdb, key); - if ((data.dptr == NULL) || - (data.dsize < sizeof(struct ctdb_ltdb_header)) || - ((struct ctdb_ltdb_header *)data.dptr)->dmaster != get_my_vnn()) { - SAFE_FREE(data.dptr); - tdb_transaction_cancel(ctx->wtdb->tdb); - talloc_free(tmp_ctx); - goto again; - } - - SAFE_FREE(data.dptr); - talloc_free(tmp_ctx); - - return 0; -} - - -/* start a transaction on a database */ -static int db_ctdb_transaction_start(struct db_context *db) -{ - struct db_ctdb_transaction_handle *h; - int ret; - struct db_ctdb_ctx *ctx = talloc_get_type_abort(db->private_data, - struct db_ctdb_ctx); - - if (!db->persistent) { - DEBUG(0,("transactions not supported on non-persistent database 0x%08x\n", - ctx->db_id)); - return -1; - } - - if (ctx->transaction) { - ctx->transaction->nesting++; - return 0; - } - - h = talloc_zero(db, struct db_ctdb_transaction_handle); - if (h == NULL) { - DEBUG(0,(__location__ " oom for transaction handle\n")); - return -1; - } - - h->ctx = ctx; - - ret = db_ctdb_transaction_fetch_start(h); - if (ret != 0) { - talloc_free(h); - return -1; - } - - talloc_set_destructor(h, db_ctdb_transaction_destructor); - - ctx->transaction = h; - - DEBUG(5,(__location__ " Started transaction on db 0x%08x\n", ctx->db_id)); - - return 0; -} - - - -/* - fetch a record inside a transaction - */ -static int db_ctdb_transaction_fetch(struct db_ctdb_ctx *db, - TALLOC_CTX *mem_ctx, - TDB_DATA key, TDB_DATA *data) -{ - struct db_ctdb_transaction_handle *h = db->transaction; - - *data = tdb_fetch(h->ctx->wtdb->tdb, key); - - if (data->dptr != NULL) { - uint8_t *oldptr = (uint8_t *)data->dptr; - data->dsize -= sizeof(struct ctdb_ltdb_header); - if (data->dsize == 0) { - data->dptr = NULL; - } else { - data->dptr = (uint8 *) - talloc_memdup( - mem_ctx, data->dptr+sizeof(struct ctdb_ltdb_header), - data->dsize); - } - SAFE_FREE(oldptr); - if (data->dptr == NULL && data->dsize != 0) { - return -1; - } - } - - if (!h->in_replay) { - h->m_all = db_ctdb_marshall_add(h, h->m_all, h->ctx->db_id, 1, key, NULL, *data); - if (h->m_all == NULL) { - DEBUG(0,(__location__ " Failed to add to marshalling record\n")); - data->dsize = 0; - talloc_free(data->dptr); - return -1; - } - } - - return 0; -} - - -static NTSTATUS db_ctdb_store_transaction(struct db_record *rec, TDB_DATA data, int flag); -static NTSTATUS db_ctdb_delete_transaction(struct db_record *rec); - -static struct db_record *db_ctdb_fetch_locked_transaction(struct db_ctdb_ctx *ctx, - TALLOC_CTX *mem_ctx, - TDB_DATA key) -{ - struct db_record *result; - TDB_DATA ctdb_data; - - if (!(result = talloc(mem_ctx, struct db_record))) { - DEBUG(0, ("talloc failed\n")); - return NULL; - } - - result->private_data = ctx->transaction; - - result->key.dsize = key.dsize; - result->key.dptr = (uint8 *)talloc_memdup(result, key.dptr, key.dsize); - if (result->key.dptr == NULL) { - DEBUG(0, ("talloc failed\n")); - TALLOC_FREE(result); - return NULL; - } - - result->store = db_ctdb_store_transaction; - result->delete_rec = db_ctdb_delete_transaction; - - ctdb_data = tdb_fetch(ctx->wtdb->tdb, key); - if (ctdb_data.dptr == NULL) { - /* create the record */ - result->value = tdb_null; - return result; - } - - result->value.dsize = ctdb_data.dsize - sizeof(struct ctdb_ltdb_header); - result->value.dptr = NULL; - - if ((result->value.dsize != 0) - && !(result->value.dptr = (uint8 *)talloc_memdup( - result, ctdb_data.dptr + sizeof(struct ctdb_ltdb_header), - result->value.dsize))) { - DEBUG(0, ("talloc failed\n")); - TALLOC_FREE(result); - } - - SAFE_FREE(ctdb_data.dptr); - - return result; -} - -static int db_ctdb_record_destructor(struct db_record **recp) -{ - struct db_record *rec = talloc_get_type_abort(*recp, struct db_record); - struct db_ctdb_transaction_handle *h = talloc_get_type_abort( - rec->private_data, struct db_ctdb_transaction_handle); - int ret = h->ctx->db->transaction_commit(h->ctx->db); - if (ret != 0) { - DEBUG(0,(__location__ " transaction_commit failed\n")); - } - return 0; -} - -/* - auto-create a transaction for persistent databases - */ -static struct db_record *db_ctdb_fetch_locked_persistent(struct db_ctdb_ctx *ctx, - TALLOC_CTX *mem_ctx, - TDB_DATA key) -{ - int res; - struct db_record *rec, **recp; - - res = db_ctdb_transaction_start(ctx->db); - if (res == -1) { - return NULL; - } - - rec = db_ctdb_fetch_locked_transaction(ctx, mem_ctx, key); - if (rec == NULL) { - ctx->db->transaction_cancel(ctx->db); - return NULL; - } - - /* destroy this transaction when we release the lock */ - recp = talloc(rec, struct db_record *); - if (recp == NULL) { - ctx->db->transaction_cancel(ctx->db); - talloc_free(rec); - return NULL; - } - *recp = rec; - talloc_set_destructor(recp, db_ctdb_record_destructor); - return rec; -} - - -/* - stores a record inside a transaction - */ -static int db_ctdb_transaction_store(struct db_ctdb_transaction_handle *h, - TDB_DATA key, TDB_DATA data) -{ - TALLOC_CTX *tmp_ctx = talloc_new(h); - int ret; - TDB_DATA rec; - struct ctdb_ltdb_header header; - - /* we need the header so we can update the RSN */ - rec = tdb_fetch(h->ctx->wtdb->tdb, key); - if (rec.dptr == NULL) { - /* the record doesn't exist - create one with us as dmaster. - This is only safe because we are in a transaction and this - is a persistent database */ - ZERO_STRUCT(header); - header.dmaster = get_my_vnn(); - } else { - memcpy(&header, rec.dptr, sizeof(struct ctdb_ltdb_header)); - rec.dsize -= sizeof(struct ctdb_ltdb_header); - /* a special case, we are writing the same data that is there now */ - if (data.dsize == rec.dsize && - memcmp(data.dptr, rec.dptr + sizeof(struct ctdb_ltdb_header), data.dsize) == 0) { - SAFE_FREE(rec.dptr); - talloc_free(tmp_ctx); - return 0; - } - SAFE_FREE(rec.dptr); - } - - header.rsn++; - - if (!h->in_replay) { - h->m_all = db_ctdb_marshall_add(h, h->m_all, h->ctx->db_id, 0, key, NULL, data); - if (h->m_all == NULL) { - DEBUG(0,(__location__ " Failed to add to marshalling record\n")); - talloc_free(tmp_ctx); - return -1; - } - } - - h->m_write = db_ctdb_marshall_add(h, h->m_write, h->ctx->db_id, 0, key, &header, data); - if (h->m_write == NULL) { - DEBUG(0,(__location__ " Failed to add to marshalling record\n")); - talloc_free(tmp_ctx); - return -1; - } - - rec.dsize = data.dsize + sizeof(struct ctdb_ltdb_header); - rec.dptr = talloc_size(tmp_ctx, rec.dsize); - if (rec.dptr == NULL) { - DEBUG(0,(__location__ " Failed to alloc record\n")); - talloc_free(tmp_ctx); - return -1; - } - memcpy(rec.dptr, &header, sizeof(struct ctdb_ltdb_header)); - memcpy(sizeof(struct ctdb_ltdb_header) + (uint8_t *)rec.dptr, data.dptr, data.dsize); - - ret = tdb_store(h->ctx->wtdb->tdb, key, rec, TDB_REPLACE); - - talloc_free(tmp_ctx); - - return ret; -} - - -/* - a record store inside a transaction - */ -static NTSTATUS db_ctdb_store_transaction(struct db_record *rec, TDB_DATA data, int flag) -{ - struct db_ctdb_transaction_handle *h = talloc_get_type_abort( - rec->private_data, struct db_ctdb_transaction_handle); - int ret; - - ret = db_ctdb_transaction_store(h, rec->key, data); - if (ret != 0) { - return tdb_error_to_ntstatus(h->ctx->wtdb->tdb); - } - return NT_STATUS_OK; -} - -/* - a record delete inside a transaction - */ -static NTSTATUS db_ctdb_delete_transaction(struct db_record *rec) -{ - struct db_ctdb_transaction_handle *h = talloc_get_type_abort( - rec->private_data, struct db_ctdb_transaction_handle); - int ret; - - ret = db_ctdb_transaction_store(h, rec->key, tdb_null); - if (ret != 0) { - return tdb_error_to_ntstatus(h->ctx->wtdb->tdb); - } - return NT_STATUS_OK; -} - - -/* - replay a transaction - */ -static int ctdb_replay_transaction(struct db_ctdb_transaction_handle *h) -{ - int ret, i; - struct ctdb_rec_data *rec = NULL; - - h->in_replay = true; - talloc_free(h->m_write); - h->m_write = NULL; - - ret = db_ctdb_transaction_fetch_start(h); - if (ret != 0) { - return ret; - } - - for (i=0;i<h->m_all->count;i++) { - TDB_DATA key, data; - - rec = db_ctdb_marshall_loop_next(h->m_all, rec, NULL, NULL, &key, &data); - if (rec == NULL) { - DEBUG(0, (__location__ " Out of records in ctdb_replay_transaction?\n")); - goto failed; - } - - if (rec->reqid == 0) { - /* its a store */ - if (db_ctdb_transaction_store(h, key, data) != 0) { - goto failed; - } - } else { - TDB_DATA data2; - TALLOC_CTX *tmp_ctx = talloc_new(h); - - if (db_ctdb_transaction_fetch(h->ctx, tmp_ctx, key, &data2) != 0) { - talloc_free(tmp_ctx); - goto failed; - } - if (data2.dsize != data.dsize || - memcmp(data2.dptr, data.dptr, data.dsize) != 0) { - /* the record has changed on us - we have to give up */ - talloc_free(tmp_ctx); - goto failed; - } - talloc_free(tmp_ctx); - } - } - - return 0; - -failed: - tdb_transaction_cancel(h->ctx->wtdb->tdb); - return -1; -} - - -/* - commit a transaction - */ -static int db_ctdb_transaction_commit(struct db_context *db) +static NTSTATUS db_ctdb_store(struct db_record *rec, TDB_DATA data, int flag) { - struct db_ctdb_ctx *ctx = talloc_get_type_abort(db->private_data, - struct db_ctdb_ctx); - NTSTATUS rets; + struct db_ctdb_rec *crec = talloc_get_type_abort( + rec->private_data, struct db_ctdb_rec); + TDB_DATA cdata; int ret; - int status; - int retries = 0; - struct db_ctdb_transaction_handle *h = ctx->transaction; - enum ctdb_controls failure_control = CTDB_CONTROL_TRANS2_ERROR; - - if (h == NULL) { - DEBUG(0,(__location__ " transaction commit with no open transaction on db 0x%08x\n", ctx->db_id)); - return -1; - } - if (h->nested_cancel) { - db->transaction_cancel(db); - DEBUG(5,(__location__ " Failed transaction commit after nested cancel\n")); - return -1; - } - - if (h->nesting != 0) { - h->nesting--; - return 0; - } - - DEBUG(5,(__location__ " Commit transaction on db 0x%08x\n", ctx->db_id)); - - talloc_set_destructor(h, NULL); - - /* our commit strategy is quite complex. - - - we first try to commit the changes to all other nodes - - - if that works, then we commit locally and we are done - - - if a commit on another node fails, then we need to cancel - the transaction, then restart the transaction (thus - opening a window of time for a pending recovery to - complete), then replay the transaction, checking all the - reads and writes (checking that reads give the same data, - and writes succeed). Then we retry the transaction to the - other nodes - */ - -again: - if (h->m_write == NULL) { - /* no changes were made, potentially after a retry */ - tdb_transaction_cancel(h->ctx->wtdb->tdb); - talloc_free(h); - ctx->transaction = NULL; - return 0; - } - - /* tell ctdbd to commit to the other nodes */ - rets = ctdbd_control_local(messaging_ctdbd_connection(), - retries==0?CTDB_CONTROL_TRANS2_COMMIT:CTDB_CONTROL_TRANS2_COMMIT_RETRY, - h->ctx->db_id, 0, - db_ctdb_marshall_finish(h->m_write), NULL, NULL, &status); - if (!NT_STATUS_IS_OK(rets) || status != 0) { - tdb_transaction_cancel(h->ctx->wtdb->tdb); - sleep(1); - - if (!NT_STATUS_IS_OK(rets)) { - failure_control = CTDB_CONTROL_TRANS2_ERROR; - } else { - /* work out what error code we will give if we - have to fail the operation */ - switch ((enum ctdb_trans2_commit_error)status) { - case CTDB_TRANS2_COMMIT_SUCCESS: - case CTDB_TRANS2_COMMIT_SOMEFAIL: - case CTDB_TRANS2_COMMIT_TIMEOUT: - failure_control = CTDB_CONTROL_TRANS2_ERROR; - break; - case CTDB_TRANS2_COMMIT_ALLFAIL: - failure_control = CTDB_CONTROL_TRANS2_FINISHED; - break; - } - } - - if (++retries == 5) { - DEBUG(0,(__location__ " Giving up transaction on db 0x%08x after %d retries failure_control=%u\n", - h->ctx->db_id, retries, (unsigned)failure_control)); - ctdbd_control_local(messaging_ctdbd_connection(), failure_control, - h->ctx->db_id, CTDB_CTRL_FLAG_NOREPLY, - tdb_null, NULL, NULL, NULL); - h->ctx->transaction = NULL; - talloc_free(h); - ctx->transaction = NULL; - return -1; - } - - if (ctdb_replay_transaction(h) != 0) { - DEBUG(0,(__location__ " Failed to replay transaction failure_control=%u\n", - (unsigned)failure_control)); - ctdbd_control_local(messaging_ctdbd_connection(), failure_control, - h->ctx->db_id, CTDB_CTRL_FLAG_NOREPLY, - tdb_null, NULL, NULL, NULL); - h->ctx->transaction = NULL; - talloc_free(h); - ctx->transaction = NULL; - return -1; - } - goto again; - } else { - failure_control = CTDB_CONTROL_TRANS2_ERROR; - } + cdata.dsize = sizeof(crec->header) + data.dsize; - /* do the real commit locally */ - ret = tdb_transaction_commit(h->ctx->wtdb->tdb); - if (ret != 0) { - DEBUG(0,(__location__ " Failed to commit transaction failure_control=%u\n", - (unsigned)failure_control)); - ctdbd_control_local(messaging_ctdbd_connection(), failure_control, h->ctx->db_id, - CTDB_CTRL_FLAG_NOREPLY, tdb_null, NULL, NULL, NULL); - h->ctx->transaction = NULL; - talloc_free(h); - return ret; + if (!(cdata.dptr = SMB_MALLOC_ARRAY(uint8, cdata.dsize))) { + return NT_STATUS_NO_MEMORY; } - /* tell ctdbd that we are finished with our local commit */ - ctdbd_control_local(messaging_ctdbd_connection(), CTDB_CONTROL_TRANS2_FINISHED, - h->ctx->db_id, CTDB_CTRL_FLAG_NOREPLY, - tdb_null, NULL, NULL, NULL); - h->ctx->transaction = NULL; - talloc_free(h); - return 0; -} - - -/* - cancel a transaction - */ -static int db_ctdb_transaction_cancel(struct db_context *db) -{ - struct db_ctdb_ctx *ctx = talloc_get_type_abort(db->private_data, - struct db_ctdb_ctx); - struct db_ctdb_transaction_handle *h = ctx->transaction; - - if (h == NULL) { - DEBUG(0,(__location__ " transaction cancel with no open transaction on db 0x%08x\n", ctx->db_id)); - return -1; - } + memcpy(cdata.dptr, &crec->header, sizeof(crec->header)); + memcpy(cdata.dptr + sizeof(crec->header), data.dptr, data.dsize); - if (h->nesting != 0) { - h->nesting--; - h->nested_cancel = true; - return 0; - } + ret = tdb_store(crec->ctdb_ctx->wtdb->tdb, rec->key, cdata, TDB_REPLACE); - DEBUG(5,(__location__ " Cancel transaction on db 0x%08x\n", ctx->db_id)); + SAFE_FREE(cdata.dptr); - ctx->transaction = NULL; - talloc_free(h); - return 0; + return (ret == 0) ? NT_STATUS_OK : NT_STATUS_INTERNAL_DB_CORRUPTION; } -static NTSTATUS db_ctdb_store(struct db_record *rec, TDB_DATA data, int flag) +/* for persistent databases the store is a bit different. We have to + ask the ctdb daemon to push the record to all nodes after the + store */ +static NTSTATUS db_ctdb_store_persistent(struct db_record *rec, TDB_DATA data, int flag) { struct db_ctdb_rec *crec = talloc_get_type_abort( rec->private_data, struct db_ctdb_rec); TDB_DATA cdata; int ret; + NTSTATUS status; cdata.dsize = sizeof(crec->header) + data.dsize; @@ -782,32 +74,42 @@ static NTSTATUS db_ctdb_store(struct db_record *rec, TDB_DATA data, int flag) return NT_STATUS_NO_MEMORY; } + crec->header.rsn++; + memcpy(cdata.dptr, &crec->header, sizeof(crec->header)); memcpy(cdata.dptr + sizeof(crec->header), data.dptr, data.dsize); ret = tdb_store(crec->ctdb_ctx->wtdb->tdb, rec->key, cdata, TDB_REPLACE); + status = (ret == 0) ? NT_STATUS_OK : NT_STATUS_INTERNAL_DB_CORRUPTION; + + /* now tell ctdbd to update this record on all other nodes */ + if (NT_STATUS_IS_OK(status)) { + status = ctdbd_persistent_store(messaging_ctdbd_connection(), crec->ctdb_ctx->db_id, rec->key, cdata); + } SAFE_FREE(cdata.dptr); - return (ret == 0) ? NT_STATUS_OK - : tdb_error_to_ntstatus(crec->ctdb_ctx->wtdb->tdb); + return status; } - - static NTSTATUS db_ctdb_delete(struct db_record *rec) { + struct db_ctdb_rec *crec = talloc_get_type_abort( + rec->private_data, struct db_ctdb_rec); TDB_DATA data; + int ret; /* * We have to store the header with empty data. TODO: Fix the * tdb-level cleanup */ - ZERO_STRUCT(data); + data.dptr = (uint8 *)&crec->header; + data.dsize = sizeof(crec->header); - return db_ctdb_store(rec, data, 0); + ret = tdb_store(crec->ctdb_ctx->wtdb->tdb, rec->key, data, TDB_REPLACE); + return (ret == 0) ? NT_STATUS_OK : NT_STATUS_INTERNAL_DB_CORRUPTION; } static int db_ctdb_record_destr(struct db_record* data) @@ -830,11 +132,12 @@ static int db_ctdb_record_destr(struct db_record* data) return 0; } -static struct db_record *fetch_locked_internal(struct db_ctdb_ctx *ctx, - TALLOC_CTX *mem_ctx, - TDB_DATA key, - bool persistent) +static struct db_record *db_ctdb_fetch_locked(struct db_context *db, + TALLOC_CTX *mem_ctx, + TDB_DATA key) { + struct db_ctdb_ctx *ctx = talloc_get_type_abort(db->private_data, + struct db_ctdb_ctx); struct db_record *result; struct db_ctdb_rec *crec; NTSTATUS status; @@ -883,7 +186,11 @@ again: return NULL; } - result->store = db_ctdb_store; + if (db->persistent) { + result->store = db_ctdb_store_persistent; + } else { + result->store = db_ctdb_store; + } result->delete_rec = db_ctdb_delete; talloc_set_destructor(result, db_ctdb_record_destr); @@ -946,24 +253,6 @@ again: return result; } -static struct db_record *db_ctdb_fetch_locked(struct db_context *db, - TALLOC_CTX *mem_ctx, - TDB_DATA key) -{ - struct db_ctdb_ctx *ctx = talloc_get_type_abort(db->private_data, - struct db_ctdb_ctx); - - if (ctx->transaction != NULL) { - return db_ctdb_fetch_locked_transaction(ctx, mem_ctx, key); - } - - if (db->persistent) { - return db_ctdb_fetch_locked_persistent(ctx, mem_ctx, key); - } - - return fetch_locked_internal(ctx, mem_ctx, key, db->persistent); -} - /* fetch (unlocked, no migration) operation on ctdb */ @@ -975,10 +264,6 @@ static int db_ctdb_fetch(struct db_context *db, TALLOC_CTX *mem_ctx, NTSTATUS status; TDB_DATA ctdb_data; - if (ctx->transaction) { - return db_ctdb_transaction_fetch(ctx, mem_ctx, key, data); - } - /* try a direct fetch */ ctdb_data = tdb_fetch(ctx->wtdb->tdb, key); @@ -1156,6 +441,14 @@ static int db_ctdb_get_seqnum(struct db_context *db) return tdb_get_seqnum(ctx->wtdb->tdb); } +static int db_ctdb_trans_dummy(struct db_context *db) +{ + /* + * Not implemented yet, just return ok + */ + return 0; +} + struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx, const char *name, int hash_size, int tdb_flags, @@ -1182,9 +475,6 @@ struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx, return NULL; } - db_ctdb->transaction = NULL; - db_ctdb->db = result; - if (!NT_STATUS_IS_OK(ctdbd_db_attach(messaging_ctdbd_connection(),name, &db_ctdb->db_id, tdb_flags))) { DEBUG(0, ("ctdbd_db_attach failed for %s\n", name)); TALLOC_FREE(result); @@ -1217,9 +507,9 @@ struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx, result->traverse = db_ctdb_traverse; result->traverse_read = db_ctdb_traverse_read; result->get_seqnum = db_ctdb_get_seqnum; - result->transaction_start = db_ctdb_transaction_start; - result->transaction_commit = db_ctdb_transaction_commit; - result->transaction_cancel = db_ctdb_transaction_cancel; + result->transaction_start = db_ctdb_trans_dummy; + result->transaction_commit = db_ctdb_trans_dummy; + result->transaction_cancel = db_ctdb_trans_dummy; DEBUG(3,("db_open_ctdb: opened database '%s' with dbid 0x%x\n", name, db_ctdb->db_id)); diff --git a/source/lib/dbwrap_tdb2.c b/source/lib/dbwrap_tdb2.c new file mode 100644 index 0000000000..9f68ef4a7d --- /dev/null +++ b/source/lib/dbwrap_tdb2.c @@ -0,0 +1,1265 @@ +/* + Unix SMB/CIFS implementation. + + Database interface wrapper around tdb/ctdb + + Copyright (C) Volker Lendecke 2005-2007 + Copyright (C) Stefan Metzmacher 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 <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include "librpc/gen_ndr/ndr_messaging.h" + +struct db_tdb2_ctx { + struct db_context *db; + const char *name; + struct tdb_wrap *mtdb; + const char *mtdb_path; + bool master_transaction; + struct { + int hash_size; + int tdb_flags; + int open_flags; + mode_t mode; + } open; + struct tdb_wrap *ltdb; + const char *ltdb_path; + bool local_transaction; + int transaction; + bool out_of_sync; + uint32_t lseqnum; + uint32_t mseqnum; +#define DB_TDB2_MASTER_SEQNUM_KEYSTR "DB_TDB2_MASTER_SEQNUM_KEYSTR" + TDB_DATA mseqkey; + uint32_t max_buffer_size; + uint32_t current_buffer_size; + struct dbwrap_tdb2_changes changes; +}; + + +static NTSTATUS db_tdb2_store(struct db_record *rec, TDB_DATA data, int flag); +static NTSTATUS db_tdb2_delete(struct db_record *rec); + +static void db_tdb2_queue_change(struct db_tdb2_ctx *db_ctx, const TDB_DATA key); +static void db_tdb2_send_notify(struct db_tdb2_ctx *db_ctx); + +static struct db_context *db_open_tdb2_ex(TALLOC_CTX *mem_ctx, + const char *name, + int hash_size, int tdb_flags, + int open_flags, mode_t mode, + const struct dbwrap_tdb2_changes *chgs); + +static int db_tdb2_sync_from_master(struct db_tdb2_ctx *db_ctx, + const struct dbwrap_tdb2_changes *changes); + +static int db_tdb2_open_master(struct db_tdb2_ctx *db_ctx, bool transaction, + const struct dbwrap_tdb2_changes *changes); +static int db_tdb2_commit_local(struct db_tdb2_ctx *db_ctx, uint32_t mseqnum); +static int db_tdb2_close_master(struct db_tdb2_ctx *db_ctx); +static int db_tdb2_transaction_cancel(struct db_context *db); + +static void db_tdb2_receive_changes(struct messaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id server_id, + DATA_BLOB *data); + +static struct messaging_context *global_tdb2_msg_ctx; +static bool global_tdb2_msg_ctx_initialized; + +void db_tdb2_setup_messaging(struct messaging_context *msg_ctx, bool server) +{ + global_tdb2_msg_ctx = msg_ctx; + + global_tdb2_msg_ctx_initialized = true; + + if (!server) { + return; + } + + if (!lp_parm_bool(-1, "dbwrap", "use_tdb2", false)) { + return; + } + + messaging_register(msg_ctx, NULL, MSG_DBWRAP_TDB2_CHANGES, + db_tdb2_receive_changes); +} + +static struct messaging_context *db_tdb2_get_global_messaging_context(void) +{ + struct messaging_context *msg_ctx; + + if (global_tdb2_msg_ctx_initialized) { + return global_tdb2_msg_ctx; + } + + msg_ctx = messaging_init(NULL, procid_self(), + event_context_init(NULL)); + + db_tdb2_setup_messaging(msg_ctx, false); + + return global_tdb2_msg_ctx; +} + +struct tdb_fetch_locked_state { + TALLOC_CTX *mem_ctx; + struct db_record *result; +}; + +static int db_tdb2_fetchlock_parse(TDB_DATA key, TDB_DATA data, + void *private_data) +{ + struct tdb_fetch_locked_state *state = + (struct tdb_fetch_locked_state *)private_data; + + state->result = (struct db_record *)talloc_size( + state->mem_ctx, + sizeof(struct db_record) + key.dsize + data.dsize); + + if (state->result == NULL) { + return 0; + } + + state->result->key.dsize = key.dsize; + state->result->key.dptr = ((uint8 *)state->result) + + sizeof(struct db_record); + memcpy(state->result->key.dptr, key.dptr, key.dsize); + + state->result->value.dsize = data.dsize; + + if (data.dsize > 0) { + state->result->value.dptr = state->result->key.dptr+key.dsize; + memcpy(state->result->value.dptr, data.dptr, data.dsize); + } + else { + state->result->value.dptr = NULL; + } + + return 0; +} + +static struct db_record *db_tdb2_fetch_locked(struct db_context *db, + TALLOC_CTX *mem_ctx, TDB_DATA key) +{ + struct db_tdb2_ctx *ctx = talloc_get_type_abort(db->private_data, + struct db_tdb2_ctx); + struct tdb_fetch_locked_state state; + + /* Do not accidently allocate/deallocate w/o need when debug level is lower than needed */ + if(DEBUGLEVEL >= 10) { + char *keystr = hex_encode(NULL, (unsigned char*)key.dptr, key.dsize); + DEBUG(10, (DEBUGLEVEL > 10 + ? "Locking key %s\n" : "Locking key %.20s\n", + keystr)); + TALLOC_FREE(keystr); + } + + /* + * we only support modifications within a + * started transaction. + */ + if (ctx->transaction == 0) { + DEBUG(0, ("db_tdb2_fetch_locked[%s]: no transaction started\n", + ctx->name)); + smb_panic("no transaction"); + return NULL; + } + + state.mem_ctx = mem_ctx; + state.result = NULL; + + tdb_parse_record(ctx->mtdb->tdb, key, db_tdb2_fetchlock_parse, &state); + + if (state.result == NULL) { + db_tdb2_fetchlock_parse(key, tdb_null, &state); + } + + if (state.result == NULL) { + return NULL; + } + + state.result->private_data = talloc_reference(state.result, ctx); + state.result->store = db_tdb2_store; + state.result->delete_rec = db_tdb2_delete; + + DEBUG(10, ("Allocated locked data 0x%p\n", state.result)); + + return state.result; +} + +struct tdb_fetch_state { + TALLOC_CTX *mem_ctx; + int result; + TDB_DATA data; +}; + +static int db_tdb2_fetch_parse(TDB_DATA key, TDB_DATA data, + void *private_data) +{ + struct tdb_fetch_state *state = + (struct tdb_fetch_state *)private_data; + + state->data.dptr = (uint8 *)talloc_memdup(state->mem_ctx, data.dptr, + data.dsize); + if (state->data.dptr == NULL) { + state->result = -1; + return 0; + } + + state->data.dsize = data.dsize; + return 0; +} + +static void db_tdb2_resync_before_read(struct db_tdb2_ctx *db_ctx, TDB_DATA *kbuf) +{ + if (db_ctx->mtdb) { + return; + } + + if (!db_ctx->out_of_sync) { + return; + } + + /* + * this function operates on the local copy, + * so hide the DB_TDB2_MASTER_SEQNUM_KEYSTR from the caller. + */ + if (kbuf && (db_ctx->mseqkey.dsize == kbuf->dsize) && + (memcmp(db_ctx->mseqkey.dptr, kbuf->dptr, kbuf->dsize) == 0)) { + return; + } + + DEBUG(0,("resync_before_read[%s/%s]\n", + db_ctx->mtdb_path, db_ctx->ltdb_path)); + + db_tdb2_open_master(db_ctx, false, NULL); + db_tdb2_close_master(db_ctx); +} + +static int db_tdb2_fetch(struct db_context *db, TALLOC_CTX *mem_ctx, + TDB_DATA key, TDB_DATA *pdata) +{ + struct db_tdb2_ctx *ctx = talloc_get_type_abort( + db->private_data, struct db_tdb2_ctx); + + struct tdb_fetch_state state; + + db_tdb2_resync_before_read(ctx, &key); + + if (ctx->out_of_sync) { + DEBUG(0,("out of sync[%s] failing fetch\n", + ctx->ltdb_path)); + errno = EIO; + return -1; + } + + state.mem_ctx = mem_ctx; + state.result = 0; + state.data = tdb_null; + + tdb_parse_record(ctx->ltdb->tdb, key, db_tdb2_fetch_parse, &state); + + if (state.result == -1) { + return -1; + } + + *pdata = state.data; + return 0; +} + +static NTSTATUS db_tdb2_store(struct db_record *rec, TDB_DATA data, int flag) +{ + struct db_tdb2_ctx *ctx = talloc_get_type_abort(rec->private_data, + struct db_tdb2_ctx); + int ret; + + /* + * This has a bug: We need to replace rec->value for correct + * operation, but right now brlock and locking don't use the value + * anymore after it was stored. + */ + + /* first store it to the master copy */ + ret = tdb_store(ctx->mtdb->tdb, rec->key, data, flag); + if (ret != 0) { + return NT_STATUS_UNSUCCESSFUL; + } + + /* then store it to the local copy */ + ret = tdb_store(ctx->ltdb->tdb, rec->key, data, flag); + if (ret != 0) { + /* try to restore the old value in the master copy */ + if (rec->value.dptr) { + tdb_store(ctx->mtdb->tdb, rec->key, + rec->value, TDB_REPLACE); + } else { + tdb_delete(ctx->mtdb->tdb, rec->key); + } + return NT_STATUS_INTERNAL_DB_CORRUPTION; + } + + db_tdb2_queue_change(ctx, rec->key); + + return NT_STATUS_OK; +} + +static NTSTATUS db_tdb2_delete(struct db_record *rec) +{ + struct db_tdb2_ctx *ctx = talloc_get_type_abort(rec->private_data, + struct db_tdb2_ctx); + int ret; + + ret = tdb_delete(ctx->mtdb->tdb, rec->key); + if (ret != 0) { + if (tdb_error(ctx->mtdb->tdb) == TDB_ERR_NOEXIST) { + return NT_STATUS_NOT_FOUND; + } + + return NT_STATUS_UNSUCCESSFUL; + } + + ret = tdb_delete(ctx->ltdb->tdb, rec->key); + if (ret != 0) { + /* try to restore the value in the master copy */ + tdb_store(ctx->mtdb->tdb, rec->key, + rec->value, TDB_REPLACE); + return NT_STATUS_INTERNAL_DB_CORRUPTION; + } + + db_tdb2_queue_change(ctx, rec->key); + + return NT_STATUS_OK; +} + +struct db_tdb2_traverse_ctx { + struct db_tdb2_ctx *db_ctx; + int (*f)(struct db_record *rec, void *private_data); + void *private_data; +}; + +static int db_tdb2_traverse_func(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, + void *private_data) +{ + struct db_tdb2_traverse_ctx *ctx = + (struct db_tdb2_traverse_ctx *)private_data; + struct db_record rec; + + /* this function operates on the master copy */ + + rec.key = kbuf; + rec.value = dbuf; + rec.store = db_tdb2_store; + rec.delete_rec = db_tdb2_delete; + rec.private_data = ctx->db_ctx; + + return ctx->f(&rec, ctx->private_data); +} + +static int db_tdb2_traverse(struct db_context *db, + int (*f)(struct db_record *rec, void *private_data), + void *private_data) +{ + struct db_tdb2_ctx *db_ctx = + talloc_get_type_abort(db->private_data, struct db_tdb2_ctx); + struct db_tdb2_traverse_ctx ctx; + + /* + * we only support modifications within a + * started transaction. + */ + if (db_ctx->transaction == 0) { + DEBUG(0, ("db_tdb2_traverse[%s]: no transaction started\n", + db_ctx->name)); + smb_panic("no transaction"); + return -1; + } + + /* here we traverse the master copy */ + ctx.db_ctx = db_ctx; + ctx.f = f; + ctx.private_data = private_data; + return tdb_traverse(db_ctx->mtdb->tdb, db_tdb2_traverse_func, &ctx); +} + +static NTSTATUS db_tdb2_store_deny(struct db_record *rec, TDB_DATA data, int flag) +{ + return NT_STATUS_MEDIA_WRITE_PROTECTED; +} + +static NTSTATUS db_tdb2_delete_deny(struct db_record *rec) +{ + return NT_STATUS_MEDIA_WRITE_PROTECTED; +} + +static int db_tdb2_traverse_read_func(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, + void *private_data) +{ + struct db_tdb2_traverse_ctx *ctx = + (struct db_tdb2_traverse_ctx *)private_data; + struct db_record rec; + + /* + * this function operates on the local copy, + * so hide the DB_TDB2_MASTER_SEQNUM_KEYSTR from the caller. + */ + if ((ctx->db_ctx->mseqkey.dsize == kbuf.dsize) && + (memcmp(ctx->db_ctx->mseqkey.dptr, kbuf.dptr, kbuf.dsize) == 0)) { + return 0; + } + + rec.key = kbuf; + rec.value = dbuf; + rec.store = db_tdb2_store_deny; + rec.delete_rec = db_tdb2_delete_deny; + rec.private_data = ctx->db_ctx; + + return ctx->f(&rec, ctx->private_data); +} + +static int db_tdb2_traverse_read(struct db_context *db, + int (*f)(struct db_record *rec, void *private_data), + void *private_data) +{ + struct db_tdb2_ctx *db_ctx = + talloc_get_type_abort(db->private_data, struct db_tdb2_ctx); + struct db_tdb2_traverse_ctx ctx; + int ret; + + db_tdb2_resync_before_read(db_ctx, NULL); + + if (db_ctx->out_of_sync) { + DEBUG(0,("out of sync[%s] failing traverse_read\n", + db_ctx->ltdb_path)); + errno = EIO; + return -1; + } + + /* here we traverse the local copy */ + ctx.db_ctx = db_ctx; + ctx.f = f; + ctx.private_data = private_data; + ret = tdb_traverse_read(db_ctx->ltdb->tdb, db_tdb2_traverse_read_func, &ctx); + if (ret > 0) { + /* we have filtered one entry */ + ret--; + } + + return ret; +} + +static int db_tdb2_get_seqnum(struct db_context *db) + +{ + struct db_tdb2_ctx *db_ctx = + talloc_get_type_abort(db->private_data, struct db_tdb2_ctx); + uint32_t nlseq; + uint32_t nmseq; + bool ok; + + nlseq = tdb_get_seqnum(db_ctx->ltdb->tdb); + + if (nlseq == db_ctx->lseqnum) { + return db_ctx->mseqnum; + } + + ok = tdb_fetch_uint32_byblob(db_ctx->ltdb->tdb, + db_ctx->mseqkey, + &nmseq); + if (!ok) { + /* TODO: what should we do here? */ + return db_ctx->mseqnum; + } + + db_ctx->lseqnum = nlseq; + db_ctx->mseqnum = nmseq; + + return db_ctx->mseqnum; +} + +static int db_tdb2_transaction_start(struct db_context *db) +{ + struct db_tdb2_ctx *db_ctx = + talloc_get_type_abort(db->private_data, struct db_tdb2_ctx); + int ret; + + if (db_ctx->transaction) { + db_ctx->transaction++; + return 0; + } + + /* we need to open the master tdb in order to */ + ret = db_tdb2_open_master(db_ctx, true, NULL); + if (ret != 0) { + return ret; + } + + ret = tdb_transaction_start(db_ctx->ltdb->tdb); + if (ret != 0) { + db_tdb2_close_master(db_ctx); + return ret; + } + + db_ctx->local_transaction = true; + db_ctx->transaction = 1; + + return 0; +} + +static void db_tdb2_queue_change(struct db_tdb2_ctx *db_ctx, const TDB_DATA key) +{ + size_t size_needed = 4 + key.dsize; + size_t size_new = db_ctx->current_buffer_size + size_needed; + uint32_t i; + DATA_BLOB *keys; + + db_ctx->changes.num_changes++; + + if (db_ctx->changes.num_changes > 1 && + db_ctx->changes.keys == NULL) { + /* + * this means we already overflowed + */ + return; + } + + if (db_ctx->changes.num_changes == 1) { + db_ctx->changes.old_seqnum = db_ctx->mseqnum; + } + + for (i=0; i < db_ctx->changes.num_keys; i++) { + int ret; + + if (key.dsize != db_ctx->changes.keys[i].length) { + continue; + } + ret = memcmp(key.dptr, db_ctx->changes.keys[i].data, key.dsize); + if (ret != 0) { + continue; + } + + /* + * the key is already in the list + * so we're done + */ + return; + } + + if (db_ctx->max_buffer_size < size_new) { + goto overflow; + } + + keys = TALLOC_REALLOC_ARRAY(db_ctx, db_ctx->changes.keys, + DATA_BLOB, + db_ctx->changes.num_keys + 1); + if (!keys) { + goto overflow; + } + db_ctx->changes.keys = keys; + + keys[db_ctx->changes.num_keys].data = (uint8_t *)talloc_memdup(keys, + key.dptr, + key.dsize); + if (!keys[db_ctx->changes.num_keys].data) { + goto overflow; + } + keys[db_ctx->changes.num_keys].length = key.dsize; + db_ctx->changes.num_keys++; + db_ctx->current_buffer_size = size_new; + + return; + +overflow: + /* + * on overflow discard the buffer and let + * the others reload the whole tdb + */ + db_ctx->current_buffer_size = 0; + db_ctx->changes.num_keys = 0; + TALLOC_FREE(db_ctx->changes.keys); + return; +} + +static void db_tdb2_send_notify(struct db_tdb2_ctx *db_ctx) +{ + enum ndr_err_code ndr_err; + bool ok; + DATA_BLOB blob; + struct messaging_context *msg_ctx; + int num_msgs = 0; + struct server_id self = procid_self(); + + msg_ctx = db_tdb2_get_global_messaging_context(); + + db_ctx->changes.name = db_ctx->name; + + DEBUG(10,("%s[%s] size[%u/%u] changes[%u] keys[%u] seqnum[%u=>%u]\n", + __FUNCTION__, + db_ctx->changes.name, + db_ctx->current_buffer_size, + db_ctx->max_buffer_size, + db_ctx->changes.num_changes, + db_ctx->changes.num_keys, + db_ctx->changes.old_seqnum, + db_ctx->changes.new_seqnum)); + + if (db_ctx->changes.num_changes == 0) { + DEBUG(10,("db_tdb2_send_notify[%s]: no changes\n", + db_ctx->changes.name)); + goto done; + } + + if (!msg_ctx) { + DEBUG(1,("db_tdb2_send_notify[%s]: skipped (no msg ctx)\n", + db_ctx->changes.name)); + goto done; + } + + ndr_err = ndr_push_struct_blob( + &blob, talloc_tos(), &db_ctx->changes, + (ndr_push_flags_fn_t)ndr_push_dbwrap_tdb2_changes); + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { + DEBUG(0,("db_tdb2_send_notify[%s]: failed to push changes: %s\n", + db_ctx->changes.name, + nt_errstr(ndr_map_error2ntstatus(ndr_err)))); + goto done; + } + + ok = message_send_all(msg_ctx, MSG_DBWRAP_TDB2_CHANGES, + blob.data, blob.length, &num_msgs); + if (!ok) { + DEBUG(0,("db_tdb2_send_notify[%s]: failed to send changes\n", + db_ctx->changes.name)); + goto done; + } + + DEBUG(10,("db_tdb2_send_notify[%s]: pid %s send %u messages\n", + db_ctx->name, procid_str_static(&self), num_msgs)); + +done: + TALLOC_FREE(db_ctx->changes.keys); + ZERO_STRUCT(db_ctx->changes); + + return; +} + +static void db_tdb2_receive_changes(struct messaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id server_id, + DATA_BLOB *data) +{ + enum ndr_err_code ndr_err; + struct dbwrap_tdb2_changes changes; + struct db_context *db; + struct server_id self; + + if (procid_is_me(&server_id)) { + DEBUG(0,("db_tdb2_receive_changes: ignore selfpacket\n")); + return; + } + + self = procid_self(); + + DEBUG(10,("db_tdb2_receive_changes: from %s to %s\n", + procid_str(debug_ctx(), &server_id), + procid_str(debug_ctx(), &self))); + + ndr_err = ndr_pull_struct_blob_all( + data, talloc_tos(), &changes, + (ndr_pull_flags_fn_t)ndr_pull_dbwrap_tdb2_changes); + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { + DEBUG(0,("db_tdb2_receive_changes: failed to pull changes: %s\n", + nt_errstr(ndr_map_error2ntstatus(ndr_err)))); + goto done; + } + + if(DEBUGLEVEL >= 10) { + NDR_PRINT_DEBUG(dbwrap_tdb2_changes, &changes); + } + + /* open the db, this will sync it */ + db = db_open_tdb2_ex(talloc_tos(), changes.name, 0, + 0, O_RDWR, 0600, &changes); + TALLOC_FREE(db); +done: + return; +} + +static int db_tdb2_transaction_commit(struct db_context *db) +{ + struct db_tdb2_ctx *db_ctx = + talloc_get_type_abort(db->private_data, struct db_tdb2_ctx); + int ret; + uint32_t mseqnum; + + if (db_ctx->transaction == 0) { + return -1; + } else if (db_ctx->transaction > 1) { + db_ctx->transaction--; + return 0; + } + + mseqnum = tdb_get_seqnum(db_ctx->mtdb->tdb); + db_ctx->changes.new_seqnum = mseqnum; + + /* first commit to the master copy */ + ret = tdb_transaction_commit(db_ctx->mtdb->tdb); + db_ctx->master_transaction = false; + if (ret != 0) { + int saved_errno = errno; + db_tdb2_transaction_cancel(db); + errno = saved_errno; + return ret; + } + + /* + * Note: as we've already commited the changes to the master copy + * so we ignore errors in the following functions + */ + ret = db_tdb2_commit_local(db_ctx, mseqnum); + if (ret == 0) { + db_ctx->out_of_sync = false; + } else { + db_ctx->out_of_sync = true; + } + + db_ctx->transaction = 0; + + db_tdb2_close_master(db_ctx); + + db_tdb2_send_notify(db_ctx); + + return 0; +} + +static int db_tdb2_transaction_cancel(struct db_context *db) +{ + struct db_tdb2_ctx *db_ctx = + talloc_get_type_abort(db->private_data, struct db_tdb2_ctx); + int saved_errno; + int ret; + + if (db_ctx->transaction == 0) { + return -1; + } + if (db_ctx->transaction > 1) { + db_ctx->transaction--; + return 0; + } + + /* cancel the transaction and close the master copy */ + ret = db_tdb2_close_master(db_ctx); + saved_errno = errno; + + /* now cancel on the local copy and ignore any error */ + tdb_transaction_cancel(db_ctx->ltdb->tdb); + db_ctx->local_transaction = false; + + db_ctx->transaction = 0; + + errno = saved_errno; + return ret; +} + +static int db_tdb2_open_master(struct db_tdb2_ctx *db_ctx, bool transaction, + const struct dbwrap_tdb2_changes *changes) +{ + int ret; + + db_ctx->mtdb = tdb_wrap_open(db_ctx, + db_ctx->mtdb_path, + db_ctx->open.hash_size, + db_ctx->open.tdb_flags|TDB_NOMMAP|TDB_SEQNUM, + db_ctx->open.open_flags, + db_ctx->open.mode); + if (db_ctx->mtdb == NULL) { + DEBUG(0, ("Could not open master tdb[%s]: %s\n", + db_ctx->mtdb_path, + strerror(errno))); + return -1; + } + DEBUG(10,("open_master[%s]\n", db_ctx->mtdb_path)); + + if (!db_ctx->ltdb) { + struct stat st; + + if (fstat(tdb_fd(db_ctx->mtdb->tdb), &st) == 0) { + db_ctx->open.mode = st.st_mode; + } + + /* make sure the local one uses the same hash size as the master one */ + db_ctx->open.hash_size = tdb_hash_size(db_ctx->mtdb->tdb); + + db_ctx->ltdb = tdb_wrap_open(db_ctx, + db_ctx->ltdb_path, + db_ctx->open.hash_size, + db_ctx->open.tdb_flags|TDB_SEQNUM, + db_ctx->open.open_flags|O_CREAT, + db_ctx->open.mode); + if (db_ctx->ltdb == NULL) { + DEBUG(0, ("Could not open local tdb[%s]: %s\n", + db_ctx->ltdb_path, + strerror(errno))); + TALLOC_FREE(db_ctx->mtdb); + return -1; + } + DEBUG(10,("open_local[%s]\n", db_ctx->ltdb_path)); + } + + if (transaction) { + ret = tdb_transaction_start(db_ctx->mtdb->tdb); + if (ret != 0) { + DEBUG(0,("open failed to start transaction[%s]\n", + db_ctx->mtdb_path)); + db_tdb2_close_master(db_ctx); + return ret; + } + db_ctx->master_transaction = true; + } + + ret = db_tdb2_sync_from_master(db_ctx, changes); + if (ret != 0) { + DEBUG(0,("open failed to sync from master[%s]\n", + db_ctx->ltdb_path)); + db_tdb2_close_master(db_ctx); + return ret; + } + + return 0; +} + +static int db_tdb2_commit_local(struct db_tdb2_ctx *db_ctx, uint32_t mseqnum) +{ + bool ok; + int ret; + + /* first fetch the master seqnum */ + db_ctx->mseqnum = mseqnum; + + /* now we try to store the master seqnum in the local tdb */ + ok = tdb_store_uint32_byblob(db_ctx->ltdb->tdb, + db_ctx->mseqkey, + db_ctx->mseqnum); + if (!ok) { + tdb_transaction_cancel(db_ctx->ltdb->tdb); + db_ctx->local_transaction = false; + DEBUG(0,("local failed[%s] store mseq[%u]\n", + db_ctx->ltdb_path, db_ctx->mseqnum)); + return -1; + } + + /* now commit all changes to the local tdb */ + ret = tdb_transaction_commit(db_ctx->ltdb->tdb); + db_ctx->local_transaction = false; + if (ret != 0) { + DEBUG(0,("local failed[%s] commit mseq[%u]\n", + db_ctx->ltdb_path, db_ctx->mseqnum)); + return ret; + } + + /* + * and update the cached local seqnum this is needed to + * let us cache the master seqnum. + */ + db_ctx->lseqnum = tdb_get_seqnum(db_ctx->ltdb->tdb); + DEBUG(10,("local updated[%s] mseq[%u]\n", + db_ctx->ltdb_path, db_ctx->mseqnum)); + + return 0; +} + +static int db_tdb2_close_master(struct db_tdb2_ctx *db_ctx) +{ + if (db_ctx->master_transaction) { + tdb_transaction_cancel(db_ctx->mtdb->tdb); + } + db_ctx->master_transaction = false; + /* now we can close the master handle */ + TALLOC_FREE(db_ctx->mtdb); + + DEBUG(10,("close_master[%s] ok\n", db_ctx->mtdb_path)); + return 0; +} + +static int db_tdb2_traverse_sync_all_func(TDB_CONTEXT *tdb, + TDB_DATA kbuf, TDB_DATA dbuf, + void *private_data) +{ + struct db_tdb2_traverse_ctx *ctx = + (struct db_tdb2_traverse_ctx *)private_data; + uint32_t *seqnum = (uint32_t *)ctx->private_data; + int ret; + + DEBUG(10,("sync_entry[%s]\n", ctx->db_ctx->mtdb_path)); + + /* Do not accidently allocate/deallocate w/o need when debug level is lower than needed */ + if(DEBUGLEVEL >= 10) { + char *keystr = hex_encode(NULL, (unsigned char*)kbuf.dptr, kbuf.dsize); + DEBUG(10, (DEBUGLEVEL > 10 + ? "Locking key %s\n" : "Locking key %.20s\n", + keystr)); + TALLOC_FREE(keystr); + } + + ret = tdb_store(ctx->db_ctx->ltdb->tdb, kbuf, dbuf, TDB_INSERT); + if (ret != 0) { + DEBUG(0,("sync_entry[%s] %d: %s\n", + ctx->db_ctx->ltdb_path, ret, + tdb_errorstr(ctx->db_ctx->ltdb->tdb))); + return ret; + } + + *seqnum = tdb_get_seqnum(ctx->db_ctx->mtdb->tdb); + + return 0; +} + +static int db_tdb2_sync_all(struct db_tdb2_ctx *db_ctx, uint32_t *seqnum) +{ + struct db_tdb2_traverse_ctx ctx; + int ret; + + ret = tdb_wipe_all(db_ctx->ltdb->tdb); + if (ret != 0) { + DEBUG(0,("tdb_wipe_all[%s] failed %d: %s\n", + db_ctx->ltdb_path, ret, + tdb_errorstr(db_ctx->ltdb->tdb))); + return ret; + } + + ctx.db_ctx = db_ctx; + ctx.f = NULL; + ctx.private_data = seqnum; + ret = tdb_traverse_read(db_ctx->mtdb->tdb, + db_tdb2_traverse_sync_all_func, + &ctx); + DEBUG(10,("db_tdb2_sync_all[%s] count[%d]\n", + db_ctx->mtdb_path, ret)); + if (ret < 0) { + return ret; + } + + return 0; +} + +static int db_tdb2_sync_changes(struct db_tdb2_ctx *db_ctx, + const struct dbwrap_tdb2_changes *changes, + uint32_t *seqnum) +{ + uint32_t cseqnum; + uint32_t mseqnum; + uint32_t i; + int ret; + bool need_full_sync = false; + + DEBUG(10,("db_tdb2_sync_changes[%s] changes[%u]\n", + changes->name, changes->num_changes)); + if(DEBUGLEVEL >= 10) { + NDR_PRINT_DEBUG(dbwrap_tdb2_changes, discard_const(changes)); + } + + /* for the master tdb for reading */ + ret = tdb_lockall_read(db_ctx->mtdb->tdb); + if (ret != 0) { + DEBUG(0,("tdb_lockall_read[%s] %d\n", db_ctx->mtdb_path, ret)); + return ret; + } + + /* first fetch seqnum we know about */ + cseqnum = db_tdb2_get_seqnum(db_ctx->db); + + /* then fetch the master seqnum */ + mseqnum = tdb_get_seqnum(db_ctx->mtdb->tdb); + + if (cseqnum == mseqnum) { + DEBUG(10,("db_tdb2_sync_changes[%s] uptodate[%u]\n", + db_ctx->mtdb_path, mseqnum)); + /* we hit a race before and now noticed we're uptodate */ + goto done; + } + + /* now see if the changes describe what we need */ + if (changes->old_seqnum != cseqnum) { + need_full_sync = true; + } + + if (changes->new_seqnum != mseqnum) { + need_full_sync = true; + } + + /* this was the overflow case */ + if (changes->num_keys == 0) { + need_full_sync = true; + } + + if (need_full_sync) { + tdb_unlockall_read(db_ctx->mtdb->tdb); + DEBUG(0,("fallback to full sync[%s] seq[%u=>%u] keys[%u]\n", + db_ctx->ltdb_path, cseqnum, mseqnum, + changes->num_keys)); + return db_tdb2_sync_all(db_ctx, &mseqnum); + } + + for (i=0; i < changes->num_keys; i++) { + const char *op = NULL; + bool del = false; + TDB_DATA key; + TDB_DATA val; + + key.dsize = changes->keys[i].length; + key.dptr = changes->keys[i].data; + + val = tdb_fetch(db_ctx->mtdb->tdb, key); + ret = tdb_error(db_ctx->mtdb->tdb); + if (ret == TDB_ERR_NOEXIST) { + del = true; + } else if (ret != 0) { + DEBUG(0,("sync_changes[%s] failure %d\n", + db_ctx->mtdb_path, ret)); + goto failed; + } + + if (del) { + op = "delete"; + ret = tdb_delete(db_ctx->ltdb->tdb, key); + DEBUG(10,("sync_changes[%s] delete key[%u] %d\n", + db_ctx->mtdb_path, i, ret)); + } else { + op = "store"; + ret = tdb_store(db_ctx->ltdb->tdb, key, + val, TDB_REPLACE); + DEBUG(10,("sync_changes[%s] store key[%u] %d\n", + db_ctx->mtdb_path, i, ret)); + } + SAFE_FREE(val.dptr); + if (ret != 0) { + DEBUG(0,("sync_changes[%s] %s key[%u] failed %d\n", + db_ctx->mtdb_path, op, i, ret)); + goto failed; + } + } + +done: + tdb_unlockall_read(db_ctx->mtdb->tdb); + + *seqnum = mseqnum; + return 0; +failed: + tdb_unlockall_read(db_ctx->mtdb->tdb); + return ret; +} + +static int db_tdb2_sync_from_master(struct db_tdb2_ctx *db_ctx, + const struct dbwrap_tdb2_changes *changes) +{ + int ret; + uint32_t cseqnum; + uint32_t mseqnum; + bool force = false; + + /* first fetch seqnum we know about */ + cseqnum = db_tdb2_get_seqnum(db_ctx->db); + + /* then fetch the master seqnum */ + mseqnum = tdb_get_seqnum(db_ctx->mtdb->tdb); + + if (db_ctx->lseqnum == 0) { + force = true; + } + + if (!force && cseqnum == mseqnum) { + DEBUG(10,("uptodate[%s] mseq[%u]\n", + db_ctx->ltdb_path, mseqnum)); + /* the local copy is uptodate, close the master db */ + return 0; + } + DEBUG(10,("not uptodate[%s] seq[%u=>%u]\n", + db_ctx->ltdb_path, cseqnum, mseqnum)); + + ret = tdb_transaction_start(db_ctx->ltdb->tdb); + if (ret != 0) { + DEBUG(0,("failed to start transaction[%s] %d: %s\n", + db_ctx->ltdb_path, ret, + tdb_errorstr(db_ctx->ltdb->tdb))); + db_ctx->out_of_sync = true; + return ret; + } + db_ctx->local_transaction = true; + + if (changes && !force) { + ret = db_tdb2_sync_changes(db_ctx, changes, &mseqnum); + if (ret != 0) { + db_ctx->out_of_sync = true; + tdb_transaction_cancel(db_ctx->ltdb->tdb); + db_ctx->local_transaction = false; + return ret; + } + } else { + ret = db_tdb2_sync_all(db_ctx, &mseqnum); + if (ret != 0) { + db_ctx->out_of_sync = true; + tdb_transaction_cancel(db_ctx->ltdb->tdb); + db_ctx->local_transaction = false; + return ret; + } + } + + ret = db_tdb2_commit_local(db_ctx, mseqnum); + if (ret != 0) { + db_ctx->out_of_sync = true; + return ret; + } + + db_ctx->out_of_sync = false; + + return 0; +} + +static int db_tdb2_ctx_destructor(struct db_tdb2_ctx *db_tdb2) +{ + db_tdb2_close_master(db_tdb2); + if (db_tdb2->local_transaction) { + tdb_transaction_cancel(db_tdb2->ltdb->tdb); + } + db_tdb2->local_transaction = false; + TALLOC_FREE(db_tdb2->ltdb); + return 0; +} + +static struct db_context *db_open_tdb2_ex(TALLOC_CTX *mem_ctx, + const char *name, + int hash_size, int tdb_flags, + int open_flags, mode_t mode, + const struct dbwrap_tdb2_changes *chgs) +{ + struct db_context *result = NULL; + struct db_tdb2_ctx *db_tdb2; + int ret; + const char *md; + const char *ld; + const char *bn; + + bn = strrchr_m(name, '/'); + if (bn) { + bn++; + DEBUG(3,("db_open_tdb2: use basename[%s] of abspath[%s]:\n", + bn, name)); + } else { + bn = name; + } + + md = lp_parm_const_string(-1, "dbwrap_tdb2", "master directory", NULL); + if (!md) { + DEBUG(0,("'dbwrap_tdb2:master directory' empty\n")); + goto fail; + } + + ld = lp_parm_const_string(-1, "dbwrap_tdb2", "local directory", NULL); + if (!ld) { + DEBUG(0,("'dbwrap_tdb2:local directory' empty\n")); + goto fail; + } + + result = TALLOC_ZERO_P(mem_ctx, struct db_context); + if (result == NULL) { + DEBUG(0, ("talloc failed\n")); + goto fail; + } + + result->private_data = db_tdb2 = TALLOC_ZERO_P(result, struct db_tdb2_ctx); + if (db_tdb2 == NULL) { + DEBUG(0, ("talloc failed\n")); + goto fail; + } + + db_tdb2->db = result; + + db_tdb2->open.hash_size = hash_size; + db_tdb2->open.tdb_flags = tdb_flags; + db_tdb2->open.open_flags= open_flags; + db_tdb2->open.mode = mode; + + db_tdb2->max_buffer_size = lp_parm_ulong(-1, "dbwrap_tdb2", + "notify buffer size", 512); + + db_tdb2->name = talloc_strdup(db_tdb2, bn); + if (db_tdb2->name == NULL) { + DEBUG(0, ("talloc_strdup failed\n")); + goto fail; + } + + db_tdb2->mtdb_path = talloc_asprintf(db_tdb2, "%s/%s", + md, bn); + if (db_tdb2->mtdb_path == NULL) { + DEBUG(0, ("talloc_asprintf failed\n")); + goto fail; + } + + db_tdb2->ltdb_path = talloc_asprintf(db_tdb2, "%s/%s.tdb2", + ld, bn); + if (db_tdb2->ltdb_path == NULL) { + DEBUG(0, ("talloc_asprintf failed\n")); + goto fail; + } + + db_tdb2->mseqkey = string_term_tdb_data(DB_TDB2_MASTER_SEQNUM_KEYSTR); + + /* + * this implicit opens the local one if as it's not yet open + * it syncs the local copy. + */ + ret = db_tdb2_open_master(db_tdb2, false, chgs); + if (ret != 0) { + goto fail; + } + + ret = db_tdb2_close_master(db_tdb2); + if (ret != 0) { + goto fail; + } + + DEBUG(10,("db_open_tdb2[%s] opened with mseq[%u]\n", + db_tdb2->name, db_tdb2->mseqnum)); + + result->fetch_locked = db_tdb2_fetch_locked; + result->fetch = db_tdb2_fetch; + result->traverse = db_tdb2_traverse; + result->traverse_read = db_tdb2_traverse_read; + result->get_seqnum = db_tdb2_get_seqnum; + result->persistent = ((tdb_flags & TDB_CLEAR_IF_FIRST) == 0); + result->transaction_start = db_tdb2_transaction_start; + result->transaction_commit = db_tdb2_transaction_commit; + result->transaction_cancel = db_tdb2_transaction_cancel; + + talloc_set_destructor(db_tdb2, db_tdb2_ctx_destructor); + + return result; + + fail: + if (result != NULL) { + TALLOC_FREE(result); + } + return NULL; +} + +struct db_context *db_open_tdb2(TALLOC_CTX *mem_ctx, + const char *name, + int hash_size, int tdb_flags, + int open_flags, mode_t mode) +{ + return db_open_tdb2_ex(mem_ctx, name, hash_size, + tdb_flags, open_flags, mode, NULL); +} diff --git a/source/lib/dbwrap_util.c b/source/lib/dbwrap_util.c index ddc613150b..09e9071d8c 100644 --- a/source/lib/dbwrap_util.c +++ b/source/lib/dbwrap_util.c @@ -210,8 +210,7 @@ NTSTATUS dbwrap_trans_store(struct db_context *db, TDB_DATA key, TDB_DATA dbuf, if (res != 0) { DEBUG(5, ("tdb_transaction_commit failed\n")); status = NT_STATUS_INTERNAL_DB_CORRUPTION; - TALLOC_FREE(rec); - return status; + goto cancel; } return NT_STATUS_OK; @@ -256,8 +255,7 @@ NTSTATUS dbwrap_trans_delete(struct db_context *db, TDB_DATA key) if (res != 0) { DEBUG(5, ("tdb_transaction_commit failed\n")); status = NT_STATUS_INTERNAL_DB_CORRUPTION; - TALLOC_FREE(rec); - return status; + goto cancel; } return NT_STATUS_OK; diff --git a/source/lib/events.c b/source/lib/events.c index f03138708b..f5d6480a6f 100644 --- a/source/lib/events.c +++ b/source/lib/events.c @@ -63,9 +63,7 @@ static int timed_event_destructor(struct timed_event *te) { DEBUG(10, ("Destroying timed event %lx \"%s\"\n", (unsigned long)te, te->event_name)); - if (te->event_ctx != NULL) { - DLIST_REMOVE(te->event_ctx->timed_events, te); - } + DLIST_REMOVE(te->event_ctx->timed_events, te); return 0; } @@ -133,9 +131,9 @@ struct timed_event *event_add_timed(struct event_context *event_ctx, static int fd_event_destructor(struct fd_event *fde) { - if (fde->event_ctx != NULL) { - DLIST_REMOVE(fde->event_ctx->fd_events, fde); - } + struct event_context *event_ctx = fde->event_ctx; + + DLIST_REMOVE(event_ctx->fd_events, fde); return 0; } @@ -294,7 +292,7 @@ bool run_events(struct event_context *event_ctx, if (FD_ISSET(fde->fd, read_fds)) flags |= EVENT_FD_READ; if (FD_ISSET(fde->fd, write_fds)) flags |= EVENT_FD_WRITE; - if (flags & fde->flags) { + if (flags) { fde->handler(event_ctx, fde, flags, fde->private_data); fired = True; } @@ -356,30 +354,9 @@ int event_loop_once(struct event_context *ev) return 0; } -static int event_context_destructor(struct event_context *ev) -{ - while (ev->fd_events != NULL) { - ev->fd_events->event_ctx = NULL; - DLIST_REMOVE(ev->fd_events, ev->fd_events); - } - while (ev->timed_events != NULL) { - ev->timed_events->event_ctx = NULL; - DLIST_REMOVE(ev->timed_events, ev->timed_events); - } - return 0; -} - struct event_context *event_context_init(TALLOC_CTX *mem_ctx) { - struct event_context *result; - - result = TALLOC_ZERO_P(mem_ctx, struct event_context); - if (result == NULL) { - return NULL; - } - - talloc_set_destructor(result, event_context_destructor); - return result; + return TALLOC_ZERO_P(NULL, struct event_context); } int set_event_dispatch_time(struct event_context *event_ctx, diff --git a/source/lib/fault.c b/source/lib/fault.c index d4c1142937..1964955f1b 100644 --- a/source/lib/fault.c +++ b/source/lib/fault.c @@ -188,11 +188,6 @@ void dump_core_setup(const char *progname) become_root(); } - if (corepath == NULL) { - DEBUG(0, ("Can not dump core: corepath not set up\n")); - exit(1); - } - if (*corepath != '\0') { /* The chdir might fail if we dump core before we finish * processing the config file. diff --git a/source/lib/fsusage.c b/source/lib/fsusage.c index 66ffb9f442..c5dec5ee8d 100644 --- a/source/lib/fsusage.c +++ b/source/lib/fsusage.c @@ -122,13 +122,8 @@ int sys_fsusage(const char *path, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) #endif /* STAT_STATFS4 */ #if defined(STAT_STATVFS) || defined(STAT_STATVFS64) /* SVR4 */ -#if defined HAVE_FRSIZE # define CONVERT_BLOCKS(B) \ adjust_blocks ((SMB_BIG_UINT)(B), fsd.f_frsize ? (SMB_BIG_UINT)fsd.f_frsize : (SMB_BIG_UINT)fsd.f_bsize, (SMB_BIG_UINT)512) -#else -# define CONVERT_BLOCKS(B) \ - adjust_blocks ((SMB_BIG_UINT)(B), (SMB_BIG_UINT)fsd.f_bsize, (SMB_BIG_UINT)512) -#endif #ifdef STAT_STATVFS64 struct statvfs64 fsd; diff --git a/source/lib/iconv.c b/source/lib/iconv.c index 3ceb637b8e..6575dba5a9 100644 --- a/source/lib/iconv.c +++ b/source/lib/iconv.c @@ -136,7 +136,7 @@ static size_t sys_iconv(void *cd, char **outbuf, size_t *outbytesleft) { size_t ret = iconv((iconv_t)cd, - (void *)inbuf, inbytesleft, + (char **)inbuf, inbytesleft, outbuf, outbytesleft); if (ret == (size_t)-1) { int saved_errno = errno; diff --git a/source/lib/idmap_cache.c b/source/lib/idmap_cache.c deleted file mode 100644 index 6377635a65..0000000000 --- a/source/lib/idmap_cache.c +++ /dev/null @@ -1,260 +0,0 @@ -/* - Unix SMB/CIFS implementation. - ID Mapping Cache - - Copyright (C) Volker Lendecke 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 <http://www.gnu.org/licenses/>.*/ - -#include "includes.h" - -/** - * Find a sid2uid mapping - * @param[in] sid the sid to map - * @param[out] puid where to put the result - * @param[out] expired is the cache entry expired? - * @retval Was anything in the cache at all? - * - * If *puid == -1 this was a negative mapping. - */ - -bool idmap_cache_find_sid2uid(const struct dom_sid *sid, uid_t *puid, - bool *expired) -{ - fstring sidstr; - char *key; - char *value; - char *endptr; - time_t timeout; - uid_t uid; - bool ret; - - key = talloc_asprintf(talloc_tos(), "IDMAP/SID2UID/%s", - sid_to_fstring(sidstr, sid)); - if (key == NULL) { - return false; - } - ret = gencache_get(key, &value, &timeout); - TALLOC_FREE(key); - if (!ret) { - return false; - } - uid = strtol(value, &endptr, 10); - ret = (*endptr == '\0'); - SAFE_FREE(value); - if (ret) { - *puid = uid; - *expired = (timeout <= time(NULL)); - } - return ret; -} - -/** - * Find a uid2sid mapping - * @param[in] uid the uid to map - * @param[out] sid where to put the result - * @param[out] expired is the cache entry expired? - * @retval Was anything in the cache at all? - * - * If "is_null_sid(sid)", this was a negative mapping. - */ - -bool idmap_cache_find_uid2sid(uid_t uid, struct dom_sid *sid, bool *expired) -{ - char *key; - char *value; - time_t timeout; - bool ret = true; - - key = talloc_asprintf(talloc_tos(), "IDMAP/UID2SID/%d", (int)uid); - if (key == NULL) { - return false; - } - ret = gencache_get(key, &value, &timeout); - TALLOC_FREE(key); - if (!ret) { - return false; - } - ZERO_STRUCTP(sid); - if (value[0] != '-') { - ret = string_to_sid(sid, value); - } - SAFE_FREE(value); - if (ret) { - *expired = (timeout <= time(NULL)); - } - return ret; -} - -/** - * Store a mapping in the idmap cache - * @param[in] sid the sid to map - * @param[in] uid the uid to map - * - * If both parameters are valid values, then a positive mapping in both - * directions is stored. If "is_null_sid(sid)" is true, then this will be a - * negative mapping of uid, we want to cache that for this uid we could not - * find anything. Likewise if "uid==-1", then we want to cache that we did not - * find a mapping for the sid passed here. - */ - -void idmap_cache_set_sid2uid(const struct dom_sid *sid, uid_t uid) -{ - time_t now = time(NULL); - time_t timeout; - fstring sidstr, key, value; - - if (!is_null_sid(sid)) { - fstr_sprintf(key, "IDMAP/SID2UID/%s", - sid_to_fstring(sidstr, sid)); - fstr_sprintf(value, "%d", (int)uid); - timeout = (uid == -1) - ? lp_idmap_negative_cache_time() - : lp_idmap_cache_time(); - gencache_set(key, value, now + timeout); - } - if (uid != -1) { - fstr_sprintf(key, "IDMAP/UID2SID/%d", (int)uid); - if (is_null_sid(sid)) { - /* negative uid mapping */ - fstrcpy(value, "-"); - timeout = lp_idmap_negative_cache_time(); - } - else { - sid_to_fstring(value, sid); - timeout = lp_idmap_cache_time(); - } - gencache_set(key, value, now + timeout); - } -} - -/** - * Find a sid2gid mapping - * @param[in] sid the sid to map - * @param[out] pgid where to put the result - * @param[out] expired is the cache entry expired? - * @retval Was anything in the cache at all? - * - * If *pgid == -1 this was a negative mapping. - */ - -bool idmap_cache_find_sid2gid(const struct dom_sid *sid, gid_t *pgid, - bool *expired) -{ - fstring sidstr; - char *key; - char *value; - char *endptr; - time_t timeout; - gid_t gid; - bool ret; - - key = talloc_asprintf(talloc_tos(), "IDMAP/SID2GID/%s", - sid_to_fstring(sidstr, sid)); - if (key == NULL) { - return false; - } - ret = gencache_get(key, &value, &timeout); - TALLOC_FREE(key); - if (!ret) { - return false; - } - gid = strtol(value, &endptr, 10); - ret = (*endptr == '\0'); - SAFE_FREE(value); - if (ret) { - *pgid = gid; - *expired = (timeout <= time(NULL)); - } - return ret; -} - -/** - * Find a gid2sid mapping - * @param[in] gid the gid to map - * @param[out] sid where to put the result - * @param[out] expired is the cache entry expired? - * @retval Was anything in the cache at all? - * - * If "is_null_sid(sid)", this was a negative mapping. - */ - -bool idmap_cache_find_gid2sid(gid_t gid, struct dom_sid *sid, bool *expired) -{ - char *key; - char *value; - time_t timeout; - bool ret = true; - - key = talloc_asprintf(talloc_tos(), "IDMAP/GID2SID/%d", (int)gid); - if (key == NULL) { - return false; - } - ret = gencache_get(key, &value, &timeout); - TALLOC_FREE(key); - if (!ret) { - return false; - } - ZERO_STRUCTP(sid); - if (value[0] != '-') { - ret = string_to_sid(sid, value); - } - SAFE_FREE(value); - if (ret) { - *expired = (timeout <= time(NULL)); - } - return ret; -} - -/** - * Store a mapping in the idmap cache - * @param[in] sid the sid to map - * @param[in] gid the gid to map - * - * If both parameters are valid values, then a positive mapping in both - * directions is stored. If "is_null_sid(sid)" is true, then this will be a - * negative mapping of gid, we want to cache that for this gid we could not - * find anything. Likewise if "gid==-1", then we want to cache that we did not - * find a mapping for the sid passed here. - */ - -void idmap_cache_set_sid2gid(const struct dom_sid *sid, gid_t gid) -{ - time_t now = time(NULL); - time_t timeout; - fstring sidstr, key, value; - - if (!is_null_sid(sid)) { - fstr_sprintf(key, "IDMAP/SID2GID/%s", - sid_to_fstring(sidstr, sid)); - fstr_sprintf(value, "%d", (int)gid); - timeout = (gid == -1) - ? lp_idmap_negative_cache_time() - : lp_idmap_cache_time(); - gencache_set(key, value, now + timeout); - } - if (gid != -1) { - fstr_sprintf(key, "IDMAP/GID2SID/%d", (int)gid); - if (is_null_sid(sid)) { - /* negative gid mapping */ - fstrcpy(value, "-"); - timeout = lp_idmap_negative_cache_time(); - } - else { - sid_to_fstring(value, sid); - timeout = lp_idmap_cache_time(); - } - gencache_set(key, value, now + timeout); - } -} diff --git a/source/lib/ldb/common/ldb.c b/source/lib/ldb/common/ldb.c index c8aa6afdfc..743711b967 100644 --- a/source/lib/ldb/common/ldb.c +++ b/source/lib/ldb/common/ldb.c @@ -787,7 +787,6 @@ int ldb_search(struct ldb_context *ldb, done: if (ret != LDB_SUCCESS) { talloc_free(res); - res = NULL; } *_res = res; diff --git a/source/lib/ldb/web/index.html b/source/lib/ldb/web/index.html index 4c569caa25..2715a0d8bd 100644 --- a/source/lib/ldb/web/index.html +++ b/source/lib/ldb/web/index.html @@ -41,9 +41,9 @@ The main features that separate ldb from other solutions are: Currently ldb is completely lacking in programmer or user documentation. This is your opportunity to make a contribution! Start with the public functions declared in <a -href="http://samba.org/ftp/unpacked/ldb/include/ldb.h">ldb.h</a> +href="http://samba.org/ftp/unpacked/samba4/source/lib/ldb/include/ldb.h">ldb.h</a> and the example code in the <a -href="http://samba.org/ftp/unpacked/ldb/tools/">tools +href="http://samba.org/ftp/unpacked/samba4/source/lib/ldb/tools/">tools directory</a>. Documentation in the same docbook format used by Samba would be preferred. @@ -52,17 +52,21 @@ would be preferred. ldb does not currently have its own mailing list or bug tracking system. For now, please use the <a href="https://lists.samba.org/mailman/listinfo/samba-technical">samba-technical</a> -mailing list or the <a href="https://lists.samba.org/mailman/listinfo/ldb">ldb</a> -mailing list, and the <a href="http://bugzilla.samba.org/">Samba bugzilla</a> bug tracking system. +mailing list, and the <a href="http://bugzilla.samba.org/">Samba +bugzilla</a> bug tracking system. <h2>Download</h2> -You can download the latest release either via rsync or thtough git.<br> -<br> -To fetch via git see the following guide:<br> -<a href="http://wiki.samba.org/index.php/Using_Git_for_Samba_Development">Using Git for Samba Development</a><br> -Once you have cloned the tree switch to the v4-0-test branch and cd into the source/lib/ldb directory.<br> -<br> +You can download the latest release either via rsync or anonymous +svn. To fetch via svn use the following commands: + +<pre> + svn co svn://svnanon.samba.org/samba/branches/SAMBA_4_0/source/lib/ldb ldb + svn co svn://svnanon.samba.org/samba/branches/SAMBA_4_0/source/lib/tdb tdb + svn co svn://svnanon.samba.org/samba/branches/SAMBA_4_0/source/lib/talloc talloc + svn co svn://svnanon.samba.org/samba/branches/SAMBA_4_0/source/lib/replace libreplace +</pre> + To fetch via rsync use these commands: <pre> diff --git a/source/lib/messages.c b/source/lib/messages.c index f5933cafdb..ea03f8d43b 100644 --- a/source/lib/messages.c +++ b/source/lib/messages.c @@ -211,7 +211,7 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, status = messaging_ctdbd_init(ctx, ctx, &ctx->remote); if (!NT_STATUS_IS_OK(status)) { - DEBUG(1, ("messaging_ctdb_init failed: %s\n", + DEBUG(0, ("messaging_ctdb_init failed: %s\n", nt_errstr(status))); TALLOC_FREE(ctx); return NULL; @@ -246,7 +246,7 @@ NTSTATUS messaging_reinit(struct messaging_context *msg_ctx) &msg_ctx->remote); if (!NT_STATUS_IS_OK(status)) { - DEBUG(1, ("messaging_ctdb_init failed: %s\n", + DEBUG(0, ("messaging_ctdb_init failed: %s\n", nt_errstr(status))); return status; } diff --git a/source/lib/messages_ctdbd.c b/source/lib/messages_ctdbd.c index 847ab0fe6a..7d182a57d8 100644 --- a/source/lib/messages_ctdbd.c +++ b/source/lib/messages_ctdbd.c @@ -53,8 +53,9 @@ struct ctdbd_connection *messaging_ctdbd_connection(void) msg = messaging_init(NULL, procid_self(), ev); if (!msg) { DEBUG(0,("messaging_init failed\n")); - return NULL; } + + db_tdb2_setup_messaging(msg, false); } if (global_ctdb_connection_pid != getpid()) { diff --git a/source/lib/messages_local.c b/source/lib/messages_local.c index f436afc2ff..0cd482647a 100644 --- a/source/lib/messages_local.c +++ b/source/lib/messages_local.c @@ -65,8 +65,8 @@ static void sig_usr1(void) static int messaging_tdb_destructor(struct messaging_backend *tdb_ctx) { - struct tdb_wrap *tdb = (struct tdb_wrap *)tdb_ctx->private_data; - TALLOC_FREE(tdb); + TDB_CONTEXT *tdb = (TDB_CONTEXT *)tdb_ctx->private_data; + tdb_close(tdb); return 0; } @@ -79,16 +79,16 @@ NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx, struct messaging_backend **presult) { struct messaging_backend *result; - struct tdb_wrap *tdb; + TDB_CONTEXT *tdb; if (!(result = TALLOC_P(mem_ctx, struct messaging_backend))) { DEBUG(0, ("talloc failed\n")); return NT_STATUS_NO_MEMORY; } - tdb = tdb_wrap_open(result, lock_path("messages.tdb"), - 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT, - O_RDWR|O_CREAT,0600); + tdb = tdb_open_log(lock_path("messages.tdb"), + 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT, + O_RDWR|O_CREAT,0600); if (!tdb) { NTSTATUS status = map_nt_error_from_unix(errno); @@ -101,7 +101,7 @@ NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx, sec_init(); /* Activate the per-hashchain freelist */ - tdb_set_max_dead(tdb->tdb, 5); + tdb_set_max_dead(tdb, 5); CatchSignal(SIGUSR1, SIGNAL_CAST sig_usr1); @@ -293,7 +293,7 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx, struct messaging_rec *rec; NTSTATUS status; TDB_DATA key; - struct tdb_wrap *tdb = (struct tdb_wrap *)backend->private_data; + TDB_CONTEXT *tdb = (TDB_CONTEXT *)backend->private_data; TALLOC_CTX *frame = talloc_stackframe(); /* NULL pointer means implicit length zero. */ @@ -310,12 +310,12 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx, key = message_key_pid(frame, pid); - if (tdb_chainlock(tdb->tdb, key) == -1) { + if (tdb_chainlock(tdb, key) == -1) { TALLOC_FREE(frame); return NT_STATUS_LOCK_NOT_GRANTED; } - status = messaging_tdb_fetch(tdb->tdb, key, talloc_tos(), &msg_array); + status = messaging_tdb_fetch(tdb, key, talloc_tos(), &msg_array); if (!NT_STATUS_IS_OK(status)) { goto done; @@ -345,7 +345,7 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx, msg_array->messages = rec; msg_array->num_messages += 1; - status = messaging_tdb_store(tdb->tdb, key, msg_array); + status = messaging_tdb_store(tdb, key, msg_array); if (!NT_STATUS_IS_OK(status)) { goto done; @@ -356,11 +356,11 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx, if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) { DEBUG(2, ("pid %s doesn't exist - deleting messages record\n", procid_str_static(&pid))); - tdb_delete(tdb->tdb, message_key_pid(talloc_tos(), pid)); + tdb_delete(tdb, message_key_pid(talloc_tos(), pid)); } done: - tdb_chainunlock(tdb->tdb, key); + tdb_chainunlock(tdb, key); TALLOC_FREE(frame); return status; } @@ -409,8 +409,7 @@ static NTSTATUS retrieve_all_messages(TDB_CONTEXT *msg_tdb, void message_dispatch(struct messaging_context *msg_ctx) { struct messaging_array *msg_array = NULL; - struct tdb_wrap *tdb = (struct tdb_wrap *) - (msg_ctx->local->private_data); + TDB_CONTEXT *tdb = (TDB_CONTEXT *)(msg_ctx->local->private_data); uint32 i; if (!received_signal) @@ -421,8 +420,7 @@ void message_dispatch(struct messaging_context *msg_ctx) received_signal = 0; - if (!NT_STATUS_IS_OK(retrieve_all_messages(tdb->tdb, NULL, - &msg_array))) { + if (!NT_STATUS_IS_OK(retrieve_all_messages(tdb, NULL, &msg_array))) { return; } diff --git a/source/lib/module.c b/source/lib/module.c index 76983387ff..2e56e8e8b9 100644 --- a/source/lib/module.c +++ b/source/lib/module.c @@ -118,7 +118,7 @@ NTSTATUS smb_probe_module(const char *subsystem, const char *module) full_path = talloc_asprintf(ctx, "%s/%s.%s", - modules_path(subsystem), + lib_path(subsystem), module, shlib_ext()); if (!full_path) { diff --git a/source/lib/ms_fnmatch.c b/source/lib/ms_fnmatch.c index ca534467fa..8b69f1c2d2 100644 --- a/source/lib/ms_fnmatch.c +++ b/source/lib/ms_fnmatch.c @@ -154,7 +154,6 @@ int ms_fnmatch(const char *pattern, const char *string, bool translate_pattern, struct max_n *max_n = NULL; struct max_n *max_n_free = NULL; struct max_n one_max_n; - size_t converted_size; if (ISDOTDOT(string)) { string = "."; @@ -170,11 +169,11 @@ int ms_fnmatch(const char *pattern, const char *string, bool translate_pattern, } } - if (!push_ucs2_allocate(&p, pattern, &converted_size)) { + if (push_ucs2_allocate(&p, pattern) == (size_t)-1) { return -1; } - if (!push_ucs2_allocate(&s, string, &converted_size)) { + if (push_ucs2_allocate(&s, string) == (size_t)-1) { SAFE_FREE(p); return -1; } diff --git a/source/lib/netapi/cm.c b/source/lib/netapi/cm.c index a5c85bfe6b..071ebfd4bc 100644 --- a/source/lib/netapi/cm.c +++ b/source/lib/netapi/cm.c @@ -25,9 +25,9 @@ /******************************************************************** ********************************************************************/ -static WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx, - const char *server_name, - struct cli_state **cli) +WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx, + const char *server_name, + struct cli_state **cli) { struct cli_state *cli_ipc = NULL; @@ -91,107 +91,98 @@ static struct client_pipe_connection *pipe_connections; /******************************************************************** ********************************************************************/ -static NTSTATUS pipe_cm_find(struct cli_state *cli, - const struct ndr_syntax_id *interface, - struct rpc_pipe_client **presult) +static struct rpc_pipe_client *pipe_cm_find(struct cli_state *cli, + int pipe_idx, + NTSTATUS *status) { struct client_pipe_connection *p; for (p = pipe_connections; p; p = p->next) { - if (!rpc_pipe_np_smb_conn(p->pipe)) { - return NT_STATUS_PIPE_EMPTY; + if (!p->pipe->cli) { + *status = NT_STATUS_PIPE_EMPTY; + return NULL; } - if (strequal(cli->desthost, p->pipe->desthost) - && ndr_syntax_id_equal(&p->pipe->abstract_syntax, - interface)) { - *presult = p->pipe; - return NT_STATUS_OK; + if (strequal(cli->desthost, p->pipe->cli->desthost) && + pipe_idx == p->pipe->pipe_idx) { + *status = NT_STATUS_OK; + return p->pipe; } } - return NT_STATUS_PIPE_NOT_AVAILABLE; + *status = NT_STATUS_PIPE_NOT_AVAILABLE; + + return NULL; } /******************************************************************** ********************************************************************/ -static NTSTATUS pipe_cm_connect(TALLOC_CTX *mem_ctx, - struct cli_state *cli, - const struct ndr_syntax_id *interface, - struct rpc_pipe_client **presult) +static struct rpc_pipe_client *pipe_cm_connect(TALLOC_CTX *mem_ctx, + struct cli_state *cli, + int pipe_idx, + NTSTATUS *status) { struct client_pipe_connection *p; - NTSTATUS status; p = TALLOC_ZERO_ARRAY(mem_ctx, struct client_pipe_connection, 1); if (!p) { - return NT_STATUS_NO_MEMORY; + *status = NT_STATUS_NO_MEMORY; + return NULL; } - status = cli_rpc_pipe_open_noauth(cli, interface, &p->pipe); - if (!NT_STATUS_IS_OK(status)) { + p->pipe = cli_rpc_pipe_open_noauth(cli, pipe_idx, status); + if (!p->pipe) { TALLOC_FREE(p); - return status; + return NULL; } DLIST_ADD(pipe_connections, p); - *presult = p->pipe; - return NT_STATUS_OK; + return p->pipe; } /******************************************************************** ********************************************************************/ -static NTSTATUS pipe_cm_open(TALLOC_CTX *ctx, - struct cli_state *cli, - const struct ndr_syntax_id *interface, - struct rpc_pipe_client **presult) +static struct rpc_pipe_client *pipe_cm_open(TALLOC_CTX *ctx, + struct cli_state *cli, + int pipe_idx, + NTSTATUS *status) { - if (NT_STATUS_IS_OK(pipe_cm_find(cli, interface, presult))) { - return NT_STATUS_OK; + struct rpc_pipe_client *p; + + p = pipe_cm_find(cli, pipe_idx, status); + if (!p) { + p = pipe_cm_connect(ctx, cli, pipe_idx, status); } - return pipe_cm_connect(ctx, cli, interface, presult); + return p; } /******************************************************************** ********************************************************************/ WERROR libnetapi_open_pipe(struct libnetapi_ctx *ctx, - const char *server_name, - const struct ndr_syntax_id *interface, - struct cli_state **pcli, - struct rpc_pipe_client **presult) + struct cli_state *cli, + int pipe_idx, + struct rpc_pipe_client **pipe_cli) { - struct rpc_pipe_client *result = NULL; NTSTATUS status; - WERROR werr; - struct cli_state *cli = NULL; - if (!presult) { + if (!cli || !pipe_cli) { return WERR_INVALID_PARAM; } - werr = libnetapi_open_ipc_connection(ctx, server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - return werr; - } - - status = pipe_cm_open(ctx, cli, interface, &result); - if (!NT_STATUS_IS_OK(status)) { + *pipe_cli = pipe_cm_open(ctx, cli, pipe_idx, &status); + if (!*pipe_cli) { libnetapi_set_error_string(ctx, "failed to open PIPE %s: %s", - cli_get_pipe_name_from_iface(debug_ctx(), cli, - interface), + cli_get_pipe_name(pipe_idx), get_friendly_nt_error_msg(status)); return WERR_DEST_NOT_FOUND; } - *presult = result; - *pcli = cli; - return WERR_OK; } diff --git a/source/lib/netapi/examples/Makefile.in b/source/lib/netapi/examples/Makefile.in index b1c1e59be7..1e2e28c471 100644 --- a/source/lib/netapi/examples/Makefile.in +++ b/source/lib/netapi/examples/Makefile.in @@ -22,47 +22,10 @@ PROGS = bin/getdc@EXEEXT@ \ bin/netdomjoin@EXEEXT@ \ bin/netdomjoin-gui@EXEEXT@ \ bin/getjoinableous@EXEEXT@ \ - bin/rename_machine@EXEEXT@ \ bin/user_add@EXEEXT@ \ bin/user_del@EXEEXT@ \ bin/user_enum@EXEEXT@ \ - bin/user_dispinfo@EXEEXT@ \ - bin/user_chgpwd@EXEEXT@ \ - bin/user_getinfo@EXEEXT@ \ - bin/user_setinfo@EXEEXT@ \ - bin/user_modalsget@EXEEXT@ \ - bin/user_modalsset@EXEEXT@ \ - bin/user_getgroups@EXEEXT@ \ - bin/user_setgroups@EXEEXT@ \ - bin/user_getlocalgroups@EXEEXT@ \ - bin/group_add@EXEEXT@ \ - bin/group_del@EXEEXT@ \ - bin/group_enum@EXEEXT@ \ - bin/group_setinfo@EXEEXT@ \ - bin/group_getinfo@EXEEXT@ \ - bin/group_adduser@EXEEXT@ \ - bin/group_deluser@EXEEXT@ \ - bin/group_getusers@EXEEXT@ \ - bin/group_setusers@EXEEXT@ \ - bin/localgroup_add@EXEEXT@ \ - bin/localgroup_del@EXEEXT@ \ - bin/localgroup_getinfo@EXEEXT@ \ - bin/localgroup_setinfo@EXEEXT@ \ - bin/localgroup_enum@EXEEXT@ \ - bin/localgroup_addmembers@EXEEXT@ \ - bin/localgroup_delmembers@EXEEXT@ \ - bin/localgroup_setmembers@EXEEXT@ \ - bin/localgroup_getmembers@EXEEXT@ \ - bin/remote_tod@EXEEXT@ \ - bin/server_getinfo@EXEEXT@ \ - bin/share_add@EXEEXT@ \ - bin/share_del@EXEEXT@ \ - bin/share_enum@EXEEXT@ \ - bin/share_getinfo@EXEEXT@ \ - bin/share_setinfo@EXEEXT@ \ - bin/file_close@EXEEXT@ \ - bin/file_getinfo@EXEEXT@ \ - bin/file_enum@EXEEXT@ + bin/user_dispinfo@EXEEXT@ all: $(PROGS) @@ -93,50 +56,13 @@ bin/.dummy: CMDLINE_OBJ = common.o GETDC_OBJ = getdc/getdc.o $(CMDLINE_OBJ) DSGETDC_OBJ = dsgetdc/dsgetdc.o $(CMDLINE_OBJ) -NETDOMJOIN_OBJ = join/netdomjoin.o $(CMDLINE_OBJ) +NETDOMJOIN_OBJ = netdomjoin/netdomjoin.o $(CMDLINE_OBJ) NETDOMJOIN_GUI_OBJ = netdomjoin-gui/netdomjoin-gui.o -GETJOINABLEOUS_OBJ = join/getjoinableous.o $(CMDLINE_OBJ) -RENAMEMACHINE_OBJ = join/rename_machine.o $(CMDLINE_OBJ) +GETJOINABLEOUS_OBJ = getjoinableous/getjoinableous.o $(CMDLINE_OBJ) USERADD_OBJ = user/user_add.o $(CMDLINE_OBJ) USERDEL_OBJ = user/user_del.o $(CMDLINE_OBJ) USERENUM_OBJ = user/user_enum.o $(CMDLINE_OBJ) USERDISPINFO_OBJ = user/user_dispinfo.o $(CMDLINE_OBJ) -USERCHGPWD_OBJ = user/user_chgpwd.o $(CMDLINE_OBJ) -USERGETINFO_OBJ = user/user_getinfo.o $(CMDLINE_OBJ) -USERSETINFO_OBJ = user/user_setinfo.o $(CMDLINE_OBJ) -USERMODALSGET_OBJ = user/user_modalsget.o $(CMDLINE_OBJ) -USERMODALSSET_OBJ = user/user_modalsset.o $(CMDLINE_OBJ) -USERGETGROUPS_OBJ = user/user_getgroups.o $(CMDLINE_OBJ) -USERSETGROUPS_OBJ = user/user_setgroups.o $(CMDLINE_OBJ) -USERGETLOCALGROUPS_OBJ = user/user_getlocalgroups.o $(CMDLINE_OBJ) -GROUPADD_OBJ = group/group_add.o $(CMDLINE_OBJ) -GROUPDEL_OBJ = group/group_del.o $(CMDLINE_OBJ) -GROUPENUM_OBJ = group/group_enum.o $(CMDLINE_OBJ) -GROUPSETINFO_OBJ = group/group_setinfo.o $(CMDLINE_OBJ) -GROUPGETINFO_OBJ = group/group_getinfo.o $(CMDLINE_OBJ) -GROUPADDUSER_OBJ = group/group_adduser.o $(CMDLINE_OBJ) -GROUPDELUSER_OBJ = group/group_deluser.o $(CMDLINE_OBJ) -GROUPGETUSERS_OBJ = group/group_getusers.o $(CMDLINE_OBJ) -GROUPSETUSERS_OBJ = group/group_setusers.o $(CMDLINE_OBJ) -LOCALGROUPADD_OBJ = localgroup/localgroup_add.o $(CMDLINE_OBJ) -LOCALGROUPDEL_OBJ = localgroup/localgroup_del.o $(CMDLINE_OBJ) -LOCALGROUPGETINFO_OBJ = localgroup/localgroup_getinfo.o $(CMDLINE_OBJ) -LOCALGROUPSETINFO_OBJ = localgroup/localgroup_setinfo.o $(CMDLINE_OBJ) -LOCALGROUPENUM_OBJ = localgroup/localgroup_enum.o $(CMDLINE_OBJ) -LOCALGROUPADDMEMBERS_OBJ = localgroup/localgroup_addmembers.o $(CMDLINE_OBJ) -LOCALGROUPDELMEMBERS_OBJ = localgroup/localgroup_delmembers.o $(CMDLINE_OBJ) -LOCALGROUPSETMEMBERS_OBJ = localgroup/localgroup_setmembers.o $(CMDLINE_OBJ) -LOCALGROUPGETMEMBERS_OBJ = localgroup/localgroup_getmembers.o $(CMDLINE_OBJ) -REMOTETOD_OBJ = server/remote_tod.o $(CMDLINE_OBJ) -SERVERGETINFO_OBJ = server/server_getinfo.o $(CMDLINE_OBJ) -SHAREADD_OBJ = share/share_add.o $(CMDLINE_OBJ) -SHAREDEL_OBJ = share/share_del.o $(CMDLINE_OBJ) -SHAREENUM_OBJ = share/share_enum.o $(CMDLINE_OBJ) -SHAREGETINFO_OBJ = share/share_getinfo.o $(CMDLINE_OBJ) -SHARESETINFO_OBJ = share/share_setinfo.o $(CMDLINE_OBJ) -FILECLOSE_OBJ = file/file_close.o $(CMDLINE_OBJ) -FILEGETINFO_OBJ = file/file_getinfo.o $(CMDLINE_OBJ) -FILEENUM_OBJ = file/file_enum.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -150,10 +76,6 @@ bin/getjoinableous@EXEEXT@: $(BINARY_PREREQS) $(GETJOINABLEOUS_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GETJOINABLEOUS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) -bin/rename_machine@EXEEXT@: $(BINARY_PREREQS) $(RENAMEMACHINE_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(RENAMEMACHINE_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - bin/netdomjoin@EXEEXT@: $(BINARY_PREREQS) $(NETDOMJOIN_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(NETDOMJOIN_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) @@ -178,150 +100,6 @@ bin/user_dispinfo@EXEEXT@: $(BINARY_PREREQS) $(USERDISPINFO_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(USERDISPINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) -bin/user_chgpwd@EXEEXT@: $(BINARY_PREREQS) $(USERCHGPWD_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(USERCHGPWD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/user_getinfo@EXEEXT@: $(BINARY_PREREQS) $(USERGETINFO_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(USERGETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/user_setinfo@EXEEXT@: $(BINARY_PREREQS) $(USERSETINFO_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(USERSETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/user_modalsget@EXEEXT@: $(BINARY_PREREQS) $(USERMODALSGET_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(USERMODALSGET_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/user_modalsset@EXEEXT@: $(BINARY_PREREQS) $(USERMODALSSET_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(USERMODALSSET_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/user_getgroups@EXEEXT@: $(BINARY_PREREQS) $(USERGETGROUPS_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(USERGETGROUPS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/user_setgroups@EXEEXT@: $(BINARY_PREREQS) $(USERSETGROUPS_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(USERSETGROUPS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/user_getlocalgroups@EXEEXT@: $(BINARY_PREREQS) $(USERGETLOCALGROUPS_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(USERGETLOCALGROUPS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/group_add@EXEEXT@: $(BINARY_PREREQS) $(GROUPADD_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(GROUPADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/group_del@EXEEXT@: $(BINARY_PREREQS) $(GROUPDEL_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(GROUPDEL_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/group_enum@EXEEXT@: $(BINARY_PREREQS) $(GROUPENUM_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(GROUPENUM_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/group_setinfo@EXEEXT@: $(BINARY_PREREQS) $(GROUPSETINFO_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(GROUPSETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/group_getinfo@EXEEXT@: $(BINARY_PREREQS) $(GROUPGETINFO_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(GROUPGETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/group_adduser@EXEEXT@: $(BINARY_PREREQS) $(GROUPADDUSER_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(GROUPADDUSER_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/group_deluser@EXEEXT@: $(BINARY_PREREQS) $(GROUPDELUSER_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(GROUPDELUSER_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/group_getusers@EXEEXT@: $(BINARY_PREREQS) $(GROUPGETUSERS_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(GROUPGETUSERS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/group_setusers@EXEEXT@: $(BINARY_PREREQS) $(GROUPSETUSERS_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(GROUPSETUSERS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/localgroup_add@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPADD_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(LOCALGROUPADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/localgroup_del@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPDEL_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(LOCALGROUPDEL_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/localgroup_getinfo@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPGETINFO_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(LOCALGROUPGETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/localgroup_setinfo@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPSETINFO_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(LOCALGROUPSETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/localgroup_enum@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPENUM_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(LOCALGROUPENUM_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/localgroup_addmembers@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPADDMEMBERS_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(LOCALGROUPADDMEMBERS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/localgroup_delmembers@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPDELMEMBERS_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(LOCALGROUPDELMEMBERS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/localgroup_setmembers@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPSETMEMBERS_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(LOCALGROUPSETMEMBERS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/localgroup_getmembers@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPGETMEMBERS_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(LOCALGROUPGETMEMBERS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/remote_tod@EXEEXT@: $(BINARY_PREREQS) $(REMOTETOD_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(REMOTETOD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/server_getinfo@EXEEXT@: $(BINARY_PREREQS) $(SERVERGETINFO_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(SERVERGETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/share_add@EXEEXT@: $(BINARY_PREREQS) $(SHAREADD_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(SHAREADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/share_del@EXEEXT@: $(BINARY_PREREQS) $(SHAREDEL_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(SHAREDEL_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/share_enum@EXEEXT@: $(BINARY_PREREQS) $(SHAREENUM_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(SHAREENUM_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/share_getinfo@EXEEXT@: $(BINARY_PREREQS) $(SHAREGETINFO_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(SHAREGETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/share_setinfo@EXEEXT@: $(BINARY_PREREQS) $(SHARESETINFO_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(SHARESETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/file_close@EXEEXT@: $(BINARY_PREREQS) $(FILECLOSE_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(FILECLOSE_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/file_getinfo@EXEEXT@: $(BINARY_PREREQS) $(FILEGETINFO_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(FILEGETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -bin/file_enum@EXEEXT@: $(BINARY_PREREQS) $(FILEENUM_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(FILEENUM_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source/lib/netapi/examples/file/file_close.c b/source/lib/netapi/examples/file/file_close.c deleted file mode 100644 index 759173a0ec..0000000000 --- a/source/lib/netapi/examples/file/file_close.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetFileClose query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - uint32_t fileid = 0; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("file_close", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname fileid"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - fileid = atoi(poptGetArg(pc)); - - /* NetFileClose */ - - status = NetFileClose(hostname, fileid); - if (status != 0) { - printf("NetFileClose failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/file/file_enum.c b/source/lib/netapi/examples/file/file_enum.c deleted file mode 100644 index 5fbb285194..0000000000 --- a/source/lib/netapi/examples/file/file_enum.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetFileEnum query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *basepath = NULL; - const char *username = NULL; - uint32_t level = 3; - uint8_t *buffer = NULL; - uint32_t entries_read = 0; - uint32_t total_entries = 0; - uint32_t resume_handle = 0; - int i; - - struct FILE_INFO_2 *i2 = NULL; - struct FILE_INFO_3 *i3 = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("file_enum", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname basepath username level"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - basepath = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - username = poptGetArg(pc); - - if (poptPeekArg(pc)) { - level = atoi(poptGetArg(pc)); - } - - /* NetFileEnum */ - - do { - - status = NetFileEnum(hostname, - basepath, - username, - level, - &buffer, - (uint32_t)-1, - &entries_read, - &total_entries, - &resume_handle); - if (status == 0 || status == ERROR_MORE_DATA) { - printf("total entries: %d\n", total_entries); - switch (level) { - case 2: - i2 = (struct FILE_INFO_2 *)buffer; - break; - case 3: - i3 = (struct FILE_INFO_3 *)buffer; - break; - default: - break; - } - for (i=0; i<entries_read; i++) { - switch (level) { - case 2: - printf("file_id: %d\n", i2->fi2_id); - i2++; - break; - case 3: - printf("file_id: %d\n", i3->fi3_id); - printf("permissions: %d\n", i3->fi3_permissions); - printf("num_locks: %d\n", i3->fi3_num_locks); - printf("pathname: %s\n", i3->fi3_pathname); - printf("username: %s\n", i3->fi3_username); - i3++; - break; - default: - break; - } - } - NetApiBufferFree(buffer); - } - } while (status == ERROR_MORE_DATA); - - if (status != 0) { - printf("NetFileEnum failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/file/file_getinfo.c b/source/lib/netapi/examples/file/file_getinfo.c deleted file mode 100644 index 9ad8305bc5..0000000000 --- a/source/lib/netapi/examples/file/file_getinfo.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetFileGetInfo query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - uint32_t fileid = 0; - uint32_t level = 3; - uint8_t *buffer = NULL; - - struct FILE_INFO_2 *i2 = NULL; - struct FILE_INFO_3 *i3 = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("file_getinfo", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname fileid"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - fileid = atoi(poptGetArg(pc)); - - if (poptPeekArg(pc)) { - level = atoi(poptGetArg(pc)); - } - - /* NetFileGetInfo */ - - status = NetFileGetInfo(hostname, - fileid, - level, - &buffer); - if (status != 0) { - printf("NetFileGetInfo failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - switch (level) { - case 2: - i2 = (struct FILE_INFO_2 *)buffer; - printf("file_id: %d\n", i2->fi2_id); - break; - case 3: - i3 = (struct FILE_INFO_3 *)buffer; - printf("file_id: %d\n", i3->fi3_id); - printf("permissions: %d\n", i3->fi3_permissions); - printf("num_locks: %d\n", i3->fi3_num_locks); - printf("pathname: %s\n", i3->fi3_pathname); - printf("username: %s\n", i3->fi3_username); - break; - default: - break; - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/join/getjoinableous.c b/source/lib/netapi/examples/getjoinableous/getjoinableous.c index 732f73dd57..732f73dd57 100644 --- a/source/lib/netapi/examples/join/getjoinableous.c +++ b/source/lib/netapi/examples/getjoinableous/getjoinableous.c diff --git a/source/lib/netapi/examples/group/group_add.c b/source/lib/netapi/examples/group/group_add.c deleted file mode 100644 index 4da97c5fc5..0000000000 --- a/source/lib/netapi/examples/group/group_add.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetGroupAdd query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *groupname = NULL; - struct GROUP_INFO_1 g1; - uint32_t parm_error = 0; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("group_add", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname groupname"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - groupname = poptGetArg(pc); - - /* NetGroupAdd */ - - g1.grpi1_name = groupname; - g1.grpi1_comment = "Domain Group created using NetApi example code"; - - status = NetGroupAdd(hostname, - 1, - (uint8_t *)&g1, - &parm_error); - if (status != 0) { - printf("NetGroupAdd failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/group/group_adduser.c b/source/lib/netapi/examples/group/group_adduser.c deleted file mode 100644 index 253b3c5ab4..0000000000 --- a/source/lib/netapi/examples/group/group_adduser.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetGroupAddUser query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *groupname = NULL; - const char *username = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("group_adduser", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname groupname username"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - groupname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - username = poptGetArg(pc); - - /* NetGroupAddUser */ - - status = NetGroupAddUser(hostname, - groupname, - username); - if (status != 0) { - printf("NetGroupAddUser failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/group/group_del.c b/source/lib/netapi/examples/group/group_del.c deleted file mode 100644 index 789e429ea2..0000000000 --- a/source/lib/netapi/examples/group/group_del.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetGroupDel query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *groupname = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("group_del", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname groupname"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - groupname = poptGetArg(pc); - - /* NetGroupDel */ - - status = NetGroupDel(hostname, groupname); - if (status != 0) { - printf("NetGroupDel failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/group/group_deluser.c b/source/lib/netapi/examples/group/group_deluser.c deleted file mode 100644 index 751ab5c630..0000000000 --- a/source/lib/netapi/examples/group/group_deluser.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetGroupDelUser query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *groupname = NULL; - const char *username = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("group_deluser", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname groupname username"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - groupname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - username = poptGetArg(pc); - - /* NetGroupDelUser */ - - status = NetGroupDelUser(hostname, - groupname, - username); - if (status != 0) { - printf("NetGroupDelUser failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/group/group_enum.c b/source/lib/netapi/examples/group/group_enum.c deleted file mode 100644 index fe2aee1dab..0000000000 --- a/source/lib/netapi/examples/group/group_enum.c +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetGroupEnum query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - uint32_t level = 0; - uint8_t *buffer = NULL; - uint32_t entries_read = 0; - uint32_t total_entries = 0; - uint32_t resume_handle = 0; - int i; - char *sid_str = NULL; - - struct GROUP_INFO_0 *info0 = NULL; - struct GROUP_INFO_1 *info1 = NULL; - struct GROUP_INFO_2 *info2 = NULL; - struct GROUP_INFO_3 *info3 = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("group_enum", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname level"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (poptPeekArg(pc)) { - level = atoi(poptGetArg(pc)); - } - - /* NetGroupEnum */ - - do { - status = NetGroupEnum(hostname, - level, - &buffer, - (uint32_t)-1, - &entries_read, - &total_entries, - &resume_handle); - if (status == 0 || status == ERROR_MORE_DATA) { - printf("total entries: %d\n", total_entries); - switch (level) { - case 0: - info0 = (struct GROUP_INFO_0 *)buffer; - break; - case 1: - info1 = (struct GROUP_INFO_1 *)buffer; - break; - case 2: - info2 = (struct GROUP_INFO_2 *)buffer; - break; - case 3: - info3 = (struct GROUP_INFO_3 *)buffer; - break; - default: - break; - } - for (i=0; i<entries_read; i++) { - switch (level) { - case 0: - printf("#%d group: %s\n", i, info0->grpi0_name); - info0++; - break; - case 1: - printf("#%d group: %s\n", i, info1->grpi1_name); - printf("#%d comment: %s\n", i, info1->grpi1_comment); - info1++; - break; - case 2: - printf("#%d group: %s\n", i, info2->grpi2_name); - printf("#%d comment: %s\n", i, info2->grpi2_comment); - printf("#%d rid: %d\n", i, info2->grpi2_group_id); - printf("#%d attributes: 0x%08x\n", i, info2->grpi2_attributes); - info2++; - break; - case 3: - printf("#%d group: %s\n", i, info3->grpi3_name); - printf("#%d comment: %s\n", i, info3->grpi3_comment); - if (ConvertSidToStringSid(info3->grpi3_group_sid, - &sid_str)) { - printf("#%d group_sid: %s\n", i, sid_str); - free(sid_str); - } - printf("#%d attributes: 0x%08x\n", i, info3->grpi3_attributes); - info3++; - break; - - - } - } - NetApiBufferFree(buffer); - } - } while (status == ERROR_MORE_DATA); - - if (status != 0) { - printf("NetGroupEnum failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/group/group_getinfo.c b/source/lib/netapi/examples/group/group_getinfo.c deleted file mode 100644 index 2e5b793905..0000000000 --- a/source/lib/netapi/examples/group/group_getinfo.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetGroupGetInfo query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *groupname = NULL; - uint8_t *buffer = NULL; - uint32_t level = 0; - struct GROUP_INFO_0 *g0; - struct GROUP_INFO_1 *g1; - struct GROUP_INFO_2 *g2; - struct GROUP_INFO_3 *g3; - char *sid_str = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("group_getinfo", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname groupname level"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - groupname = poptGetArg(pc); - - if (poptPeekArg(pc)) { - level = atoi(poptGetArg(pc)); - } - - /* NetGroupGetInfo */ - - status = NetGroupGetInfo(hostname, - groupname, - level, - &buffer); - if (status != 0) { - printf("NetGroupGetInfo failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - switch (level) { - case 0: - g0 = (struct GROUP_INFO_0 *)buffer; - printf("name: %s\n", g0->grpi0_name); - break; - case 1: - g1 = (struct GROUP_INFO_1 *)buffer; - printf("name: %s\n", g1->grpi1_name); - printf("comment: %s\n", g1->grpi1_comment); - break; - case 2: - g2 = (struct GROUP_INFO_2 *)buffer; - printf("name: %s\n", g2->grpi2_name); - printf("comment: %s\n", g2->grpi2_comment); - printf("group_id: %d\n", g2->grpi2_group_id); - printf("attributes: %d\n", g2->grpi2_attributes); - break; - case 3: - g3 = (struct GROUP_INFO_3 *)buffer; - printf("name: %s\n", g3->grpi3_name); - printf("comment: %s\n", g3->grpi3_comment); - if (ConvertSidToStringSid(g3->grpi3_group_sid, - &sid_str)) { - printf("group_sid: %s\n", sid_str); - free(sid_str); - } - printf("attributes: %d\n", g3->grpi3_attributes); - break; - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/group/group_getusers.c b/source/lib/netapi/examples/group/group_getusers.c deleted file mode 100644 index 72e79ec3a2..0000000000 --- a/source/lib/netapi/examples/group/group_getusers.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetGroupGetUsers query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *groupname = NULL; - uint32_t level = 0; - uint8_t *buffer = NULL; - uint32_t entries_read = 0; - uint32_t total_entries = 0; - uint32_t resume_handle = 0; - int i; - - struct GROUP_USERS_INFO_0 *info0 = NULL; - struct GROUP_USERS_INFO_1 *info1 = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("group_getusers", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname groupname level"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - groupname = poptGetArg(pc); - - if (poptPeekArg(pc)) { - level = atoi(poptGetArg(pc)); - } - - /* NetGroupGetUsers */ - - do { - status = NetGroupGetUsers(hostname, - groupname, - level, - &buffer, - (uint32_t)-1, - &entries_read, - &total_entries, - &resume_handle); - if (status == 0 || status == ERROR_MORE_DATA) { - printf("total entries: %d\n", total_entries); - switch (level) { - case 0: - info0 = (struct GROUP_USERS_INFO_0 *)buffer; - break; - case 1: - info1 = (struct GROUP_USERS_INFO_1 *)buffer; - break; - default: - break; - } - for (i=0; i<entries_read; i++) { - switch (level) { - case 0: - printf("#%d member: %s\n", i, info0->grui0_name); - info0++; - break; - case 1: - printf("#%d member: %s\n", i, info1->grui1_name); - printf("#%d attributes: %d\n", i, info1->grui1_attributes); - info1++; - break; - } - } - NetApiBufferFree(buffer); - } - } while (status == ERROR_MORE_DATA); - - if (status != 0) { - printf("NetGroupGetUsers failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/group/group_setinfo.c b/source/lib/netapi/examples/group/group_setinfo.c deleted file mode 100644 index cd30d8b9b8..0000000000 --- a/source/lib/netapi/examples/group/group_setinfo.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetGroupSetInfo query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *groupname = NULL; - const char *option = NULL; - uint8_t *buffer = NULL; - uint32_t level = 0; - uint32_t parm_err = 0; - struct GROUP_INFO_0 g0; - struct GROUP_INFO_1 g1; - struct GROUP_INFO_2 g2; - struct GROUP_INFO_3 g3; - struct GROUP_INFO_1002 g1002; - struct GROUP_INFO_1005 g1005; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("group_setinfo", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname groupname level option"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - groupname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - level = atoi(poptGetArg(pc)); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - option = poptGetArg(pc); - - /* NetGroupSetInfo */ - - switch (level) { - case 0: - g0.grpi0_name = option; - buffer = (uint8_t *)&g0; - break; - case 1: - g1.grpi1_name = option; /* this one will be ignored */ - g1.grpi1_comment = option; - buffer = (uint8_t *)&g1; - break; - case 2: - g2.grpi2_name = option; /* this one will be ignored */ - g2.grpi2_comment = option; - g2.grpi2_group_id = 4711; /* this one will be ignored */ - g2.grpi2_attributes = 7; - buffer = (uint8_t *)&g2; - break; - case 3: - g3.grpi3_name = option; /* this one will be ignored */ - g3.grpi3_comment = option; - g2.grpi2_attributes = 7; - buffer = (uint8_t *)&g3; - break; - case 1002: - g1002.grpi1002_comment = option; - buffer = (uint8_t *)&g1002; - break; - case 1005: - g1005.grpi1005_attributes = atoi(option); - buffer = (uint8_t *)&g1005; - break; - } - - status = NetGroupSetInfo(hostname, - groupname, - level, - buffer, - &parm_err); - if (status != 0) { - printf("NetGroupSetInfo failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/group/group_setusers.c b/source/lib/netapi/examples/group/group_setusers.c deleted file mode 100644 index 70cf10514c..0000000000 --- a/source/lib/netapi/examples/group/group_setusers.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetGroupSetUsers query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *groupname = NULL; - uint32_t level = 0; - uint8_t *buffer = NULL; - uint32_t num_entries = 0; - const char **names = NULL; - int i = 0; - size_t buf_size = 0; - - struct GROUP_USERS_INFO_0 *g0 = NULL; - struct GROUP_USERS_INFO_1 *g1 = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("group_setusers", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname groupname level"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - groupname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - - names = poptGetArgs(pc); - for (i=0; names[i] != NULL; i++) { - num_entries++; - } - - switch (level) { - case 0: - buf_size = sizeof(struct GROUP_USERS_INFO_0) * num_entries; - - status = NetApiBufferAllocate(buf_size, (void **)&g0); - if (status) { - printf("NetApiBufferAllocate failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - for (i=0; i<num_entries; i++) { - g0[i].grui0_name = names[i]; - } - - buffer = (uint8_t *)g0; - break; - case 1: - buf_size = sizeof(struct GROUP_USERS_INFO_1) * num_entries; - - status = NetApiBufferAllocate(buf_size, (void **)&g1); - if (status) { - printf("NetApiBufferAllocate failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - for (i=0; i<num_entries; i++) { - g1[i].grui1_name = names[i]; - } - - buffer = (uint8_t *)g1; - break; - default: - break; - } - - /* NetGroupSetUsers */ - - status = NetGroupSetUsers(hostname, - groupname, - level, - buffer, - num_entries); - if (status != 0) { - printf("NetGroupSetUsers failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/join/rename_machine.c b/source/lib/netapi/examples/join/rename_machine.c deleted file mode 100644 index a21f9198d8..0000000000 --- a/source/lib/netapi/examples/join/rename_machine.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetRenameMachineInDomain query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <string.h> -#include <stdio.h> -#include <sys/types.h> -#include <inttypes.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - const char *host_name = NULL; - const char *new_machine_name = NULL; - uint32_t rename_opt = 0; - struct libnetapi_ctx *ctx = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("rename_machine", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname newmachinename"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - host_name = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - new_machine_name = poptGetArg(pc); - - /* NetRenameMachineInDomain */ - - status = NetRenameMachineInDomain(host_name, - new_machine_name, - ctx->username, - ctx->password, - rename_opt); - if (status != 0) { - printf("failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/localgroup/localgroup_add.c b/source/lib/netapi/examples/localgroup/localgroup_add.c deleted file mode 100644 index 7f23c99db1..0000000000 --- a/source/lib/netapi/examples/localgroup/localgroup_add.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetLocalGroupAdd query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *groupname = NULL; - const char *comment = NULL; - struct LOCALGROUP_INFO_0 g0; - struct LOCALGROUP_INFO_1 g1; - uint32_t parm_error = 0; - uint8_t *buf = NULL; - uint32_t level = 0; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("localgroup_add", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname groupname comment"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - groupname = poptGetArg(pc); - - if (poptPeekArg(pc)) { - comment = poptGetArg(pc); - } - - /* NetLocalGroupAdd */ - - if (comment) { - level = 1; - g1.lgrpi1_name = groupname; - g1.lgrpi1_comment = comment; - buf = (uint8_t *)&g1; - } else { - level = 0; - g0.lgrpi0_name = groupname; - buf = (uint8_t *)&g0; - } - - status = NetLocalGroupAdd(hostname, - level, - buf, - &parm_error); - if (status != 0) { - printf("NetLocalGroupAdd failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/localgroup/localgroup_addmembers.c b/source/lib/netapi/examples/localgroup/localgroup_addmembers.c deleted file mode 100644 index aa4a9b59b0..0000000000 --- a/source/lib/netapi/examples/localgroup/localgroup_addmembers.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetLocalGroupAddMembers query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *groupname = NULL; - struct LOCALGROUP_MEMBERS_INFO_0 *g0; - struct LOCALGROUP_MEMBERS_INFO_3 *g3; - uint32_t total_entries = 0; - uint8_t *buffer = NULL; - uint32_t level = 3; - const char **names = NULL; - int i = 0; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("localgroup_addmembers", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname groupname member1 member2 ..."); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - groupname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - - names = poptGetArgs(pc); - for (i=0; names[i] != NULL; i++) { - total_entries++; - } - - switch (level) { - case 0: - status = NetApiBufferAllocate(sizeof(struct LOCALGROUP_MEMBERS_INFO_0) * total_entries, - (void **)&g0); - if (status) { - printf("NetApiBufferAllocate failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - for (i=0; i<total_entries; i++) { - if (!ConvertStringSidToSid(names[i], &g0[i].lgrmi0_sid)) { - printf("could not convert sid\n"); - goto out; - } - } - - buffer = (uint8_t *)g0; - break; - case 3: - status = NetApiBufferAllocate(sizeof(struct LOCALGROUP_MEMBERS_INFO_3) * total_entries, - (void **)&g3); - if (status) { - printf("NetApiBufferAllocate failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - for (i=0; i<total_entries; i++) { - g3[i].lgrmi3_domainandname = names[i]; - } - - buffer = (uint8_t *)g3; - break; - default: - break; - } - - /* NetLocalGroupAddMembers */ - - status = NetLocalGroupAddMembers(hostname, - groupname, - level, - buffer, - total_entries); - if (status != 0) { - printf("NetLocalGroupAddMembers failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/localgroup/localgroup_del.c b/source/lib/netapi/examples/localgroup/localgroup_del.c deleted file mode 100644 index a2515dfdcd..0000000000 --- a/source/lib/netapi/examples/localgroup/localgroup_del.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetLocalGroupDel query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *groupname = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("localgroup_del", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname groupname"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - groupname = poptGetArg(pc); - - /* NetLocalGroupDel */ - - status = NetLocalGroupDel(hostname, - groupname); - if (status != 0) { - printf("NetLocalGroupDel failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/localgroup/localgroup_delmembers.c b/source/lib/netapi/examples/localgroup/localgroup_delmembers.c deleted file mode 100644 index 7bd3ec0993..0000000000 --- a/source/lib/netapi/examples/localgroup/localgroup_delmembers.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetLocalGroupDelMembers query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *groupname = NULL; - struct LOCALGROUP_MEMBERS_INFO_0 *g0; - struct LOCALGROUP_MEMBERS_INFO_3 *g3; - uint32_t total_entries = 0; - uint8_t *buffer = NULL; - uint32_t level = 3; - const char **names = NULL; - int i = 0; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("localgroup_delmembers", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname groupname member1 member2 ..."); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - groupname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - - names = poptGetArgs(pc); - for (i=0; names[i] != NULL; i++) { - total_entries++; - } - - switch (level) { - case 0: - status = NetApiBufferAllocate(sizeof(struct LOCALGROUP_MEMBERS_INFO_0) * total_entries, - (void **)&g0); - if (status) { - printf("NetApiBufferAllocate failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - for (i=0; i<total_entries; i++) { - if (!ConvertStringSidToSid(names[i], &g0[i].lgrmi0_sid)) { - printf("could not convert sid\n"); - goto out; - } - } - - buffer = (uint8_t *)g0; - break; - case 3: - status = NetApiBufferAllocate(sizeof(struct LOCALGROUP_MEMBERS_INFO_3) * total_entries, - (void **)&g3); - if (status) { - printf("NetApiBufferAllocate failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - for (i=0; i<total_entries; i++) { - g3[i].lgrmi3_domainandname = names[i]; - } - - buffer = (uint8_t *)g3; - break; - default: - break; - } - - /* NetLocalGroupDelMembers */ - - status = NetLocalGroupDelMembers(hostname, - groupname, - level, - buffer, - total_entries); - if (status != 0) { - printf("NetLocalGroupDelMembers failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/localgroup/localgroup_enum.c b/source/lib/netapi/examples/localgroup/localgroup_enum.c deleted file mode 100644 index 6fe0cf4173..0000000000 --- a/source/lib/netapi/examples/localgroup/localgroup_enum.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetLocalGroupEnum query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - uint32_t level = 0; - uint8_t *buffer = NULL; - uint32_t entries_read = 0; - uint32_t total_entries = 0; - uint32_t resume_handle = 0; - int i; - - struct LOCALGROUP_INFO_0 *info0 = NULL; - struct LOCALGROUP_INFO_1 *info1 = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("localgroup_enum", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname level"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (poptPeekArg(pc)) { - level = atoi(poptGetArg(pc)); - } - - /* NetLocalGroupEnum */ - - do { - status = NetLocalGroupEnum(hostname, - level, - &buffer, - (uint32_t)-1, - &entries_read, - &total_entries, - &resume_handle); - if (status == 0 || status == ERROR_MORE_DATA) { - printf("total entries: %d\n", total_entries); - switch (level) { - case 0: - info0 = (struct LOCALGROUP_INFO_0 *)buffer; - break; - case 1: - info1 = (struct LOCALGROUP_INFO_1 *)buffer; - break; - default: - break; - } - for (i=0; i<entries_read; i++) { - switch (level) { - case 0: - printf("#%d group: %s\n", i, info0->lgrpi0_name); - info0++; - break; - case 1: - printf("#%d group: %s\n", i, info1->lgrpi1_name); - printf("#%d comment: %s\n", i, info1->lgrpi1_comment); - info1++; - break; - default: - break; - } - } - NetApiBufferFree(buffer); - } - } while (status == ERROR_MORE_DATA); - - if (status != 0) { - printf("NetLocalGroupEnum failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/localgroup/localgroup_getinfo.c b/source/lib/netapi/examples/localgroup/localgroup_getinfo.c deleted file mode 100644 index cd8fa8c3b3..0000000000 --- a/source/lib/netapi/examples/localgroup/localgroup_getinfo.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetLocalGroupGetInfo query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *groupname = NULL; - uint8_t *buffer = NULL; - uint32_t level = 0; - struct LOCALGROUP_INFO_0 *g0; - struct LOCALGROUP_INFO_1 *g1; - struct LOCALGROUP_INFO_1002 *g1002; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("localgroup_getinfo", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname groupname level"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - groupname = poptGetArg(pc); - - if (poptPeekArg(pc)) { - level = atoi(poptGetArg(pc)); - } - - /* NetLocalGroupGetInfo */ - - status = NetLocalGroupGetInfo(hostname, - groupname, - level, - &buffer); - if (status != 0) { - printf("NetLocalGroupGetInfo failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - switch (level) { - case 0: - g0 = (struct LOCALGROUP_INFO_0 *)buffer; - printf("name: %s\n", g0->lgrpi0_name); - break; - case 1: - g1 = (struct LOCALGROUP_INFO_1 *)buffer; - printf("name: %s\n", g1->lgrpi1_name); - printf("comment: %s\n", g1->lgrpi1_comment); - break; - case 1002: - g1002 = (struct LOCALGROUP_INFO_1002 *)buffer; - printf("comment: %s\n", g1002->lgrpi1002_comment); - break; - } - NetApiBufferFree(buffer); - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/localgroup/localgroup_getmembers.c b/source/lib/netapi/examples/localgroup/localgroup_getmembers.c deleted file mode 100644 index 0589870d02..0000000000 --- a/source/lib/netapi/examples/localgroup/localgroup_getmembers.c +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetLocalGroupGetMembers query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *groupname = NULL; - uint32_t level = 0; - uint8_t *buffer = NULL; - uint32_t entries_read = 0; - uint32_t total_entries = 0; - uint32_t resume_handle = 0; - char *sid_str = NULL; - int i; - - struct LOCALGROUP_MEMBERS_INFO_0 *info0 = NULL; - struct LOCALGROUP_MEMBERS_INFO_1 *info1 = NULL; - struct LOCALGROUP_MEMBERS_INFO_2 *info2 = NULL; - struct LOCALGROUP_MEMBERS_INFO_3 *info3 = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("localgroup_getmembers", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname groupname level"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - groupname = poptGetArg(pc); - - if (poptPeekArg(pc)) { - level = atoi(poptGetArg(pc)); - } - - /* NetLocalGroupGetMembers */ - - do { - status = NetLocalGroupGetMembers(hostname, - groupname, - level, - &buffer, - (uint32_t)-1, - &entries_read, - &total_entries, - &resume_handle); - if (status == 0 || status == ERROR_MORE_DATA) { - printf("total entries: %d\n", total_entries); - switch (level) { - case 0: - info0 = (struct LOCALGROUP_MEMBERS_INFO_0 *)buffer; - break; - case 1: - info1 = (struct LOCALGROUP_MEMBERS_INFO_1 *)buffer; - break; - case 2: - info2 = (struct LOCALGROUP_MEMBERS_INFO_2 *)buffer; - break; - case 3: - info3 = (struct LOCALGROUP_MEMBERS_INFO_3 *)buffer; - break; - default: - break; - } - for (i=0; i<entries_read; i++) { - switch (level) { - case 0: - if (ConvertSidToStringSid(info0->lgrmi0_sid, - &sid_str)) { - printf("#%d member sid: %s\n", i, sid_str); - free(sid_str); - } - info0++; - break; - case 1: - if (ConvertSidToStringSid(info1->lgrmi1_sid, - &sid_str)) { - printf("#%d member sid: %s\n", i, sid_str); - free(sid_str); - } - printf("#%d sid type: %d\n", i, info1->lgrmi1_sidusage); - printf("#%d name: %s\n", i, info1->lgrmi1_name); - info1++; - break; - case 2: - if (ConvertSidToStringSid(info2->lgrmi2_sid, - &sid_str)) { - printf("#%d member sid: %s\n", i, sid_str); - free(sid_str); - } - printf("#%d sid type: %d\n", i, info2->lgrmi2_sidusage); - printf("#%d full name: %s\n", i, info2->lgrmi2_domainandname); - info2++; - break; - case 3: - printf("#%d full name: %s\n", i, info3->lgrmi3_domainandname); - info3++; - break; - default: - break; - } - } - NetApiBufferFree(buffer); - } - } while (status == ERROR_MORE_DATA); - - if (status != 0) { - printf("NetLocalGroupGetMembers failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/localgroup/localgroup_setinfo.c b/source/lib/netapi/examples/localgroup/localgroup_setinfo.c deleted file mode 100644 index efcec76786..0000000000 --- a/source/lib/netapi/examples/localgroup/localgroup_setinfo.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetLocalGroupSetInfo query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *groupname = NULL; - uint8_t *buffer = NULL; - uint32_t level = 0; - struct LOCALGROUP_INFO_0 g0; - struct LOCALGROUP_INFO_1 g1; - struct LOCALGROUP_INFO_1002 g1002; - const char *newname = NULL; - const char *newcomment = NULL; - uint32_t parm_err = 0; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - { "newname", 0, POPT_ARG_STRING, NULL, 'n', "New Local Group Name", "NEWNAME" }, - { "newcomment", 0, POPT_ARG_STRING, NULL, 'c', "New Local Group Comment", "NETCOMMENT" }, - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("localgroup_setinfo", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname groupname level"); - while((opt = poptGetNextOpt(pc)) != -1) { - switch (opt) { - case 'n': - newname = poptGetOptArg(pc); - break; - case 'c': - newcomment = poptGetOptArg(pc); - break; - } - - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - groupname = poptGetArg(pc); - - if (poptPeekArg(pc)) { - level = atoi(poptGetArg(pc)); - } - - if (newname && !newcomment) { - g0.lgrpi0_name = newname; - buffer = (uint8_t *)&g0; - level = 0; - } else if (newcomment && !newname) { - g1002.lgrpi1002_comment = newcomment; - buffer = (uint8_t *)&g1002; - level = 1002; - } else if (newname && newcomment) { - g1.lgrpi1_name = newname; - g1.lgrpi1_comment = newcomment; - buffer = (uint8_t *)&g1; - level = 1; - } else { - printf("not enough input\n"); - goto out; - } - - /* NetLocalGroupSetInfo */ - - status = NetLocalGroupSetInfo(hostname, - groupname, - level, - buffer, - &parm_err); - if (status != 0) { - printf("NetLocalGroupSetInfo failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/localgroup/localgroup_setmembers.c b/source/lib/netapi/examples/localgroup/localgroup_setmembers.c deleted file mode 100644 index c35f2bbb81..0000000000 --- a/source/lib/netapi/examples/localgroup/localgroup_setmembers.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetLocalGroupSetMembers query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *groupname = NULL; - struct LOCALGROUP_MEMBERS_INFO_0 *g0; - struct LOCALGROUP_MEMBERS_INFO_3 *g3; - uint32_t total_entries = 0; - uint8_t *buffer = NULL; - uint32_t level = 3; - const char **names = NULL; - int i = 0; - size_t buf_size = 0; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("localgroup_setmembers", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname groupname member1 member2 ..."); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - groupname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - - names = poptGetArgs(pc); - for (i=0; names[i] != NULL; i++) { - total_entries++; - } - - switch (level) { - case 0: - buf_size = sizeof(struct LOCALGROUP_MEMBERS_INFO_0) * total_entries; - - status = NetApiBufferAllocate(buf_size, (void **)&g0); - if (status) { - printf("NetApiBufferAllocate failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - for (i=0; i<total_entries; i++) { - if (!ConvertStringSidToSid(names[i], &g0[i].lgrmi0_sid)) { - printf("could not convert sid\n"); - goto out; - } - } - - buffer = (uint8_t *)g0; - break; - case 3: - buf_size = sizeof(struct LOCALGROUP_MEMBERS_INFO_3) * total_entries; - - status = NetApiBufferAllocate(buf_size, (void **)&g3); - if (status) { - printf("NetApiBufferAllocate failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - for (i=0; i<total_entries; i++) { - g3[i].lgrmi3_domainandname = names[i]; - } - - buffer = (uint8_t *)g3; - break; - default: - break; - } - - /* NetLocalGroupSetMembers */ - - status = NetLocalGroupSetMembers(hostname, - groupname, - level, - buffer, - total_entries); - if (status != 0) { - printf("NetLocalGroupSetMembers failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - NetApiBufferFree(buffer); - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 40a6e415eb..418b9c8b8e 100644 --- a/source/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -38,6 +38,14 @@ #define SAMBA_IMAGE_PATH "/usr/share/pixmaps/samba/logo.png" #define SAMBA_IMAGE_PATH_SMALL "/usr/share/pixmaps/samba/logo-small.png" +#define WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED ( 0x00000020 ) +#define WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE ( 0x00000004 ) +#define WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE ( 0x00000002 ) +#define WKSSVC_JOIN_FLAGS_JOIN_TYPE ( 0x00000001 ) + +#define NetSetupWorkgroupName ( 2 ) +#define NetSetupDomainName ( 3 ) + #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0) static gboolean verbose = FALSE; @@ -77,7 +85,6 @@ typedef struct join_state { gboolean settings_changed; gboolean hostname_changed; uint32_t stored_num_ous; - char *target_hostname; } join_state; static void debug(const char *format, ...) @@ -101,23 +108,14 @@ static gboolean callback_delete_event(GtkWidget *widget, return FALSE; } -static void callback_do_close_data(GtkWidget *widget, - gpointer data) +static void callback_do_close(GtkWidget *widget, + gpointer data) { - debug("callback_do_close_data called\n"); + debug("callback_do_close called\n"); if (data) { gtk_widget_destroy(GTK_WIDGET(data)); - } -} - -static void callback_do_close_widget(GtkWidget *widget, - gpointer data) -{ - debug("callback_do_close_widget called\n"); - - if (widget) { - gtk_widget_destroy(widget); + data = NULL; } } @@ -187,10 +185,7 @@ static void callback_apply_description_change(GtkWidget *widget, info1005.sv1005_comment = state->comment_new; - status = NetServerSetInfo(state->target_hostname, - 1005, - (uint8_t *)&info1005, - &parm_err); + status = NetServerSetInfo(NULL, 1005, (uint8_t *)&info1005, &parm_err); if (status) { debug("NetServerSetInfo failed with: %s\n", libnetapi_errstr(status)); @@ -201,7 +196,6 @@ static void callback_apply_description_change(GtkWidget *widget, "Failed to change computer description: %s.", libnetapi_get_error_string(state->ctx, status)); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); - gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_main)); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), @@ -273,7 +267,6 @@ static void callback_do_reboot(GtkWidget *widget, GTK_BUTTONS_OK, "You must restart this computer for the changes to take effect."); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); - gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_do_change)); #if 0 g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), @@ -297,9 +290,7 @@ static void callback_do_reboot(GtkWidget *widget, const char *buffer; uint16_t type; - status = NetGetJoinInformation(state->target_hostname, - &buffer, - &type); + status = NetGetJoinInformation(NULL, &buffer, &type); if (status != 0) { g_print("failed to query status\n"); return; @@ -475,7 +466,6 @@ static void callback_do_hostname_change(GtkWidget *widget, str); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); - gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_main)); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); @@ -505,11 +495,9 @@ static void callback_creds_prompt(GtkWidget *widget, gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); gtk_widget_set_size_request(GTK_WIDGET(window), 380, 280); gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); - gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(state->window_do_change)); - gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS); g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(callback_do_close_widget), NULL); + G_CALLBACK(callback_do_close), window); state->window_creds_prompt = window; gtk_container_set_border_width(GTK_CONTAINER(window), 10); @@ -643,9 +631,9 @@ static void callback_do_join(GtkWidget *widget, if (state->name_type_new == NetSetupDomainName) { domain_join = TRUE; join_creds_required = TRUE; - join_flags = NETSETUP_JOIN_DOMAIN | - NETSETUP_ACCT_CREATE | - NETSETUP_DOMAIN_JOIN_IF_JOINED; /* for testing */ + join_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | + WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE | + WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED; /* for testing */ } if ((state->name_type_initial == NetSetupDomainName) && @@ -653,8 +641,8 @@ static void callback_do_join(GtkWidget *widget, try_unjoin = TRUE; unjoin_creds_required = TRUE; join_creds_required = FALSE; - unjoin_flags = NETSETUP_JOIN_DOMAIN | - NETSETUP_ACCT_DELETE; + unjoin_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | + WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE; } if (try_unjoin) { @@ -675,7 +663,7 @@ static void callback_do_join(GtkWidget *widget, } } - status = NetUnjoinDomain(state->target_hostname, + status = NetUnjoinDomain(NULL, state->account, state->password, unjoin_flags); @@ -729,7 +717,6 @@ static void callback_do_join(GtkWidget *widget, err_str); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); - gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_do_change)); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); @@ -766,7 +753,7 @@ static void callback_do_join(GtkWidget *widget, } debug("\n"); - status = NetJoinDomain(state->target_hostname, + status = NetJoinDomain(NULL, state->name_buffer_new, account_ou, state->account, @@ -787,7 +774,6 @@ static void callback_do_join(GtkWidget *widget, err_str); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); - gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_do_change)); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); @@ -810,7 +796,6 @@ static void callback_do_join(GtkWidget *widget, new_workgroup_type); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); - gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_do_change)); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); @@ -834,19 +819,13 @@ static void callback_enter_hostname_and_unlock(GtkWidget *widget, if (strcasecmp(state->my_hostname, entry_text) == 0) { state->hostname_changed = FALSE; gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); - /* return; */ - } else { - state->hostname_changed = TRUE; + return; } - + state->hostname_changed = TRUE; if (state->name_type_initial == NetSetupDomainName) { - if (asprintf(&str, "%s.%s", entry_text, state->my_dnsdomain) == -1) { - return; - } + asprintf(&str, "%s.%s", entry_text, state->my_dnsdomain); } else { - if (asprintf(&str, "%s.", entry_text) == -1) { - return; - } + asprintf(&str, "%s.", entry_text); } gtk_label_set_text(GTK_LABEL(state->label_full_computer_name), str); free(str); @@ -861,7 +840,7 @@ static void callback_enter_computer_description_and_unlock(GtkWidget *widget, { const gchar *entry_text = NULL; struct join_state *state = (struct join_state *)data; - int string_unchanged = FALSE; + int string_unchanged = 0; entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); debug("callback_enter_computer_description_and_unlock: %s\n", @@ -874,8 +853,8 @@ static void callback_enter_computer_description_and_unlock(GtkWidget *widget, return; } #endif - if (entry_text && state->comment && strcasecmp(state->comment, entry_text) == 0) { - string_unchanged = TRUE; + if (entry_text && strcasecmp(state->comment, entry_text) == 0) { + string_unchanged = 1; gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), FALSE); return; @@ -1004,7 +983,6 @@ static void callback_do_getous(GtkWidget *widget, err_str); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); - gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_do_change)); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); @@ -1026,8 +1004,7 @@ static void callback_do_getous(GtkWidget *widget, return; } - status = NetGetJoinableOUs(state->target_hostname, - domain, + status = NetGetJoinableOUs(NULL, domain, state->account, state->password, &num_ous, &ous); @@ -1042,7 +1019,6 @@ static void callback_do_getous(GtkWidget *widget, "Failed to query joinable OUs: %s", libnetapi_get_error_string(state->ctx, status)); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); - gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_do_change)); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); return; @@ -1108,11 +1084,9 @@ static void callback_do_change(GtkWidget *widget, gtk_window_set_resizable(GTK_WINDOW(window), FALSE); gtk_widget_set_size_request(GTK_WIDGET(window), 480, 650); gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); - gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(state->window_main)); - gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS); g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(callback_do_close_widget), NULL); + G_CALLBACK(callback_do_close), window); gtk_container_set_border_width(GTK_CONTAINER(window), 10); @@ -1158,14 +1132,10 @@ static void callback_do_change(GtkWidget *widget, char *str = NULL; entry_text = gtk_entry_get_text(GTK_ENTRY(entry)); if (state->name_type_initial == NetSetupDomainName) { - if (asprintf(&str, "%s.%s", entry_text, - state->my_dnsdomain) == -1) { - return; - } + asprintf(&str, "%s.%s", entry_text, + state->my_dnsdomain); } else { - if (asprintf(&str, "%s.", entry_text) == -1) { - return; - } + asprintf(&str, "%s.", entry_text); } gtk_label_set_text(GTK_LABEL(state->label_full_computer_name), str); @@ -1310,8 +1280,6 @@ static void callback_do_about(GtkWidget *widget, GError *error = NULL; GtkWidget *about; - struct join_state *state = (struct join_state *)data; - debug("callback_do_about called\n"); logo = gdk_pixbuf_new_from_file(SAMBA_IMAGE_PATH, @@ -1335,7 +1303,6 @@ static void callback_do_about(GtkWidget *widget, } gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(about), "Samba gtk domain join utility"); gtk_window_set_modal(GTK_WINDOW(about), TRUE); - gtk_window_set_transient_for(GTK_WINDOW(about), GTK_WINDOW(state->window_main)); g_signal_connect_swapped(about, "response", G_CALLBACK(gtk_widget_destroy), about); @@ -1382,7 +1349,6 @@ static int draw_main_window(struct join_state *state) gtk_widget_set_size_request(GTK_WIDGET(window), 600, 600); gtk_window_set_resizable(GTK_WINDOW(window), FALSE); gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); - gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS); g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(callback_delete_event), NULL); @@ -1470,14 +1436,10 @@ static int draw_main_window(struct join_state *state) /* Label */ char *str = NULL; if (state->name_type_initial == NetSetupDomainName) { - if (asprintf(&str, "%s.%s", state->my_hostname, - state->my_dnsdomain) == -1) { - return -1; - } + asprintf(&str, "%s.%s", state->my_hostname, + state->my_dnsdomain); } else { - if (asprintf(&str, "%s.", state->my_hostname) == -1) { - return -1; - } + asprintf(&str, "%s.", state->my_hostname); } label = gtk_label_new(str); @@ -1577,7 +1539,7 @@ static int draw_main_window(struct join_state *state) gtk_container_add(GTK_CONTAINER(bbox2), button2); g_signal_connect(G_OBJECT(button2), "clicked", G_CALLBACK(callback_do_about), - state); + window); #if 0 button2 = gtk_button_new_from_stock(GTK_STOCK_HELP); gtk_container_add(GTK_CONTAINER(bbox2), button2); @@ -1609,55 +1571,8 @@ static int init_join_state(struct join_state **state) return 0; } -static NET_API_STATUS get_server_comment(struct join_state *state) -{ - struct SERVER_INFO_101 *info101 = NULL; - struct SERVER_INFO_1005 *info1005 = NULL; - NET_API_STATUS status; - - status = NetServerGetInfo(state->target_hostname, - 101, - (uint8_t **)&info101); - if (status == 0) { - state->comment = strdup(info101->sv101_comment); - if (!state->comment) { - return -1; - } - NetApiBufferFree(info101); - return NET_API_STATUS_SUCCESS; - } - - switch (status) { - case 124: /* WERR_UNKNOWN_LEVEL */ - case 50: /* WERR_NOT_SUPPORTED */ - break; - default: - goto failed; - } - - status = NetServerGetInfo(state->target_hostname, - 1005, - (uint8_t **)&info1005); - if (status == 0) { - state->comment = strdup(info1005->sv1005_comment); - if (!state->comment) { - return -1; - } - NetApiBufferFree(info1005); - return NET_API_STATUS_SUCCESS; - } - - failed: - printf("NetServerGetInfo failed with: %s\n", - libnetapi_get_error_string(state->ctx, status)); - - return status; -} - static int initialize_join_state(struct join_state *state, - const char *debug_level, - const char *target_hostname, - const char *target_username) + const char *debug_level) { struct libnetapi_ctx *ctx = NULL; NET_API_STATUS status = 0; @@ -1671,30 +1586,6 @@ static int initialize_join_state(struct join_state *state, libnetapi_set_debuglevel(ctx, debug_level); } - if (target_hostname) { - state->target_hostname = strdup(target_hostname); - if (!state->target_hostname) { - return -1; - } - } - - if (target_username) { - char *puser = strdup(target_username); - char *p = NULL; - - if ((p = strchr(puser,'%'))) { - size_t len; - *p = 0; - libnetapi_set_username(ctx, puser); - libnetapi_set_password(ctx, p+1); - len = strlen(p+1); - memset(strchr(target_username,'%')+1,'X',len); - } else { - libnetapi_set_username(ctx, puser); - } - free(puser); - } - { char my_hostname[HOST_NAME_MAX]; const char *p = NULL; @@ -1741,9 +1632,7 @@ static int initialize_join_state(struct join_state *state, { const char *buffer = NULL; uint16_t type = 0; - status = NetGetJoinInformation(state->target_hostname, - &buffer, - &type); + status = NetGetJoinInformation(NULL, &buffer, &type); if (status != 0) { printf("NetGetJoinInformation failed with: %s\n", libnetapi_get_error_string(state->ctx, status)); @@ -1758,10 +1647,43 @@ static int initialize_join_state(struct join_state *state, NetApiBufferFree((void *)buffer); } - status = get_server_comment(state); - if (status != 0) { - return -1; + { + struct SERVER_INFO_1005 *info1005 = NULL; + uint8_t *buffer = NULL; + + status = NetServerGetInfo(NULL, 1005, &buffer); + if (status != 0) { + printf("NetServerGetInfo failed with: %s\n", + libnetapi_get_error_string(state->ctx, status)); + return status; + } + + info1005 = (struct SERVER_INFO_1005 *)buffer; + + state->comment = strdup(info1005->sv1005_comment); + if (!state->comment) { + return -1; + } + NetApiBufferFree(buffer); + } +#if 0 + { + struct srvsvc_NetSrvInfo100 *info100 = NULL; + uint8_t *buffer = NULL; + + status = NetServerGetInfo(NULL, 100, &buffer); + if (status) { + return status; + } + + info100 = (struct srvsvc_NetSrvInfo100 *)buffer; + + state->comment = strdup(info100->comment); + if (!state->comment) { + return -1; + } } +#endif state->ctx = ctx; @@ -1772,8 +1694,6 @@ int main(int argc, char **argv) { GOptionContext *context = NULL; static const char *debug_level = NULL; - static const char *target_hostname = NULL; - static const char *target_username = NULL; struct join_state *state = NULL; GError *error = NULL; int ret = 0; @@ -1781,8 +1701,6 @@ int main(int argc, char **argv) static GOptionEntry entries[] = { { "debug", 'd', 0, G_OPTION_ARG_STRING, &debug_level, "Debug level (for samba)", "N" }, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Verbose output", 0 }, - { "target", 'S', 0, G_OPTION_ARG_STRING, &target_hostname, "Target hostname", 0 }, - { "username", 'U', 0, G_OPTION_ARG_STRING, &target_username, "Target hostname", 0 }, { NULL } }; @@ -1800,9 +1718,7 @@ int main(int argc, char **argv) return ret; } - ret = initialize_join_state(state, debug_level, - target_hostname, - target_username); + ret = initialize_join_state(state, debug_level); if (ret) { return ret; } diff --git a/source/lib/netapi/examples/join/netdomjoin.c b/source/lib/netapi/examples/netdomjoin/netdomjoin.c index 08ce71b938..bd7c36382a 100644 --- a/source/lib/netapi/examples/join/netdomjoin.c +++ b/source/lib/netapi/examples/netdomjoin/netdomjoin.c @@ -39,9 +39,7 @@ int main(int argc, const char **argv) const char *account_ou = NULL; const char *account = NULL; const char *password = NULL; - uint32_t join_flags = NETSETUP_JOIN_DOMAIN | - NETSETUP_ACCT_CREATE | - NETSETUP_DOMAIN_JOIN_IF_JOINED; + uint32_t join_flags = 0x00000023; struct libnetapi_ctx *ctx = NULL; poptContext pc; diff --git a/source/lib/netapi/examples/server/remote_tod.c b/source/lib/netapi/examples/server/remote_tod.c deleted file mode 100644 index 7636f6ac95..0000000000 --- a/source/lib/netapi/examples/server/remote_tod.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetRemoteTOD query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - struct TIME_OF_DAY_INFO *tod = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("tod", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - - /* NetRemoteTOD */ - - status = NetRemoteTOD(hostname, - (uint8_t **)&tod); - if (status != 0) { - printf("NetRemoteTOD failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } else { - printf("%d-%d-%d %d:%d:%d\n", - tod->tod_day, tod->tod_month, tod->tod_year, - tod->tod_hours, tod->tod_mins, tod->tod_secs); - NetApiBufferFree(tod); - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/server/server_getinfo.c b/source/lib/netapi/examples/server/server_getinfo.c deleted file mode 100644 index afd2edd05d..0000000000 --- a/source/lib/netapi/examples/server/server_getinfo.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetServerGetInfo query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - uint8_t *buffer = NULL; - uint32_t level = 100; - - struct SERVER_INFO_100 *i100; - struct SERVER_INFO_101 *i101; - struct SERVER_INFO_102 *i102; - struct SERVER_INFO_1005 *i1005; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("server_getinfo", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname level"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (poptPeekArg(pc)) { - level = atoi(poptGetArg(pc)); - } - - /* NetServerGetInfo */ - - status = NetServerGetInfo(hostname, - level, - &buffer); - if (status != 0) { - printf("NetServerGetInfo failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - switch (level) { - case 100: - i100 = (struct SERVER_INFO_100 *)buffer; - printf("platform id: %d\n", i100->sv100_platform_id); - printf("name: %s\n", i100->sv100_name); - break; - case 101: - i101 = (struct SERVER_INFO_101 *)buffer; - printf("platform id: %d\n", i101->sv101_platform_id); - printf("name: %s\n", i101->sv101_name); - printf("version major: %d\n", i101->sv101_version_major); - printf("version minor: %d\n", i101->sv101_version_minor); - printf("type: 0x%08x\n", i101->sv101_type); - printf("comment: %s\n", i101->sv101_comment); - break; - case 102: - i102 = (struct SERVER_INFO_102 *)buffer; - printf("platform id: %d\n", i102->sv102_platform_id); - printf("name: %s\n", i102->sv102_name); - printf("version major: %d\n", i102->sv102_version_major); - printf("version minor: %d\n", i102->sv102_version_minor); - printf("type: 0x%08x\n", i102->sv102_type); - printf("comment: %s\n", i102->sv102_comment); - printf("users: %d\n", i102->sv102_users); - printf("disc: %d\n", i102->sv102_disc); - printf("hidden: %d\n", i102->sv102_hidden); - printf("announce: %d\n", i102->sv102_announce); - printf("anndelta: %d\n", i102->sv102_anndelta); - printf("licenses: %d\n", i102->sv102_licenses); - printf("userpath: %s\n", i102->sv102_userpath); - break; - case 1005: - i1005 = (struct SERVER_INFO_1005 *)buffer; - printf("comment: %s\n", i1005->sv1005_comment); - break; - default: - break; - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/share/share_add.c b/source/lib/netapi/examples/share/share_add.c deleted file mode 100644 index 3d7948840d..0000000000 --- a/source/lib/netapi/examples/share/share_add.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetShareAdd query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *sharename = NULL; - const char *path = NULL; - uint32_t level = 0; - uint32_t parm_err = 0; - - struct SHARE_INFO_2 i2; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("share_add", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname sharename path"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - sharename = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - path = poptGetArg(pc); - - if (poptPeekArg(pc)) { - level = atoi(poptGetArg(pc)); - } - - /* NetShareAdd */ - - i2.shi2_netname = sharename; - i2.shi2_type = 0; - i2.shi2_remark = "Test share created via NetApi"; - i2.shi2_permissions = 0; - i2.shi2_max_uses = (uint32_t)-1; - i2.shi2_current_uses = 0; - i2.shi2_path = path; - i2.shi2_passwd = NULL; - - status = NetShareAdd(hostname, - 2, - (uint8_t *)&i2, - &parm_err); - if (status != 0) { - printf("NetShareAdd failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/share/share_del.c b/source/lib/netapi/examples/share/share_del.c deleted file mode 100644 index 20e3ce5a8b..0000000000 --- a/source/lib/netapi/examples/share/share_del.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetShareDel query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *sharename = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("share_del", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname sharename"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - sharename = poptGetArg(pc); - - /* NetShareDel */ - - status = NetShareDel(hostname, - sharename, - 0); - if (status != 0) { - printf("NetShareDel failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/share/share_enum.c b/source/lib/netapi/examples/share/share_enum.c deleted file mode 100644 index b1f4043795..0000000000 --- a/source/lib/netapi/examples/share/share_enum.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetShareEnum query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - uint32_t level = 0; - uint8_t *buffer = NULL; - uint32_t entries_read = 0; - uint32_t total_entries = 0; - uint32_t resume_handle = 0; - int i; - - struct SHARE_INFO_0 *i0 = NULL; - struct SHARE_INFO_1 *i1 = NULL; - struct SHARE_INFO_2 *i2 = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("share_enum", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname level"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (poptPeekArg(pc)) { - level = atoi(poptGetArg(pc)); - } - - /* NetShareEnum */ - - do { - status = NetShareEnum(hostname, - level, - &buffer, - (uint32_t)-1, - &entries_read, - &total_entries, - &resume_handle); - if (status == 0 || status == ERROR_MORE_DATA) { - printf("total entries: %d\n", total_entries); - switch (level) { - case 0: - i0 = (struct SHARE_INFO_0 *)buffer; - break; - case 1: - i1 = (struct SHARE_INFO_1 *)buffer; - break; - case 2: - i2 = (struct SHARE_INFO_2 *)buffer; - break; - default: - break; - } - for (i=0; i<entries_read; i++) { - switch (level) { - case 0: - printf("#%d netname: %s\n", i, i0->shi0_netname); - i0++; - break; - case 1: - printf("#%d netname: %s\n", i, i1->shi1_netname); - printf("#%d type: %d\n", i, i1->shi1_type); - printf("#%d remark: %s\n", i, i1->shi1_remark); - i1++; - break; - case 2: - printf("#%d netname: %s\n", i, i2->shi2_netname); - printf("#%d type: %d\n", i, i2->shi2_type); - printf("#%d remark: %s\n", i, i2->shi2_remark); - printf("#%d permissions: %d\n", i, i2->shi2_permissions); - printf("#%d max users: %d\n", i, i2->shi2_max_uses); - printf("#%d current users: %d\n", i, i2->shi2_current_uses); - printf("#%d path: %s\n", i, i2->shi2_path); - printf("#%d password: %s\n", i, i2->shi2_passwd); - i2++; - break; - default: - break; - } - } - NetApiBufferFree(buffer); - } - } while (status == ERROR_MORE_DATA); - - if (status != 0) { - printf("NetShareEnum failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/share/share_getinfo.c b/source/lib/netapi/examples/share/share_getinfo.c deleted file mode 100644 index 479da5cc4a..0000000000 --- a/source/lib/netapi/examples/share/share_getinfo.c +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetShareGetInfo query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *sharename = NULL; - uint32_t level = 2; - uint8_t *buffer = NULL; - - struct SHARE_INFO_0 *i0 = NULL; - struct SHARE_INFO_1 *i1 = NULL; - struct SHARE_INFO_2 *i2 = NULL; - struct SHARE_INFO_501 *i501 = NULL; - struct SHARE_INFO_1005 *i1005 = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("share_getinfo", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname sharename level"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - sharename = poptGetArg(pc); - - if (poptPeekArg(pc)) { - level = atoi(poptGetArg(pc)); - } - - /* NetShareGetInfo */ - - status = NetShareGetInfo(hostname, - sharename, - level, - &buffer); - if (status != 0) { - printf("NetShareGetInfo failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - switch (level) { - case 0: - i0 = (struct SHARE_INFO_0 *)buffer; - break; - case 1: - i1 = (struct SHARE_INFO_1 *)buffer; - break; - case 2: - i2 = (struct SHARE_INFO_2 *)buffer; - break; - case 501: - i501 = (struct SHARE_INFO_501 *)buffer; - break; - case 1005: - i1005 = (struct SHARE_INFO_1005 *)buffer; - break; - - default: - break; - } - - switch (level) { - case 0: - printf("netname: %s\n", i0->shi0_netname); - break; - case 1: - printf("netname: %s\n", i1->shi1_netname); - printf("type: %d\n", i1->shi1_type); - printf("remark: %s\n", i1->shi1_remark); - break; - case 2: - printf("netname: %s\n", i2->shi2_netname); - printf("type: %d\n", i2->shi2_type); - printf("remark: %s\n", i2->shi2_remark); - printf("permissions: %d\n", i2->shi2_permissions); - printf("max users: %d\n", i2->shi2_max_uses); - printf("current users: %d\n", i2->shi2_current_uses); - printf("path: %s\n", i2->shi2_path); - printf("password: %s\n", i2->shi2_passwd); - break; - case 501: - printf("netname: %s\n", i501->shi501_netname); - printf("type: %d\n", i501->shi501_type); - printf("remark: %s\n", i501->shi501_remark); - printf("flags: %d\n", i501->shi501_flags); - break; - case 1005: - printf("flags: %d\n", i1005->shi1005_flags); - break; - default: - break; - } - NetApiBufferFree(buffer); - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/share/share_setinfo.c b/source/lib/netapi/examples/share/share_setinfo.c deleted file mode 100644 index f4748f4122..0000000000 --- a/source/lib/netapi/examples/share/share_setinfo.c +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetShareSetInfo query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *sharename = NULL; - const char *comment = "NetApi generated Share comment"; - uint32_t level = 1004; - uint8_t *buffer = NULL; - uint32_t parm_err = 0; - - struct SHARE_INFO_1004 i1004; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("share_setinfo", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname sharename comment"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - sharename = poptGetArg(pc); - - if (poptPeekArg(pc)) { - comment = poptGetArg(pc); - } - - /* NetShareSetInfo */ - switch (level) { - case 1004: - i1004.shi1004_remark = comment; - buffer = (uint8_t *)&i1004; - break; - default: - break; - } - - status = NetShareSetInfo(hostname, - sharename, - level, - buffer, - &parm_err); - if (status != 0) { - printf("NetShareSetInfo failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/user/user_chgpwd.c b/source/lib/netapi/examples/user/user_chgpwd.c deleted file mode 100644 index 8b37ec2a99..0000000000 --- a/source/lib/netapi/examples/user/user_chgpwd.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetUserChangePassword query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *username = NULL; - const char *old_password = NULL; - const char *new_password = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("user_chgpwd", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname username old_password new_password"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - username = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - old_password = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - new_password = poptGetArg(pc); - - /* NetUserChangePassword */ - - status = NetUserChangePassword(hostname, - username, - old_password, - new_password); - if (status != 0) { - printf("NetUserChangePassword failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/user/user_dispinfo.c b/source/lib/netapi/examples/user/user_dispinfo.c index 23024fe9fe..9f862505aa 100644 --- a/source/lib/netapi/examples/user/user_dispinfo.c +++ b/source/lib/netapi/examples/user/user_dispinfo.c @@ -78,13 +78,11 @@ int main(int argc, const char **argv) if (status == 0 || status == ERROR_MORE_DATA) { user = (struct NET_DISPLAY_USER *)buffer; for (i=0; i<entries_read; i++) { - printf("user %d: %s\n", i + idx, - user->usri1_name); + printf("user %d: %s\n", i, user->usri1_name); user++; } NetApiBufferFree(buffer); } - idx += entries_read; } while (status == ERROR_MORE_DATA); if (status != 0) { diff --git a/source/lib/netapi/examples/user/user_enum.c b/source/lib/netapi/examples/user/user_enum.c index cf77bf2d54..e1f6bda10b 100644 --- a/source/lib/netapi/examples/user/user_enum.c +++ b/source/lib/netapi/examples/user/user_enum.c @@ -32,18 +32,13 @@ int main(int argc, const char **argv) NET_API_STATUS status; struct libnetapi_ctx *ctx = NULL; const char *hostname = NULL; - uint32_t level = 0; uint8_t *buffer = NULL; uint32_t entries_read = 0; uint32_t total_entries = 0; uint32_t resume_handle = 0; - char *sid_str = NULL; int i; - struct USER_INFO_0 *info0 = NULL; - struct USER_INFO_10 *info10 = NULL; - struct USER_INFO_20 *info20 = NULL; - struct USER_INFO_23 *info23 = NULL; + struct USER_INFO_0 *info0; poptContext pc; int opt; @@ -61,7 +56,7 @@ int main(int argc, const char **argv) pc = poptGetContext("user_enum", argc, argv, long_options, 0); - poptSetOtherOptionHelp(pc, "hostname level"); + poptSetOtherOptionHelp(pc, "hostname"); while((opt = poptGetNextOpt(pc)) != -1) { } @@ -71,74 +66,22 @@ int main(int argc, const char **argv) } hostname = poptGetArg(pc); - if (poptPeekArg(pc)) { - level = atoi(poptGetArg(pc)); - } - /* NetUserEnum */ do { status = NetUserEnum(hostname, - level, - FILTER_NORMAL_ACCOUNT, + 0, + 0, &buffer, (uint32_t)-1, &entries_read, &total_entries, &resume_handle); if (status == 0 || status == ERROR_MORE_DATA) { - - switch (level) { - case 0: - info0 = (struct USER_INFO_0 *)buffer; - break; - case 10: - info10 = (struct USER_INFO_10 *)buffer; - break; - case 20: - info20 = (struct USER_INFO_20 *)buffer; - break; - case 23: - info23 = (struct USER_INFO_23 *)buffer; - break; - default: - break; - } - + info0 = (struct USER_INFO_0 *)buffer; for (i=0; i<entries_read; i++) { - switch (level) { - case 0: - printf("#%d user: %s\n", i, info0->usri0_name); - info0++; - break; - case 10: - printf("#%d user: %s\n", i, info10->usri10_name); - printf("#%d comment: %s\n", i, info10->usri10_comment); - printf("#%d usr_comment: %s\n", i, info10->usri10_usr_comment); - printf("#%d full_name: %s\n", i, info10->usri10_full_name); - info10++; - break; - case 20: - printf("#%d user: %s\n", i, info20->usri20_name); - printf("#%d comment: %s\n", i, info20->usri20_comment); - printf("#%d flags: 0x%08x\n", i, info20->usri20_flags); - printf("#%d rid: %d\n", i, info20->usri20_user_id); - info20++; - break; - case 23: - printf("#%d user: %s\n", i, info23->usri23_name); - printf("#%d comment: %s\n", i, info23->usri23_comment); - printf("#%d flags: 0x%08x\n", i, info23->usri23_flags); - if (ConvertSidToStringSid(info23->usri23_user_sid, - &sid_str)) { - printf("#%d sid: %s\n", i, sid_str); - free(sid_str); - } - info23++; - break; - default: - break; - } + printf("user %d: %s\n", i, info0->usri0_name); + info0++; } NetApiBufferFree(buffer); } diff --git a/source/lib/netapi/examples/user/user_getgroups.c b/source/lib/netapi/examples/user/user_getgroups.c deleted file mode 100644 index 939415e0eb..0000000000 --- a/source/lib/netapi/examples/user/user_getgroups.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetUserGetGroups query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *username = NULL; - uint32_t level = 0; - uint8_t *buffer = NULL; - uint32_t entries_read = 0; - uint32_t total_entries = 0; - int i; - - struct GROUP_USERS_INFO_0 *info0 = NULL; - struct GROUP_USERS_INFO_1 *info1 = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("user_getgroups", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname username level"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - username = poptGetArg(pc); - - if (poptPeekArg(pc)) { - level = atoi(poptGetArg(pc)); - } - - /* NetUserGetGroups */ - - do { - status = NetUserGetGroups(hostname, - username, - level, - &buffer, - (uint32_t)-1, - &entries_read, - &total_entries); - if (status == 0 || status == ERROR_MORE_DATA) { - - switch (level) { - case 0: - info0 = (struct GROUP_USERS_INFO_0 *)buffer; - break; - case 1: - info1 = (struct GROUP_USERS_INFO_1 *)buffer; - break; - default: - break; - } - - for (i=0; i<entries_read; i++) { - switch (level) { - case 0: - printf("#%d group: %s\n", i, info0->grui0_name); - info0++; - break; - case 1: - printf("#%d group: %s\n", i, info1->grui1_name); - printf("#%d attributes: %d\n", i, info1->grui1_attributes); - info1++; - break; - default: - break; - } - } - NetApiBufferFree(buffer); - } - } while (status == ERROR_MORE_DATA); - - if (status != 0) { - printf("NetUserGetGroups failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/user/user_getinfo.c b/source/lib/netapi/examples/user/user_getinfo.c deleted file mode 100644 index 9e95260b5a..0000000000 --- a/source/lib/netapi/examples/user/user_getinfo.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetUserGetInfo query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *username = NULL; - uint8_t *buffer = NULL; - uint32_t level = 0; - char *sid_str = NULL; - int i; - - struct USER_INFO_0 *u0; - struct USER_INFO_1 *u1; - struct USER_INFO_2 *u2; - struct USER_INFO_3 *u3; - struct USER_INFO_4 *u4; - struct USER_INFO_10 *u10; - struct USER_INFO_11 *u11; - struct USER_INFO_20 *u20; - struct USER_INFO_23 *u23; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("user_getinfo", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname username level"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - username = poptGetArg(pc); - - if (poptPeekArg(pc)) { - level = atoi(poptGetArg(pc)); - } - - /* NetUserGetInfo */ - - status = NetUserGetInfo(hostname, - username, - level, - &buffer); - if (status != 0) { - printf("NetUserGetInfo failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - switch (level) { - case 0: - u0 = (struct USER_INFO_0 *)buffer; - printf("name: %s\n", u0->usri0_name); - break; - case 1: - u1 = (struct USER_INFO_1 *)buffer; - printf("name: %s\n", u1->usri1_name); - printf("password: %s\n", u1->usri1_password); - printf("password_age: %d\n", u1->usri1_password_age); - printf("priv: %d\n", u1->usri1_priv); - printf("homedir: %s\n", u1->usri1_home_dir); - printf("comment: %s\n", u1->usri1_comment); - printf("flags: 0x%08x\n", u1->usri1_flags); - printf("script: %s\n", u1->usri1_script_path); - break; - case 2: - u2 = (struct USER_INFO_2 *)buffer; - printf("name: %s\n", u2->usri2_name); - printf("password: %s\n", u2->usri2_password); - printf("password_age: %d\n", u2->usri2_password_age); - printf("priv: %d\n", u2->usri2_priv); - printf("homedir: %s\n", u2->usri2_home_dir); - printf("comment: %s\n", u2->usri2_comment); - printf("flags: 0x%08x\n", u2->usri2_flags); - printf("script: %s\n", u2->usri2_script_path); - printf("auth flags: 0x%08x\n", u2->usri2_auth_flags); - printf("full name: %s\n", u2->usri2_full_name); - printf("user comment: %s\n", u2->usri2_usr_comment); - printf("user parameters: %s\n", u2->usri2_parms); - printf("workstations: %s\n", u2->usri2_workstations); - printf("last logon (seconds since jan. 1, 1970 GMT): %d\n", - u2->usri2_last_logon); - printf("last logoff (seconds since jan. 1, 1970 GMT): %d\n", - u2->usri2_last_logoff); - printf("account expires (seconds since jan. 1, 1970 GMT): %d\n", - u2->usri2_acct_expires); - printf("max storage: %d\n", u2->usri2_max_storage); - printf("units per week: %d\n", u2->usri2_units_per_week); - printf("logon hours:"); - for (i=0; i<21; i++) { - printf(" %x", (uint8_t)u2->usri2_logon_hours[i]); - } - printf("\n"); - printf("bad password count: %d\n", u2->usri2_bad_pw_count); - printf("logon count: %d\n", u2->usri2_num_logons); - printf("logon server: %s\n", u2->usri2_logon_server); - printf("country code: %d\n", u2->usri2_country_code); - printf("code page: %d\n", u2->usri2_code_page); - break; - case 3: - u3 = (struct USER_INFO_3 *)buffer; - printf("name: %s\n", u3->usri3_name); - printf("password_age: %d\n", u3->usri3_password_age); - printf("priv: %d\n", u3->usri3_priv); - printf("homedir: %s\n", u3->usri3_home_dir); - printf("comment: %s\n", u3->usri3_comment); - printf("flags: 0x%08x\n", u3->usri3_flags); - printf("script: %s\n", u3->usri3_script_path); - printf("auth flags: 0x%08x\n", u3->usri3_auth_flags); - printf("full name: %s\n", u3->usri3_full_name); - printf("user comment: %s\n", u3->usri3_usr_comment); - printf("user parameters: %s\n", u3->usri3_parms); - printf("workstations: %s\n", u3->usri3_workstations); - printf("last logon (seconds since jan. 1, 1970 GMT): %d\n", - u3->usri3_last_logon); - printf("last logoff (seconds since jan. 1, 1970 GMT): %d\n", - u3->usri3_last_logoff); - printf("account expires (seconds since jan. 1, 1970 GMT): %d\n", - u3->usri3_acct_expires); - printf("max storage: %d\n", u3->usri3_max_storage); - printf("units per week: %d\n", u3->usri3_units_per_week); - printf("logon hours:"); - for (i=0; i<21; i++) { - printf(" %x", (uint8_t)u3->usri3_logon_hours[i]); - } - printf("\n"); - printf("bad password count: %d\n", u3->usri3_bad_pw_count); - printf("logon count: %d\n", u3->usri3_num_logons); - printf("logon server: %s\n", u3->usri3_logon_server); - printf("country code: %d\n", u3->usri3_country_code); - printf("code page: %d\n", u3->usri3_code_page); - printf("user id: %d\n", u3->usri3_user_id); - printf("primary group id: %d\n", u3->usri3_primary_group_id); - printf("profile: %s\n", u3->usri3_profile); - printf("home dir drive: %s\n", u3->usri3_home_dir_drive); - printf("password expired: %d\n", u3->usri3_password_expired); - break; - case 4: - u4 = (struct USER_INFO_4 *)buffer; - printf("name: %s\n", u4->usri4_name); - printf("password: %s\n", u4->usri4_password); - printf("password_age: %d\n", u4->usri4_password_age); - printf("priv: %d\n", u4->usri4_priv); - printf("homedir: %s\n", u4->usri4_home_dir); - printf("comment: %s\n", u4->usri4_comment); - printf("flags: 0x%08x\n", u4->usri4_flags); - printf("script: %s\n", u4->usri4_script_path); - printf("auth flags: 0x%08x\n", u4->usri4_auth_flags); - printf("full name: %s\n", u4->usri4_full_name); - printf("user comment: %s\n", u4->usri4_usr_comment); - printf("user parameters: %s\n", u4->usri4_parms); - printf("workstations: %s\n", u4->usri4_workstations); - printf("last logon (seconds since jan. 1, 1970 GMT): %d\n", - u4->usri4_last_logon); - printf("last logoff (seconds since jan. 1, 1970 GMT): %d\n", - u4->usri4_last_logoff); - printf("account expires (seconds since jan. 1, 1970 GMT): %d\n", - u4->usri4_acct_expires); - printf("max storage: %d\n", u4->usri4_max_storage); - printf("units per week: %d\n", u4->usri4_units_per_week); - printf("logon hours:"); - for (i=0; i<21; i++) { - printf(" %x", (uint8_t)u4->usri4_logon_hours[i]); - } - printf("\n"); - printf("bad password count: %d\n", u4->usri4_bad_pw_count); - printf("logon count: %d\n", u4->usri4_num_logons); - printf("logon server: %s\n", u4->usri4_logon_server); - printf("country code: %d\n", u4->usri4_country_code); - printf("code page: %d\n", u4->usri4_code_page); - if (ConvertSidToStringSid(u4->usri4_user_sid, - &sid_str)) { - printf("user_sid: %s\n", sid_str); - free(sid_str); - } - printf("primary group id: %d\n", u4->usri4_primary_group_id); - printf("profile: %s\n", u4->usri4_profile); - printf("home dir drive: %s\n", u4->usri4_home_dir_drive); - printf("password expired: %d\n", u4->usri4_password_expired); - break; - case 10: - u10 = (struct USER_INFO_10 *)buffer; - printf("name: %s\n", u10->usri10_name); - printf("comment: %s\n", u10->usri10_comment); - printf("usr_comment: %s\n", u10->usri10_usr_comment); - printf("full_name: %s\n", u10->usri10_full_name); - break; - case 11: - u11 = (struct USER_INFO_11 *)buffer; - printf("name: %s\n", u11->usri11_name); - printf("comment: %s\n", u11->usri11_comment); - printf("user comment: %s\n", u11->usri11_usr_comment); - printf("full name: %s\n", u11->usri11_full_name); - printf("priv: %d\n", u11->usri11_priv); - printf("auth flags: 0x%08x\n", u11->usri11_auth_flags); - printf("password_age: %d\n", u11->usri11_password_age); - printf("homedir: %s\n", u11->usri11_home_dir); - printf("user parameters: %s\n", u11->usri11_parms); - printf("last logon (seconds since jan. 1, 1970 GMT): %d\n", - u11->usri11_last_logon); - printf("last logoff (seconds since jan. 1, 1970 GMT): %d\n", - u11->usri11_last_logoff); - printf("bad password count: %d\n", u11->usri11_bad_pw_count); - printf("logon count: %d\n", u11->usri11_num_logons); - printf("logon server: %s\n", u11->usri11_logon_server); - printf("country code: %d\n", u11->usri11_country_code); - printf("workstations: %s\n", u11->usri11_workstations); - printf("max storage: %d\n", u11->usri11_max_storage); - printf("units per week: %d\n", u11->usri11_units_per_week); - printf("logon hours:"); - for (i=0; i<21; i++) { - printf(" %x", (uint8_t)u11->usri11_logon_hours[i]); - } - printf("\n"); - printf("code page: %d\n", u11->usri11_code_page); - break; - case 20: - u20 = (struct USER_INFO_20 *)buffer; - printf("name: %s\n", u20->usri20_name); - printf("comment: %s\n", u20->usri20_comment); - printf("flags: 0x%08x\n", u20->usri20_flags); - printf("rid: %d\n", u20->usri20_user_id); - break; - case 23: - u23 = (struct USER_INFO_23 *)buffer; - printf("name: %s\n", u23->usri23_name); - printf("comment: %s\n", u23->usri23_comment); - printf("flags: 0x%08x\n", u23->usri23_flags); - if (ConvertSidToStringSid(u23->usri23_user_sid, - &sid_str)) { - printf("user_sid: %s\n", sid_str); - free(sid_str); - } - break; - default: - break; - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/user/user_getlocalgroups.c b/source/lib/netapi/examples/user/user_getlocalgroups.c deleted file mode 100644 index 133104d7c1..0000000000 --- a/source/lib/netapi/examples/user/user_getlocalgroups.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetUserGetLocalGroups query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *username = NULL; - uint32_t level = 0; - uint8_t *buffer = NULL; - uint32_t entries_read = 0; - uint32_t total_entries = 0; - uint32_t flags = 0; - int i; - - struct LOCALGROUP_USERS_INFO_0 *info0 = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("user_getlocalgroups", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname username"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - username = poptGetArg(pc); - - /* NetUserGetLocalGroups */ - - do { - status = NetUserGetLocalGroups(hostname, - username, - level, - flags, - &buffer, - (uint32_t)-1, - &entries_read, - &total_entries); - if (status == 0 || status == ERROR_MORE_DATA) { - - switch (level) { - case 0: - info0 = (struct LOCALGROUP_USERS_INFO_0 *)buffer; - break; - default: - break; - } - - for (i=0; i<entries_read; i++) { - switch (level) { - case 0: - printf("#%d group: %s\n", i, info0->lgrui0_name); - info0++; - break; - default: - break; - } - } - NetApiBufferFree(buffer); - } - } while (status == ERROR_MORE_DATA); - - if (status != 0) { - printf("NetUserGetLocalGroups failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/user/user_modalsget.c b/source/lib/netapi/examples/user/user_modalsget.c deleted file mode 100644 index 4dcb41bef7..0000000000 --- a/source/lib/netapi/examples/user/user_modalsget.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetUserModalsGet query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - uint8_t *buffer = NULL; - uint32_t level = 0; - char *sid_str = NULL; - - struct USER_MODALS_INFO_0 *u0; - struct USER_MODALS_INFO_1 *u1; - struct USER_MODALS_INFO_2 *u2; - struct USER_MODALS_INFO_3 *u3; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("user_modalsget", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname level"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (poptPeekArg(pc)) { - level = atoi(poptGetArg(pc)); - } - - /* NetUserModalsGet */ - - status = NetUserModalsGet(hostname, - level, - &buffer); - if (status != 0) { - printf("NetUserModalsGet failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - switch (level) { - case 0: - u0 = (struct USER_MODALS_INFO_0 *)buffer; - printf("min passwd len: %d character\n", - u0->usrmod0_min_passwd_len); - printf("max passwd age: %d (days)\n", - u0->usrmod0_max_passwd_age/86400); - printf("min passwd age: %d (days)\n", - u0->usrmod0_min_passwd_age/86400); - printf("force logoff: %d (seconds)\n", - u0->usrmod0_force_logoff); - printf("password history length: %d entries\n", - u0->usrmod0_password_hist_len); - break; - case 1: - u1 = (struct USER_MODALS_INFO_1 *)buffer; - printf("role: %d\n", u1->usrmod1_role); - printf("primary: %s\n", u1->usrmod1_primary); - break; - case 2: - u2 = (struct USER_MODALS_INFO_2 *)buffer; - printf("domain name: %s\n", u2->usrmod2_domain_name); - if (ConvertSidToStringSid(u2->usrmod2_domain_id, - &sid_str)) { - printf("domain sid: %s\n", sid_str); - free(sid_str); - } - break; - case 3: - u3 = (struct USER_MODALS_INFO_3 *)buffer; - printf("lockout duration: %d (seconds)\n", - u3->usrmod3_lockout_duration); - printf("lockout observation window: %d (seconds)\n", - u3->usrmod3_lockout_observation_window); - printf("lockout threshold: %d entries\n", - u3->usrmod3_lockout_threshold); - break; - default: - break; - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/user/user_modalsset.c b/source/lib/netapi/examples/user/user_modalsset.c deleted file mode 100644 index 57e1ef70ea..0000000000 --- a/source/lib/netapi/examples/user/user_modalsset.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetUserModalsSet query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - uint8_t *buffer = NULL; - uint32_t level = 0; - uint32_t value = 0; - uint32_t parm_err = 0; - - struct USER_MODALS_INFO_0 u0; - struct USER_MODALS_INFO_1 u1; - struct USER_MODALS_INFO_2 u2; - struct USER_MODALS_INFO_3 u3; - struct USER_MODALS_INFO_1001 u1001; - struct USER_MODALS_INFO_1002 u1002; - struct USER_MODALS_INFO_1003 u1003; - struct USER_MODALS_INFO_1004 u1004; - struct USER_MODALS_INFO_1005 u1005; - struct USER_MODALS_INFO_1006 u1006; - struct USER_MODALS_INFO_1007 u1007; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("user_modalsset", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname level value"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (poptPeekArg(pc)) { - level = atoi(poptGetArg(pc)); - } - - if (poptPeekArg(pc)) { - value = atoi(poptGetArg(pc)); - } - - switch (level) { - case 0: - u0.usrmod0_min_passwd_len = 0; - u0.usrmod0_max_passwd_age = (86400 * 30); /* once a month */ - u0.usrmod0_min_passwd_age = 0; - u0.usrmod0_force_logoff = TIMEQ_FOREVER; - u0.usrmod0_password_hist_len = 0; - buffer = (uint8_t *)&u0; - break; - case 1: - case 2: - case 3: - case 1001: - u1001.usrmod1001_min_passwd_len = 0; - buffer = (uint8_t *)&u1001; - break; - case 1002: - u1002.usrmod1002_max_passwd_age = 0; - buffer = (uint8_t *)&u1002; - break; - case 1003: - u1003.usrmod1003_min_passwd_age = (86400 * 30); /* once a month */ - buffer = (uint8_t *)&u1003; - break; - case 1004: - u1004.usrmod1004_force_logoff = TIMEQ_FOREVER; - buffer = (uint8_t *)&u1004; - break; - case 1005: - u1005.usrmod1005_password_hist_len = 0; - buffer = (uint8_t *)&u1005; - break; - case 1006: - case 1007: - default: - break; - } - - /* NetUserModalsSet */ - - status = NetUserModalsSet(hostname, - level, - buffer, - &parm_err); - if (status != 0) { - printf("NetUserModalsSet failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/user/user_setgroups.c b/source/lib/netapi/examples/user/user_setgroups.c deleted file mode 100644 index de3ff22ec8..0000000000 --- a/source/lib/netapi/examples/user/user_setgroups.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetUserSetGroups query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *username = NULL; - uint32_t level = 0; - uint8_t *buffer = NULL; - uint32_t num_entries = 0; - const char **names = NULL; - int i = 0; - size_t buf_size = 0; - - struct GROUP_USERS_INFO_0 *g0 = NULL; - struct GROUP_USERS_INFO_1 *g1 = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("user_setgroups", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname username group1 group2 ..."); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - username = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - - names = poptGetArgs(pc); - for (i=0; names[i] != NULL; i++) { - num_entries++; - } - - switch (level) { - case 0: - buf_size = sizeof(struct GROUP_USERS_INFO_0) * num_entries; - - status = NetApiBufferAllocate(buf_size, (void **)&g0); - if (status) { - printf("NetApiBufferAllocate failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - for (i=0; i<num_entries; i++) { - g0[i].grui0_name = names[i]; - } - - buffer = (uint8_t *)g0; - break; - case 1: - buf_size = sizeof(struct GROUP_USERS_INFO_1) * num_entries; - - status = NetApiBufferAllocate(buf_size, (void **)&g1); - if (status) { - printf("NetApiBufferAllocate failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - for (i=0; i<num_entries; i++) { - g1[i].grui1_name = names[i]; - g1[i].grui1_attributes = 0; /* ? */ - } - - buffer = (uint8_t *)g1; - break; - default: - break; - } - - /* NetUserSetGroups */ - - status = NetUserSetGroups(hostname, - username, - level, - buffer, - num_entries); - if (status != 0) { - printf("NetUserSetGroups failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - out: - NetApiBufferFree(buffer); - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/examples/user/user_setinfo.c b/source/lib/netapi/examples/user/user_setinfo.c deleted file mode 100644 index 4f02ae7781..0000000000 --- a/source/lib/netapi/examples/user/user_setinfo.c +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetUserSetInfo query - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - const char *username = NULL; - uint32_t level = 0; - uint32_t parm_err = 0; - uint8_t *buffer = NULL; - const char *val = NULL; - - struct USER_INFO_0 u0; - struct USER_INFO_1 u1; - struct USER_INFO_2 u2; - struct USER_INFO_3 u3; - struct USER_INFO_4 u4; - struct USER_INFO_21 u21; - struct USER_INFO_22 u22; - struct USER_INFO_1003 u1003; - struct USER_INFO_1005 u1005; - struct USER_INFO_1006 u1006; - struct USER_INFO_1007 u1007; - struct USER_INFO_1008 u1008; - struct USER_INFO_1009 u1009; - struct USER_INFO_1010 u1010; - struct USER_INFO_1011 u1011; - struct USER_INFO_1012 u1012; - struct USER_INFO_1014 u1014; - struct USER_INFO_1017 u1017; - struct USER_INFO_1020 u1020; - struct USER_INFO_1024 u1024; - struct USER_INFO_1051 u1051; - struct USER_INFO_1052 u1052; - struct USER_INFO_1053 u1053; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("user_setinfo", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname username level"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - username = poptGetArg(pc); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - level = atoi(poptGetArg(pc)); - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - val = poptGetArg(pc); - - /* NetUserSetInfo */ - - switch (level) { - case 0: - u0.usri0_name = val; - buffer = (uint8_t *)&u0; - break; - case 1: - case 2: - case 3: - case 4: - break; - case 21: - break; - case 22: - break; - case 1003: - u1003.usri1003_password = val; - buffer = (uint8_t *)&u1003; - break; - case 1005: - u1005.usri1005_priv = atoi(val); - buffer = (uint8_t *)&u1005; - break; - case 1006: - u1006.usri1006_home_dir = val; - buffer = (uint8_t *)&u1006; - break; - case 1007: - u1007.usri1007_comment = val; - buffer = (uint8_t *)&u1007; - break; - case 1008: - u1008.usri1008_flags = atoi(val); - buffer = (uint8_t *)&u1008; - break; - case 1009: - u1009.usri1009_script_path = val; - buffer = (uint8_t *)&u1009; - break; - case 1010: - u1010.usri1010_auth_flags = atoi(val); - buffer = (uint8_t *)&u1010; - break; - case 1011: - u1011.usri1011_full_name = val; - buffer = (uint8_t *)&u1011; - break; - case 1012: - u1012.usri1012_usr_comment = val; - buffer = (uint8_t *)&u1012; - break; - case 1014: - u1014.usri1014_workstations = val; - buffer = (uint8_t *)&u1014; - break; - case 1017: - u1017.usri1017_acct_expires = atoi(val); - buffer = (uint8_t *)&u1017; - break; - case 1020: - break; - case 1024: - u1024.usri1024_country_code = atoi(val); - buffer = (uint8_t *)&u1024; - break; - case 1051: - u1051.usri1051_primary_group_id = atoi(val); - buffer = (uint8_t *)&u1051; - break; - case 1052: - u1052.usri1052_profile = val; - buffer = (uint8_t *)&u1052; - break; - case 1053: - u1053.usri1053_home_dir_drive = val; - buffer = (uint8_t *)&u1053; - break; - default: - break; - } - - status = NetUserSetInfo(hostname, - username, - level, - buffer, - &parm_err); - if (status != 0) { - printf("NetUserSetInfo failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - goto out; - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/file.c b/source/lib/netapi/file.c deleted file mode 100644 index 036af32f38..0000000000 --- a/source/lib/netapi/file.c +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetApi File Support - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include "includes.h" - -#include "librpc/gen_ndr/libnetapi.h" -#include "lib/netapi/netapi.h" -#include "lib/netapi/netapi_private.h" -#include "lib/netapi/libnetapi.h" - -/**************************************************************** -****************************************************************/ - -WERROR NetFileClose_r(struct libnetapi_ctx *ctx, - struct NetFileClose *r) -{ - WERROR werr; - NTSTATUS status; - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_srvsvc.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - status = rpccli_srvsvc_NetFileClose(pipe_cli, ctx, - r->in.server_name, - r->in.fileid, - &werr); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - done: - if (!cli) { - return werr; - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetFileClose_l(struct libnetapi_ctx *ctx, - struct NetFileClose *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetFileClose); -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS map_srvsvc_FileInfo_to_FILE_INFO_buffer(TALLOC_CTX *mem_ctx, - uint32_t level, - union srvsvc_NetFileInfo *info, - uint8_t **buffer, - uint32_t *num_entries) -{ - struct FILE_INFO_2 i2; - struct FILE_INFO_3 i3; - - switch (level) { - case 2: - i2.fi2_id = info->info2->fid; - - ADD_TO_ARRAY(mem_ctx, struct FILE_INFO_2, i2, - (struct FILE_INFO_2 **)buffer, - num_entries); - break; - case 3: - i3.fi3_id = info->info3->fid; - i3.fi3_permissions = info->info3->permissions; - i3.fi3_num_locks = info->info3->num_locks; - i3.fi3_pathname = talloc_strdup(mem_ctx, info->info3->path); - i3.fi3_username = talloc_strdup(mem_ctx, info->info3->user); - - NT_STATUS_HAVE_NO_MEMORY(i3.fi3_pathname); - NT_STATUS_HAVE_NO_MEMORY(i3.fi3_username); - - ADD_TO_ARRAY(mem_ctx, struct FILE_INFO_3, i3, - (struct FILE_INFO_3 **)buffer, - num_entries); - break; - default: - return NT_STATUS_INVALID_INFO_CLASS; - } - - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetFileGetInfo_r(struct libnetapi_ctx *ctx, - struct NetFileGetInfo *r) -{ - WERROR werr; - NTSTATUS status; - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - union srvsvc_NetFileInfo info; - uint32_t num_entries = 0; - - if (!r->out.buffer) { - return WERR_INVALID_PARAM; - } - - switch (r->in.level) { - case 2: - case 3: - break; - default: - return WERR_UNKNOWN_LEVEL; - } - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_srvsvc.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - status = rpccli_srvsvc_NetFileGetInfo(pipe_cli, ctx, - r->in.server_name, - r->in.fileid, - r->in.level, - &info, - &werr); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - status = map_srvsvc_FileInfo_to_FILE_INFO_buffer(ctx, - r->in.level, - &info, - r->out.buffer, - &num_entries); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - done: - if (!cli) { - return werr; - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetFileGetInfo_l(struct libnetapi_ctx *ctx, - struct NetFileGetInfo *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetFileGetInfo); -} - -/**************************************************************** -****************************************************************/ - -WERROR NetFileEnum_r(struct libnetapi_ctx *ctx, - struct NetFileEnum *r) -{ - WERROR werr; - NTSTATUS status; - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - struct srvsvc_NetFileInfoCtr info_ctr; - struct srvsvc_NetFileCtr2 ctr2; - struct srvsvc_NetFileCtr3 ctr3; - uint32_t num_entries = 0; - uint32_t i; - - if (!r->out.buffer) { - return WERR_INVALID_PARAM; - } - - switch (r->in.level) { - case 2: - case 3: - break; - default: - return WERR_UNKNOWN_LEVEL; - } - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_srvsvc.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - ZERO_STRUCT(info_ctr); - - info_ctr.level = r->in.level; - switch (r->in.level) { - case 2: - ZERO_STRUCT(ctr2); - info_ctr.ctr.ctr2 = &ctr2; - break; - case 3: - ZERO_STRUCT(ctr3); - info_ctr.ctr.ctr3 = &ctr3; - break; - } - - status = rpccli_srvsvc_NetFileEnum(pipe_cli, ctx, - r->in.server_name, - r->in.base_path, - r->in.user_name, - &info_ctr, - r->in.prefmaxlen, - r->out.total_entries, - r->out.resume_handle, - &werr); - if (NT_STATUS_IS_ERR(status)) { - goto done; - } - - for (i=0; i < info_ctr.ctr.ctr2->count; i++) { - union srvsvc_NetFileInfo _i; - switch (r->in.level) { - case 2: - _i.info2 = &info_ctr.ctr.ctr2->array[i]; - break; - case 3: - _i.info3 = &info_ctr.ctr.ctr3->array[i]; - break; - } - - status = map_srvsvc_FileInfo_to_FILE_INFO_buffer(ctx, - r->in.level, - &_i, - r->out.buffer, - &num_entries); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - } - - if (r->out.entries_read) { - *r->out.entries_read = num_entries; - } - - if (r->out.total_entries) { - *r->out.total_entries = num_entries; - } - - done: - if (!cli) { - return werr; - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetFileEnum_l(struct libnetapi_ctx *ctx, - struct NetFileEnum *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetFileEnum); -} diff --git a/source/lib/netapi/getdc.c b/source/lib/netapi/getdc.c index 07a6544af1..c1d021b1d4 100644 --- a/source/lib/netapi/getdc.c +++ b/source/lib/netapi/getdc.c @@ -31,7 +31,7 @@ WERROR NetGetDCName_l(struct libnetapi_ctx *ctx, struct NetGetDCName *r) { - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGetDCName); + return WERR_NOT_SUPPORTED; } /******************************************************************** @@ -45,10 +45,12 @@ WERROR NetGetDCName_r(struct libnetapi_ctx *ctx, NTSTATUS status; WERROR werr; - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_netlogon.syntax_id, - &cli, - &pipe_cli); + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_NETLOGON, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -69,7 +71,7 @@ WERROR NetGetDCName_r(struct libnetapi_ctx *ctx, WERROR NetGetAnyDCName_l(struct libnetapi_ctx *ctx, struct NetGetAnyDCName *r) { - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGetAnyDCName); + return WERR_NOT_SUPPORTED; } /******************************************************************** @@ -83,10 +85,12 @@ WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx, NTSTATUS status; WERROR werr; - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_netlogon.syntax_id, - &cli, - &pipe_cli); + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_NETLOGON, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -140,10 +144,12 @@ WERROR DsGetDcName_r(struct libnetapi_ctx *ctx, struct cli_state *cli = NULL; struct rpc_pipe_client *pipe_cli = NULL; - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_netlogon.syntax_id, - &cli, - &pipe_cli); + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_NETLOGON, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } diff --git a/source/lib/netapi/group.c b/source/lib/netapi/group.c deleted file mode 100644 index c3fccb4840..0000000000 --- a/source/lib/netapi/group.c +++ /dev/null @@ -1,1691 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetApi Group Support - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include "includes.h" - -#include "librpc/gen_ndr/libnetapi.h" -#include "lib/netapi/netapi.h" -#include "lib/netapi/netapi_private.h" -#include "lib/netapi/libnetapi.h" - -/**************************************************************** -****************************************************************/ - -WERROR NetGroupAdd_r(struct libnetapi_ctx *ctx, - struct NetGroupAdd *r) -{ - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - NTSTATUS status; - WERROR werr; - POLICY_HND connect_handle, domain_handle, group_handle; - struct lsa_String lsa_group_name; - struct dom_sid2 *domain_sid = NULL; - uint32_t rid = 0; - - struct GROUP_INFO_0 *info0 = NULL; - struct GROUP_INFO_1 *info1 = NULL; - struct GROUP_INFO_2 *info2 = NULL; - struct GROUP_INFO_3 *info3 = NULL; - union samr_GroupInfo info; - - ZERO_STRUCT(connect_handle); - ZERO_STRUCT(domain_handle); - ZERO_STRUCT(group_handle); - - if (!r->in.buffer) { - return WERR_INVALID_PARAM; - } - - switch (r->in.level) { - case 0: - info0 = (struct GROUP_INFO_0 *)r->in.buffer; - break; - case 1: - info1 = (struct GROUP_INFO_1 *)r->in.buffer; - break; - case 2: - info2 = (struct GROUP_INFO_2 *)r->in.buffer; - break; - case 3: - info3 = (struct GROUP_INFO_3 *)r->in.buffer; - break; - default: - werr = WERR_UNKNOWN_LEVEL; - goto done; - } - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_CREATE_GROUP | - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - switch (r->in.level) { - case 0: - init_lsa_String(&lsa_group_name, info0->grpi0_name); - break; - case 1: - init_lsa_String(&lsa_group_name, info1->grpi1_name); - break; - case 2: - init_lsa_String(&lsa_group_name, info2->grpi2_name); - break; - case 3: - init_lsa_String(&lsa_group_name, info3->grpi3_name); - break; - } - - status = rpccli_samr_CreateDomainGroup(pipe_cli, ctx, - &domain_handle, - &lsa_group_name, - SEC_STD_DELETE | - SAMR_GROUP_ACCESS_SET_INFO, - &group_handle, - &rid); - - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - switch (r->in.level) { - case 1: - if (info1->grpi1_comment) { - init_lsa_String(&info.description, - info1->grpi1_comment); - - status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, - &group_handle, - GROUPINFODESCRIPTION, - &info); - } - break; - case 2: - if (info2->grpi2_comment) { - init_lsa_String(&info.description, - info2->grpi2_comment); - - status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, - &group_handle, - GROUPINFODESCRIPTION, - &info); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto failed; - } - } - - if (info2->grpi2_attributes != 0) { - info.attributes.attributes = info2->grpi2_attributes; - status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, - &group_handle, - GROUPINFOATTRIBUTES, - &info); - - } - break; - case 3: - if (info3->grpi3_comment) { - init_lsa_String(&info.description, - info3->grpi3_comment); - - status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, - &group_handle, - GROUPINFODESCRIPTION, - &info); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto failed; - } - } - - if (info3->grpi3_attributes != 0) { - info.attributes.attributes = info3->grpi3_attributes; - status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, - &group_handle, - GROUPINFOATTRIBUTES, - &info); - } - break; - default: - break; - } - - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto failed; - } - - werr = WERR_OK; - goto done; - - failed: - rpccli_samr_DeleteDomainGroup(pipe_cli, ctx, - &group_handle); - - done: - if (!cli) { - return werr; - } - - if (is_valid_policy_hnd(&group_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &group_handle); - } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetGroupAdd_l(struct libnetapi_ctx *ctx, - struct NetGroupAdd *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGroupAdd); -} - -/**************************************************************** -****************************************************************/ - -WERROR NetGroupDel_r(struct libnetapi_ctx *ctx, - struct NetGroupDel *r) -{ - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - NTSTATUS status; - WERROR werr; - POLICY_HND connect_handle, domain_handle, group_handle; - struct lsa_String lsa_group_name; - struct dom_sid2 *domain_sid = NULL; - int i = 0; - - struct samr_Ids rids; - struct samr_Ids types; - union samr_GroupInfo *info = NULL; - struct samr_RidTypeArray *rid_array = NULL; - - ZERO_STRUCT(connect_handle); - ZERO_STRUCT(domain_handle); - ZERO_STRUCT(group_handle); - - if (!r->in.group_name) { - return WERR_INVALID_PARAM; - } - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - init_lsa_String(&lsa_group_name, r->in.group_name); - - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &domain_handle, - 1, - &lsa_group_name, - &rids, - &types); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - if (types.ids[0] != SID_NAME_DOM_GRP) { - werr = WERR_INVALID_DATATYPE; - goto done; - } - - status = rpccli_samr_OpenGroup(pipe_cli, ctx, - &domain_handle, - SEC_STD_DELETE | - SAMR_GROUP_ACCESS_GET_MEMBERS | - SAMR_GROUP_ACCESS_REMOVE_MEMBER | - SAMR_GROUP_ACCESS_ADD_MEMBER | - SAMR_GROUP_ACCESS_LOOKUP_INFO, - rids.ids[0], - &group_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_QueryGroupInfo(pipe_cli, ctx, - &group_handle, - GROUPINFOATTRIBUTES, - &info); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - -#if 0 - /* breaks against NT4 */ - if (!(info->attributes.attributes & SE_GROUP_ENABLED)) { - werr = WERR_ACCESS_DENIED; - goto done; - } -#endif - status = rpccli_samr_QueryGroupMember(pipe_cli, ctx, - &group_handle, - &rid_array); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - { - struct lsa_Strings names; - struct samr_Ids member_types; - - status = rpccli_samr_LookupRids(pipe_cli, ctx, - &domain_handle, - rid_array->count, - rid_array->rids, - &names, - &member_types); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - } - - for (i=0; i < rid_array->count; i++) { - - status = rpccli_samr_DeleteGroupMember(pipe_cli, ctx, - &group_handle, - rid_array->rids[i]); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - } - - status = rpccli_samr_DeleteDomainGroup(pipe_cli, ctx, - &group_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - ZERO_STRUCT(group_handle); - - werr = WERR_OK; - - done: - if (!cli) { - return werr; - } - - if (is_valid_policy_hnd(&group_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &group_handle); - } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetGroupDel_l(struct libnetapi_ctx *ctx, - struct NetGroupDel *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGroupDel); -} - -/**************************************************************** -****************************************************************/ - -WERROR NetGroupSetInfo_r(struct libnetapi_ctx *ctx, - struct NetGroupSetInfo *r) -{ - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - NTSTATUS status; - WERROR werr; - POLICY_HND connect_handle, domain_handle, group_handle; - struct lsa_String lsa_group_name; - struct dom_sid2 *domain_sid = NULL; - - struct samr_Ids rids; - struct samr_Ids types; - union samr_GroupInfo info; - struct GROUP_INFO_0 *g0; - struct GROUP_INFO_1 *g1; - struct GROUP_INFO_2 *g2; - struct GROUP_INFO_3 *g3; - struct GROUP_INFO_1002 *g1002; - struct GROUP_INFO_1005 *g1005; - - ZERO_STRUCT(connect_handle); - ZERO_STRUCT(domain_handle); - ZERO_STRUCT(group_handle); - - if (!r->in.group_name) { - return WERR_INVALID_PARAM; - } - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - init_lsa_String(&lsa_group_name, r->in.group_name); - - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &domain_handle, - 1, - &lsa_group_name, - &rids, - &types); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - if (types.ids[0] != SID_NAME_DOM_GRP) { - werr = WERR_INVALID_DATATYPE; - goto done; - } - - status = rpccli_samr_OpenGroup(pipe_cli, ctx, - &domain_handle, - SAMR_GROUP_ACCESS_SET_INFO | - SAMR_GROUP_ACCESS_LOOKUP_INFO, - rids.ids[0], - &group_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - switch (r->in.level) { - case 0: - g0 = (struct GROUP_INFO_0 *)r->in.buffer; - init_lsa_String(&info.name, g0->grpi0_name); - status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, - &group_handle, - GROUPINFONAME, - &info); - break; - case 1: - g1 = (struct GROUP_INFO_1 *)r->in.buffer; - init_lsa_String(&info.description, g1->grpi1_comment); - status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, - &group_handle, - GROUPINFODESCRIPTION, - &info); - break; - case 2: - g2 = (struct GROUP_INFO_2 *)r->in.buffer; - init_lsa_String(&info.description, g2->grpi2_comment); - status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, - &group_handle, - GROUPINFODESCRIPTION, - &info); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - info.attributes.attributes = g2->grpi2_attributes; - status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, - &group_handle, - GROUPINFOATTRIBUTES, - &info); - break; - case 3: - g3 = (struct GROUP_INFO_3 *)r->in.buffer; - init_lsa_String(&info.description, g3->grpi3_comment); - status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, - &group_handle, - GROUPINFODESCRIPTION, - &info); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - info.attributes.attributes = g3->grpi3_attributes; - status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, - &group_handle, - GROUPINFOATTRIBUTES, - &info); - break; - case 1002: - g1002 = (struct GROUP_INFO_1002 *)r->in.buffer; - init_lsa_String(&info.description, g1002->grpi1002_comment); - status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, - &group_handle, - GROUPINFODESCRIPTION, - &info); - break; - case 1005: - g1005 = (struct GROUP_INFO_1005 *)r->in.buffer; - info.attributes.attributes = g1005->grpi1005_attributes; - status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, - &group_handle, - GROUPINFOATTRIBUTES, - &info); - break; - default: - status = NT_STATUS_INVALID_LEVEL; - break; - } - - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - werr = WERR_OK; - - done: - if (!cli) { - return werr; - } - - if (is_valid_policy_hnd(&group_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &group_handle); - } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetGroupSetInfo_l(struct libnetapi_ctx *ctx, - struct NetGroupSetInfo *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGroupSetInfo); -} - -/**************************************************************** -****************************************************************/ - -static WERROR map_group_info_to_buffer(TALLOC_CTX *mem_ctx, - uint32_t level, - struct samr_GroupInfoAll *info, - struct dom_sid2 *domain_sid, - uint32_t rid, - uint8_t **buffer) -{ - struct GROUP_INFO_0 info0; - struct GROUP_INFO_1 info1; - struct GROUP_INFO_2 info2; - struct GROUP_INFO_3 info3; - struct dom_sid sid; - - switch (level) { - case 0: - info0.grpi0_name = info->name.string; - - *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info0, sizeof(info0)); - - break; - case 1: - info1.grpi1_name = info->name.string; - info1.grpi1_comment = info->description.string; - - *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info1, sizeof(info1)); - - break; - case 2: - info2.grpi2_name = info->name.string; - info2.grpi2_comment = info->description.string; - info2.grpi2_group_id = rid; - info2.grpi2_attributes = info->attributes; - - *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info2, sizeof(info2)); - - break; - case 3: - if (!sid_compose(&sid, domain_sid, rid)) { - return WERR_NOMEM; - } - - info3.grpi3_name = info->name.string; - info3.grpi3_comment = info->description.string; - info3.grpi3_attributes = info->attributes; - info3.grpi3_group_sid = (struct domsid *)sid_dup_talloc(mem_ctx, &sid); - - *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info3, sizeof(info3)); - - break; - default: - return WERR_UNKNOWN_LEVEL; - } - - W_ERROR_HAVE_NO_MEMORY(*buffer); - - return WERR_OK; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetGroupGetInfo_r(struct libnetapi_ctx *ctx, - struct NetGroupGetInfo *r) -{ - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - NTSTATUS status; - WERROR werr; - POLICY_HND connect_handle, domain_handle, group_handle; - struct lsa_String lsa_group_name; - struct dom_sid2 *domain_sid = NULL; - - struct samr_Ids rids; - struct samr_Ids types; - union samr_GroupInfo *info = NULL; - bool group_info_all = false; - - ZERO_STRUCT(connect_handle); - ZERO_STRUCT(domain_handle); - ZERO_STRUCT(group_handle); - - if (!r->in.group_name) { - return WERR_INVALID_PARAM; - } - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - init_lsa_String(&lsa_group_name, r->in.group_name); - - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &domain_handle, - 1, - &lsa_group_name, - &rids, - &types); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - if (types.ids[0] != SID_NAME_DOM_GRP) { - werr = WERR_INVALID_DATATYPE; - goto done; - } - - status = rpccli_samr_OpenGroup(pipe_cli, ctx, - &domain_handle, - SAMR_GROUP_ACCESS_LOOKUP_INFO, - rids.ids[0], - &group_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_QueryGroupInfo(pipe_cli, ctx, - &group_handle, - GROUPINFOALL2, - &info); - if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_INFO_CLASS)) { - status = rpccli_samr_QueryGroupInfo(pipe_cli, ctx, - &group_handle, - GROUPINFOALL, - &info); - group_info_all = true; - } - - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - werr = map_group_info_to_buffer(ctx, r->in.level, - group_info_all ? &info->all : &info->all2, - domain_sid, rids.ids[0], - r->out.buffer); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - done: - if (!cli) { - return werr; - } - - if (is_valid_policy_hnd(&group_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &group_handle); - } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetGroupGetInfo_l(struct libnetapi_ctx *ctx, - struct NetGroupGetInfo *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGroupGetInfo); -} - -/**************************************************************** -****************************************************************/ - -WERROR NetGroupAddUser_r(struct libnetapi_ctx *ctx, - struct NetGroupAddUser *r) -{ - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - NTSTATUS status; - WERROR werr; - POLICY_HND connect_handle, domain_handle, group_handle; - struct lsa_String lsa_group_name, lsa_user_name; - struct dom_sid2 *domain_sid = NULL; - - struct samr_Ids rids; - struct samr_Ids types; - - ZERO_STRUCT(connect_handle); - ZERO_STRUCT(domain_handle); - ZERO_STRUCT(group_handle); - - if (!r->in.group_name) { - return WERR_INVALID_PARAM; - } - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - init_lsa_String(&lsa_group_name, r->in.group_name); - - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &domain_handle, - 1, - &lsa_group_name, - &rids, - &types); - if (!NT_STATUS_IS_OK(status)) { - werr = WERR_GROUP_NOT_FOUND; - goto done; - } - - if (types.ids[0] != SID_NAME_DOM_GRP) { - werr = WERR_GROUP_NOT_FOUND; - goto done; - } - - status = rpccli_samr_OpenGroup(pipe_cli, ctx, - &domain_handle, - SAMR_GROUP_ACCESS_ADD_MEMBER, - rids.ids[0], - &group_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - init_lsa_String(&lsa_user_name, r->in.user_name); - - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &domain_handle, - 1, - &lsa_user_name, - &rids, - &types); - if (!NT_STATUS_IS_OK(status)) { - werr = WERR_USER_NOT_FOUND; - goto done; - } - - if (types.ids[0] != SID_NAME_USER) { - werr = WERR_USER_NOT_FOUND; - goto done; - } - - status = rpccli_samr_AddGroupMember(pipe_cli, ctx, - &group_handle, - rids.ids[0], - 7); /* why ? */ - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - werr = WERR_OK; - - done: - if (!cli) { - return werr; - } - - if (is_valid_policy_hnd(&group_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &group_handle); - } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetGroupAddUser_l(struct libnetapi_ctx *ctx, - struct NetGroupAddUser *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGroupAddUser); -} - -/**************************************************************** -****************************************************************/ - -WERROR NetGroupDelUser_r(struct libnetapi_ctx *ctx, - struct NetGroupDelUser *r) -{ - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - NTSTATUS status; - WERROR werr; - POLICY_HND connect_handle, domain_handle, group_handle; - struct lsa_String lsa_group_name, lsa_user_name; - struct dom_sid2 *domain_sid = NULL; - - struct samr_Ids rids; - struct samr_Ids types; - - ZERO_STRUCT(connect_handle); - ZERO_STRUCT(domain_handle); - ZERO_STRUCT(group_handle); - - if (!r->in.group_name) { - return WERR_INVALID_PARAM; - } - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - init_lsa_String(&lsa_group_name, r->in.group_name); - - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &domain_handle, - 1, - &lsa_group_name, - &rids, - &types); - if (!NT_STATUS_IS_OK(status)) { - werr = WERR_GROUP_NOT_FOUND; - goto done; - } - - if (types.ids[0] != SID_NAME_DOM_GRP) { - werr = WERR_GROUP_NOT_FOUND; - goto done; - } - - status = rpccli_samr_OpenGroup(pipe_cli, ctx, - &domain_handle, - SAMR_GROUP_ACCESS_REMOVE_MEMBER, - rids.ids[0], - &group_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - init_lsa_String(&lsa_user_name, r->in.user_name); - - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &domain_handle, - 1, - &lsa_user_name, - &rids, - &types); - if (!NT_STATUS_IS_OK(status)) { - werr = WERR_USER_NOT_FOUND; - goto done; - } - - if (types.ids[0] != SID_NAME_USER) { - werr = WERR_USER_NOT_FOUND; - goto done; - } - - status = rpccli_samr_DeleteGroupMember(pipe_cli, ctx, - &group_handle, - rids.ids[0]); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - werr = WERR_OK; - - done: - if (!cli) { - return werr; - } - - if (is_valid_policy_hnd(&group_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &group_handle); - } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetGroupDelUser_l(struct libnetapi_ctx *ctx, - struct NetGroupDelUser *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGroupDelUser); -} - -/**************************************************************** -****************************************************************/ - -static WERROR convert_samr_disp_groups_to_GROUP_INFO_0_buffer(TALLOC_CTX *mem_ctx, - struct samr_DispInfoFullGroups *groups, - uint8_t **buffer) -{ - struct GROUP_INFO_0 *g0; - int i; - - g0 = TALLOC_ZERO_ARRAY(mem_ctx, struct GROUP_INFO_0, groups->count); - W_ERROR_HAVE_NO_MEMORY(g0); - - for (i=0; i<groups->count; i++) { - g0[i].grpi0_name = talloc_strdup(mem_ctx, - groups->entries[i].account_name.string); - W_ERROR_HAVE_NO_MEMORY(g0[i].grpi0_name); - } - - *buffer = (uint8_t *)talloc_memdup(mem_ctx, g0, - sizeof(struct GROUP_INFO_0) * groups->count); - W_ERROR_HAVE_NO_MEMORY(*buffer); - - return WERR_OK; -} - -/**************************************************************** -****************************************************************/ - -static WERROR convert_samr_disp_groups_to_GROUP_INFO_1_buffer(TALLOC_CTX *mem_ctx, - struct samr_DispInfoFullGroups *groups, - uint8_t **buffer) -{ - struct GROUP_INFO_1 *g1; - int i; - - g1 = TALLOC_ZERO_ARRAY(mem_ctx, struct GROUP_INFO_1, groups->count); - W_ERROR_HAVE_NO_MEMORY(g1); - - for (i=0; i<groups->count; i++) { - g1[i].grpi1_name = talloc_strdup(mem_ctx, - groups->entries[i].account_name.string); - g1[i].grpi1_comment = talloc_strdup(mem_ctx, - groups->entries[i].description.string); - W_ERROR_HAVE_NO_MEMORY(g1[i].grpi1_name); - } - - *buffer = (uint8_t *)talloc_memdup(mem_ctx, g1, - sizeof(struct GROUP_INFO_1) * groups->count); - W_ERROR_HAVE_NO_MEMORY(*buffer); - - return WERR_OK; -} - -/**************************************************************** -****************************************************************/ - -static WERROR convert_samr_disp_groups_to_GROUP_INFO_2_buffer(TALLOC_CTX *mem_ctx, - struct samr_DispInfoFullGroups *groups, - uint8_t **buffer) -{ - struct GROUP_INFO_2 *g2; - int i; - - g2 = TALLOC_ZERO_ARRAY(mem_ctx, struct GROUP_INFO_2, groups->count); - W_ERROR_HAVE_NO_MEMORY(g2); - - for (i=0; i<groups->count; i++) { - g2[i].grpi2_name = talloc_strdup(mem_ctx, - groups->entries[i].account_name.string); - g2[i].grpi2_comment = talloc_strdup(mem_ctx, - groups->entries[i].description.string); - g2[i].grpi2_group_id = groups->entries[i].rid; - g2[i].grpi2_attributes = groups->entries[i].acct_flags; - W_ERROR_HAVE_NO_MEMORY(g2[i].grpi2_name); - } - - *buffer = (uint8_t *)talloc_memdup(mem_ctx, g2, - sizeof(struct GROUP_INFO_2) * groups->count); - W_ERROR_HAVE_NO_MEMORY(*buffer); - - return WERR_OK; -} - -/**************************************************************** -****************************************************************/ - -static WERROR convert_samr_disp_groups_to_GROUP_INFO_3_buffer(TALLOC_CTX *mem_ctx, - struct samr_DispInfoFullGroups *groups, - const struct dom_sid *domain_sid, - uint8_t **buffer) -{ - struct GROUP_INFO_3 *g3; - int i; - - g3 = TALLOC_ZERO_ARRAY(mem_ctx, struct GROUP_INFO_3, groups->count); - W_ERROR_HAVE_NO_MEMORY(g3); - - for (i=0; i<groups->count; i++) { - - struct dom_sid sid; - - if (!sid_compose(&sid, domain_sid, groups->entries[i].rid)) { - return WERR_NOMEM; - } - - g3[i].grpi3_name = talloc_strdup(mem_ctx, - groups->entries[i].account_name.string); - g3[i].grpi3_comment = talloc_strdup(mem_ctx, - groups->entries[i].description.string); - g3[i].grpi3_group_sid = (struct domsid *)sid_dup_talloc(mem_ctx, &sid); - g3[i].grpi3_attributes = groups->entries[i].acct_flags; - W_ERROR_HAVE_NO_MEMORY(g3[i].grpi3_name); - } - - *buffer = (uint8_t *)talloc_memdup(mem_ctx, g3, - sizeof(struct GROUP_INFO_3) * groups->count); - W_ERROR_HAVE_NO_MEMORY(*buffer); - - return WERR_OK; -} - -/**************************************************************** -****************************************************************/ - -static WERROR convert_samr_disp_groups_to_GROUP_INFO_buffer(TALLOC_CTX *mem_ctx, - uint32_t level, - struct samr_DispInfoFullGroups *groups, - const struct dom_sid *domain_sid, - uint32_t *entries_read, - uint8_t **buffer) -{ - if (entries_read) { - *entries_read = groups->count; - } - - switch (level) { - case 0: - return convert_samr_disp_groups_to_GROUP_INFO_0_buffer(mem_ctx, groups, buffer); - case 1: - return convert_samr_disp_groups_to_GROUP_INFO_1_buffer(mem_ctx, groups, buffer); - case 2: - return convert_samr_disp_groups_to_GROUP_INFO_2_buffer(mem_ctx, groups, buffer); - case 3: - return convert_samr_disp_groups_to_GROUP_INFO_3_buffer(mem_ctx, groups, domain_sid, buffer); - default: - return WERR_UNKNOWN_LEVEL; - } -} - -/**************************************************************** -****************************************************************/ - -WERROR NetGroupEnum_r(struct libnetapi_ctx *ctx, - struct NetGroupEnum *r) -{ - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - struct policy_handle connect_handle; - struct dom_sid2 *domain_sid = NULL; - struct policy_handle domain_handle; - union samr_DispInfo info; - union samr_DomainInfo *domain_info = NULL; - - uint32_t total_size = 0; - uint32_t returned_size = 0; - - NTSTATUS status = NT_STATUS_OK; - WERROR werr, tmp_werr; - - ZERO_STRUCT(connect_handle); - ZERO_STRUCT(domain_handle); - - switch (r->in.level) { - case 0: - case 1: - case 2: - case 3: - break; - default: - return WERR_UNKNOWN_LEVEL; - } - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 | - SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS | - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - status = rpccli_samr_QueryDomainInfo(pipe_cli, ctx, - &domain_handle, - 2, - &domain_info); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - if (r->out.total_entries) { - *r->out.total_entries = domain_info->info2.num_groups; - } - - status = rpccli_samr_QueryDisplayInfo2(pipe_cli, - ctx, - &domain_handle, - 3, - r->in.resume_handle ? - *r->in.resume_handle : 0, - (uint32_t)-1, - r->in.prefmaxlen, - &total_size, - &returned_size, - &info); - werr = ntstatus_to_werror(status); - if (NT_STATUS_IS_ERR(status)) { - goto done; - } - - if (r->out.resume_handle) { - *r->out.resume_handle = - info.info3.entries[info.info3.count-1].idx; - } - - tmp_werr = convert_samr_disp_groups_to_GROUP_INFO_buffer(ctx, - r->in.level, - &info.info3, - domain_sid, - r->out.entries_read, - r->out.buffer); - if (!W_ERROR_IS_OK(tmp_werr)) { - werr = tmp_werr; - goto done; - } - - done: - if (!cli) { - return werr; - } - - /* if last query */ - if (NT_STATUS_IS_OK(status) || - NT_STATUS_IS_ERR(status)) { - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetGroupEnum_l(struct libnetapi_ctx *ctx, - struct NetGroupEnum *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGroupEnum); -} - -/**************************************************************** -****************************************************************/ - -WERROR NetGroupGetUsers_r(struct libnetapi_ctx *ctx, - struct NetGroupGetUsers *r) -{ - /* FIXME: this call needs to cope with large replies */ - - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - struct policy_handle connect_handle, domain_handle, group_handle; - struct lsa_String lsa_account_name; - struct dom_sid2 *domain_sid = NULL; - struct samr_Ids group_rids, name_types; - struct samr_RidTypeArray *rid_array = NULL; - struct lsa_Strings names; - struct samr_Ids member_types; - - int i; - uint32_t entries_read = 0; - - NTSTATUS status = NT_STATUS_OK; - WERROR werr; - - ZERO_STRUCT(connect_handle); - ZERO_STRUCT(domain_handle); - - if (!r->out.buffer) { - return WERR_INVALID_PARAM; - } - - *r->out.buffer = NULL; - *r->out.entries_read = 0; - - switch (r->in.level) { - case 0: - case 1: - break; - default: - return WERR_UNKNOWN_LEVEL; - } - - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - init_lsa_String(&lsa_account_name, r->in.group_name); - - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &domain_handle, - 1, - &lsa_account_name, - &group_rids, - &name_types); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_OpenGroup(pipe_cli, ctx, - &domain_handle, - SAMR_GROUP_ACCESS_GET_MEMBERS, - group_rids.ids[0], - &group_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_QueryGroupMember(pipe_cli, ctx, - &group_handle, - &rid_array); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_LookupRids(pipe_cli, ctx, - &domain_handle, - rid_array->count, - rid_array->rids, - &names, - &member_types); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - for (i=0; i < names.count; i++) { - - if (member_types.ids[i] != SID_NAME_USER) { - continue; - } - - status = add_GROUP_USERS_INFO_X_buffer(ctx, - r->in.level, - names.names[i].string, - 7, - r->out.buffer, - &entries_read); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - } - - if (r->out.entries_read) { - *r->out.entries_read = entries_read; - } - - if (r->out.total_entries) { - *r->out.total_entries = entries_read; - } - - werr = WERR_OK; - - done: - if (!cli) { - return werr; - } - - if (is_valid_policy_hnd(&group_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &group_handle); - } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetGroupGetUsers_l(struct libnetapi_ctx *ctx, - struct NetGroupGetUsers *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGroupGetUsers); -} - -/**************************************************************** -****************************************************************/ - -WERROR NetGroupSetUsers_r(struct libnetapi_ctx *ctx, - struct NetGroupSetUsers *r) -{ - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - struct policy_handle connect_handle, domain_handle, group_handle; - struct lsa_String lsa_account_name; - struct dom_sid2 *domain_sid = NULL; - union samr_GroupInfo *group_info = NULL; - struct samr_Ids user_rids, name_types; - struct samr_Ids group_rids, group_types; - struct samr_RidTypeArray *rid_array = NULL; - struct lsa_String *lsa_names = NULL; - - uint32_t *add_rids = NULL; - uint32_t *del_rids = NULL; - size_t num_add_rids = 0; - size_t num_del_rids = 0; - - uint32_t *member_rids = NULL; - size_t num_member_rids = 0; - - struct GROUP_USERS_INFO_0 *i0 = NULL; - struct GROUP_USERS_INFO_1 *i1 = NULL; - - int i, k; - - NTSTATUS status = NT_STATUS_OK; - WERROR werr; - - ZERO_STRUCT(connect_handle); - ZERO_STRUCT(domain_handle); - - if (!r->in.buffer) { - return WERR_INVALID_PARAM; - } - - switch (r->in.level) { - case 0: - case 1: - break; - default: - return WERR_UNKNOWN_LEVEL; - } - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - init_lsa_String(&lsa_account_name, r->in.group_name); - - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &domain_handle, - 1, - &lsa_account_name, - &group_rids, - &group_types); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_OpenGroup(pipe_cli, ctx, - &domain_handle, - SAMR_GROUP_ACCESS_GET_MEMBERS | - SAMR_GROUP_ACCESS_ADD_MEMBER | - SAMR_GROUP_ACCESS_REMOVE_MEMBER | - SAMR_GROUP_ACCESS_LOOKUP_INFO, - group_rids.ids[0], - &group_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_QueryGroupInfo(pipe_cli, ctx, - &group_handle, - GROUPINFOATTRIBUTES, - &group_info); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - switch (r->in.level) { - case 0: - i0 = (struct GROUP_USERS_INFO_0 *)r->in.buffer; - break; - case 1: - i1 = (struct GROUP_USERS_INFO_1 *)r->in.buffer; - break; - } - - lsa_names = talloc_array(ctx, struct lsa_String, r->in.num_entries); - if (!lsa_names) { - werr = WERR_NOMEM; - goto done; - } - - for (i=0; i < r->in.num_entries; i++) { - - switch (r->in.level) { - case 0: - init_lsa_String(&lsa_names[i], i0->grui0_name); - i0++; - break; - case 1: - init_lsa_String(&lsa_names[i], i1->grui1_name); - i1++; - break; - } - } - - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &domain_handle, - r->in.num_entries, - lsa_names, - &user_rids, - &name_types); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - member_rids = user_rids.ids; - num_member_rids = user_rids.count; - - status = rpccli_samr_QueryGroupMember(pipe_cli, ctx, - &group_handle, - &rid_array); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - /* add list */ - - for (i=0; i < r->in.num_entries; i++) { - bool already_member = false; - for (k=0; k < rid_array->count; k++) { - if (member_rids[i] == rid_array->rids[k]) { - already_member = true; - break; - } - } - if (!already_member) { - if (!add_rid_to_array_unique(ctx, - member_rids[i], - &add_rids, &num_add_rids)) { - werr = WERR_GENERAL_FAILURE; - goto done; - } - } - } - - /* del list */ - - for (k=0; k < rid_array->count; k++) { - bool keep_member = false; - for (i=0; i < r->in.num_entries; i++) { - if (member_rids[i] == rid_array->rids[k]) { - keep_member = true; - break; - } - } - if (!keep_member) { - if (!add_rid_to_array_unique(ctx, - rid_array->rids[k], - &del_rids, &num_del_rids)) { - werr = WERR_GENERAL_FAILURE; - goto done; - } - } - } - - /* add list */ - - for (i=0; i < num_add_rids; i++) { - status = rpccli_samr_AddGroupMember(pipe_cli, ctx, - &group_handle, - add_rids[i], - 7 /* ? */); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - } - - /* del list */ - - for (i=0; i < num_del_rids; i++) { - status = rpccli_samr_DeleteGroupMember(pipe_cli, ctx, - &group_handle, - del_rids[i]); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - } - - werr = WERR_OK; - - done: - if (!cli) { - return werr; - } - - if (is_valid_policy_hnd(&group_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &group_handle); - } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetGroupSetUsers_l(struct libnetapi_ctx *ctx, - struct NetGroupSetUsers *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGroupSetUsers); -} diff --git a/source/lib/netapi/joindomain.c b/source/lib/netapi/joindomain.c index d15e2e733c..66f7cfb13f 100644 --- a/source/lib/netapi/joindomain.c +++ b/source/lib/netapi/joindomain.c @@ -105,10 +105,12 @@ WERROR NetJoinDomain_r(struct libnetapi_ctx *ctx, WERROR werr; unsigned int old_timeout = 0; - werr = libnetapi_open_pipe(ctx, r->in.server, - &ndr_table_wkssvc.syntax_id, - &cli, - &pipe_cli); + werr = libnetapi_open_ipc_connection(ctx, r->in.server, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_WKSSVC, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -234,10 +236,12 @@ WERROR NetUnjoinDomain_r(struct libnetapi_ctx *ctx, WERROR werr; unsigned int old_timeout = 0; - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_wkssvc.syntax_id, - &cli, - &pipe_cli); + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_WKSSVC, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -284,10 +288,12 @@ WERROR NetGetJoinInformation_r(struct libnetapi_ctx *ctx, WERROR werr; const char *buffer = NULL; - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_wkssvc.syntax_id, - &cli, - &pipe_cli); + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_WKSSVC, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -364,7 +370,7 @@ WERROR NetGetJoinableOUs_l(struct libnetapi_ctx *ctx, dc = strip_hostname(info->dc_unc); - ads = ads_init(info->domain_name, info->domain_name, dc); + ads = ads_init(r->in.domain, r->in.domain, dc); if (!ads) { return WERR_GENERAL_FAILURE; } @@ -383,7 +389,7 @@ WERROR NetGetJoinableOUs_l(struct libnetapi_ctx *ctx, ads->auth.password = SMB_STRDUP(ctx->password); } - ads_status = ads_connect_user_creds(ads); + ads_status = ads_connect(ads); if (!ADS_ERR_OK(ads_status)) { ads_destroy(&ads); return WERR_DEFAULT_JOIN_REQUIRED; @@ -416,10 +422,12 @@ WERROR NetGetJoinableOUs_r(struct libnetapi_ctx *ctx, NTSTATUS status; WERROR werr; - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_wkssvc.syntax_id, - &cli, - &pipe_cli); + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_WKSSVC, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -445,57 +453,9 @@ WERROR NetGetJoinableOUs_r(struct libnetapi_ctx *ctx, } done: - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetRenameMachineInDomain_r(struct libnetapi_ctx *ctx, - struct NetRenameMachineInDomain *r) -{ - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - struct wkssvc_PasswordBuffer *encrypted_password = NULL; - NTSTATUS status; - WERROR werr; - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_wkssvc.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - if (r->in.password) { - encode_wkssvc_join_password_buffer(ctx, - r->in.password, - &cli->user_session_key, - &encrypted_password); - } - - status = rpccli_wkssvc_NetrRenameMachineInDomain2(pipe_cli, ctx, - r->in.server_name, - r->in.new_machine_name, - r->in.account, - encrypted_password, - r->in.rename_options, - &werr); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; + if (cli) { + cli_shutdown(cli); } - done: return werr; } - -/**************************************************************** -****************************************************************/ - -WERROR NetRenameMachineInDomain_l(struct libnetapi_ctx *ctx, - struct NetRenameMachineInDomain *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetRenameMachineInDomain); -} diff --git a/source/lib/netapi/libnetapi.c b/source/lib/netapi/libnetapi.c index 043190a1f9..e71adc6893 100644 --- a/source/lib/netapi/libnetapi.c +++ b/source/lib/netapi/libnetapi.c @@ -21,7 +21,7 @@ #include "librpc/gen_ndr/libnetapi.h" #include "lib/netapi/netapi.h" #include "lib/netapi/netapi_private.h" -#include "lib/netapi/libnetapi.h" +#include "libnetapi.h" #include "librpc/gen_ndr/ndr_libnetapi.h" /**************************************************************** @@ -215,54 +215,6 @@ NET_API_STATUS NetGetJoinableOUs(const char * server_name /* [in] [unique] */, } /**************************************************************** - NetRenameMachineInDomain -****************************************************************/ - -NET_API_STATUS NetRenameMachineInDomain(const char * server_name /* [in] */, - const char * new_machine_name /* [in] */, - const char * account /* [in] */, - const char * password /* [in] */, - uint32_t rename_options /* [in] */) -{ - struct NetRenameMachineInDomain r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.new_machine_name = new_machine_name; - r.in.account = account; - r.in.password = password; - r.in.rename_options = rename_options; - - /* Out parameters */ - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetRenameMachineInDomain, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetRenameMachineInDomain_l(ctx, &r); - } else { - werr = NetRenameMachineInDomain_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetRenameMachineInDomain, &r); - } - - return r.out.result; -} - -/**************************************************************** NetServerGetInfo ****************************************************************/ @@ -634,390 +586,6 @@ NET_API_STATUS NetUserEnum(const char * server_name /* [in] [unique] */, } /**************************************************************** - NetUserChangePassword -****************************************************************/ - -NET_API_STATUS NetUserChangePassword(const char * domain_name /* [in] */, - const char * user_name /* [in] */, - const char * old_password /* [in] */, - const char * new_password /* [in] */) -{ - struct NetUserChangePassword r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.domain_name = domain_name; - r.in.user_name = user_name; - r.in.old_password = old_password; - r.in.new_password = new_password; - - /* Out parameters */ - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetUserChangePassword, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(domain_name)) { - werr = NetUserChangePassword_l(ctx, &r); - } else { - werr = NetUserChangePassword_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetUserChangePassword, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetUserGetInfo -****************************************************************/ - -NET_API_STATUS NetUserGetInfo(const char * server_name /* [in] */, - const char * user_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */) -{ - struct NetUserGetInfo r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.user_name = user_name; - r.in.level = level; - - /* Out parameters */ - r.out.buffer = buffer; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetUserGetInfo, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetUserGetInfo_l(ctx, &r); - } else { - werr = NetUserGetInfo_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetUserGetInfo, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetUserSetInfo -****************************************************************/ - -NET_API_STATUS NetUserSetInfo(const char * server_name /* [in] */, - const char * user_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */) -{ - struct NetUserSetInfo r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.user_name = user_name; - r.in.level = level; - r.in.buffer = buffer; - - /* Out parameters */ - r.out.parm_err = parm_err; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetUserSetInfo, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetUserSetInfo_l(ctx, &r); - } else { - werr = NetUserSetInfo_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetUserSetInfo, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetUserGetGroups -****************************************************************/ - -NET_API_STATUS NetUserGetGroups(const char * server_name /* [in] */, - const char * user_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */) -{ - struct NetUserGetGroups r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.user_name = user_name; - r.in.level = level; - r.in.prefmaxlen = prefmaxlen; - - /* Out parameters */ - r.out.buffer = buffer; - r.out.entries_read = entries_read; - r.out.total_entries = total_entries; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetUserGetGroups, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetUserGetGroups_l(ctx, &r); - } else { - werr = NetUserGetGroups_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetUserGetGroups, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetUserSetGroups -****************************************************************/ - -NET_API_STATUS NetUserSetGroups(const char * server_name /* [in] */, - const char * user_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t num_entries /* [in] */) -{ - struct NetUserSetGroups r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.user_name = user_name; - r.in.level = level; - r.in.buffer = buffer; - r.in.num_entries = num_entries; - - /* Out parameters */ - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetUserSetGroups, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetUserSetGroups_l(ctx, &r); - } else { - werr = NetUserSetGroups_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetUserSetGroups, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetUserGetLocalGroups -****************************************************************/ - -NET_API_STATUS NetUserGetLocalGroups(const char * server_name /* [in] */, - const char * user_name /* [in] */, - uint32_t level /* [in] */, - uint32_t flags /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */) -{ - struct NetUserGetLocalGroups r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.user_name = user_name; - r.in.level = level; - r.in.flags = flags; - r.in.prefmaxlen = prefmaxlen; - - /* Out parameters */ - r.out.buffer = buffer; - r.out.entries_read = entries_read; - r.out.total_entries = total_entries; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetUserGetLocalGroups, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetUserGetLocalGroups_l(ctx, &r); - } else { - werr = NetUserGetLocalGroups_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetUserGetLocalGroups, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetUserModalsGet -****************************************************************/ - -NET_API_STATUS NetUserModalsGet(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */) -{ - struct NetUserModalsGet r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.level = level; - - /* Out parameters */ - r.out.buffer = buffer; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetUserModalsGet, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetUserModalsGet_l(ctx, &r); - } else { - werr = NetUserModalsGet_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetUserModalsGet, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetUserModalsSet -****************************************************************/ - -NET_API_STATUS NetUserModalsSet(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */) -{ - struct NetUserModalsSet r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.level = level; - r.in.buffer = buffer; - - /* Out parameters */ - r.out.parm_err = parm_err; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetUserModalsSet, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetUserModalsSet_l(ctx, &r); - } else { - werr = NetUserModalsSet_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetUserModalsSet, &r); - } - - return r.out.result; -} - -/**************************************************************** NetQueryDisplayInformation ****************************************************************/ @@ -1069,1287 +637,3 @@ NET_API_STATUS NetQueryDisplayInformation(const char * server_name /* [in] [uniq return r.out.result; } -/**************************************************************** - NetGroupAdd -****************************************************************/ - -NET_API_STATUS NetGroupAdd(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */) -{ - struct NetGroupAdd r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.level = level; - r.in.buffer = buffer; - - /* Out parameters */ - r.out.parm_err = parm_err; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetGroupAdd, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetGroupAdd_l(ctx, &r); - } else { - werr = NetGroupAdd_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetGroupAdd, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetGroupDel -****************************************************************/ - -NET_API_STATUS NetGroupDel(const char * server_name /* [in] */, - const char * group_name /* [in] */) -{ - struct NetGroupDel r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.group_name = group_name; - - /* Out parameters */ - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetGroupDel, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetGroupDel_l(ctx, &r); - } else { - werr = NetGroupDel_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetGroupDel, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetGroupEnum -****************************************************************/ - -NET_API_STATUS NetGroupEnum(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */, - uint32_t *resume_handle /* [in,out] [ref] */) -{ - struct NetGroupEnum r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.level = level; - r.in.prefmaxlen = prefmaxlen; - r.in.resume_handle = resume_handle; - - /* Out parameters */ - r.out.buffer = buffer; - r.out.entries_read = entries_read; - r.out.total_entries = total_entries; - r.out.resume_handle = resume_handle; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetGroupEnum, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetGroupEnum_l(ctx, &r); - } else { - werr = NetGroupEnum_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetGroupEnum, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetGroupSetInfo -****************************************************************/ - -NET_API_STATUS NetGroupSetInfo(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */) -{ - struct NetGroupSetInfo r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.group_name = group_name; - r.in.level = level; - r.in.buffer = buffer; - - /* Out parameters */ - r.out.parm_err = parm_err; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetGroupSetInfo, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetGroupSetInfo_l(ctx, &r); - } else { - werr = NetGroupSetInfo_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetGroupSetInfo, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetGroupGetInfo -****************************************************************/ - -NET_API_STATUS NetGroupGetInfo(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */) -{ - struct NetGroupGetInfo r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.group_name = group_name; - r.in.level = level; - - /* Out parameters */ - r.out.buffer = buffer; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetGroupGetInfo, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetGroupGetInfo_l(ctx, &r); - } else { - werr = NetGroupGetInfo_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetGroupGetInfo, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetGroupAddUser -****************************************************************/ - -NET_API_STATUS NetGroupAddUser(const char * server_name /* [in] */, - const char * group_name /* [in] */, - const char * user_name /* [in] */) -{ - struct NetGroupAddUser r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.group_name = group_name; - r.in.user_name = user_name; - - /* Out parameters */ - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetGroupAddUser, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetGroupAddUser_l(ctx, &r); - } else { - werr = NetGroupAddUser_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetGroupAddUser, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetGroupDelUser -****************************************************************/ - -NET_API_STATUS NetGroupDelUser(const char * server_name /* [in] */, - const char * group_name /* [in] */, - const char * user_name /* [in] */) -{ - struct NetGroupDelUser r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.group_name = group_name; - r.in.user_name = user_name; - - /* Out parameters */ - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetGroupDelUser, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetGroupDelUser_l(ctx, &r); - } else { - werr = NetGroupDelUser_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetGroupDelUser, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetGroupGetUsers -****************************************************************/ - -NET_API_STATUS NetGroupGetUsers(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */, - uint32_t *resume_handle /* [in,out] [ref] */) -{ - struct NetGroupGetUsers r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.group_name = group_name; - r.in.level = level; - r.in.prefmaxlen = prefmaxlen; - r.in.resume_handle = resume_handle; - - /* Out parameters */ - r.out.buffer = buffer; - r.out.entries_read = entries_read; - r.out.total_entries = total_entries; - r.out.resume_handle = resume_handle; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetGroupGetUsers, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetGroupGetUsers_l(ctx, &r); - } else { - werr = NetGroupGetUsers_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetGroupGetUsers, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetGroupSetUsers -****************************************************************/ - -NET_API_STATUS NetGroupSetUsers(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t num_entries /* [in] */) -{ - struct NetGroupSetUsers r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.group_name = group_name; - r.in.level = level; - r.in.buffer = buffer; - r.in.num_entries = num_entries; - - /* Out parameters */ - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetGroupSetUsers, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetGroupSetUsers_l(ctx, &r); - } else { - werr = NetGroupSetUsers_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetGroupSetUsers, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetLocalGroupAdd -****************************************************************/ - -NET_API_STATUS NetLocalGroupAdd(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */) -{ - struct NetLocalGroupAdd r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.level = level; - r.in.buffer = buffer; - - /* Out parameters */ - r.out.parm_err = parm_err; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetLocalGroupAdd, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetLocalGroupAdd_l(ctx, &r); - } else { - werr = NetLocalGroupAdd_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetLocalGroupAdd, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetLocalGroupDel -****************************************************************/ - -NET_API_STATUS NetLocalGroupDel(const char * server_name /* [in] */, - const char * group_name /* [in] */) -{ - struct NetLocalGroupDel r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.group_name = group_name; - - /* Out parameters */ - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetLocalGroupDel, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetLocalGroupDel_l(ctx, &r); - } else { - werr = NetLocalGroupDel_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetLocalGroupDel, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetLocalGroupGetInfo -****************************************************************/ - -NET_API_STATUS NetLocalGroupGetInfo(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */) -{ - struct NetLocalGroupGetInfo r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.group_name = group_name; - r.in.level = level; - - /* Out parameters */ - r.out.buffer = buffer; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetLocalGroupGetInfo, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetLocalGroupGetInfo_l(ctx, &r); - } else { - werr = NetLocalGroupGetInfo_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetLocalGroupGetInfo, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetLocalGroupSetInfo -****************************************************************/ - -NET_API_STATUS NetLocalGroupSetInfo(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */) -{ - struct NetLocalGroupSetInfo r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.group_name = group_name; - r.in.level = level; - r.in.buffer = buffer; - - /* Out parameters */ - r.out.parm_err = parm_err; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetLocalGroupSetInfo, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetLocalGroupSetInfo_l(ctx, &r); - } else { - werr = NetLocalGroupSetInfo_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetLocalGroupSetInfo, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetLocalGroupEnum -****************************************************************/ - -NET_API_STATUS NetLocalGroupEnum(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */, - uint32_t *resume_handle /* [in,out] [ref] */) -{ - struct NetLocalGroupEnum r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.level = level; - r.in.prefmaxlen = prefmaxlen; - r.in.resume_handle = resume_handle; - - /* Out parameters */ - r.out.buffer = buffer; - r.out.entries_read = entries_read; - r.out.total_entries = total_entries; - r.out.resume_handle = resume_handle; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetLocalGroupEnum, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetLocalGroupEnum_l(ctx, &r); - } else { - werr = NetLocalGroupEnum_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetLocalGroupEnum, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetLocalGroupAddMembers -****************************************************************/ - -NET_API_STATUS NetLocalGroupAddMembers(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t total_entries /* [in] */) -{ - struct NetLocalGroupAddMembers r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.group_name = group_name; - r.in.level = level; - r.in.buffer = buffer; - r.in.total_entries = total_entries; - - /* Out parameters */ - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetLocalGroupAddMembers, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetLocalGroupAddMembers_l(ctx, &r); - } else { - werr = NetLocalGroupAddMembers_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetLocalGroupAddMembers, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetLocalGroupDelMembers -****************************************************************/ - -NET_API_STATUS NetLocalGroupDelMembers(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t total_entries /* [in] */) -{ - struct NetLocalGroupDelMembers r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.group_name = group_name; - r.in.level = level; - r.in.buffer = buffer; - r.in.total_entries = total_entries; - - /* Out parameters */ - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetLocalGroupDelMembers, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetLocalGroupDelMembers_l(ctx, &r); - } else { - werr = NetLocalGroupDelMembers_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetLocalGroupDelMembers, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetLocalGroupGetMembers -****************************************************************/ - -NET_API_STATUS NetLocalGroupGetMembers(const char * server_name /* [in] */, - const char * local_group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */, - uint32_t *resume_handle /* [in,out] [ref] */) -{ - struct NetLocalGroupGetMembers r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.local_group_name = local_group_name; - r.in.level = level; - r.in.prefmaxlen = prefmaxlen; - r.in.resume_handle = resume_handle; - - /* Out parameters */ - r.out.buffer = buffer; - r.out.entries_read = entries_read; - r.out.total_entries = total_entries; - r.out.resume_handle = resume_handle; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetLocalGroupGetMembers, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetLocalGroupGetMembers_l(ctx, &r); - } else { - werr = NetLocalGroupGetMembers_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetLocalGroupGetMembers, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetLocalGroupSetMembers -****************************************************************/ - -NET_API_STATUS NetLocalGroupSetMembers(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t total_entries /* [in] */) -{ - struct NetLocalGroupSetMembers r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.group_name = group_name; - r.in.level = level; - r.in.buffer = buffer; - r.in.total_entries = total_entries; - - /* Out parameters */ - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetLocalGroupSetMembers, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetLocalGroupSetMembers_l(ctx, &r); - } else { - werr = NetLocalGroupSetMembers_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetLocalGroupSetMembers, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetRemoteTOD -****************************************************************/ - -NET_API_STATUS NetRemoteTOD(const char * server_name /* [in] */, - uint8_t **buffer /* [out] [ref] */) -{ - struct NetRemoteTOD r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - - /* Out parameters */ - r.out.buffer = buffer; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetRemoteTOD, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetRemoteTOD_l(ctx, &r); - } else { - werr = NetRemoteTOD_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetRemoteTOD, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetShareAdd -****************************************************************/ - -NET_API_STATUS NetShareAdd(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */) -{ - struct NetShareAdd r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.level = level; - r.in.buffer = buffer; - - /* Out parameters */ - r.out.parm_err = parm_err; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetShareAdd, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetShareAdd_l(ctx, &r); - } else { - werr = NetShareAdd_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetShareAdd, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetShareDel -****************************************************************/ - -NET_API_STATUS NetShareDel(const char * server_name /* [in] */, - const char * net_name /* [in] */, - uint32_t reserved /* [in] */) -{ - struct NetShareDel r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.net_name = net_name; - r.in.reserved = reserved; - - /* Out parameters */ - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetShareDel, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetShareDel_l(ctx, &r); - } else { - werr = NetShareDel_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetShareDel, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetShareEnum -****************************************************************/ - -NET_API_STATUS NetShareEnum(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */, - uint32_t *resume_handle /* [in,out] [ref] */) -{ - struct NetShareEnum r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.level = level; - r.in.prefmaxlen = prefmaxlen; - r.in.resume_handle = resume_handle; - - /* Out parameters */ - r.out.buffer = buffer; - r.out.entries_read = entries_read; - r.out.total_entries = total_entries; - r.out.resume_handle = resume_handle; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetShareEnum, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetShareEnum_l(ctx, &r); - } else { - werr = NetShareEnum_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetShareEnum, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetShareGetInfo -****************************************************************/ - -NET_API_STATUS NetShareGetInfo(const char * server_name /* [in] */, - const char * net_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */) -{ - struct NetShareGetInfo r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.net_name = net_name; - r.in.level = level; - - /* Out parameters */ - r.out.buffer = buffer; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetShareGetInfo, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetShareGetInfo_l(ctx, &r); - } else { - werr = NetShareGetInfo_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetShareGetInfo, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetShareSetInfo -****************************************************************/ - -NET_API_STATUS NetShareSetInfo(const char * server_name /* [in] */, - const char * net_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */) -{ - struct NetShareSetInfo r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.net_name = net_name; - r.in.level = level; - r.in.buffer = buffer; - - /* Out parameters */ - r.out.parm_err = parm_err; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetShareSetInfo, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetShareSetInfo_l(ctx, &r); - } else { - werr = NetShareSetInfo_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetShareSetInfo, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetFileClose -****************************************************************/ - -NET_API_STATUS NetFileClose(const char * server_name /* [in] */, - uint32_t fileid /* [in] */) -{ - struct NetFileClose r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.fileid = fileid; - - /* Out parameters */ - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetFileClose, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetFileClose_l(ctx, &r); - } else { - werr = NetFileClose_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetFileClose, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetFileGetInfo -****************************************************************/ - -NET_API_STATUS NetFileGetInfo(const char * server_name /* [in] */, - uint32_t fileid /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */) -{ - struct NetFileGetInfo r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.fileid = fileid; - r.in.level = level; - - /* Out parameters */ - r.out.buffer = buffer; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetFileGetInfo, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetFileGetInfo_l(ctx, &r); - } else { - werr = NetFileGetInfo_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetFileGetInfo, &r); - } - - return r.out.result; -} - -/**************************************************************** - NetFileEnum -****************************************************************/ - -NET_API_STATUS NetFileEnum(const char * server_name /* [in] */, - const char * base_path /* [in] */, - const char * user_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */, - uint32_t *resume_handle /* [in,out] [ref] */) -{ - struct NetFileEnum r; - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - /* In parameters */ - r.in.server_name = server_name; - r.in.base_path = base_path; - r.in.user_name = user_name; - r.in.level = level; - r.in.prefmaxlen = prefmaxlen; - r.in.resume_handle = resume_handle; - - /* Out parameters */ - r.out.buffer = buffer; - r.out.entries_read = entries_read; - r.out.total_entries = total_entries; - r.out.resume_handle = resume_handle; - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_IN_DEBUG(NetFileEnum, &r); - } - - if (LIBNETAPI_LOCAL_SERVER(server_name)) { - werr = NetFileEnum_l(ctx, &r); - } else { - werr = NetFileEnum_r(ctx, &r); - } - - r.out.result = W_ERROR_V(werr); - - if (DEBUGLEVEL >= 10) { - NDR_PRINT_OUT_DEBUG(NetFileEnum, &r); - } - - return r.out.result; -} - diff --git a/source/lib/netapi/libnetapi.h b/source/lib/netapi/libnetapi.h index 1b84b75f94..7aff355652 100644 --- a/source/lib/netapi/libnetapi.h +++ b/source/lib/netapi/libnetapi.h @@ -35,15 +35,6 @@ WERROR NetGetJoinableOUs_r(struct libnetapi_ctx *ctx, struct NetGetJoinableOUs *r); WERROR NetGetJoinableOUs_l(struct libnetapi_ctx *ctx, struct NetGetJoinableOUs *r); -NET_API_STATUS NetRenameMachineInDomain(const char * server_name /* [in] */, - const char * new_machine_name /* [in] */, - const char * account /* [in] */, - const char * password /* [in] */, - uint32_t rename_options /* [in] */); -WERROR NetRenameMachineInDomain_r(struct libnetapi_ctx *ctx, - struct NetRenameMachineInDomain *r); -WERROR NetRenameMachineInDomain_l(struct libnetapi_ctx *ctx, - struct NetRenameMachineInDomain *r); NET_API_STATUS NetServerGetInfo(const char * server_name /* [in] [unique] */, uint32_t level /* [in] */, uint8_t **buffer /* [out] [ref] */); @@ -109,78 +100,6 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, struct NetUserEnum *r); WERROR NetUserEnum_l(struct libnetapi_ctx *ctx, struct NetUserEnum *r); -NET_API_STATUS NetUserChangePassword(const char * domain_name /* [in] */, - const char * user_name /* [in] */, - const char * old_password /* [in] */, - const char * new_password /* [in] */); -WERROR NetUserChangePassword_r(struct libnetapi_ctx *ctx, - struct NetUserChangePassword *r); -WERROR NetUserChangePassword_l(struct libnetapi_ctx *ctx, - struct NetUserChangePassword *r); -NET_API_STATUS NetUserGetInfo(const char * server_name /* [in] */, - const char * user_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */); -WERROR NetUserGetInfo_r(struct libnetapi_ctx *ctx, - struct NetUserGetInfo *r); -WERROR NetUserGetInfo_l(struct libnetapi_ctx *ctx, - struct NetUserGetInfo *r); -NET_API_STATUS NetUserSetInfo(const char * server_name /* [in] */, - const char * user_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */); -WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, - struct NetUserSetInfo *r); -WERROR NetUserSetInfo_l(struct libnetapi_ctx *ctx, - struct NetUserSetInfo *r); -NET_API_STATUS NetUserGetGroups(const char * server_name /* [in] */, - const char * user_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */); -WERROR NetUserGetGroups_r(struct libnetapi_ctx *ctx, - struct NetUserGetGroups *r); -WERROR NetUserGetGroups_l(struct libnetapi_ctx *ctx, - struct NetUserGetGroups *r); -NET_API_STATUS NetUserSetGroups(const char * server_name /* [in] */, - const char * user_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t num_entries /* [in] */); -WERROR NetUserSetGroups_r(struct libnetapi_ctx *ctx, - struct NetUserSetGroups *r); -WERROR NetUserSetGroups_l(struct libnetapi_ctx *ctx, - struct NetUserSetGroups *r); -NET_API_STATUS NetUserGetLocalGroups(const char * server_name /* [in] */, - const char * user_name /* [in] */, - uint32_t level /* [in] */, - uint32_t flags /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */); -WERROR NetUserGetLocalGroups_r(struct libnetapi_ctx *ctx, - struct NetUserGetLocalGroups *r); -WERROR NetUserGetLocalGroups_l(struct libnetapi_ctx *ctx, - struct NetUserGetLocalGroups *r); -NET_API_STATUS NetUserModalsGet(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */); -WERROR NetUserModalsGet_r(struct libnetapi_ctx *ctx, - struct NetUserModalsGet *r); -WERROR NetUserModalsGet_l(struct libnetapi_ctx *ctx, - struct NetUserModalsGet *r); -NET_API_STATUS NetUserModalsSet(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */); -WERROR NetUserModalsSet_r(struct libnetapi_ctx *ctx, - struct NetUserModalsSet *r); -WERROR NetUserModalsSet_l(struct libnetapi_ctx *ctx, - struct NetUserModalsSet *r); NET_API_STATUS NetQueryDisplayInformation(const char * server_name /* [in] [unique] */, uint32_t level /* [in] */, uint32_t idx /* [in] */, @@ -192,238 +111,4 @@ WERROR NetQueryDisplayInformation_r(struct libnetapi_ctx *ctx, struct NetQueryDisplayInformation *r); WERROR NetQueryDisplayInformation_l(struct libnetapi_ctx *ctx, struct NetQueryDisplayInformation *r); -NET_API_STATUS NetGroupAdd(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */); -WERROR NetGroupAdd_r(struct libnetapi_ctx *ctx, - struct NetGroupAdd *r); -WERROR NetGroupAdd_l(struct libnetapi_ctx *ctx, - struct NetGroupAdd *r); -NET_API_STATUS NetGroupDel(const char * server_name /* [in] */, - const char * group_name /* [in] */); -WERROR NetGroupDel_r(struct libnetapi_ctx *ctx, - struct NetGroupDel *r); -WERROR NetGroupDel_l(struct libnetapi_ctx *ctx, - struct NetGroupDel *r); -NET_API_STATUS NetGroupEnum(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */, - uint32_t *resume_handle /* [in,out] [ref] */); -WERROR NetGroupEnum_r(struct libnetapi_ctx *ctx, - struct NetGroupEnum *r); -WERROR NetGroupEnum_l(struct libnetapi_ctx *ctx, - struct NetGroupEnum *r); -NET_API_STATUS NetGroupSetInfo(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */); -WERROR NetGroupSetInfo_r(struct libnetapi_ctx *ctx, - struct NetGroupSetInfo *r); -WERROR NetGroupSetInfo_l(struct libnetapi_ctx *ctx, - struct NetGroupSetInfo *r); -NET_API_STATUS NetGroupGetInfo(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */); -WERROR NetGroupGetInfo_r(struct libnetapi_ctx *ctx, - struct NetGroupGetInfo *r); -WERROR NetGroupGetInfo_l(struct libnetapi_ctx *ctx, - struct NetGroupGetInfo *r); -NET_API_STATUS NetGroupAddUser(const char * server_name /* [in] */, - const char * group_name /* [in] */, - const char * user_name /* [in] */); -WERROR NetGroupAddUser_r(struct libnetapi_ctx *ctx, - struct NetGroupAddUser *r); -WERROR NetGroupAddUser_l(struct libnetapi_ctx *ctx, - struct NetGroupAddUser *r); -NET_API_STATUS NetGroupDelUser(const char * server_name /* [in] */, - const char * group_name /* [in] */, - const char * user_name /* [in] */); -WERROR NetGroupDelUser_r(struct libnetapi_ctx *ctx, - struct NetGroupDelUser *r); -WERROR NetGroupDelUser_l(struct libnetapi_ctx *ctx, - struct NetGroupDelUser *r); -NET_API_STATUS NetGroupGetUsers(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */, - uint32_t *resume_handle /* [in,out] [ref] */); -WERROR NetGroupGetUsers_r(struct libnetapi_ctx *ctx, - struct NetGroupGetUsers *r); -WERROR NetGroupGetUsers_l(struct libnetapi_ctx *ctx, - struct NetGroupGetUsers *r); -NET_API_STATUS NetGroupSetUsers(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t num_entries /* [in] */); -WERROR NetGroupSetUsers_r(struct libnetapi_ctx *ctx, - struct NetGroupSetUsers *r); -WERROR NetGroupSetUsers_l(struct libnetapi_ctx *ctx, - struct NetGroupSetUsers *r); -NET_API_STATUS NetLocalGroupAdd(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */); -WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, - struct NetLocalGroupAdd *r); -WERROR NetLocalGroupAdd_l(struct libnetapi_ctx *ctx, - struct NetLocalGroupAdd *r); -NET_API_STATUS NetLocalGroupDel(const char * server_name /* [in] */, - const char * group_name /* [in] */); -WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, - struct NetLocalGroupDel *r); -WERROR NetLocalGroupDel_l(struct libnetapi_ctx *ctx, - struct NetLocalGroupDel *r); -NET_API_STATUS NetLocalGroupGetInfo(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */); -WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, - struct NetLocalGroupGetInfo *r); -WERROR NetLocalGroupGetInfo_l(struct libnetapi_ctx *ctx, - struct NetLocalGroupGetInfo *r); -NET_API_STATUS NetLocalGroupSetInfo(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */); -WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, - struct NetLocalGroupSetInfo *r); -WERROR NetLocalGroupSetInfo_l(struct libnetapi_ctx *ctx, - struct NetLocalGroupSetInfo *r); -NET_API_STATUS NetLocalGroupEnum(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */, - uint32_t *resume_handle /* [in,out] [ref] */); -WERROR NetLocalGroupEnum_r(struct libnetapi_ctx *ctx, - struct NetLocalGroupEnum *r); -WERROR NetLocalGroupEnum_l(struct libnetapi_ctx *ctx, - struct NetLocalGroupEnum *r); -NET_API_STATUS NetLocalGroupAddMembers(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t total_entries /* [in] */); -WERROR NetLocalGroupAddMembers_r(struct libnetapi_ctx *ctx, - struct NetLocalGroupAddMembers *r); -WERROR NetLocalGroupAddMembers_l(struct libnetapi_ctx *ctx, - struct NetLocalGroupAddMembers *r); -NET_API_STATUS NetLocalGroupDelMembers(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t total_entries /* [in] */); -WERROR NetLocalGroupDelMembers_r(struct libnetapi_ctx *ctx, - struct NetLocalGroupDelMembers *r); -WERROR NetLocalGroupDelMembers_l(struct libnetapi_ctx *ctx, - struct NetLocalGroupDelMembers *r); -NET_API_STATUS NetLocalGroupGetMembers(const char * server_name /* [in] */, - const char * local_group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */, - uint32_t *resume_handle /* [in,out] [ref] */); -WERROR NetLocalGroupGetMembers_r(struct libnetapi_ctx *ctx, - struct NetLocalGroupGetMembers *r); -WERROR NetLocalGroupGetMembers_l(struct libnetapi_ctx *ctx, - struct NetLocalGroupGetMembers *r); -NET_API_STATUS NetLocalGroupSetMembers(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t total_entries /* [in] */); -WERROR NetLocalGroupSetMembers_r(struct libnetapi_ctx *ctx, - struct NetLocalGroupSetMembers *r); -WERROR NetLocalGroupSetMembers_l(struct libnetapi_ctx *ctx, - struct NetLocalGroupSetMembers *r); -NET_API_STATUS NetRemoteTOD(const char * server_name /* [in] */, - uint8_t **buffer /* [out] [ref] */); -WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx, - struct NetRemoteTOD *r); -WERROR NetRemoteTOD_l(struct libnetapi_ctx *ctx, - struct NetRemoteTOD *r); -NET_API_STATUS NetShareAdd(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */); -WERROR NetShareAdd_r(struct libnetapi_ctx *ctx, - struct NetShareAdd *r); -WERROR NetShareAdd_l(struct libnetapi_ctx *ctx, - struct NetShareAdd *r); -NET_API_STATUS NetShareDel(const char * server_name /* [in] */, - const char * net_name /* [in] */, - uint32_t reserved /* [in] */); -WERROR NetShareDel_r(struct libnetapi_ctx *ctx, - struct NetShareDel *r); -WERROR NetShareDel_l(struct libnetapi_ctx *ctx, - struct NetShareDel *r); -NET_API_STATUS NetShareEnum(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */, - uint32_t *resume_handle /* [in,out] [ref] */); -WERROR NetShareEnum_r(struct libnetapi_ctx *ctx, - struct NetShareEnum *r); -WERROR NetShareEnum_l(struct libnetapi_ctx *ctx, - struct NetShareEnum *r); -NET_API_STATUS NetShareGetInfo(const char * server_name /* [in] */, - const char * net_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */); -WERROR NetShareGetInfo_r(struct libnetapi_ctx *ctx, - struct NetShareGetInfo *r); -WERROR NetShareGetInfo_l(struct libnetapi_ctx *ctx, - struct NetShareGetInfo *r); -NET_API_STATUS NetShareSetInfo(const char * server_name /* [in] */, - const char * net_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */); -WERROR NetShareSetInfo_r(struct libnetapi_ctx *ctx, - struct NetShareSetInfo *r); -WERROR NetShareSetInfo_l(struct libnetapi_ctx *ctx, - struct NetShareSetInfo *r); -NET_API_STATUS NetFileClose(const char * server_name /* [in] */, - uint32_t fileid /* [in] */); -WERROR NetFileClose_r(struct libnetapi_ctx *ctx, - struct NetFileClose *r); -WERROR NetFileClose_l(struct libnetapi_ctx *ctx, - struct NetFileClose *r); -NET_API_STATUS NetFileGetInfo(const char * server_name /* [in] */, - uint32_t fileid /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */); -WERROR NetFileGetInfo_r(struct libnetapi_ctx *ctx, - struct NetFileGetInfo *r); -WERROR NetFileGetInfo_l(struct libnetapi_ctx *ctx, - struct NetFileGetInfo *r); -NET_API_STATUS NetFileEnum(const char * server_name /* [in] */, - const char * base_path /* [in] */, - const char * user_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */, - uint32_t *resume_handle /* [in,out] [ref] */); -WERROR NetFileEnum_r(struct libnetapi_ctx *ctx, - struct NetFileEnum *r); -WERROR NetFileEnum_l(struct libnetapi_ctx *ctx, - struct NetFileEnum *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ diff --git a/source/lib/netapi/localgroup.c b/source/lib/netapi/localgroup.c deleted file mode 100644 index 25a3427bc1..0000000000 --- a/source/lib/netapi/localgroup.c +++ /dev/null @@ -1,1358 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetApi LocalGroup Support - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include "includes.h" - -#include "librpc/gen_ndr/libnetapi.h" -#include "lib/netapi/netapi.h" -#include "lib/netapi/netapi_private.h" -#include "lib/netapi/libnetapi.h" - -static NTSTATUS libnetapi_samr_lookup_and_open_alias(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *pipe_cli, - struct policy_handle *domain_handle, - const char *group_name, - uint32_t access_rights, - struct policy_handle *alias_handle) -{ - NTSTATUS status; - - struct lsa_String lsa_account_name; - struct samr_Ids user_rids, name_types; - - init_lsa_String(&lsa_account_name, group_name); - - status = rpccli_samr_LookupNames(pipe_cli, mem_ctx, - domain_handle, - 1, - &lsa_account_name, - &user_rids, - &name_types); - if (!NT_STATUS_IS_OK(status)) { - return status; - } - - switch (name_types.ids[0]) { - case SID_NAME_ALIAS: - case SID_NAME_WKN_GRP: - break; - default: - return NT_STATUS_INVALID_SID; - } - - return rpccli_samr_OpenAlias(pipe_cli, mem_ctx, - domain_handle, - access_rights, - user_rids.ids[0], - alias_handle); -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS libnetapi_samr_open_alias_queryinfo(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *pipe_cli, - struct policy_handle *handle, - uint32_t rid, - uint32_t access_rights, - enum samr_AliasInfoEnum level, - union samr_AliasInfo **alias_info) -{ - NTSTATUS status; - struct policy_handle alias_handle; - union samr_AliasInfo *_alias_info = NULL; - - ZERO_STRUCT(alias_handle); - - status = rpccli_samr_OpenAlias(pipe_cli, mem_ctx, - handle, - access_rights, - rid, - &alias_handle); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - - status = rpccli_samr_QueryAliasInfo(pipe_cli, mem_ctx, - &alias_handle, - level, - &_alias_info); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - - *alias_info = _alias_info; - - done: - if (is_valid_policy_hnd(&alias_handle)) { - rpccli_samr_Close(pipe_cli, mem_ctx, &alias_handle); - } - - return status; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, - struct NetLocalGroupAdd *r) -{ - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - NTSTATUS status; - WERROR werr; - struct lsa_String lsa_account_name; - struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; - struct dom_sid2 *domain_sid = NULL; - uint32_t rid; - - struct LOCALGROUP_INFO_0 *info0 = NULL; - struct LOCALGROUP_INFO_1 *info1 = NULL; - - const char *alias_name = NULL; - - if (!r->in.buffer) { - return WERR_INVALID_PARAM; - } - - switch (r->in.level) { - case 0: - info0 = (struct LOCALGROUP_INFO_0 *)r->in.buffer; - alias_name = info0->lgrpi0_name; - break; - case 1: - info1 = (struct LOCALGROUP_INFO_1 *)r->in.buffer; - alias_name = info1->lgrpi1_name; - break; - default: - werr = WERR_UNKNOWN_LEVEL; - goto done; - } - - ZERO_STRUCT(connect_handle); - ZERO_STRUCT(builtin_handle); - ZERO_STRUCT(domain_handle); - ZERO_STRUCT(alias_handle); - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, - SAMR_ACCESS_OPEN_DOMAIN | - SAMR_ACCESS_ENUM_DOMAINS, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &builtin_handle); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - status = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, - &builtin_handle, - alias_name, - SAMR_ALIAS_ACCESS_LOOKUP_INFO, - &alias_handle); - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); - } - - if (NT_STATUS_IS_OK(status)) { - werr = WERR_ALIAS_EXISTS; - goto done; - } - - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_CREATE_ALIAS | - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - init_lsa_String(&lsa_account_name, alias_name); - - status = rpccli_samr_CreateDomAlias(pipe_cli, ctx, - &domain_handle, - &lsa_account_name, - SEC_STD_DELETE | - SAMR_ALIAS_ACCESS_SET_INFO, - &alias_handle, - &rid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - if (r->in.level == 1 && info1->lgrpi1_comment) { - - union samr_AliasInfo alias_info; - - init_lsa_String(&alias_info.description, info1->lgrpi1_comment); - - status = rpccli_samr_SetAliasInfo(pipe_cli, ctx, - &alias_handle, - ALIASINFODESCRIPTION, - &alias_info); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - } - - werr = WERR_OK; - - done: - if (!cli) { - return werr; - } - - if (is_valid_policy_hnd(&alias_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &alias_handle); - } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetLocalGroupAdd_l(struct libnetapi_ctx *ctx, - struct NetLocalGroupAdd *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetLocalGroupAdd); -} - -/**************************************************************** -****************************************************************/ - - -WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, - struct NetLocalGroupDel *r) -{ - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - NTSTATUS status; - WERROR werr; - struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; - struct dom_sid2 *domain_sid = NULL; - - if (!r->in.group_name) { - return WERR_INVALID_PARAM; - } - - ZERO_STRUCT(connect_handle); - ZERO_STRUCT(builtin_handle); - ZERO_STRUCT(domain_handle); - ZERO_STRUCT(alias_handle); - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, - SAMR_ACCESS_OPEN_DOMAIN | - SAMR_ACCESS_ENUM_DOMAINS, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &builtin_handle); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - status = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, - &builtin_handle, - r->in.group_name, - SEC_STD_DELETE, - &alias_handle); - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); - } - - if (NT_STATUS_IS_OK(status)) { - goto delete_alias; - } - - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_CREATE_ALIAS | - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - status = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, - &domain_handle, - r->in.group_name, - SEC_STD_DELETE, - &alias_handle); - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - } - - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - - delete_alias: - status = rpccli_samr_DeleteDomAlias(pipe_cli, ctx, - &alias_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - ZERO_STRUCT(alias_handle); - - werr = WERR_OK; - - done: - if (!cli) { - return werr; - } - - if (is_valid_policy_hnd(&alias_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &alias_handle); - } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetLocalGroupDel_l(struct libnetapi_ctx *ctx, - struct NetLocalGroupDel *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetLocalGroupDel); -} - -/**************************************************************** -****************************************************************/ - -static WERROR map_alias_info_to_buffer(TALLOC_CTX *mem_ctx, - const char *alias_name, - struct samr_AliasInfoAll *info, - uint32_t level, - uint32_t *entries_read, - uint8_t **buffer) -{ - struct LOCALGROUP_INFO_0 g0; - struct LOCALGROUP_INFO_1 g1; - struct LOCALGROUP_INFO_1002 g1002; - - switch (level) { - case 0: - g0.lgrpi0_name = talloc_strdup(mem_ctx, alias_name); - W_ERROR_HAVE_NO_MEMORY(g0.lgrpi0_name); - - ADD_TO_ARRAY(mem_ctx, struct LOCALGROUP_INFO_0, g0, - (struct LOCALGROUP_INFO_0 **)buffer, entries_read); - - break; - case 1: - g1.lgrpi1_name = talloc_strdup(mem_ctx, alias_name); - g1.lgrpi1_comment = talloc_strdup(mem_ctx, info->description.string); - W_ERROR_HAVE_NO_MEMORY(g1.lgrpi1_name); - - ADD_TO_ARRAY(mem_ctx, struct LOCALGROUP_INFO_1, g1, - (struct LOCALGROUP_INFO_1 **)buffer, entries_read); - - break; - case 1002: - g1002.lgrpi1002_comment = talloc_strdup(mem_ctx, info->description.string); - - ADD_TO_ARRAY(mem_ctx, struct LOCALGROUP_INFO_1002, g1002, - (struct LOCALGROUP_INFO_1002 **)buffer, entries_read); - - break; - default: - return WERR_UNKNOWN_LEVEL; - } - - return WERR_OK; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, - struct NetLocalGroupGetInfo *r) -{ - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - NTSTATUS status; - WERROR werr; - struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; - struct dom_sid2 *domain_sid = NULL; - union samr_AliasInfo *alias_info = NULL; - uint32_t entries_read = 0; - - if (!r->in.group_name) { - return WERR_INVALID_PARAM; - } - - switch (r->in.level) { - case 0: - case 1: - case 1002: - break; - default: - return WERR_UNKNOWN_LEVEL; - } - - ZERO_STRUCT(connect_handle); - ZERO_STRUCT(builtin_handle); - ZERO_STRUCT(domain_handle); - ZERO_STRUCT(alias_handle); - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, - SAMR_ACCESS_OPEN_DOMAIN | - SAMR_ACCESS_ENUM_DOMAINS, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &builtin_handle); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - status = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, - &builtin_handle, - r->in.group_name, - SAMR_ALIAS_ACCESS_LOOKUP_INFO, - &alias_handle); - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); - } - - if (NT_STATUS_IS_OK(status)) { - goto query_alias; - } - - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_CREATE_ALIAS | - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - status = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, - &domain_handle, - r->in.group_name, - SAMR_ALIAS_ACCESS_LOOKUP_INFO, - &alias_handle); - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - } - - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - query_alias: - status = rpccli_samr_QueryAliasInfo(pipe_cli, ctx, - &alias_handle, - ALIASINFOALL, - &alias_info); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - werr = map_alias_info_to_buffer(ctx, - r->in.group_name, - &alias_info->all, - r->in.level, &entries_read, - r->out.buffer); - - done: - if (!cli) { - return werr; - } - - if (is_valid_policy_hnd(&alias_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &alias_handle); - } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetLocalGroupGetInfo_l(struct libnetapi_ctx *ctx, - struct NetLocalGroupGetInfo *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetLocalGroupGetInfo); -} - -/**************************************************************** -****************************************************************/ - -static WERROR map_buffer_to_alias_info(TALLOC_CTX *mem_ctx, - uint32_t level, - uint8_t *buffer, - enum samr_AliasInfoEnum *alias_level, - union samr_AliasInfo **alias_info) -{ - struct LOCALGROUP_INFO_0 *info0; - struct LOCALGROUP_INFO_1 *info1; - struct LOCALGROUP_INFO_1002 *info1002; - union samr_AliasInfo *info = NULL; - - info = TALLOC_ZERO_P(mem_ctx, union samr_AliasInfo); - W_ERROR_HAVE_NO_MEMORY(info); - - switch (level) { - case 0: - info0 = (struct LOCALGROUP_INFO_0 *)buffer; - init_lsa_String(&info->name, info0->lgrpi0_name); - *alias_level = ALIASINFONAME; - break; - case 1: - info1 = (struct LOCALGROUP_INFO_1 *)buffer; - /* group name will be ignored */ - init_lsa_String(&info->description, info1->lgrpi1_comment); - *alias_level = ALIASINFODESCRIPTION; - break; - case 1002: - info1002 = (struct LOCALGROUP_INFO_1002 *)buffer; - init_lsa_String(&info->description, info1002->lgrpi1002_comment); - *alias_level = ALIASINFODESCRIPTION; - break; - } - - *alias_info = info; - - return WERR_OK; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, - struct NetLocalGroupSetInfo *r) -{ - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - NTSTATUS status; - WERROR werr; - struct lsa_String lsa_account_name; - struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; - struct dom_sid2 *domain_sid = NULL; - enum samr_AliasInfoEnum alias_level = 0; - union samr_AliasInfo *alias_info = NULL; - - if (!r->in.group_name) { - return WERR_INVALID_PARAM; - } - - switch (r->in.level) { - case 0: - case 1: - case 1002: - break; - default: - return WERR_UNKNOWN_LEVEL; - } - - ZERO_STRUCT(connect_handle); - ZERO_STRUCT(builtin_handle); - ZERO_STRUCT(domain_handle); - ZERO_STRUCT(alias_handle); - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, - SAMR_ACCESS_OPEN_DOMAIN | - SAMR_ACCESS_ENUM_DOMAINS, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &builtin_handle); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - init_lsa_String(&lsa_account_name, r->in.group_name); - - status = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, - &builtin_handle, - r->in.group_name, - SAMR_ALIAS_ACCESS_SET_INFO, - &alias_handle); - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); - } - - if (NT_STATUS_IS_OK(status)) { - goto set_alias; - } - - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - status = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, - &domain_handle, - r->in.group_name, - SAMR_ALIAS_ACCESS_SET_INFO, - &alias_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - } - - set_alias: - - werr = map_buffer_to_alias_info(ctx, r->in.level, r->in.buffer, - &alias_level, &alias_info); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - status = rpccli_samr_SetAliasInfo(pipe_cli, ctx, - &alias_handle, - alias_level, - alias_info); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - werr = WERR_OK; - - done: - if (!cli) { - return werr; - } - - if (is_valid_policy_hnd(&alias_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &alias_handle); - } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetLocalGroupSetInfo_l(struct libnetapi_ctx *ctx, - struct NetLocalGroupSetInfo *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetLocalGroupSetInfo); -} - -/**************************************************************** -****************************************************************/ - -WERROR NetLocalGroupEnum_r(struct libnetapi_ctx *ctx, - struct NetLocalGroupEnum *r) -{ - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - NTSTATUS status; - WERROR werr; - struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; - struct dom_sid2 *domain_sid = NULL; - uint32_t entries_read = 0; - union samr_DomainInfo *domain_info = NULL; - union samr_DomainInfo *builtin_info = NULL; - struct samr_SamArray *domain_sam_array = NULL; - struct samr_SamArray *builtin_sam_array = NULL; - int i; - - if (!r->out.buffer) { - return WERR_INVALID_PARAM; - } - - switch (r->in.level) { - case 0: - case 1: - break; - default: - return WERR_UNKNOWN_LEVEL; - } - - if (r->out.total_entries) { - *r->out.total_entries = 0; - } - if (r->out.entries_read) { - *r->out.entries_read = 0; - } - - ZERO_STRUCT(connect_handle); - ZERO_STRUCT(builtin_handle); - ZERO_STRUCT(domain_handle); - ZERO_STRUCT(alias_handle); - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, - SAMR_ACCESS_OPEN_DOMAIN | - SAMR_ACCESS_ENUM_DOMAINS, - SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 | - SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS | - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &builtin_handle); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_OPEN_DOMAIN | - SAMR_ACCESS_ENUM_DOMAINS, - SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 | - SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS | - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - status = rpccli_samr_QueryDomainInfo(pipe_cli, ctx, - &builtin_handle, - 2, - &builtin_info); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - if (r->out.total_entries) { - *r->out.total_entries += builtin_info->info2.num_aliases; - } - - status = rpccli_samr_QueryDomainInfo(pipe_cli, ctx, - &domain_handle, - 2, - &domain_info); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - if (r->out.total_entries) { - *r->out.total_entries += domain_info->info2.num_aliases; - } - - status = rpccli_samr_EnumDomainAliases(pipe_cli, ctx, - &builtin_handle, - r->in.resume_handle, - &builtin_sam_array, - r->in.prefmaxlen, - &entries_read); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - for (i=0; i<builtin_sam_array->count; i++) { - union samr_AliasInfo *alias_info = NULL; - - if (r->in.level == 1) { - - status = libnetapi_samr_open_alias_queryinfo(ctx, pipe_cli, - &builtin_handle, - builtin_sam_array->entries[i].idx, - SAMR_ALIAS_ACCESS_LOOKUP_INFO, - ALIASINFOALL, - &alias_info); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - } - - werr = map_alias_info_to_buffer(ctx, - builtin_sam_array->entries[i].name.string, - alias_info ? &alias_info->all : NULL, - r->in.level, - r->out.entries_read, - r->out.buffer); - } - - status = rpccli_samr_EnumDomainAliases(pipe_cli, ctx, - &domain_handle, - r->in.resume_handle, - &domain_sam_array, - r->in.prefmaxlen, - &entries_read); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - for (i=0; i<domain_sam_array->count; i++) { - - union samr_AliasInfo *alias_info = NULL; - - if (r->in.level == 1) { - status = libnetapi_samr_open_alias_queryinfo(ctx, pipe_cli, - &domain_handle, - domain_sam_array->entries[i].idx, - SAMR_ALIAS_ACCESS_LOOKUP_INFO, - ALIASINFOALL, - &alias_info); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - } - - werr = map_alias_info_to_buffer(ctx, - domain_sam_array->entries[i].name.string, - alias_info ? &alias_info->all : NULL, - r->in.level, - r->out.entries_read, - r->out.buffer); - } - - done: - if (!cli) { - return werr; - } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetLocalGroupEnum_l(struct libnetapi_ctx *ctx, - struct NetLocalGroupEnum *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetLocalGroupEnum); -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS libnetapi_lsa_lookup_names3(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *lsa_pipe, - const char *name, - struct dom_sid *sid) -{ - NTSTATUS status; - struct policy_handle lsa_handle; - - struct lsa_RefDomainList *domains = NULL; - struct lsa_TransSidArray3 sids; - uint32_t count = 0; - - struct lsa_String names; - uint32_t num_names = 1; - - if (!sid || !name) { - return NT_STATUS_INVALID_PARAMETER; - } - - ZERO_STRUCT(sids); - - init_lsa_String(&names, name); - - status = rpccli_lsa_open_policy2(lsa_pipe, mem_ctx, - false, - STD_RIGHT_READ_CONTROL_ACCESS | - LSA_POLICY_VIEW_LOCAL_INFORMATION | - LSA_POLICY_LOOKUP_NAMES, - &lsa_handle); - NT_STATUS_NOT_OK_RETURN(status); - - status = rpccli_lsa_LookupNames3(lsa_pipe, mem_ctx, - &lsa_handle, - num_names, - &names, - &domains, - &sids, - LSA_LOOKUP_NAMES_ALL, /* sure ? */ - &count, - 0, 0); - NT_STATUS_NOT_OK_RETURN(status); - - if (count != 1 || sids.count != 1) { - return NT_STATUS_NONE_MAPPED; - } - - sid_copy(sid, sids.sids[0].sid); - - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - -static WERROR NetLocalGroupModifyMembers_r(struct libnetapi_ctx *ctx, - struct NetLocalGroupAddMembers *add, - struct NetLocalGroupDelMembers *del, - struct NetLocalGroupSetMembers *set) -{ - struct NetLocalGroupAddMembers *r = NULL; - - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - struct rpc_pipe_client *lsa_pipe = NULL; - NTSTATUS status; - WERROR werr; - struct lsa_String lsa_account_name; - struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; - struct dom_sid2 *domain_sid = NULL; - struct dom_sid *member_sids = NULL; - int i = 0, k = 0; - - struct LOCALGROUP_MEMBERS_INFO_0 *info0 = NULL; - struct LOCALGROUP_MEMBERS_INFO_3 *info3 = NULL; - - struct dom_sid *add_sids = NULL; - struct dom_sid *del_sids = NULL; - size_t num_add_sids = 0; - size_t num_del_sids = 0; - - if ((!add && !del && !set) || (add && del && set)) { - return WERR_INVALID_PARAM; - } - - if (add) { - r = add; - } - - if (del) { - r = (struct NetLocalGroupAddMembers *)del; - } - - if (set) { - r = (struct NetLocalGroupAddMembers *)set; - } - - if (!r->in.group_name) { - return WERR_INVALID_PARAM; - } - - switch (r->in.level) { - case 0: - case 3: - break; - default: - return WERR_UNKNOWN_LEVEL; - } - - if (r->in.total_entries == 0 || !r->in.buffer) { - return WERR_INVALID_PARAM; - } - - ZERO_STRUCT(connect_handle); - ZERO_STRUCT(builtin_handle); - ZERO_STRUCT(domain_handle); - ZERO_STRUCT(alias_handle); - - member_sids = TALLOC_ZERO_ARRAY(ctx, struct dom_sid, - r->in.total_entries); - W_ERROR_HAVE_NO_MEMORY(member_sids); - - switch (r->in.level) { - case 0: - info0 = (struct LOCALGROUP_MEMBERS_INFO_0 *)r->in.buffer; - for (i=0; i < r->in.total_entries; i++) { - sid_copy(&member_sids[i], (struct dom_sid *)info0[i].lgrmi0_sid); - } - break; - case 3: - info3 = (struct LOCALGROUP_MEMBERS_INFO_3 *)r->in.buffer; - break; - default: - break; - } - - if (r->in.level == 3) { - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_lsarpc.syntax_id, - &cli, - &lsa_pipe); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - for (i=0; i < r->in.total_entries; i++) { - status = libnetapi_lsa_lookup_names3(ctx, lsa_pipe, - info3[i].lgrmi3_domainandname, - &member_sids[i]); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - } - TALLOC_FREE(lsa_pipe); - } - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, - SAMR_ACCESS_OPEN_DOMAIN | - SAMR_ACCESS_ENUM_DOMAINS, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &builtin_handle); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - init_lsa_String(&lsa_account_name, r->in.group_name); - - status = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, - &builtin_handle, - r->in.group_name, - SAMR_ALIAS_ACCESS_ADD_MEMBER | - SAMR_ALIAS_ACCESS_REMOVE_MEMBER | - SAMR_ALIAS_ACCESS_GET_MEMBERS | - SAMR_ALIAS_ACCESS_LOOKUP_INFO, - &alias_handle); - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); - } - - if (NT_STATUS_IS_OK(status)) { - goto modify_membership; - } - - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - status = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, - &domain_handle, - r->in.group_name, - SAMR_ALIAS_ACCESS_ADD_MEMBER | - SAMR_ALIAS_ACCESS_REMOVE_MEMBER | - SAMR_ALIAS_ACCESS_GET_MEMBERS | - SAMR_ALIAS_ACCESS_LOOKUP_INFO, - &alias_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - } - - modify_membership: - - if (add) { - for (i=0; i < r->in.total_entries; i++) { - status = add_sid_to_array_unique(ctx, &member_sids[i], - &add_sids, - &num_add_sids); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - } - } - - if (del) { - for (i=0; i < r->in.total_entries; i++) { - status = add_sid_to_array_unique(ctx, &member_sids[i], - &del_sids, - &num_del_sids); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - } - } - - if (set) { - - struct lsa_SidArray current_sids; - - status = rpccli_samr_GetMembersInAlias(pipe_cli, ctx, - &alias_handle, - ¤t_sids); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - /* add list */ - - for (i=0; i < r->in.total_entries; i++) { - bool already_member = false; - for (k=0; k < current_sids.num_sids; k++) { - if (sid_equal(&member_sids[i], - current_sids.sids[k].sid)) { - already_member = true; - break; - } - } - if (!already_member) { - status = add_sid_to_array_unique(ctx, - &member_sids[i], - &add_sids, &num_add_sids); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - } - } - - /* del list */ - - for (k=0; k < current_sids.num_sids; k++) { - bool keep_member = false; - for (i=0; i < r->in.total_entries; i++) { - if (sid_equal(&member_sids[i], - current_sids.sids[k].sid)) { - keep_member = true; - break; - } - } - if (!keep_member) { - status = add_sid_to_array_unique(ctx, - current_sids.sids[k].sid, - &del_sids, &num_del_sids); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - } - } - } - - /* add list */ - - for (i=0; i < num_add_sids; i++) { - status = rpccli_samr_AddAliasMember(pipe_cli, ctx, - &alias_handle, - &add_sids[i]); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - } - - /* del list */ - - for (i=0; i < num_del_sids; i++) { - status = rpccli_samr_DeleteAliasMember(pipe_cli, ctx, - &alias_handle, - &del_sids[i]); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - } - - werr = WERR_OK; - - done: - if (!cli) { - return werr; - } - - if (is_valid_policy_hnd(&alias_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &alias_handle); - } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetLocalGroupAddMembers_r(struct libnetapi_ctx *ctx, - struct NetLocalGroupAddMembers *r) -{ - return NetLocalGroupModifyMembers_r(ctx, r, NULL, NULL); -} - -/**************************************************************** -****************************************************************/ - -WERROR NetLocalGroupAddMembers_l(struct libnetapi_ctx *ctx, - struct NetLocalGroupAddMembers *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetLocalGroupAddMembers); -} - -/**************************************************************** -****************************************************************/ - -WERROR NetLocalGroupDelMembers_r(struct libnetapi_ctx *ctx, - struct NetLocalGroupDelMembers *r) -{ - return NetLocalGroupModifyMembers_r(ctx, NULL, r, NULL); -} - -/**************************************************************** -****************************************************************/ - -WERROR NetLocalGroupDelMembers_l(struct libnetapi_ctx *ctx, - struct NetLocalGroupDelMembers *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetLocalGroupDelMembers); -} - -/**************************************************************** -****************************************************************/ - -WERROR NetLocalGroupGetMembers_r(struct libnetapi_ctx *ctx, - struct NetLocalGroupGetMembers *r) -{ - return WERR_NOT_SUPPORTED; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetLocalGroupGetMembers_l(struct libnetapi_ctx *ctx, - struct NetLocalGroupGetMembers *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetLocalGroupGetMembers); -} - -/**************************************************************** -****************************************************************/ - -WERROR NetLocalGroupSetMembers_r(struct libnetapi_ctx *ctx, - struct NetLocalGroupSetMembers *r) -{ - return NetLocalGroupModifyMembers_r(ctx, NULL, NULL, r); -} - -/**************************************************************** -****************************************************************/ - -WERROR NetLocalGroupSetMembers_l(struct libnetapi_ctx *ctx, - struct NetLocalGroupSetMembers *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetLocalGroupSetMembers); -} - diff --git a/source/lib/netapi/netapi.c b/source/lib/netapi/netapi.c index 889388173f..cf1be00849 100644 --- a/source/lib/netapi/netapi.c +++ b/source/lib/netapi/netapi.c @@ -30,30 +30,8 @@ static bool libnetapi_initialized = false; /**************************************************************** ****************************************************************/ -static NET_API_STATUS libnetapi_init_private_context(struct libnetapi_ctx *ctx) -{ - struct libnetapi_private_ctx *priv; - - if (!ctx) { - return W_ERROR_V(WERR_INVALID_PARAM); - } - - priv = TALLOC_ZERO_P(ctx, struct libnetapi_private_ctx); - if (!priv) { - return W_ERROR_V(WERR_NOMEM); - } - - ctx->private_data = priv; - - return NET_API_STATUS_SUCCESS; -} - -/**************************************************************** -****************************************************************/ - NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) { - NET_API_STATUS status; struct libnetapi_ctx *ctx = NULL; char *krb5_cc_env = NULL; @@ -118,12 +96,6 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) return W_ERROR_V(WERR_NOMEM); } - status = libnetapi_init_private_context(ctx); - if (status != 0) { - TALLOC_FREE(frame); - return status; - } - libnetapi_initialized = true; *context = stat_ctx = ctx; @@ -153,8 +125,6 @@ NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx) return NET_API_STATUS_SUCCESS; } - libnetapi_samr_free(ctx); - libnetapi_shutdown_cm(ctx); if (ctx->krb5_cc_env) { @@ -309,33 +279,6 @@ const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ -NET_API_STATUS NetApiBufferAllocate(uint32_t byte_count, - void **buffer) -{ - void *buf = NULL; - - if (!buffer) { - return W_ERROR_V(WERR_INSUFFICIENT_BUFFER); - } - - if (byte_count == 0) { - goto done; - } - - buf = talloc_size(NULL, byte_count); - if (!buf) { - return W_ERROR_V(WERR_NOMEM); - } - - done: - *buffer = buf; - - return NET_API_STATUS_SUCCESS; -} - -/**************************************************************** -****************************************************************/ - NET_API_STATUS NetApiBufferFree(void *buffer) { if (!buffer) { diff --git a/source/lib/netapi/netapi.h b/source/lib/netapi/netapi.h index 9687461920..ce97e4c02e 100644 --- a/source/lib/netapi/netapi.h +++ b/source/lib/netapi/netapi.h @@ -33,8 +33,6 @@ typedef enum { #define ERROR_MORE_DATA ( 234L ) -#define ENCRYPTED_PWLEN ( 16 ) - /**************************************************************** ****************************************************************/ @@ -52,17 +50,6 @@ struct GUID { #ifndef _HEADER_libnetapi -#ifndef MAXSUBAUTHS -#define MAXSUBAUTHS 15 /* max sub authorities in a SID */ -#endif - -struct domsid { - uint8_t sid_rev_num; - uint8_t num_auths; - uint8_t id_auth[6]; - uint32_t sub_auths[MAXSUBAUTHS]; -}; - struct DOMAIN_CONTROLLER_INFO { const char * domain_controller_name; const char * domain_controller_address; @@ -75,66 +62,6 @@ struct DOMAIN_CONTROLLER_INFO { const char * client_site_name; }; -/* bitmap NetJoinFlags */ -#define NETSETUP_JOIN_DOMAIN ( 0x00000001 ) -#define NETSETUP_ACCT_CREATE ( 0x00000002 ) -#define NETSETUP_ACCT_DELETE ( 0x00000004 ) -#define NETSETUP_WIN9X_UPGRADE ( 0x00000010 ) -#define NETSETUP_DOMAIN_JOIN_IF_JOINED ( 0x00000020 ) -#define NETSETUP_JOIN_UNSECURE ( 0x00000040 ) -#define NETSETUP_MACHINE_PWD_PASSED ( 0x00000080 ) -#define NETSETUP_DEFER_SPN_SET ( 0x00000100 ) -#define NETSETUP_JOIN_DC_ACCOUNT ( 0x00000200 ) -#define NETSETUP_JOIN_WITH_NEW_NAME ( 0x00000400 ) -#define NETSETUP_INSTALL_INVOCATION ( 0x00040000 ) -#define NETSETUP_IGNORE_UNSUPPORTED_FLAGS ( 0x10000000 ) - -#define FILTER_TEMP_DUPLICATE_ACCOUNT ( 0x0001 ) -#define FILTER_NORMAL_ACCOUNT ( 0x0002 ) -#define FILTER_INTERDOMAIN_TRUST_ACCOUNT ( 0x0008 ) -#define FILTER_WORKSTATION_TRUST_ACCOUNT ( 0x0010 ) -#define FILTER_SERVER_TRUST_ACCOUNT ( 0x0020 ) - -#define TIMEQ_FOREVER ( (uint32_t)-1L ) - -enum NETSETUP_JOIN_STATUS { - NetSetupUnknownStatus=0, - NetSetupUnjoined=1, - NetSetupWorkgroupName=2, - NetSetupDomainName=3 -}; - -struct SERVER_INFO_100 { - uint32_t sv100_platform_id; - const char * sv100_name; -}; - -struct SERVER_INFO_101 { - uint32_t sv101_platform_id; - const char * sv101_name; - uint32_t sv101_version_major; - uint32_t sv101_version_minor; - uint32_t sv101_type; - const char * sv101_comment; -}; - -struct SERVER_INFO_102 { - uint32_t sv102_platform_id; - const char * sv102_name; - uint32_t sv102_version_major; - uint32_t sv102_version_minor; - uint32_t sv102_type; - const char * sv102_comment; - uint32_t sv102_users; - uint32_t sv102_disc; - uint8_t sv102_hidden; - uint32_t sv102_announce; - uint32_t sv102_anndelta; - uint32_t sv102_licenses; - const char * sv102_userpath; -}; - - struct SERVER_INFO_1005 { const char * sv1005_comment; }; @@ -143,10 +70,6 @@ struct USER_INFO_0 { const char * usri0_name; }; -#define USER_PRIV_GUEST ( 0 ) -#define USER_PRIV_USER ( 1 ) -#define USER_PRIV_ADMIN ( 2 ) - struct USER_INFO_1 { const char * usri1_name; const char * usri1_password; @@ -158,311 +81,6 @@ struct USER_INFO_1 { const char * usri1_script_path; }; -#define AF_OP_PRINT ( 0x1 ) -#define AF_OP_COMM ( 0x2 ) -#define AF_OP_SERVER ( 0x4 ) -#define AF_OP_ACCOUNTS ( 0x8 ) - -struct USER_INFO_2 { - const char * usri2_name; - const char * usri2_password; - uint32_t usri2_password_age; - uint32_t usri2_priv; - const char * usri2_home_dir; - const char * usri2_comment; - uint32_t usri2_flags; - const char * usri2_script_path; - uint32_t usri2_auth_flags; - const char * usri2_full_name; - const char * usri2_usr_comment; - const char * usri2_parms; - const char * usri2_workstations; - uint32_t usri2_last_logon; - uint32_t usri2_last_logoff; - uint32_t usri2_acct_expires; - uint32_t usri2_max_storage; - uint32_t usri2_units_per_week; - uint8_t *usri2_logon_hours;/* [unique] */ - uint32_t usri2_bad_pw_count; - uint32_t usri2_num_logons; - const char * usri2_logon_server; - uint32_t usri2_country_code; - uint32_t usri2_code_page; -}; - -struct USER_INFO_3 { - const char * usri3_name; - uint32_t usri3_password_age; - uint32_t usri3_priv; - const char * usri3_home_dir; - const char * usri3_comment; - uint32_t usri3_flags; - const char * usri3_script_path; - uint32_t usri3_auth_flags; - const char * usri3_full_name; - const char * usri3_usr_comment; - const char * usri3_parms; - const char * usri3_workstations; - uint32_t usri3_last_logon; - uint32_t usri3_last_logoff; - uint32_t usri3_acct_expires; - uint32_t usri3_max_storage; - uint32_t usri3_units_per_week; - uint8_t *usri3_logon_hours;/* [unique] */ - uint32_t usri3_bad_pw_count; - uint32_t usri3_num_logons; - const char * usri3_logon_server; - uint32_t usri3_country_code; - uint32_t usri3_code_page; - uint32_t usri3_user_id; - uint32_t usri3_primary_group_id; - const char * usri3_profile; - const char * usri3_home_dir_drive; - uint32_t usri3_password_expired; -}; - -struct USER_INFO_4 { - const char * usri4_name; - const char * usri4_password; - uint32_t usri4_password_age; - uint32_t usri4_priv; - const char * usri4_home_dir; - const char * usri4_comment; - uint32_t usri4_flags; - const char * usri4_script_path; - uint32_t usri4_auth_flags; - const char * usri4_full_name; - const char * usri4_usr_comment; - const char * usri4_parms; - const char * usri4_workstations; - uint32_t usri4_last_logon; - uint32_t usri4_last_logoff; - uint32_t usri4_acct_expires; - uint32_t usri4_max_storage; - uint32_t usri4_units_per_week; - uint8_t *usri4_logon_hours;/* [unique] */ - uint32_t usri4_bad_pw_count; - uint32_t usri4_num_logons; - const char * usri4_logon_server; - uint32_t usri4_country_code; - uint32_t usri4_code_page; - struct domsid *usri4_user_sid;/* [unique] */ - uint32_t usri4_primary_group_id; - const char * usri4_profile; - const char * usri4_home_dir_drive; - uint32_t usri4_password_expired; -}; - -struct USER_INFO_10 { - const char * usri10_name; - const char * usri10_comment; - const char * usri10_usr_comment; - const char * usri10_full_name; -}; - -struct USER_INFO_11 { - const char * usri11_name; - const char * usri11_comment; - const char * usri11_usr_comment; - const char * usri11_full_name; - uint32_t usri11_priv; - uint32_t usri11_auth_flags; - uint32_t usri11_password_age; - const char * usri11_home_dir; - const char * usri11_parms; - uint32_t usri11_last_logon; - uint32_t usri11_last_logoff; - uint32_t usri11_bad_pw_count; - uint32_t usri11_num_logons; - const char * usri11_logon_server; - uint32_t usri11_country_code; - const char * usri11_workstations; - uint32_t usri11_max_storage; - uint32_t usri11_units_per_week; - uint8_t *usri11_logon_hours;/* [unique] */ - uint32_t usri11_code_page; -}; - -struct USER_INFO_20 { - const char * usri20_name; - const char * usri20_full_name; - const char * usri20_comment; - uint32_t usri20_flags; - uint32_t usri20_user_id; -}; - -struct USER_INFO_21 { - uint8_t *usri21_password; -}; - -struct USER_INFO_22 { - const char * usri22_name; - uint8_t *usri22_password; - uint32_t usri22_password_age; - uint32_t usri22_priv; - const char * usri22_home_dir; - const char * usri22_comment; - uint32_t usri22_flags; - uint32_t usri22_script_path; - uint32_t usri22_auth_flags; - const char * usri22_full_name; - const char * usri22_usr_comment; - const char * usri22_parms; - const char * usri22_workstations; - uint32_t usri22_last_logon; - uint32_t usri22_last_logoff; - uint32_t usri22_acct_expires; - uint32_t usri22_max_storage; - uint32_t usri22_units_per_week; - uint8_t *usri22_logon_hours;/* [unique] */ - uint32_t usri22_bad_pw_count; - uint32_t usri22_num_logons; - const char * usri22_logon_server; - uint32_t usri22_country_code; - uint32_t usri22_code_page; -}; - -struct USER_INFO_23 { - const char * usri23_name; - const char * usri23_full_name; - const char * usri23_comment; - uint32_t usri23_flags; - struct domsid *usri23_user_sid;/* [unique] */ -}; - -struct USER_INFO_1003 { - const char * usri1003_password; -}; - -struct USER_INFO_1005 { - uint32_t usri1005_priv; -}; - -struct USER_INFO_1006 { - const char * usri1006_home_dir; -}; - -struct USER_INFO_1007 { - const char * usri1007_comment; -}; - -struct USER_INFO_1008 { - uint32_t usri1008_flags; -}; - -struct USER_INFO_1009 { - const char * usri1009_script_path; -}; - -struct USER_INFO_1010 { - uint32_t usri1010_auth_flags; -}; - -struct USER_INFO_1011 { - const char * usri1011_full_name; -}; - -struct USER_INFO_1012 { - const char * usri1012_usr_comment; -}; - -struct USER_INFO_1013 { - const char * usri1013_parms; -}; - -struct USER_INFO_1014 { - const char * usri1014_workstations; -}; - -struct USER_INFO_1017 { - uint32_t usri1017_acct_expires; -}; - -struct USER_INFO_1018 { - uint32_t usri1018_max_storage; -}; - -struct USER_INFO_1020 { - uint32_t usri1020_units_per_week; - uint8_t *usri1020_logon_hours;/* [unique] */ -}; - -struct USER_INFO_1023 { - const char * usri1023_logon_server; -}; - -struct USER_INFO_1024 { - uint32_t usri1024_country_code; -}; - -struct USER_INFO_1025 { - uint32_t usri1025_code_page; -}; - -struct USER_INFO_1051 { - uint32_t usri1051_primary_group_id; -}; - -struct USER_INFO_1052 { - const char * usri1052_profile; -}; - -struct USER_INFO_1053 { - const char * usri1053_home_dir_drive; -}; - -struct USER_MODALS_INFO_0 { - uint32_t usrmod0_min_passwd_len; - uint32_t usrmod0_max_passwd_age; - uint32_t usrmod0_min_passwd_age; - uint32_t usrmod0_force_logoff; - uint32_t usrmod0_password_hist_len; -}; - -struct USER_MODALS_INFO_1 { - uint32_t usrmod1_role; - const char * usrmod1_primary; -}; - -struct USER_MODALS_INFO_2 { - const char * usrmod2_domain_name; - struct domsid *usrmod2_domain_id;/* [unique] */ -}; - -struct USER_MODALS_INFO_3 { - uint32_t usrmod3_lockout_duration; - uint32_t usrmod3_lockout_observation_window; - uint32_t usrmod3_lockout_threshold; -}; - -struct USER_MODALS_INFO_1001 { - uint32_t usrmod1001_min_passwd_len; -}; - -struct USER_MODALS_INFO_1002 { - uint32_t usrmod1002_max_passwd_age; -}; - -struct USER_MODALS_INFO_1003 { - uint32_t usrmod1003_min_passwd_age; -}; - -struct USER_MODALS_INFO_1004 { - uint32_t usrmod1004_force_logoff; -}; - -struct USER_MODALS_INFO_1005 { - uint32_t usrmod1005_password_hist_len; -}; - -struct USER_MODALS_INFO_1006 { - uint32_t usrmod1006_role; -}; - -struct USER_MODALS_INFO_1007 { - const char * usrmod1007_primary; -}; - struct NET_DISPLAY_USER { const char * usri1_name; const char * usri1_comment; @@ -488,163 +106,6 @@ struct NET_DISPLAY_GROUP { uint32_t grpi3_next_index; }; -struct GROUP_INFO_0 { - const char * grpi0_name; -}; - -struct GROUP_INFO_1 { - const char * grpi1_name; - const char * grpi1_comment; -}; - -struct GROUP_INFO_2 { - const char * grpi2_name; - const char * grpi2_comment; - uint32_t grpi2_group_id; - uint32_t grpi2_attributes; -}; - -struct GROUP_INFO_3 { - const char * grpi3_name; - const char * grpi3_comment; - struct domsid * grpi3_group_sid; - uint32_t grpi3_attributes; -}; - -struct GROUP_INFO_1002 { - const char * grpi1002_comment; -}; - -struct GROUP_INFO_1005 { - uint32_t grpi1005_attributes; -}; - -struct GROUP_USERS_INFO_0 { - const char * grui0_name; -}; - -struct GROUP_USERS_INFO_1 { - const char * grui1_name; - uint32_t grui1_attributes; -}; - -struct LOCALGROUP_INFO_0 { - const char * lgrpi0_name; -}; - -struct LOCALGROUP_INFO_1 { - const char * lgrpi1_name; - const char * lgrpi1_comment; -}; - -struct LOCALGROUP_INFO_1002 { - const char * lgrpi1002_comment; -}; - -enum SID_NAME_USE { - SidTypeUser=1, - SidTypeGroup=2, - SidTypeDomain=3, - SidTypeAlias=4, - SidTypeWellKnownGroup=5, - SidTypeDeletedAccount=6, - SidTypeInvalid=7, - SidTypeUnknown=8, - SidTypeComputer=9, - SidTypeLabel=10 -}; - -struct LOCALGROUP_MEMBERS_INFO_0 { - struct domsid *lgrmi0_sid;/* [unique] */ -}; - -struct LOCALGROUP_MEMBERS_INFO_1 { - struct domsid *lgrmi1_sid;/* [unique] */ - enum SID_NAME_USE lgrmi1_sidusage; - const char * lgrmi1_name; -}; - -struct LOCALGROUP_MEMBERS_INFO_2 { - struct domsid *lgrmi2_sid;/* [unique] */ - enum SID_NAME_USE lgrmi2_sidusage; - const char * lgrmi2_domainandname; -}; - -struct LOCALGROUP_MEMBERS_INFO_3 { - const char * lgrmi3_domainandname; -}; - -struct LOCALGROUP_USERS_INFO_0 { - const char * lgrui0_name; -}; - -struct TIME_OF_DAY_INFO { - uint32_t tod_elapsedt; - uint32_t tod_msecs; - uint32_t tod_hours; - uint32_t tod_mins; - uint32_t tod_secs; - uint32_t tod_hunds; - int32_t tod_timezone; - uint32_t tod_tinterval; - uint32_t tod_day; - uint32_t tod_month; - uint32_t tod_year; - uint32_t tod_weekday; -}; - -struct SHARE_INFO_0 { - const char * shi0_netname; -}; - -struct SHARE_INFO_1 { - const char * shi1_netname; - uint32_t shi1_type; - const char * shi1_remark; -}; - -struct SHARE_INFO_2 { - const char * shi2_netname; - uint32_t shi2_type; - const char * shi2_remark; - uint32_t shi2_permissions; - uint32_t shi2_max_uses; - uint32_t shi2_current_uses; - const char * shi2_path; - const char * shi2_passwd; -}; - -struct SHARE_INFO_501 { - const char * shi501_netname; - uint32_t shi501_type; - const char * shi501_remark; - uint32_t shi501_flags; -}; - -struct SHARE_INFO_1004 { - const char * shi1004_remark; -}; - -struct SHARE_INFO_1005 { - uint32_t shi1005_flags; -}; - -struct SHARE_INFO_1006 { - uint32_t shi1006_max_uses; -}; - -struct FILE_INFO_2 { - uint32_t fi2_id; -}; - -struct FILE_INFO_3 { - uint32_t fi3_id; - uint32_t fi3_permissions; - uint32_t fi3_num_locks; - const char * fi3_pathname; - const char * fi3_username; -}; - #endif /* _HEADER_libnetapi */ /**************************************************************** @@ -658,9 +119,6 @@ struct libnetapi_ctx { char *password; char *krb5_cc_env; int use_kerberos; - int disable_policy_handle_cache; - - void *private_data; }; /**************************************************************** @@ -718,12 +176,6 @@ const char *libnetapi_errstr(NET_API_STATUS status); const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx, NET_API_STATUS status); -/**************************************************************** - NetApiBufferAllocate -****************************************************************/ - -NET_API_STATUS NetApiBufferAllocate(uint32_t byte_count, - void **buffer); /**************************************************************** NetApiBufferFree @@ -733,36 +185,6 @@ NET_API_STATUS NetApiBufferFree(void *buffer); /************************************************************//** * - * ConvertSidToStringSid - * - * @brief Convert a domain sid into a string - * - * @param[in] sid A pointer to a sid structure - * @param[in,out] sid_string A pointer that holds a pointer to a sid string. Caller - * needs to free with free(3) - * @return bool - ***************************************************************/ - -int ConvertSidToStringSid(const struct domsid *sid, - char **sid_string); - -/************************************************************//** - * - * ConvertStringSidToSid - * - * @brief Convert a string into a domain sid - * - * @param[in] sid_string A pointer to a sid string. - * @param[in,out] sid A pointer that holds a pointer to a sid structure. - * Caller needs to free with free(3) - * @return bool - ***************************************************************/ - -int ConvertStringSidToSid(const char *sid_string, - struct domsid **sid); - -/************************************************************//** - * * NetJoinDomain * * @brief Join a computer to a domain or workgroup @@ -852,29 +274,6 @@ NET_API_STATUS NetGetJoinableOUs(const char * server_name /* [in] */, /************************************************************//** * - * NetRenameMachineInDomain - * - * @brief Rename a machine in a domain - * - * @param[in] server_name The server name to connect to - * @param[in] new_machine_name The new machine name - * @param[in] account The domain account used for the query - * @param[in] password The domain account's password used for the query - * @param[in] rename_options Options used for the rename operation - * @return NET_API_STATUS - * - * example join/rename_machine.c - * - ***************************************************************/ - -NET_API_STATUS NetRenameMachineInDomain(const char * server_name /* [in] */, - const char * new_machine_name /* [in] */, - const char * account /* [in] */, - const char * password /* [in] */, - uint32_t rename_options /* [in] */); - -/************************************************************//** - * * NetServerGetInfo * * @brief Get Information on a server @@ -1040,183 +439,6 @@ NET_API_STATUS NetUserEnum(const char * server_name /* [in] */, /************************************************************//** * - * NetUserChangePassword - * - * @brief Change the password for a user on a given server or in a given domain - * - * @param[in] domain_name The server or domain name to connect to - * @param[in] user_name The user account to change the password for - * @param[in] old_password The user account's old password - * @param[in] new_password The user account's new password - * @return NET_API_STATUS - * - * example user/user_chgpwd.c - ***************************************************************/ - -NET_API_STATUS NetUserChangePassword(const char * domain_name /* [in] */, - const char * user_name /* [in] */, - const char * old_password /* [in] */, - const char * new_password /* [in] */); - -/************************************************************//** - * - * NetUserGetInfo - * - * @brief Get User Information - * - * @param[in] server_name The server name to connect to - * @param[in] user_name The name of the user that is going to be queried - * @param[in] level The level defining the requested USER_INFO_X structure - * @param[out] buffer The buffer containing a USER_INFO_X structure - * @return NET_API_STATUS - * - * example user/user_getinfo.c - ***************************************************************/ - -NET_API_STATUS NetUserGetInfo(const char * server_name /* [in] */, - const char * user_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */); - -/************************************************************//** - * - * NetUserSetInfo - * - * @brief Set User Information - * - * @param[in] server_name The server name to connect to - * @param[in] user_name The name of the user that is going to be modified - * @param[in] level The level defining the requested USER_INFO_X structure - * @param[in] buffer The buffer containing a USER_INFO_X structure - * @param[out] parm_err The returned parameter error number if any - * @return NET_API_STATUS - * - * example user/user_setinfo.c - ***************************************************************/ - -NET_API_STATUS NetUserSetInfo(const char * server_name /* [in] */, - const char * user_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */); - -/************************************************************//** - * - * NetUserModalsGet - * - * @brief Get SAM domain and password information - * - * @param[in] server_name The server name to connect to - * @param[in] level The level defining which USER_MODALS_INFO_X buffer to query - * @param[out] buffer The returned USER_MODALS_INFO_X buffer - * @return NET_API_STATUS - * - * example user/user_modalsget.c - ***************************************************************/ - -NET_API_STATUS NetUserModalsGet(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */); - -/************************************************************//** - * - * NetUserModalsSet - * - * @brief Set SAM domain and password information - * - * @param[in] server_name The server name to connect to - * @param[in] level The level defining which USER_MODALS_INFO_X buffer to query - * @param[out] buffer The buffer conntaing a USER_MODALS_INFO_X structure - * @param[out] parm_err The returned parameter error number if any - * @return NET_API_STATUS - * - * example user/user_modalsset.c - ***************************************************************/ - -NET_API_STATUS NetUserModalsSet(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */); - -/************************************************************//** - * - * NetUserGetGroups - * - * @brief Enumerate grouplist of a user on a server - * - * @param[in] server_name The server name to connect to - * @param[in] user_name The user name to query - * @param[in] level The enumeration level used for the query (Currently only - * level 0 is supported) - * @param[out] buffer The returned enumeration buffer - * @param[in] prefmaxlen The requested maximal buffer size - * @param[out] entries_read The number of returned entries - * @param[out] total_entries The number of total entries - * @return NET_API_STATUS - * - * example user/user_getgroups.c - ***************************************************************/ - -NET_API_STATUS NetUserGetGroups(const char * server_name /* [in] */, - const char * user_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */); - -/************************************************************//** - * - * NetUserSetGroups - * - * @brief Set grouplist of a user on a server - * - * @param[in] server_name The server name to connect to - * @param[in] user_name The user name to query - * @param[in] level The level defining the GROUP_USERS_INFO_X structures in the buffer - * @param[in] buffer The buffer containing GROUP_USERS_INFO_X structures - * @param[in] num_entries The number of X structures in the buffer - * @return NET_API_STATUS - * - * example user/user_setgroups.c - ***************************************************************/ - -NET_API_STATUS NetUserSetGroups(const char * server_name /* [in] */, - const char * user_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t num_entries /* [in] */); - -/************************************************************//** - * - * NetUserGetLocalGroups - * - * @brief Enumerate local grouplist of a user on a server - * - * @param[in] server_name The server name to connect to - * @param[in] user_name The user name to query - * @param[in] level The enumeration level used for the query - * @param[in] flags The flags used for the query - * @param[out] buffer The returned enumeration buffer - * @param[in] prefmaxlen The requested maximal buffer size - * @param[out] entries_read The number of returned entries - * @param[out] total_entries The number of total entries - * @return NET_API_STATUS - * - * example user/user_getlocalgroups.c - ***************************************************************/ - -NET_API_STATUS NetUserGetLocalGroups(const char * server_name /* [in] */, - const char * user_name /* [in] */, - uint32_t level /* [in] */, - uint32_t flags /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */); - -/************************************************************//** - * * NetQueryDisplayInformation * * @brief Enumerate accounts on a server @@ -1241,598 +463,6 @@ NET_API_STATUS NetQueryDisplayInformation(const char * server_name /* [in] [uniq uint32_t *entries_read /* [out] [ref] */, void **buffer /* [out] [noprint,ref] */); -/************************************************************//** - * - * NetGroupAdd - * - * @brief Create Domain Group - * - * @param[in] server_name The server name to connect to - * @param[in] level The level used for the new group creation - * @param[in] buf The buffer containing the group structure - * @param[out] parm_err The returned parameter error number if any - * @return NET_API_STATUS - * - * example group/group_add.c - ***************************************************************/ - -NET_API_STATUS NetGroupAdd(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buf /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */); - -/************************************************************//** - * - * NetGroupDel - * - * @brief Delete Domain Group - * - * @param[in] server_name The server name to connect to - * @param[in] group_name The name of the group that is going to be deleted - * @return NET_API_STATUS - * - * example group/group_del.c - ***************************************************************/ - -NET_API_STATUS NetGroupDel(const char * server_name /* [in] */, - const char * group_name /* [in] */); - -/************************************************************//** - * - * NetGroupEnum - * - * @brief Enumerate groups on a server - * - * @param[in] server_name The server name to connect to - * @param[in] level The enumeration level used for the query (Currently only - * level 0 is supported) - * @param[out] buffer The returned enumeration buffer - * @param[in] prefmaxlen The requested maximal buffer size - * @param[out] entries_read The number of returned entries - * @param[out] total_entries The number of total entries - * @param[in,out] resume_handle A handle passed in and returned for resuming - * operations - * @return NET_API_STATUS - * - * example group/group_enum.c - ***************************************************************/ - -NET_API_STATUS NetGroupEnum(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */, - uint32_t *resume_handle /* [in,out] [ref] */); - -/************************************************************//** - * - * NetGroupSetInfo - * - * @brief Set Domain Group Information - * - * @param[in] server_name The server name to connect to - * @param[in] group_name The name of the group that is going to be modified - * @param[in] level The level defining the structure type in buf - * @param[in] buf The buffer containing a GROUP_INFO_X structure - * @param[out] parm_err The returned parameter error number if any - * @return NET_API_STATUS - * - * example group/group_setinfo.c - ***************************************************************/ - -NET_API_STATUS NetGroupSetInfo(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buf /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */); - -/************************************************************//** - * - * NetGroupGetInfo - * - * @brief Get Domain Group Information - * - * @param[in] server_name The server name to connect to - * @param[in] group_name The name of the group that is going to be queried - * @param[in] level The level defining the requested GROUP_INFO_X structure - * @param[out] buf The buffer containing a GROUP_INFO_X structure - * @return NET_API_STATUS - * - * example group/group_getinfo.c - ***************************************************************/ - -NET_API_STATUS NetGroupGetInfo(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buf /* [out] [ref] */); - -/************************************************************//** - * - * NetGroupAddUser - * - * @brief Add existing User to existing Domain Group - * - * @param[in] server_name The server name to connect to - * @param[in] group_name The name of the group that is going to be modified - * @param[in] user_name The name of the user that is going to be added to the - * group - * @return NET_API_STATUS - * - * example group/group_adduser.c - ***************************************************************/ - -NET_API_STATUS NetGroupAddUser(const char * server_name /* [in] */, - const char * group_name /* [in] */, - const char * user_name /* [in] */); - -/************************************************************//** - * - * NetGroupDelUser - * - * @brief Remove User from Domain Group - * - * @param[in] server_name The server name to connect to - * @param[in] group_name The name of the group that is going to be modified - * @param[in] user_name The name of the user that is going to be removed from - * the group - * @return NET_API_STATUS - * - * example group/group_deluser.c - ***************************************************************/ - -NET_API_STATUS NetGroupDelUser(const char * server_name /* [in] */, - const char * group_name /* [in] */, - const char * user_name /* [in] */); - -/************************************************************//** - * - * NetGroupGetUsers - * - * @brief Get Users for a group on a server - * - * @param[in] server_name The server name to connect to - * @param[in] group_name The group name to enumerate users for - * @param[in] level The enumeration level used for the query - * @param[out] buffer The returned enumeration buffer - * @param[in] prefmaxlen The requested maximal buffer size - * @param[out] entries_read The number of returned entries - * @param[out] total_entries The number of total entries - * @param[in,out] resume_handle A handle passed in and returned for resuming - * operations - * @return NET_API_STATUS - * - * example group/group_getusers.c - ***************************************************************/ - -NET_API_STATUS NetGroupGetUsers(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */, - uint32_t *resume_handle /* [in,out] [ref] */); - -/************************************************************//** - * - * NetGroupSetUsers - * - * @brief Set Users for a group on a server - * - * @param[in] server_name The server name to connect to - * @param[in] group_name The group name to enumerate users for - * @param[in] level The enumeration level used for the query - * @param[in] buffer The buffer containing a X structure - * @param[in] num_entries The number of X entries in the buffer - * @return NET_API_STATUS - * - * example group/group_setusers.c - ***************************************************************/ - -NET_API_STATUS NetGroupSetUsers(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t num_entries /* [in] */); - -/************************************************************//** - * - * NetLocalGroupAdd - * - * @brief Create Local Group - * - * @param[in] server_name The server name to connect to - * @param[in] level The level used for the new group creation - * @param[in] buf The buffer containing the group structure - * @param[out] parm_err The returned parameter error number if any - * @return NET_API_STATUS - * - * example localgroup/localgroup_add.c - ***************************************************************/ - -NET_API_STATUS NetLocalGroupAdd(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buf /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */); - -/************************************************************//** - * - * NetLocalGroupDel - * - * @brief Delete Local Group - * - * @param[in] server_name The server name to connect to - * @param[in] group_name The name of the group that is going to be deleted - * @return NET_API_STATUS - * - * example localgroup/localgroup_del.c - ***************************************************************/ - - -NET_API_STATUS NetLocalGroupDel(const char * server_name /* [in] */, - const char * group_name /* [in] */); - -/************************************************************//** - * - * NetLocalGroupGetInfo - * - * @brief Get Local Group Information - * - * @param[in] server_name The server name to connect to - * @param[in] group_name The name of the group that is going to be queried - * @param[in] level The level defining the requested LOCALGROUP_INFO_X structure - * @param[out] buf The buffer containing a LOCALGROUP_INFO_X structure - * @return NET_API_STATUS - * - * example localgroup/localgroup_getinfo.c - ***************************************************************/ - -NET_API_STATUS NetLocalGroupGetInfo(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buf /* [out] [ref] */); - -/************************************************************//** - * - * NetLocalGroupSetInfo - * - * @brief Set Local Group Information - * - * @param[in] server_name The server name to connect to - * @param[in] group_name The name of the group that is going to be modified - * @param[in] level The level defining the requested LOCALGROUP_INFO_X structure - * @param[in] buf The buffer containing a LOCALGROUP_INFO_X structure - * @param[out] parm_err The returned parameter error number if any - * @return NET_API_STATUS - * - * example localgroup/localgroup_setinfo.c - ***************************************************************/ - - -NET_API_STATUS NetLocalGroupSetInfo(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buf /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */); - -/************************************************************//** - * - * NetLocalGroupEnum - * - * @brief Enumerate local groups on a server - * - * @param[in] server_name The server name to connect to - * @param[in] level The enumeration level used for the query (Currently only - * level 0 is supported) - * @param[out] buffer The returned enumeration buffer - * @param[in] prefmaxlen The requested maximal buffer size - * @param[out] entries_read The number of returned entries - * @param[out] total_entries The number of total entries - * @param[in,out] resume_handle A handle passed in and returned for resuming - * operations - * @return NET_API_STATUS - * - * example localgroup/localgroup_enum.c - ***************************************************************/ - -NET_API_STATUS NetLocalGroupEnum(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */, - uint32_t *resume_handle /* [in,out] [ref] */); - -/************************************************************//** - * - * NetLocalGroupAddMembers - * - * @brief Add Members to a Local Group - * - * @param[in] server_name The server name to connect to - * @param[in] group_name The name of the group that is going to modified - * @param[in] level The level defining the LOCALGROUP_MEMBERS_INFO_X structure - * @param[in] buffer The buffer containing a LOCALGROUP_MEMBERS_INFO_X structure - * @param[in] total_entries The number of LOCALGROUP_MEMBERS_INFO_X entries in - * the buffer - * @return NET_API_STATUS - * - * example localgroup/localgroup_addmembers.c - ***************************************************************/ - -NET_API_STATUS NetLocalGroupAddMembers(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t total_entries /* [in] */); - -/************************************************************//** - * - * NetLocalGroupDelMembers - * - * @brief Delete Members from a Local Group - * - * @param[in] server_name The server name to connect to - * @param[in] group_name The name of the group that is going to modified - * @param[in] level The level defining the LOCALGROUP_MEMBERS_INFO_X structure - * @param[in] buffer The buffer containing a LOCALGROUP_MEMBERS_INFO_X structure - * @param[in] total_entries The number of LOCALGROUP_MEMBERS_INFO_X entries in - * the buffer - * @return NET_API_STATUS - * - * example localgroup/localgroup_delmembers.c - ***************************************************************/ - -NET_API_STATUS NetLocalGroupDelMembers(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t total_entries /* [in] */); - -/************************************************************//** - * - * NetLocalGroupGetMembers - * - * @brief Enumerate Members in a local group - * - * @param[in] server_name The server name to connect to - * @param[in] local_group_name The localgroup that is going to be queried - * @param[in] level The level defining the LOCALGROUP_MEMBERS_INFO_X structure - * @param[out] buffer The buffer containing a LOCALGROUP_MEMBERS_INFO_X - * structure - * @param[in] prefmaxlen The requested maximal buffer size - * @param[out] entries_read The number of LOCALGROUP_MEMBERS_INFO_X entries in the buffer - * @param[out] total_entries The total number of LOCALGROUP_MEMBERS_INFO_X entries for that group - * @param[in,out] resume_handle A handle passed in and returned for resuming - * operations - * @return NET_API_STATUS - * - * example localgroup/localgroup_getmembers.c - ***************************************************************/ - -NET_API_STATUS NetLocalGroupGetMembers(const char * server_name /* [in] */, - const char * local_group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */, - uint32_t *resume_handle /* [in,out] [ref] */); - -/************************************************************//** - * - * NetLocalGroupSetMembers - * - * @brief Set Members in a Local Group - * - * @param[in] server_name The server name to connect to - * @param[in] group_name The name of the group that is going to modified - * @param[in] level The level defining the LOCALGROUP_MEMBERS_INFO_X structure - * @param[in] buffer The buffer containing a LOCALGROUP_MEMBERS_INFO_X structure - * @param[in] total_entries The number of LOCALGROUP_MEMBERS_INFO_X entries in - * the buffer - * @return NET_API_STATUS - * - * example localgroup/localgroup_setmembers.c - ***************************************************************/ - -NET_API_STATUS NetLocalGroupSetMembers(const char * server_name /* [in] */, - const char * group_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t total_entries /* [in] */); - -/************************************************************//** - * - * NetRemoteTOD - * - * @brief Query remote Time of Day - * - * @param[in] server_name The server name to connect to - * @param[out] buf The buffer containing a TIME_OF_DAY_INFO structure - * @return NET_API_STATUS - * - * example server/remote_tod.c - ***************************************************************/ - -NET_API_STATUS NetRemoteTOD(const char * server_name /* [in] */, - uint8_t **buf /* [out] [ref] */); - -/************************************************************//** - * - * NetShareAdd - * - * @brief Add Share - * - * @param[in] server_name The server name to connect to - * @param[in] level The level defining the requested SHARE_INFO_X structure - * @param[in] buffer The buffer containing a SHARE_INFO_X structure - * @param[out] parm_err The returned parameter error number if any - * @return NET_API_STATUS - * - * example share/share_add.c - ***************************************************************/ - -NET_API_STATUS NetShareAdd(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */); - -/************************************************************//** - * - * NetShareDel - * - * @brief Delete Share - * - * @param[in] server_name The server name to connect to - * @param[in] net_name The name of the share to delete - * @param[in] reserved - * @return NET_API_STATUS - * - * example share/share_del.c - ***************************************************************/ - -NET_API_STATUS NetShareDel(const char * server_name /* [in] */, - const char * net_name /* [in] */, - uint32_t reserved /* [in] */); - -/************************************************************//** - * - * NetShareEnum - * - * @brief Enumerate Shares - * - * @param[in] server_name The server name to connect to - * @param[in] level The level defining the SHARE_INFO_X structure - * @param[out] buffer The buffer containing a SHARE_INFO_X structure - * @param[in] prefmaxlen The requested maximal buffer size - * @param[out] entries_read The number of SHARE_INFO_X entries in the buffer - * @param[out] total_entries The total number of SHARE_INFO_X entries - * @param[in,out] resume_handle A handle passed in and returned for resuming - * operations - * @return NET_API_STATUS - * - * example share/share_enum.c - ***************************************************************/ - -NET_API_STATUS NetShareEnum(const char * server_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */, - uint32_t *resume_handle /* [in,out] [ref] */); - -/************************************************************//** - * - * NetShareGetInfo - * - * @brief Get Share Info - * - * @param[in] server_name The server name to connect to - * @param[in] net_name The name of the share to query - * @param[in] level The level defining the SHARE_INFO_X structure - * @param[out] buffer The buffer containing a SHARE_INFO_X structure - * @return NET_API_STATUS - * - * example share/share_getinfo.c - ***************************************************************/ - -NET_API_STATUS NetShareGetInfo(const char * server_name /* [in] */, - const char * net_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */); - -/************************************************************//** - * - * NetShareSetInfo - * - * @brief Set Share Info - * - * @param[in] server_name The server name to connect to - * @param[in] net_name The name of the share to query - * @param[in] level The level defining the SHARE_INFO_X structure - * @param[in] buffer The buffer containing a SHARE_INFO_X structure - * @param[out] parm_err The returned parameter error number if any - * @return NET_API_STATUS - * - * example share/share_setinfo.c - ***************************************************************/ - -NET_API_STATUS NetShareSetInfo(const char * server_name /* [in] */, - const char * net_name /* [in] */, - uint32_t level /* [in] */, - uint8_t *buffer /* [in] [ref] */, - uint32_t *parm_err /* [out] [ref] */); - -/************************************************************//** - * - * NetFileClose - * - * @brief Close a file - * - * @param[in] server_name The server name to connect to - * @param[in] fileid The fileid of the file that is going to be closed - * @return NET_API_STATUS - * - * example file/file_close.c - ***************************************************************/ - -NET_API_STATUS NetFileClose(const char * server_name /* [in] */, - uint32_t fileid /* [in] */); - -/************************************************************//** - * - * NetFileGetInfo - * - * @brief Close a file - * - * @param[in] server_name The server name to connect to - * @param[in] fileid The fileid of the file that is going to be closed - * @param[in] level The level of the FILE_INFO_X buffer - * @param[out] buffer The buffer containing a FILE_INFO_X structure - * @return NET_API_STATUS - * - * example file/file_getinfo.c - ***************************************************************/ - -NET_API_STATUS NetFileGetInfo(const char * server_name /* [in] */, - uint32_t fileid /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */); - -/************************************************************//** - * - * NetFileEnum - * - * @brief Enumerate Files - * - * @param[in] server_name The server name to connect to - * @param[in] base_path The - * @param[in] user_name The - * @param[in] level The level defining the FILE_INFO_X structure - * @param[out] buffer The buffer containing a FILE_INFO_X structure - * @param[in] prefmaxlen The requested maximal buffer size - * @param[out] entries_read The number of FILE_INFO_X entries in the buffer - * @param[out] total_entries The total number of FILE_INFO_X entries - * @param[in,out] resume_handle A handle passed in and returned for resuming - * operations - * @return NET_API_STATUS - * - * example file/file_enum.c - ***************************************************************/ - -NET_API_STATUS NetFileEnum(const char * server_name /* [in] */, - const char * base_path /* [in] */, - const char * user_name /* [in] */, - uint32_t level /* [in] */, - uint8_t **buffer /* [out] [ref] */, - uint32_t prefmaxlen /* [in] */, - uint32_t *entries_read /* [out] [ref] */, - uint32_t *total_entries /* [out] [ref] */, - uint32_t *resume_handle /* [in,out] [ref] */); - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/source/lib/netapi/netapi_private.h b/source/lib/netapi/netapi_private.h index e6a2eb8e99..a575f42f4e 100644 --- a/source/lib/netapi/netapi_private.h +++ b/source/lib/netapi/netapi_private.h @@ -20,68 +20,17 @@ #ifndef __LIB_NETAPI_PRIVATE_H__ #define __LIB_NETAPI_PRIVATE_H__ -#define LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, fn) \ - DEBUG(10,("redirecting call %s to localhost\n", #fn)); \ - if (!r->in.server_name) { \ - r->in.server_name = "localhost"; \ - } \ - return fn ## _r(ctx, r); - -struct libnetapi_private_ctx { - struct { - const char *domain_name; - struct dom_sid *domain_sid; - struct rpc_pipe_client *cli; - - uint32_t connect_mask; - struct policy_handle connect_handle; - - uint32_t domain_mask; - struct policy_handle domain_handle; - - uint32_t builtin_mask; - struct policy_handle builtin_handle; - } samr; - -}; - NET_API_STATUS libnetapi_get_password(struct libnetapi_ctx *ctx, char **password); NET_API_STATUS libnetapi_get_username(struct libnetapi_ctx *ctx, char **username); NET_API_STATUS libnetapi_set_error_string(struct libnetapi_ctx *ctx, const char *format, ...); NET_API_STATUS libnetapi_get_debuglevel(struct libnetapi_ctx *ctx, char **debuglevel); +WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx, + const char *server_name, + struct cli_state **cli); WERROR libnetapi_shutdown_cm(struct libnetapi_ctx *ctx); WERROR libnetapi_open_pipe(struct libnetapi_ctx *ctx, - const char *server_name, - const struct ndr_syntax_id *interface, - struct cli_state **pcli, - struct rpc_pipe_client **presult); -WERROR libnetapi_samr_open_domain(struct libnetapi_ctx *mem_ctx, - struct rpc_pipe_client *pipe_cli, - uint32_t connect_mask, - uint32_t domain_mask, - struct policy_handle *connect_handle, - struct policy_handle *domain_handle, - struct dom_sid2 **domain_sid); -WERROR libnetapi_samr_open_builtin_domain(struct libnetapi_ctx *mem_ctx, - struct rpc_pipe_client *pipe_cli, - uint32_t connect_mask, - uint32_t builtin_mask, - struct policy_handle *connect_handle, - struct policy_handle *builtin_handle); -void libnetapi_samr_close_domain_handle(struct libnetapi_ctx *ctx, - struct policy_handle *handle); -void libnetapi_samr_close_builtin_handle(struct libnetapi_ctx *ctx, - struct policy_handle *handle); -void libnetapi_samr_close_connect_handle(struct libnetapi_ctx *ctx, - struct policy_handle *handle); -void libnetapi_samr_free(struct libnetapi_ctx *ctx); - -NTSTATUS add_GROUP_USERS_INFO_X_buffer(TALLOC_CTX *mem_ctx, - uint32_t level, - const char *group_name, - uint32_t attributes, - uint8_t **buffer, - uint32_t *num_entries); - + struct cli_state *cli, + int pipe_idx, + struct rpc_pipe_client **pipe_cli); #endif diff --git a/source/lib/netapi/samr.c b/source/lib/netapi/samr.c deleted file mode 100644 index dbcef38dc7..0000000000 --- a/source/lib/netapi/samr.c +++ /dev/null @@ -1,319 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetApi Samr Support - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include "includes.h" -#include "lib/netapi/netapi.h" -#include "lib/netapi/netapi_private.h" - -/**************************************************************** -****************************************************************/ - -WERROR libnetapi_samr_open_domain(struct libnetapi_ctx *mem_ctx, - struct rpc_pipe_client *pipe_cli, - uint32_t connect_mask, - uint32_t domain_mask, - struct policy_handle *connect_handle, - struct policy_handle *domain_handle, - struct dom_sid2 **domain_sid) -{ - NTSTATUS status; - WERROR werr; - struct libnetapi_private_ctx *priv; - uint32_t resume_handle = 0; - uint32_t num_entries = 0; - struct samr_SamArray *sam = NULL; - const char *domain_name = NULL; - struct lsa_String lsa_domain_name; - bool domain_found = true; - int i; - - priv = talloc_get_type_abort(mem_ctx->private_data, - struct libnetapi_private_ctx); - - if (is_valid_policy_hnd(&priv->samr.connect_handle)) { - if ((priv->samr.connect_mask & connect_mask) == connect_mask) { - *connect_handle = priv->samr.connect_handle; - } else { - libnetapi_samr_close_connect_handle(mem_ctx, - &priv->samr.connect_handle); - } - } - - if (is_valid_policy_hnd(&priv->samr.domain_handle)) { - if ((priv->samr.domain_mask & domain_mask) == domain_mask) { - *domain_handle = priv->samr.domain_handle; - } else { - libnetapi_samr_close_domain_handle(mem_ctx, - &priv->samr.domain_handle); - } - } - - if (priv->samr.domain_sid) { - *domain_sid = priv->samr.domain_sid; - } - - if (is_valid_policy_hnd(&priv->samr.connect_handle) && - ((priv->samr.connect_mask & connect_mask) == connect_mask) && - is_valid_policy_hnd(&priv->samr.domain_handle) && - (priv->samr.domain_mask & domain_mask) == domain_mask) { - return WERR_OK; - } - - if (!is_valid_policy_hnd(connect_handle)) { - status = rpccli_try_samr_connects(pipe_cli, mem_ctx, - connect_mask, - connect_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - } - - status = rpccli_samr_EnumDomains(pipe_cli, mem_ctx, - connect_handle, - &resume_handle, - &sam, - 0xffffffff, - &num_entries); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - for (i=0; i<num_entries; i++) { - - domain_name = sam->entries[i].name.string; - - if (strequal(domain_name, builtin_domain_name())) { - continue; - } - - domain_found = true; - break; - } - - if (!domain_found) { - werr = WERR_NO_SUCH_DOMAIN; - goto done; - } - - init_lsa_String(&lsa_domain_name, domain_name); - - status = rpccli_samr_LookupDomain(pipe_cli, mem_ctx, - connect_handle, - &lsa_domain_name, - domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_OpenDomain(pipe_cli, mem_ctx, - connect_handle, - domain_mask, - *domain_sid, - domain_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - priv->samr.cli = pipe_cli; - - priv->samr.domain_name = domain_name; - priv->samr.domain_sid = *domain_sid; - - priv->samr.connect_mask = connect_mask; - priv->samr.connect_handle = *connect_handle; - - priv->samr.domain_mask = domain_mask; - priv->samr.domain_handle = *domain_handle; - - werr = WERR_OK; - - done: - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR libnetapi_samr_open_builtin_domain(struct libnetapi_ctx *mem_ctx, - struct rpc_pipe_client *pipe_cli, - uint32_t connect_mask, - uint32_t builtin_mask, - struct policy_handle *connect_handle, - struct policy_handle *builtin_handle) -{ - NTSTATUS status; - WERROR werr; - struct libnetapi_private_ctx *priv; - - priv = talloc_get_type_abort(mem_ctx->private_data, - struct libnetapi_private_ctx); - - if (is_valid_policy_hnd(&priv->samr.connect_handle)) { - if ((priv->samr.connect_mask & connect_mask) == connect_mask) { - *connect_handle = priv->samr.connect_handle; - } else { - libnetapi_samr_close_connect_handle(mem_ctx, - &priv->samr.connect_handle); - } - } - - if (is_valid_policy_hnd(&priv->samr.builtin_handle)) { - if ((priv->samr.builtin_mask & builtin_mask) == builtin_mask) { - *builtin_handle = priv->samr.builtin_handle; - } else { - libnetapi_samr_close_builtin_handle(mem_ctx, - &priv->samr.builtin_handle); - } - } - - if (is_valid_policy_hnd(&priv->samr.connect_handle) && - ((priv->samr.connect_mask & connect_mask) == connect_mask) && - is_valid_policy_hnd(&priv->samr.builtin_handle) && - (priv->samr.builtin_mask & builtin_mask) == builtin_mask) { - return WERR_OK; - } - - if (!is_valid_policy_hnd(connect_handle)) { - status = rpccli_try_samr_connects(pipe_cli, mem_ctx, - connect_mask, - connect_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - } - - status = rpccli_samr_OpenDomain(pipe_cli, mem_ctx, - connect_handle, - builtin_mask, - CONST_DISCARD(DOM_SID *, &global_sid_Builtin), - builtin_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - priv->samr.cli = pipe_cli; - - priv->samr.connect_mask = connect_mask; - priv->samr.connect_handle = *connect_handle; - - priv->samr.builtin_mask = builtin_mask; - priv->samr.builtin_handle = *builtin_handle; - - werr = WERR_OK; - - done: - return werr; -} - -/**************************************************************** -****************************************************************/ - -void libnetapi_samr_close_domain_handle(struct libnetapi_ctx *ctx, - struct policy_handle *handle) -{ - struct libnetapi_private_ctx *priv; - - if (!is_valid_policy_hnd(handle)) { - return; - } - - priv = talloc_get_type_abort(ctx->private_data, - struct libnetapi_private_ctx); - - if (!policy_hnd_equal(handle, &priv->samr.domain_handle)) { - return; - } - - rpccli_samr_Close(priv->samr.cli, ctx, handle); - - ZERO_STRUCT(priv->samr.domain_handle); -} - -/**************************************************************** -****************************************************************/ - -void libnetapi_samr_close_builtin_handle(struct libnetapi_ctx *ctx, - struct policy_handle *handle) -{ - struct libnetapi_private_ctx *priv; - - if (!is_valid_policy_hnd(handle)) { - return; - } - - priv = talloc_get_type_abort(ctx->private_data, - struct libnetapi_private_ctx); - - if (!policy_hnd_equal(handle, &priv->samr.builtin_handle)) { - return; - } - - rpccli_samr_Close(priv->samr.cli, ctx, handle); - - ZERO_STRUCT(priv->samr.builtin_handle); -} - -/**************************************************************** -****************************************************************/ - -void libnetapi_samr_close_connect_handle(struct libnetapi_ctx *ctx, - struct policy_handle *handle) -{ - struct libnetapi_private_ctx *priv; - - if (!is_valid_policy_hnd(handle)) { - return; - } - - priv = talloc_get_type_abort(ctx->private_data, - struct libnetapi_private_ctx); - - if (!policy_hnd_equal(handle, &priv->samr.connect_handle)) { - return; - } - - rpccli_samr_Close(priv->samr.cli, ctx, handle); - - ZERO_STRUCT(priv->samr.connect_handle); -} - -/**************************************************************** -****************************************************************/ - -void libnetapi_samr_free(struct libnetapi_ctx *ctx) -{ - struct libnetapi_private_ctx *priv; - - if (!ctx->private_data) { - return; - } - - priv = talloc_get_type_abort(ctx->private_data, - struct libnetapi_private_ctx); - - libnetapi_samr_close_domain_handle(ctx, &priv->samr.domain_handle); - libnetapi_samr_close_builtin_handle(ctx, &priv->samr.builtin_handle); - libnetapi_samr_close_connect_handle(ctx, &priv->samr.connect_handle); -} diff --git a/source/lib/netapi/serverinfo.c b/source/lib/netapi/serverinfo.c index b2a134b0af..dd7a8808b4 100644 --- a/source/lib/netapi/serverinfo.c +++ b/source/lib/netapi/serverinfo.c @@ -28,29 +28,6 @@ /**************************************************************** ****************************************************************/ -static WERROR NetServerGetInfo_l_101(struct libnetapi_ctx *ctx, - uint8_t **buffer) -{ - struct SERVER_INFO_101 i; - - i.sv101_platform_id = PLATFORM_ID_NT; - i.sv101_name = global_myname(); - i.sv101_version_major = lp_major_announce_version(); - i.sv101_version_minor = lp_minor_announce_version(); - i.sv101_type = lp_default_server_announce(); - i.sv101_comment = lp_serverstring(); - - *buffer = (uint8_t *)talloc_memdup(ctx, &i, sizeof(i)); - if (!*buffer) { - return WERR_NOMEM; - } - - return WERR_OK; -} - -/**************************************************************** -****************************************************************/ - static WERROR NetServerGetInfo_l_1005(struct libnetapi_ctx *ctx, uint8_t **buffer) { @@ -72,8 +49,6 @@ WERROR NetServerGetInfo_l(struct libnetapi_ctx *ctx, struct NetServerGetInfo *r) { switch (r->in.level) { - case 101: - return NetServerGetInfo_l_101(ctx, r->out.buffer); case 1005: return NetServerGetInfo_l_1005(ctx, r->out.buffer); default: @@ -86,78 +61,6 @@ WERROR NetServerGetInfo_l(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ -static NTSTATUS map_server_info_to_SERVER_INFO_buffer(TALLOC_CTX *mem_ctx, - uint32_t level, - union srvsvc_NetSrvInfo *i, - uint8_t **buffer) -{ - struct SERVER_INFO_100 i100; - struct SERVER_INFO_101 i101; - struct SERVER_INFO_102 i102; - struct SERVER_INFO_1005 i1005; - - uint32_t num_info = 0; - - switch (level) { - case 100: - i100.sv100_platform_id = i->info100->platform_id; - i100.sv100_name = talloc_strdup(mem_ctx, i->info100->server_name); - - ADD_TO_ARRAY(mem_ctx, struct SERVER_INFO_100, i100, - (struct SERVER_INFO_100 **)buffer, - &num_info); - break; - - case 101: - i101.sv101_platform_id = i->info101->platform_id; - i101.sv101_name = talloc_strdup(mem_ctx, i->info101->server_name); - i101.sv101_version_major = i->info101->version_major; - i101.sv101_version_minor = i->info101->version_minor; - i101.sv101_type = i->info101->server_type; - i101.sv101_comment = talloc_strdup(mem_ctx, i->info101->comment); - - ADD_TO_ARRAY(mem_ctx, struct SERVER_INFO_101, i101, - (struct SERVER_INFO_101 **)buffer, - &num_info); - break; - - case 102: - i102.sv102_platform_id = i->info102->platform_id; - i102.sv102_name = talloc_strdup(mem_ctx, i->info102->server_name); - i102.sv102_version_major = i->info102->version_major; - i102.sv102_version_minor = i->info102->version_minor; - i102.sv102_type = i->info102->server_type; - i102.sv102_comment = talloc_strdup(mem_ctx, i->info102->comment); - i102.sv102_users = i->info102->users; - i102.sv102_disc = i->info102->disc; - i102.sv102_hidden = i->info102->hidden; - i102.sv102_announce = i->info102->announce; - i102.sv102_anndelta = i->info102->anndelta; - i102.sv102_licenses = i->info102->licenses; - i102.sv102_userpath = talloc_strdup(mem_ctx, i->info102->userpath); - - ADD_TO_ARRAY(mem_ctx, struct SERVER_INFO_102, i102, - (struct SERVER_INFO_102 **)buffer, - &num_info); - break; - - case 1005: - i1005.sv1005_comment = talloc_strdup(mem_ctx, i->info1005->comment); - - ADD_TO_ARRAY(mem_ctx, struct SERVER_INFO_1005, i1005, - (struct SERVER_INFO_1005 **)buffer, - &num_info); - break; - default: - return NT_STATUS_NOT_SUPPORTED; - } - - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx, struct NetServerGetInfo *r) { @@ -167,24 +70,12 @@ WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx, WERROR werr; union srvsvc_NetSrvInfo info; - if (!r->out.buffer) { - return WERR_INVALID_PARAM; - } - - switch (r->in.level) { - case 100: - case 101: - case 102: - case 1005: - break; - default: - return WERR_UNKNOWN_LEVEL; + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; } - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_srvsvc.syntax_id, - &cli, - &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, PI_SRVSVC, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -199,10 +90,9 @@ WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx, goto done; } - status = map_server_info_to_SERVER_INFO_buffer(ctx, r->in.level, &info, - r->out.buffer); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + *r->out.buffer = (uint8_t *)talloc_memdup(ctx, &info, sizeof(info)); + if (!*r->out.buffer) { + werr = WERR_NOMEM; goto done; } @@ -280,10 +170,12 @@ WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx, WERROR werr; union srvsvc_NetSrvInfo info; - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_srvsvc.syntax_id, - &cli, - &pipe_cli); + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_SRVSVC, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -311,50 +203,3 @@ WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx, done: return werr; } - -/**************************************************************** -****************************************************************/ - -WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx, - struct NetRemoteTOD *r) -{ - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - NTSTATUS status; - WERROR werr; - struct srvsvc_NetRemoteTODInfo *info = NULL; - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_srvsvc.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - status = rpccli_srvsvc_NetRemoteTOD(pipe_cli, ctx, - r->in.server_name, - &info, - &werr); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - *r->out.buffer = (uint8_t *)talloc_memdup(ctx, info, - sizeof(struct srvsvc_NetRemoteTODInfo)); - W_ERROR_HAVE_NO_MEMORY(*r->out.buffer); - - done: - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetRemoteTOD_l(struct libnetapi_ctx *ctx, - struct NetRemoteTOD *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetRemoteTOD); -} - diff --git a/source/lib/netapi/share.c b/source/lib/netapi/share.c deleted file mode 100644 index 1d0e1810f1..0000000000 --- a/source/lib/netapi/share.c +++ /dev/null @@ -1,555 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetApi Share Support - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include "includes.h" - -#include "librpc/gen_ndr/libnetapi.h" -#include "lib/netapi/netapi.h" -#include "lib/netapi/netapi_private.h" -#include "lib/netapi/libnetapi.h" - -/**************************************************************** -****************************************************************/ - -static NTSTATUS map_srvsvc_share_info_to_SHARE_INFO_buffer(TALLOC_CTX *mem_ctx, - uint32_t level, - union srvsvc_NetShareInfo *info, - uint8_t **buffer, - uint32_t *num_shares) -{ - struct SHARE_INFO_0 i0; - struct SHARE_INFO_1 i1; - struct SHARE_INFO_2 i2; - struct SHARE_INFO_501 i501; - struct SHARE_INFO_1005 i1005; - - struct srvsvc_NetShareInfo0 *s0; - struct srvsvc_NetShareInfo1 *s1; - struct srvsvc_NetShareInfo2 *s2; - struct srvsvc_NetShareInfo501 *s501; - struct srvsvc_NetShareInfo1005 *s1005; - - if (!buffer) { - return NT_STATUS_INVALID_PARAMETER; - } - - switch (level) { - case 0: - s0 = info->info0; - - i0.shi0_netname = talloc_strdup(mem_ctx, s0->name); - - ADD_TO_ARRAY(mem_ctx, struct SHARE_INFO_0, i0, - (struct SHARE_INFO_0 **)buffer, - num_shares); - break; - - case 1: - s1 = info->info1; - - i1.shi1_netname = talloc_strdup(mem_ctx, s1->name); - i1.shi1_type = s1->type; - i1.shi1_remark = talloc_strdup(mem_ctx, s1->comment); - - ADD_TO_ARRAY(mem_ctx, struct SHARE_INFO_1, i1, - (struct SHARE_INFO_1 **)buffer, - num_shares); - break; - - case 2: - s2 = info->info2; - - i2.shi2_netname = talloc_strdup(mem_ctx, s2->name); - i2.shi2_type = s2->type; - i2.shi2_remark = talloc_strdup(mem_ctx, s2->comment); - i2.shi2_permissions = s2->permissions; - i2.shi2_max_uses = s2->max_users; - i2.shi2_current_uses = s2->current_users; - i2.shi2_path = talloc_strdup(mem_ctx, s2->path); - i2.shi2_passwd = talloc_strdup(mem_ctx, s2->password); - - ADD_TO_ARRAY(mem_ctx, struct SHARE_INFO_2, i2, - (struct SHARE_INFO_2 **)buffer, - num_shares); - break; - - case 501: - s501 = info->info501; - - i501.shi501_netname = talloc_strdup(mem_ctx, s501->name); - i501.shi501_type = s501->type; - i501.shi501_remark = talloc_strdup(mem_ctx, s501->comment); - i501.shi501_flags = s501->csc_policy; - - ADD_TO_ARRAY(mem_ctx, struct SHARE_INFO_501, i501, - (struct SHARE_INFO_501 **)buffer, - num_shares); - break; - - case 1005: - s1005 = info->info1005; - - i1005.shi1005_flags = s1005->dfs_flags; - - ADD_TO_ARRAY(mem_ctx, struct SHARE_INFO_1005, i1005, - (struct SHARE_INFO_1005 **)buffer, - num_shares); - break; - - default: - return NT_STATUS_INVALID_PARAMETER; - } - - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS map_SHARE_INFO_buffer_to_srvsvc_share_info(TALLOC_CTX *mem_ctx, - uint8_t *buffer, - uint32_t level, - union srvsvc_NetShareInfo *info) -{ - struct SHARE_INFO_2 *i2 = NULL; - struct SHARE_INFO_1004 *i1004 = NULL; - struct srvsvc_NetShareInfo2 *s2 = NULL; - struct srvsvc_NetShareInfo1004 *s1004 = NULL; - - if (!buffer) { - return NT_STATUS_INVALID_PARAMETER; - } - - switch (level) { - case 2: - i2 = (struct SHARE_INFO_2 *)buffer; - - s2 = TALLOC_P(mem_ctx, struct srvsvc_NetShareInfo2); - NT_STATUS_HAVE_NO_MEMORY(s2); - - s2->name = i2->shi2_netname; - s2->type = i2->shi2_type; - s2->comment = i2->shi2_remark; - s2->permissions = i2->shi2_permissions; - s2->max_users = i2->shi2_max_uses; - s2->current_users = i2->shi2_current_uses; - s2->path = i2->shi2_path; - s2->password = i2->shi2_passwd; - - info->info2 = s2; - - break; - case 1004: - i1004 = (struct SHARE_INFO_1004 *)buffer; - - s1004 = TALLOC_P(mem_ctx, struct srvsvc_NetShareInfo1004); - NT_STATUS_HAVE_NO_MEMORY(s1004); - - s1004->comment = i1004->shi1004_remark; - - info->info1004 = s1004; - - break; - default: - return NT_STATUS_INVALID_PARAMETER; - } - - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetShareAdd_r(struct libnetapi_ctx *ctx, - struct NetShareAdd *r) -{ - WERROR werr; - NTSTATUS status; - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - union srvsvc_NetShareInfo info; - - if (!r->in.buffer) { - return WERR_INVALID_PARAM; - } - - switch (r->in.level) { - case 2: - break; - case 502: - case 503: - return WERR_NOT_SUPPORTED; - default: - return WERR_UNKNOWN_LEVEL; - } - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_srvsvc.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - status = map_SHARE_INFO_buffer_to_srvsvc_share_info(ctx, - r->in.buffer, - r->in.level, - &info); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_srvsvc_NetShareAdd(pipe_cli, ctx, - r->in.server_name, - r->in.level, - &info, - r->out.parm_err, - &werr); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - done: - if (!cli) { - return werr; - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetShareAdd_l(struct libnetapi_ctx *ctx, - struct NetShareAdd *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareAdd); -} - -/**************************************************************** -****************************************************************/ - -WERROR NetShareDel_r(struct libnetapi_ctx *ctx, - struct NetShareDel *r) -{ - WERROR werr; - NTSTATUS status; - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - - if (!r->in.net_name) { - return WERR_INVALID_PARAM; - } - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_srvsvc.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - status = rpccli_srvsvc_NetShareDel(pipe_cli, ctx, - r->in.server_name, - r->in.net_name, - r->in.reserved, - &werr); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - done: - if (!cli) { - return werr; - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetShareDel_l(struct libnetapi_ctx *ctx, - struct NetShareDel *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareDel); -} - -/**************************************************************** -****************************************************************/ - -WERROR NetShareEnum_r(struct libnetapi_ctx *ctx, - struct NetShareEnum *r) -{ - WERROR werr; - NTSTATUS status; - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - struct srvsvc_NetShareInfoCtr info_ctr; - struct srvsvc_NetShareCtr0 ctr0; - struct srvsvc_NetShareCtr1 ctr1; - struct srvsvc_NetShareCtr2 ctr2; - uint32_t i; - - if (!r->out.buffer) { - return WERR_INVALID_PARAM; - } - - switch (r->in.level) { - case 0: - case 1: - case 2: - break; - case 502: - case 503: - return WERR_NOT_SUPPORTED; - default: - return WERR_UNKNOWN_LEVEL; - } - - ZERO_STRUCT(info_ctr); - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_srvsvc.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - info_ctr.level = r->in.level; - switch (r->in.level) { - case 0: - ZERO_STRUCT(ctr0); - info_ctr.ctr.ctr0 = &ctr0; - break; - case 1: - ZERO_STRUCT(ctr1); - info_ctr.ctr.ctr1 = &ctr1; - break; - case 2: - ZERO_STRUCT(ctr2); - info_ctr.ctr.ctr2 = &ctr2; - break; - } - - status = rpccli_srvsvc_NetShareEnumAll(pipe_cli, ctx, - r->in.server_name, - &info_ctr, - r->in.prefmaxlen, - r->out.total_entries, - r->out.resume_handle, - &werr); - if (NT_STATUS_IS_ERR(status)) { - goto done; - } - - for (i=0; i < info_ctr.ctr.ctr1->count; i++) { - union srvsvc_NetShareInfo _i; - switch (r->in.level) { - case 0: - _i.info0 = &info_ctr.ctr.ctr0->array[i]; - break; - case 1: - _i.info1 = &info_ctr.ctr.ctr1->array[i]; - break; - case 2: - _i.info2 = &info_ctr.ctr.ctr2->array[i]; - break; - } - - status = map_srvsvc_share_info_to_SHARE_INFO_buffer(ctx, - r->in.level, - &_i, - r->out.buffer, - r->out.entries_read); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - } - } - - done: - if (!cli) { - return werr; - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetShareEnum_l(struct libnetapi_ctx *ctx, - struct NetShareEnum *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareEnum); -} - -/**************************************************************** -****************************************************************/ - -WERROR NetShareGetInfo_r(struct libnetapi_ctx *ctx, - struct NetShareGetInfo *r) -{ - WERROR werr; - NTSTATUS status; - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - union srvsvc_NetShareInfo info; - uint32_t num_entries = 0; - - if (!r->in.net_name || !r->out.buffer) { - return WERR_INVALID_PARAM; - } - - switch (r->in.level) { - case 0: - case 1: - case 2: - case 501: - case 1005: - break; - case 502: - case 503: - return WERR_NOT_SUPPORTED; - default: - return WERR_UNKNOWN_LEVEL; - } - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_srvsvc.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - status = rpccli_srvsvc_NetShareGetInfo(pipe_cli, ctx, - r->in.server_name, - r->in.net_name, - r->in.level, - &info, - &werr); - - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - status = map_srvsvc_share_info_to_SHARE_INFO_buffer(ctx, - r->in.level, - &info, - r->out.buffer, - &num_entries); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - } - - done: - if (!cli) { - return werr; - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetShareGetInfo_l(struct libnetapi_ctx *ctx, - struct NetShareGetInfo *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareGetInfo); -} - -/**************************************************************** -****************************************************************/ - -WERROR NetShareSetInfo_r(struct libnetapi_ctx *ctx, - struct NetShareSetInfo *r) -{ - WERROR werr; - NTSTATUS status; - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - union srvsvc_NetShareInfo info; - - if (!r->in.buffer) { - return WERR_INVALID_PARAM; - } - - switch (r->in.level) { - case 2: - case 1004: - break; - case 1: - case 502: - case 503: - case 1005: - case 1006: - case 1501: - return WERR_NOT_SUPPORTED; - default: - return WERR_UNKNOWN_LEVEL; - } - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_srvsvc.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - status = map_SHARE_INFO_buffer_to_srvsvc_share_info(ctx, - r->in.buffer, - r->in.level, - &info); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_srvsvc_NetShareSetInfo(pipe_cli, ctx, - r->in.server_name, - r->in.net_name, - r->in.level, - &info, - r->out.parm_err, - &werr); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - done: - if (!cli) { - return werr; - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetShareSetInfo_l(struct libnetapi_ctx *ctx, - struct NetShareSetInfo *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareSetInfo); -} diff --git a/source/lib/netapi/sid.c b/source/lib/netapi/sid.c deleted file mode 100644 index a9bca2689f..0000000000 --- a/source/lib/netapi/sid.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetApi Support - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include "includes.h" - -#include "lib/netapi/netapi.h" - -/**************************************************************** -****************************************************************/ - -int ConvertSidToStringSid(const struct domsid *sid, - char **sid_string) -{ - char *ret; - - if (!sid || !sid_string) { - return false; - } - - ret = sid_string_talloc(NULL, (const struct dom_sid *)sid); - if (!ret) { - return false; - } - - *sid_string = SMB_STRDUP(ret); - - TALLOC_FREE(ret); - - if (!*sid_string) { - return false; - } - - return true; -} - -/**************************************************************** -****************************************************************/ - -int ConvertStringSidToSid(const char *sid_string, - struct domsid **sid) -{ - struct dom_sid _sid; - - if (!sid_string || !sid) { - return false; - } - - if (!string_to_sid(&_sid, sid_string)) { - return false; - } - - *sid = (struct domsid *)SMB_MALLOC(sizeof(struct domsid)); - if (!*sid) { - return false; - } - - sid_copy((struct dom_sid*)*sid, &_sid); - - return true; -} diff --git a/source/lib/netapi/tests/Makefile.in b/source/lib/netapi/tests/Makefile.in deleted file mode 100644 index d3f0663908..0000000000 --- a/source/lib/netapi/tests/Makefile.in +++ /dev/null @@ -1,57 +0,0 @@ -KRB5LIBS=@KRB5_LIBS@ -LDAP_LIBS=@LDAP_LIBS@ -LIBS=@LIBS@ -lnetapi -ltdb -ltalloc -DEVELOPER_CFLAGS=@DEVELOPER_CFLAGS@ -FLAGS=-I../ -L../../../bin @CFLAGS@ $(GTK_FLAGS) -CC=@CC@ -PICFLAG=@PICFLAG@ -LDFLAGS=@PIE_LDFLAGS@ @LDFLAGS@ -DYNEXP=@DYNEXP@ -NETAPI_LIBS=$(LIBS) $(KRB5LIBS) $(LDAP_LIBS) -CMDLINE_LIBS=$(NETAPI_LIBS) @POPTLIBS@ - -# Compile a source file. -COMPILE_CC = $(CC) -I. $(FLAGS) $(PICFLAG) -c $< -o $@ -COMPILE = $(COMPILE_CC) - -PROGS = bin/netapitest@EXEEXT@ - -all: $(PROGS) - -MAKEDIR = || exec false; \ - if test -d "$$dir"; then :; else \ - echo mkdir "$$dir"; \ - mkdir -p "$$dir" >/dev/null 2>&1 || \ - test -d "$$dir" || \ - mkdir "$$dir" || \ - exec false; fi || exec false - -BINARY_PREREQS = bin/.dummy - -bin/.dummy: - @if (: >> $@ || : > $@) >/dev/null 2>&1; then :; else \ - dir=bin $(MAKEDIR); fi - @: >> $@ || : > $@ # what a fancy emoticon! - -.c.o: - @if (: >> $@ || : > $@) >/dev/null 2>&1; then rm -f $@; else \ - dir=`echo $@ | sed 's,/[^/]*$$,,;s,^$$,.,'` $(MAKEDIR); fi - @echo Compiling $*.c - @$(COMPILE) && exit 0;\ - echo "The following command failed:" 1>&2;\ - echo "$(COMPILE_CC)" 1>&2;\ - $(COMPILE_CC) >/dev/null 2>&1 - -CMDLINE_OBJ = common.o -NETAPIBUFFER_OBJ = netapibuffer.o -NETAPITEST_OBJ = netapitest.o netlocalgroup.o netuser.o netgroup.o netdisplay.o netshare.o $(CMDLINE_OBJ) - -bin/netapitest@EXEEXT@: $(BINARY_PREREQS) $(NETAPITEST_OBJ) - @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(NETAPITEST_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) - -clean: - -rm -f $(PROGS) - -rm -f core */*~ *~ \ - */*.o */*/*.o */*/*/*.o - diff --git a/source/lib/netapi/tests/common.c b/source/lib/netapi/tests/common.c deleted file mode 100644 index 22175afb48..0000000000 --- a/source/lib/netapi/tests/common.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetApi testsuite - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <inttypes.h> - -#include <popt.h> -#include <netapi.h> - -#include "common.h" - -void popt_common_callback(poptContext con, - enum poptCallbackReason reason, - const struct poptOption *opt, - const char *arg, const void *data) -{ - struct libnetapi_ctx *ctx = NULL; - - libnetapi_getctx(&ctx); - - if (reason == POPT_CALLBACK_REASON_PRE) { - } - - if (reason == POPT_CALLBACK_REASON_POST) { - } - - if (!opt) { - return; - } - switch (opt->val) { - case 'U': { - char *puser = strdup(arg); - char *p = NULL; - - if ((p = strchr(puser,'%'))) { - size_t len; - *p = 0; - libnetapi_set_username(ctx, puser); - libnetapi_set_password(ctx, p+1); - len = strlen(p+1); - memset(strchr(arg,'%')+1,'X',len); - } else { - libnetapi_set_username(ctx, puser); - } - free(puser); - break; - } - case 'd': - libnetapi_set_debuglevel(ctx, arg); - break; - case 'p': - libnetapi_set_password(ctx, arg); - break; - case 'k': - libnetapi_set_use_kerberos(ctx); - break; - } -} - -struct poptOption popt_common_netapi_examples[] = { - { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST, (void *)popt_common_callback }, - { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Username used for connection", "USERNAME" }, - { "password", 'p', POPT_ARG_STRING, NULL, 'p', "Password used for connection", "PASSWORD" }, - { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Debuglevel", "DEBUGLEVEL" }, - { "kerberos", 'k', POPT_ARG_NONE, NULL, 'k', "Use Kerberos", NULL }, - POPT_TABLEEND -}; - diff --git a/source/lib/netapi/tests/common.h b/source/lib/netapi/tests/common.h deleted file mode 100644 index 5a320321ba..0000000000 --- a/source/lib/netapi/tests/common.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetApi testsuite - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <popt.h> - -void popt_common_callback(poptContext con, - enum poptCallbackReason reason, - const struct poptOption *opt, - const char *arg, const void *data); - -extern struct poptOption popt_common_netapi_examples[]; - -#define POPT_COMMON_LIBNETAPI_EXAMPLES { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_netapi_examples, 0, "Common samba netapi example options:", NULL }, - -NET_API_STATUS test_netuseradd(const char *hostname, - const char *username); - -NET_API_STATUS netapitest_localgroup(struct libnetapi_ctx *ctx, - const char *hostname); -NET_API_STATUS netapitest_user(struct libnetapi_ctx *ctx, - const char *hostname); -NET_API_STATUS netapitest_group(struct libnetapi_ctx *ctx, - const char *hostname); -NET_API_STATUS netapitest_display(struct libnetapi_ctx *ctx, - const char *hostname); -NET_API_STATUS netapitest_share(struct libnetapi_ctx *ctx, - const char *hostname); - -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) -#endif - -#define NETAPI_STATUS(x,y,fn) \ - printf("FAILURE: line %d: %s failed with status: %s (%d)\n", \ - __LINE__, fn, libnetapi_get_error_string(x,y), y); - -#define NETAPI_STATUS_MSG(x,y,fn,z) \ - printf("FAILURE: line %d: %s failed with status: %s (%d), %s\n", \ - __LINE__, fn, libnetapi_get_error_string(x,y), y, z); - -#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x)) diff --git a/source/lib/netapi/tests/netapitest.c b/source/lib/netapi/tests/netapitest.c deleted file mode 100644 index 87144020f5..0000000000 --- a/source/lib/netapi/tests/netapitest.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetApi testsuite - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status = 0; - struct libnetapi_ctx *ctx = NULL; - const char *hostname = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("netapitest", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - hostname = poptGetArg(pc); - - status = netapitest_localgroup(ctx, hostname); - if (status) { - goto out; - } - - status = netapitest_user(ctx, hostname); - if (status) { - goto out; - } - - status = netapitest_group(ctx, hostname); - if (status) { - goto out; - } - - status = netapitest_display(ctx, hostname); - if (status) { - goto out; - } - - status = netapitest_share(ctx, hostname); - if (status) { - goto out; - } - - out: - if (status != 0) { - printf("testsuite failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} diff --git a/source/lib/netapi/tests/netdisplay.c b/source/lib/netapi/tests/netdisplay.c deleted file mode 100644 index 090792cec2..0000000000 --- a/source/lib/netapi/tests/netdisplay.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetGroup testsuite - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -static NET_API_STATUS test_netquerydisplayinformation(const char *hostname, - uint32_t level, - const char *name) -{ - NET_API_STATUS status; - uint32_t entries_read = 0; - int found_name = 0; - const char *current_name; - uint8_t *buffer = NULL; - uint32_t idx = 0; - int i; - - struct NET_DISPLAY_USER *user; - struct NET_DISPLAY_GROUP *group; - struct NET_DISPLAY_MACHINE *machine; - - printf("testing NetQueryDisplayInformation level %d\n", level); - - do { - status = NetQueryDisplayInformation(hostname, - level, - idx, - 1000, - (uint32_t)-1, - &entries_read, - (void **)&buffer); - if (status == 0 || status == ERROR_MORE_DATA) { - switch (level) { - case 1: - user = (struct NET_DISPLAY_USER *)buffer; - break; - case 2: - machine = (struct NET_DISPLAY_MACHINE *)buffer; - break; - case 3: - group = (struct NET_DISPLAY_GROUP *)buffer; - break; - default: - return -1; - } - - for (i=0; i<entries_read; i++) { - - switch (level) { - case 1: - current_name = user->usri1_name; - break; - case 2: - current_name = machine->usri2_name; - break; - case 3: - current_name = group->grpi3_name; - break; - default: - break; - } - - if (name && strcasecmp(current_name, name) == 0) { - found_name = 1; - } - - switch (level) { - case 1: - user++; - break; - case 2: - machine++; - break; - case 3: - group++; - break; - } - } - NetApiBufferFree(buffer); - } - idx += entries_read; - } while (status == ERROR_MORE_DATA); - - if (status) { - return status; - } - - if (name && !found_name) { - printf("failed to get name\n"); - return -1; - } - - return 0; -} - -NET_API_STATUS netapitest_display(struct libnetapi_ctx *ctx, - const char *hostname) -{ - NET_API_STATUS status = 0; - uint32_t levels[] = { 1, 2, 3}; - int i; - - printf("NetDisplay tests\n"); - - /* test enum */ - - for (i=0; i<ARRAY_SIZE(levels); i++) { - - status = test_netquerydisplayinformation(hostname, levels[i], NULL); - if (status) { - NETAPI_STATUS(ctx, status, "NetQueryDisplayInformation"); - goto out; - } - } - - status = 0; - - printf("NetDisplay tests succeeded\n"); - out: - if (status != 0) { - printf("NetDisplay testsuite failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - return status; -} diff --git a/source/lib/netapi/tests/netgroup.c b/source/lib/netapi/tests/netgroup.c deleted file mode 100644 index a89a772ce4..0000000000 --- a/source/lib/netapi/tests/netgroup.c +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetGroup testsuite - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -static NET_API_STATUS test_netgroupenum(const char *hostname, - uint32_t level, - const char *groupname) -{ - NET_API_STATUS status; - uint32_t entries_read = 0; - uint32_t total_entries = 0; - uint32_t resume_handle = 0; - int found_group = 0; - const char *current_name; - uint8_t *buffer = NULL; - int i; - - struct GROUP_INFO_0 *info0; - struct GROUP_INFO_1 *info1; - struct GROUP_INFO_2 *info2; - struct GROUP_INFO_3 *info3; - - printf("testing NetGroupEnum level %d\n", level); - - do { - status = NetGroupEnum(hostname, - level, - &buffer, - 120, //(uint32_t)-1, - &entries_read, - &total_entries, - &resume_handle); - if (status == 0 || status == ERROR_MORE_DATA) { - switch (level) { - case 0: - info0 = (struct GROUP_INFO_0 *)buffer; - break; - case 1: - info1 = (struct GROUP_INFO_1 *)buffer; - break; - case 2: - info2 = (struct GROUP_INFO_2 *)buffer; - break; - case 3: - info3 = (struct GROUP_INFO_3 *)buffer; - break; - default: - return -1; - } - - for (i=0; i<entries_read; i++) { - - switch (level) { - case 0: - current_name = info0->grpi0_name; - break; - case 1: - current_name = info1->grpi1_name; - break; - case 2: - current_name = info2->grpi2_name; - break; - case 3: - current_name = info3->grpi3_name; - break; - default: - break; - } - - if (strcasecmp(current_name, groupname) == 0) { - found_group = 1; - } - - switch (level) { - case 0: - info0++; - break; - case 1: - info1++; - break; - case 2: - info2++; - break; - case 3: - info3++; - break; - } - } - NetApiBufferFree(buffer); - } - } while (status == ERROR_MORE_DATA); - - if (status) { - return status; - } - - if (!found_group) { - printf("failed to get group\n"); - return -1; - } - - return 0; -} - -NET_API_STATUS netapitest_group(struct libnetapi_ctx *ctx, - const char *hostname) -{ - NET_API_STATUS status = 0; - const char *username, *groupname, *groupname2; - uint8_t *buffer = NULL; - struct GROUP_INFO_0 g0; - uint32_t parm_err = 0; - uint32_t levels[] = { 0, 1, 2, 3}; - uint32_t enum_levels[] = { 0, 1, 2, 3}; - int i; - - printf("NetGroup tests\n"); - - username = "torture_test_user"; - groupname = "torture_test_group"; - groupname2 = "torture_test_group2"; - - /* cleanup */ - NetGroupDel(hostname, groupname); - NetGroupDel(hostname, groupname2); - NetUserDel(hostname, username); - - /* add a group */ - - g0.grpi0_name = groupname; - - printf("testing NetGroupAdd\n"); - - status = NetGroupAdd(hostname, 0, (uint8_t *)&g0, &parm_err); - if (status) { - NETAPI_STATUS(ctx, status, "NetGroupAdd"); - goto out; - } - - /* 2nd add must fail */ - - status = NetGroupAdd(hostname, 0, (uint8_t *)&g0, &parm_err); - if (status == 0) { - NETAPI_STATUS(ctx, status, "NetGroupAdd"); - goto out; - } - - /* test enum */ - - for (i=0; i<ARRAY_SIZE(enum_levels); i++) { - - status = test_netgroupenum(hostname, enum_levels[i], groupname); - if (status) { - NETAPI_STATUS(ctx, status, "NetGroupEnum"); - goto out; - } - } - - /* basic queries */ - - for (i=0; i<ARRAY_SIZE(levels); i++) { - - printf("testing NetGroupGetInfo level %d\n", levels[i]); - - status = NetGroupGetInfo(hostname, groupname, levels[i], &buffer); - if (status && status != 124) { - NETAPI_STATUS(ctx, status, "NetGroupGetInfo"); - goto out; - } - } - - /* group rename */ - - g0.grpi0_name = groupname2; - - printf("testing NetGroupSetInfo level 0\n"); - - status = NetGroupSetInfo(hostname, groupname, 0, (uint8_t *)&g0, &parm_err); - if (status) { - NETAPI_STATUS(ctx, status, "NetGroupSetInfo"); - goto out; - } - - /* should not exist anymore */ - - status = NetGroupDel(hostname, groupname); - if (status == 0) { - NETAPI_STATUS(ctx, status, "NetGroupDel"); - goto out; - } - - /* query info */ - - for (i=0; i<ARRAY_SIZE(levels); i++) { - - status = NetGroupGetInfo(hostname, groupname2, levels[i], &buffer); - if (status && status != 124) { - NETAPI_STATUS(ctx, status, "NetGroupGetInfo"); - goto out; - } - } - - /* add user to group */ - - status = test_netuseradd(hostname, username); - if (status) { - NETAPI_STATUS(ctx, status, "NetUserAdd"); - goto out; - } - - printf("testing NetGroupAddUser\n"); - - status = NetGroupAddUser(hostname, groupname2, username); - if (status) { - NETAPI_STATUS(ctx, status, "NetGroupAddUser"); - goto out; - } - - printf("testing NetGroupDelUser\n"); - - status = NetGroupDelUser(hostname, groupname2, username); - if (status) { - NETAPI_STATUS(ctx, status, "NetGroupDelUser"); - goto out; - } - - status = NetUserDel(hostname, username); - if (status) { - NETAPI_STATUS(ctx, status, "NetUserDel"); - goto out; - } - - /* delete */ - - printf("testing NetGroupDel\n"); - - status = NetGroupDel(hostname, groupname2); - if (status) { - NETAPI_STATUS(ctx, status, "NetGroupDel"); - goto out; - }; - - /* should not exist anymore */ - - status = NetGroupGetInfo(hostname, groupname2, 0, &buffer); - if (status == 0) { - NETAPI_STATUS_MSG(ctx, status, "NetGroupGetInfo", "expected failure and error code"); - goto out; - }; - - status = 0; - - printf("NetGroup tests succeeded\n"); - out: - if (status != 0) { - printf("NetGroup testsuite failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - return status; -} diff --git a/source/lib/netapi/tests/netlocalgroup.c b/source/lib/netapi/tests/netlocalgroup.c deleted file mode 100644 index 0d82059356..0000000000 --- a/source/lib/netapi/tests/netlocalgroup.c +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetLocalGroup testsuite - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -static NET_API_STATUS test_netlocalgroupenum(const char *hostname, - uint32_t level, - const char *groupname) -{ - NET_API_STATUS status; - uint32_t entries_read = 0; - uint32_t total_entries = 0; - uint32_t resume_handle = 0; - int found_group = 0; - const char *current_name; - uint8_t *buffer = NULL; - int i; - - struct LOCALGROUP_INFO_0 *info0; - struct LOCALGROUP_INFO_1 *info1; - - printf("testing NetLocalGroupEnum level %d\n", level); - - do { - status = NetLocalGroupEnum(hostname, - level, - &buffer, - (uint32_t)-1, - &entries_read, - &total_entries, - &resume_handle); - if (status == 0 || status == ERROR_MORE_DATA) { - switch (level) { - case 0: - info0 = (struct LOCALGROUP_INFO_0 *)buffer; - break; - case 1: - info1 = (struct LOCALGROUP_INFO_1 *)buffer; - break; - default: - return -1; - } - - for (i=0; i<entries_read; i++) { - - switch (level) { - case 0: - current_name = info0->lgrpi0_name; - break; - case 1: - current_name = info1->lgrpi1_name; - break; - default: - break; - } - - if (strcasecmp(current_name, groupname) == 0) { - found_group = 1; - } - - switch (level) { - case 0: - info0++; - break; - case 1: - info1++; - break; - } - } - NetApiBufferFree(buffer); - } - } while (status == ERROR_MORE_DATA); - - if (status) { - return status; - } - - if (!found_group) { - printf("failed to get group\n"); - return -1; - } - - return 0; -} - -NET_API_STATUS netapitest_localgroup(struct libnetapi_ctx *ctx, - const char *hostname) -{ - NET_API_STATUS status = 0; - const char *groupname, *groupname2; - uint8_t *buffer = NULL; - struct LOCALGROUP_INFO_0 g0; - uint32_t parm_err = 0; - uint32_t levels[] = { 0, 1, 1002 }; - uint32_t enum_levels[] = { 0, 1 }; - int i; - - printf("NetLocalgroup tests\n"); - - groupname = "torture_test_localgroup"; - groupname2 = "torture_test_localgroup2"; - - /* cleanup */ - NetLocalGroupDel(hostname, groupname); - NetLocalGroupDel(hostname, groupname2); - - /* add a localgroup */ - - printf("testing NetLocalGroupAdd\n"); - - g0.lgrpi0_name = groupname; - - status = NetLocalGroupAdd(hostname, 0, (uint8_t *)&g0, &parm_err); - if (status) { - NETAPI_STATUS(ctx, status, "NetLocalGroupAdd"); - goto out; - }; - - /* test enum */ - - for (i=0; i<ARRAY_SIZE(enum_levels); i++) { - - status = test_netlocalgroupenum(hostname, enum_levels[i], groupname); - if (status) { - NETAPI_STATUS(ctx, status, "NetLocalGroupEnum"); - goto out; - } - } - - - /* basic queries */ - - for (i=0; i<ARRAY_SIZE(levels); i++) { - - printf("testing NetLocalGroupGetInfo level %d\n", levels[i]); - - status = NetLocalGroupGetInfo(hostname, groupname, levels[i], &buffer); - if (status && status != 124) { - NETAPI_STATUS(ctx, status, "NetLocalGroupGetInfo"); - goto out; - }; - } - - /* alias rename */ - - printf("testing NetLocalGroupSetInfo level 0\n"); - - g0.lgrpi0_name = groupname2; - - status = NetLocalGroupSetInfo(hostname, groupname, 0, (uint8_t *)&g0, &parm_err); - if (status) { - NETAPI_STATUS(ctx, status, "NetLocalGroupSetInfo"); - goto out; - }; - - /* should not exist anymore */ - - status = NetLocalGroupDel(hostname, groupname); - if (status == 0) { - NETAPI_STATUS(ctx, status, "NetLocalGroupDel"); - goto out; - }; - - /* query info */ - - for (i=0; i<ARRAY_SIZE(levels); i++) { - status = NetLocalGroupGetInfo(hostname, groupname2, levels[i], &buffer); - if (status && status != 124) { - NETAPI_STATUS(ctx, status, "NetLocalGroupGetInfo"); - goto out; - }; - } - - /* delete */ - - printf("testing NetLocalGroupDel\n"); - - status = NetLocalGroupDel(hostname, groupname2); - if (status) { - NETAPI_STATUS(ctx, status, "NetLocalGroupDel"); - goto out; - }; - - /* should not exist anymore */ - - status = NetLocalGroupGetInfo(hostname, groupname2, 0, &buffer); - if (status == 0) { - NETAPI_STATUS(ctx, status, "NetLocalGroupGetInfo"); - goto out; - }; - - status = 0; - - printf("NetLocalgroup tests succeeded\n"); - out: - if (status != 0) { - printf("NetLocalGroup testsuite failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - return status; -} diff --git a/source/lib/netapi/tests/netshare.c b/source/lib/netapi/tests/netshare.c deleted file mode 100644 index 9446c307b3..0000000000 --- a/source/lib/netapi/tests/netshare.c +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetShare testsuite - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -static NET_API_STATUS test_netshareenum(const char *hostname, - uint32_t level, - const char *sharename) -{ - NET_API_STATUS status; - uint32_t entries_read = 0; - uint32_t total_entries = 0; - uint32_t resume_handle = 0; - int found_share = 0; - const char *current_name; - uint8_t *buffer = NULL; - int i; - - struct SHARE_INFO_0 *i0; - struct SHARE_INFO_1 *i1; - struct SHARE_INFO_2 *i2; - - printf("testing NetShareEnum level %d\n", level); - - do { - status = NetShareEnum(hostname, - level, - &buffer, - (uint32_t)-1, - &entries_read, - &total_entries, - &resume_handle); - if (status == 0 || status == ERROR_MORE_DATA) { - switch (level) { - case 0: - i0 = (struct SHARE_INFO_0 *)buffer; - break; - case 1: - i1 = (struct SHARE_INFO_1 *)buffer; - break; - case 2: - i2 = (struct SHARE_INFO_2 *)buffer; - break; - default: - return -1; - } - - for (i=0; i<entries_read; i++) { - - switch (level) { - case 0: - current_name = i0->shi0_netname; - break; - case 1: - current_name = i1->shi1_netname; - break; - case 2: - current_name = i2->shi2_netname; - break; - default: - break; - } - - if (strcasecmp(current_name, sharename) == 0) { - found_share = 1; - } - - switch (level) { - case 0: - i0++; - break; - case 1: - i1++; - break; - case 2: - i2++; - break; - } - } - NetApiBufferFree(buffer); - } - } while (status == ERROR_MORE_DATA); - - if (status) { - return status; - } - - if (!found_share) { - printf("failed to get share\n"); - return -1; - } - - return 0; -} - -NET_API_STATUS netapitest_share(struct libnetapi_ctx *ctx, - const char *hostname) -{ - NET_API_STATUS status = 0; - const char *sharename, *comment; - uint8_t *buffer = NULL; - struct SHARE_INFO_2 i2; - struct SHARE_INFO_1004 i1004; - struct SHARE_INFO_501 *i501 = NULL; - uint32_t parm_err = 0; - uint32_t levels[] = { 0, 1, 2, 501, 1005 }; - uint32_t enum_levels[] = { 0, 1, 2 }; - int i; - - printf("NetShare tests\n"); - - sharename = "torture_test_share"; - - /* cleanup */ - NetShareDel(hostname, sharename, 0); - - /* add a share */ - - printf("testing NetShareAdd\n"); - - ZERO_STRUCT(i2); - - i2.shi2_netname = sharename; - i2.shi2_path = "c:\\"; - - status = NetShareAdd(hostname, 2, (uint8_t *)&i2, &parm_err); - if (status) { - NETAPI_STATUS(ctx, status, "NetShareAdd"); - goto out; - }; - - /* test enum */ - - for (i=0; i<ARRAY_SIZE(enum_levels); i++) { - - status = test_netshareenum(hostname, enum_levels[i], sharename); - if (status) { - NETAPI_STATUS(ctx, status, "NetShareEnum"); - goto out; - } - } - - /* basic queries */ - - for (i=0; i<ARRAY_SIZE(levels); i++) { - - printf("testing NetShareGetInfo level %d\n", levels[i]); - - status = NetShareGetInfo(hostname, sharename, levels[i], &buffer); - if (status && status != 124) { - NETAPI_STATUS(ctx, status, "NetShareGetInfo"); - goto out; - } - } - - - comment = "NetApi generated comment"; - - i1004.shi1004_remark = comment; - - printf("testing NetShareSetInfo level 1004\n"); - - status = NetShareSetInfo(hostname, sharename, 1004, (uint8_t *)&i1004, &parm_err); - if (status) { - NETAPI_STATUS(ctx, status, "NetShareSetInfo"); - goto out; - } - - status = NetShareGetInfo(hostname, sharename, 501, (uint8_t **)&i501); - if (status) { - NETAPI_STATUS(ctx, status, "NetShareGetInfo"); - goto out; - } - - if (strcasecmp(i501->shi501_remark, comment) != 0) { - NETAPI_STATUS(ctx, status, "NetShareGetInfo"); - goto out; - } - - /* delete */ - - printf("testing NetShareDel\n"); - - status = NetShareDel(hostname, sharename, 0); - if (status) { - NETAPI_STATUS(ctx, status, "NetShareDel"); - goto out; - }; - - /* should not exist anymore */ - - status = NetShareGetInfo(hostname, sharename, 0, &buffer); - if (status == 0) { - NETAPI_STATUS(ctx, status, "NetShareGetInfo"); - goto out; - }; - - status = 0; - - printf("NetShare tests succeeded\n"); - out: - if (status != 0) { - printf("NetShare testsuite failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - return status; -} diff --git a/source/lib/netapi/tests/netuser.c b/source/lib/netapi/tests/netuser.c deleted file mode 100644 index f1622e45c4..0000000000 --- a/source/lib/netapi/tests/netuser.c +++ /dev/null @@ -1,458 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetUser testsuite - * Copyright (C) Guenther Deschner 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 <http://www.gnu.org/licenses/>. - */ - -#include <sys/types.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <netapi.h> - -#include "common.h" - -static NET_API_STATUS test_netuserenum(const char *hostname, - uint32_t level, - const char *username) -{ - NET_API_STATUS status; - uint32_t entries_read = 0; - uint32_t total_entries = 0; - uint32_t resume_handle = 0; - const char *current_name; - int found_user = 0; - uint8_t *buffer = NULL; - int i; - - struct USER_INFO_0 *info0; - struct USER_INFO_1 *info1; - struct USER_INFO_2 *info2; - struct USER_INFO_3 *info3; - struct USER_INFO_4 *info4; - struct USER_INFO_10 *info10; - struct USER_INFO_11 *info11; - struct USER_INFO_20 *info20; - struct USER_INFO_23 *info23; - - printf("testing NetUserEnum level %d\n", level); - - do { - status = NetUserEnum(hostname, - level, - FILTER_NORMAL_ACCOUNT, - &buffer, - 120, //(uint32_t)-1, - &entries_read, - &total_entries, - &resume_handle); - if (status == 0 || status == ERROR_MORE_DATA) { - switch (level) { - case 0: - info0 = (struct USER_INFO_0 *)buffer; - break; - case 1: - info1 = (struct USER_INFO_1 *)buffer; - break; - case 2: - info2 = (struct USER_INFO_2 *)buffer; - break; - case 3: - info3 = (struct USER_INFO_3 *)buffer; - break; - case 4: - info4 = (struct USER_INFO_4 *)buffer; - break; - case 10: - info10 = (struct USER_INFO_10 *)buffer; - break; - case 11: - info11 = (struct USER_INFO_11 *)buffer; - break; - case 20: - info20 = (struct USER_INFO_20 *)buffer; - break; - case 23: - info23 = (struct USER_INFO_23 *)buffer; - break; - default: - return -1; - } - - for (i=0; i<entries_read; i++) { - - switch (level) { - case 0: - current_name = info0->usri0_name; - break; - case 1: - current_name = info1->usri1_name; - break; - case 2: - current_name = info2->usri2_name; - break; - case 3: - current_name = info3->usri3_name; - break; - case 4: - current_name = info4->usri4_name; - break; - case 10: - current_name = info10->usri10_name; - break; - case 11: - current_name = info11->usri11_name; - break; - case 20: - current_name = info20->usri20_name; - break; - case 23: - current_name = info23->usri23_name; - break; - default: - return -1; - } - - if (strcasecmp(current_name, username) == 0) { - found_user = 1; - } - - switch (level) { - case 0: - info0++; - break; - case 1: - info1++; - break; - case 2: - info2++; - break; - case 3: - info3++; - break; - case 4: - info4++; - break; - case 10: - info10++; - break; - case 11: - info11++; - break; - case 20: - info20++; - break; - case 23: - info23++; - break; - default: - break; - } - } - NetApiBufferFree(buffer); - } - } while (status == ERROR_MORE_DATA); - - if (status) { - return status; - } - - if (!found_user) { - printf("failed to get user\n"); - return -1; - } - - return 0; -} - -NET_API_STATUS test_netuseradd(const char *hostname, - const char *username) -{ - struct USER_INFO_1 u1; - uint32_t parm_err = 0; - - ZERO_STRUCT(u1); - - printf("testing NetUserAdd\n"); - - u1.usri1_name = username; - u1.usri1_password = "W297!832jD8J"; - u1.usri1_password_age = 0; - u1.usri1_priv = 0; - u1.usri1_home_dir = NULL; - u1.usri1_comment = "User created using Samba NetApi Example code"; - u1.usri1_flags = 0; - u1.usri1_script_path = NULL; - - return NetUserAdd(hostname, 1, (uint8_t *)&u1, &parm_err); -} - -static NET_API_STATUS test_netusermodals(struct libnetapi_ctx *ctx, - const char *hostname) -{ - NET_API_STATUS status; - struct USER_MODALS_INFO_0 *u0 = NULL; - struct USER_MODALS_INFO_0 *_u0 = NULL; - uint8_t *buffer = NULL; - uint32_t parm_err = 0; - uint32_t levels[] = { 0, 1, 2, 3 }; - int i = 0; - - for (i=0; i<ARRAY_SIZE(levels); i++) { - - printf("testing NetUserModalsGet level %d\n", levels[i]); - - status = NetUserModalsGet(hostname, levels[i], &buffer); - if (status) { - NETAPI_STATUS(ctx, status, "NetUserModalsGet"); - return status; - } - } - - status = NetUserModalsGet(hostname, 0, (uint8_t **)&u0); - if (status) { - NETAPI_STATUS(ctx, status, "NetUserModalsGet"); - return status; - } - - printf("testing NetUserModalsSet\n"); - - status = NetUserModalsSet(hostname, 0, (uint8_t *)u0, &parm_err); - if (status) { - NETAPI_STATUS(ctx, status, "NetUserModalsSet"); - return status; - } - - status = NetUserModalsGet(hostname, 0, (uint8_t **)&_u0); - if (status) { - NETAPI_STATUS(ctx, status, "NetUserModalsGet"); - return status; - } - - if (memcmp(u0, _u0, sizeof(u0) != 0)) { - printf("USER_MODALS_INFO_0 struct has changed!!!!\n"); - return -1; - } - - return 0; -} - -static NET_API_STATUS test_netusergetgroups(const char *hostname, - uint32_t level, - const char *username, - const char *groupname) -{ - NET_API_STATUS status; - uint32_t entries_read = 0; - uint32_t total_entries = 0; - const char *current_name; - int found_group = 0; - uint8_t *buffer = NULL; - int i; - - struct GROUP_USERS_INFO_0 *i0; - struct GROUP_USERS_INFO_1 *i1; - - printf("testing NetUserGetGroups level %d\n", level); - - do { - status = NetUserGetGroups(hostname, - username, - level, - &buffer, - 120, //(uint32_t)-1, - &entries_read, - &total_entries); - if (status == 0 || status == ERROR_MORE_DATA) { - switch (level) { - case 0: - i0 = (struct GROUP_USERS_INFO_0 *)buffer; - break; - case 1: - i1 = (struct GROUP_USERS_INFO_1 *)buffer; - break; - default: - return -1; - } - - for (i=0; i<entries_read; i++) { - - switch (level) { - case 0: - current_name = i0->grui0_name; - break; - case 1: - current_name = i1->grui1_name; - break; - default: - return -1; - } - - if (groupname && strcasecmp(current_name, groupname) == 0) { - found_group = 1; - } - - switch (level) { - case 0: - i0++; - break; - case 1: - i1++; - break; - default: - break; - } - } - NetApiBufferFree(buffer); - } - } while (status == ERROR_MORE_DATA); - - if (status) { - return status; - } - - if (groupname && !found_group) { - printf("failed to get membership\n"); - return -1; - } - - return 0; -} - -NET_API_STATUS netapitest_user(struct libnetapi_ctx *ctx, - const char *hostname) -{ - NET_API_STATUS status = 0; - const char *username, *username2; - uint8_t *buffer = NULL; - uint32_t levels[] = { 0, 1, 2, 3, 4, 10, 11, 20, 23 }; - uint32_t enum_levels[] = { 0, 1, 2, 3, 4, 10, 11, 20, 23 }; - uint32_t getgr_levels[] = { 0, 1 }; - int i; - - struct USER_INFO_1007 u1007; - uint32_t parm_err = 0; - - printf("NetUser tests\n"); - - username = "torture_test_user"; - username2 = "torture_test_user2"; - - /* cleanup */ - NetUserDel(hostname, username); - NetUserDel(hostname, username2); - - /* add a user */ - - status = test_netuseradd(hostname, username); - if (status) { - NETAPI_STATUS(ctx, status, "NetUserAdd"); - goto out; - } - - /* enum the new user */ - - for (i=0; i<ARRAY_SIZE(enum_levels); i++) { - - status = test_netuserenum(hostname, enum_levels[i], username); - if (status) { - NETAPI_STATUS(ctx, status, "NetUserEnum"); - goto out; - } - } - - /* basic queries */ - - for (i=0; i<ARRAY_SIZE(levels); i++) { - - printf("testing NetUserGetInfo level %d\n", levels[i]); - - status = NetUserGetInfo(hostname, username, levels[i], &buffer); - if (status && status != 124) { - NETAPI_STATUS(ctx, status, "NetUserGetInfo"); - goto out; - } - } - - /* testing getgroups */ - - for (i=0; i<ARRAY_SIZE(getgr_levels); i++) { - - status = test_netusergetgroups(hostname, getgr_levels[i], username, NULL); - if (status) { - NETAPI_STATUS(ctx, status, "NetUserGetGroups"); - goto out; - } - } - - /* modify description */ - - printf("testing NetUserSetInfo level %d\n", 1007); - - u1007.usri1007_comment = "NetApi modified user"; - - status = NetUserSetInfo(hostname, username, 1007, (uint8_t *)&u1007, &parm_err); - if (status) { - NETAPI_STATUS(ctx, status, "NetUserSetInfo"); - goto out; - } - - /* query info */ - - for (i=0; i<ARRAY_SIZE(levels); i++) { - status = NetUserGetInfo(hostname, username, levels[i], &buffer); - if (status && status != 124) { - NETAPI_STATUS(ctx, status, "NetUserGetInfo"); - goto out; - } - } - - /* delete */ - - printf("testing NetUserDel\n"); - - status = NetUserDel(hostname, username); - if (status) { - NETAPI_STATUS(ctx, status, "NetUserDel"); - goto out; - } - - /* should not exist anymore */ - - status = NetUserGetInfo(hostname, username, 0, &buffer); - if (status == 0) { - NETAPI_STATUS(ctx, status, "NetUserGetInfo"); - goto out; - } - - status = test_netusermodals(ctx, hostname); - if (status) { - goto out; - } - - status = 0; - - printf("NetUser tests succeeded\n"); - out: - if (status != 0) { - printf("NetUser testsuite failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } - - return status; -} diff --git a/source/lib/netapi/user.c b/source/lib/netapi/user.c index 7d0c47f331..05a051067a 100644 --- a/source/lib/netapi/user.c +++ b/source/lib/netapi/user.c @@ -27,283 +27,102 @@ /**************************************************************** ****************************************************************/ -static void convert_USER_INFO_X_to_samr_user_info21(struct USER_INFO_X *infoX, - struct samr_UserInfo21 *info21) +static void convert_USER_INFO_1_to_samr_user_info25(struct USER_INFO_1 *info1, + DATA_BLOB *user_session_key, + struct samr_UserInfo25 *info25) { - uint32_t fields_present = 0; + uint32_t fields_present = SAMR_FIELD_ACCT_FLAGS; struct samr_LogonHours zero_logon_hours; struct lsa_BinaryString zero_parameters; + uint32_t acct_flags = 0; NTTIME password_age; - ZERO_STRUCTP(info21); + ZERO_STRUCTP(info25); ZERO_STRUCT(zero_logon_hours); ZERO_STRUCT(zero_parameters); - if (infoX->usriX_flags) { - fields_present |= SAMR_FIELD_ACCT_FLAGS; - } - if (infoX->usriX_name) { - fields_present |= SAMR_FIELD_ACCOUNT_NAME; + if (info1->usri1_name) { + fields_present |= SAMR_FIELD_FULL_NAME; } - if (infoX->usriX_password) { + if (info1->usri1_password) { fields_present |= SAMR_FIELD_PASSWORD; } - if (infoX->usriX_flags) { + if (info1->usri1_flags) { fields_present |= SAMR_FIELD_ACCT_FLAGS; } - if (infoX->usriX_name) { + if (info1->usri1_name) { fields_present |= SAMR_FIELD_FULL_NAME; } - if (infoX->usriX_home_dir) { + if (info1->usri1_home_dir) { fields_present |= SAMR_FIELD_HOME_DIRECTORY; } - if (infoX->usriX_script_path) { + if (info1->usri1_script_path) { fields_present |= SAMR_FIELD_LOGON_SCRIPT; } - if (infoX->usriX_comment) { + if (info1->usri1_comment) { fields_present |= SAMR_FIELD_DESCRIPTION; } - if (infoX->usriX_password_age) { + if (info1->usri1_password_age) { fields_present |= SAMR_FIELD_FORCE_PWD_CHANGE; } - if (infoX->usriX_full_name) { - fields_present |= SAMR_FIELD_FULL_NAME; - } - if (infoX->usriX_usr_comment) { - fields_present |= SAMR_FIELD_COMMENT; - } - if (infoX->usriX_profile) { - fields_present |= SAMR_FIELD_PROFILE_PATH; - } - if (infoX->usriX_home_dir_drive) { - fields_present |= SAMR_FIELD_HOME_DRIVE; - } - if (infoX->usriX_primary_group_id) { - fields_present |= SAMR_FIELD_PRIMARY_GID; - } - if (infoX->usriX_country_code) { - fields_present |= SAMR_FIELD_COUNTRY_CODE; - } - if (infoX->usriX_workstations) { - fields_present |= SAMR_FIELD_WORKSTATIONS; - } - unix_to_nt_time_abs(&password_age, infoX->usriX_password_age); + acct_flags |= info1->usri1_flags | ACB_NORMAL; - /* TODO: infoX->usriX_priv */ - init_samr_user_info21(info21, + unix_to_nt_time_abs(&password_age, info1->usri1_password_age); + + /* TODO: info1->usri1_priv */ + init_samr_user_info21(&info25->info, 0, 0, 0, 0, 0, password_age, - infoX->usriX_name, - infoX->usriX_full_name, - infoX->usriX_home_dir, - infoX->usriX_home_dir_drive, - infoX->usriX_script_path, - infoX->usriX_profile, - infoX->usriX_comment, - infoX->usriX_workstations, - infoX->usriX_usr_comment, + NULL, + info1->usri1_name, + info1->usri1_home_dir, + NULL, + info1->usri1_script_path, + NULL, + info1->usri1_comment, + NULL, + NULL, &zero_parameters, 0, - infoX->usriX_primary_group_id, - infoX->usriX_flags, + 0, + acct_flags, fields_present, zero_logon_hours, 0, 0, - infoX->usriX_country_code, + 0, 0, 0, 0, 0); -} -/**************************************************************** -****************************************************************/ + if (info1->usri1_password) { + uchar pwbuf[532]; + struct MD5Context ctx; + uint8_t confounder[16]; + DATA_BLOB confounded_session_key = data_blob(NULL, 16); -static NTSTATUS construct_USER_INFO_X(uint32_t level, - uint8_t *buffer, - struct USER_INFO_X *uX) -{ - struct USER_INFO_0 *u0 = NULL; - struct USER_INFO_1 *u1 = NULL; - struct USER_INFO_2 *u2 = NULL; - struct USER_INFO_1003 *u1003 = NULL; - struct USER_INFO_1006 *u1006 = NULL; - struct USER_INFO_1007 *u1007 = NULL; - struct USER_INFO_1009 *u1009 = NULL; - struct USER_INFO_1011 *u1011 = NULL; - struct USER_INFO_1012 *u1012 = NULL; - struct USER_INFO_1014 *u1014 = NULL; - struct USER_INFO_1024 *u1024 = NULL; - struct USER_INFO_1051 *u1051 = NULL; - struct USER_INFO_1052 *u1052 = NULL; - struct USER_INFO_1053 *u1053 = NULL; - - if (!buffer || !uX) { - return NT_STATUS_INVALID_PARAMETER; - } - - ZERO_STRUCTP(uX); + encode_pw_buffer(pwbuf, info1->usri1_password, STR_UNICODE); - switch (level) { - case 0: - u0 = (struct USER_INFO_0 *)buffer; - uX->usriX_name = u0->usri0_name; - break; - case 1: - u1 = (struct USER_INFO_1 *)buffer; - uX->usriX_name = u1->usri1_name; - uX->usriX_password = u1->usri1_password; - uX->usriX_password_age = u1->usri1_password_age; - uX->usriX_priv = u1->usri1_priv; - uX->usriX_home_dir = u1->usri1_home_dir; - uX->usriX_comment = u1->usri1_comment; - uX->usriX_flags = u1->usri1_flags; - uX->usriX_script_path = u1->usri1_script_path; - break; - case 2: - u2 = (struct USER_INFO_2 *)buffer; - uX->usriX_name = u2->usri2_name; - uX->usriX_password = u2->usri2_password; - uX->usriX_password_age = u2->usri2_password_age; - uX->usriX_priv = u2->usri2_priv; - uX->usriX_home_dir = u2->usri2_home_dir; - uX->usriX_comment = u2->usri2_comment; - uX->usriX_flags = u2->usri2_flags; - uX->usriX_script_path = u2->usri2_script_path; - uX->usriX_auth_flags = u2->usri2_auth_flags; - uX->usriX_full_name = u2->usri2_full_name; - uX->usriX_usr_comment = u2->usri2_usr_comment; - uX->usriX_parms = u2->usri2_parms; - uX->usriX_workstations = u2->usri2_workstations; - uX->usriX_last_logon = u2->usri2_last_logon; - uX->usriX_last_logoff = u2->usri2_last_logoff; - uX->usriX_acct_expires = u2->usri2_acct_expires; - uX->usriX_max_storage = u2->usri2_max_storage; - uX->usriX_units_per_week= u2->usri2_units_per_week; - uX->usriX_logon_hours = u2->usri2_logon_hours; - uX->usriX_bad_pw_count = u2->usri2_bad_pw_count; - uX->usriX_num_logons = u2->usri2_num_logons; - uX->usriX_logon_server = u2->usri2_logon_server; - uX->usriX_country_code = u2->usri2_country_code; - uX->usriX_code_page = u2->usri2_code_page; - break; - case 1003: - u1003 = (struct USER_INFO_1003 *)buffer; - uX->usriX_password = u1003->usri1003_password; - break; - case 1006: - u1006 = (struct USER_INFO_1006 *)buffer; - uX->usriX_home_dir = u1006->usri1006_home_dir; - break; - case 1007: - u1007 = (struct USER_INFO_1007 *)buffer; - uX->usriX_comment = u1007->usri1007_comment; - break; - case 1009: - u1009 = (struct USER_INFO_1009 *)buffer; - uX->usriX_script_path = u1009->usri1009_script_path; - break; - case 1011: - u1011 = (struct USER_INFO_1011 *)buffer; - uX->usriX_full_name = u1011->usri1011_full_name; - break; - case 1012: - u1012 = (struct USER_INFO_1012 *)buffer; - uX->usriX_usr_comment = u1012->usri1012_usr_comment; - break; - case 1014: - u1014 = (struct USER_INFO_1014 *)buffer; - uX->usriX_workstations = u1014->usri1014_workstations; - break; - case 1024: - u1024 = (struct USER_INFO_1024 *)buffer; - uX->usriX_country_code = u1024->usri1024_country_code; - break; - case 1051: - u1051 = (struct USER_INFO_1051 *)buffer; - uX->usriX_primary_group_id = u1051->usri1051_primary_group_id; - break; - case 1052: - u1052 = (struct USER_INFO_1052 *)buffer; - uX->usriX_profile = u1052->usri1052_profile; - break; - case 1053: - u1053 = (struct USER_INFO_1053 *)buffer; - uX->usriX_home_dir_drive = u1053->usri1053_home_dir_drive; - break; - case 3: - case 4: - default: - return NT_STATUS_INVALID_INFO_CLASS; - } + generate_random_buffer((uint8_t *)confounder, 16); - return NT_STATUS_OK; -} + MD5Init(&ctx); + MD5Update(&ctx, confounder, 16); + MD5Update(&ctx, user_session_key->data, + user_session_key->length); + MD5Final(confounded_session_key.data, &ctx); -/**************************************************************** -****************************************************************/ + SamOEMhashBlob(pwbuf, 516, &confounded_session_key); + memcpy(&pwbuf[516], confounder, 16); -static NTSTATUS set_user_info_USER_INFO_X(TALLOC_CTX *ctx, - struct rpc_pipe_client *pipe_cli, - DATA_BLOB *session_key, - struct policy_handle *user_handle, - struct USER_INFO_X *uX) -{ - union samr_UserInfo user_info; - struct samr_UserInfo21 info21; - NTSTATUS status; - - if (!uX) { - return NT_STATUS_INVALID_PARAMETER; - } - - convert_USER_INFO_X_to_samr_user_info21(uX, &info21); - - ZERO_STRUCT(user_info); - - if (uX->usriX_password) { - - user_info.info25.info = info21; - - init_samr_CryptPasswordEx(uX->usriX_password, - session_key, - &user_info.info25.password); - - status = rpccli_samr_SetUserInfo2(pipe_cli, ctx, - user_handle, - 25, - &user_info); - - if (NT_STATUS_EQUAL(status, NT_STATUS(DCERPC_FAULT_INVALID_TAG))) { - - user_info.info23.info = info21; - - init_samr_CryptPassword(uX->usriX_password, - session_key, - &user_info.info23.password); - - status = rpccli_samr_SetUserInfo2(pipe_cli, ctx, - user_handle, - 23, - &user_info); - } - } else { - - user_info.info21 = info21; - - status = rpccli_samr_SetUserInfo(pipe_cli, ctx, - user_handle, - 21, - &user_info); + memcpy(info25->password.data, pwbuf, sizeof(pwbuf)); + data_blob_free(&confounded_session_key); } - - return status; } /**************************************************************** @@ -316,14 +135,21 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; + uint32_t resume_handle = 0; + uint32_t num_entries = 0; POLICY_HND connect_handle, domain_handle, user_handle; - struct lsa_String lsa_account_name; + struct samr_SamArray *sam = NULL; + const char *domain_name = NULL; + struct lsa_String lsa_domain_name, lsa_account_name; struct dom_sid2 *domain_sid = NULL; + struct samr_UserInfo25 info25; union samr_UserInfo *user_info = NULL; struct samr_PwInfo pw_info; uint32_t access_granted = 0; uint32_t rid = 0; - struct USER_INFO_X uX; + bool domain_found = true; + int i; + struct USER_INFO_1 *info1; ZERO_STRUCT(connect_handle); ZERO_STRUCT(domain_handle); @@ -335,6 +161,7 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, switch (r->in.level) { case 1: + info1 = (struct USER_INFO_1 *)r->in.buffer; break; case 2: case 3: @@ -344,34 +171,77 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); if (!W_ERROR_IS_OK(werr)) { goto done; } - status = construct_USER_INFO_X(r->in.level, r->in.buffer, &uX); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } - werr = libnetapi_samr_open_domain(ctx, pipe_cli, + status = rpccli_try_samr_connects(pipe_cli, ctx, SAMR_ACCESS_ENUM_DOMAINS | SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 | - SAMR_DOMAIN_ACCESS_CREATE_USER | - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_EnumDomains(pipe_cli, ctx, + &connect_handle, + &resume_handle, + &sam, + 0xffffffff, + &num_entries); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + for (i=0; i<num_entries; i++) { + + domain_name = sam->entries[i].name.string; + + if (strequal(domain_name, builtin_domain_name())) { + continue; + } + + domain_found = true; + break; + } + + if (!domain_found) { + werr = WERR_NO_SUCH_DOMAIN; + goto done; + } + + init_lsa_String(&lsa_domain_name, domain_name); + + status = rpccli_samr_LookupDomain(pipe_cli, ctx, &connect_handle, - &domain_handle, + &lsa_domain_name, &domain_sid); - if (!W_ERROR_IS_OK(werr)) { + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenDomain(pipe_cli, ctx, + &connect_handle, + SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 | + SAMR_DOMAIN_ACCESS_CREATE_USER | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + domain_sid, + &domain_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); goto done; } - init_lsa_String(&lsa_account_name, uX.usriX_name); + init_lsa_String(&lsa_account_name, info1->usri1_name); status = rpccli_samr_CreateUser2(pipe_cli, ctx, &domain_handle, @@ -412,12 +282,26 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, goto done; } - uX.usriX_flags |= ACB_NORMAL; + ZERO_STRUCTP(user_info); - status = set_user_info_USER_INFO_X(ctx, pipe_cli, - &cli->user_session_key, - &user_handle, - &uX); + convert_USER_INFO_1_to_samr_user_info25(info1, + &cli->user_session_key, + &info25); + + if (info1->usri1_password) { + user_info->info25 = info25; + status = rpccli_samr_SetUserInfo2(pipe_cli, ctx, + &user_handle, + 25, + user_info); + } else { + user_info->info21 = info25.info; + status = rpccli_samr_SetUserInfo(pipe_cli, ctx, + &user_handle, + 21, + user_info); + + } if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto failed; @@ -438,10 +322,11 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, if (is_valid_policy_hnd(&user_handle)) { rpccli_samr_Close(pipe_cli, ctx, &user_handle); } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); + if (is_valid_policy_hnd(&domain_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + } + if (is_valid_policy_hnd(&connect_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &connect_handle); } return werr; @@ -453,7 +338,12 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, WERROR NetUserAdd_l(struct libnetapi_ctx *ctx, struct NetUserAdd *r) { - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserAdd); + /* for now just talk to local RPC server */ + if (!r->in.server_name) { + r->in.server_name = "localhost"; + } + + return NetUserAdd_r(ctx, r); } /**************************************************************** @@ -466,34 +356,88 @@ WERROR NetUserDel_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; + uint32_t resume_handle = 0; + uint32_t num_entries = 0; POLICY_HND connect_handle, builtin_handle, domain_handle, user_handle; - struct lsa_String lsa_account_name; + struct samr_SamArray *sam = NULL; + const char *domain_name = NULL; + struct lsa_String lsa_domain_name, lsa_account_name; struct samr_Ids user_rids, name_types; struct dom_sid2 *domain_sid = NULL; struct dom_sid2 user_sid; + bool domain_found = true; + int i; ZERO_STRUCT(connect_handle); ZERO_STRUCT(builtin_handle); ZERO_STRUCT(domain_handle); ZERO_STRUCT(user_handle); - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } - werr = libnetapi_samr_open_domain(ctx, pipe_cli, + status = rpccli_try_samr_connects(pipe_cli, ctx, SAMR_ACCESS_ENUM_DOMAINS | SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_EnumDomains(pipe_cli, ctx, + &connect_handle, + &resume_handle, + &sam, + 0xffffffff, + &num_entries); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + for (i=0; i<num_entries; i++) { + + domain_name = sam->entries[i].name.string; + + if (strequal(domain_name, builtin_domain_name())) { + continue; + } + + domain_found = true; + break; + } + + if (!domain_found) { + werr = WERR_NO_SUCH_DOMAIN; + goto done; + } + + init_lsa_String(&lsa_domain_name, domain_name); + + status = rpccli_samr_LookupDomain(pipe_cli, ctx, &connect_handle, - &domain_handle, + &lsa_domain_name, &domain_sid); - if (!W_ERROR_IS_OK(werr)) { + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenDomain(pipe_cli, ctx, + &connect_handle, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + domain_sid, + &domain_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); goto done; } @@ -557,11 +501,14 @@ WERROR NetUserDel_r(struct libnetapi_ctx *ctx, if (is_valid_policy_hnd(&user_handle)) { rpccli_samr_Close(pipe_cli, ctx, &user_handle); } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); + if (is_valid_policy_hnd(&builtin_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); + } + if (is_valid_policy_hnd(&domain_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + } + if (is_valid_policy_hnd(&connect_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &connect_handle); } return werr; @@ -573,576 +520,46 @@ WERROR NetUserDel_r(struct libnetapi_ctx *ctx, WERROR NetUserDel_l(struct libnetapi_ctx *ctx, struct NetUserDel *r) { - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserDel); -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS libnetapi_samr_lookup_user(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *pipe_cli, - struct policy_handle *domain_handle, - struct policy_handle *builtin_handle, - const char *user_name, - const struct dom_sid *domain_sid, - uint32_t rid, - uint32_t level, - struct samr_UserInfo21 **info21, - struct sec_desc_buf **sec_desc, - uint32_t *auth_flag_p) -{ - NTSTATUS status; - - struct policy_handle user_handle; - union samr_UserInfo *user_info = NULL; - struct samr_RidWithAttributeArray *rid_array = NULL; - uint32_t access_mask = SEC_STD_READ_CONTROL | - SAMR_USER_ACCESS_GET_ATTRIBUTES | - SAMR_USER_ACCESS_GET_NAME_ETC; - - ZERO_STRUCT(user_handle); - - switch (level) { - case 0: - break; - case 1: - access_mask |= SAMR_USER_ACCESS_GET_LOGONINFO | - SAMR_USER_ACCESS_GET_GROUPS; - break; - case 2: - case 3: - case 4: - case 11: - access_mask |= SAMR_USER_ACCESS_GET_LOGONINFO | - SAMR_USER_ACCESS_GET_GROUPS | - SAMR_USER_ACCESS_GET_LOCALE; - break; - case 10: - case 20: - case 23: - break; - default: - return NT_STATUS_INVALID_LEVEL; - } - - if (level == 0) { - return NT_STATUS_OK; + /* for now just talk to local RPC server */ + if (!r->in.server_name) { + r->in.server_name = "localhost"; } - status = rpccli_samr_OpenUser(pipe_cli, mem_ctx, - domain_handle, - access_mask, - rid, - &user_handle); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - - status = rpccli_samr_QueryUserInfo(pipe_cli, mem_ctx, - &user_handle, - 21, - &user_info); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - - status = rpccli_samr_QuerySecurity(pipe_cli, mem_ctx, - &user_handle, - SECINFO_DACL, - sec_desc); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - - if (access_mask & SAMR_USER_ACCESS_GET_GROUPS) { - - struct lsa_SidArray sid_array; - struct samr_Ids alias_rids; - int i; - uint32_t auth_flag = 0; - struct dom_sid sid; - - status = rpccli_samr_GetGroupsForUser(pipe_cli, mem_ctx, - &user_handle, - &rid_array); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - - sid_array.num_sids = rid_array->count + 1; - sid_array.sids = talloc_array(mem_ctx, struct lsa_SidPtr, - sid_array.num_sids); - NT_STATUS_HAVE_NO_MEMORY(sid_array.sids); - - for (i=0; i<rid_array->count; i++) { - sid_compose(&sid, domain_sid, rid_array->rids[i].rid); - sid_array.sids[i].sid = sid_dup_talloc(mem_ctx, &sid); - NT_STATUS_HAVE_NO_MEMORY(sid_array.sids[i].sid); - } - - sid_compose(&sid, domain_sid, rid); - sid_array.sids[i].sid = sid_dup_talloc(mem_ctx, &sid); - NT_STATUS_HAVE_NO_MEMORY(sid_array.sids[i].sid); - - status = rpccli_samr_GetAliasMembership(pipe_cli, mem_ctx, - builtin_handle, - &sid_array, - &alias_rids); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - - for (i=0; i<alias_rids.count; i++) { - switch (alias_rids.ids[i]) { - case 550: /* Print Operators */ - auth_flag |= AF_OP_PRINT; - break; - case 549: /* Server Operators */ - auth_flag |= AF_OP_SERVER; - break; - case 548: /* Account Operators */ - auth_flag |= AF_OP_ACCOUNTS; - break; - default: - break; - } - } - - if (auth_flag_p) { - *auth_flag_p = auth_flag; - } - } - - *info21 = &user_info->info21; - - done: - if (is_valid_policy_hnd(&user_handle)) { - rpccli_samr_Close(pipe_cli, mem_ctx, &user_handle); - } - - return status; -} - -/**************************************************************** -****************************************************************/ - -static uint32_t samr_rid_to_priv_level(uint32_t rid) -{ - switch (rid) { - case DOMAIN_RID_ADMINISTRATOR: - return USER_PRIV_ADMIN; - case DOMAIN_RID_GUEST: - return USER_PRIV_GUEST; - default: - return USER_PRIV_USER; - } -} - -/**************************************************************** -****************************************************************/ - -static uint32_t samr_acb_flags_to_netapi_flags(uint32_t acb) -{ - uint32_t fl = UF_SCRIPT; /* god knows why */ - - fl |= ads_acb2uf(acb); - - return fl; + return NetUserDel_r(ctx, r); } /**************************************************************** ****************************************************************/ -static NTSTATUS info21_to_USER_INFO_1(TALLOC_CTX *mem_ctx, - const struct samr_UserInfo21 *i21, - struct USER_INFO_1 *i) +static WERROR convert_samr_samarray_to_USER_INFO_buffer(TALLOC_CTX *mem_ctx, + struct samr_SamArray *sam_array, + uint32_t level, + uint8_t **buffer) { - ZERO_STRUCTP(i); - i->usri1_name = talloc_strdup(mem_ctx, i21->account_name.string); - NT_STATUS_HAVE_NO_MEMORY(i->usri1_name); - i->usri1_password = NULL; - i->usri1_password_age = time(NULL) - nt_time_to_unix(i21->last_password_change); - i->usri1_priv = samr_rid_to_priv_level(i21->rid); - i->usri1_home_dir = talloc_strdup(mem_ctx, i21->home_directory.string); - i->usri1_comment = talloc_strdup(mem_ctx, i21->description.string); - i->usri1_flags = samr_acb_flags_to_netapi_flags(i21->acct_flags); - i->usri1_script_path = talloc_strdup(mem_ctx, i21->logon_script.string); - - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS info21_to_USER_INFO_2(TALLOC_CTX *mem_ctx, - const struct samr_UserInfo21 *i21, - uint32_t auth_flag, - struct USER_INFO_2 *i) -{ - ZERO_STRUCTP(i); - - i->usri2_name = talloc_strdup(mem_ctx, i21->account_name.string); - NT_STATUS_HAVE_NO_MEMORY(i->usri2_name); - i->usri2_password = NULL; - i->usri2_password_age = time(NULL) - nt_time_to_unix(i21->last_password_change); - i->usri2_priv = samr_rid_to_priv_level(i21->rid); - i->usri2_home_dir = talloc_strdup(mem_ctx, i21->home_directory.string); - i->usri2_comment = talloc_strdup(mem_ctx, i21->description.string); - i->usri2_flags = samr_acb_flags_to_netapi_flags(i21->acct_flags); - i->usri2_script_path = talloc_strdup(mem_ctx, i21->logon_script.string); - i->usri2_auth_flags = auth_flag; - i->usri2_full_name = talloc_strdup(mem_ctx, i21->full_name.string); - i->usri2_usr_comment = talloc_strdup(mem_ctx, i21->comment.string); - i->usri2_parms = talloc_strndup(mem_ctx, (const char *)i21->parameters.array, i21->parameters.size/2); - i->usri2_workstations = talloc_strdup(mem_ctx, i21->workstations.string); - i->usri2_last_logon = nt_time_to_unix(i21->last_logon); - i->usri2_last_logoff = nt_time_to_unix(i21->last_logoff); - i->usri2_acct_expires = nt_time_to_unix(i21->acct_expiry); - i->usri2_max_storage = USER_MAXSTORAGE_UNLIMITED; /* FIXME */ - i->usri2_units_per_week = i21->logon_hours.units_per_week; - i->usri2_logon_hours = (uint8_t *)talloc_memdup(mem_ctx, i21->logon_hours.bits, 21); - i->usri2_bad_pw_count = i21->bad_password_count; - i->usri2_num_logons = i21->logon_count; - i->usri2_logon_server = talloc_strdup(mem_ctx, "\\\\*"); - i->usri2_country_code = i21->country_code; - i->usri2_code_page = i21->code_page; - - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS info21_to_USER_INFO_3(TALLOC_CTX *mem_ctx, - const struct samr_UserInfo21 *i21, - uint32_t auth_flag, - struct USER_INFO_3 *i) -{ - ZERO_STRUCTP(i); - - i->usri3_name = talloc_strdup(mem_ctx, i21->account_name.string); - NT_STATUS_HAVE_NO_MEMORY(i->usri3_name); - i->usri3_password_age = time(NULL) - nt_time_to_unix(i21->last_password_change); - i->usri3_priv = samr_rid_to_priv_level(i21->rid); - i->usri3_home_dir = talloc_strdup(mem_ctx, i21->home_directory.string); - i->usri3_comment = talloc_strdup(mem_ctx, i21->description.string); - i->usri3_flags = samr_acb_flags_to_netapi_flags(i21->acct_flags); - i->usri3_script_path = talloc_strdup(mem_ctx, i21->logon_script.string); - i->usri3_auth_flags = auth_flag; - i->usri3_full_name = talloc_strdup(mem_ctx, i21->full_name.string); - i->usri3_usr_comment = talloc_strdup(mem_ctx, i21->comment.string); - i->usri3_parms = talloc_strndup(mem_ctx, (const char *)i21->parameters.array, i21->parameters.size/2); - i->usri3_workstations = talloc_strdup(mem_ctx, i21->workstations.string); - i->usri3_last_logon = nt_time_to_unix(i21->last_logon); - i->usri3_last_logoff = nt_time_to_unix(i21->last_logoff); - i->usri3_acct_expires = nt_time_to_unix(i21->acct_expiry); - i->usri3_max_storage = USER_MAXSTORAGE_UNLIMITED; /* FIXME */ - i->usri3_units_per_week = i21->logon_hours.units_per_week; - i->usri3_logon_hours = (uint8_t *)talloc_memdup(mem_ctx, i21->logon_hours.bits, 21); - i->usri3_bad_pw_count = i21->bad_password_count; - i->usri3_num_logons = i21->logon_count; - i->usri3_logon_server = talloc_strdup(mem_ctx, "\\\\*"); - i->usri3_country_code = i21->country_code; - i->usri3_code_page = i21->code_page; - i->usri3_user_id = i21->rid; - i->usri3_primary_group_id = i21->primary_gid; - i->usri3_profile = talloc_strdup(mem_ctx, i21->profile_path.string); - i->usri3_home_dir_drive = talloc_strdup(mem_ctx, i21->home_drive.string); - i->usri3_password_expired = i21->password_expired; - - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS info21_to_USER_INFO_4(TALLOC_CTX *mem_ctx, - const struct samr_UserInfo21 *i21, - uint32_t auth_flag, - struct dom_sid *domain_sid, - struct USER_INFO_4 *i) -{ - struct dom_sid sid; - - ZERO_STRUCTP(i); - - i->usri4_name = talloc_strdup(mem_ctx, i21->account_name.string); - NT_STATUS_HAVE_NO_MEMORY(i->usri4_name); - i->usri4_password_age = time(NULL) - nt_time_to_unix(i21->last_password_change); - i->usri4_password = NULL; - i->usri4_priv = samr_rid_to_priv_level(i21->rid); - i->usri4_home_dir = talloc_strdup(mem_ctx, i21->home_directory.string); - i->usri4_comment = talloc_strdup(mem_ctx, i21->description.string); - i->usri4_flags = samr_acb_flags_to_netapi_flags(i21->acct_flags); - i->usri4_script_path = talloc_strdup(mem_ctx, i21->logon_script.string); - i->usri4_auth_flags = auth_flag; - i->usri4_full_name = talloc_strdup(mem_ctx, i21->full_name.string); - i->usri4_usr_comment = talloc_strdup(mem_ctx, i21->comment.string); - i->usri4_parms = talloc_strndup(mem_ctx, (const char *)i21->parameters.array, i21->parameters.size/2); - i->usri4_workstations = talloc_strdup(mem_ctx, i21->workstations.string); - i->usri4_last_logon = nt_time_to_unix(i21->last_logon); - i->usri4_last_logoff = nt_time_to_unix(i21->last_logoff); - i->usri4_acct_expires = nt_time_to_unix(i21->acct_expiry); - i->usri4_max_storage = USER_MAXSTORAGE_UNLIMITED; /* FIXME */ - i->usri4_units_per_week = i21->logon_hours.units_per_week; - i->usri4_logon_hours = (uint8_t *)talloc_memdup(mem_ctx, i21->logon_hours.bits, 21); - i->usri4_bad_pw_count = i21->bad_password_count; - i->usri4_num_logons = i21->logon_count; - i->usri4_logon_server = talloc_strdup(mem_ctx, "\\\\*"); - i->usri4_country_code = i21->country_code; - i->usri4_code_page = i21->code_page; - if (!sid_compose(&sid, domain_sid, i21->rid)) { - return NT_STATUS_NO_MEMORY; - } - i->usri4_user_sid = (struct domsid *)sid_dup_talloc(mem_ctx, &sid); - i->usri4_primary_group_id = i21->primary_gid; - i->usri4_profile = talloc_strdup(mem_ctx, i21->profile_path.string); - i->usri4_home_dir_drive = talloc_strdup(mem_ctx, i21->home_drive.string); - i->usri4_password_expired = i21->password_expired; - - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS info21_to_USER_INFO_10(TALLOC_CTX *mem_ctx, - const struct samr_UserInfo21 *i21, - struct USER_INFO_10 *i) -{ - ZERO_STRUCTP(i); - - i->usri10_name = talloc_strdup(mem_ctx, i21->account_name.string); - NT_STATUS_HAVE_NO_MEMORY(i->usri10_name); - i->usri10_comment = talloc_strdup(mem_ctx, i21->description.string); - i->usri10_full_name = talloc_strdup(mem_ctx, i21->full_name.string); - i->usri10_usr_comment = talloc_strdup(mem_ctx, i21->comment.string); - - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS info21_to_USER_INFO_11(TALLOC_CTX *mem_ctx, - const struct samr_UserInfo21 *i21, - uint32_t auth_flag, - struct USER_INFO_11 *i) -{ - ZERO_STRUCTP(i); - - i->usri11_name = talloc_strdup(mem_ctx, i21->account_name.string); - NT_STATUS_HAVE_NO_MEMORY(i->usri11_name); - i->usri11_comment = talloc_strdup(mem_ctx, i21->description.string); - i->usri11_usr_comment = talloc_strdup(mem_ctx, i21->comment.string); - i->usri11_full_name = talloc_strdup(mem_ctx, i21->full_name.string); - i->usri11_priv = samr_rid_to_priv_level(i21->rid); - i->usri11_auth_flags = auth_flag; - i->usri11_password_age = time(NULL) - nt_time_to_unix(i21->last_password_change); - i->usri11_home_dir = talloc_strdup(mem_ctx, i21->home_directory.string); - i->usri11_parms = talloc_strndup(mem_ctx, (const char *)i21->parameters.array, i21->parameters.size/2); - i->usri11_last_logon = nt_time_to_unix(i21->last_logon); - i->usri11_last_logoff = nt_time_to_unix(i21->last_logoff); - i->usri11_bad_pw_count = i21->bad_password_count; - i->usri11_num_logons = i21->logon_count; - i->usri11_logon_server = talloc_strdup(mem_ctx, "\\\\*"); - i->usri11_country_code = i21->country_code; - i->usri11_workstations = talloc_strdup(mem_ctx, i21->workstations.string); - i->usri11_max_storage = USER_MAXSTORAGE_UNLIMITED; /* FIXME */ - i->usri11_units_per_week = i21->logon_hours.units_per_week; - i->usri11_logon_hours = (uint8_t *)talloc_memdup(mem_ctx, i21->logon_hours.bits, 21); - i->usri11_code_page = i21->code_page; - - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS info21_to_USER_INFO_20(TALLOC_CTX *mem_ctx, - const struct samr_UserInfo21 *i21, - struct USER_INFO_20 *i) -{ - ZERO_STRUCTP(i); - - i->usri20_name = talloc_strdup(mem_ctx, i21->account_name.string); - NT_STATUS_HAVE_NO_MEMORY(i->usri20_name); - i->usri20_comment = talloc_strdup(mem_ctx, i21->description.string); - i->usri20_full_name = talloc_strdup(mem_ctx, i21->full_name.string); - i->usri20_flags = samr_acb_flags_to_netapi_flags(i21->acct_flags); - i->usri20_user_id = i21->rid; - - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS info21_to_USER_INFO_23(TALLOC_CTX *mem_ctx, - const struct samr_UserInfo21 *i21, - struct dom_sid *domain_sid, - struct USER_INFO_23 *i) -{ - struct dom_sid sid; - - ZERO_STRUCTP(i); - - i->usri23_name = talloc_strdup(mem_ctx, i21->account_name.string); - NT_STATUS_HAVE_NO_MEMORY(i->usri23_name); - i->usri23_comment = talloc_strdup(mem_ctx, i21->description.string); - i->usri23_full_name = talloc_strdup(mem_ctx, i21->full_name.string); - i->usri23_flags = samr_acb_flags_to_netapi_flags(i21->acct_flags); - if (!sid_compose(&sid, domain_sid, i21->rid)) { - return NT_STATUS_NO_MEMORY; - } - i->usri23_user_sid = (struct domsid *)sid_dup_talloc(mem_ctx, &sid); - - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *pipe_cli, - struct dom_sid *domain_sid, - struct policy_handle *domain_handle, - struct policy_handle *builtin_handle, - const char *user_name, - uint32_t rid, - uint32_t level, - uint8_t **buffer, - uint32_t *num_entries) -{ - NTSTATUS status; - - struct samr_UserInfo21 *info21 = NULL; - struct sec_desc_buf *sec_desc = NULL; - uint32_t auth_flag = 0; - - struct USER_INFO_0 info0; - struct USER_INFO_1 info1; - struct USER_INFO_2 info2; - struct USER_INFO_3 info3; - struct USER_INFO_4 info4; - struct USER_INFO_10 info10; - struct USER_INFO_11 info11; - struct USER_INFO_20 info20; - struct USER_INFO_23 info23; - - switch (level) { - case 0: - case 1: - case 2: - case 3: - case 4: - case 10: - case 11: - case 20: - case 23: - break; - default: - return NT_STATUS_INVALID_LEVEL; - } - - if (level == 0) { - info0.usri0_name = talloc_strdup(mem_ctx, user_name); - NT_STATUS_HAVE_NO_MEMORY(info0.usri0_name); - - ADD_TO_ARRAY(mem_ctx, struct USER_INFO_0, info0, - (struct USER_INFO_0 **)buffer, num_entries); - - return NT_STATUS_OK; - } - - status = libnetapi_samr_lookup_user(mem_ctx, pipe_cli, - domain_handle, - builtin_handle, - user_name, - domain_sid, - rid, - level, - &info21, - &sec_desc, - &auth_flag); - - if (!NT_STATUS_IS_OK(status)) { - goto done; - } + struct USER_INFO_0 *info0 = NULL; + int i; switch (level) { case 0: - /* already returned above */ - break; - case 1: - status = info21_to_USER_INFO_1(mem_ctx, info21, &info1); - NT_STATUS_NOT_OK_RETURN(status); - - ADD_TO_ARRAY(mem_ctx, struct USER_INFO_1, info1, - (struct USER_INFO_1 **)buffer, num_entries); - - break; - case 2: - status = info21_to_USER_INFO_2(mem_ctx, info21, auth_flag, &info2); - NT_STATUS_NOT_OK_RETURN(status); - - ADD_TO_ARRAY(mem_ctx, struct USER_INFO_2, info2, - (struct USER_INFO_2 **)buffer, num_entries); - - break; - case 3: - status = info21_to_USER_INFO_3(mem_ctx, info21, auth_flag, &info3); - NT_STATUS_NOT_OK_RETURN(status); - - ADD_TO_ARRAY(mem_ctx, struct USER_INFO_3, info3, - (struct USER_INFO_3 **)buffer, num_entries); - - break; - case 4: - status = info21_to_USER_INFO_4(mem_ctx, info21, auth_flag, domain_sid, &info4); - NT_STATUS_NOT_OK_RETURN(status); - - ADD_TO_ARRAY(mem_ctx, struct USER_INFO_4, info4, - (struct USER_INFO_4 **)buffer, num_entries); - - break; - case 10: - status = info21_to_USER_INFO_10(mem_ctx, info21, &info10); - NT_STATUS_NOT_OK_RETURN(status); - - ADD_TO_ARRAY(mem_ctx, struct USER_INFO_10, info10, - (struct USER_INFO_10 **)buffer, num_entries); - - break; - case 11: - status = info21_to_USER_INFO_11(mem_ctx, info21, auth_flag, &info11); - NT_STATUS_NOT_OK_RETURN(status); - - ADD_TO_ARRAY(mem_ctx, struct USER_INFO_11, info11, - (struct USER_INFO_11 **)buffer, num_entries); - - break; - case 20: - status = info21_to_USER_INFO_20(mem_ctx, info21, &info20); - NT_STATUS_NOT_OK_RETURN(status); - - ADD_TO_ARRAY(mem_ctx, struct USER_INFO_20, info20, - (struct USER_INFO_20 **)buffer, num_entries); - - break; - case 23: - status = info21_to_USER_INFO_23(mem_ctx, info21, domain_sid, &info23); - NT_STATUS_NOT_OK_RETURN(status); + info0 = TALLOC_ZERO_ARRAY(mem_ctx, struct USER_INFO_0, + sam_array->count); + W_ERROR_HAVE_NO_MEMORY(info0); + + for (i=0; i<sam_array->count; i++) { + info0[i].usri0_name = talloc_strdup(mem_ctx, + sam_array->entries[i].name.string); + W_ERROR_HAVE_NO_MEMORY(info0[i].usri0_name); + } - ADD_TO_ARRAY(mem_ctx, struct USER_INFO_23, info23, - (struct USER_INFO_23 **)buffer, num_entries); + *buffer = (uint8_t *)talloc_memdup(mem_ctx, info0, + sizeof(struct USER_INFO_0) * sam_array->count); + W_ERROR_HAVE_NO_MEMORY(*buffer); break; default: - return NT_STATUS_INVALID_LEVEL; + return WERR_NOT_SUPPORTED; } - done: - return status; + return WERR_OK; } /**************************************************************** @@ -1155,137 +572,133 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; struct policy_handle connect_handle; struct dom_sid2 *domain_sid = NULL; - struct policy_handle domain_handle, builtin_handle; + struct policy_handle domain_handle; struct samr_SamArray *sam = NULL; - uint32_t filter = ACB_NORMAL; + uint32_t num_entries = 0; int i; - uint32_t entries_read = 0; + const char *domain_name = NULL; + bool domain_found = true; + uint32_t dom_resume_handle = 0; + struct lsa_String lsa_domain_name; - NTSTATUS status = NT_STATUS_OK; + NTSTATUS status; WERROR werr; ZERO_STRUCT(connect_handle); ZERO_STRUCT(domain_handle); - ZERO_STRUCT(builtin_handle); - - if (!r->out.buffer) { - return WERR_INVALID_PARAM; - } - - *r->out.buffer = NULL; - *r->out.entries_read = 0; switch (r->in.level) { case 0: + break; case 1: case 2: case 3: - case 4: case 10: case 11: case 20: case 23: - break; default: - return WERR_UNKNOWN_LEVEL; + return WERR_NOT_SUPPORTED; } - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); if (!W_ERROR_IS_OK(werr)) { goto done; } - werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT | - SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS, - &connect_handle, - &builtin_handle); + werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 | - SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS | - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + status = rpccli_try_samr_connects(pipe_cli, ctx, + SAMR_ACCESS_OPEN_DOMAIN | + SAMR_ACCESS_ENUM_DOMAINS, + &connect_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_EnumDomains(pipe_cli, ctx, + &connect_handle, + &dom_resume_handle, + &sam, + 0xffffffff, + &num_entries); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + for (i=0; i<num_entries; i++) { + + domain_name = sam->entries[i].name.string; + + if (strequal(domain_name, builtin_domain_name())) { + continue; + } + + domain_found = true; + break; + } + + if (!domain_found) { + werr = WERR_NO_SUCH_DOMAIN; + goto done; + } + + init_lsa_String(&lsa_domain_name, domain_name); + + status = rpccli_samr_LookupDomain(pipe_cli, ctx, &connect_handle, - &domain_handle, + &lsa_domain_name, &domain_sid); - if (!W_ERROR_IS_OK(werr)) { + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); goto done; } - switch (r->in.filter) { - case FILTER_NORMAL_ACCOUNT: - filter = ACB_NORMAL; - break; - case FILTER_TEMP_DUPLICATE_ACCOUNT: - filter = ACB_TEMPDUP; - break; - case FILTER_INTERDOMAIN_TRUST_ACCOUNT: - filter = ACB_DOMTRUST; - break; - case FILTER_WORKSTATION_TRUST_ACCOUNT: - filter = ACB_WSTRUST; - break; - case FILTER_SERVER_TRUST_ACCOUNT: - filter = ACB_SVRTRUST; - break; - default: - break; + status = rpccli_samr_OpenDomain(pipe_cli, + ctx, + &connect_handle, + SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 | + SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + domain_sid, + &domain_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; } status = rpccli_samr_EnumDomainUsers(pipe_cli, ctx, &domain_handle, r->in.resume_handle, - filter, + r->in.filter, &sam, r->in.prefmaxlen, - &entries_read); - werr = ntstatus_to_werror(status); - if (NT_STATUS_IS_ERR(status)) { + r->out.entries_read); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); goto done; } - for (i=0; i < sam->count; i++) { - - status = libnetapi_samr_lookup_user_map_USER_INFO(ctx, pipe_cli, - domain_sid, - &domain_handle, - &builtin_handle, - sam->entries[i].name.string, - sam->entries[i].idx, - r->in.level, - r->out.buffer, - r->out.entries_read); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - } + werr = convert_samr_samarray_to_USER_INFO_buffer(ctx, sam, + r->in.level, + r->out.buffer); done: if (!cli) { return werr; } - /* if last query */ - if (NT_STATUS_IS_OK(status) || - NT_STATUS_IS_ERR(status)) { - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } + if (is_valid_policy_hnd(&domain_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + } + if (is_valid_policy_hnd(&connect_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &connect_handle); } return werr; @@ -1297,7 +710,7 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, WERROR NetUserEnum_l(struct libnetapi_ctx *ctx, struct NetUserEnum *r) { - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserEnum); + return WERR_NOT_SUPPORTED; } /**************************************************************** @@ -1432,11 +845,11 @@ static WERROR convert_samr_dispinfo_to_NET_DISPLAY_GROUP(TALLOC_CTX *mem_ctx, /**************************************************************** ****************************************************************/ -static WERROR convert_samr_dispinfo_to_NET_DISPLAY(TALLOC_CTX *mem_ctx, - union samr_DispInfo *info, - uint32_t level, - uint32_t *entries_read, - void **buffer) +WERROR convert_samr_dispinfo_to_NET_DISPLAY(TALLOC_CTX *mem_ctx, + union samr_DispInfo *info, + uint32_t level, + uint32_t *entries_read, + void **buffer) { switch (level) { case 1: @@ -1473,1968 +886,143 @@ WERROR NetQueryDisplayInformation_r(struct libnetapi_ctx *ctx, struct dom_sid2 *domain_sid = NULL; struct policy_handle domain_handle; union samr_DispInfo info; + struct samr_SamArray *sam = NULL; + uint32_t num_entries = 0; + int i; + const char *domain_name = NULL; + bool domain_found = true; + uint32_t dom_resume_handle = 0; + struct lsa_String lsa_domain_name; uint32_t total_size = 0; uint32_t returned_size = 0; - NTSTATUS status = NT_STATUS_OK; - WERROR werr; - - ZERO_STRUCT(connect_handle); - ZERO_STRUCT(domain_handle); - - switch (r->in.level) { - case 1: - case 2: - case 3: - break; - default: - return WERR_UNKNOWN_LEVEL; - } - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 | - SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS | - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - status = rpccli_samr_QueryDisplayInfo2(pipe_cli, - ctx, - &domain_handle, - r->in.level, - r->in.idx, - r->in.entries_requested, - r->in.prefmaxlen, - &total_size, - &returned_size, - &info); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - werr = convert_samr_dispinfo_to_NET_DISPLAY(ctx, &info, - r->in.level, - r->out.entries_read, - r->out.buffer); - done: - if (!cli) { - return werr; - } - - /* if last query */ - if (NT_STATUS_IS_OK(status) || - NT_STATUS_IS_ERR(status)) { - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } - } - - return werr; - -} - -/**************************************************************** -****************************************************************/ - - -WERROR NetQueryDisplayInformation_l(struct libnetapi_ctx *ctx, - struct NetQueryDisplayInformation *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetQueryDisplayInformation); -} - -/**************************************************************** -****************************************************************/ - -WERROR NetUserChangePassword_r(struct libnetapi_ctx *ctx, - struct NetUserChangePassword *r) -{ - return WERR_NOT_SUPPORTED; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetUserChangePassword_l(struct libnetapi_ctx *ctx, - struct NetUserChangePassword *r) -{ - return WERR_NOT_SUPPORTED; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetUserGetInfo_r(struct libnetapi_ctx *ctx, - struct NetUserGetInfo *r) -{ - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - struct policy_handle connect_handle, domain_handle, builtin_handle, user_handle; - struct lsa_String lsa_account_name; - struct dom_sid2 *domain_sid = NULL; - struct samr_Ids user_rids, name_types; - uint32_t num_entries = 0; - ZERO_STRUCT(connect_handle); ZERO_STRUCT(domain_handle); - ZERO_STRUCT(builtin_handle); - ZERO_STRUCT(user_handle); - - if (!r->out.buffer) { - return WERR_INVALID_PARAM; - } switch (r->in.level) { - case 0: case 1: case 2: case 3: - case 4: - case 10: - case 11: - case 20: - case 23: - break; - default: - werr = WERR_UNKNOWN_LEVEL; - goto done; - } - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT | - SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS, - &connect_handle, - &builtin_handle); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - init_lsa_String(&lsa_account_name, r->in.user_name); - - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &domain_handle, - 1, - &lsa_account_name, - &user_rids, - &name_types); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = libnetapi_samr_lookup_user_map_USER_INFO(ctx, pipe_cli, - domain_sid, - &domain_handle, - &builtin_handle, - r->in.user_name, - user_rids.ids[0], - r->in.level, - r->out.buffer, - &num_entries); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - done: - if (!cli) { - return werr; - } - - if (is_valid_policy_hnd(&user_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &user_handle); - } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetUserGetInfo_l(struct libnetapi_ctx *ctx, - struct NetUserGetInfo *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserGetInfo); -} - -/**************************************************************** -****************************************************************/ - -WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, - struct NetUserSetInfo *r) -{ - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - NTSTATUS status; - WERROR werr; - - struct policy_handle connect_handle, domain_handle, builtin_handle, user_handle; - struct lsa_String lsa_account_name; - struct dom_sid2 *domain_sid = NULL; - struct samr_Ids user_rids, name_types; - uint32_t user_mask = 0; - - struct USER_INFO_X uX; - - ZERO_STRUCT(connect_handle); - ZERO_STRUCT(domain_handle); - ZERO_STRUCT(builtin_handle); - ZERO_STRUCT(user_handle); - - if (!r->in.buffer) { - return WERR_INVALID_PARAM; - } - - switch (r->in.level) { - case 0: - case 1003: - user_mask = SAMR_USER_ACCESS_SET_PASSWORD; - break; - case 1006: - case 1007: - case 1009: - case 1011: - case 1014: - case 1052: - case 1053: - user_mask = SAMR_USER_ACCESS_SET_ATTRIBUTES; - break; - case 1012: - case 1024: - user_mask = SAMR_USER_ACCESS_SET_LOC_COM; - case 1051: - user_mask = SAMR_USER_ACCESS_SET_ATTRIBUTES | - SAMR_USER_ACCESS_GET_GROUPS; - break; - case 1: - case 2: - case 3: - case 4: - case 21: - case 22: - case 1005: - case 1008: - case 1010: - case 1017: - case 1020: - werr = WERR_NOT_SUPPORTED; - goto done; - default: - werr = WERR_UNKNOWN_LEVEL; - goto done; - } - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 | - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT | - SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS, - &connect_handle, - &builtin_handle); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - init_lsa_String(&lsa_account_name, r->in.user_name); - - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &domain_handle, - 1, - &lsa_account_name, - &user_rids, - &name_types); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_OpenUser(pipe_cli, ctx, - &domain_handle, - user_mask, - user_rids.ids[0], - &user_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = construct_USER_INFO_X(r->in.level, r->in.buffer, &uX); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = set_user_info_USER_INFO_X(ctx, pipe_cli, - &cli->user_session_key, - &user_handle, - &uX); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - werr = WERR_OK; - - done: - if (!cli) { - return werr; - } - - if (is_valid_policy_hnd(&user_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &user_handle); - } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetUserSetInfo_l(struct libnetapi_ctx *ctx, - struct NetUserSetInfo *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserSetInfo); -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS query_USER_MODALS_INFO_rpc(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *pipe_cli, - struct policy_handle *domain_handle, - struct samr_DomInfo1 *info1, - struct samr_DomInfo3 *info3, - struct samr_DomInfo5 *info5, - struct samr_DomInfo6 *info6, - struct samr_DomInfo7 *info7, - struct samr_DomInfo12 *info12) -{ - NTSTATUS status; - union samr_DomainInfo *dom_info = NULL; - - if (info1) { - status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx, - domain_handle, - 1, - &dom_info); - NT_STATUS_NOT_OK_RETURN(status); - - *info1 = dom_info->info1; - } - - if (info3) { - status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx, - domain_handle, - 3, - &dom_info); - NT_STATUS_NOT_OK_RETURN(status); - - *info3 = dom_info->info3; - } - - if (info5) { - status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx, - domain_handle, - 5, - &dom_info); - NT_STATUS_NOT_OK_RETURN(status); - - *info5 = dom_info->info5; - } - - if (info6) { - status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx, - domain_handle, - 6, - &dom_info); - NT_STATUS_NOT_OK_RETURN(status); - - *info6 = dom_info->info6; - } - - if (info7) { - status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx, - domain_handle, - 7, - &dom_info); - NT_STATUS_NOT_OK_RETURN(status); - - *info7 = dom_info->info7; - } - - if (info12) { - status = rpccli_samr_QueryDomainInfo2(pipe_cli, mem_ctx, - domain_handle, - 12, - &dom_info); - NT_STATUS_NOT_OK_RETURN(status); - - *info12 = dom_info->info12; - } - - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS query_USER_MODALS_INFO_0(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *pipe_cli, - struct policy_handle *domain_handle, - struct USER_MODALS_INFO_0 *info0) -{ - NTSTATUS status; - struct samr_DomInfo1 dom_info1; - struct samr_DomInfo3 dom_info3; - - ZERO_STRUCTP(info0); - - status = query_USER_MODALS_INFO_rpc(mem_ctx, - pipe_cli, - domain_handle, - &dom_info1, - &dom_info3, - NULL, - NULL, - NULL, - NULL); - NT_STATUS_NOT_OK_RETURN(status); - - info0->usrmod0_min_passwd_len = - dom_info1.min_password_length; - info0->usrmod0_max_passwd_age = - nt_time_to_unix_abs((NTTIME *)&dom_info1.max_password_age); - info0->usrmod0_min_passwd_age = - nt_time_to_unix_abs((NTTIME *)&dom_info1.min_password_age); - info0->usrmod0_password_hist_len = - dom_info1.password_history_length; - - info0->usrmod0_force_logoff = - nt_time_to_unix_abs(&dom_info3.force_logoff_time); - - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS query_USER_MODALS_INFO_1(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *pipe_cli, - struct policy_handle *domain_handle, - struct USER_MODALS_INFO_1 *info1) -{ - NTSTATUS status; - struct samr_DomInfo6 dom_info6; - struct samr_DomInfo7 dom_info7; - - status = query_USER_MODALS_INFO_rpc(mem_ctx, - pipe_cli, - domain_handle, - NULL, - NULL, - NULL, - &dom_info6, - &dom_info7, - NULL); - NT_STATUS_NOT_OK_RETURN(status); - - info1->usrmod1_primary = - talloc_strdup(mem_ctx, dom_info6.primary.string); - - info1->usrmod1_role = dom_info7.role; - - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS query_USER_MODALS_INFO_2(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *pipe_cli, - struct policy_handle *domain_handle, - struct dom_sid *domain_sid, - struct USER_MODALS_INFO_2 *info2) -{ - NTSTATUS status; - struct samr_DomInfo5 dom_info5; - - status = query_USER_MODALS_INFO_rpc(mem_ctx, - pipe_cli, - domain_handle, - NULL, - NULL, - &dom_info5, - NULL, - NULL, - NULL); - NT_STATUS_NOT_OK_RETURN(status); - - info2->usrmod2_domain_name = - talloc_strdup(mem_ctx, dom_info5.domain_name.string); - info2->usrmod2_domain_id = - (struct domsid *)sid_dup_talloc(mem_ctx, domain_sid); - - NT_STATUS_HAVE_NO_MEMORY(info2->usrmod2_domain_name); - NT_STATUS_HAVE_NO_MEMORY(info2->usrmod2_domain_id); - - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS query_USER_MODALS_INFO_3(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *pipe_cli, - struct policy_handle *domain_handle, - struct USER_MODALS_INFO_3 *info3) -{ - NTSTATUS status; - struct samr_DomInfo12 dom_info12; - - status = query_USER_MODALS_INFO_rpc(mem_ctx, - pipe_cli, - domain_handle, - NULL, - NULL, - NULL, - NULL, - NULL, - &dom_info12); - NT_STATUS_NOT_OK_RETURN(status); - - info3->usrmod3_lockout_duration = - nt_time_to_unix_abs(&dom_info12.lockout_duration); - info3->usrmod3_lockout_observation_window = - nt_time_to_unix_abs(&dom_info12.lockout_window); - info3->usrmod3_lockout_threshold = - dom_info12.lockout_threshold; - - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS query_USER_MODALS_INFO_to_buffer(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *pipe_cli, - uint32_t level, - struct policy_handle *domain_handle, - struct dom_sid *domain_sid, - uint8_t **buffer) -{ - NTSTATUS status; - - struct USER_MODALS_INFO_0 info0; - struct USER_MODALS_INFO_1 info1; - struct USER_MODALS_INFO_2 info2; - struct USER_MODALS_INFO_3 info3; - - if (!buffer) { - return ERROR_INSUFFICIENT_BUFFER; - } - - switch (level) { - case 0: - status = query_USER_MODALS_INFO_0(mem_ctx, - pipe_cli, - domain_handle, - &info0); - NT_STATUS_NOT_OK_RETURN(status); - - *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info0, - sizeof(info0)); - break; - - case 1: - status = query_USER_MODALS_INFO_1(mem_ctx, - pipe_cli, - domain_handle, - &info1); - NT_STATUS_NOT_OK_RETURN(status); - - *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info1, - sizeof(info1)); - break; - case 2: - status = query_USER_MODALS_INFO_2(mem_ctx, - pipe_cli, - domain_handle, - domain_sid, - &info2); - NT_STATUS_NOT_OK_RETURN(status); - - *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info2, - sizeof(info2)); - break; - case 3: - status = query_USER_MODALS_INFO_3(mem_ctx, - pipe_cli, - domain_handle, - &info3); - NT_STATUS_NOT_OK_RETURN(status); - - *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info3, - sizeof(info3)); - break; - default: - break; - } - - NT_STATUS_HAVE_NO_MEMORY(*buffer); - - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetUserModalsGet_r(struct libnetapi_ctx *ctx, - struct NetUserModalsGet *r) -{ - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - NTSTATUS status; - WERROR werr; - - struct policy_handle connect_handle, domain_handle; - struct dom_sid2 *domain_sid = NULL; - uint32_t access_mask = SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT; - - ZERO_STRUCT(connect_handle); - ZERO_STRUCT(domain_handle); - - if (!r->out.buffer) { - return WERR_INVALID_PARAM; - } - - switch (r->in.level) { - case 0: - access_mask |= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 | - SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2; - break; - case 1: - case 2: - access_mask |= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2; - break; - case 3: - access_mask |= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1; - break; - default: - werr = WERR_UNKNOWN_LEVEL; - goto done; - } - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - access_mask, - &connect_handle, - &domain_handle, - &domain_sid); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - /* 0: 1 + 3 */ - /* 1: 6 + 7 */ - /* 2: 5 */ - /* 3: 12 (DomainInfo2) */ - - status = query_USER_MODALS_INFO_to_buffer(ctx, - pipe_cli, - r->in.level, - &domain_handle, - domain_sid, - r->out.buffer); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - done: - if (!cli) { - return werr; - } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetUserModalsGet_l(struct libnetapi_ctx *ctx, - struct NetUserModalsGet *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserModalsGet); -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS set_USER_MODALS_INFO_rpc(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *pipe_cli, - struct policy_handle *domain_handle, - struct samr_DomInfo1 *info1, - struct samr_DomInfo3 *info3, - struct samr_DomInfo12 *info12) -{ - NTSTATUS status; - union samr_DomainInfo dom_info; - - if (info1) { - - ZERO_STRUCT(dom_info); - - dom_info.info1 = *info1; - - status = rpccli_samr_SetDomainInfo(pipe_cli, mem_ctx, - domain_handle, - 1, - &dom_info); - NT_STATUS_NOT_OK_RETURN(status); - } - - if (info3) { - - ZERO_STRUCT(dom_info); - - dom_info.info3 = *info3; - - status = rpccli_samr_SetDomainInfo(pipe_cli, mem_ctx, - domain_handle, - 3, - &dom_info); - - NT_STATUS_NOT_OK_RETURN(status); - } - - if (info12) { - - ZERO_STRUCT(dom_info); - - dom_info.info12 = *info12; - - status = rpccli_samr_SetDomainInfo(pipe_cli, mem_ctx, - domain_handle, - 12, - &dom_info); - - NT_STATUS_NOT_OK_RETURN(status); - } - - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS set_USER_MODALS_INFO_0_buffer(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *pipe_cli, - struct policy_handle *domain_handle, - struct USER_MODALS_INFO_0 *info0) -{ - NTSTATUS status; - struct samr_DomInfo1 dom_info_1; - struct samr_DomInfo3 dom_info_3; - - status = query_USER_MODALS_INFO_rpc(mem_ctx, - pipe_cli, - domain_handle, - &dom_info_1, - &dom_info_3, - NULL, - NULL, - NULL, - NULL); - NT_STATUS_NOT_OK_RETURN(status); - - dom_info_1.min_password_length = - info0->usrmod0_min_passwd_len; - dom_info_1.password_history_length = - info0->usrmod0_password_hist_len; - - unix_to_nt_time_abs((NTTIME *)&dom_info_1.max_password_age, - info0->usrmod0_max_passwd_age); - unix_to_nt_time_abs((NTTIME *)&dom_info_1.min_password_age, - info0->usrmod0_min_passwd_age); - - unix_to_nt_time_abs(&dom_info_3.force_logoff_time, - info0->usrmod0_force_logoff); - - return set_USER_MODALS_INFO_rpc(mem_ctx, - pipe_cli, - domain_handle, - &dom_info_1, - &dom_info_3, - NULL); -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS set_USER_MODALS_INFO_3_buffer(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *pipe_cli, - struct policy_handle *domain_handle, - struct USER_MODALS_INFO_3 *info3) -{ - NTSTATUS status; - struct samr_DomInfo12 dom_info_12; - - status = query_USER_MODALS_INFO_rpc(mem_ctx, - pipe_cli, - domain_handle, - NULL, - NULL, - NULL, - NULL, - NULL, - &dom_info_12); - NT_STATUS_NOT_OK_RETURN(status); - - unix_to_nt_time_abs((NTTIME *)&dom_info_12.lockout_duration, - info3->usrmod3_lockout_duration); - unix_to_nt_time_abs((NTTIME *)&dom_info_12.lockout_window, - info3->usrmod3_lockout_observation_window); - dom_info_12.lockout_threshold = info3->usrmod3_lockout_threshold; - - return set_USER_MODALS_INFO_rpc(mem_ctx, - pipe_cli, - domain_handle, - NULL, - NULL, - &dom_info_12); -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS set_USER_MODALS_INFO_1001_buffer(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *pipe_cli, - struct policy_handle *domain_handle, - struct USER_MODALS_INFO_1001 *info1001) -{ - NTSTATUS status; - struct samr_DomInfo1 dom_info_1; - - status = query_USER_MODALS_INFO_rpc(mem_ctx, - pipe_cli, - domain_handle, - &dom_info_1, - NULL, - NULL, - NULL, - NULL, - NULL); - NT_STATUS_NOT_OK_RETURN(status); - - dom_info_1.min_password_length = - info1001->usrmod1001_min_passwd_len; - - return set_USER_MODALS_INFO_rpc(mem_ctx, - pipe_cli, - domain_handle, - &dom_info_1, - NULL, - NULL); -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS set_USER_MODALS_INFO_1002_buffer(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *pipe_cli, - struct policy_handle *domain_handle, - struct USER_MODALS_INFO_1002 *info1002) -{ - NTSTATUS status; - struct samr_DomInfo1 dom_info_1; - - status = query_USER_MODALS_INFO_rpc(mem_ctx, - pipe_cli, - domain_handle, - &dom_info_1, - NULL, - NULL, - NULL, - NULL, - NULL); - NT_STATUS_NOT_OK_RETURN(status); - - unix_to_nt_time_abs((NTTIME *)&dom_info_1.max_password_age, - info1002->usrmod1002_max_passwd_age); - - return set_USER_MODALS_INFO_rpc(mem_ctx, - pipe_cli, - domain_handle, - &dom_info_1, - NULL, - NULL); -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS set_USER_MODALS_INFO_1003_buffer(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *pipe_cli, - struct policy_handle *domain_handle, - struct USER_MODALS_INFO_1003 *info1003) -{ - NTSTATUS status; - struct samr_DomInfo1 dom_info_1; - - status = query_USER_MODALS_INFO_rpc(mem_ctx, - pipe_cli, - domain_handle, - &dom_info_1, - NULL, - NULL, - NULL, - NULL, - NULL); - NT_STATUS_NOT_OK_RETURN(status); - - unix_to_nt_time_abs((NTTIME *)&dom_info_1.min_password_age, - info1003->usrmod1003_min_passwd_age); - - return set_USER_MODALS_INFO_rpc(mem_ctx, - pipe_cli, - domain_handle, - &dom_info_1, - NULL, - NULL); -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS set_USER_MODALS_INFO_1004_buffer(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *pipe_cli, - struct policy_handle *domain_handle, - struct USER_MODALS_INFO_1004 *info1004) -{ - NTSTATUS status; - struct samr_DomInfo3 dom_info_3; - - status = query_USER_MODALS_INFO_rpc(mem_ctx, - pipe_cli, - domain_handle, - NULL, - &dom_info_3, - NULL, - NULL, - NULL, - NULL); - NT_STATUS_NOT_OK_RETURN(status); - - unix_to_nt_time_abs(&dom_info_3.force_logoff_time, - info1004->usrmod1004_force_logoff); - - return set_USER_MODALS_INFO_rpc(mem_ctx, - pipe_cli, - domain_handle, - NULL, - &dom_info_3, - NULL); -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS set_USER_MODALS_INFO_1005_buffer(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *pipe_cli, - struct policy_handle *domain_handle, - struct USER_MODALS_INFO_1005 *info1005) -{ - NTSTATUS status; - struct samr_DomInfo1 dom_info_1; - - status = query_USER_MODALS_INFO_rpc(mem_ctx, - pipe_cli, - domain_handle, - &dom_info_1, - NULL, - NULL, - NULL, - NULL, - NULL); - NT_STATUS_NOT_OK_RETURN(status); - - dom_info_1.password_history_length = - info1005->usrmod1005_password_hist_len; - - return set_USER_MODALS_INFO_rpc(mem_ctx, - pipe_cli, - domain_handle, - &dom_info_1, - NULL, - NULL); -} - -/**************************************************************** -****************************************************************/ - -static NTSTATUS set_USER_MODALS_INFO_buffer(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *pipe_cli, - uint32_t level, - struct policy_handle *domain_handle, - struct dom_sid *domain_sid, - uint8_t *buffer) -{ - struct USER_MODALS_INFO_0 *info0; - struct USER_MODALS_INFO_3 *info3; - struct USER_MODALS_INFO_1001 *info1001; - struct USER_MODALS_INFO_1002 *info1002; - struct USER_MODALS_INFO_1003 *info1003; - struct USER_MODALS_INFO_1004 *info1004; - struct USER_MODALS_INFO_1005 *info1005; - - if (!buffer) { - return ERROR_INSUFFICIENT_BUFFER; - } - - switch (level) { - case 0: - info0 = (struct USER_MODALS_INFO_0 *)buffer; - return set_USER_MODALS_INFO_0_buffer(mem_ctx, - pipe_cli, - domain_handle, - info0); - case 3: - info3 = (struct USER_MODALS_INFO_3 *)buffer; - return set_USER_MODALS_INFO_3_buffer(mem_ctx, - pipe_cli, - domain_handle, - info3); - case 1001: - info1001 = (struct USER_MODALS_INFO_1001 *)buffer; - return set_USER_MODALS_INFO_1001_buffer(mem_ctx, - pipe_cli, - domain_handle, - info1001); - case 1002: - info1002 = (struct USER_MODALS_INFO_1002 *)buffer; - return set_USER_MODALS_INFO_1002_buffer(mem_ctx, - pipe_cli, - domain_handle, - info1002); - case 1003: - info1003 = (struct USER_MODALS_INFO_1003 *)buffer; - return set_USER_MODALS_INFO_1003_buffer(mem_ctx, - pipe_cli, - domain_handle, - info1003); - case 1004: - info1004 = (struct USER_MODALS_INFO_1004 *)buffer; - return set_USER_MODALS_INFO_1004_buffer(mem_ctx, - pipe_cli, - domain_handle, - info1004); - case 1005: - info1005 = (struct USER_MODALS_INFO_1005 *)buffer; - return set_USER_MODALS_INFO_1005_buffer(mem_ctx, - pipe_cli, - domain_handle, - info1005); - - default: - break; - } - - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetUserModalsSet_r(struct libnetapi_ctx *ctx, - struct NetUserModalsSet *r) -{ - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - NTSTATUS status; - WERROR werr; - - struct policy_handle connect_handle, domain_handle; - struct dom_sid2 *domain_sid = NULL; - uint32_t access_mask = SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT; - - ZERO_STRUCT(connect_handle); - ZERO_STRUCT(domain_handle); - - if (!r->in.buffer) { - return WERR_INVALID_PARAM; - } - - switch (r->in.level) { - case 0: - access_mask |= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 | - SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 | - SAMR_DOMAIN_ACCESS_SET_INFO_1 | - SAMR_DOMAIN_ACCESS_SET_INFO_2; - break; - case 3: - case 1001: - case 1002: - case 1003: - case 1005: - access_mask |= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 | - SAMR_DOMAIN_ACCESS_SET_INFO_1; - break; - case 1004: - access_mask |= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 | - SAMR_DOMAIN_ACCESS_SET_INFO_2; - break; - case 1: - case 2: - case 1006: - case 1007: - werr = WERR_NOT_SUPPORTED; - break; - default: - werr = WERR_UNKNOWN_LEVEL; - goto done; - } - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - access_mask, - &connect_handle, - &domain_handle, - &domain_sid); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - status = set_USER_MODALS_INFO_buffer(ctx, - pipe_cli, - r->in.level, - &domain_handle, - domain_sid, - r->in.buffer); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - done: - if (!cli) { - return werr; - } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetUserModalsSet_l(struct libnetapi_ctx *ctx, - struct NetUserModalsSet *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserModalsSet); -} - -/**************************************************************** -****************************************************************/ - -NTSTATUS add_GROUP_USERS_INFO_X_buffer(TALLOC_CTX *mem_ctx, - uint32_t level, - const char *group_name, - uint32_t attributes, - uint8_t **buffer, - uint32_t *num_entries) -{ - struct GROUP_USERS_INFO_0 u0; - struct GROUP_USERS_INFO_1 u1; - - switch (level) { - case 0: - u0.grui0_name = talloc_strdup(mem_ctx, group_name); - NT_STATUS_HAVE_NO_MEMORY(u0.grui0_name); - - ADD_TO_ARRAY(mem_ctx, struct GROUP_USERS_INFO_0, u0, - (struct GROUP_USERS_INFO_0 **)buffer, num_entries); - break; - case 1: - u1.grui1_name = talloc_strdup(mem_ctx, group_name); - NT_STATUS_HAVE_NO_MEMORY(u1.grui1_name); - - u1.grui1_attributes = attributes; - - ADD_TO_ARRAY(mem_ctx, struct GROUP_USERS_INFO_1, u1, - (struct GROUP_USERS_INFO_1 **)buffer, num_entries); - break; - default: - return NT_STATUS_INVALID_INFO_CLASS; - } - - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetUserGetGroups_r(struct libnetapi_ctx *ctx, - struct NetUserGetGroups *r) -{ - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - struct policy_handle connect_handle, domain_handle, user_handle; - struct lsa_String lsa_account_name; - struct dom_sid2 *domain_sid = NULL; - struct samr_Ids user_rids, name_types; - struct samr_RidWithAttributeArray *rid_array = NULL; - struct lsa_Strings names; - struct samr_Ids types; - uint32_t *rids = NULL; - - int i; - uint32_t entries_read = 0; - - NTSTATUS status = NT_STATUS_OK; - WERROR werr; - - ZERO_STRUCT(connect_handle); - ZERO_STRUCT(domain_handle); - - if (!r->out.buffer) { - return WERR_INVALID_PARAM; - } - - *r->out.buffer = NULL; - *r->out.entries_read = 0; - - switch (r->in.level) { - case 0: - case 1: break; default: return WERR_UNKNOWN_LEVEL; } - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); if (!W_ERROR_IS_OK(werr)) { goto done; } - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); + werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } - init_lsa_String(&lsa_account_name, r->in.user_name); - - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &domain_handle, - 1, - &lsa_account_name, - &user_rids, - &name_types); + status = rpccli_try_samr_connects(pipe_cli, ctx, + SAMR_ACCESS_OPEN_DOMAIN | + SAMR_ACCESS_ENUM_DOMAINS, + &connect_handle); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto done; } - status = rpccli_samr_OpenUser(pipe_cli, ctx, - &domain_handle, - SAMR_USER_ACCESS_GET_GROUPS, - user_rids.ids[0], - &user_handle); + status = rpccli_samr_EnumDomains(pipe_cli, ctx, + &connect_handle, + &dom_resume_handle, + &sam, + 0xffffffff, + &num_entries); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto done; } - status = rpccli_samr_GetGroupsForUser(pipe_cli, ctx, - &user_handle, - &rid_array); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } + for (i=0; i<num_entries; i++) { - rids = talloc_array(ctx, uint32_t, rid_array->count); - if (!rids) { - werr = WERR_NOMEM; - goto done; - } - - for (i=0; i < rid_array->count; i++) { - rids[i] = rid_array->rids[i].rid; - } - - status = rpccli_samr_LookupRids(pipe_cli, ctx, - &domain_handle, - rid_array->count, - rids, - &names, - &types); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } + domain_name = sam->entries[i].name.string; - for (i=0; i < rid_array->count; i++) { - status = add_GROUP_USERS_INFO_X_buffer(ctx, - r->in.level, - names.names[i].string, - rid_array->rids[i].attributes, - r->out.buffer, - &entries_read); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; + if (strequal(domain_name, builtin_domain_name())) { + continue; } - } - - if (r->out.entries_read) { - *r->out.entries_read = entries_read; - } - if (r->out.total_entries) { - *r->out.total_entries = entries_read; - } - - done: - if (!cli) { - return werr; - } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetUserGetGroups_l(struct libnetapi_ctx *ctx, - struct NetUserGetGroups *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserGetGroups); -} - -/**************************************************************** -****************************************************************/ - -WERROR NetUserSetGroups_r(struct libnetapi_ctx *ctx, - struct NetUserSetGroups *r) -{ - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - struct policy_handle connect_handle, domain_handle, user_handle, group_handle; - struct lsa_String lsa_account_name; - struct dom_sid2 *domain_sid = NULL; - struct samr_Ids user_rids, name_types; - struct samr_Ids group_rids; - struct samr_RidWithAttributeArray *rid_array = NULL; - struct lsa_String *lsa_names = NULL; - - uint32_t *add_rids = NULL; - uint32_t *del_rids = NULL; - size_t num_add_rids = 0; - size_t num_del_rids = 0; - - uint32_t *member_rids = NULL; - size_t num_member_rids = 0; - - struct GROUP_USERS_INFO_0 *i0 = NULL; - struct GROUP_USERS_INFO_1 *i1 = NULL; - int i, k; - - NTSTATUS status = NT_STATUS_OK; - WERROR werr; - - ZERO_STRUCT(connect_handle); - ZERO_STRUCT(domain_handle); - - if (!r->in.buffer) { - return WERR_INVALID_PARAM; + domain_found = true; + break; } - switch (r->in.level) { - case 0: - case 1: - break; - default: - return WERR_UNKNOWN_LEVEL; - } - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { + if (!domain_found) { + werr = WERR_NO_SUCH_DOMAIN; goto done; } - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + init_lsa_String(&lsa_domain_name, domain_name); + + status = rpccli_samr_LookupDomain(pipe_cli, ctx, &connect_handle, - &domain_handle, + &lsa_domain_name, &domain_sid); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - init_lsa_String(&lsa_account_name, r->in.user_name); - - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &domain_handle, - 1, - &lsa_account_name, - &user_rids, - &name_types); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto done; } - status = rpccli_samr_OpenUser(pipe_cli, ctx, - &domain_handle, - SAMR_USER_ACCESS_GET_GROUPS, - user_rids.ids[0], - &user_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - switch (r->in.level) { - case 0: - i0 = (struct GROUP_USERS_INFO_0 *)r->in.buffer; - break; - case 1: - i1 = (struct GROUP_USERS_INFO_1 *)r->in.buffer; - break; - } - - lsa_names = talloc_array(ctx, struct lsa_String, r->in.num_entries); - if (!lsa_names) { - werr = WERR_NOMEM; - goto done; - } - - for (i=0; i < r->in.num_entries; i++) { - - switch (r->in.level) { - case 0: - init_lsa_String(&lsa_names[i], i0->grui0_name); - i0++; - break; - case 1: - init_lsa_String(&lsa_names[i], i1->grui1_name); - i1++; - break; - } - } - - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &domain_handle, - r->in.num_entries, - lsa_names, - &group_rids, - &name_types); + status = rpccli_samr_OpenDomain(pipe_cli, + ctx, + &connect_handle, + SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + domain_sid, + &domain_handle); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto done; } - member_rids = group_rids.ids; - num_member_rids = group_rids.count; - - status = rpccli_samr_GetGroupsForUser(pipe_cli, ctx, - &user_handle, - &rid_array); + status = rpccli_samr_QueryDisplayInfo2(pipe_cli, + ctx, + &domain_handle, + r->in.level, + r->in.idx, + r->in.entries_requested, + r->in.prefmaxlen, + &total_size, + &returned_size, + &info); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto done; } - /* add list */ - - for (i=0; i < r->in.num_entries; i++) { - bool already_member = false; - for (k=0; k < rid_array->count; k++) { - if (member_rids[i] == rid_array->rids[k].rid) { - already_member = true; - break; - } - } - if (!already_member) { - if (!add_rid_to_array_unique(ctx, - member_rids[i], - &add_rids, &num_add_rids)) { - werr = WERR_GENERAL_FAILURE; - goto done; - } - } - } - - /* del list */ - - for (k=0; k < rid_array->count; k++) { - bool keep_member = false; - for (i=0; i < r->in.num_entries; i++) { - if (member_rids[i] == rid_array->rids[k].rid) { - keep_member = true; - break; - } - } - if (!keep_member) { - if (!add_rid_to_array_unique(ctx, - rid_array->rids[k].rid, - &del_rids, &num_del_rids)) { - werr = WERR_GENERAL_FAILURE; - goto done; - } - } - } - - /* add list */ - - for (i=0; i < num_add_rids; i++) { - status = rpccli_samr_OpenGroup(pipe_cli, ctx, - &domain_handle, - SAMR_GROUP_ACCESS_ADD_MEMBER, - add_rids[i], - &group_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_AddGroupMember(pipe_cli, ctx, - &group_handle, - user_rids.ids[0], - 7 /* ? */); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - if (is_valid_policy_hnd(&group_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &group_handle); - } - } - - /* del list */ - - for (i=0; i < num_del_rids; i++) { - status = rpccli_samr_OpenGroup(pipe_cli, ctx, - &domain_handle, - SAMR_GROUP_ACCESS_REMOVE_MEMBER, - del_rids[i], - &group_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_DeleteGroupMember(pipe_cli, ctx, - &group_handle, - user_rids.ids[0]); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - if (is_valid_policy_hnd(&group_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &group_handle); - } - } - - werr = WERR_OK; - + werr = convert_samr_dispinfo_to_NET_DISPLAY(ctx, &info, + r->in.level, + r->out.entries_read, + r->out.buffer); done: if (!cli) { return werr; } - if (is_valid_policy_hnd(&group_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &group_handle); + if (is_valid_policy_hnd(&domain_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); + if (is_valid_policy_hnd(&connect_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &connect_handle); } return werr; -} -/**************************************************************** -****************************************************************/ - -WERROR NetUserSetGroups_l(struct libnetapi_ctx *ctx, - struct NetUserSetGroups *r) -{ - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserSetGroups); } /**************************************************************** ****************************************************************/ -static NTSTATUS add_LOCALGROUP_USERS_INFO_X_buffer(TALLOC_CTX *mem_ctx, - uint32_t level, - const char *group_name, - uint8_t **buffer, - uint32_t *num_entries) -{ - struct LOCALGROUP_USERS_INFO_0 u0; - - switch (level) { - case 0: - u0.lgrui0_name = talloc_strdup(mem_ctx, group_name); - NT_STATUS_HAVE_NO_MEMORY(u0.lgrui0_name); - - ADD_TO_ARRAY(mem_ctx, struct LOCALGROUP_USERS_INFO_0, u0, - (struct LOCALGROUP_USERS_INFO_0 **)buffer, num_entries); - break; - default: - return NT_STATUS_INVALID_INFO_CLASS; - } - return NT_STATUS_OK; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetUserGetLocalGroups_r(struct libnetapi_ctx *ctx, - struct NetUserGetLocalGroups *r) -{ - struct cli_state *cli = NULL; - struct rpc_pipe_client *pipe_cli = NULL; - struct policy_handle connect_handle, domain_handle, user_handle, - builtin_handle; - struct lsa_String lsa_account_name; - struct dom_sid2 *domain_sid = NULL; - struct samr_Ids user_rids, name_types; - struct samr_RidWithAttributeArray *rid_array = NULL; - struct lsa_Strings names; - struct samr_Ids types; - uint32_t *rids = NULL; - size_t num_rids = 0; - struct dom_sid user_sid; - struct lsa_SidArray sid_array; - struct samr_Ids domain_rids; - struct samr_Ids builtin_rids; - - int i; - uint32_t entries_read = 0; - - NTSTATUS status = NT_STATUS_OK; - WERROR werr; - - ZERO_STRUCT(connect_handle); - ZERO_STRUCT(domain_handle); - - if (!r->out.buffer) { - return WERR_INVALID_PARAM; - } - - *r->out.buffer = NULL; - *r->out.entries_read = 0; - - switch (r->in.level) { - case 0: - case 1: - break; - default: - return WERR_UNKNOWN_LEVEL; - } - - werr = libnetapi_open_pipe(ctx, r->in.server_name, - &ndr_table_samr.syntax_id, - &cli, - &pipe_cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT | - SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS, - &connect_handle, - &domain_handle, - &domain_sid); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT | - SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS, - &connect_handle, - &builtin_handle); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - init_lsa_String(&lsa_account_name, r->in.user_name); - - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &domain_handle, - 1, - &lsa_account_name, - &user_rids, - &name_types); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_OpenUser(pipe_cli, ctx, - &domain_handle, - SAMR_USER_ACCESS_GET_GROUPS, - user_rids.ids[0], - &user_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_GetGroupsForUser(pipe_cli, ctx, - &user_handle, - &rid_array); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - if (!sid_compose(&user_sid, domain_sid, user_rids.ids[0])) { - werr = WERR_NOMEM; - goto done; - } - - sid_array.num_sids = rid_array->count + 1; - sid_array.sids = TALLOC_ARRAY(ctx, struct lsa_SidPtr, sid_array.num_sids); - if (!sid_array.sids) { - werr = WERR_NOMEM; - goto done; - } - - sid_array.sids[0].sid = sid_dup_talloc(ctx, &user_sid); - if (!sid_array.sids[0].sid) { - werr = WERR_NOMEM; - goto done; - } - - for (i=0; i < rid_array->count; i++) { - struct dom_sid sid; - - if (!sid_compose(&sid, domain_sid, rid_array->rids[i].rid)) { - werr = WERR_NOMEM; - goto done; - } - - sid_array.sids[i+1].sid = sid_dup_talloc(ctx, &sid); - if (!sid_array.sids[i+1].sid) { - werr = WERR_NOMEM; - goto done; - } - } - - status = rpccli_samr_GetAliasMembership(pipe_cli, ctx, - &domain_handle, - &sid_array, - &domain_rids); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - for (i=0; i < domain_rids.count; i++) { - if (!add_rid_to_array_unique(ctx, domain_rids.ids[i], - &rids, &num_rids)) { - werr = WERR_NOMEM; - goto done; - } - } - - status = rpccli_samr_GetAliasMembership(pipe_cli, ctx, - &builtin_handle, - &sid_array, - &builtin_rids); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - for (i=0; i < builtin_rids.count; i++) { - if (!add_rid_to_array_unique(ctx, builtin_rids.ids[i], - &rids, &num_rids)) { - werr = WERR_NOMEM; - goto done; - } - } - - status = rpccli_samr_LookupRids(pipe_cli, ctx, - &builtin_handle, - num_rids, - rids, - &names, - &types); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - for (i=0; i < names.count; i++) { - status = add_LOCALGROUP_USERS_INFO_X_buffer(ctx, - r->in.level, - names.names[i].string, - r->out.buffer, - &entries_read); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - } - - if (r->out.entries_read) { - *r->out.entries_read = entries_read; - } - if (r->out.total_entries) { - *r->out.total_entries = entries_read; - } - - done: - if (!cli) { - return werr; - } - - if (ctx->disable_policy_handle_cache) { - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); - } - - return werr; -} - -/**************************************************************** -****************************************************************/ - -WERROR NetUserGetLocalGroups_l(struct libnetapi_ctx *ctx, - struct NetUserGetLocalGroups *r) +WERROR NetQueryDisplayInformation_l(struct libnetapi_ctx *ctx, + struct NetQueryDisplayInformation *r) { - LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserGetLocalGroups); + return WERR_NOT_SUPPORTED; } diff --git a/source/lib/popt_common.c b/source/lib/popt_common.c index 8ceac26bf2..25e41ab5f3 100644 --- a/source/lib/popt_common.c +++ b/source/lib/popt_common.c @@ -171,12 +171,6 @@ struct poptOption popt_common_version[] = { POPT_TABLEEND }; -struct poptOption popt_common_debuglevel[] = { - { NULL, 0, POPT_ARG_CALLBACK, (void *)popt_common_callback }, - { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Set debug level", "DEBUGLEVEL" }, - POPT_TABLEEND -}; - /* Handle command line options: * --sbindir @@ -184,7 +178,6 @@ struct poptOption popt_common_debuglevel[] = { * --swatdir * --lmhostsfile * --libdir - * --modulesdir * --shlibext * --lockdir * --piddir @@ -198,7 +191,6 @@ enum dyn_item{ DYN_SWATDIR, DYN_LMHOSTSFILE, DYN_LIBDIR, - DYN_MODULESDIR, DYN_SHLIBEXT, DYN_LOCKDIR, DYN_PIDDIR, @@ -244,12 +236,6 @@ static void popt_dynconfig_callback(poptContext con, } break; - case DYN_MODULESDIR: - if (arg) { - set_dyn_MODULESDIR(arg); - } - break; - case DYN_SHLIBEXT: if (arg) { set_dyn_SHLIBEXT(arg); @@ -297,8 +283,6 @@ const struct poptOption popt_common_dynconfig[] = { "Path to lmhosts file", "LMHOSTSFILE" }, { "libdir", '\0' , POPT_ARG_STRING, NULL, DYN_LIBDIR, "Path to shared library directory", "LIBDIR" }, - { "modulesdir", '\0' , POPT_ARG_STRING, NULL, DYN_MODULESDIR, - "Path to shared modules directory", "MODULESDIR" }, { "shlibext", '\0' , POPT_ARG_STRING, NULL, DYN_SHLIBEXT, "Shared library extension", "SHLIBEXT" }, { "lockdir", '\0' , POPT_ARG_STRING, NULL, DYN_LOCKDIR, diff --git a/source/lib/replace/libreplace_ld.m4 b/source/lib/replace/libreplace_ld.m4 index 81bde46219..9995d69bbc 100644 --- a/source/lib/replace/libreplace_ld.m4 +++ b/source/lib/replace/libreplace_ld.m4 @@ -271,7 +271,7 @@ AC_DEFUN([AC_LIBREPLACE_LD_SHLIB_ALLOW_UNDEF_FLAG], LD_SHLIB_ALLOW_UNDEF_FLAG="-undefined dynamic_lookup" ;; *aix*) - LD_SHLIB_ALLOW_UNDEF_FLAG="-Wl,-bnoentry" + LD_SHLIB_ALLOW_UNDEF_FLAG="--Wl,-bnoentry" ;; esac diff --git a/source/lib/replace/system/kerberos.h b/source/lib/replace/system/kerberos.h index 2981024bee..78aa7b943f 100644 --- a/source/lib/replace/system/kerberos.h +++ b/source/lib/replace/system/kerberos.h @@ -129,9 +129,8 @@ /* Whether krb5_princ_realm returns krb5_realm or krb5_data */ #define KRB5_PRINC_REALM_RETURNS_REALM 1 -#include <krb5.h> -#include <com_err.h> - +#include "heimdal/lib/krb5/krb5.h" +#include "heimdal/lib/com_err/com_err.h" #endif #endif diff --git a/source/lib/sendfile.c b/source/lib/sendfile.c index d1b178577c..20b2371273 100644 --- a/source/lib/sendfile.c +++ b/source/lib/sendfile.c @@ -383,8 +383,7 @@ ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, SMB_OFF_T of hdtrl.iov_base = NULL; hdtrl.iov_len = 0; } else { - hdtrl.iov_base = - (caddr_t)hdtrl.iov_base + nwritten; + hdtrl.iov_base += nwritten; hdtrl.iov_len -= nwritten; nwritten = 0; } diff --git a/source/lib/sharesec.c b/source/lib/sharesec.c index 4380000080..d89434782d 100644 --- a/source/lib/sharesec.c +++ b/source/lib/sharesec.c @@ -51,7 +51,7 @@ static bool share_info_db_init(void) return True; } - share_db = db_open(NULL, state_path("share_info.tdb"), 0, + share_db = db_open_trans(NULL, state_path("share_info.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600); if (share_db == NULL) { DEBUG(0,("Failed to open share info database %s (%s)\n", @@ -109,7 +109,7 @@ static bool share_info_db_init(void) if (share_db->transaction_commit(share_db) != 0) { DEBUG(0, ("transaction_commit failed\n")); - return false; + goto cancel; } return true; diff --git a/source/lib/smbconf/smbconf_reg.c b/source/lib/smbconf/smbconf_reg.c index 033f800e2a..dfce7502c5 100644 --- a/source/lib/smbconf/smbconf_reg.c +++ b/source/lib/smbconf/smbconf_reg.c @@ -52,7 +52,6 @@ static bool smbconf_reg_valname_forbidden(const char *valname) "lock dir", "config backend", "include", - "includes", /* this has a special meaning internally */ NULL }; const char **forbidden = NULL; @@ -67,8 +66,8 @@ static bool smbconf_reg_valname_forbidden(const char *valname) static bool smbconf_reg_valname_valid(const char *valname) { - return (!smbconf_reg_valname_forbidden(valname) && - lp_parameter_is_valid(valname)); + return (lp_parameter_is_valid(valname) && + !smbconf_reg_valname_forbidden(valname)); } /** diff --git a/source/lib/smbldap.c b/source/lib/smbldap.c index 93494d6dad..bcde53c3e5 100644 --- a/source/lib/smbldap.c +++ b/source/lib/smbldap.c @@ -298,7 +298,6 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = { { char **values; char *result; - size_t converted_size; if (attribute == NULL) { return NULL; @@ -318,7 +317,7 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = { return NULL; } - if (!pull_utf8_talloc(mem_ctx, &result, values[0], &converted_size)) { + if (pull_utf8_talloc(mem_ctx, &result, values[0]) == (size_t)-1) { DEBUG(10, ("pull_utf8_talloc failed\n")); ldap_value_free(values); return NULL; @@ -431,7 +430,6 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = { if (value != NULL) { char *utf8_value = NULL; - size_t converted_size; j = 0; if (mods[i]->mod_values != NULL) { @@ -444,7 +442,7 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = { /* notreached. */ } - if (!push_utf8_allocate(&utf8_value, value, &converted_size)) { + if (push_utf8_allocate(&utf8_value, value) == (size_t)-1) { smb_panic("smbldap_set_mod: String conversion failure!"); /* notreached. */ } @@ -1202,7 +1200,6 @@ static int smbldap_search_ext(struct smbldap_state *ldap_state, char *utf8_filter; time_t endtime = time(NULL)+lp_ldap_timeout(); struct timeval timeout; - size_t converted_size; SMB_ASSERT(ldap_state); @@ -1233,7 +1230,7 @@ static int smbldap_search_ext(struct smbldap_state *ldap_state, ZERO_STRUCT(ldap_state->last_rebind); } - if (!push_utf8_allocate(&utf8_filter, filter, &converted_size)) { + if (push_utf8_allocate(&utf8_filter, filter) == (size_t)-1) { return LDAP_NO_MEMORY; } @@ -1399,13 +1396,12 @@ int smbldap_modify(struct smbldap_state *ldap_state, const char *dn, LDAPMod *at int attempts = 0; char *utf8_dn; time_t endtime = time(NULL)+lp_ldap_timeout(); - size_t converted_size; SMB_ASSERT(ldap_state); DEBUG(5,("smbldap_modify: dn => [%s]\n", dn )); - if (!push_utf8_allocate(&utf8_dn, dn, &converted_size)) { + if (push_utf8_allocate(&utf8_dn, dn) == (size_t)-1) { return LDAP_NO_MEMORY; } @@ -1443,13 +1439,12 @@ int smbldap_add(struct smbldap_state *ldap_state, const char *dn, LDAPMod *attrs int attempts = 0; char *utf8_dn; time_t endtime = time(NULL)+lp_ldap_timeout(); - size_t converted_size; SMB_ASSERT(ldap_state); DEBUG(5,("smbldap_add: dn => [%s]\n", dn )); - if (!push_utf8_allocate(&utf8_dn, dn, &converted_size)) { + if (push_utf8_allocate(&utf8_dn, dn) == (size_t)-1) { return LDAP_NO_MEMORY; } @@ -1487,13 +1482,12 @@ int smbldap_delete(struct smbldap_state *ldap_state, const char *dn) int attempts = 0; char *utf8_dn; time_t endtime = time(NULL)+lp_ldap_timeout(); - size_t converted_size; SMB_ASSERT(ldap_state); DEBUG(5,("smbldap_delete: dn => [%s]\n", dn )); - if (!push_utf8_allocate(&utf8_dn, dn, &converted_size)) { + if (push_utf8_allocate(&utf8_dn, dn) == (size_t)-1) { return LDAP_NO_MEMORY; } @@ -1660,16 +1654,14 @@ NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx, struct event_context *event_ctx, char *smbldap_get_dn(LDAP *ld, LDAPMessage *entry) { char *utf8_dn, *unix_dn; - size_t converted_size; utf8_dn = ldap_get_dn(ld, entry); if (!utf8_dn) { DEBUG (5, ("smbldap_get_dn: ldap_get_dn failed\n")); return NULL; } - if (!pull_utf8_allocate(&unix_dn, utf8_dn, &converted_size)) { - DEBUG (0, ("smbldap_get_dn: String conversion failure utf8 " - "[%s]\n", utf8_dn)); + if (pull_utf8_allocate(&unix_dn, utf8_dn) == (size_t)-1) { + DEBUG (0, ("smbldap_get_dn: String conversion failure utf8 [%s]\n", utf8_dn)); return NULL; } ldap_memfree(utf8_dn); @@ -1680,14 +1672,13 @@ char *smbldap_get_dn(LDAP *ld, LDAPMessage *entry) LDAPMessage *entry) { char *utf8_dn, *unix_dn; - size_t converted_size; utf8_dn = ldap_get_dn(ld, entry); if (!utf8_dn) { DEBUG (5, ("smbldap_get_dn: ldap_get_dn failed\n")); return NULL; } - if (!pull_utf8_talloc(mem_ctx, &unix_dn, utf8_dn, &converted_size)) { + if (pull_utf8_talloc(mem_ctx, &unix_dn, utf8_dn) == (size_t)-1) { DEBUG (0, ("smbldap_get_dn: String conversion failure utf8 " "[%s]\n", utf8_dn)); return NULL; diff --git a/source/lib/socket_wrapper/config.m4 b/source/lib/socket_wrapper/config.m4 index f3ffb895a9..42212abc7f 100644 --- a/source/lib/socket_wrapper/config.m4 +++ b/source/lib/socket_wrapper/config.m4 @@ -1,22 +1,22 @@ AC_ARG_ENABLE(socket-wrapper, [ --enable-socket-wrapper Turn on socket wrapper library (default=no)]) -DEFAULT_TEST_OPTIONS= +DEFAULT_TEST_TARGET=test-noswrap HAVE_SOCKET_WRAPPER=no if eval "test x$developer = xyes"; then enable_socket_wrapper=yes fi - + if eval "test x$enable_socket_wrapper = xyes"; then AC_DEFINE(SOCKET_WRAPPER,1,[Use socket wrapper library]) - DEFAULT_TEST_OPTIONS=--socket-wrapper + DEFAULT_TEST_TARGET=test-swrap HAVE_SOCKET_WRAPPER=yes # this is only used for samba3 SOCKET_WRAPPER_OBJS="lib/socket_wrapper/socket_wrapper.o" fi -AC_SUBST(DEFAULT_TEST_OPTIONS) +AC_SUBST(DEFAULT_TEST_TARGET) AC_SUBST(HAVE_SOCKET_WRAPPER) AC_SUBST(SOCKET_WRAPPER_OBJS) diff --git a/source/lib/socket_wrapper/config.mk b/source/lib/socket_wrapper/config.mk deleted file mode 100644 index 60cfb3209a..0000000000 --- a/source/lib/socket_wrapper/config.mk +++ /dev/null @@ -1,8 +0,0 @@ -############################## -# Start SUBSYSTEM SOCKET_WRAPPER -[SUBSYSTEM::SOCKET_WRAPPER] -PRIVATE_DEPENDENCIES = LIBREPLACE_NETWORK -# End SUBSYSTEM SOCKET_WRAPPER -############################## - -SOCKET_WRAPPER_OBJ_FILES = $(socketwrappersrcdir)/socket_wrapper.o diff --git a/source/lib/socket_wrapper/socket_wrapper.c b/source/lib/socket_wrapper/socket_wrapper.c index 33e4b38370..c0a7c16a2a 100644 --- a/source/lib/socket_wrapper/socket_wrapper.c +++ b/source/lib/socket_wrapper/socket_wrapper.c @@ -1,5 +1,5 @@ /* - * Copyright (C) Jelmer Vernooij 2005,2008 <jelmer@samba.org> + * Copyright (C) Jelmer Vernooij 2005 <jelmer@samba.org> * Copyright (C) Stefan Metzmacher 2006 <metze@samba.org> * * All rights reserved. @@ -42,19 +42,26 @@ #ifdef _SAMBA_BUILD_ #define SOCKET_WRAPPER_NOT_REPLACE -#include "lib/replace/replace.h" +#include "includes.h" #include "system/network.h" #include "system/filesys.h" -#include "system/time.h" + +#ifdef malloc +#undef malloc +#endif +#ifdef calloc +#undef calloc +#endif +#ifdef strdup +#undef strdup +#endif #else /* _SAMBA_BUILD_ */ #include <sys/types.h> -#include <sys/time.h> #include <sys/stat.h> #include <sys/socket.h> #include <sys/ioctl.h> -#include <sys/filio.h> #include <errno.h> #include <sys/un.h> #include <netinet/in.h> @@ -66,10 +73,8 @@ #include <stdio.h> #include <stdint.h> -#endif - -#ifndef _PUBLIC_ #define _PUBLIC_ + #endif #define SWRAP_DLIST_ADD(list,item) do { \ @@ -140,13 +145,9 @@ #define SOCKET_FORMAT "%c%02X%04X" #define SOCKET_TYPE_CHAR_TCP 'T' #define SOCKET_TYPE_CHAR_UDP 'U' -#define SOCKET_TYPE_CHAR_TCP_V6 'X' -#define SOCKET_TYPE_CHAR_UDP_V6 'Y' #define MAX_WRAPPED_INTERFACES 16 -#define SW_IPV6_ADDRESS 1 - static struct sockaddr *sockaddr_dup(const void *data, socklen_t len) { struct sockaddr *ret = (struct sockaddr *)malloc(len); @@ -154,35 +155,6 @@ static struct sockaddr *sockaddr_dup(const void *data, socklen_t len) return ret; } -static void set_port(int family, int prt, struct sockaddr *addr) -{ - switch (family) { - case AF_INET: - ((struct sockaddr_in *)addr)->sin_port = htons(prt); - break; -#ifdef HAVE_IPV6 - case AF_INET6: - ((struct sockaddr_in6 *)addr)->sin6_port = htons(prt); - break; -#endif - } -} - -static size_t socket_length(int family) -{ - switch (family) { - case AF_INET: - return sizeof(struct sockaddr_in); -#ifdef HAVE_IPV6 - case AF_INET6: - return sizeof(struct sockaddr_in6); -#endif - } - return 0; -} - - - struct socket_info { int fd; @@ -213,7 +185,8 @@ struct socket_info static struct socket_info *sockets; -const char *socket_wrapper_dir(void) + +static const char *socket_wrapper_dir(void) { const char *s = getenv("SOCKET_WRAPPER_DIR"); if (s == NULL) { @@ -225,7 +198,7 @@ const char *socket_wrapper_dir(void) return s; } -unsigned int socket_wrapper_default_iface(void) +static unsigned int socket_wrapper_default_iface(void) { const char *s = getenv("SOCKET_WRAPPER_DEFAULT_IFACE"); if (s) { @@ -240,13 +213,17 @@ unsigned int socket_wrapper_default_iface(void) return 1;/* 127.0.0.1 */ } -static int convert_un_in(const struct sockaddr_un *un, struct sockaddr *in, socklen_t *len) +static int convert_un_in(const struct sockaddr_un *un, struct sockaddr_in *in, socklen_t *len) { unsigned int iface; unsigned int prt; const char *p; char type; + if ((*len) < sizeof(struct sockaddr_in)) { + return 0; + } + p = strrchr(un->sun_path, '/'); if (p) p++; else p = un->sun_path; @@ -255,145 +232,80 @@ static int convert_un_in(const struct sockaddr_un *un, struct sockaddr *in, sock return -1; } - if (iface == 0 || iface > MAX_WRAPPED_INTERFACES) { + if (type != SOCKET_TYPE_CHAR_TCP && type != SOCKET_TYPE_CHAR_UDP) { errno = EINVAL; return -1; } - if (prt > 0xFFFF) { + if (iface == 0 || iface > MAX_WRAPPED_INTERFACES) { errno = EINVAL; return -1; } - switch(type) { - case SOCKET_TYPE_CHAR_TCP: - case SOCKET_TYPE_CHAR_UDP: { - struct sockaddr_in *in2 = (struct sockaddr_in *)in; - - if ((*len) < sizeof(*in2)) { - errno = EINVAL; - return -1; - } - - memset(in2, 0, sizeof(*in2)); - in2->sin_family = AF_INET; - in2->sin_addr.s_addr = htonl((127<<24) | iface); - in2->sin_port = htons(prt); - - *len = sizeof(*in2); - break; - } -#ifdef HAVE_IPV6 - case SOCKET_TYPE_CHAR_TCP_V6: - case SOCKET_TYPE_CHAR_UDP_V6: { - struct sockaddr_in6 *in2 = (struct sockaddr_in6 *)in; - - if ((*len) < sizeof(*in2)) { - errno = EINVAL; - return -1; - } - - memset(in2, 0, sizeof(*in2)); - in2->sin6_family = AF_INET6; - in2->sin6_addr.s6_addr[0] = SW_IPV6_ADDRESS; - in2->sin6_port = htons(prt); - - *len = sizeof(*in2); - break; - } -#endif - default: + if (prt > 0xFFFF) { errno = EINVAL; return -1; } + in->sin_family = AF_INET; + in->sin_addr.s_addr = htonl((127<<24) | iface); + in->sin_port = htons(prt); + + *len = sizeof(struct sockaddr_in); return 0; } -static int convert_in_un_remote(struct socket_info *si, const struct sockaddr *inaddr, struct sockaddr_un *un, +static int convert_in_un_remote(struct socket_info *si, const struct sockaddr_in *in, struct sockaddr_un *un, int *bcast) { + char u_type = '\0'; + char b_type = '\0'; + char a_type = '\0'; char type = '\0'; - unsigned int prt; + unsigned int addr= ntohl(in->sin_addr.s_addr); + unsigned int prt = ntohs(in->sin_port); unsigned int iface; int is_bcast = 0; if (bcast) *bcast = 0; - switch (si->family) { - case AF_INET: { - const struct sockaddr_in *in = - (const struct sockaddr_in *)inaddr; - unsigned int addr = ntohl(in->sin_addr.s_addr); - char u_type = '\0'; - char b_type = '\0'; - char a_type = '\0'; - - switch (si->type) { - case SOCK_STREAM: - u_type = SOCKET_TYPE_CHAR_TCP; - break; - case SOCK_DGRAM: - u_type = SOCKET_TYPE_CHAR_UDP; - a_type = SOCKET_TYPE_CHAR_UDP; - b_type = SOCKET_TYPE_CHAR_UDP; - break; - } - - prt = ntohs(in->sin_port); - if (a_type && addr == 0xFFFFFFFF) { - /* 255.255.255.255 only udp */ - is_bcast = 2; - type = a_type; - iface = socket_wrapper_default_iface(); - } else if (b_type && addr == 0x7FFFFFFF) { - /* 127.255.255.255 only udp */ - is_bcast = 1; - type = b_type; - iface = socket_wrapper_default_iface(); - } else if ((addr & 0xFFFFFF00) == 0x7F000000) { - /* 127.0.0.X */ - is_bcast = 0; - type = u_type; - iface = (addr & 0x000000FF); - } else { - errno = ENETUNREACH; - return -1; - } - if (bcast) *bcast = is_bcast; - break; + if (prt == 0) { + errno = EINVAL; + return -1; } -#ifdef HAVE_IPV6 - case AF_INET6: { - const struct sockaddr_in6 *in = - (const struct sockaddr_in6 *)inaddr; - - switch (si->type) { - case SOCK_STREAM: - type = SOCKET_TYPE_CHAR_TCP_V6; - break; - case SOCK_DGRAM: - type = SOCKET_TYPE_CHAR_UDP_V6; - break; - } - - /* XXX no multicast/broadcast */ - prt = ntohs(in->sin6_port); - iface = SW_IPV6_ADDRESS; - + switch (si->type) { + case SOCK_STREAM: + u_type = SOCKET_TYPE_CHAR_TCP; + break; + case SOCK_DGRAM: + u_type = SOCKET_TYPE_CHAR_UDP; + a_type = SOCKET_TYPE_CHAR_UDP; + b_type = SOCKET_TYPE_CHAR_UDP; break; } -#endif - default: + + if (a_type && addr == 0xFFFFFFFF) { + /* 255.255.255.255 only udp */ + is_bcast = 2; + type = a_type; + iface = socket_wrapper_default_iface(); + } else if (b_type && addr == 0x7FFFFFFF) { + /* 127.255.255.255 only udp */ + is_bcast = 1; + type = b_type; + iface = socket_wrapper_default_iface(); + } else if ((addr & 0xFFFFFF00) == 0x7F000000) { + /* 127.0.0.X */ + is_bcast = 0; + type = u_type; + iface = (addr & 0x000000FF); + } else { errno = ENETUNREACH; return -1; } - if (prt == 0) { - errno = EINVAL; - return -1; - } + if (bcast) *bcast = is_bcast; if (is_bcast) { snprintf(un->sun_path, sizeof(un->sun_path), "%s/EINVAL", @@ -408,96 +320,60 @@ static int convert_in_un_remote(struct socket_info *si, const struct sockaddr *i return 0; } -static int convert_in_un_alloc(struct socket_info *si, const struct sockaddr *inaddr, struct sockaddr_un *un, +static int convert_in_un_alloc(struct socket_info *si, const struct sockaddr_in *in, struct sockaddr_un *un, int *bcast) { + char u_type = '\0'; + char d_type = '\0'; + char b_type = '\0'; + char a_type = '\0'; char type = '\0'; - unsigned int prt; + unsigned int addr= ntohl(in->sin_addr.s_addr); + unsigned int prt = ntohs(in->sin_port); unsigned int iface; struct stat st; int is_bcast = 0; if (bcast) *bcast = 0; - switch (si->family) { - case AF_INET: { - const struct sockaddr_in *in = - (const struct sockaddr_in *)inaddr; - unsigned int addr = ntohl(in->sin_addr.s_addr); - char u_type = '\0'; - char d_type = '\0'; - char b_type = '\0'; - char a_type = '\0'; - - prt = ntohs(in->sin_port); - - switch (si->type) { - case SOCK_STREAM: - u_type = SOCKET_TYPE_CHAR_TCP; - d_type = SOCKET_TYPE_CHAR_TCP; - break; - case SOCK_DGRAM: - u_type = SOCKET_TYPE_CHAR_UDP; - d_type = SOCKET_TYPE_CHAR_UDP; - a_type = SOCKET_TYPE_CHAR_UDP; - b_type = SOCKET_TYPE_CHAR_UDP; - break; - } - - if (addr == 0) { - /* 0.0.0.0 */ - is_bcast = 0; - type = d_type; - iface = socket_wrapper_default_iface(); - } else if (a_type && addr == 0xFFFFFFFF) { - /* 255.255.255.255 only udp */ - is_bcast = 2; - type = a_type; - iface = socket_wrapper_default_iface(); - } else if (b_type && addr == 0x7FFFFFFF) { - /* 127.255.255.255 only udp */ - is_bcast = 1; - type = b_type; - iface = socket_wrapper_default_iface(); - } else if ((addr & 0xFFFFFF00) == 0x7F000000) { - /* 127.0.0.X */ - is_bcast = 0; - type = u_type; - iface = (addr & 0x000000FF); - } else { - errno = EADDRNOTAVAIL; - return -1; - } + switch (si->type) { + case SOCK_STREAM: + u_type = SOCKET_TYPE_CHAR_TCP; + d_type = SOCKET_TYPE_CHAR_TCP; break; - } -#ifdef HAVE_IPV6 - case AF_INET6: { - const struct sockaddr_in6 *in = - (const struct sockaddr_in6 *)inaddr; - - switch (si->type) { - case SOCK_STREAM: - type = SOCKET_TYPE_CHAR_TCP_V6; - break; - case SOCK_DGRAM: - type = SOCKET_TYPE_CHAR_UDP_V6; - break; - } - - /* XXX no multicast/broadcast */ - - prt = ntohs(in->sin6_port); - iface = SW_IPV6_ADDRESS; - + case SOCK_DGRAM: + u_type = SOCKET_TYPE_CHAR_UDP; + d_type = SOCKET_TYPE_CHAR_UDP; + a_type = SOCKET_TYPE_CHAR_UDP; + b_type = SOCKET_TYPE_CHAR_UDP; break; } -#endif - default: - errno = ENETUNREACH; + + if (addr == 0) { + /* 0.0.0.0 */ + is_bcast = 0; + type = d_type; + iface = socket_wrapper_default_iface(); + } else if (a_type && addr == 0xFFFFFFFF) { + /* 255.255.255.255 only udp */ + is_bcast = 2; + type = a_type; + iface = socket_wrapper_default_iface(); + } else if (b_type && addr == 0x7FFFFFFF) { + /* 127.255.255.255 only udp */ + is_bcast = 1; + type = b_type; + iface = socket_wrapper_default_iface(); + } else if ((addr & 0xFFFFFF00) == 0x7F000000) { + /* 127.0.0.X */ + is_bcast = 0; + type = u_type; + iface = (addr & 0x000000FF); + } else { + errno = EADDRNOTAVAIL; return -1; } - if (bcast) *bcast = is_bcast; if (prt == 0) { @@ -507,13 +383,11 @@ static int convert_in_un_alloc(struct socket_info *si, const struct sockaddr *in socket_wrapper_dir(), type, iface, prt); if (stat(un->sun_path, &st) == 0) continue; - set_port(si->family, prt, si->myname); - break; - } - if (prt == 10000) { - errno = ENFILE; - return -1; + ((struct sockaddr_in *)si->myname)->sin_port = htons(prt); + return 0; } + errno = ENFILE; + return -1; } snprintf(un->sun_path, sizeof(un->sun_path), "%s/"SOCKET_FORMAT, @@ -542,9 +416,6 @@ static int sockaddr_convert_to_un(struct socket_info *si, const struct sockaddr switch (in_addr->sa_family) { case AF_INET: -#ifdef HAVE_IPV6 - case AF_INET6: -#endif switch (si->type) { case SOCK_STREAM: case SOCK_DGRAM: @@ -554,9 +425,9 @@ static int sockaddr_convert_to_un(struct socket_info *si, const struct sockaddr return -1; } if (alloc_sock) { - return convert_in_un_alloc(si, in_addr, out_addr, bcast); + return convert_in_un_alloc(si, (const struct sockaddr_in *)in_addr, out_addr, bcast); } else { - return convert_in_un_remote(si, in_addr, out_addr, bcast); + return convert_in_un_remote(si, (const struct sockaddr_in *)in_addr, out_addr, bcast); } default: break; @@ -571,21 +442,25 @@ static int sockaddr_convert_from_un(const struct socket_info *si, socklen_t un_addrlen, int family, struct sockaddr *out_addr, - socklen_t *out_addrlen) + socklen_t *_out_addrlen) { - if (out_addr == NULL || out_addrlen == NULL) + socklen_t out_addrlen; + + if (out_addr == NULL || _out_addrlen == NULL) return 0; if (un_addrlen == 0) { - *out_addrlen = 0; + *_out_addrlen = 0; return 0; } + out_addrlen = *_out_addrlen; + if (out_addrlen > un_addrlen) { + out_addrlen = un_addrlen; + } + switch (family) { case AF_INET: -#ifdef HAVE_IPV6 - case AF_INET6: -#endif switch (si->type) { case SOCK_STREAM: case SOCK_DGRAM: @@ -594,7 +469,7 @@ static int sockaddr_convert_from_un(const struct socket_info *si, errno = ESOCKTNOSUPPORT; return -1; } - return convert_un_in(in_addr, out_addr, out_addrlen); + return convert_un_in(in_addr, (struct sockaddr_in *)out_addr, _out_addrlen); default: break; } @@ -750,7 +625,7 @@ static struct swrap_packet *swrap_packet_init(struct timeval *tval, int socket_type, const unsigned char *payload, size_t payload_len, - unsigned long tcp_seqno, + unsigned long tcp_seq, unsigned long tcp_ack, unsigned char tcp_ctl, int unreachable, @@ -781,9 +656,6 @@ static struct swrap_packet *swrap_packet_init(struct timeval *tval, wire_hdr_len = sizeof(packet->ip.hdr) + sizeof(packet->ip.p.udp); wire_len = wire_hdr_len + payload_len; break; - - default: - return NULL; } if (unreachable) { @@ -852,7 +724,7 @@ static struct swrap_packet *swrap_packet_init(struct timeval *tval, case SOCK_STREAM: packet->ip.p.tcp.source_port = src_port; packet->ip.p.tcp.dest_port = dest_port; - packet->ip.p.tcp.seq_num = htonl(tcp_seqno); + packet->ip.p.tcp.seq_num = htonl(tcp_seq); packet->ip.p.tcp.ack_num = htonl(tcp_ack); packet->ip.p.tcp.hdr_length = 0x50; /* 5 * 32 bit words */ packet->ip.p.tcp.control = tcp_ctl; @@ -908,36 +780,39 @@ static int swrap_get_pcap_fd(const char *fname) return fd; } -static struct swrap_packet *swrap_marshall_packet(struct socket_info *si, - const struct sockaddr *addr, - enum swrap_packet_type type, - const void *buf, size_t len, - size_t *packet_len) +static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *addr, + enum swrap_packet_type type, + const void *buf, size_t len) { const struct sockaddr_in *src_addr; const struct sockaddr_in *dest_addr; - unsigned long tcp_seqno = 0; + const char *file_name; + unsigned long tcp_seq = 0; unsigned long tcp_ack = 0; unsigned char tcp_ctl = 0; int unreachable = 0; - struct timeval tv; + struct swrap_packet *packet; + size_t packet_len = 0; + int fd; - switch (si->family) { - case AF_INET: - break; - default: - return NULL; + file_name = socket_wrapper_pcap_file(); + if (!file_name) { + return; + } + + if (si->family != AF_INET) { + return; } switch (type) { case SWRAP_CONNECT_SEND: - if (si->type != SOCK_STREAM) return NULL; + if (si->type != SOCK_STREAM) return; src_addr = (const struct sockaddr_in *)si->myname; dest_addr = (const struct sockaddr_in *)addr; - tcp_seqno = si->io.pck_snd; + tcp_seq = si->io.pck_snd; tcp_ack = si->io.pck_rcv; tcp_ctl = 0x02; /* SYN */ @@ -946,12 +821,12 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si, break; case SWRAP_CONNECT_RECV: - if (si->type != SOCK_STREAM) return NULL; + if (si->type != SOCK_STREAM) return; dest_addr = (const struct sockaddr_in *)si->myname; src_addr = (const struct sockaddr_in *)addr; - tcp_seqno = si->io.pck_rcv; + tcp_seq = si->io.pck_rcv; tcp_ack = si->io.pck_snd; tcp_ctl = 0x12; /** SYN,ACK */ @@ -960,13 +835,13 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si, break; case SWRAP_CONNECT_UNREACH: - if (si->type != SOCK_STREAM) return NULL; + if (si->type != SOCK_STREAM) return; dest_addr = (const struct sockaddr_in *)si->myname; src_addr = (const struct sockaddr_in *)addr; /* Unreachable: resend the data of SWRAP_CONNECT_SEND */ - tcp_seqno = si->io.pck_snd - 1; + tcp_seq = si->io.pck_snd - 1; tcp_ack = si->io.pck_rcv; tcp_ctl = 0x02; /* SYN */ unreachable = 1; @@ -974,24 +849,24 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si, break; case SWRAP_CONNECT_ACK: - if (si->type != SOCK_STREAM) return NULL; + if (si->type != SOCK_STREAM) return; src_addr = (const struct sockaddr_in *)si->myname; dest_addr = (const struct sockaddr_in *)addr; - tcp_seqno = si->io.pck_snd; + tcp_seq = si->io.pck_snd; tcp_ack = si->io.pck_rcv; tcp_ctl = 0x10; /* ACK */ break; case SWRAP_ACCEPT_SEND: - if (si->type != SOCK_STREAM) return NULL; + if (si->type != SOCK_STREAM) return; dest_addr = (const struct sockaddr_in *)si->myname; src_addr = (const struct sockaddr_in *)addr; - tcp_seqno = si->io.pck_rcv; + tcp_seq = si->io.pck_rcv; tcp_ack = si->io.pck_snd; tcp_ctl = 0x02; /* SYN */ @@ -1000,12 +875,12 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si, break; case SWRAP_ACCEPT_RECV: - if (si->type != SOCK_STREAM) return NULL; + if (si->type != SOCK_STREAM) return; src_addr = (const struct sockaddr_in *)si->myname; dest_addr = (const struct sockaddr_in *)addr; - tcp_seqno = si->io.pck_snd; + tcp_seq = si->io.pck_snd; tcp_ack = si->io.pck_rcv; tcp_ctl = 0x12; /* SYN,ACK */ @@ -1014,12 +889,12 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si, break; case SWRAP_ACCEPT_ACK: - if (si->type != SOCK_STREAM) return NULL; + if (si->type != SOCK_STREAM) return; dest_addr = (const struct sockaddr_in *)si->myname; src_addr = (const struct sockaddr_in *)addr; - tcp_seqno = si->io.pck_rcv; + tcp_seq = si->io.pck_rcv; tcp_ack = si->io.pck_snd; tcp_ctl = 0x10; /* ACK */ @@ -1029,7 +904,7 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si, src_addr = (const struct sockaddr_in *)si->myname; dest_addr = (const struct sockaddr_in *)si->peername; - tcp_seqno = si->io.pck_snd; + tcp_seq = si->io.pck_snd; tcp_ack = si->io.pck_rcv; tcp_ctl = 0x18; /* PSH,ACK */ @@ -1042,12 +917,13 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si, src_addr = (const struct sockaddr_in *)si->peername; if (si->type == SOCK_DGRAM) { - return swrap_marshall_packet(si, si->peername, + swrap_dump_packet(si, si->peername, SWRAP_SENDTO_UNREACH, - buf, len, packet_len); + buf, len); + return; } - tcp_seqno = si->io.pck_rcv; + tcp_seq = si->io.pck_rcv; tcp_ack = si->io.pck_snd; tcp_ctl = 0x14; /** RST,ACK */ @@ -1058,10 +934,10 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si, src_addr = (const struct sockaddr_in *)si->peername; if (si->type == SOCK_DGRAM) { - return NULL; + return; } - tcp_seqno = si->io.pck_rcv; + tcp_seq = si->io.pck_rcv; tcp_ack = si->io.pck_snd; tcp_ctl = 0x14; /* RST,ACK */ @@ -1071,7 +947,7 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si, dest_addr = (const struct sockaddr_in *)si->myname; src_addr = (const struct sockaddr_in *)si->peername; - tcp_seqno = si->io.pck_rcv; + tcp_seq = si->io.pck_rcv; tcp_ack = si->io.pck_snd; tcp_ctl = 0x18; /* PSH,ACK */ @@ -1084,10 +960,10 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si, src_addr = (const struct sockaddr_in *)si->peername; if (si->type == SOCK_DGRAM) { - return NULL; + return; } - tcp_seqno = si->io.pck_rcv; + tcp_seq = si->io.pck_rcv; tcp_ack = si->io.pck_snd; tcp_ctl = 0x14; /* RST,ACK */ @@ -1118,12 +994,12 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si, break; case SWRAP_CLOSE_SEND: - if (si->type != SOCK_STREAM) return NULL; + if (si->type != SOCK_STREAM) return; src_addr = (const struct sockaddr_in *)si->myname; dest_addr = (const struct sockaddr_in *)si->peername; - tcp_seqno = si->io.pck_snd; + tcp_seq = si->io.pck_snd; tcp_ack = si->io.pck_rcv; tcp_ctl = 0x11; /* FIN, ACK */ @@ -1132,12 +1008,12 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si, break; case SWRAP_CLOSE_RECV: - if (si->type != SOCK_STREAM) return NULL; + if (si->type != SOCK_STREAM) return; dest_addr = (const struct sockaddr_in *)si->myname; src_addr = (const struct sockaddr_in *)si->peername; - tcp_seqno = si->io.pck_rcv; + tcp_seq = si->io.pck_rcv; tcp_ack = si->io.pck_snd; tcp_ctl = 0x11; /* FIN,ACK */ @@ -1146,44 +1022,26 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si, break; case SWRAP_CLOSE_ACK: - if (si->type != SOCK_STREAM) return NULL; + if (si->type != SOCK_STREAM) return; src_addr = (const struct sockaddr_in *)si->myname; dest_addr = (const struct sockaddr_in *)si->peername; - tcp_seqno = si->io.pck_snd; + tcp_seq = si->io.pck_snd; tcp_ack = si->io.pck_rcv; tcp_ctl = 0x10; /* ACK */ break; default: - return NULL; + return; } swrapGetTimeOfDay(&tv); - return swrap_packet_init(&tv, src_addr, dest_addr, si->type, + packet = swrap_packet_init(&tv, src_addr, dest_addr, si->type, (const unsigned char *)buf, len, - tcp_seqno, tcp_ack, tcp_ctl, unreachable, - packet_len); -} - -static void swrap_dump_packet(struct socket_info *si, - const struct sockaddr *addr, - enum swrap_packet_type type, - const void *buf, size_t len) -{ - const char *file_name; - struct swrap_packet *packet; - size_t packet_len = 0; - int fd; - - file_name = socket_wrapper_pcap_file(); - if (!file_name) { - return; - } - - packet = swrap_marshall_packet(si, addr, type, buf, len, &packet_len); + tcp_seq, tcp_ack, tcp_ctl, unreachable, + &packet_len); if (!packet) { return; } @@ -1207,9 +1065,6 @@ _PUBLIC_ int swrap_socket(int family, int type, int protocol) switch (family) { case AF_INET: -#ifdef HAVE_IPV6 - case AF_INET6: -#endif break; case AF_UNIX: return real_socket(family, type, protocol); @@ -1231,16 +1086,6 @@ _PUBLIC_ int swrap_socket(int family, int type, int protocol) switch (protocol) { case 0: break; - case 6: - if (type == SOCK_STREAM) { - break; - } - /*fall through*/ - case 17: - if (type == SOCK_DGRAM) { - break; - } - /*fall through*/ default: errno = EPROTONOSUPPORT; return -1; @@ -1270,8 +1115,8 @@ _PUBLIC_ int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) socklen_t un_addrlen = sizeof(un_addr); struct sockaddr_un un_my_addr; socklen_t un_my_addrlen = sizeof(un_my_addr); - struct sockaddr *my_addr; - socklen_t my_addrlen, len; + struct sockaddr my_addr; + socklen_t my_addrlen = sizeof(my_addr); int ret; parent_si = find_socket_info(s); @@ -1279,37 +1124,18 @@ _PUBLIC_ int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) return real_accept(s, addr, addrlen); } - /* - * assume out sockaddr have the same size as the in parent - * socket family - */ - my_addrlen = socket_length(parent_si->family); - if (my_addrlen <= 0) { - errno = EINVAL; - return -1; - } - - my_addr = (struct sockaddr *)malloc(my_addrlen); - if (my_addr == NULL) { - return -1; - } - memset(&un_addr, 0, sizeof(un_addr)); memset(&un_my_addr, 0, sizeof(un_my_addr)); + memset(&my_addr, 0, sizeof(my_addr)); ret = real_accept(s, (struct sockaddr *)&un_addr, &un_addrlen); - if (ret == -1) { - free(my_addr); - return ret; - } + if (ret == -1) return ret; fd = ret; - len = my_addrlen; ret = sockaddr_convert_from_un(parent_si, &un_addr, un_addrlen, - parent_si->family, my_addr, &len); + parent_si->family, addr, addrlen); if (ret == -1) { - free(my_addr); close(fd); return ret; } @@ -1324,16 +1150,6 @@ _PUBLIC_ int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) child_si->bound = 1; child_si->is_server = 1; - child_si->peername_len = len; - child_si->peername = sockaddr_dup(my_addr, len); - - if (addr != NULL && addrlen != NULL) { - *addrlen = len; - if (*addrlen >= len) - memcpy(addr, my_addr, len); - *addrlen = 0; - } - ret = real_getsockname(fd, (struct sockaddr *)&un_my_addr, &un_my_addrlen); if (ret == -1) { free(child_si); @@ -1341,19 +1157,19 @@ _PUBLIC_ int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) return ret; } - len = my_addrlen; ret = sockaddr_convert_from_un(child_si, &un_my_addr, un_my_addrlen, - child_si->family, my_addr, &len); + child_si->family, &my_addr, &my_addrlen); if (ret == -1) { free(child_si); - free(my_addr); close(fd); return ret; } - child_si->myname_len = len; - child_si->myname = sockaddr_dup(my_addr, len); - free(my_addr); + child_si->myname_len = my_addrlen; + child_si->myname = sockaddr_dup(&my_addr, my_addrlen); + + child_si->peername_len = *addrlen; + child_si->peername = sockaddr_dup(addr, *addrlen); SWRAP_DLIST_ADD(sockets, child_si); @@ -1374,6 +1190,7 @@ static int autobind_start; static int swrap_auto_bind(struct socket_info *si) { struct sockaddr_un un_addr; + struct sockaddr_in in; int i; char type; int ret; @@ -1389,55 +1206,13 @@ static int swrap_auto_bind(struct socket_info *si) un_addr.sun_family = AF_UNIX; - switch (si->family) { - case AF_INET: { - struct sockaddr_in in; - - switch (si->type) { - case SOCK_STREAM: - type = SOCKET_TYPE_CHAR_TCP; - break; - case SOCK_DGRAM: - type = SOCKET_TYPE_CHAR_UDP; - break; - default: - errno = ESOCKTNOSUPPORT; - return -1; - } - - memset(&in, 0, sizeof(in)); - in.sin_family = AF_INET; - in.sin_addr.s_addr = htonl(127<<24 | - socket_wrapper_default_iface()); - - si->myname_len = sizeof(in); - si->myname = sockaddr_dup(&in, si->myname_len); + switch (si->type) { + case SOCK_STREAM: + type = SOCKET_TYPE_CHAR_TCP; break; - } -#ifdef HAVE_IPV6 - case AF_INET6: { - struct sockaddr_in6 in6; - - switch (si->type) { - case SOCK_STREAM: - type = SOCKET_TYPE_CHAR_TCP_V6; - break; - case SOCK_DGRAM: - type = SOCKET_TYPE_CHAR_UDP_V6; - break; - default: - errno = ESOCKTNOSUPPORT; - return -1; - } - - memset(&in6, 0, sizeof(in6)); - in6.sin6_family = AF_INET6; - in6.sin6_addr.s6_addr[0] = SW_IPV6_ADDRESS; - si->myname_len = sizeof(in6); - si->myname = sockaddr_dup(&in6, si->myname_len); + case SOCK_DGRAM: + type = SOCKET_TYPE_CHAR_UDP; break; - } -#endif default: errno = ESOCKTNOSUPPORT; return -1; @@ -1467,8 +1242,13 @@ static int swrap_auto_bind(struct socket_info *si) return -1; } - set_port(si->family, port, si->myname); - + memset(&in, 0, sizeof(in)); + in.sin_family = AF_INET; + in.sin_port = htons(port); + in.sin_addr.s_addr = htonl(127<<24 | socket_wrapper_default_iface()); + + si->myname_len = sizeof(in); + si->myname = sockaddr_dup(&in, si->myname_len); return 0; } @@ -1488,11 +1268,6 @@ _PUBLIC_ int swrap_connect(int s, const struct sockaddr *serv_addr, socklen_t ad if (ret == -1) return -1; } - if (si->family != serv_addr->sa_family) { - errno = EINVAL; - return -1; - } - ret = sockaddr_convert_to_un(si, (const struct sockaddr *)serv_addr, addrlen, &un_addr, 0, NULL); if (ret == -1) return -1; @@ -1643,8 +1418,6 @@ _PUBLIC_ ssize_t swrap_recvfrom(int s, void *buf, size_t len, int flags, struct return real_recvfrom(s, buf, len, flags, from, fromlen); } - len = MIN(len, 1500); - /* irix 6.4 forgets to null terminate the sun_path string :-( */ memset(&un_addr, 0, sizeof(un_addr)); ret = real_recvfrom(s, buf, len, flags, (struct sockaddr *)&un_addr, &un_addrlen); @@ -1673,51 +1446,38 @@ _PUBLIC_ ssize_t swrap_sendto(int s, const void *buf, size_t len, int flags, con return real_sendto(s, buf, len, flags, to, tolen); } - len = MIN(len, 1500); - - switch (si->type) { - case SOCK_STREAM: - ret = real_send(s, buf, len, flags); - break; - case SOCK_DGRAM: - if (si->bound == 0) { - ret = swrap_auto_bind(si); - if (ret == -1) return -1; - } - - ret = sockaddr_convert_to_un(si, to, tolen, &un_addr, 0, &bcast); + if (si->bound == 0) { + ret = swrap_auto_bind(si); if (ret == -1) return -1; - - if (bcast) { - struct stat st; - unsigned int iface; - unsigned int prt = ntohs(((const struct sockaddr_in *)to)->sin_port); - char type; - - type = SOCKET_TYPE_CHAR_UDP; - - for(iface=0; iface <= MAX_WRAPPED_INTERFACES; iface++) { - snprintf(un_addr.sun_path, sizeof(un_addr.sun_path), "%s/"SOCKET_FORMAT, - socket_wrapper_dir(), type, iface, prt); - if (stat(un_addr.sun_path, &st) != 0) continue; - - /* ignore the any errors in broadcast sends */ - real_sendto(s, buf, len, flags, (struct sockaddr *)&un_addr, sizeof(un_addr)); - } - - swrap_dump_packet(si, to, SWRAP_SENDTO, buf, len); - - return len; + } + + ret = sockaddr_convert_to_un(si, to, tolen, &un_addr, 0, &bcast); + if (ret == -1) return -1; + + if (bcast) { + struct stat st; + unsigned int iface; + unsigned int prt = ntohs(((const struct sockaddr_in *)to)->sin_port); + char type; + + type = SOCKET_TYPE_CHAR_UDP; + + for(iface=0; iface <= MAX_WRAPPED_INTERFACES; iface++) { + snprintf(un_addr.sun_path, sizeof(un_addr.sun_path), "%s/"SOCKET_FORMAT, + socket_wrapper_dir(), type, iface, prt); + if (stat(un_addr.sun_path, &st) != 0) continue; + + /* ignore the any errors in broadcast sends */ + real_sendto(s, buf, len, flags, (struct sockaddr *)&un_addr, sizeof(un_addr)); } - - ret = real_sendto(s, buf, len, flags, (struct sockaddr *)&un_addr, sizeof(un_addr)); - break; - default: - ret = -1; - errno = EHOSTUNREACH; - break; + + swrap_dump_packet(si, to, SWRAP_SENDTO, buf, len); + + return len; } - + + ret = real_sendto(s, buf, len, flags, (struct sockaddr *)&un_addr, sizeof(un_addr)); + /* to give better errors */ if (ret == -1 && errno == ENOENT) { errno = EHOSTUNREACH; @@ -1768,8 +1528,6 @@ _PUBLIC_ ssize_t swrap_recv(int s, void *buf, size_t len, int flags) return real_recv(s, buf, len, flags); } - len = MIN(len, 1500); - ret = real_recv(s, buf, len, flags); if (ret == -1 && errno != EAGAIN && errno != ENOBUFS) { swrap_dump_packet(si, NULL, SWRAP_RECV_RST, NULL, 0); @@ -1792,8 +1550,6 @@ _PUBLIC_ ssize_t swrap_send(int s, const void *buf, size_t len, int flags) return real_send(s, buf, len, flags); } - len = MIN(len, 1500); - ret = real_send(s, buf, len, flags); if (ret == -1) { diff --git a/source/lib/socket_wrapper/socket_wrapper.h b/source/lib/socket_wrapper/socket_wrapper.h index cc8b937608..1d8dac1763 100644 --- a/source/lib/socket_wrapper/socket_wrapper.h +++ b/source/lib/socket_wrapper/socket_wrapper.h @@ -36,8 +36,6 @@ #ifndef __SOCKET_WRAPPER_H__ #define __SOCKET_WRAPPER_H__ -const char *socket_wrapper_dir(void); -unsigned int socket_wrapper_default_iface(void); int swrap_socket(int family, int type, int protocol); int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen); int swrap_connect(int s, const struct sockaddr *serv_addr, socklen_t addrlen); @@ -132,5 +130,4 @@ int swrap_close(int); #define close(s) swrap_close(s) #endif - #endif /* __SOCKET_WRAPPER_H__ */ diff --git a/source/lib/socket_wrapper/testsuite.c b/source/lib/socket_wrapper/testsuite.c deleted file mode 100644 index 8877418e4c..0000000000 --- a/source/lib/socket_wrapper/testsuite.c +++ /dev/null @@ -1,105 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - local testing of the socket wrapper - - Copyright (C) Jelmer Vernooij 2007 - - 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 <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" -#include "system/network.h" -#include "lib/socket_wrapper/socket_wrapper.h" -#include "torture/torture.h" - -static char *old_dir = NULL; -static char *old_iface = NULL; - -static void backup_env(void) -{ - old_dir = getenv("SOCKET_WRAPPER_DIR"); - old_iface = getenv("SOCKET_WRAPPER_DEFAULT_IFACE"); -} - -static void restore_env(void) -{ - if (old_dir == NULL) - unsetenv("SOCKET_WRAPPER_DIR"); - else - setenv("SOCKET_WRAPPER_DIR", old_dir, 1); - if (old_iface == NULL) - unsetenv("SOCKET_WRAPPER_DEFAULT_IFACE"); - else - setenv("SOCKET_WRAPPER_DEFAULT_IFACE", old_iface, 1); -} - -static bool test_socket_wrapper_dir(struct torture_context *tctx) -{ - backup_env(); - - setenv("SOCKET_WRAPPER_DIR", "foo", 1); - torture_assert_str_equal(tctx, socket_wrapper_dir(), "foo", "setting failed"); - setenv("SOCKET_WRAPPER_DIR", "./foo", 1); - torture_assert_str_equal(tctx, socket_wrapper_dir(), "foo", "setting failed"); - unsetenv("SOCKET_WRAPPER_DIR"); - torture_assert_str_equal(tctx, socket_wrapper_dir(), NULL, "resetting failed"); - - restore_env(); - - return true; -} - -static bool test_swrap_socket(struct torture_context *tctx) -{ - backup_env(); - setenv("SOCKET_WRAPPER_DIR", "foo", 1); - - torture_assert_int_equal(tctx, swrap_socket(1337, 1337, 0), -1, "unknown address family fails"); - torture_assert_int_equal(tctx, errno, EAFNOSUPPORT, "correct errno set"); - torture_assert_int_equal(tctx, swrap_socket(AF_INET, 1337, 0), -1, "unknown type fails"); - torture_assert_int_equal(tctx, errno, EPROTONOSUPPORT, "correct errno set"); - torture_assert_int_equal(tctx, swrap_socket(AF_INET, SOCK_DGRAM, 10), -1, "unknown protocol fails"); - torture_assert_int_equal(tctx, errno, EPROTONOSUPPORT, "correct errno set"); - - restore_env(); - - return true; -} - -unsigned int socket_wrapper_default_iface(void); -static bool test_socket_wrapper_default_iface(struct torture_context *tctx) -{ - backup_env(); - unsetenv("SOCKET_WRAPPER_DEFAULT_IFACE"); - torture_assert_int_equal(tctx, socket_wrapper_default_iface(), 1, "unset"); - setenv("SOCKET_WRAPPER_DEFAULT_IFACE", "2", 1); - torture_assert_int_equal(tctx, socket_wrapper_default_iface(), 2, "unset"); - setenv("SOCKET_WRAPPER_DEFAULT_IFACE", "bla", 1); - torture_assert_int_equal(tctx, socket_wrapper_default_iface(), 1, "unset"); - restore_env(); - return true; -} - -struct torture_suite *torture_local_socket_wrapper(TALLOC_CTX *mem_ctx) -{ - struct torture_suite *suite = torture_suite_create(mem_ctx, - "SOCKET-WRAPPER"); - - torture_suite_add_simple_test(suite, "socket_wrapper_dir", test_socket_wrapper_dir); - torture_suite_add_simple_test(suite, "socket", test_swrap_socket); - torture_suite_add_simple_test(suite, "socket_wrapper_default_iface", test_socket_wrapper_default_iface); - - return suite; -} diff --git a/source/lib/substitute.c b/source/lib/substitute.c index acfe55d761..6c74f54649 100644 --- a/source/lib/substitute.c +++ b/source/lib/substitute.c @@ -21,6 +21,8 @@ #include "includes.h" +extern struct current_user current_user; + userdom_struct current_user_info; fstring remote_proto="UNKNOWN"; @@ -211,18 +213,11 @@ static const char *get_smb_user_name(void) /******************************************************************* Setup the strings used by substitutions. Called per packet. Ensure %U name is set correctly also. - - smb_name must be sanitized by alpha_strcpy ********************************************************************/ -void set_current_user_info(const char *smb_name, const char *unix_name, - const char *full_name, const char *domain) +void set_current_user_info(const userdom_struct *pcui) { - fstrcpy(current_user_info.smb_name, smb_name); - fstrcpy(current_user_info.unix_name, unix_name); - fstrcpy(current_user_info.full_name, full_name); - fstrcpy(current_user_info.domain, domain); - + current_user_info = *pcui; /* The following is safe as current_user_info.smb_name * has already been sanitised in register_existing_vuid. */ @@ -906,9 +901,9 @@ char *standard_sub_conn(TALLOC_CTX *ctx, connection_struct *conn, const char *st { return talloc_sub_advanced(ctx, lp_servicename(SNUM(conn)), - conn->server_info->unix_name, + conn->user, conn->connectpath, - conn->server_info->utok.gid, + conn->gid, get_smb_user_name(), "", str); diff --git a/source/lib/talloc/Makefile.in b/source/lib/talloc/Makefile.in index 07b8fd4ff0..851dc81aea 100644 --- a/source/lib/talloc/Makefile.in +++ b/source/lib/talloc/Makefile.in @@ -17,7 +17,6 @@ EXTRA_TARGETS = @DOC_TARGET@ PICFLAG = @PICFLAG@ PACKAGE_VERSION = @PACKAGE_VERSION@ SHLIBEXT = @SHLIBEXT@ -SHLD = @SHLD@ SHLD_FLAGS = @SHLD_FLAGS@ tallocdir = @tallocdir@ @@ -28,8 +27,8 @@ all:: showflags $(EXTRA_TARGETS) include $(tallocdir)/rules.mk include $(tallocdir)/talloc.mk -$(TALLOC_SOLIB): $(LIBOBJ) - $(SHLD) $(SHLD_FLAGS) -o $@ $(LIBOBJ) @SONAMEFLAG@$(TALLOC_SONAME) +$(SOLIB): $(LIBOBJ) + $(CC) $(SHLD_FLAGS) -o $@ $(LIBOBJ) @SONAMEFLAG@$(SONAME) check: test diff --git a/source/lib/talloc/NEWS b/source/lib/talloc/NEWS deleted file mode 100644 index e5b3aa0731..0000000000 --- a/source/lib/talloc/NEWS +++ /dev/null @@ -1,13 +0,0 @@ -1.0.1 26 May 2007 - - BUGS - - * Set name of correctly when using talloc_append_string() (metze) - - LICENSE - - * Change license of files in lib/replace to LGPL (was GPL). (jelmer) - -1.0.0 30 April 2007 - - Initial release. diff --git a/source/lib/talloc/config.mk b/source/lib/talloc/config.mk index c13e1b79ab..540a05d100 100644 --- a/source/lib/talloc/config.mk +++ b/source/lib/talloc/config.mk @@ -1,7 +1,8 @@ [LIBRARY::LIBTALLOC] -OUTPUT_TYPE = MERGED_OBJ +VERSION = 1.2.0 +SO_VERSION = 1 +OBJ_FILES = talloc.o +PC_FILE = talloc.pc +MANPAGE = talloc.3 CFLAGS = -Ilib/talloc - -LIBTALLOC_OBJ_FILES = lib/talloc/talloc.o - -MANPAGES += $(tallocdir)/talloc.3 +PUBLIC_HEADERS = talloc.h diff --git a/source/lib/talloc/configure.ac b/source/lib/talloc/configure.ac index 4719aa04b5..3dcf74ba25 100644 --- a/source/lib/talloc/configure.ac +++ b/source/lib/talloc/configure.ac @@ -18,7 +18,6 @@ AC_SUBST(DOC_TARGET) AC_LD_PICFLAG AC_LD_SHLIBEXT AC_LD_SONAMEFLAG -AC_LIBREPLACE_SHLD AC_LIBREPLACE_SHLD_FLAGS AC_OUTPUT(Makefile talloc.pc) diff --git a/source/lib/talloc/talloc.c b/source/lib/talloc/talloc.c index 1f7e52439f..99210f3e1b 100644 --- a/source/lib/talloc/talloc.c +++ b/source/lib/talloc/talloc.c @@ -1437,12 +1437,12 @@ char *talloc_strndup_append_buffer(char *s, const char *a, size_t n) #endif char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) -{ +{ int len; char *ret; va_list ap2; char c; - + /* this call looks strange, but it makes it work on older solaris boxes */ va_copy(ap2, ap); len = vsnprintf(&c, 1, fmt, ap2); diff --git a/source/lib/talloc/talloc.mk b/source/lib/talloc/talloc.mk index e1fe88c84b..590adc74f2 100644 --- a/source/lib/talloc/talloc.mk +++ b/source/lib/talloc/talloc.mk @@ -1,9 +1,9 @@ TALLOC_OBJ = $(tallocdir)/talloc.o -TALLOC_SOLIB = libtalloc.$(SHLIBEXT).$(PACKAGE_VERSION) -TALLOC_SONAME = libtalloc.$(SHLIBEXT).1 +SOLIB = libtalloc.$(SHLIBEXT).$(PACKAGE_VERSION) +SONAME = libtalloc.$(SHLIBEXT).1 -all:: libtalloc.a $(TALLOC_SOLIB) testsuite +all:: libtalloc.a $(SOLIB) testsuite testsuite:: $(LIBOBJ) testsuite.o $(CC) $(CFLAGS) -o testsuite testsuite.o $(LIBOBJ) $(LIBS) @@ -16,7 +16,7 @@ install:: all ${INSTALLCMD} -d $(DESTDIR)$(libdir) ${INSTALLCMD} -d $(DESTDIR)$(libdir)/pkgconfig ${INSTALLCMD} -m 755 libtalloc.a $(DESTDIR)$(libdir) - ${INSTALLCMD} -m 755 $(TALLOC_SOLIB) $(DESTDIR)$(libdir) + ${INSTALLCMD} -m 755 $(SOLIB) $(DESTDIR)$(libdir) ${INSTALLCMD} -d $(DESTDIR)${includedir} ${INSTALLCMD} -m 644 $(srcdir)/talloc.h $(DESTDIR)$(includedir) ${INSTALLCMD} -m 644 talloc.pc $(DESTDIR)$(libdir)/pkgconfig @@ -28,7 +28,7 @@ install:: all doc:: talloc.3 talloc.3.html clean:: - rm -f *~ $(LIBOBJ) $(TALLOC_SOLIB) libtalloc.a testsuite testsuite.o *.gc?? talloc.3 talloc.3.html + rm -f *~ $(LIBOBJ) $(SOLIB) libtalloc.a testsuite testsuite.o *.gc?? talloc.3 talloc.3.html test:: testsuite ./testsuite diff --git a/source/lib/talloc/testsuite.c b/source/lib/talloc/testsuite.c index 3f06eee566..fedbda95aa 100644 --- a/source/lib/talloc/testsuite.c +++ b/source/lib/talloc/testsuite.c @@ -48,8 +48,7 @@ static double timeval_elapsed(struct timeval *tv) } #define torture_assert_str_equal(test, arg1, arg2, desc) \ - if (arg1 == NULL && arg2 == NULL) { \ - } else if (strcmp(arg1, arg2)) { \ + if (strcmp(arg1, arg2)) { \ printf("failure: %s [\n%s: Expected %s, got %s: %s\n]\n", \ test, __location__, arg1, arg2, desc); \ return false; \ diff --git a/source/lib/talloc/web/index.html b/source/lib/talloc/web/index.html index 5deab93665..106920e8a5 100644 --- a/source/lib/talloc/web/index.html +++ b/source/lib/talloc/web/index.html @@ -12,7 +12,7 @@ destructors. It is the core memory allocator used in Samba4, and has made a huge difference in many aspects of Samba4 development.<p> To get started with talloc, I would recommend you read the <a -href="http://samba.org/ftp/unpacked/talloc/talloc_guide.txt">talloc guide</a>. +href="http://samba.org/ftp/unpacked/samba4/source/lib/talloc/talloc_guide.txt">talloc guide</a>. <h2>Discussion and bug reports</h2> @@ -24,16 +24,19 @@ bugzilla</a> bug tracking system. <h2>Download</h2> -You can download the latest release either via rsync or git.<br> -<br> -To fetch via git see the following guide:<br> -<a href="http://wiki.samba.org/index.php/Using_Git_for_Samba_Development">Using Git for Samba Development</a><br> -Once you have cloned the tree switch to the v4-0-test branch and cd into the source/lib/talloc directory.<br> -<br> +You can download the latest release either via rsync or anonymous +svn. To fetch via svn use the following command: + +<pre> + svn co svn://svnanon.samba.org/samba/branches/SAMBA_4_0/source/lib/talloc talloc + svn co svn://svnanon.samba.org/samba/branches/SAMBA_4_0/source/lib/replace libreplace +</pre> + To fetch via rsync use this command: <pre> - rsync -Pavz samba.org::ftp/unpacked/talloc . + rsync -Pavz samba.org::ftp/unpacked/samba4/source/lib/talloc . + rsync -Pavz samba.org::ftp/unpacked/samba4/source/lib/libreplace . </pre> <hr> diff --git a/source/lib/tdb/Makefile.in b/source/lib/tdb/Makefile.in index 090bb6e2dc..fd36ed078e 100644 --- a/source/lib/tdb/Makefile.in +++ b/source/lib/tdb/Makefile.in @@ -16,44 +16,97 @@ CPPFLAGS = @CPPFLAGS@ -I$(srcdir)/include -Iinclude CFLAGS = $(CPPFLAGS) @CFLAGS@ LDFLAGS = @LDFLAGS@ EXEEXT = @EXEEXT@ -SHLD = @SHLD@ SHLD_FLAGS = @SHLD_FLAGS@ PACKAGE_VERSION = @PACKAGE_VERSION@ PICFLAG = @PICFLAG@ +SONAMEFLAG = @SONAMEFLAG@ SHLIBEXT = @SHLIBEXT@ -SWIG = swig -PYTHON = @PYTHON@ -PYTHON_CONFIG = @PYTHON_CONFIG@ -PYTHON_BUILD_TARGET = @PYTHON_BUILD_TARGET@ -PYTHON_INSTALL_TARGET = @PYTHON_INSTALL_TARGET@ -PYTHON_CHECK_TARGET = @PYTHON_CHECK_TARGET@ -LIB_PATH_VAR = @LIB_PATH_VAR@ -tdbdir = @tdbdir@ + +.PHONY: test + +PROGS = bin/tdbtool$(EXEEXT) bin/tdbdump$(EXEEXT) bin/tdbbackup$(EXEEXT) +PROGS_NOINSTALL = bin/tdbtest$(EXEEXT) bin/tdbtorture$(EXEEXT) +ALL_PROGS = $(PROGS) $(PROGS_NOINSTALL) TDB_OBJ = @TDB_OBJ@ @LIBREPLACEOBJ@ -default: all +DIRS = bin common tools + +SONAME = libtdb.$(SHLIBEXT).1 +SOLIB = libtdb.$(SHLIBEXT).$(PACKAGE_VERSION) + +all: showflags dirs $(PROGS) $(SOLIB) libtdb.a + +showflags: + @echo 'tdb will be compiled with flags:' + @echo ' CFLAGS = $(CFLAGS)' + @echo ' CPPFLAGS = $(CPPFLAGS)' + @echo ' LDFLAGS = $(LDFLAGS)' + @echo ' LIBS = $(LIBS)' + +.SUFFIXES: .c .o + +.c.o: + @echo Compiling $*.c + @mkdir -p `dirname $@` + @$(CC) $(PICFLAG) $(CFLAGS) -c $< -o $@ + +dirs: + @mkdir -p $(DIRS) + +install: all + mkdir -p $(DESTDIR)$(bindir) + mkdir -p $(DESTDIR)$(includedir) + mkdir -p $(DESTDIR)$(libdir) + mkdir -p $(DESTDIR)$(libdir)/pkgconfig + cp $(PROGS) $(DESTDIR)$(bindir) + cp $(srcdir)/include/tdb.h $(DESTDIR)$(includedir) + cp tdb.pc $(DESTDIR)$(libdir)/pkgconfig + cp libtdb.a $(SOLIB) $(DESTDIR)$(libdir) + +libtdb.a: $(TDB_OBJ) + ar -rv libtdb.a $(TDB_OBJ) + +libtdb.(SHLIBEXT): $(SOLIB) + ln -s $< $@ + +$(SONAME): $(SOLIB) + ln -s $< $@ + +$(SOLIB): $(TDB_OBJ) + $(CC) $(SHLD_FLAGS) -o $@ $(TDB_OBJ) $(SONAMEFLAG)$(SONAME) + +TDB_LIB = libtdb.a + +bin/tdbtest$(EXEEXT): tools/tdbtest.o $(TDB_LIB) + $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtest tools/tdbtest.o -L. -ltdb -lgdbm + +bin/tdbtool$(EXEEXT): tools/tdbtool.o $(TDB_LIB) + $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtool tools/tdbtool.o -L. -ltdb -include $(tdbdir)/tdb.mk -include $(tdbdir)/rules.mk +bin/tdbtorture$(EXEEXT): tools/tdbtorture.o $(TDB_LIB) + $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtorture tools/tdbtorture.o -L. -ltdb -all:: showflags dirs $(PROGS) $(TDB_SOLIB) libtdb.a $(PYTHON_BUILD_TARGET) +bin/tdbdump$(EXEEXT): tools/tdbdump.o $(TDB_LIB) + $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbdump tools/tdbdump.o -L. -ltdb -install:: all -$(TDB_SOLIB): $(TDB_OBJ) - $(SHLD) $(SHLD_FLAGS) -o $@ $(TDB_OBJ) @SONAMEFLAG@$(TDB_SONAME) +bin/tdbbackup$(EXEEXT): tools/tdbbackup.o $(TDB_LIB) + $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbbackup tools/tdbbackup.o -L. -ltdb -check: test +test: bin/tdbtorture$(EXEEXT) + bin/tdbtorture$(EXEEXT) -test:: $(PYTHON_CHECK_TARGET) -installcheck:: test install +installcheck: test install -clean:: - rm -f *.o *.a */*.o +clean: + rm -f $(ALL_PROGS) *.o *.a common/*.o tools/*.o tdb.pc + rm -f test.db test.tdb torture.tdb test.gdbm + rm -f $(SONAME) $(SOLIB) libtdb.a -distclean:: clean +distclean: clean + rm -f *~ */*~ rm -f config.log config.status include/config.h config.cache rm -f Makefile -realdistclean:: distclean +realdistclean: distclean rm -f configure include/config.h.in diff --git a/source/lib/tdb/autogen.sh b/source/lib/tdb/autogen.sh index 88ac4cfcf7..bf84eeee19 100755 --- a/source/lib/tdb/autogen.sh +++ b/source/lib/tdb/autogen.sh @@ -9,8 +9,6 @@ autoheader $IPATHS || exit 1 rm -rf autom4te.cache -swig -O -Wall -python -keyword tdb.i # Ignore errors for now - echo "Now run ./configure and then make." exit 0 diff --git a/source/lib/tdb/config.mk b/source/lib/tdb/config.mk index b9a8f80dda..01a23f00de 100644 --- a/source/lib/tdb/config.mk +++ b/source/lib/tdb/config.mk @@ -1,57 +1,68 @@ ################################################ # Start SUBSYSTEM LIBTDB [LIBRARY::LIBTDB] -OUTPUT_TYPE = STATIC_LIBRARY +VERSION = 0.0.1 +SO_VERSION = 0 +PC_FILE = tdb.pc +OBJ_FILES = \ + common/tdb.o common/dump.o common/io.o common/lock.o \ + common/open.o common/traverse.o common/freelist.o \ + common/error.o common/transaction.o CFLAGS = -Ilib/tdb/include +PUBLIC_HEADERS = include/tdb.h # # End SUBSYSTEM ldb ################################################ -LIBTDB_OBJ_FILES = $(addprefix lib/tdb/common/, \ - tdb.o dump.o io.o lock.o \ - open.o traverse.o freelist.o \ - error.o transaction.o) - ################################################ # Start BINARY tdbtool [BINARY::tdbtool] INSTALLDIR = BINDIR +OBJ_FILES= \ + tools/tdbtool.o PRIVATE_DEPENDENCIES = \ LIBTDB # End BINARY tdbtool ################################################ -tdbtool_OBJ_FILES = lib/tdb/tools/tdbtool.o - ################################################ # Start BINARY tdbtorture [BINARY::tdbtorture] INSTALLDIR = BINDIR +OBJ_FILES= \ + tools/tdbtorture.o PRIVATE_DEPENDENCIES = \ LIBTDB # End BINARY tdbtorture ################################################ -tdbtorture_OBJ_FILES = lib/tdb/tools/tdbtorture.o - ################################################ # Start BINARY tdbdump [BINARY::tdbdump] INSTALLDIR = BINDIR +OBJ_FILES= \ + tools/tdbdump.o PRIVATE_DEPENDENCIES = \ LIBTDB # End BINARY tdbdump ################################################ -tdbdump_OBJ_FILES = lib/tdb/tools/tdbdump.o - ################################################ # Start BINARY tdbbackup [BINARY::tdbbackup] INSTALLDIR = BINDIR +OBJ_FILES= \ + tools/tdbbackup.o PRIVATE_DEPENDENCIES = \ LIBTDB # End BINARY tdbbackup ################################################ -tdbbackup_OBJ_FILES = lib/tdb/tools/tdbbackup.o +####################### +# Start LIBRARY swig_tdb +[LIBRARY::swig_tdb] +LIBRARY_REALNAME = swig/_tdb.$(SHLIBEXT) +OBJ_FILES = swig/tdb_wrap.o +PUBLIC_DEPENDENCIES = LIBTDB DYNCONFIG +# End LIBRARY swig_tdb +####################### diff --git a/source/lib/tdb/configure.ac b/source/lib/tdb/configure.ac index eaf70d30b4..14761bcc1a 100644 --- a/source/lib/tdb/configure.ac +++ b/source/lib/tdb/configure.ac @@ -2,29 +2,13 @@ AC_PREREQ(2.50) AC_DEFUN([SMB_MODULE_DEFAULT], [echo -n ""]) AC_DEFUN([SMB_LIBRARY_ENABLE], [echo -n ""]) AC_DEFUN([SMB_ENABLE], [echo -n ""]) -AC_INIT(tdb, 1.1.2) +AC_INIT(tdb, 1.1.1) AC_CONFIG_SRCDIR([common/tdb.c]) AC_CONFIG_HEADER(include/config.h) AC_LIBREPLACE_ALL_CHECKS AC_LD_SONAMEFLAG AC_LD_PICFLAG AC_LD_SHLIBEXT -AC_LIBREPLACE_SHLD AC_LIBREPLACE_SHLD_FLAGS -AC_LIBREPLACE_RUNTIME_LIB_PATH_VAR m4_include(libtdb.m4) -AC_PATH_PROGS([PYTHON_CONFIG], [python2.6-config python2.5-config python2.4-config python-config]) -AC_PATH_PROGS([PYTHON], [python2.6 python2.5 python2.4 python]) - -PYTHON_BUILD_TARGET="build-python" -PYTHON_INSTALL_TARGET="install-python" -PYTHON_CHECK_TARGET="check-python" -AC_SUBST(PYTHON_BUILD_TARGET) -AC_SUBST(PYTHON_INSTALL_TARGET) -AC_SUBST(PYTHON_CHECK_TARGET) -if test -z "$PYTHON_CONFIG"; then - PYTHON_BUILD_TARGET="" - PYTHON_INSTALL_TARGET="" - PYTHON_CHECK_TARGET="" -fi AC_OUTPUT(Makefile tdb.pc) diff --git a/source/lib/tdb/libtdb.m4 b/source/lib/tdb/libtdb.m4 index 1e17a7a4f2..7682edada9 100644 --- a/source/lib/tdb/libtdb.m4 +++ b/source/lib/tdb/libtdb.m4 @@ -28,3 +28,35 @@ AC_CHECK_HEADERS(getopt.h sys/select.h sys/time.h) AC_HAVE_DECL(pread, [#include <unistd.h>]) AC_HAVE_DECL(pwrite, [#include <unistd.h>]) + +AC_MSG_CHECKING([for Python]) + +PYTHON= + +AC_ARG_WITH(python, +[ --with-python=PYTHONNAME build Python libraries], +[ case "${withval-python}" in + yes) + PYTHON=python + ;; + no) + PYTHON= + ;; + *) + PYTHON=${withval-python} + ;; + esac ]) + +if test x"$PYTHON" != "x"; then + incdir=`python -c 'import sys; print "%s/include/python%d.%d" % (sys.prefix, sys.version_info[[0]], sys.version_info[[1]])'` + CPPFLAGS="$CPPFLAGS -I $incdir" +fi + +if test x"$PYTHON" != "x"; then + AC_MSG_RESULT([${withval-python}]) +else + SMB_ENABLE(swig_tdb, NO) + AC_MSG_RESULT(no) +fi + +AC_SUBST(PYTHON) diff --git a/source/lib/tdb/python.mk b/source/lib/tdb/python.mk deleted file mode 100644 index 12e8217df9..0000000000 --- a/source/lib/tdb/python.mk +++ /dev/null @@ -1,10 +0,0 @@ -[PYTHON::swig_tdb] -LIBRARY_REALNAME = _tdb.$(SHLIBEXT) -PUBLIC_DEPENDENCIES = LIBTDB DYNCONFIG - -swig_tdb_OBJ_FILES = $(tdbsrcdir)/tdb_wrap.o - -$(eval $(call python_py_module_template,tdb.py,$(tdbsrcdir)/tdb.py)) - -$(swig_tdb_OBJ_FILES): CFLAGS+=$(CFLAG_NO_UNUSED_MACROS) $(CFLAG_NO_CAST_QUAL) - diff --git a/source/lib/tdb/python/tdbdump.py b/source/lib/tdb/python/tdbdump.py deleted file mode 100644 index d759d771c8..0000000000 --- a/source/lib/tdb/python/tdbdump.py +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/python -# Trivial reimplementation of tdbdump in Python - -import tdb, sys - -if len(sys.argv) < 2: - print "Usage: tdbdump.py <tdb-file>" - sys.exit(1) - -db = tdb.Tdb(sys.argv[1]) -for (k, v) in db.iteritems(): - print "{\nkey(%d) = %r\ndata(%d) = %r\n}" % (len(k), k, len(v), v) diff --git a/source/lib/tdb/python/tests/simple.py b/source/lib/tdb/python/tests/simple.py deleted file mode 100644 index 7147718c91..0000000000 --- a/source/lib/tdb/python/tests/simple.py +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/bin/python -# Some simple tests for the Python bindings for TDB -# Note that this tests the interface of the Python bindings -# It does not test tdb itself. -# -# Copyright (C) 2007-2008 Jelmer Vernooij <jelmer@samba.org> -# Published under the GNU LGPLv3 or later - -import tdb -from unittest import TestCase -import os, tempfile - - -class OpenTdbTests(TestCase): - def test_nonexistant_read(self): - self.assertRaises(IOError, tdb.Tdb, "/some/nonexistant/file", 0, tdb.DEFAULT, os.O_RDWR) - - -class SimpleTdbTests(TestCase): - def setUp(self): - super(SimpleTdbTests, self).setUp() - self.tdb = tdb.Tdb(tempfile.mkstemp()[1], 0, tdb.DEFAULT, os.O_CREAT|os.O_RDWR) - self.assertNotEqual(None, self.tdb) - - def tearDown(self): - del self.tdb - - def test_repr(self): - self.assertTrue(repr(self.tdb).startswith("Tdb('")) - - def test_lockall(self): - self.tdb.lock_all() - - def test_max_dead(self): - self.tdb.max_dead = 20 - - def test_unlockall(self): - self.tdb.lock_all() - self.tdb.unlock_all() - - def test_lockall_read(self): - self.tdb.read_lock_all() - self.tdb.read_unlock_all() - - def test_reopen(self): - self.tdb.reopen() - - def test_store(self): - self.tdb.store("bar", "bla") - self.assertEquals("bla", self.tdb.get("bar")) - - def test_getitem(self): - self.tdb["bar"] = "foo" - self.tdb.reopen() - self.assertEquals("foo", self.tdb["bar"]) - - def test_delete(self): - self.tdb["bar"] = "foo" - del self.tdb["bar"] - self.assertRaises(KeyError, lambda: self.tdb["bar"]) - - def test_contains(self): - self.tdb["bla"] = "bloe" - self.assertTrue("bla" in self.tdb) - - def test_keyerror(self): - self.assertRaises(KeyError, lambda: self.tdb["bla"]) - - def test_hash_size(self): - self.tdb.hash_size - - def test_map_size(self): - self.tdb.map_size - - def test_name(self): - self.tdb.name - - def test_iterator(self): - self.tdb["bla"] = "1" - self.tdb["brainslug"] = "2" - self.assertEquals(["bla", "brainslug"], list(self.tdb)) - - def test_items(self): - self.tdb["bla"] = "1" - self.tdb["brainslug"] = "2" - self.assertEquals([("bla", "1"), ("brainslug", "2")], self.tdb.items()) - - def test_iteritems(self): - self.tdb["bloe"] = "2" - self.tdb["bla"] = "25" - i = self.tdb.iteritems() - self.assertEquals(set([("bla", "25"), ("bloe", "2")]), - set([i.next(), i.next()])) - - def test_transaction_cancel(self): - self.tdb["bloe"] = "2" - self.tdb.transaction_start() - self.tdb["bloe"] = "1" - self.tdb.transaction_cancel() - self.assertEquals("2", self.tdb["bloe"]) - - def test_transaction_commit(self): - self.tdb["bloe"] = "2" - self.tdb.transaction_start() - self.tdb["bloe"] = "1" - self.tdb.transaction_commit() - self.assertEquals("1", self.tdb["bloe"]) - - def test_iterator(self): - self.tdb["bloe"] = "2" - self.tdb["bla"] = "hoi" - i = iter(self.tdb) - self.assertEquals(set(["bloe", "bla"]), set([i.next(), i.next()])) - - def test_keys(self): - self.tdb["bloe"] = "2" - self.tdb["bla"] = "25" - self.assertEquals(["bla", "bloe"], self.tdb.keys()) - - def test_iterkeys(self): - self.tdb["bloe"] = "2" - self.tdb["bla"] = "25" - i = self.tdb.iterkeys() - self.assertEquals(set(["bloe", "bla"]), set([i.next(), i.next()])) - - def test_values(self): - self.tdb["bloe"] = "2" - self.tdb["bla"] = "25" - self.assertEquals(["25", "2"], self.tdb.values()) - - def test_itervalues(self): - self.tdb["bloe"] = "2" - self.tdb["bla"] = "25" - i = self.tdb.itervalues() - self.assertEquals(set(["25", "2"]), set([i.next(), i.next()])) - - def test_clear(self): - self.tdb["bloe"] = "2" - self.tdb["bla"] = "25" - self.assertEquals(2, len(self.tdb)) - self.tdb.clear() - self.assertEquals(0, len(self.tdb)) - - def test_len(self): - self.assertEquals(0, len(self.tdb)) - self.tdb["entry"] = "value" - self.assertEquals(1, len(self.tdb)) - - -if __name__ == '__main__': - import unittest - unittest.TestProgram() diff --git a/source/lib/tdb/rules.mk b/source/lib/tdb/rules.mk deleted file mode 100644 index 7b765625df..0000000000 --- a/source/lib/tdb/rules.mk +++ /dev/null @@ -1,21 +0,0 @@ -.SUFFIXES: .i _wrap.c - -.i_wrap.c: - $(SWIG) -O -Wall -python -keyword $< - -showflags:: - @echo 'tdb will be compiled with flags:' - @echo ' CFLAGS = $(CFLAGS)' - @echo ' CPPFLAGS = $(CPPFLAGS)' - @echo ' LDFLAGS = $(LDFLAGS)' - @echo ' LIBS = $(LIBS)' - -.SUFFIXES: .c .o - -.c.o: - @echo Compiling $*.c - @mkdir -p `dirname $@` - @$(CC) $(PICFLAG) $(CFLAGS) -c $< -o $@ - -distclean:: - rm -f *~ */*~ diff --git a/source/lib/tdb/swig/Tdb.py b/source/lib/tdb/swig/Tdb.py new file mode 100644 index 0000000000..529d0753d1 --- /dev/null +++ b/source/lib/tdb/swig/Tdb.py @@ -0,0 +1,115 @@ +"""Provide a more Pythonic and object-oriented interface to tdb.""" + +# +# Swig interface to Samba +# +# Copyright (C) Tim Potter 2006 +# +# 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 <http://www.gnu.org/licenses/>. +# + +import os +from tdb import * + +# Open flags + +DEFAULT = TDB_DEFAULT +CLEAR_IF_FIRST = TDB_CLEAR_IF_FIRST +INTERNAL = TDB_INTERNAL +NOLOCK = TDB_NOLOCK +NOMMAP = TDB_NOMMAP + +# Class representing a TDB file + +class Tdb: + + # Create and destroy Tdb objects + + def __init__(self, name, hash_size = 0, flags = TDB_DEFAULT, + open_flags = os.O_RDWR | os.O_CREAT, mode = 0600): + self.tdb = tdb_open(name, hash_size, flags, open_flags, mode) + if self.tdb is None: + raise IOError, tdb_errorstr(self.tdb) + + def __del__(self): + self.close() + + def close(self): + if hasattr(self, 'tdb') and self.tdb is not None: + if tdb_close(self.tdb) == -1: + raise IOError, tdb_errorstr(self.tdb) + self.tdb = None + + # Random access to keys, values + + def __getitem__(self, key): + result = tdb_fetch(self.tdb, key) + if result is None: + raise KeyError, '%s: %s' % (key, tdb_errorstr(self.tdb)) + return result + + def __setitem__(self, key, item): + if tdb_store(self.tdb, key, item) == -1: + raise IOError, tdb_errorstr(self.tdb) + + def __delitem__(self, key): + if not tdb_exists(self.tdb, key): + raise KeyError, '%s: %s' % (key, tdb_errorstr(self.tdb)) + tdb_delete(self.tdb, key) + + def has_key(self, key): + return tdb_exists(self.tdb, key) + + # Tdb iterator + + class TdbIterator: + def __init__(self, tdb): + self.tdb = tdb + self.key = None + + def __iter__(self): + return self + + def next(self): + if self.key is None: + self.key = tdb_firstkey(self.tdb) + if self.key is None: + raise StopIteration + return self.key + else: + self.key = tdb_nextkey(self.tdb, self.key) + if self.key is None: + raise StopIteration + return self.key + + def __iter__(self): + return Tdb.TdbIterator(self.tdb) + + # Implement other dict functions using TdbIterator + + def keys(self): + return [k for k in iter(self)] + + def values(self): + return [self[k] for k in iter(self)] + + def items(self): + return [(k, self[k]) for k in iter(self)] + + def __len__(self): + return len(self.keys()) + + def clear(self): + for k in iter(self): + del(self[k]) diff --git a/source/lib/tdb/swig/tdb.i b/source/lib/tdb/swig/tdb.i new file mode 100644 index 0000000000..fbb0f29dec --- /dev/null +++ b/source/lib/tdb/swig/tdb.i @@ -0,0 +1,167 @@ +/* + Unix SMB/CIFS implementation. + + Swig interface to tdb. + + Copyright (C) 2004,2005 Tim Potter <tpot@samba.org> + + ** NOTE! The following LGPL license applies to the tdb + ** library. This does NOT imply that all of Samba is released + ** under the LGPL + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +%module tdb + +%{ + +/* This symbol is used in both includes.h and Python.h which causes an + annoying compiler warning. */ + +#ifdef HAVE_FSTAT +#undef HAVE_FSTAT +#endif + +#if (__GNUC__ >= 3) +/** Use gcc attribute to check printf fns. a1 is the 1-based index of + * the parameter containing the format, and a2 the index of the first + * argument. Note that some gcc 2.x versions don't handle this + * properly **/ +#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2))) +#else +#define PRINTF_ATTRIBUTE(a1, a2) +#endif + +/* Include tdb headers */ + +#include "lib/tdb/include/tdb.h" + +%} + +/* The tdb functions will crash if a NULL tdb context is passed */ + +%include exception.i + +%typemap(check) TDB_CONTEXT* { + if ($1 == NULL) + SWIG_exception(SWIG_ValueError, + "tdb context must be non-NULL"); +} + +/* In and out typemaps for the TDB_DATA structure. This is converted to + and from the Python string type which can contain arbitrary binary + data.. */ + +%typemap(in) TDB_DATA { + if (!PyString_Check($input)) { + PyErr_SetString(PyExc_TypeError, "string arg expected"); + return NULL; + } + $1.dsize = PyString_Size($input); + $1.dptr = PyString_AsString($input); +} + +%typemap(out) TDB_DATA { + if ($1.dptr == NULL && $1.dsize == 0) { + $result = Py_None; + } else { + $result = PyString_FromStringAndSize($1.dptr, $1.dsize); + free($1.dptr); + } +} + +/* Treat a mode_t as an unsigned integer */ + +typedef int mode_t; + +/* flags to tdb_store() */ + +#define TDB_REPLACE 1 +#define TDB_INSERT 2 +#define TDB_MODIFY 3 + +/* flags for tdb_open() */ + +#define TDB_DEFAULT 0 /* just a readability place holder */ +#define TDB_CLEAR_IF_FIRST 1 +#define TDB_INTERNAL 2 /* don't store on disk */ +#define TDB_NOLOCK 4 /* don't do any locking */ +#define TDB_NOMMAP 8 /* don't use mmap */ +#define TDB_CONVERT 16 /* convert endian (internal use) */ +#define TDB_BIGENDIAN 32 /* header is big-endian (internal use) */ + +/* Throw an IOError exception if tdb_open() or tdb_open_ex() returns NULL */ + +%exception { + $action + if (result == NULL) { + PyErr_SetFromErrno(PyExc_IOError); + SWIG_fail; + } +} + +TDB_CONTEXT *tdb_open(const char *name, int hash_size, int tdb_flags, + int open_flags, mode_t mode); + +TDB_CONTEXT *tdb_open_ex(const char *name, int hash_size, int tdb_flags, + int open_flags, mode_t mode, + tdb_log_func log_fn, + tdb_hash_func hash_fn); + +%exception; + +int tdb_reopen(TDB_CONTEXT *tdb); + +int tdb_reopen_all(int parent_longlived); + +void tdb_logging_function(TDB_CONTEXT *tdb, tdb_log_func); + +enum TDB_ERROR tdb_error(TDB_CONTEXT *tdb); + +const char *tdb_errorstr(TDB_CONTEXT *tdb); + +TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key); + +int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key); + +int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag = TDB_REPLACE); + +int tdb_append(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA new_dbuf); + +int tdb_close(TDB_CONTEXT *tdb); + +TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb); + +TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA key); + +int tdb_traverse(TDB_CONTEXT *tdb, tdb_traverse_func fn, void *state); + +int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key); + +int tdb_lockall(TDB_CONTEXT *tdb); + +void tdb_unlockall(TDB_CONTEXT *tdb); + +/* Low level locking functions: use with care */ + +int tdb_chainlock(TDB_CONTEXT *tdb, TDB_DATA key); + +int tdb_chainunlock(TDB_CONTEXT *tdb, TDB_DATA key); + +/* Debug functions. Not used in production. */ + +void tdb_dump_all(TDB_CONTEXT *tdb); + +int tdb_printfreelist(TDB_CONTEXT *tdb); diff --git a/source/lib/tdb/tdb.i b/source/lib/tdb/tdb.i deleted file mode 100644 index 3d8b697732..0000000000 --- a/source/lib/tdb/tdb.i +++ /dev/null @@ -1,323 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - Swig interface to tdb. - - Copyright (C) 2004-2006 Tim Potter <tpot@samba.org> - Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org> - - ** NOTE! The following LGPL license applies to the tdb - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see <http://www.gnu.org/licenses/>. -*/ - -%define DOCSTRING -"TDB is a simple key-value database similar to GDBM that supports multiple writers." -%enddef - -%module(docstring=DOCSTRING) tdb - -%{ - -/* This symbol is used in both includes.h and Python.h which causes an - annoying compiler warning. */ - -#ifdef HAVE_FSTAT -#undef HAVE_FSTAT -#endif - -/* Include tdb headers */ -#include <stdint.h> -#include <signal.h> -#include <tdb.h> -#include <fcntl.h> - -typedef TDB_CONTEXT tdb; -%} - -/* The tdb functions will crash if a NULL tdb context is passed */ - -%import exception.i -%import stdint.i - -%typemap(check,noblock=1) TDB_CONTEXT* { - if ($1 == NULL) - SWIG_exception(SWIG_ValueError, - "tdb context must be non-NULL"); -} - -/* In and out typemaps for the TDB_DATA structure. This is converted to - and from the Python string type which can contain arbitrary binary - data.. */ - -%typemap(in,noblock=1) TDB_DATA { - if ($input == Py_None) { - $1.dsize = 0; - $1.dptr = NULL; - } else if (!PyString_Check($input)) { - PyErr_SetString(PyExc_TypeError, "string arg expected"); - return NULL; - } else { - $1.dsize = PyString_Size($input); - $1.dptr = (uint8_t *)PyString_AsString($input); - } -} - -%typemap(out,noblock=1) TDB_DATA { - if ($1.dptr == NULL && $1.dsize == 0) { - $result = Py_None; - } else { - $result = PyString_FromStringAndSize((const char *)$1.dptr, $1.dsize); - free($1.dptr); - } -} - -/* Treat a mode_t as an unsigned integer */ -typedef int mode_t; - -/* flags to tdb_store() */ -%constant int REPLACE = TDB_REPLACE; -%constant int INSERT = TDB_INSERT; -%constant int MODIFY = TDB_MODIFY; - -/* flags for tdb_open() */ -%constant int DEFAULT = TDB_DEFAULT; -%constant int CLEAR_IF_FIRST = TDB_CLEAR_IF_FIRST; -%constant int INTERNAL = TDB_INTERNAL; -%constant int NOLOCK = TDB_NOLOCK; -%constant int NOMMAP = TDB_NOMMAP; -%constant int CONVERT = TDB_CONVERT; -%constant int BIGENDIAN = TDB_BIGENDIAN; - -enum TDB_ERROR { - TDB_SUCCESS=0, - TDB_ERR_CORRUPT, - TDB_ERR_IO, - TDB_ERR_LOCK, - TDB_ERR_OOM, - TDB_ERR_EXISTS, - TDB_ERR_NOLOCK, - TDB_ERR_LOCK_TIMEOUT, - TDB_ERR_NOEXIST, - TDB_ERR_EINVAL, - TDB_ERR_RDONLY -}; - -%rename(lock_all) tdb_context::lockall; -%rename(unlock_all) tdb_context::unlockall; - -%rename(read_lock_all) tdb_context::lockall_read; -%rename(read_unlock_all) tdb_context::unlockall_read; - -%typemap(default,noblock=1) int tdb_flags { - $1 = TDB_DEFAULT; -} - -%typemap(default,noblock=1) int flags { - $1 = O_RDWR; -} - -%typemap(default,noblock=1) int hash_size { - $1 = 0; -} - -%typemap(default,noblock=1) mode_t mode { - $1 = 0600; -} - -%typemap(default,noblock=1) int flag { - $1 = TDB_REPLACE; -} - -%rename(Tdb) tdb_context; -%feature("docstring") tdb_context "A TDB file."; -%typemap(out,noblock=1) tdb * { - /* Throw an IOError exception from errno if tdb_open() returns NULL */ - if ($1 == NULL) { - PyErr_SetFromErrno(PyExc_IOError); - SWIG_fail; - } - $result = SWIG_NewPointerObj($1, $1_descriptor, 0); -} - -typedef struct tdb_context { - %extend { - %feature("docstring") tdb "S.__init__(name,hash_size=0,tdb_flags=TDB_DEFAULT,flags=O_RDWR,mode=0600)\n" - "Open a TDB file."; - tdb(const char *name, int hash_size, int tdb_flags, int flags, mode_t mode) { - return tdb_open(name, hash_size, tdb_flags, flags, mode); - } - %feature("docstring") error "S.error() -> int\n" - "Find last error number returned by operation on this TDB."; - enum TDB_ERROR error(); - ~tdb() { tdb_close($self); } - %feature("docstring") close "S.close() -> None\n" - "Close the TDB file."; - int close(); - int append(TDB_DATA key, TDB_DATA new_dbuf); - %feature("docstring") errorstr "S.errorstr() -> errorstring\n" - "Obtain last error message."; - const char *errorstr(); - %rename(get) fetch; - %feature("docstring") fetch "S.fetch(key) -> value\n" - "Fetch a value."; - TDB_DATA fetch(TDB_DATA key); - %feature("docstring") delete "S.delete(key) -> None\n" - "Delete an entry."; - int delete(TDB_DATA key); - %feature("docstring") store "S.store(key, value, flag=TDB_REPLACE) -> None\n" - "Store an entry."; - int store(TDB_DATA key, TDB_DATA dbuf, int flag); - %feature("docstring") exists "S.exists(key) -> bool\n" - "Check whether key exists in this database."; - int exists(TDB_DATA key); - %feature("docstring") firstkey "S.firstkey() -> data\n" - "Return the first key in this database."; - TDB_DATA firstkey(); - %feature("docstring") nextkey "S.nextkey(prev) -> data\n" - "Return the next key in this database."; - TDB_DATA nextkey(TDB_DATA key); - %feature("docstring") lockall "S.lockall() -> bool"; - int lockall(); - %feature("docstring") unlockall "S.unlockall() -> bool"; - int unlockall(); - %feature("docstring") unlockall "S.lockall_read() -> bool"; - int lockall_read(); - %feature("docstring") unlockall "S.unlockall_read() -> bool"; - int unlockall_read(); - %feature("docstring") reopen "S.reopen() -> bool\n" - "Reopen this file."; - int reopen(); - %feature("docstring") transaction_start "S.transaction_start() -> None\n" - "Start a new transaction."; - int transaction_start(); - %feature("docstring") transaction_commit "S.transaction_commit() -> None\n" - "Commit the currently active transaction."; - int transaction_commit(); - %feature("docstring") transaction_cancel "S.transaction_cancel() -> None\n" - "Cancel the currently active transaction."; - int transaction_cancel(); - int transaction_recover(); - %feature("docstring") hash_size "S.hash_size() -> int"; - int hash_size(); - %feature("docstring") map_size "S.map_size() -> int"; - size_t map_size(); - %feature("docstring") get_flags "S.get_flags() -> int"; - int get_flags(); - %feature("docstring") set_max_dead "S.set_max_dead(int) -> None"; - void set_max_dead(int max_dead); - %feature("docstring") name "S.name() -> path\n" \ - "Return filename of this TDB file."; - const char *name(); - } - - %pythoncode { - def __repr__(self): - return "Tdb('%s')" % self.name() - - # Random access to keys, values - def __getitem__(self, key): - result = self.get(key) - if result is None: - raise KeyError, '%s: %s' % (key, self.errorstr()) - return result - - def __setitem__(self, key, item): - if self.store(key, item) == -1: - raise IOError, self.errorstr() - - def __delitem__(self, key): - if not self.exists(key): - raise KeyError, '%s: %s' % (key, self.errorstr()) - self.delete(key) - - def __contains__(self, key): - return self.exists(key) != 0 - - def has_key(self, key): - return self.exists(key) != 0 - - def fetch_uint32(self, key): - data = self.get(key) - if data is None: - return None - import struct - return struct.unpack("<L", data)[0] - - def fetch_int32(self, key): - data = self.get(key) - if data is None: - return None - import struct - return struct.unpack("<l", data)[0] - - # Tdb iterator - class TdbIterator: - def __init__(self, tdb): - self.tdb = tdb - self.key = None - - def __iter__(self): - return self - - def next(self): - if self.key is None: - self.key = self.tdb.firstkey() - if self.key is None: - raise StopIteration - return self.key - else: - self.key = self.tdb.nextkey(self.key) - if self.key is None: - raise StopIteration - return self.key - - def __iter__(self): - return self.TdbIterator(self) - - # Implement other dict functions using TdbIterator - - def keys(self): - return [k for k in iter(self)] - - def values(self): - return [self[k] for k in iter(self)] - - def items(self): - return [(k, self[k]) for k in iter(self)] - - def __len__(self): - return len(self.keys()) - - def clear(self): - for k in iter(self): - del(self[k]) - - def iterkeys(self): - for k in iter(self): - yield k - - def itervalues(self): - for k in iter(self): - yield self[k] - - def iteritems(self): - for k in iter(self): - yield (k, self[k]) - - # TODO: any other missing methods for container types - } -} tdb; diff --git a/source/lib/tdb/tdb.mk b/source/lib/tdb/tdb.mk deleted file mode 100644 index fa8db6d34c..0000000000 --- a/source/lib/tdb/tdb.mk +++ /dev/null @@ -1,86 +0,0 @@ -dirs:: - @mkdir -p bin common tools - -PROGS = bin/tdbtool$(EXEEXT) bin/tdbdump$(EXEEXT) bin/tdbbackup$(EXEEXT) -PROGS_NOINSTALL = bin/tdbtest$(EXEEXT) bin/tdbtorture$(EXEEXT) -ALL_PROGS = $(PROGS) $(PROGS_NOINSTALL) - -TDB_SONAME = libtdb.$(SHLIBEXT).1 -TDB_SOLIB = libtdb.$(SHLIBEXT).$(PACKAGE_VERSION) - -TDB_LIB = libtdb.a - -bin/tdbtest$(EXEEXT): tools/tdbtest.o $(TDB_LIB) - $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtest tools/tdbtest.o -L. -ltdb -lgdbm - -bin/tdbtool$(EXEEXT): tools/tdbtool.o $(TDB_LIB) - $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtool tools/tdbtool.o -L. -ltdb - -bin/tdbtorture$(EXEEXT): tools/tdbtorture.o $(TDB_LIB) - $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtorture tools/tdbtorture.o -L. -ltdb - -bin/tdbdump$(EXEEXT): tools/tdbdump.o $(TDB_LIB) - $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbdump tools/tdbdump.o -L. -ltdb - -bin/tdbbackup$(EXEEXT): tools/tdbbackup.o $(TDB_LIB) - $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbbackup tools/tdbbackup.o -L. -ltdb - -test:: bin/tdbtorture$(EXEEXT) $(TDB_SONAME) - $(LIB_PATH_VAR)=. bin/tdbtorture$(EXEEXT) - -clean:: - rm -f test.db test.tdb torture.tdb test.gdbm - rm -f $(TDB_SONAME) $(TDB_SOLIB) libtdb.a libtdb.$(SHLIBEXT) - rm -f $(ALL_PROGS) tdb.pc - -build-python:: _tdb.$(SHLIBEXT) - -tdb_wrap.o: $(tdbdir)/tdb_wrap.c - $(CC) $(PICFLAG) -c $(tdbdir)/tdb_wrap.c $(CFLAGS) `$(PYTHON_CONFIG) --cflags` - -_tdb.$(SHLIBEXT): libtdb.$(SHLIBEXT) tdb_wrap.o - $(SHLD) $(SHLD_FLAGS) -o $@ tdb_wrap.o -L. -ltdb `$(PYTHON_CONFIG) --ldflags` - -install:: installdirs installbin installheaders installlibs \ - $(PYTHON_INSTALL_TARGET) - -install-python:: build-python - mkdir -p $(DESTDIR)`$(PYTHON) -c "import distutils.sysconfig; print distutils.sysconfig.get_python_lib(0, prefix='$(prefix)')"` \ - $(DESTDIR)`$(PYTHON) -c "import distutils.sysconfig; print distutils.sysconfig.get_python_lib(1, prefix='$(prefix)')"` - cp $(tdbdir)/tdb.py $(DESTDIR)`$(PYTHON) -c "import distutils.sysconfig; print distutils.sysconfig.get_python_lib(0, prefix='$(prefix)')"` - cp _tdb.$(SHLIBEXT) $(DESTDIR)`$(PYTHON) -c "import distutils.sysconfig; print distutils.sysconfig.get_python_lib(1, prefix='$(prefix)')"` - -check-python:: build-python $(TDB_SONAME) - $(LIB_PATH_VAR)=. PYTHONPATH=".:$(tdbdir)" $(PYTHON) $(tdbdir)/python/tests/simple.py - -install-swig:: - mkdir -p $(DESTDIR)`$(SWIG) -swiglib` - cp tdb.i $(DESTDIR)`$(SWIG) -swiglib` - -clean:: - rm -f _tdb.$(SHLIBEXT) - -installdirs:: - mkdir -p $(DESTDIR)$(bindir) - mkdir -p $(DESTDIR)$(includedir) - mkdir -p $(DESTDIR)$(libdir) - mkdir -p $(DESTDIR)$(libdir)/pkgconfig - -installbin:: all installdirs - cp $(PROGS) $(DESTDIR)$(bindir) - -installheaders:: installdirs - cp $(srcdir)/include/tdb.h $(DESTDIR)$(includedir) - -installlibs:: all installdirs - cp tdb.pc $(DESTDIR)$(libdir)/pkgconfig - cp libtdb.a $(TDB_SOLIB) $(DESTDIR)$(libdir) - -libtdb.a: $(TDB_OBJ) - ar -rv libtdb.a $(TDB_OBJ) - -libtdb.$(SHLIBEXT): $(TDB_SOLIB) - ln -fs $< $@ - -$(TDB_SONAME): $(TDB_SOLIB) - ln -fs $< $@ diff --git a/source/lib/tdb/tdb.pc.in b/source/lib/tdb/tdb.pc.in index 6f8f553736..bb440f9cf5 100644 --- a/source/lib/tdb/tdb.pc.in +++ b/source/lib/tdb/tdb.pc.in @@ -8,4 +8,3 @@ Description: A trivial database Version: @PACKAGE_VERSION@ Libs: -L${libdir} -ltdb Cflags: -I${includedir} -URL: http://tdb.samba.org/ diff --git a/source/lib/tdb/tdb.py b/source/lib/tdb/tdb.py deleted file mode 100644 index 9f306bab8c..0000000000 --- a/source/lib/tdb/tdb.py +++ /dev/null @@ -1,341 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 1.3.35 -# -# Don't modify this file, modify the SWIG interface instead. - -""" -TDB is a simple key-value database similar to GDBM that supports multiple writers. -""" - -import _tdb -import new -new_instancemethod = new.instancemethod -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'PySwigObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError,name - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -import types -try: - _object = types.ObjectType - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 -del types - - -def _swig_setattr_nondynamic_method(set): - def set_attr(self,name,value): - if (name == "thisown"): return self.this.own(value) - if hasattr(self,name) or (name == "this"): - set(self,name,value) - else: - raise AttributeError("You cannot add attributes to %s" % self) - return set_attr - - -REPLACE = _tdb.REPLACE -INSERT = _tdb.INSERT -MODIFY = _tdb.MODIFY -DEFAULT = _tdb.DEFAULT -CLEAR_IF_FIRST = _tdb.CLEAR_IF_FIRST -INTERNAL = _tdb.INTERNAL -NOLOCK = _tdb.NOLOCK -NOMMAP = _tdb.NOMMAP -CONVERT = _tdb.CONVERT -BIGENDIAN = _tdb.BIGENDIAN -TDB_SUCCESS = _tdb.TDB_SUCCESS -TDB_ERR_CORRUPT = _tdb.TDB_ERR_CORRUPT -TDB_ERR_IO = _tdb.TDB_ERR_IO -TDB_ERR_LOCK = _tdb.TDB_ERR_LOCK -TDB_ERR_OOM = _tdb.TDB_ERR_OOM -TDB_ERR_EXISTS = _tdb.TDB_ERR_EXISTS -TDB_ERR_NOLOCK = _tdb.TDB_ERR_NOLOCK -TDB_ERR_LOCK_TIMEOUT = _tdb.TDB_ERR_LOCK_TIMEOUT -TDB_ERR_NOEXIST = _tdb.TDB_ERR_NOEXIST -TDB_ERR_EINVAL = _tdb.TDB_ERR_EINVAL -TDB_ERR_RDONLY = _tdb.TDB_ERR_RDONLY -class Tdb(object): - """A TDB file.""" - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self, *args, **kwargs): - """ - S.__init__(name,hash_size=0,tdb_flags=TDB_DEFAULT,flags=O_RDWR,mode=0600) - Open a TDB file. - """ - _tdb.Tdb_swiginit(self,_tdb.new_Tdb(*args, **kwargs)) - def error(*args, **kwargs): - """ - S.error() -> int - Find last error number returned by operation on this TDB. - """ - return _tdb.Tdb_error(*args, **kwargs) - - __swig_destroy__ = _tdb.delete_Tdb - def close(*args, **kwargs): - """ - S.close() -> None - Close the TDB file. - """ - return _tdb.Tdb_close(*args, **kwargs) - - def errorstr(*args, **kwargs): - """ - S.errorstr() -> errorstring - Obtain last error message. - """ - return _tdb.Tdb_errorstr(*args, **kwargs) - - def get(*args, **kwargs): - """ - S.fetch(key) -> value - Fetch a value. - """ - return _tdb.Tdb_get(*args, **kwargs) - - def delete(*args, **kwargs): - """ - S.delete(key) -> None - Delete an entry. - """ - return _tdb.Tdb_delete(*args, **kwargs) - - def store(*args, **kwargs): - """ - S.store(key, value, flag=TDB_REPLACE) -> None - Store an entry. - """ - return _tdb.Tdb_store(*args, **kwargs) - - def exists(*args, **kwargs): - """ - S.exists(key) -> bool - Check whether key exists in this database. - """ - return _tdb.Tdb_exists(*args, **kwargs) - - def firstkey(*args, **kwargs): - """ - S.firstkey() -> data - Return the first key in this database. - """ - return _tdb.Tdb_firstkey(*args, **kwargs) - - def nextkey(*args, **kwargs): - """ - S.nextkey(prev) -> data - Return the next key in this database. - """ - return _tdb.Tdb_nextkey(*args, **kwargs) - - def lock_all(*args, **kwargs): - """S.lockall() -> bool""" - return _tdb.Tdb_lock_all(*args, **kwargs) - - def unlock_all(*args, **kwargs): - """S.unlockall() -> bool""" - return _tdb.Tdb_unlock_all(*args, **kwargs) - - def reopen(*args, **kwargs): - """ - S.reopen() -> bool - Reopen this file. - """ - return _tdb.Tdb_reopen(*args, **kwargs) - - def transaction_start(*args, **kwargs): - """ - S.transaction_start() -> None - Start a new transaction. - """ - return _tdb.Tdb_transaction_start(*args, **kwargs) - - def transaction_commit(*args, **kwargs): - """ - S.transaction_commit() -> None - Commit the currently active transaction. - """ - return _tdb.Tdb_transaction_commit(*args, **kwargs) - - def transaction_cancel(*args, **kwargs): - """ - S.transaction_cancel() -> None - Cancel the currently active transaction. - """ - return _tdb.Tdb_transaction_cancel(*args, **kwargs) - - def hash_size(*args, **kwargs): - """S.hash_size() -> int""" - return _tdb.Tdb_hash_size(*args, **kwargs) - - def map_size(*args, **kwargs): - """S.map_size() -> int""" - return _tdb.Tdb_map_size(*args, **kwargs) - - def get_flags(*args, **kwargs): - """S.get_flags() -> int""" - return _tdb.Tdb_get_flags(*args, **kwargs) - - def set_max_dead(*args, **kwargs): - """S.set_max_dead(int) -> None""" - return _tdb.Tdb_set_max_dead(*args, **kwargs) - - def name(*args, **kwargs): - """ - S.name() -> path - Return filename of this TDB file. - """ - return _tdb.Tdb_name(*args, **kwargs) - - def __repr__(self): - return "Tdb('%s')" % self.name() - - - def __getitem__(self, key): - result = self.get(key) - if result is None: - raise KeyError, '%s: %s' % (key, self.errorstr()) - return result - - def __setitem__(self, key, item): - if self.store(key, item) == -1: - raise IOError, self.errorstr() - - def __delitem__(self, key): - if not self.exists(key): - raise KeyError, '%s: %s' % (key, self.errorstr()) - self.delete(key) - - def __contains__(self, key): - return self.exists(key) != 0 - - def has_key(self, key): - return self.exists(key) != 0 - - def fetch_uint32(self, key): - data = self.get(key) - if data is None: - return None - import struct - return struct.unpack("<L", data)[0] - - def fetch_int32(self, key): - data = self.get(key) - if data is None: - return None - import struct - return struct.unpack("<l", data)[0] - - - class TdbIterator: - def __init__(self, tdb): - self.tdb = tdb - self.key = None - - def __iter__(self): - return self - - def next(self): - if self.key is None: - self.key = self.tdb.firstkey() - if self.key is None: - raise StopIteration - return self.key - else: - self.key = self.tdb.nextkey(self.key) - if self.key is None: - raise StopIteration - return self.key - - def __iter__(self): - return self.TdbIterator(self) - - - - def keys(self): - return [k for k in iter(self)] - - def values(self): - return [self[k] for k in iter(self)] - - def items(self): - return [(k, self[k]) for k in iter(self)] - - def __len__(self): - return len(self.keys()) - - def clear(self): - for k in iter(self): - del(self[k]) - - def iterkeys(self): - for k in iter(self): - yield k - - def itervalues(self): - for k in iter(self): - yield self[k] - - def iteritems(self): - for k in iter(self): - yield (k, self[k]) - - - -Tdb.error = new_instancemethod(_tdb.Tdb_error,None,Tdb) -Tdb.close = new_instancemethod(_tdb.Tdb_close,None,Tdb) -Tdb.append = new_instancemethod(_tdb.Tdb_append,None,Tdb) -Tdb.errorstr = new_instancemethod(_tdb.Tdb_errorstr,None,Tdb) -Tdb.get = new_instancemethod(_tdb.Tdb_get,None,Tdb) -Tdb.delete = new_instancemethod(_tdb.Tdb_delete,None,Tdb) -Tdb.store = new_instancemethod(_tdb.Tdb_store,None,Tdb) -Tdb.exists = new_instancemethod(_tdb.Tdb_exists,None,Tdb) -Tdb.firstkey = new_instancemethod(_tdb.Tdb_firstkey,None,Tdb) -Tdb.nextkey = new_instancemethod(_tdb.Tdb_nextkey,None,Tdb) -Tdb.lock_all = new_instancemethod(_tdb.Tdb_lock_all,None,Tdb) -Tdb.unlock_all = new_instancemethod(_tdb.Tdb_unlock_all,None,Tdb) -Tdb.read_lock_all = new_instancemethod(_tdb.Tdb_read_lock_all,None,Tdb) -Tdb.read_unlock_all = new_instancemethod(_tdb.Tdb_read_unlock_all,None,Tdb) -Tdb.reopen = new_instancemethod(_tdb.Tdb_reopen,None,Tdb) -Tdb.transaction_start = new_instancemethod(_tdb.Tdb_transaction_start,None,Tdb) -Tdb.transaction_commit = new_instancemethod(_tdb.Tdb_transaction_commit,None,Tdb) -Tdb.transaction_cancel = new_instancemethod(_tdb.Tdb_transaction_cancel,None,Tdb) -Tdb.transaction_recover = new_instancemethod(_tdb.Tdb_transaction_recover,None,Tdb) -Tdb.hash_size = new_instancemethod(_tdb.Tdb_hash_size,None,Tdb) -Tdb.map_size = new_instancemethod(_tdb.Tdb_map_size,None,Tdb) -Tdb.get_flags = new_instancemethod(_tdb.Tdb_get_flags,None,Tdb) -Tdb.set_max_dead = new_instancemethod(_tdb.Tdb_set_max_dead,None,Tdb) -Tdb.name = new_instancemethod(_tdb.Tdb_name,None,Tdb) -Tdb_swigregister = _tdb.Tdb_swigregister -Tdb_swigregister(Tdb) - - - diff --git a/source/lib/tdb/tdb_wrap.c b/source/lib/tdb/tdb_wrap.c deleted file mode 100644 index 32665d79fd..0000000000 --- a/source/lib/tdb/tdb_wrap.c +++ /dev/null @@ -1,4307 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 1.3.35 - * - * This file is not intended to be easily readable and contains a number of - * coding conventions designed to improve portability and efficiency. Do not make - * changes to this file unless you know what you are doing--modify the SWIG - * interface file instead. - * ----------------------------------------------------------------------------- */ - -#define SWIGPYTHON -#define SWIG_PYTHON_NO_BUILD_NONE -/* ----------------------------------------------------------------------------- - * This section contains generic SWIG labels for method/variable - * declarations/attributes, and other compiler dependent labels. - * ----------------------------------------------------------------------------- */ - -/* template workaround for compilers that cannot correctly implement the C++ standard */ -#ifndef SWIGTEMPLATEDISAMBIGUATOR -# if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560) -# define SWIGTEMPLATEDISAMBIGUATOR template -# elif defined(__HP_aCC) -/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ -/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ -# define SWIGTEMPLATEDISAMBIGUATOR template -# else -# define SWIGTEMPLATEDISAMBIGUATOR -# endif -#endif - -/* inline attribute */ -#ifndef SWIGINLINE -# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) -# define SWIGINLINE inline -# else -# define SWIGINLINE -# endif -#endif - -/* attribute recognised by some compilers to avoid 'unused' warnings */ -#ifndef SWIGUNUSED -# if defined(__GNUC__) -# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) -# define SWIGUNUSED __attribute__ ((__unused__)) -# else -# define SWIGUNUSED -# endif -# elif defined(__ICC) -# define SWIGUNUSED __attribute__ ((__unused__)) -# else -# define SWIGUNUSED -# endif -#endif - -#ifndef SWIGUNUSEDPARM -# ifdef __cplusplus -# define SWIGUNUSEDPARM(p) -# else -# define SWIGUNUSEDPARM(p) p SWIGUNUSED -# endif -#endif - -/* internal SWIG method */ -#ifndef SWIGINTERN -# define SWIGINTERN static SWIGUNUSED -#endif - -/* internal inline SWIG method */ -#ifndef SWIGINTERNINLINE -# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE -#endif - -/* exporting methods */ -#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) -# ifndef GCC_HASCLASSVISIBILITY -# define GCC_HASCLASSVISIBILITY -# endif -#endif - -#ifndef SWIGEXPORT -# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -# if defined(STATIC_LINKED) -# define SWIGEXPORT -# else -# define SWIGEXPORT __declspec(dllexport) -# endif -# else -# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) -# define SWIGEXPORT __attribute__ ((visibility("default"))) -# else -# define SWIGEXPORT -# endif -# endif -#endif - -/* calling conventions for Windows */ -#ifndef SWIGSTDCALL -# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -# define SWIGSTDCALL __stdcall -# else -# define SWIGSTDCALL -# endif -#endif - -/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ -#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) -# define _CRT_SECURE_NO_DEPRECATE -#endif - -/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ -#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) -# define _SCL_SECURE_NO_DEPRECATE -#endif - - - -/* Python.h has to appear first */ -#include <Python.h> - -/* ----------------------------------------------------------------------------- - * swigrun.swg - * - * This file contains generic CAPI SWIG runtime support for pointer - * type checking. - * ----------------------------------------------------------------------------- */ - -/* This should only be incremented when either the layout of swig_type_info changes, - or for whatever reason, the runtime changes incompatibly */ -#define SWIG_RUNTIME_VERSION "4" - -/* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ -#ifdef SWIG_TYPE_TABLE -# define SWIG_QUOTE_STRING(x) #x -# define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x) -# define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE) -#else -# define SWIG_TYPE_TABLE_NAME -#endif - -/* - You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for - creating a static or dynamic library from the swig runtime code. - In 99.9% of the cases, swig just needs to declare them as 'static'. - - But only do this if is strictly necessary, ie, if you have problems - with your compiler or so. -*/ - -#ifndef SWIGRUNTIME -# define SWIGRUNTIME SWIGINTERN -#endif - -#ifndef SWIGRUNTIMEINLINE -# define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE -#endif - -/* Generic buffer size */ -#ifndef SWIG_BUFFER_SIZE -# define SWIG_BUFFER_SIZE 1024 -#endif - -/* Flags for pointer conversions */ -#define SWIG_POINTER_DISOWN 0x1 -#define SWIG_CAST_NEW_MEMORY 0x2 - -/* Flags for new pointer objects */ -#define SWIG_POINTER_OWN 0x1 - - -/* - Flags/methods for returning states. - - The swig conversion methods, as ConvertPtr, return and integer - that tells if the conversion was successful or not. And if not, - an error code can be returned (see swigerrors.swg for the codes). - - Use the following macros/flags to set or process the returning - states. - - In old swig versions, you usually write code as: - - if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) { - // success code - } else { - //fail code - } - - Now you can be more explicit as: - - int res = SWIG_ConvertPtr(obj,vptr,ty.flags); - if (SWIG_IsOK(res)) { - // success code - } else { - // fail code - } - - that seems to be the same, but now you can also do - - Type *ptr; - int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags); - if (SWIG_IsOK(res)) { - // success code - if (SWIG_IsNewObj(res) { - ... - delete *ptr; - } else { - ... - } - } else { - // fail code - } - - I.e., now SWIG_ConvertPtr can return new objects and you can - identify the case and take care of the deallocation. Of course that - requires also to SWIG_ConvertPtr to return new result values, as - - int SWIG_ConvertPtr(obj, ptr,...) { - if (<obj is ok>) { - if (<need new object>) { - *ptr = <ptr to new allocated object>; - return SWIG_NEWOBJ; - } else { - *ptr = <ptr to old object>; - return SWIG_OLDOBJ; - } - } else { - return SWIG_BADOBJ; - } - } - - Of course, returning the plain '0(success)/-1(fail)' still works, but you can be - more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the - swig errors code. - - Finally, if the SWIG_CASTRANK_MODE is enabled, the result code - allows to return the 'cast rank', for example, if you have this - - int food(double) - int fooi(int); - - and you call - - food(1) // cast rank '1' (1 -> 1.0) - fooi(1) // cast rank '0' - - just use the SWIG_AddCast()/SWIG_CheckState() - - - */ -#define SWIG_OK (0) -#define SWIG_ERROR (-1) -#define SWIG_IsOK(r) (r >= 0) -#define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError) - -/* The CastRankLimit says how many bits are used for the cast rank */ -#define SWIG_CASTRANKLIMIT (1 << 8) -/* The NewMask denotes the object was created (using new/malloc) */ -#define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1) -/* The TmpMask is for in/out typemaps that use temporal objects */ -#define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1) -/* Simple returning values */ -#define SWIG_BADOBJ (SWIG_ERROR) -#define SWIG_OLDOBJ (SWIG_OK) -#define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK) -#define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK) -/* Check, add and del mask methods */ -#define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r) -#define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r) -#define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK)) -#define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r) -#define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r) -#define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK)) - - -/* Cast-Rank Mode */ -#if defined(SWIG_CASTRANK_MODE) -# ifndef SWIG_TypeRank -# define SWIG_TypeRank unsigned long -# endif -# ifndef SWIG_MAXCASTRANK /* Default cast allowed */ -# define SWIG_MAXCASTRANK (2) -# endif -# define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1) -# define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK) -SWIGINTERNINLINE int SWIG_AddCast(int r) { - return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r; -} -SWIGINTERNINLINE int SWIG_CheckState(int r) { - return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; -} -#else /* no cast-rank mode */ -# define SWIG_AddCast -# define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0) -#endif - - - - -#include <string.h> - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void *(*swig_converter_func)(void *, int *); -typedef struct swig_type_info *(*swig_dycast_func)(void **); - -/* Structure to store information on one type */ -typedef struct swig_type_info { - const char *name; /* mangled name of this type */ - const char *str; /* human readable name of this type */ - swig_dycast_func dcast; /* dynamic cast function down a hierarchy */ - struct swig_cast_info *cast; /* linked list of types that can cast into this type */ - void *clientdata; /* language specific type data */ - int owndata; /* flag if the structure owns the clientdata */ -} swig_type_info; - -/* Structure to store a type and conversion function used for casting */ -typedef struct swig_cast_info { - swig_type_info *type; /* pointer to type that is equivalent to this type */ - swig_converter_func converter; /* function to cast the void pointers */ - struct swig_cast_info *next; /* pointer to next cast in linked list */ - struct swig_cast_info *prev; /* pointer to the previous cast */ -} swig_cast_info; - -/* Structure used to store module information - * Each module generates one structure like this, and the runtime collects - * all of these structures and stores them in a circularly linked list.*/ -typedef struct swig_module_info { - swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */ - size_t size; /* Number of types in this module */ - struct swig_module_info *next; /* Pointer to next element in circularly linked list */ - swig_type_info **type_initial; /* Array of initially generated type structures */ - swig_cast_info **cast_initial; /* Array of initially generated casting structures */ - void *clientdata; /* Language specific module data */ -} swig_module_info; - -/* - Compare two type names skipping the space characters, therefore - "char*" == "char *" and "Class<int>" == "Class<int >", etc. - - Return 0 when the two name types are equivalent, as in - strncmp, but skipping ' '. -*/ -SWIGRUNTIME int -SWIG_TypeNameComp(const char *f1, const char *l1, - const char *f2, const char *l2) { - for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) { - while ((*f1 == ' ') && (f1 != l1)) ++f1; - while ((*f2 == ' ') && (f2 != l2)) ++f2; - if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1; - } - return (int)((l1 - f1) - (l2 - f2)); -} - -/* - Check type equivalence in a name list like <name1>|<name2>|... - Return 0 if not equal, 1 if equal -*/ -SWIGRUNTIME int -SWIG_TypeEquiv(const char *nb, const char *tb) { - int equiv = 0; - const char* te = tb + strlen(tb); - const char* ne = nb; - while (!equiv && *ne) { - for (nb = ne; *ne; ++ne) { - if (*ne == '|') break; - } - equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0; - if (*ne) ++ne; - } - return equiv; -} - -/* - Check type equivalence in a name list like <name1>|<name2>|... - Return 0 if equal, -1 if nb < tb, 1 if nb > tb -*/ -SWIGRUNTIME int -SWIG_TypeCompare(const char *nb, const char *tb) { - int equiv = 0; - const char* te = tb + strlen(tb); - const char* ne = nb; - while (!equiv && *ne) { - for (nb = ne; *ne; ++ne) { - if (*ne == '|') break; - } - equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0; - if (*ne) ++ne; - } - return equiv; -} - - -/* think of this as a c++ template<> or a scheme macro */ -#define SWIG_TypeCheck_Template(comparison, ty) \ - if (ty) { \ - swig_cast_info *iter = ty->cast; \ - while (iter) { \ - if (comparison) { \ - if (iter == ty->cast) return iter; \ - /* Move iter to the top of the linked list */ \ - iter->prev->next = iter->next; \ - if (iter->next) \ - iter->next->prev = iter->prev; \ - iter->next = ty->cast; \ - iter->prev = 0; \ - if (ty->cast) ty->cast->prev = iter; \ - ty->cast = iter; \ - return iter; \ - } \ - iter = iter->next; \ - } \ - } \ - return 0 - -/* - Check the typename -*/ -SWIGRUNTIME swig_cast_info * -SWIG_TypeCheck(const char *c, swig_type_info *ty) { - SWIG_TypeCheck_Template(strcmp(iter->type->name, c) == 0, ty); -} - -/* Same as previous function, except strcmp is replaced with a pointer comparison */ -SWIGRUNTIME swig_cast_info * -SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *into) { - SWIG_TypeCheck_Template(iter->type == from, into); -} - -/* - Cast a pointer up an inheritance hierarchy -*/ -SWIGRUNTIMEINLINE void * -SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { - return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); -} - -/* - Dynamic pointer casting. Down an inheritance hierarchy -*/ -SWIGRUNTIME swig_type_info * -SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { - swig_type_info *lastty = ty; - if (!ty || !ty->dcast) return ty; - while (ty && (ty->dcast)) { - ty = (*ty->dcast)(ptr); - if (ty) lastty = ty; - } - return lastty; -} - -/* - Return the name associated with this type -*/ -SWIGRUNTIMEINLINE const char * -SWIG_TypeName(const swig_type_info *ty) { - return ty->name; -} - -/* - Return the pretty name associated with this type, - that is an unmangled type name in a form presentable to the user. -*/ -SWIGRUNTIME const char * -SWIG_TypePrettyName(const swig_type_info *type) { - /* The "str" field contains the equivalent pretty names of the - type, separated by vertical-bar characters. We choose - to print the last name, as it is often (?) the most - specific. */ - if (!type) return NULL; - if (type->str != NULL) { - const char *last_name = type->str; - const char *s; - for (s = type->str; *s; s++) - if (*s == '|') last_name = s+1; - return last_name; - } - else - return type->name; -} - -/* - Set the clientdata field for a type -*/ -SWIGRUNTIME void -SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { - swig_cast_info *cast = ti->cast; - /* if (ti->clientdata == clientdata) return; */ - ti->clientdata = clientdata; - - while (cast) { - if (!cast->converter) { - swig_type_info *tc = cast->type; - if (!tc->clientdata) { - SWIG_TypeClientData(tc, clientdata); - } - } - cast = cast->next; - } -} -SWIGRUNTIME void -SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) { - SWIG_TypeClientData(ti, clientdata); - ti->owndata = 1; -} - -/* - Search for a swig_type_info structure only by mangled name - Search is a O(log #types) - - We start searching at module start, and finish searching when start == end. - Note: if start == end at the beginning of the function, we go all the way around - the circular list. -*/ -SWIGRUNTIME swig_type_info * -SWIG_MangledTypeQueryModule(swig_module_info *start, - swig_module_info *end, - const char *name) { - swig_module_info *iter = start; - do { - if (iter->size) { - register size_t l = 0; - register size_t r = iter->size - 1; - do { - /* since l+r >= 0, we can (>> 1) instead (/ 2) */ - register size_t i = (l + r) >> 1; - const char *iname = iter->types[i]->name; - if (iname) { - register int compare = strcmp(name, iname); - if (compare == 0) { - return iter->types[i]; - } else if (compare < 0) { - if (i) { - r = i - 1; - } else { - break; - } - } else if (compare > 0) { - l = i + 1; - } - } else { - break; /* should never happen */ - } - } while (l <= r); - } - iter = iter->next; - } while (iter != end); - return 0; -} - -/* - Search for a swig_type_info structure for either a mangled name or a human readable name. - It first searches the mangled names of the types, which is a O(log #types) - If a type is not found it then searches the human readable names, which is O(#types). - - We start searching at module start, and finish searching when start == end. - Note: if start == end at the beginning of the function, we go all the way around - the circular list. -*/ -SWIGRUNTIME swig_type_info * -SWIG_TypeQueryModule(swig_module_info *start, - swig_module_info *end, - const char *name) { - /* STEP 1: Search the name field using binary search */ - swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name); - if (ret) { - return ret; - } else { - /* STEP 2: If the type hasn't been found, do a complete search - of the str field (the human readable name) */ - swig_module_info *iter = start; - do { - register size_t i = 0; - for (; i < iter->size; ++i) { - if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name))) - return iter->types[i]; - } - iter = iter->next; - } while (iter != end); - } - - /* neither found a match */ - return 0; -} - -/* - Pack binary data into a string -*/ -SWIGRUNTIME char * -SWIG_PackData(char *c, void *ptr, size_t sz) { - static const char hex[17] = "0123456789abcdef"; - register const unsigned char *u = (unsigned char *) ptr; - register const unsigned char *eu = u + sz; - for (; u != eu; ++u) { - register unsigned char uu = *u; - *(c++) = hex[(uu & 0xf0) >> 4]; - *(c++) = hex[uu & 0xf]; - } - return c; -} - -/* - Unpack binary data from a string -*/ -SWIGRUNTIME const char * -SWIG_UnpackData(const char *c, void *ptr, size_t sz) { - register unsigned char *u = (unsigned char *) ptr; - register const unsigned char *eu = u + sz; - for (; u != eu; ++u) { - register char d = *(c++); - register unsigned char uu; - if ((d >= '0') && (d <= '9')) - uu = ((d - '0') << 4); - else if ((d >= 'a') && (d <= 'f')) - uu = ((d - ('a'-10)) << 4); - else - return (char *) 0; - d = *(c++); - if ((d >= '0') && (d <= '9')) - uu |= (d - '0'); - else if ((d >= 'a') && (d <= 'f')) - uu |= (d - ('a'-10)); - else - return (char *) 0; - *u = uu; - } - return c; -} - -/* - Pack 'void *' into a string buffer. -*/ -SWIGRUNTIME char * -SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) { - char *r = buff; - if ((2*sizeof(void *) + 2) > bsz) return 0; - *(r++) = '_'; - r = SWIG_PackData(r,&ptr,sizeof(void *)); - if (strlen(name) + 1 > (bsz - (r - buff))) return 0; - strcpy(r,name); - return buff; -} - -SWIGRUNTIME const char * -SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) { - if (*c != '_') { - if (strcmp(c,"NULL") == 0) { - *ptr = (void *) 0; - return name; - } else { - return 0; - } - } - return SWIG_UnpackData(++c,ptr,sizeof(void *)); -} - -SWIGRUNTIME char * -SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) { - char *r = buff; - size_t lname = (name ? strlen(name) : 0); - if ((2*sz + 2 + lname) > bsz) return 0; - *(r++) = '_'; - r = SWIG_PackData(r,ptr,sz); - if (lname) { - strncpy(r,name,lname+1); - } else { - *r = 0; - } - return buff; -} - -SWIGRUNTIME const char * -SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) { - if (*c != '_') { - if (strcmp(c,"NULL") == 0) { - memset(ptr,0,sz); - return name; - } else { - return 0; - } - } - return SWIG_UnpackData(++c,ptr,sz); -} - -#ifdef __cplusplus -} -#endif - -/* Errors in SWIG */ -#define SWIG_UnknownError -1 -#define SWIG_IOError -2 -#define SWIG_RuntimeError -3 -#define SWIG_IndexError -4 -#define SWIG_TypeError -5 -#define SWIG_DivisionByZero -6 -#define SWIG_OverflowError -7 -#define SWIG_SyntaxError -8 -#define SWIG_ValueError -9 -#define SWIG_SystemError -10 -#define SWIG_AttributeError -11 -#define SWIG_MemoryError -12 -#define SWIG_NullReferenceError -13 - - - - -/* Add PyOS_snprintf for old Pythons */ -#if PY_VERSION_HEX < 0x02020000 -# if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) -# define PyOS_snprintf _snprintf -# else -# define PyOS_snprintf snprintf -# endif -#endif - -/* A crude PyString_FromFormat implementation for old Pythons */ -#if PY_VERSION_HEX < 0x02020000 - -#ifndef SWIG_PYBUFFER_SIZE -# define SWIG_PYBUFFER_SIZE 1024 -#endif - -static PyObject * -PyString_FromFormat(const char *fmt, ...) { - va_list ap; - char buf[SWIG_PYBUFFER_SIZE * 2]; - int res; - va_start(ap, fmt); - res = vsnprintf(buf, sizeof(buf), fmt, ap); - va_end(ap); - return (res < 0 || res >= (int)sizeof(buf)) ? 0 : PyString_FromString(buf); -} -#endif - -/* Add PyObject_Del for old Pythons */ -#if PY_VERSION_HEX < 0x01060000 -# define PyObject_Del(op) PyMem_DEL((op)) -#endif -#ifndef PyObject_DEL -# define PyObject_DEL PyObject_Del -#endif - -/* A crude PyExc_StopIteration exception for old Pythons */ -#if PY_VERSION_HEX < 0x02020000 -# ifndef PyExc_StopIteration -# define PyExc_StopIteration PyExc_RuntimeError -# endif -# ifndef PyObject_GenericGetAttr -# define PyObject_GenericGetAttr 0 -# endif -#endif -/* Py_NotImplemented is defined in 2.1 and up. */ -#if PY_VERSION_HEX < 0x02010000 -# ifndef Py_NotImplemented -# define Py_NotImplemented PyExc_RuntimeError -# endif -#endif - - -/* A crude PyString_AsStringAndSize implementation for old Pythons */ -#if PY_VERSION_HEX < 0x02010000 -# ifndef PyString_AsStringAndSize -# define PyString_AsStringAndSize(obj, s, len) {*s = PyString_AsString(obj); *len = *s ? strlen(*s) : 0;} -# endif -#endif - -/* PySequence_Size for old Pythons */ -#if PY_VERSION_HEX < 0x02000000 -# ifndef PySequence_Size -# define PySequence_Size PySequence_Length -# endif -#endif - - -/* PyBool_FromLong for old Pythons */ -#if PY_VERSION_HEX < 0x02030000 -static -PyObject *PyBool_FromLong(long ok) -{ - PyObject *result = ok ? Py_True : Py_False; - Py_INCREF(result); - return result; -} -#endif - -/* Py_ssize_t for old Pythons */ -/* This code is as recommended by: */ -/* http://www.python.org/dev/peps/pep-0353/#conversion-guidelines */ -#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) -typedef int Py_ssize_t; -# define PY_SSIZE_T_MAX INT_MAX -# define PY_SSIZE_T_MIN INT_MIN -#endif - -/* ----------------------------------------------------------------------------- - * error manipulation - * ----------------------------------------------------------------------------- */ - -SWIGRUNTIME PyObject* -SWIG_Python_ErrorType(int code) { - PyObject* type = 0; - switch(code) { - case SWIG_MemoryError: - type = PyExc_MemoryError; - break; - case SWIG_IOError: - type = PyExc_IOError; - break; - case SWIG_RuntimeError: - type = PyExc_RuntimeError; - break; - case SWIG_IndexError: - type = PyExc_IndexError; - break; - case SWIG_TypeError: - type = PyExc_TypeError; - break; - case SWIG_DivisionByZero: - type = PyExc_ZeroDivisionError; - break; - case SWIG_OverflowError: - type = PyExc_OverflowError; - break; - case SWIG_SyntaxError: - type = PyExc_SyntaxError; - break; - case SWIG_ValueError: - type = PyExc_ValueError; - break; - case SWIG_SystemError: - type = PyExc_SystemError; - break; - case SWIG_AttributeError: - type = PyExc_AttributeError; - break; - default: - type = PyExc_RuntimeError; - } - return type; -} - - -SWIGRUNTIME void -SWIG_Python_AddErrorMsg(const char* mesg) -{ - PyObject *type = 0; - PyObject *value = 0; - PyObject *traceback = 0; - - if (PyErr_Occurred()) PyErr_Fetch(&type, &value, &traceback); - if (value) { - PyObject *old_str = PyObject_Str(value); - PyErr_Clear(); - Py_XINCREF(type); - PyErr_Format(type, "%s %s", PyString_AsString(old_str), mesg); - Py_DECREF(old_str); - Py_DECREF(value); - } else { - PyErr_SetString(PyExc_RuntimeError, mesg); - } -} - - - -#if defined(SWIG_PYTHON_NO_THREADS) -# if defined(SWIG_PYTHON_THREADS) -# undef SWIG_PYTHON_THREADS -# endif -#endif -#if defined(SWIG_PYTHON_THREADS) /* Threading support is enabled */ -# if !defined(SWIG_PYTHON_USE_GIL) && !defined(SWIG_PYTHON_NO_USE_GIL) -# if (PY_VERSION_HEX >= 0x02030000) /* For 2.3 or later, use the PyGILState calls */ -# define SWIG_PYTHON_USE_GIL -# endif -# endif -# if defined(SWIG_PYTHON_USE_GIL) /* Use PyGILState threads calls */ -# ifndef SWIG_PYTHON_INITIALIZE_THREADS -# define SWIG_PYTHON_INITIALIZE_THREADS PyEval_InitThreads() -# endif -# ifdef __cplusplus /* C++ code */ - class SWIG_Python_Thread_Block { - bool status; - PyGILState_STATE state; - public: - void end() { if (status) { PyGILState_Release(state); status = false;} } - SWIG_Python_Thread_Block() : status(true), state(PyGILState_Ensure()) {} - ~SWIG_Python_Thread_Block() { end(); } - }; - class SWIG_Python_Thread_Allow { - bool status; - PyThreadState *save; - public: - void end() { if (status) { PyEval_RestoreThread(save); status = false; }} - SWIG_Python_Thread_Allow() : status(true), save(PyEval_SaveThread()) {} - ~SWIG_Python_Thread_Allow() { end(); } - }; -# define SWIG_PYTHON_THREAD_BEGIN_BLOCK SWIG_Python_Thread_Block _swig_thread_block -# define SWIG_PYTHON_THREAD_END_BLOCK _swig_thread_block.end() -# define SWIG_PYTHON_THREAD_BEGIN_ALLOW SWIG_Python_Thread_Allow _swig_thread_allow -# define SWIG_PYTHON_THREAD_END_ALLOW _swig_thread_allow.end() -# else /* C code */ -# define SWIG_PYTHON_THREAD_BEGIN_BLOCK PyGILState_STATE _swig_thread_block = PyGILState_Ensure() -# define SWIG_PYTHON_THREAD_END_BLOCK PyGILState_Release(_swig_thread_block) -# define SWIG_PYTHON_THREAD_BEGIN_ALLOW PyThreadState *_swig_thread_allow = PyEval_SaveThread() -# define SWIG_PYTHON_THREAD_END_ALLOW PyEval_RestoreThread(_swig_thread_allow) -# endif -# else /* Old thread way, not implemented, user must provide it */ -# if !defined(SWIG_PYTHON_INITIALIZE_THREADS) -# define SWIG_PYTHON_INITIALIZE_THREADS -# endif -# if !defined(SWIG_PYTHON_THREAD_BEGIN_BLOCK) -# define SWIG_PYTHON_THREAD_BEGIN_BLOCK -# endif -# if !defined(SWIG_PYTHON_THREAD_END_BLOCK) -# define SWIG_PYTHON_THREAD_END_BLOCK -# endif -# if !defined(SWIG_PYTHON_THREAD_BEGIN_ALLOW) -# define SWIG_PYTHON_THREAD_BEGIN_ALLOW -# endif -# if !defined(SWIG_PYTHON_THREAD_END_ALLOW) -# define SWIG_PYTHON_THREAD_END_ALLOW -# endif -# endif -#else /* No thread support */ -# define SWIG_PYTHON_INITIALIZE_THREADS -# define SWIG_PYTHON_THREAD_BEGIN_BLOCK -# define SWIG_PYTHON_THREAD_END_BLOCK -# define SWIG_PYTHON_THREAD_BEGIN_ALLOW -# define SWIG_PYTHON_THREAD_END_ALLOW -#endif - -/* ----------------------------------------------------------------------------- - * Python API portion that goes into the runtime - * ----------------------------------------------------------------------------- */ - -#ifdef __cplusplus -extern "C" { -#if 0 -} /* cc-mode */ -#endif -#endif - -/* ----------------------------------------------------------------------------- - * Constant declarations - * ----------------------------------------------------------------------------- */ - -/* Constant Types */ -#define SWIG_PY_POINTER 4 -#define SWIG_PY_BINARY 5 - -/* Constant information structure */ -typedef struct swig_const_info { - int type; - char *name; - long lvalue; - double dvalue; - void *pvalue; - swig_type_info **ptype; -} swig_const_info; - -#ifdef __cplusplus -#if 0 -{ /* cc-mode */ -#endif -} -#endif - - -/* ----------------------------------------------------------------------------- - * See the LICENSE file for information on copyright, usage and redistribution - * of SWIG, and the README file for authors - http://www.swig.org/release.html. - * - * pyrun.swg - * - * This file contains the runtime support for Python modules - * and includes code for managing global variables and pointer - * type checking. - * - * ----------------------------------------------------------------------------- */ - -/* Common SWIG API */ - -/* for raw pointers */ -#define SWIG_Python_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, 0) -#define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtr(obj, pptr, type, flags) -#define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, own) -#define SWIG_NewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(ptr, type, flags) -#define SWIG_CheckImplicit(ty) SWIG_Python_CheckImplicit(ty) -#define SWIG_AcquirePtr(ptr, src) SWIG_Python_AcquirePtr(ptr, src) -#define swig_owntype int - -/* for raw packed data */ -#define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) -#define SWIG_NewPackedObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) - -/* for class or struct pointers */ -#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_ConvertPtr(obj, pptr, type, flags) -#define SWIG_NewInstanceObj(ptr, type, flags) SWIG_NewPointerObj(ptr, type, flags) - -/* for C or C++ function pointers */ -#define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_Python_ConvertFunctionPtr(obj, pptr, type) -#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_Python_NewPointerObj(ptr, type, 0) - -/* for C++ member pointers, ie, member methods */ -#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) -#define SWIG_NewMemberObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) - - -/* Runtime API */ - -#define SWIG_GetModule(clientdata) SWIG_Python_GetModule() -#define SWIG_SetModule(clientdata, pointer) SWIG_Python_SetModule(pointer) -#define SWIG_NewClientData(obj) PySwigClientData_New(obj) - -#define SWIG_SetErrorObj SWIG_Python_SetErrorObj -#define SWIG_SetErrorMsg SWIG_Python_SetErrorMsg -#define SWIG_ErrorType(code) SWIG_Python_ErrorType(code) -#define SWIG_Error(code, msg) SWIG_Python_SetErrorMsg(SWIG_ErrorType(code), msg) -#define SWIG_fail goto fail - - -/* Runtime API implementation */ - -/* Error manipulation */ - -SWIGINTERN void -SWIG_Python_SetErrorObj(PyObject *errtype, PyObject *obj) { - SWIG_PYTHON_THREAD_BEGIN_BLOCK; - PyErr_SetObject(errtype, obj); - Py_DECREF(obj); - SWIG_PYTHON_THREAD_END_BLOCK; -} - -SWIGINTERN void -SWIG_Python_SetErrorMsg(PyObject *errtype, const char *msg) { - SWIG_PYTHON_THREAD_BEGIN_BLOCK; - PyErr_SetString(errtype, (char *) msg); - SWIG_PYTHON_THREAD_END_BLOCK; -} - -#define SWIG_Python_Raise(obj, type, desc) SWIG_Python_SetErrorObj(SWIG_Python_ExceptionType(desc), obj) - -/* Set a constant value */ - -SWIGINTERN void -SWIG_Python_SetConstant(PyObject *d, const char *name, PyObject *obj) { - PyDict_SetItemString(d, (char*) name, obj); - Py_DECREF(obj); -} - -/* Append a value to the result obj */ - -SWIGINTERN PyObject* -SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) { -#if !defined(SWIG_PYTHON_OUTPUT_TUPLE) - if (!result) { - result = obj; - } else if (result == Py_None) { - Py_DECREF(result); - result = obj; - } else { - if (!PyList_Check(result)) { - PyObject *o2 = result; - result = PyList_New(1); - PyList_SetItem(result, 0, o2); - } - PyList_Append(result,obj); - Py_DECREF(obj); - } - return result; -#else - PyObject* o2; - PyObject* o3; - if (!result) { - result = obj; - } else if (result == Py_None) { - Py_DECREF(result); - result = obj; - } else { - if (!PyTuple_Check(result)) { - o2 = result; - result = PyTuple_New(1); - PyTuple_SET_ITEM(result, 0, o2); - } - o3 = PyTuple_New(1); - PyTuple_SET_ITEM(o3, 0, obj); - o2 = result; - result = PySequence_Concat(o2, o3); - Py_DECREF(o2); - Py_DECREF(o3); - } - return result; -#endif -} - -/* Unpack the argument tuple */ - -SWIGINTERN int -SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, PyObject **objs) -{ - if (!args) { - if (!min && !max) { - return 1; - } else { - PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got none", - name, (min == max ? "" : "at least "), (int)min); - return 0; - } - } - if (!PyTuple_Check(args)) { - PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple"); - return 0; - } else { - register Py_ssize_t l = PyTuple_GET_SIZE(args); - if (l < min) { - PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", - name, (min == max ? "" : "at least "), (int)min, (int)l); - return 0; - } else if (l > max) { - PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", - name, (min == max ? "" : "at most "), (int)max, (int)l); - return 0; - } else { - register int i; - for (i = 0; i < l; ++i) { - objs[i] = PyTuple_GET_ITEM(args, i); - } - for (; l < max; ++l) { - objs[l] = 0; - } - return i + 1; - } - } -} - -/* A functor is a function object with one single object argument */ -#if PY_VERSION_HEX >= 0x02020000 -#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunctionObjArgs(functor, obj, NULL); -#else -#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunction(functor, "O", obj); -#endif - -/* - Helper for static pointer initialization for both C and C++ code, for example - static PyObject *SWIG_STATIC_POINTER(MyVar) = NewSomething(...); -*/ -#ifdef __cplusplus -#define SWIG_STATIC_POINTER(var) var -#else -#define SWIG_STATIC_POINTER(var) var = 0; if (!var) var -#endif - -/* ----------------------------------------------------------------------------- - * Pointer declarations - * ----------------------------------------------------------------------------- */ - -/* Flags for new pointer objects */ -#define SWIG_POINTER_NOSHADOW (SWIG_POINTER_OWN << 1) -#define SWIG_POINTER_NEW (SWIG_POINTER_NOSHADOW | SWIG_POINTER_OWN) - -#define SWIG_POINTER_IMPLICIT_CONV (SWIG_POINTER_DISOWN << 1) - -#ifdef __cplusplus -extern "C" { -#if 0 -} /* cc-mode */ -#endif -#endif - -/* How to access Py_None */ -#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -# ifndef SWIG_PYTHON_NO_BUILD_NONE -# ifndef SWIG_PYTHON_BUILD_NONE -# define SWIG_PYTHON_BUILD_NONE -# endif -# endif -#endif - -#ifdef SWIG_PYTHON_BUILD_NONE -# ifdef Py_None -# undef Py_None -# define Py_None SWIG_Py_None() -# endif -SWIGRUNTIMEINLINE PyObject * -_SWIG_Py_None(void) -{ - PyObject *none = Py_BuildValue((char*)""); - Py_DECREF(none); - return none; -} -SWIGRUNTIME PyObject * -SWIG_Py_None(void) -{ - static PyObject *SWIG_STATIC_POINTER(none) = _SWIG_Py_None(); - return none; -} -#endif - -/* The python void return value */ - -SWIGRUNTIMEINLINE PyObject * -SWIG_Py_Void(void) -{ - PyObject *none = Py_None; - Py_INCREF(none); - return none; -} - -/* PySwigClientData */ - -typedef struct { - PyObject *klass; - PyObject *newraw; - PyObject *newargs; - PyObject *destroy; - int delargs; - int implicitconv; -} PySwigClientData; - -SWIGRUNTIMEINLINE int -SWIG_Python_CheckImplicit(swig_type_info *ty) -{ - PySwigClientData *data = (PySwigClientData *)ty->clientdata; - return data ? data->implicitconv : 0; -} - -SWIGRUNTIMEINLINE PyObject * -SWIG_Python_ExceptionType(swig_type_info *desc) { - PySwigClientData *data = desc ? (PySwigClientData *) desc->clientdata : 0; - PyObject *klass = data ? data->klass : 0; - return (klass ? klass : PyExc_RuntimeError); -} - - -SWIGRUNTIME PySwigClientData * -PySwigClientData_New(PyObject* obj) -{ - if (!obj) { - return 0; - } else { - PySwigClientData *data = (PySwigClientData *)malloc(sizeof(PySwigClientData)); - /* the klass element */ - data->klass = obj; - Py_INCREF(data->klass); - /* the newraw method and newargs arguments used to create a new raw instance */ - if (PyClass_Check(obj)) { - data->newraw = 0; - data->newargs = obj; - Py_INCREF(obj); - } else { -#if (PY_VERSION_HEX < 0x02020000) - data->newraw = 0; -#else - data->newraw = PyObject_GetAttrString(data->klass, (char *)"__new__"); -#endif - if (data->newraw) { - Py_INCREF(data->newraw); - data->newargs = PyTuple_New(1); - PyTuple_SetItem(data->newargs, 0, obj); - } else { - data->newargs = obj; - } - Py_INCREF(data->newargs); - } - /* the destroy method, aka as the C++ delete method */ - data->destroy = PyObject_GetAttrString(data->klass, (char *)"__swig_destroy__"); - if (PyErr_Occurred()) { - PyErr_Clear(); - data->destroy = 0; - } - if (data->destroy) { - int flags; - Py_INCREF(data->destroy); - flags = PyCFunction_GET_FLAGS(data->destroy); -#ifdef METH_O - data->delargs = !(flags & (METH_O)); -#else - data->delargs = 0; -#endif - } else { - data->delargs = 0; - } - data->implicitconv = 0; - return data; - } -} - -SWIGRUNTIME void -PySwigClientData_Del(PySwigClientData* data) -{ - Py_XDECREF(data->newraw); - Py_XDECREF(data->newargs); - Py_XDECREF(data->destroy); -} - -/* =============== PySwigObject =====================*/ - -typedef struct { - PyObject_HEAD - void *ptr; - swig_type_info *ty; - int own; - PyObject *next; -} PySwigObject; - -SWIGRUNTIME PyObject * -PySwigObject_long(PySwigObject *v) -{ - return PyLong_FromVoidPtr(v->ptr); -} - -SWIGRUNTIME PyObject * -PySwigObject_format(const char* fmt, PySwigObject *v) -{ - PyObject *res = NULL; - PyObject *args = PyTuple_New(1); - if (args) { - if (PyTuple_SetItem(args, 0, PySwigObject_long(v)) == 0) { - PyObject *ofmt = PyString_FromString(fmt); - if (ofmt) { - res = PyString_Format(ofmt,args); - Py_DECREF(ofmt); - } - Py_DECREF(args); - } - } - return res; -} - -SWIGRUNTIME PyObject * -PySwigObject_oct(PySwigObject *v) -{ - return PySwigObject_format("%o",v); -} - -SWIGRUNTIME PyObject * -PySwigObject_hex(PySwigObject *v) -{ - return PySwigObject_format("%x",v); -} - -SWIGRUNTIME PyObject * -#ifdef METH_NOARGS -PySwigObject_repr(PySwigObject *v) -#else -PySwigObject_repr(PySwigObject *v, PyObject *args) -#endif -{ - const char *name = SWIG_TypePrettyName(v->ty); - PyObject *hex = PySwigObject_hex(v); - PyObject *repr = PyString_FromFormat("<Swig Object of type '%s' at 0x%s>", name, PyString_AsString(hex)); - Py_DECREF(hex); - if (v->next) { -#ifdef METH_NOARGS - PyObject *nrep = PySwigObject_repr((PySwigObject *)v->next); -#else - PyObject *nrep = PySwigObject_repr((PySwigObject *)v->next, args); -#endif - PyString_ConcatAndDel(&repr,nrep); - } - return repr; -} - -SWIGRUNTIME int -PySwigObject_print(PySwigObject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) -{ -#ifdef METH_NOARGS - PyObject *repr = PySwigObject_repr(v); -#else - PyObject *repr = PySwigObject_repr(v, NULL); -#endif - if (repr) { - fputs(PyString_AsString(repr), fp); - Py_DECREF(repr); - return 0; - } else { - return 1; - } -} - -SWIGRUNTIME PyObject * -PySwigObject_str(PySwigObject *v) -{ - char result[SWIG_BUFFER_SIZE]; - return SWIG_PackVoidPtr(result, v->ptr, v->ty->name, sizeof(result)) ? - PyString_FromString(result) : 0; -} - -SWIGRUNTIME int -PySwigObject_compare(PySwigObject *v, PySwigObject *w) -{ - void *i = v->ptr; - void *j = w->ptr; - return (i < j) ? -1 : ((i > j) ? 1 : 0); -} - -SWIGRUNTIME PyTypeObject* _PySwigObject_type(void); - -SWIGRUNTIME PyTypeObject* -PySwigObject_type(void) { - static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigObject_type(); - return type; -} - -SWIGRUNTIMEINLINE int -PySwigObject_Check(PyObject *op) { - return ((op)->ob_type == PySwigObject_type()) - || (strcmp((op)->ob_type->tp_name,"PySwigObject") == 0); -} - -SWIGRUNTIME PyObject * -PySwigObject_New(void *ptr, swig_type_info *ty, int own); - -SWIGRUNTIME void -PySwigObject_dealloc(PyObject *v) -{ - PySwigObject *sobj = (PySwigObject *) v; - PyObject *next = sobj->next; - if (sobj->own == SWIG_POINTER_OWN) { - swig_type_info *ty = sobj->ty; - PySwigClientData *data = ty ? (PySwigClientData *) ty->clientdata : 0; - PyObject *destroy = data ? data->destroy : 0; - if (destroy) { - /* destroy is always a VARARGS method */ - PyObject *res; - if (data->delargs) { - /* we need to create a temporal object to carry the destroy operation */ - PyObject *tmp = PySwigObject_New(sobj->ptr, ty, 0); - res = SWIG_Python_CallFunctor(destroy, tmp); - Py_DECREF(tmp); - } else { - PyCFunction meth = PyCFunction_GET_FUNCTION(destroy); - PyObject *mself = PyCFunction_GET_SELF(destroy); - res = ((*meth)(mself, v)); - } - Py_XDECREF(res); - } -#if !defined(SWIG_PYTHON_SILENT_MEMLEAK) - else { - const char *name = SWIG_TypePrettyName(ty); - printf("swig/python detected a memory leak of type '%s', no destructor found.\n", (name ? name : "unknown")); - } -#endif - } - Py_XDECREF(next); - PyObject_DEL(v); -} - -SWIGRUNTIME PyObject* -PySwigObject_append(PyObject* v, PyObject* next) -{ - PySwigObject *sobj = (PySwigObject *) v; -#ifndef METH_O - PyObject *tmp = 0; - if (!PyArg_ParseTuple(next,(char *)"O:append", &tmp)) return NULL; - next = tmp; -#endif - if (!PySwigObject_Check(next)) { - return NULL; - } - sobj->next = next; - Py_INCREF(next); - return SWIG_Py_Void(); -} - -SWIGRUNTIME PyObject* -#ifdef METH_NOARGS -PySwigObject_next(PyObject* v) -#else -PySwigObject_next(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) -#endif -{ - PySwigObject *sobj = (PySwigObject *) v; - if (sobj->next) { - Py_INCREF(sobj->next); - return sobj->next; - } else { - return SWIG_Py_Void(); - } -} - -SWIGINTERN PyObject* -#ifdef METH_NOARGS -PySwigObject_disown(PyObject *v) -#else -PySwigObject_disown(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) -#endif -{ - PySwigObject *sobj = (PySwigObject *)v; - sobj->own = 0; - return SWIG_Py_Void(); -} - -SWIGINTERN PyObject* -#ifdef METH_NOARGS -PySwigObject_acquire(PyObject *v) -#else -PySwigObject_acquire(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) -#endif -{ - PySwigObject *sobj = (PySwigObject *)v; - sobj->own = SWIG_POINTER_OWN; - return SWIG_Py_Void(); -} - -SWIGINTERN PyObject* -PySwigObject_own(PyObject *v, PyObject *args) -{ - PyObject *val = 0; -#if (PY_VERSION_HEX < 0x02020000) - if (!PyArg_ParseTuple(args,(char *)"|O:own",&val)) -#else - if (!PyArg_UnpackTuple(args, (char *)"own", 0, 1, &val)) -#endif - { - return NULL; - } - else - { - PySwigObject *sobj = (PySwigObject *)v; - PyObject *obj = PyBool_FromLong(sobj->own); - if (val) { -#ifdef METH_NOARGS - if (PyObject_IsTrue(val)) { - PySwigObject_acquire(v); - } else { - PySwigObject_disown(v); - } -#else - if (PyObject_IsTrue(val)) { - PySwigObject_acquire(v,args); - } else { - PySwigObject_disown(v,args); - } -#endif - } - return obj; - } -} - -#ifdef METH_O -static PyMethodDef -swigobject_methods[] = { - {(char *)"disown", (PyCFunction)PySwigObject_disown, METH_NOARGS, (char *)"releases ownership of the pointer"}, - {(char *)"acquire", (PyCFunction)PySwigObject_acquire, METH_NOARGS, (char *)"aquires ownership of the pointer"}, - {(char *)"own", (PyCFunction)PySwigObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, - {(char *)"append", (PyCFunction)PySwigObject_append, METH_O, (char *)"appends another 'this' object"}, - {(char *)"next", (PyCFunction)PySwigObject_next, METH_NOARGS, (char *)"returns the next 'this' object"}, - {(char *)"__repr__",(PyCFunction)PySwigObject_repr, METH_NOARGS, (char *)"returns object representation"}, - {0, 0, 0, 0} -}; -#else -static PyMethodDef -swigobject_methods[] = { - {(char *)"disown", (PyCFunction)PySwigObject_disown, METH_VARARGS, (char *)"releases ownership of the pointer"}, - {(char *)"acquire", (PyCFunction)PySwigObject_acquire, METH_VARARGS, (char *)"aquires ownership of the pointer"}, - {(char *)"own", (PyCFunction)PySwigObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, - {(char *)"append", (PyCFunction)PySwigObject_append, METH_VARARGS, (char *)"appends another 'this' object"}, - {(char *)"next", (PyCFunction)PySwigObject_next, METH_VARARGS, (char *)"returns the next 'this' object"}, - {(char *)"__repr__",(PyCFunction)PySwigObject_repr, METH_VARARGS, (char *)"returns object representation"}, - {0, 0, 0, 0} -}; -#endif - -#if PY_VERSION_HEX < 0x02020000 -SWIGINTERN PyObject * -PySwigObject_getattr(PySwigObject *sobj,char *name) -{ - return Py_FindMethod(swigobject_methods, (PyObject *)sobj, name); -} -#endif - -SWIGRUNTIME PyTypeObject* -_PySwigObject_type(void) { - static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer"; - - static PyNumberMethods PySwigObject_as_number = { - (binaryfunc)0, /*nb_add*/ - (binaryfunc)0, /*nb_subtract*/ - (binaryfunc)0, /*nb_multiply*/ - (binaryfunc)0, /*nb_divide*/ - (binaryfunc)0, /*nb_remainder*/ - (binaryfunc)0, /*nb_divmod*/ - (ternaryfunc)0,/*nb_power*/ - (unaryfunc)0, /*nb_negative*/ - (unaryfunc)0, /*nb_positive*/ - (unaryfunc)0, /*nb_absolute*/ - (inquiry)0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ - (coercion)0, /*nb_coerce*/ - (unaryfunc)PySwigObject_long, /*nb_int*/ - (unaryfunc)PySwigObject_long, /*nb_long*/ - (unaryfunc)0, /*nb_float*/ - (unaryfunc)PySwigObject_oct, /*nb_oct*/ - (unaryfunc)PySwigObject_hex, /*nb_hex*/ -#if PY_VERSION_HEX >= 0x02050000 /* 2.5.0 */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index */ -#elif PY_VERSION_HEX >= 0x02020000 /* 2.2.0 */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_true_divide */ -#elif PY_VERSION_HEX >= 0x02000000 /* 2.0.0 */ - 0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_or */ -#endif - }; - - static PyTypeObject pyswigobject_type; - static int type_init = 0; - if (!type_init) { - const PyTypeObject tmp - = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - (char *)"PySwigObject", /* tp_name */ - sizeof(PySwigObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)PySwigObject_dealloc, /* tp_dealloc */ - (printfunc)PySwigObject_print, /* tp_print */ -#if PY_VERSION_HEX < 0x02020000 - (getattrfunc)PySwigObject_getattr, /* tp_getattr */ -#else - (getattrfunc)0, /* tp_getattr */ -#endif - (setattrfunc)0, /* tp_setattr */ - (cmpfunc)PySwigObject_compare, /* tp_compare */ - (reprfunc)PySwigObject_repr, /* tp_repr */ - &PySwigObject_as_number, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - (hashfunc)0, /* tp_hash */ - (ternaryfunc)0, /* tp_call */ - (reprfunc)PySwigObject_str, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - swigobject_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ -#if PY_VERSION_HEX >= 0x02020000 - 0, /* tp_iter */ - 0, /* tp_iternext */ - swigobject_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0, /* tp_free */ - 0, /* tp_is_gc */ - 0, /* tp_bases */ - 0, /* tp_mro */ - 0, /* tp_cache */ - 0, /* tp_subclasses */ - 0, /* tp_weaklist */ -#endif -#if PY_VERSION_HEX >= 0x02030000 - 0, /* tp_del */ -#endif -#ifdef COUNT_ALLOCS - 0,0,0,0 /* tp_alloc -> tp_next */ -#endif - }; - pyswigobject_type = tmp; - pyswigobject_type.ob_type = &PyType_Type; - type_init = 1; - } - return &pyswigobject_type; -} - -SWIGRUNTIME PyObject * -PySwigObject_New(void *ptr, swig_type_info *ty, int own) -{ - PySwigObject *sobj = PyObject_NEW(PySwigObject, PySwigObject_type()); - if (sobj) { - sobj->ptr = ptr; - sobj->ty = ty; - sobj->own = own; - sobj->next = 0; - } - return (PyObject *)sobj; -} - -/* ----------------------------------------------------------------------------- - * Implements a simple Swig Packed type, and use it instead of string - * ----------------------------------------------------------------------------- */ - -typedef struct { - PyObject_HEAD - void *pack; - swig_type_info *ty; - size_t size; -} PySwigPacked; - -SWIGRUNTIME int -PySwigPacked_print(PySwigPacked *v, FILE *fp, int SWIGUNUSEDPARM(flags)) -{ - char result[SWIG_BUFFER_SIZE]; - fputs("<Swig Packed ", fp); - if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) { - fputs("at ", fp); - fputs(result, fp); - } - fputs(v->ty->name,fp); - fputs(">", fp); - return 0; -} - -SWIGRUNTIME PyObject * -PySwigPacked_repr(PySwigPacked *v) -{ - char result[SWIG_BUFFER_SIZE]; - if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) { - return PyString_FromFormat("<Swig Packed at %s%s>", result, v->ty->name); - } else { - return PyString_FromFormat("<Swig Packed %s>", v->ty->name); - } -} - -SWIGRUNTIME PyObject * -PySwigPacked_str(PySwigPacked *v) -{ - char result[SWIG_BUFFER_SIZE]; - if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){ - return PyString_FromFormat("%s%s", result, v->ty->name); - } else { - return PyString_FromString(v->ty->name); - } -} - -SWIGRUNTIME int -PySwigPacked_compare(PySwigPacked *v, PySwigPacked *w) -{ - size_t i = v->size; - size_t j = w->size; - int s = (i < j) ? -1 : ((i > j) ? 1 : 0); - return s ? s : strncmp((char *)v->pack, (char *)w->pack, 2*v->size); -} - -SWIGRUNTIME PyTypeObject* _PySwigPacked_type(void); - -SWIGRUNTIME PyTypeObject* -PySwigPacked_type(void) { - static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigPacked_type(); - return type; -} - -SWIGRUNTIMEINLINE int -PySwigPacked_Check(PyObject *op) { - return ((op)->ob_type == _PySwigPacked_type()) - || (strcmp((op)->ob_type->tp_name,"PySwigPacked") == 0); -} - -SWIGRUNTIME void -PySwigPacked_dealloc(PyObject *v) -{ - if (PySwigPacked_Check(v)) { - PySwigPacked *sobj = (PySwigPacked *) v; - free(sobj->pack); - } - PyObject_DEL(v); -} - -SWIGRUNTIME PyTypeObject* -_PySwigPacked_type(void) { - static char swigpacked_doc[] = "Swig object carries a C/C++ instance pointer"; - static PyTypeObject pyswigpacked_type; - static int type_init = 0; - if (!type_init) { - const PyTypeObject tmp - = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - (char *)"PySwigPacked", /* tp_name */ - sizeof(PySwigPacked), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)PySwigPacked_dealloc, /* tp_dealloc */ - (printfunc)PySwigPacked_print, /* tp_print */ - (getattrfunc)0, /* tp_getattr */ - (setattrfunc)0, /* tp_setattr */ - (cmpfunc)PySwigPacked_compare, /* tp_compare */ - (reprfunc)PySwigPacked_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - (hashfunc)0, /* tp_hash */ - (ternaryfunc)0, /* tp_call */ - (reprfunc)PySwigPacked_str, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - swigpacked_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ -#if PY_VERSION_HEX >= 0x02020000 - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0, /* tp_free */ - 0, /* tp_is_gc */ - 0, /* tp_bases */ - 0, /* tp_mro */ - 0, /* tp_cache */ - 0, /* tp_subclasses */ - 0, /* tp_weaklist */ -#endif -#if PY_VERSION_HEX >= 0x02030000 - 0, /* tp_del */ -#endif -#ifdef COUNT_ALLOCS - 0,0,0,0 /* tp_alloc -> tp_next */ -#endif - }; - pyswigpacked_type = tmp; - pyswigpacked_type.ob_type = &PyType_Type; - type_init = 1; - } - return &pyswigpacked_type; -} - -SWIGRUNTIME PyObject * -PySwigPacked_New(void *ptr, size_t size, swig_type_info *ty) -{ - PySwigPacked *sobj = PyObject_NEW(PySwigPacked, PySwigPacked_type()); - if (sobj) { - void *pack = malloc(size); - if (pack) { - memcpy(pack, ptr, size); - sobj->pack = pack; - sobj->ty = ty; - sobj->size = size; - } else { - PyObject_DEL((PyObject *) sobj); - sobj = 0; - } - } - return (PyObject *) sobj; -} - -SWIGRUNTIME swig_type_info * -PySwigPacked_UnpackData(PyObject *obj, void *ptr, size_t size) -{ - if (PySwigPacked_Check(obj)) { - PySwigPacked *sobj = (PySwigPacked *)obj; - if (sobj->size != size) return 0; - memcpy(ptr, sobj->pack, size); - return sobj->ty; - } else { - return 0; - } -} - -/* ----------------------------------------------------------------------------- - * pointers/data manipulation - * ----------------------------------------------------------------------------- */ - -SWIGRUNTIMEINLINE PyObject * -_SWIG_This(void) -{ - return PyString_FromString("this"); -} - -SWIGRUNTIME PyObject * -SWIG_This(void) -{ - static PyObject *SWIG_STATIC_POINTER(swig_this) = _SWIG_This(); - return swig_this; -} - -/* #define SWIG_PYTHON_SLOW_GETSET_THIS */ - -SWIGRUNTIME PySwigObject * -SWIG_Python_GetSwigThis(PyObject *pyobj) -{ - if (PySwigObject_Check(pyobj)) { - return (PySwigObject *) pyobj; - } else { - PyObject *obj = 0; -#if (!defined(SWIG_PYTHON_SLOW_GETSET_THIS) && (PY_VERSION_HEX >= 0x02030000)) - if (PyInstance_Check(pyobj)) { - obj = _PyInstance_Lookup(pyobj, SWIG_This()); - } else { - PyObject **dictptr = _PyObject_GetDictPtr(pyobj); - if (dictptr != NULL) { - PyObject *dict = *dictptr; - obj = dict ? PyDict_GetItem(dict, SWIG_This()) : 0; - } else { -#ifdef PyWeakref_CheckProxy - if (PyWeakref_CheckProxy(pyobj)) { - PyObject *wobj = PyWeakref_GET_OBJECT(pyobj); - return wobj ? SWIG_Python_GetSwigThis(wobj) : 0; - } -#endif - obj = PyObject_GetAttr(pyobj,SWIG_This()); - if (obj) { - Py_DECREF(obj); - } else { - if (PyErr_Occurred()) PyErr_Clear(); - return 0; - } - } - } -#else - obj = PyObject_GetAttr(pyobj,SWIG_This()); - if (obj) { - Py_DECREF(obj); - } else { - if (PyErr_Occurred()) PyErr_Clear(); - return 0; - } -#endif - if (obj && !PySwigObject_Check(obj)) { - /* a PyObject is called 'this', try to get the 'real this' - PySwigObject from it */ - return SWIG_Python_GetSwigThis(obj); - } - return (PySwigObject *)obj; - } -} - -/* Acquire a pointer value */ - -SWIGRUNTIME int -SWIG_Python_AcquirePtr(PyObject *obj, int own) { - if (own == SWIG_POINTER_OWN) { - PySwigObject *sobj = SWIG_Python_GetSwigThis(obj); - if (sobj) { - int oldown = sobj->own; - sobj->own = own; - return oldown; - } - } - return 0; -} - -/* Convert a pointer value */ - -SWIGRUNTIME int -SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int flags, int *own) { - if (!obj) return SWIG_ERROR; - if (obj == Py_None) { - if (ptr) *ptr = 0; - return SWIG_OK; - } else { - PySwigObject *sobj = SWIG_Python_GetSwigThis(obj); - if (own) - *own = 0; - while (sobj) { - void *vptr = sobj->ptr; - if (ty) { - swig_type_info *to = sobj->ty; - if (to == ty) { - /* no type cast needed */ - if (ptr) *ptr = vptr; - break; - } else { - swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); - if (!tc) { - sobj = (PySwigObject *)sobj->next; - } else { - if (ptr) { - int newmemory = 0; - *ptr = SWIG_TypeCast(tc,vptr,&newmemory); - if (newmemory == SWIG_CAST_NEW_MEMORY) { - assert(own); - if (own) - *own = *own | SWIG_CAST_NEW_MEMORY; - } - } - break; - } - } - } else { - if (ptr) *ptr = vptr; - break; - } - } - if (sobj) { - if (own) - *own = *own | sobj->own; - if (flags & SWIG_POINTER_DISOWN) { - sobj->own = 0; - } - return SWIG_OK; - } else { - int res = SWIG_ERROR; - if (flags & SWIG_POINTER_IMPLICIT_CONV) { - PySwigClientData *data = ty ? (PySwigClientData *) ty->clientdata : 0; - if (data && !data->implicitconv) { - PyObject *klass = data->klass; - if (klass) { - PyObject *impconv; - data->implicitconv = 1; /* avoid recursion and call 'explicit' constructors*/ - impconv = SWIG_Python_CallFunctor(klass, obj); - data->implicitconv = 0; - if (PyErr_Occurred()) { - PyErr_Clear(); - impconv = 0; - } - if (impconv) { - PySwigObject *iobj = SWIG_Python_GetSwigThis(impconv); - if (iobj) { - void *vptr; - res = SWIG_Python_ConvertPtrAndOwn((PyObject*)iobj, &vptr, ty, 0, 0); - if (SWIG_IsOK(res)) { - if (ptr) { - *ptr = vptr; - /* transfer the ownership to 'ptr' */ - iobj->own = 0; - res = SWIG_AddCast(res); - res = SWIG_AddNewMask(res); - } else { - res = SWIG_AddCast(res); - } - } - } - Py_DECREF(impconv); - } - } - } - } - return res; - } - } -} - -/* Convert a function ptr value */ - -SWIGRUNTIME int -SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) { - if (!PyCFunction_Check(obj)) { - return SWIG_ConvertPtr(obj, ptr, ty, 0); - } else { - void *vptr = 0; - - /* here we get the method pointer for callbacks */ - const char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc); - const char *desc = doc ? strstr(doc, "swig_ptr: ") : 0; - if (desc) { - desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0; - if (!desc) return SWIG_ERROR; - } - if (ty) { - swig_cast_info *tc = SWIG_TypeCheck(desc,ty); - if (tc) { - int newmemory = 0; - *ptr = SWIG_TypeCast(tc,vptr,&newmemory); - assert(!newmemory); /* newmemory handling not yet implemented */ - } else { - return SWIG_ERROR; - } - } else { - *ptr = vptr; - } - return SWIG_OK; - } -} - -/* Convert a packed value value */ - -SWIGRUNTIME int -SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty) { - swig_type_info *to = PySwigPacked_UnpackData(obj, ptr, sz); - if (!to) return SWIG_ERROR; - if (ty) { - if (to != ty) { - /* check type cast? */ - swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); - if (!tc) return SWIG_ERROR; - } - } - return SWIG_OK; -} - -/* ----------------------------------------------------------------------------- - * Create a new pointer object - * ----------------------------------------------------------------------------- */ - -/* - Create a new instance object, whitout calling __init__, and set the - 'this' attribute. -*/ - -SWIGRUNTIME PyObject* -SWIG_Python_NewShadowInstance(PySwigClientData *data, PyObject *swig_this) -{ -#if (PY_VERSION_HEX >= 0x02020000) - PyObject *inst = 0; - PyObject *newraw = data->newraw; - if (newraw) { - inst = PyObject_Call(newraw, data->newargs, NULL); - if (inst) { -#if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) - PyObject **dictptr = _PyObject_GetDictPtr(inst); - if (dictptr != NULL) { - PyObject *dict = *dictptr; - if (dict == NULL) { - dict = PyDict_New(); - *dictptr = dict; - PyDict_SetItem(dict, SWIG_This(), swig_this); - } - } -#else - PyObject *key = SWIG_This(); - PyObject_SetAttr(inst, key, swig_this); -#endif - } - } else { - PyObject *dict = PyDict_New(); - PyDict_SetItem(dict, SWIG_This(), swig_this); - inst = PyInstance_NewRaw(data->newargs, dict); - Py_DECREF(dict); - } - return inst; -#else -#if (PY_VERSION_HEX >= 0x02010000) - PyObject *inst; - PyObject *dict = PyDict_New(); - PyDict_SetItem(dict, SWIG_This(), swig_this); - inst = PyInstance_NewRaw(data->newargs, dict); - Py_DECREF(dict); - return (PyObject *) inst; -#else - PyInstanceObject *inst = PyObject_NEW(PyInstanceObject, &PyInstance_Type); - if (inst == NULL) { - return NULL; - } - inst->in_class = (PyClassObject *)data->newargs; - Py_INCREF(inst->in_class); - inst->in_dict = PyDict_New(); - if (inst->in_dict == NULL) { - Py_DECREF(inst); - return NULL; - } -#ifdef Py_TPFLAGS_HAVE_WEAKREFS - inst->in_weakreflist = NULL; -#endif -#ifdef Py_TPFLAGS_GC - PyObject_GC_Init(inst); -#endif - PyDict_SetItem(inst->in_dict, SWIG_This(), swig_this); - return (PyObject *) inst; -#endif -#endif -} - -SWIGRUNTIME void -SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this) -{ - PyObject *dict; -#if (PY_VERSION_HEX >= 0x02020000) && !defined(SWIG_PYTHON_SLOW_GETSET_THIS) - PyObject **dictptr = _PyObject_GetDictPtr(inst); - if (dictptr != NULL) { - dict = *dictptr; - if (dict == NULL) { - dict = PyDict_New(); - *dictptr = dict; - } - PyDict_SetItem(dict, SWIG_This(), swig_this); - return; - } -#endif - dict = PyObject_GetAttrString(inst, (char*)"__dict__"); - PyDict_SetItem(dict, SWIG_This(), swig_this); - Py_DECREF(dict); -} - - -SWIGINTERN PyObject * -SWIG_Python_InitShadowInstance(PyObject *args) { - PyObject *obj[2]; - if (!SWIG_Python_UnpackTuple(args,(char*)"swiginit", 2, 2, obj)) { - return NULL; - } else { - PySwigObject *sthis = SWIG_Python_GetSwigThis(obj[0]); - if (sthis) { - PySwigObject_append((PyObject*) sthis, obj[1]); - } else { - SWIG_Python_SetSwigThis(obj[0], obj[1]); - } - return SWIG_Py_Void(); - } -} - -/* Create a new pointer object */ - -SWIGRUNTIME PyObject * -SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) { - if (!ptr) { - return SWIG_Py_Void(); - } else { - int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; - PyObject *robj = PySwigObject_New(ptr, type, own); - PySwigClientData *clientdata = type ? (PySwigClientData *)(type->clientdata) : 0; - if (clientdata && !(flags & SWIG_POINTER_NOSHADOW)) { - PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj); - if (inst) { - Py_DECREF(robj); - robj = inst; - } - } - return robj; - } -} - -/* Create a new packed object */ - -SWIGRUNTIMEINLINE PyObject * -SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) { - return ptr ? PySwigPacked_New((void *) ptr, sz, type) : SWIG_Py_Void(); -} - -/* -----------------------------------------------------------------------------* - * Get type list - * -----------------------------------------------------------------------------*/ - -#ifdef SWIG_LINK_RUNTIME -void *SWIG_ReturnGlobalTypeList(void *); -#endif - -SWIGRUNTIME swig_module_info * -SWIG_Python_GetModule(void) { - static void *type_pointer = (void *)0; - /* first check if module already created */ - if (!type_pointer) { -#ifdef SWIG_LINK_RUNTIME - type_pointer = SWIG_ReturnGlobalTypeList((void *)0); -#else - type_pointer = PyCObject_Import((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, - (char*)"type_pointer" SWIG_TYPE_TABLE_NAME); - if (PyErr_Occurred()) { - PyErr_Clear(); - type_pointer = (void *)0; - } -#endif - } - return (swig_module_info *) type_pointer; -} - -#if PY_MAJOR_VERSION < 2 -/* PyModule_AddObject function was introduced in Python 2.0. The following function - is copied out of Python/modsupport.c in python version 2.3.4 */ -SWIGINTERN int -PyModule_AddObject(PyObject *m, char *name, PyObject *o) -{ - PyObject *dict; - if (!PyModule_Check(m)) { - PyErr_SetString(PyExc_TypeError, - "PyModule_AddObject() needs module as first arg"); - return SWIG_ERROR; - } - if (!o) { - PyErr_SetString(PyExc_TypeError, - "PyModule_AddObject() needs non-NULL value"); - return SWIG_ERROR; - } - - dict = PyModule_GetDict(m); - if (dict == NULL) { - /* Internal error -- modules must have a dict! */ - PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__", - PyModule_GetName(m)); - return SWIG_ERROR; - } - if (PyDict_SetItemString(dict, name, o)) - return SWIG_ERROR; - Py_DECREF(o); - return SWIG_OK; -} -#endif - -SWIGRUNTIME void -SWIG_Python_DestroyModule(void *vptr) -{ - swig_module_info *swig_module = (swig_module_info *) vptr; - swig_type_info **types = swig_module->types; - size_t i; - for (i =0; i < swig_module->size; ++i) { - swig_type_info *ty = types[i]; - if (ty->owndata) { - PySwigClientData *data = (PySwigClientData *) ty->clientdata; - if (data) PySwigClientData_Del(data); - } - } - Py_DECREF(SWIG_This()); -} - -SWIGRUNTIME void -SWIG_Python_SetModule(swig_module_info *swig_module) { - static PyMethodDef swig_empty_runtime_method_table[] = { {NULL, NULL, 0, NULL} };/* Sentinel */ - - PyObject *module = Py_InitModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, - swig_empty_runtime_method_table); - PyObject *pointer = PyCObject_FromVoidPtr((void *) swig_module, SWIG_Python_DestroyModule); - if (pointer && module) { - PyModule_AddObject(module, (char*)"type_pointer" SWIG_TYPE_TABLE_NAME, pointer); - } else { - Py_XDECREF(pointer); - } -} - -/* The python cached type query */ -SWIGRUNTIME PyObject * -SWIG_Python_TypeCache(void) { - static PyObject *SWIG_STATIC_POINTER(cache) = PyDict_New(); - return cache; -} - -SWIGRUNTIME swig_type_info * -SWIG_Python_TypeQuery(const char *type) -{ - PyObject *cache = SWIG_Python_TypeCache(); - PyObject *key = PyString_FromString(type); - PyObject *obj = PyDict_GetItem(cache, key); - swig_type_info *descriptor; - if (obj) { - descriptor = (swig_type_info *) PyCObject_AsVoidPtr(obj); - } else { - swig_module_info *swig_module = SWIG_Python_GetModule(); - descriptor = SWIG_TypeQueryModule(swig_module, swig_module, type); - if (descriptor) { - obj = PyCObject_FromVoidPtr(descriptor, NULL); - PyDict_SetItem(cache, key, obj); - Py_DECREF(obj); - } - } - Py_DECREF(key); - return descriptor; -} - -/* - For backward compatibility only -*/ -#define SWIG_POINTER_EXCEPTION 0 -#define SWIG_arg_fail(arg) SWIG_Python_ArgFail(arg) -#define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags) - -SWIGRUNTIME int -SWIG_Python_AddErrMesg(const char* mesg, int infront) -{ - if (PyErr_Occurred()) { - PyObject *type = 0; - PyObject *value = 0; - PyObject *traceback = 0; - PyErr_Fetch(&type, &value, &traceback); - if (value) { - PyObject *old_str = PyObject_Str(value); - Py_XINCREF(type); - PyErr_Clear(); - if (infront) { - PyErr_Format(type, "%s %s", mesg, PyString_AsString(old_str)); - } else { - PyErr_Format(type, "%s %s", PyString_AsString(old_str), mesg); - } - Py_DECREF(old_str); - } - return 1; - } else { - return 0; - } -} - -SWIGRUNTIME int -SWIG_Python_ArgFail(int argnum) -{ - if (PyErr_Occurred()) { - /* add information about failing argument */ - char mesg[256]; - PyOS_snprintf(mesg, sizeof(mesg), "argument number %d:", argnum); - return SWIG_Python_AddErrMesg(mesg, 1); - } else { - return 0; - } -} - -SWIGRUNTIMEINLINE const char * -PySwigObject_GetDesc(PyObject *self) -{ - PySwigObject *v = (PySwigObject *)self; - swig_type_info *ty = v ? v->ty : 0; - return ty ? ty->str : (char*)""; -} - -SWIGRUNTIME void -SWIG_Python_TypeError(const char *type, PyObject *obj) -{ - if (type) { -#if defined(SWIG_COBJECT_TYPES) - if (obj && PySwigObject_Check(obj)) { - const char *otype = (const char *) PySwigObject_GetDesc(obj); - if (otype) { - PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'PySwigObject(%s)' is received", - type, otype); - return; - } - } else -#endif - { - const char *otype = (obj ? obj->ob_type->tp_name : 0); - if (otype) { - PyObject *str = PyObject_Str(obj); - const char *cstr = str ? PyString_AsString(str) : 0; - if (cstr) { - PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received", - type, otype, cstr); - } else { - PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received", - type, otype); - } - Py_XDECREF(str); - return; - } - } - PyErr_Format(PyExc_TypeError, "a '%s' is expected", type); - } else { - PyErr_Format(PyExc_TypeError, "unexpected type is received"); - } -} - - -/* Convert a pointer value, signal an exception on a type mismatch */ -SWIGRUNTIME void * -SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) { - void *result; - if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) { - PyErr_Clear(); - if (flags & SWIG_POINTER_EXCEPTION) { - SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj); - SWIG_Python_ArgFail(argnum); - } - } - return result; -} - - -#ifdef __cplusplus -#if 0 -{ /* cc-mode */ -#endif -} -#endif - - - -#define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0) - -#define SWIG_contract_assert(expr, msg) if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } else - - - -/* -------- TYPES TABLE (BEGIN) -------- */ - -#define SWIGTYPE_p_TDB_DATA swig_types[0] -#define SWIGTYPE_p_char swig_types[1] -#define SWIGTYPE_p_int swig_types[2] -#define SWIGTYPE_p_long_long swig_types[3] -#define SWIGTYPE_p_short swig_types[4] -#define SWIGTYPE_p_signed_char swig_types[5] -#define SWIGTYPE_p_tdb_context swig_types[6] -#define SWIGTYPE_p_unsigned_char swig_types[7] -#define SWIGTYPE_p_unsigned_int swig_types[8] -#define SWIGTYPE_p_unsigned_long_long swig_types[9] -#define SWIGTYPE_p_unsigned_short swig_types[10] -static swig_type_info *swig_types[12]; -static swig_module_info swig_module = {swig_types, 11, 0, 0, 0, 0}; -#define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) -#define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) - -/* -------- TYPES TABLE (END) -------- */ - -#if (PY_VERSION_HEX <= 0x02000000) -# if !defined(SWIG_PYTHON_CLASSIC) -# error "This python version requires swig to be run with the '-classic' option" -# endif -#endif -#if (PY_VERSION_HEX <= 0x02020000) -# error "This python version requires swig to be run with the '-nomodern' option" -#endif -#if (PY_VERSION_HEX <= 0x02020000) -# error "This python version requires swig to be run with the '-nomodernargs' option" -#endif -#ifndef METH_O -# error "This python version requires swig to be run with the '-nofastunpack' option" -#endif -#ifdef SWIG_TypeQuery -# undef SWIG_TypeQuery -#endif -#define SWIG_TypeQuery SWIG_Python_TypeQuery - -/*----------------------------------------------- - @(target):= _tdb.so - ------------------------------------------------*/ -#define SWIG_init init_tdb - -#define SWIG_name "_tdb" - -#define SWIGVERSION 0x010335 -#define SWIG_VERSION SWIGVERSION - - -#define SWIG_as_voidptr(a) (void *)((const void *)(a)) -#define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),(void**)(a)) - - - -/* This symbol is used in both includes.h and Python.h which causes an - annoying compiler warning. */ - -#ifdef HAVE_FSTAT -#undef HAVE_FSTAT -#endif - -/* Include tdb headers */ -#include <stdint.h> -#include <signal.h> -#include <tdb.h> -#include <fcntl.h> - -typedef TDB_CONTEXT tdb; - - - #define SWIG_From_long PyInt_FromLong - - -SWIGINTERNINLINE PyObject * -SWIG_From_int (int value) -{ - return SWIG_From_long (value); -} - - -SWIGINTERN swig_type_info* -SWIG_pchar_descriptor(void) -{ - static int init = 0; - static swig_type_info* info = 0; - if (!init) { - info = SWIG_TypeQuery("_p_char"); - init = 1; - } - return info; -} - - -SWIGINTERN int -SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc) -{ - if (PyString_Check(obj)) { - char *cstr; Py_ssize_t len; - PyString_AsStringAndSize(obj, &cstr, &len); - if (cptr) { - if (alloc) { - /* - In python the user should not be able to modify the inner - string representation. To warranty that, if you define - SWIG_PYTHON_SAFE_CSTRINGS, a new/copy of the python string - buffer is always returned. - - The default behavior is just to return the pointer value, - so, be careful. - */ -#if defined(SWIG_PYTHON_SAFE_CSTRINGS) - if (*alloc != SWIG_OLDOBJ) -#else - if (*alloc == SWIG_NEWOBJ) -#endif - { - *cptr = (char *)memcpy((char *)malloc((len + 1)*sizeof(char)), cstr, sizeof(char)*(len + 1)); - *alloc = SWIG_NEWOBJ; - } - else { - *cptr = cstr; - *alloc = SWIG_OLDOBJ; - } - } else { - *cptr = PyString_AsString(obj); - } - } - if (psize) *psize = len + 1; - return SWIG_OK; - } else { - swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); - if (pchar_descriptor) { - void* vptr = 0; - if (SWIG_ConvertPtr(obj, &vptr, pchar_descriptor, 0) == SWIG_OK) { - if (cptr) *cptr = (char *) vptr; - if (psize) *psize = vptr ? (strlen((char *)vptr) + 1) : 0; - if (alloc) *alloc = SWIG_OLDOBJ; - return SWIG_OK; - } - } - } - return SWIG_TypeError; -} - - - - - -#include <limits.h> -#if !defined(SWIG_NO_LLONG_MAX) -# if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__) -# define LLONG_MAX __LONG_LONG_MAX__ -# define LLONG_MIN (-LLONG_MAX - 1LL) -# define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL) -# endif -#endif - - -SWIGINTERN int -SWIG_AsVal_double (PyObject *obj, double *val) -{ - int res = SWIG_TypeError; - if (PyFloat_Check(obj)) { - if (val) *val = PyFloat_AsDouble(obj); - return SWIG_OK; - } else if (PyInt_Check(obj)) { - if (val) *val = PyInt_AsLong(obj); - return SWIG_OK; - } else if (PyLong_Check(obj)) { - double v = PyLong_AsDouble(obj); - if (!PyErr_Occurred()) { - if (val) *val = v; - return SWIG_OK; - } else { - PyErr_Clear(); - } - } -#ifdef SWIG_PYTHON_CAST_MODE - { - int dispatch = 0; - double d = PyFloat_AsDouble(obj); - if (!PyErr_Occurred()) { - if (val) *val = d; - return SWIG_AddCast(SWIG_OK); - } else { - PyErr_Clear(); - } - if (!dispatch) { - long v = PyLong_AsLong(obj); - if (!PyErr_Occurred()) { - if (val) *val = v; - return SWIG_AddCast(SWIG_AddCast(SWIG_OK)); - } else { - PyErr_Clear(); - } - } - } -#endif - return res; -} - - -#include <float.h> - - -#include <math.h> - - -SWIGINTERNINLINE int -SWIG_CanCastAsInteger(double *d, double min, double max) { - double x = *d; - if ((min <= x && x <= max)) { - double fx = floor(x); - double cx = ceil(x); - double rd = ((x - fx) < 0.5) ? fx : cx; /* simple rint */ - if ((errno == EDOM) || (errno == ERANGE)) { - errno = 0; - } else { - double summ, reps, diff; - if (rd < x) { - diff = x - rd; - } else if (rd > x) { - diff = rd - x; - } else { - return 1; - } - summ = rd + x; - reps = diff/summ; - if (reps < 8*DBL_EPSILON) { - *d = rd; - return 1; - } - } - } - return 0; -} - - -SWIGINTERN int -SWIG_AsVal_long (PyObject *obj, long* val) -{ - if (PyInt_Check(obj)) { - if (val) *val = PyInt_AsLong(obj); - return SWIG_OK; - } else if (PyLong_Check(obj)) { - long v = PyLong_AsLong(obj); - if (!PyErr_Occurred()) { - if (val) *val = v; - return SWIG_OK; - } else { - PyErr_Clear(); - } - } -#ifdef SWIG_PYTHON_CAST_MODE - { - int dispatch = 0; - long v = PyInt_AsLong(obj); - if (!PyErr_Occurred()) { - if (val) *val = v; - return SWIG_AddCast(SWIG_OK); - } else { - PyErr_Clear(); - } - if (!dispatch) { - double d; - int res = SWIG_AddCast(SWIG_AsVal_double (obj,&d)); - if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LONG_MIN, LONG_MAX)) { - if (val) *val = (long)(d); - return res; - } - } - } -#endif - return SWIG_TypeError; -} - - -SWIGINTERN int -SWIG_AsVal_int (PyObject * obj, int *val) -{ - long v; - int res = SWIG_AsVal_long (obj, &v); - if (SWIG_IsOK(res)) { - if ((v < INT_MIN || v > INT_MAX)) { - return SWIG_OverflowError; - } else { - if (val) *val = (int)(v); - } - } - return res; -} - -SWIGINTERN tdb *new_tdb(char const *name,int hash_size,int tdb_flags,int flags,mode_t mode){ - return tdb_open(name, hash_size, tdb_flags, flags, mode); - } -SWIGINTERN void delete_tdb(tdb *self){ tdb_close(self); } - -SWIGINTERNINLINE PyObject * -SWIG_FromCharPtrAndSize(const char* carray, size_t size) -{ - if (carray) { - if (size > INT_MAX) { - swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); - return pchar_descriptor ? - SWIG_NewPointerObj((char *)(carray), pchar_descriptor, 0) : SWIG_Py_Void(); - } else { - return PyString_FromStringAndSize(carray, (int)(size)); - } - } else { - return SWIG_Py_Void(); - } -} - - -SWIGINTERNINLINE PyObject * -SWIG_FromCharPtr(const char *cptr) -{ - return SWIG_FromCharPtrAndSize(cptr, (cptr ? strlen(cptr) : 0)); -} - - -SWIGINTERNINLINE PyObject* -SWIG_From_unsigned_SS_long (unsigned long value) -{ - return (value > LONG_MAX) ? - PyLong_FromUnsignedLong(value) : PyInt_FromLong((long)(value)); -} - - -SWIGINTERNINLINE PyObject * -SWIG_From_size_t (size_t value) -{ - return SWIG_From_unsigned_SS_long ((unsigned long)(value)); -} - -#ifdef __cplusplus -extern "C" { -#endif -SWIGINTERN PyObject *_wrap_new_Tdb(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { - PyObject *resultobj = 0; - char *arg1 = (char *) 0 ; - int arg2 ; - int arg3 ; - int arg4 ; - mode_t arg5 ; - tdb *result = 0 ; - int res1 ; - char *buf1 = 0 ; - int alloc1 = 0 ; - int val2 ; - int ecode2 = 0 ; - int val3 ; - int ecode3 = 0 ; - int val4 ; - int ecode4 = 0 ; - int val5 ; - int ecode5 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - PyObject * obj2 = 0 ; - PyObject * obj3 = 0 ; - PyObject * obj4 = 0 ; - char * kwnames[] = { - (char *) "name",(char *) "hash_size",(char *) "tdb_flags",(char *) "flags",(char *) "mode", NULL - }; - - arg2 = 0; - arg3 = TDB_DEFAULT; - arg4 = O_RDWR; - arg5 = 0600; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O|OOOO:new_Tdb",kwnames,&obj0,&obj1,&obj2,&obj3,&obj4)) SWIG_fail; - res1 = SWIG_AsCharPtrAndSize(obj0, &buf1, NULL, &alloc1); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_Tdb" "', argument " "1"" of type '" "char const *""'"); - } - arg1 = (char *)(buf1); - if (obj1) { - ecode2 = SWIG_AsVal_int(obj1, &val2); - if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "new_Tdb" "', argument " "2"" of type '" "int""'"); - } - arg2 = (int)(val2); - } - if (obj2) { - ecode3 = SWIG_AsVal_int(obj2, &val3); - if (!SWIG_IsOK(ecode3)) { - SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "new_Tdb" "', argument " "3"" of type '" "int""'"); - } - arg3 = (int)(val3); - } - if (obj3) { - ecode4 = SWIG_AsVal_int(obj3, &val4); - if (!SWIG_IsOK(ecode4)) { - SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "new_Tdb" "', argument " "4"" of type '" "int""'"); - } - arg4 = (int)(val4); - } - if (obj4) { - ecode5 = SWIG_AsVal_int(obj4, &val5); - if (!SWIG_IsOK(ecode5)) { - SWIG_exception_fail(SWIG_ArgError(ecode5), "in method '" "new_Tdb" "', argument " "5"" of type '" "mode_t""'"); - } - arg5 = (mode_t)(val5); - } - result = (tdb *)new_tdb((char const *)arg1,arg2,arg3,arg4,arg5); - /* Throw an IOError exception from errno if tdb_open() returns NULL */ - if (result == NULL) { - PyErr_SetFromErrno(PyExc_IOError); - SWIG_fail; - } - resultobj = SWIG_NewPointerObj(result, SWIGTYPE_p_tdb_context, 0); - if (alloc1 == SWIG_NEWOBJ) free((char*)buf1); - return resultobj; -fail: - if (alloc1 == SWIG_NEWOBJ) free((char*)buf1); - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_error(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - enum TDB_ERROR result; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!args) SWIG_fail; - swig_obj[0] = args; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_error" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - result = (enum TDB_ERROR)tdb_error(arg1); - resultobj = SWIG_From_int((int)(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_delete_Tdb(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!args) SWIG_fail; - swig_obj[0] = args; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, SWIG_POINTER_DISOWN | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Tdb" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - delete_tdb(arg1); - - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_close(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - int result; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!args) SWIG_fail; - swig_obj[0] = args; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_close" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - result = (int)tdb_close(arg1); - resultobj = SWIG_From_int((int)(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_append(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - TDB_DATA arg2 ; - TDB_DATA arg3 ; - int result; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - PyObject * obj2 = 0 ; - char * kwnames[] = { - (char *) "self",(char *) "key",(char *) "new_dbuf", NULL - }; - - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO:Tdb_append",kwnames,&obj0,&obj1,&obj2)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_append" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - if (obj1 == Py_None) { - (&arg2)->dsize = 0; - (&arg2)->dptr = NULL; - } else if (!PyString_Check(obj1)) { - PyErr_SetString(PyExc_TypeError, "string arg expected"); - return NULL; - } else { - (&arg2)->dsize = PyString_Size(obj1); - (&arg2)->dptr = (uint8_t *)PyString_AsString(obj1); - } - if (obj2 == Py_None) { - (&arg3)->dsize = 0; - (&arg3)->dptr = NULL; - } else if (!PyString_Check(obj2)) { - PyErr_SetString(PyExc_TypeError, "string arg expected"); - return NULL; - } else { - (&arg3)->dsize = PyString_Size(obj2); - (&arg3)->dptr = (uint8_t *)PyString_AsString(obj2); - } - result = (int)tdb_append(arg1,arg2,arg3); - resultobj = SWIG_From_int((int)(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_errorstr(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - char *result = 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!args) SWIG_fail; - swig_obj[0] = args; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_errorstr" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - result = (char *)tdb_errorstr(arg1); - resultobj = SWIG_FromCharPtr((const char *)result); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - TDB_DATA arg2 ; - TDB_DATA result; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - char * kwnames[] = { - (char *) "self",(char *) "key", NULL - }; - - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Tdb_get",kwnames,&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_get" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - if (obj1 == Py_None) { - (&arg2)->dsize = 0; - (&arg2)->dptr = NULL; - } else if (!PyString_Check(obj1)) { - PyErr_SetString(PyExc_TypeError, "string arg expected"); - return NULL; - } else { - (&arg2)->dsize = PyString_Size(obj1); - (&arg2)->dptr = (uint8_t *)PyString_AsString(obj1); - } - result = tdb_fetch(arg1,arg2); - if ((&result)->dptr == NULL && (&result)->dsize == 0) { - resultobj = Py_None; - } else { - resultobj = PyString_FromStringAndSize((const char *)(&result)->dptr, (&result)->dsize); - free((&result)->dptr); - } - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_delete(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - TDB_DATA arg2 ; - int result; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - char * kwnames[] = { - (char *) "self",(char *) "key", NULL - }; - - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Tdb_delete",kwnames,&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_delete" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - if (obj1 == Py_None) { - (&arg2)->dsize = 0; - (&arg2)->dptr = NULL; - } else if (!PyString_Check(obj1)) { - PyErr_SetString(PyExc_TypeError, "string arg expected"); - return NULL; - } else { - (&arg2)->dsize = PyString_Size(obj1); - (&arg2)->dptr = (uint8_t *)PyString_AsString(obj1); - } - result = (int)tdb_delete(arg1,arg2); - resultobj = SWIG_From_int((int)(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_store(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - TDB_DATA arg2 ; - TDB_DATA arg3 ; - int arg4 ; - int result; - void *argp1 = 0 ; - int res1 = 0 ; - int val4 ; - int ecode4 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - PyObject * obj2 = 0 ; - PyObject * obj3 = 0 ; - char * kwnames[] = { - (char *) "self",(char *) "key",(char *) "dbuf",(char *) "flag", NULL - }; - - arg4 = TDB_REPLACE; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO|O:Tdb_store",kwnames,&obj0,&obj1,&obj2,&obj3)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_store" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - if (obj1 == Py_None) { - (&arg2)->dsize = 0; - (&arg2)->dptr = NULL; - } else if (!PyString_Check(obj1)) { - PyErr_SetString(PyExc_TypeError, "string arg expected"); - return NULL; - } else { - (&arg2)->dsize = PyString_Size(obj1); - (&arg2)->dptr = (uint8_t *)PyString_AsString(obj1); - } - if (obj2 == Py_None) { - (&arg3)->dsize = 0; - (&arg3)->dptr = NULL; - } else if (!PyString_Check(obj2)) { - PyErr_SetString(PyExc_TypeError, "string arg expected"); - return NULL; - } else { - (&arg3)->dsize = PyString_Size(obj2); - (&arg3)->dptr = (uint8_t *)PyString_AsString(obj2); - } - if (obj3) { - ecode4 = SWIG_AsVal_int(obj3, &val4); - if (!SWIG_IsOK(ecode4)) { - SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "Tdb_store" "', argument " "4"" of type '" "int""'"); - } - arg4 = (int)(val4); - } - result = (int)tdb_store(arg1,arg2,arg3,arg4); - resultobj = SWIG_From_int((int)(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_exists(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - TDB_DATA arg2 ; - int result; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - char * kwnames[] = { - (char *) "self",(char *) "key", NULL - }; - - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Tdb_exists",kwnames,&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_exists" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - if (obj1 == Py_None) { - (&arg2)->dsize = 0; - (&arg2)->dptr = NULL; - } else if (!PyString_Check(obj1)) { - PyErr_SetString(PyExc_TypeError, "string arg expected"); - return NULL; - } else { - (&arg2)->dsize = PyString_Size(obj1); - (&arg2)->dptr = (uint8_t *)PyString_AsString(obj1); - } - result = (int)tdb_exists(arg1,arg2); - resultobj = SWIG_From_int((int)(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_firstkey(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - TDB_DATA result; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!args) SWIG_fail; - swig_obj[0] = args; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_firstkey" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - result = tdb_firstkey(arg1); - if ((&result)->dptr == NULL && (&result)->dsize == 0) { - resultobj = Py_None; - } else { - resultobj = PyString_FromStringAndSize((const char *)(&result)->dptr, (&result)->dsize); - free((&result)->dptr); - } - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_nextkey(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - TDB_DATA arg2 ; - TDB_DATA result; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - char * kwnames[] = { - (char *) "self",(char *) "key", NULL - }; - - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Tdb_nextkey",kwnames,&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_nextkey" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - if (obj1 == Py_None) { - (&arg2)->dsize = 0; - (&arg2)->dptr = NULL; - } else if (!PyString_Check(obj1)) { - PyErr_SetString(PyExc_TypeError, "string arg expected"); - return NULL; - } else { - (&arg2)->dsize = PyString_Size(obj1); - (&arg2)->dptr = (uint8_t *)PyString_AsString(obj1); - } - result = tdb_nextkey(arg1,arg2); - if ((&result)->dptr == NULL && (&result)->dsize == 0) { - resultobj = Py_None; - } else { - resultobj = PyString_FromStringAndSize((const char *)(&result)->dptr, (&result)->dsize); - free((&result)->dptr); - } - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_lock_all(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - int result; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!args) SWIG_fail; - swig_obj[0] = args; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_lock_all" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - result = (int)tdb_lockall(arg1); - resultobj = SWIG_From_int((int)(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_unlock_all(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - int result; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!args) SWIG_fail; - swig_obj[0] = args; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_unlock_all" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - result = (int)tdb_unlockall(arg1); - resultobj = SWIG_From_int((int)(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_read_lock_all(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - int result; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!args) SWIG_fail; - swig_obj[0] = args; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_read_lock_all" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - result = (int)tdb_lockall_read(arg1); - resultobj = SWIG_From_int((int)(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_read_unlock_all(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - int result; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!args) SWIG_fail; - swig_obj[0] = args; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_read_unlock_all" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - result = (int)tdb_unlockall_read(arg1); - resultobj = SWIG_From_int((int)(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_reopen(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - int result; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!args) SWIG_fail; - swig_obj[0] = args; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_reopen" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - result = (int)tdb_reopen(arg1); - resultobj = SWIG_From_int((int)(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_transaction_start(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - int result; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!args) SWIG_fail; - swig_obj[0] = args; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_transaction_start" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - result = (int)tdb_transaction_start(arg1); - resultobj = SWIG_From_int((int)(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_transaction_commit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - int result; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!args) SWIG_fail; - swig_obj[0] = args; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_transaction_commit" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - result = (int)tdb_transaction_commit(arg1); - resultobj = SWIG_From_int((int)(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_transaction_cancel(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - int result; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!args) SWIG_fail; - swig_obj[0] = args; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_transaction_cancel" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - result = (int)tdb_transaction_cancel(arg1); - resultobj = SWIG_From_int((int)(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_transaction_recover(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - int result; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!args) SWIG_fail; - swig_obj[0] = args; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_transaction_recover" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - result = (int)tdb_transaction_recover(arg1); - resultobj = SWIG_From_int((int)(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_hash_size(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - int result; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!args) SWIG_fail; - swig_obj[0] = args; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_hash_size" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - result = (int)tdb_hash_size(arg1); - resultobj = SWIG_From_int((int)(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_map_size(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - size_t result; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!args) SWIG_fail; - swig_obj[0] = args; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_map_size" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - result = tdb_map_size(arg1); - resultobj = SWIG_From_size_t((size_t)(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_get_flags(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - int result; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!args) SWIG_fail; - swig_obj[0] = args; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_get_flags" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - result = (int)tdb_get_flags(arg1); - resultobj = SWIG_From_int((int)(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_set_max_dead(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - int arg2 ; - void *argp1 = 0 ; - int res1 = 0 ; - int val2 ; - int ecode2 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - char * kwnames[] = { - (char *) "self",(char *) "max_dead", NULL - }; - - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Tdb_set_max_dead",kwnames,&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_set_max_dead" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - ecode2 = SWIG_AsVal_int(obj1, &val2); - if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Tdb_set_max_dead" "', argument " "2"" of type '" "int""'"); - } - arg2 = (int)(val2); - tdb_set_max_dead(arg1,arg2); - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Tdb_name(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - tdb *arg1 = (tdb *) 0 ; - char *result = 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!args) SWIG_fail; - swig_obj[0] = args; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_name" "', argument " "1"" of type '" "tdb *""'"); - } - arg1 = (tdb *)(argp1); - result = (char *)tdb_name(arg1); - resultobj = SWIG_FromCharPtr((const char *)result); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *Tdb_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *obj; - if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL; - SWIG_TypeNewClientData(SWIGTYPE_p_tdb_context, SWIG_NewClientData(obj)); - return SWIG_Py_Void(); -} - -SWIGINTERN PyObject *Tdb_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - return SWIG_Python_InitShadowInstance(args); -} - -static PyMethodDef SwigMethods[] = { - { (char *)"new_Tdb", (PyCFunction) _wrap_new_Tdb, METH_VARARGS | METH_KEYWORDS, (char *)"\n" - "S.__init__(name,hash_size=0,tdb_flags=TDB_DEFAULT,flags=O_RDWR,mode=0600)\n" - "Open a TDB file.\n" - ""}, - { (char *)"Tdb_error", (PyCFunction)_wrap_Tdb_error, METH_O, (char *)"\n" - "S.error() -> int\n" - "Find last error number returned by operation on this TDB.\n" - ""}, - { (char *)"delete_Tdb", (PyCFunction)_wrap_delete_Tdb, METH_O, NULL}, - { (char *)"Tdb_close", (PyCFunction)_wrap_Tdb_close, METH_O, (char *)"\n" - "S.close() -> None\n" - "Close the TDB file.\n" - ""}, - { (char *)"Tdb_append", (PyCFunction) _wrap_Tdb_append, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Tdb_errorstr", (PyCFunction)_wrap_Tdb_errorstr, METH_O, (char *)"\n" - "S.errorstr() -> errorstring\n" - "Obtain last error message.\n" - ""}, - { (char *)"Tdb_get", (PyCFunction) _wrap_Tdb_get, METH_VARARGS | METH_KEYWORDS, (char *)"\n" - "S.fetch(key) -> value\n" - "Fetch a value.\n" - ""}, - { (char *)"Tdb_delete", (PyCFunction) _wrap_Tdb_delete, METH_VARARGS | METH_KEYWORDS, (char *)"\n" - "S.delete(key) -> None\n" - "Delete an entry.\n" - ""}, - { (char *)"Tdb_store", (PyCFunction) _wrap_Tdb_store, METH_VARARGS | METH_KEYWORDS, (char *)"\n" - "S.store(key, value, flag=TDB_REPLACE) -> None\n" - "Store an entry.\n" - ""}, - { (char *)"Tdb_exists", (PyCFunction) _wrap_Tdb_exists, METH_VARARGS | METH_KEYWORDS, (char *)"\n" - "S.exists(key) -> bool\n" - "Check whether key exists in this database.\n" - ""}, - { (char *)"Tdb_firstkey", (PyCFunction)_wrap_Tdb_firstkey, METH_O, (char *)"\n" - "S.firstkey() -> data\n" - "Return the first key in this database.\n" - ""}, - { (char *)"Tdb_nextkey", (PyCFunction) _wrap_Tdb_nextkey, METH_VARARGS | METH_KEYWORDS, (char *)"\n" - "S.nextkey(prev) -> data\n" - "Return the next key in this database.\n" - ""}, - { (char *)"Tdb_lock_all", (PyCFunction)_wrap_Tdb_lock_all, METH_O, (char *)"S.lockall() -> bool"}, - { (char *)"Tdb_unlock_all", (PyCFunction)_wrap_Tdb_unlock_all, METH_O, (char *)"S.unlockall() -> bool"}, - { (char *)"Tdb_read_lock_all", (PyCFunction)_wrap_Tdb_read_lock_all, METH_O, NULL}, - { (char *)"Tdb_read_unlock_all", (PyCFunction)_wrap_Tdb_read_unlock_all, METH_O, NULL}, - { (char *)"Tdb_reopen", (PyCFunction)_wrap_Tdb_reopen, METH_O, (char *)"\n" - "S.reopen() -> bool\n" - "Reopen this file.\n" - ""}, - { (char *)"Tdb_transaction_start", (PyCFunction)_wrap_Tdb_transaction_start, METH_O, (char *)"\n" - "S.transaction_start() -> None\n" - "Start a new transaction.\n" - ""}, - { (char *)"Tdb_transaction_commit", (PyCFunction)_wrap_Tdb_transaction_commit, METH_O, (char *)"\n" - "S.transaction_commit() -> None\n" - "Commit the currently active transaction.\n" - ""}, - { (char *)"Tdb_transaction_cancel", (PyCFunction)_wrap_Tdb_transaction_cancel, METH_O, (char *)"\n" - "S.transaction_cancel() -> None\n" - "Cancel the currently active transaction.\n" - ""}, - { (char *)"Tdb_transaction_recover", (PyCFunction)_wrap_Tdb_transaction_recover, METH_O, NULL}, - { (char *)"Tdb_hash_size", (PyCFunction)_wrap_Tdb_hash_size, METH_O, (char *)"S.hash_size() -> int"}, - { (char *)"Tdb_map_size", (PyCFunction)_wrap_Tdb_map_size, METH_O, (char *)"S.map_size() -> int"}, - { (char *)"Tdb_get_flags", (PyCFunction)_wrap_Tdb_get_flags, METH_O, (char *)"S.get_flags() -> int"}, - { (char *)"Tdb_set_max_dead", (PyCFunction) _wrap_Tdb_set_max_dead, METH_VARARGS | METH_KEYWORDS, (char *)"S.set_max_dead(int) -> None"}, - { (char *)"Tdb_name", (PyCFunction)_wrap_Tdb_name, METH_O, (char *)"\n" - "S.name() -> path\n" - "Return filename of this TDB file.\n" - ""}, - { (char *)"Tdb_swigregister", Tdb_swigregister, METH_VARARGS, NULL}, - { (char *)"Tdb_swiginit", Tdb_swiginit, METH_VARARGS, NULL}, - { NULL, NULL, 0, NULL } -}; - - -/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ - -static swig_type_info _swigt__p_TDB_DATA = {"_p_TDB_DATA", "TDB_DATA *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_int = {"_p_int", "intptr_t *|int *|int_least32_t *|int_fast32_t *|int32_t *|int_fast16_t *|mode_t *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_long_long = {"_p_long_long", "int_least64_t *|int_fast64_t *|int64_t *|long long *|intmax_t *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_short = {"_p_short", "short *|int_least16_t *|int16_t *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_signed_char = {"_p_signed_char", "signed char *|int_least8_t *|int_fast8_t *|int8_t *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_tdb_context = {"_p_tdb_context", "struct tdb_context *|tdb *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_unsigned_char = {"_p_unsigned_char", "unsigned char *|uint_least8_t *|uint_fast8_t *|uint8_t *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_unsigned_int = {"_p_unsigned_int", "uintptr_t *|uint_least32_t *|uint_fast32_t *|uint32_t *|unsigned int *|uint_fast16_t *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_unsigned_long_long = {"_p_unsigned_long_long", "uint_least64_t *|uint_fast64_t *|uint64_t *|unsigned long long *|uintmax_t *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_unsigned_short = {"_p_unsigned_short", "unsigned short *|uint_least16_t *|uint16_t *", 0, 0, (void*)0, 0}; - -static swig_type_info *swig_type_initial[] = { - &_swigt__p_TDB_DATA, - &_swigt__p_char, - &_swigt__p_int, - &_swigt__p_long_long, - &_swigt__p_short, - &_swigt__p_signed_char, - &_swigt__p_tdb_context, - &_swigt__p_unsigned_char, - &_swigt__p_unsigned_int, - &_swigt__p_unsigned_long_long, - &_swigt__p_unsigned_short, -}; - -static swig_cast_info _swigc__p_TDB_DATA[] = { {&_swigt__p_TDB_DATA, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_int[] = { {&_swigt__p_int, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_long_long[] = { {&_swigt__p_long_long, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_short[] = { {&_swigt__p_short, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_signed_char[] = { {&_swigt__p_signed_char, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_tdb_context[] = { {&_swigt__p_tdb_context, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_unsigned_char[] = { {&_swigt__p_unsigned_char, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_unsigned_int[] = { {&_swigt__p_unsigned_int, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_unsigned_long_long[] = { {&_swigt__p_unsigned_long_long, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_unsigned_short[] = { {&_swigt__p_unsigned_short, 0, 0, 0},{0, 0, 0, 0}}; - -static swig_cast_info *swig_cast_initial[] = { - _swigc__p_TDB_DATA, - _swigc__p_char, - _swigc__p_int, - _swigc__p_long_long, - _swigc__p_short, - _swigc__p_signed_char, - _swigc__p_tdb_context, - _swigc__p_unsigned_char, - _swigc__p_unsigned_int, - _swigc__p_unsigned_long_long, - _swigc__p_unsigned_short, -}; - - -/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */ - -static swig_const_info swig_const_table[] = { -{0, 0, 0, 0.0, 0, 0}}; - -#ifdef __cplusplus -} -#endif -/* ----------------------------------------------------------------------------- - * Type initialization: - * This problem is tough by the requirement that no dynamic - * memory is used. Also, since swig_type_info structures store pointers to - * swig_cast_info structures and swig_cast_info structures store pointers back - * to swig_type_info structures, we need some lookup code at initialization. - * The idea is that swig generates all the structures that are needed. - * The runtime then collects these partially filled structures. - * The SWIG_InitializeModule function takes these initial arrays out of - * swig_module, and does all the lookup, filling in the swig_module.types - * array with the correct data and linking the correct swig_cast_info - * structures together. - * - * The generated swig_type_info structures are assigned staticly to an initial - * array. We just loop through that array, and handle each type individually. - * First we lookup if this type has been already loaded, and if so, use the - * loaded structure instead of the generated one. Then we have to fill in the - * cast linked list. The cast data is initially stored in something like a - * two-dimensional array. Each row corresponds to a type (there are the same - * number of rows as there are in the swig_type_initial array). Each entry in - * a column is one of the swig_cast_info structures for that type. - * The cast_initial array is actually an array of arrays, because each row has - * a variable number of columns. So to actually build the cast linked list, - * we find the array of casts associated with the type, and loop through it - * adding the casts to the list. The one last trick we need to do is making - * sure the type pointer in the swig_cast_info struct is correct. - * - * First off, we lookup the cast->type name to see if it is already loaded. - * There are three cases to handle: - * 1) If the cast->type has already been loaded AND the type we are adding - * casting info to has not been loaded (it is in this module), THEN we - * replace the cast->type pointer with the type pointer that has already - * been loaded. - * 2) If BOTH types (the one we are adding casting info to, and the - * cast->type) are loaded, THEN the cast info has already been loaded by - * the previous module so we just ignore it. - * 3) Finally, if cast->type has not already been loaded, then we add that - * swig_cast_info to the linked list (because the cast->type) pointer will - * be correct. - * ----------------------------------------------------------------------------- */ - -#ifdef __cplusplus -extern "C" { -#if 0 -} /* c-mode */ -#endif -#endif - -#if 0 -#define SWIGRUNTIME_DEBUG -#endif - - -SWIGRUNTIME void -SWIG_InitializeModule(void *clientdata) { - size_t i; - swig_module_info *module_head, *iter; - int found, init; - - clientdata = clientdata; - - /* check to see if the circular list has been setup, if not, set it up */ - if (swig_module.next==0) { - /* Initialize the swig_module */ - swig_module.type_initial = swig_type_initial; - swig_module.cast_initial = swig_cast_initial; - swig_module.next = &swig_module; - init = 1; - } else { - init = 0; - } - - /* Try and load any already created modules */ - module_head = SWIG_GetModule(clientdata); - if (!module_head) { - /* This is the first module loaded for this interpreter */ - /* so set the swig module into the interpreter */ - SWIG_SetModule(clientdata, &swig_module); - module_head = &swig_module; - } else { - /* the interpreter has loaded a SWIG module, but has it loaded this one? */ - found=0; - iter=module_head; - do { - if (iter==&swig_module) { - found=1; - break; - } - iter=iter->next; - } while (iter!= module_head); - - /* if the is found in the list, then all is done and we may leave */ - if (found) return; - /* otherwise we must add out module into the list */ - swig_module.next = module_head->next; - module_head->next = &swig_module; - } - - /* When multiple interpeters are used, a module could have already been initialized in - a different interpreter, but not yet have a pointer in this interpreter. - In this case, we do not want to continue adding types... everything should be - set up already */ - if (init == 0) return; - - /* Now work on filling in swig_module.types */ -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: size %d\n", swig_module.size); -#endif - for (i = 0; i < swig_module.size; ++i) { - swig_type_info *type = 0; - swig_type_info *ret; - swig_cast_info *cast; - -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); -#endif - - /* if there is another module already loaded */ - if (swig_module.next != &swig_module) { - type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name); - } - if (type) { - /* Overwrite clientdata field */ -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: found type %s\n", type->name); -#endif - if (swig_module.type_initial[i]->clientdata) { - type->clientdata = swig_module.type_initial[i]->clientdata; -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name); -#endif - } - } else { - type = swig_module.type_initial[i]; - } - - /* Insert casting types */ - cast = swig_module.cast_initial[i]; - while (cast->type) { - /* Don't need to add information already in the list */ - ret = 0; -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: look cast %s\n", cast->type->name); -#endif - if (swig_module.next != &swig_module) { - ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name); -#ifdef SWIGRUNTIME_DEBUG - if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name); -#endif - } - if (ret) { - if (type == swig_module.type_initial[i]) { -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: skip old type %s\n", ret->name); -#endif - cast->type = ret; - ret = 0; - } else { - /* Check for casting already in the list */ - swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type); -#ifdef SWIGRUNTIME_DEBUG - if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); -#endif - if (!ocast) ret = 0; - } - } - - if (!ret) { -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name); -#endif - if (type->cast) { - type->cast->prev = cast; - cast->next = type->cast; - } - type->cast = cast; - } - cast++; - } - /* Set entry in modules->types array equal to the type */ - swig_module.types[i] = type; - } - swig_module.types[i] = 0; - -#ifdef SWIGRUNTIME_DEBUG - printf("**** SWIG_InitializeModule: Cast List ******\n"); - for (i = 0; i < swig_module.size; ++i) { - int j = 0; - swig_cast_info *cast = swig_module.cast_initial[i]; - printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); - while (cast->type) { - printf("SWIG_InitializeModule: cast type %s\n", cast->type->name); - cast++; - ++j; - } - printf("---- Total casts: %d\n",j); - } - printf("**** SWIG_InitializeModule: Cast List ******\n"); -#endif -} - -/* This function will propagate the clientdata field of type to -* any new swig_type_info structures that have been added into the list -* of equivalent types. It is like calling -* SWIG_TypeClientData(type, clientdata) a second time. -*/ -SWIGRUNTIME void -SWIG_PropagateClientData(void) { - size_t i; - swig_cast_info *equiv; - static int init_run = 0; - - if (init_run) return; - init_run = 1; - - for (i = 0; i < swig_module.size; i++) { - if (swig_module.types[i]->clientdata) { - equiv = swig_module.types[i]->cast; - while (equiv) { - if (!equiv->converter) { - if (equiv->type && !equiv->type->clientdata) - SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata); - } - equiv = equiv->next; - } - } - } -} - -#ifdef __cplusplus -#if 0 -{ - /* c-mode */ -#endif -} -#endif - - - -#ifdef __cplusplus -extern "C" { -#endif - - /* Python-specific SWIG API */ -#define SWIG_newvarlink() SWIG_Python_newvarlink() -#define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr) -#define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants) - - /* ----------------------------------------------------------------------------- - * global variable support code. - * ----------------------------------------------------------------------------- */ - - typedef struct swig_globalvar { - char *name; /* Name of global variable */ - PyObject *(*get_attr)(void); /* Return the current value */ - int (*set_attr)(PyObject *); /* Set the value */ - struct swig_globalvar *next; - } swig_globalvar; - - typedef struct swig_varlinkobject { - PyObject_HEAD - swig_globalvar *vars; - } swig_varlinkobject; - - SWIGINTERN PyObject * - swig_varlink_repr(swig_varlinkobject *SWIGUNUSEDPARM(v)) { - return PyString_FromString("<Swig global variables>"); - } - - SWIGINTERN PyObject * - swig_varlink_str(swig_varlinkobject *v) { - PyObject *str = PyString_FromString("("); - swig_globalvar *var; - for (var = v->vars; var; var=var->next) { - PyString_ConcatAndDel(&str,PyString_FromString(var->name)); - if (var->next) PyString_ConcatAndDel(&str,PyString_FromString(", ")); - } - PyString_ConcatAndDel(&str,PyString_FromString(")")); - return str; - } - - SWIGINTERN int - swig_varlink_print(swig_varlinkobject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) { - PyObject *str = swig_varlink_str(v); - fprintf(fp,"Swig global variables "); - fprintf(fp,"%s\n", PyString_AsString(str)); - Py_DECREF(str); - return 0; - } - - SWIGINTERN void - swig_varlink_dealloc(swig_varlinkobject *v) { - swig_globalvar *var = v->vars; - while (var) { - swig_globalvar *n = var->next; - free(var->name); - free(var); - var = n; - } - } - - SWIGINTERN PyObject * - swig_varlink_getattr(swig_varlinkobject *v, char *n) { - PyObject *res = NULL; - swig_globalvar *var = v->vars; - while (var) { - if (strcmp(var->name,n) == 0) { - res = (*var->get_attr)(); - break; - } - var = var->next; - } - if (res == NULL && !PyErr_Occurred()) { - PyErr_SetString(PyExc_NameError,"Unknown C global variable"); - } - return res; - } - - SWIGINTERN int - swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) { - int res = 1; - swig_globalvar *var = v->vars; - while (var) { - if (strcmp(var->name,n) == 0) { - res = (*var->set_attr)(p); - break; - } - var = var->next; - } - if (res == 1 && !PyErr_Occurred()) { - PyErr_SetString(PyExc_NameError,"Unknown C global variable"); - } - return res; - } - - SWIGINTERN PyTypeObject* - swig_varlink_type(void) { - static char varlink__doc__[] = "Swig var link object"; - static PyTypeObject varlink_type; - static int type_init = 0; - if (!type_init) { - const PyTypeObject tmp - = { - PyObject_HEAD_INIT(NULL) - 0, /* Number of items in variable part (ob_size) */ - (char *)"swigvarlink", /* Type name (tp_name) */ - sizeof(swig_varlinkobject), /* Basic size (tp_basicsize) */ - 0, /* Itemsize (tp_itemsize) */ - (destructor) swig_varlink_dealloc, /* Deallocator (tp_dealloc) */ - (printfunc) swig_varlink_print, /* Print (tp_print) */ - (getattrfunc) swig_varlink_getattr, /* get attr (tp_getattr) */ - (setattrfunc) swig_varlink_setattr, /* Set attr (tp_setattr) */ - 0, /* tp_compare */ - (reprfunc) swig_varlink_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - (reprfunc)swig_varlink_str, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - 0, /* tp_flags */ - varlink__doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ -#if PY_VERSION_HEX >= 0x02020000 - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */ -#endif -#if PY_VERSION_HEX >= 0x02030000 - 0, /* tp_del */ -#endif -#ifdef COUNT_ALLOCS - 0,0,0,0 /* tp_alloc -> tp_next */ -#endif - }; - varlink_type = tmp; - varlink_type.ob_type = &PyType_Type; - type_init = 1; - } - return &varlink_type; - } - - /* Create a variable linking object for use later */ - SWIGINTERN PyObject * - SWIG_Python_newvarlink(void) { - swig_varlinkobject *result = PyObject_NEW(swig_varlinkobject, swig_varlink_type()); - if (result) { - result->vars = 0; - } - return ((PyObject*) result); - } - - SWIGINTERN void - SWIG_Python_addvarlink(PyObject *p, char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) { - swig_varlinkobject *v = (swig_varlinkobject *) p; - swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar)); - if (gv) { - size_t size = strlen(name)+1; - gv->name = (char *)malloc(size); - if (gv->name) { - strncpy(gv->name,name,size); - gv->get_attr = get_attr; - gv->set_attr = set_attr; - gv->next = v->vars; - } - } - v->vars = gv; - } - - SWIGINTERN PyObject * - SWIG_globals(void) { - static PyObject *_SWIG_globals = 0; - if (!_SWIG_globals) _SWIG_globals = SWIG_newvarlink(); - return _SWIG_globals; - } - - /* ----------------------------------------------------------------------------- - * constants/methods manipulation - * ----------------------------------------------------------------------------- */ - - /* Install Constants */ - SWIGINTERN void - SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) { - PyObject *obj = 0; - size_t i; - for (i = 0; constants[i].type; ++i) { - switch(constants[i].type) { - case SWIG_PY_POINTER: - obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0); - break; - case SWIG_PY_BINARY: - obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype)); - break; - default: - obj = 0; - break; - } - if (obj) { - PyDict_SetItemString(d, constants[i].name, obj); - Py_DECREF(obj); - } - } - } - - /* -----------------------------------------------------------------------------*/ - /* Fix SwigMethods to carry the callback ptrs when needed */ - /* -----------------------------------------------------------------------------*/ - - SWIGINTERN void - SWIG_Python_FixMethods(PyMethodDef *methods, - swig_const_info *const_table, - swig_type_info **types, - swig_type_info **types_initial) { - size_t i; - for (i = 0; methods[i].ml_name; ++i) { - const char *c = methods[i].ml_doc; - if (c && (c = strstr(c, "swig_ptr: "))) { - int j; - swig_const_info *ci = 0; - const char *name = c + 10; - for (j = 0; const_table[j].type; ++j) { - if (strncmp(const_table[j].name, name, - strlen(const_table[j].name)) == 0) { - ci = &(const_table[j]); - break; - } - } - if (ci) { - size_t shift = (ci->ptype) - types; - swig_type_info *ty = types_initial[shift]; - size_t ldoc = (c - methods[i].ml_doc); - size_t lptr = strlen(ty->name)+2*sizeof(void*)+2; - char *ndoc = (char*)malloc(ldoc + lptr + 10); - if (ndoc) { - char *buff = ndoc; - void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0; - if (ptr) { - strncpy(buff, methods[i].ml_doc, ldoc); - buff += ldoc; - strncpy(buff, "swig_ptr: ", 10); - buff += 10; - SWIG_PackVoidPtr(buff, ptr, ty->name, lptr); - methods[i].ml_doc = ndoc; - } - } - } - } - } - } - -#ifdef __cplusplus -} -#endif - -/* -----------------------------------------------------------------------------* - * Partial Init method - * -----------------------------------------------------------------------------*/ - -#ifdef __cplusplus -extern "C" -#endif -SWIGEXPORT void SWIG_init(void) { - PyObject *m, *d; - - /* Fix SwigMethods to carry the callback ptrs when needed */ - SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial); - - m = Py_InitModule((char *) SWIG_name, SwigMethods); - d = PyModule_GetDict(m); - - SWIG_InitializeModule(0); - SWIG_InstallConstants(d,swig_const_table); - - - SWIG_Python_SetConstant(d, "REPLACE",SWIG_From_int((int)(TDB_REPLACE))); - SWIG_Python_SetConstant(d, "INSERT",SWIG_From_int((int)(TDB_INSERT))); - SWIG_Python_SetConstant(d, "MODIFY",SWIG_From_int((int)(TDB_MODIFY))); - SWIG_Python_SetConstant(d, "DEFAULT",SWIG_From_int((int)(TDB_DEFAULT))); - SWIG_Python_SetConstant(d, "CLEAR_IF_FIRST",SWIG_From_int((int)(TDB_CLEAR_IF_FIRST))); - SWIG_Python_SetConstant(d, "INTERNAL",SWIG_From_int((int)(TDB_INTERNAL))); - SWIG_Python_SetConstant(d, "NOLOCK",SWIG_From_int((int)(TDB_NOLOCK))); - SWIG_Python_SetConstant(d, "NOMMAP",SWIG_From_int((int)(TDB_NOMMAP))); - SWIG_Python_SetConstant(d, "CONVERT",SWIG_From_int((int)(TDB_CONVERT))); - SWIG_Python_SetConstant(d, "BIGENDIAN",SWIG_From_int((int)(TDB_BIGENDIAN))); - SWIG_Python_SetConstant(d, "TDB_SUCCESS",SWIG_From_int((int)(TDB_SUCCESS))); - SWIG_Python_SetConstant(d, "TDB_ERR_CORRUPT",SWIG_From_int((int)(TDB_ERR_CORRUPT))); - SWIG_Python_SetConstant(d, "TDB_ERR_IO",SWIG_From_int((int)(TDB_ERR_IO))); - SWIG_Python_SetConstant(d, "TDB_ERR_LOCK",SWIG_From_int((int)(TDB_ERR_LOCK))); - SWIG_Python_SetConstant(d, "TDB_ERR_OOM",SWIG_From_int((int)(TDB_ERR_OOM))); - SWIG_Python_SetConstant(d, "TDB_ERR_EXISTS",SWIG_From_int((int)(TDB_ERR_EXISTS))); - SWIG_Python_SetConstant(d, "TDB_ERR_NOLOCK",SWIG_From_int((int)(TDB_ERR_NOLOCK))); - SWIG_Python_SetConstant(d, "TDB_ERR_LOCK_TIMEOUT",SWIG_From_int((int)(TDB_ERR_LOCK_TIMEOUT))); - SWIG_Python_SetConstant(d, "TDB_ERR_NOEXIST",SWIG_From_int((int)(TDB_ERR_NOEXIST))); - SWIG_Python_SetConstant(d, "TDB_ERR_EINVAL",SWIG_From_int((int)(TDB_ERR_EINVAL))); - SWIG_Python_SetConstant(d, "TDB_ERR_RDONLY",SWIG_From_int((int)(TDB_ERR_RDONLY))); -} - diff --git a/source/lib/tdb/web/index.html b/source/lib/tdb/web/index.html deleted file mode 100644 index a53da6b8f7..0000000000 --- a/source/lib/tdb/web/index.html +++ /dev/null @@ -1,42 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> -<HTML> -<HEAD> -<TITLE>ldb</TITLE> -</HEAD> -<BODY BGCOLOR="#ffffff" TEXT="#000000" VLINK="#292555" LINK="#292555" ALINK="#cc0033"> - -<h1>tdb</h1> - -TDB is a Trivial Database. In concept, it is very much like GDBM, and BSD's DB -except that it allows multiple simultaneous writers and uses locking -internally to keep writers from trampling on each other. TDB is also extremely -small. - -<h2>Discussion and bug reports</h2> - -tdb does not currently have its own mailing list or bug tracking -system. For now, please use the <a -href="https://lists.samba.org/mailman/listinfo/samba-technical">samba-technical</a> -mailing list, and the <a href="http://bugzilla.samba.org/">Samba -bugzilla</a> bug tracking system. - -<h2>Download</h2> - -You can download the latest release either via rsync or git.<br> -<br> -To fetch via git see the following guide:<br> -<a href="http://wiki.samba.org/index.php/Using_Git_for_Samba_Development">Using Git for Samba Development</a><br> -Once you have cloned the tree switch to the v4-0-test branch and cd into the source/lib/tdb directory.<br> -<br> -To fetch via rsync use these commands: - -<pre> - rsync -Pavz samba.org::ftp/unpacked/tdb . - rsync -Pavz samba.org::ftp/unpacked/libreplace . -</pre> - -and build in tdb. It will find the replace library in the directory -above automatically. - -</BODY> -</HTML> diff --git a/source/lib/time.c b/source/lib/time.c index 8cefef6e23..425539c3b0 100644 --- a/source/lib/time.c +++ b/source/lib/time.c @@ -1351,13 +1351,6 @@ time_t nt_time_to_unix_abs(const NTTIME *nt) return (time_t)d; } -time_t uint64s_nt_time_to_unix_abs(const uint64_t *src) -{ - NTTIME nttime; - nttime = *src; - return nt_time_to_unix_abs(&nttime); -} - /**************************************************************************** Put a 8 byte filetime from a struct timespec. Uses GMT. ****************************************************************************/ diff --git a/source/lib/util.c b/source/lib/util.c index 201d87aeb5..dafaf03d56 100644 --- a/source/lib/util.c +++ b/source/lib/util.c @@ -60,6 +60,8 @@ enum protocol_types Protocol = PROTOCOL_COREPLUS; /* this is used by the chaining code */ int chain_size = 0; +int trans_num = 0; + static enum remote_arch_types ra_type = RA_UNKNOWN; /*********************************************************************** @@ -348,11 +350,6 @@ int get_cmdline_auth_info_signing_state(void) return cmdline_auth_info.signing_state; } -void set_cmdline_auth_info_use_kerberos(bool b) -{ - cmdline_auth_info.use_kerberos = b; -} - bool get_cmdline_auth_info_use_kerberos(void) { return cmdline_auth_info.use_kerberos; @@ -1907,10 +1904,10 @@ bool is_in_path(const char *name, name_compare_entry *namelist, bool case_sensit if possible. ********************************************************************/ -void set_namearray(name_compare_entry **ppname_array, const char *namelist) +void set_namearray(name_compare_entry **ppname_array, char *namelist) { char *name_end; - const char *nameptr = namelist; + char *nameptr = namelist; int num_entries = 0; int i; @@ -2603,19 +2600,6 @@ char *lib_path(const char *name) } /** - * @brief Returns an absolute path to a file in the Samba modules directory. - * - * @param name File to find, relative to MODULESDIR. - * - * @retval Pointer to a string containing the full path. - **/ - -char *modules_path(const char *name) -{ - return talloc_asprintf(talloc_tos(), "%s/%s", get_dyn_MODULESDIR(), name); -} - -/** * @brief Returns an absolute path to a file in the Samba data directory. * * @param name File to find, relative to CODEPAGEDIR. @@ -3087,7 +3071,7 @@ struct server_id interpret_pid(const char *pid_string) result.pid = pid; } else if (sscanf(pid_string, "%u", &pid) == 1) { - result.vnn = get_my_vnn(); + result.vnn = NONCLUSTER_VNN; result.pid = pid; } else { @@ -3466,16 +3450,6 @@ bool is_valid_policy_hnd(const POLICY_HND *hnd) return (memcmp(&tmp, hnd, sizeof(tmp)) != 0); } -bool policy_hnd_equal(const struct policy_handle *hnd1, - const struct policy_handle *hnd2) -{ - if (!hnd1 || !hnd2) { - return false; - } - - return (memcmp(hnd1, hnd2, sizeof(*hnd1)) == 0); -} - /**************************************************************** strip off leading '\\' from a hostname ****************************************************************/ diff --git a/source/lib/util_nttoken.c b/source/lib/util_nttoken.c index 774ef498b7..13c66a5f45 100644 --- a/source/lib/util_nttoken.c +++ b/source/lib/util_nttoken.c @@ -7,7 +7,6 @@ * Copyright (C) Rafal Szczesniak 2002 * Copyright (C) Volker Lendecke 2006 * Copyright (C) Michael Adam 2007 - * Copyright (C) Guenther Deschner 2007 * * 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 @@ -38,12 +37,14 @@ NT_USER_TOKEN *dup_nt_token(TALLOC_CTX *mem_ctx, const NT_USER_TOKEN *ptoken) if (!ptoken) return NULL; - token = TALLOC_ZERO_P(mem_ctx, NT_USER_TOKEN); + token = TALLOC_P(mem_ctx, NT_USER_TOKEN); if (token == NULL) { DEBUG(0, ("talloc failed\n")); return NULL; } + ZERO_STRUCTP(token); + if (ptoken->user_sids && ptoken->num_sids) { token->user_sids = (DOM_SID *)talloc_memdup( token, ptoken->user_sids, sizeof(DOM_SID) * ptoken->num_sids ); @@ -66,52 +67,3 @@ NT_USER_TOKEN *dup_nt_token(TALLOC_CTX *mem_ctx, const NT_USER_TOKEN *ptoken) return token; } -/**************************************************************************** - merge NT tokens -****************************************************************************/ - -NTSTATUS merge_nt_token(TALLOC_CTX *mem_ctx, - const struct nt_user_token *token_1, - const struct nt_user_token *token_2, - struct nt_user_token **token_out) -{ - struct nt_user_token *token = NULL; - NTSTATUS status; - int i; - - if (!token_1 || !token_2 || !token_out) { - return NT_STATUS_INVALID_PARAMETER; - } - - token = TALLOC_ZERO_P(mem_ctx, struct nt_user_token); - NT_STATUS_HAVE_NO_MEMORY(token); - - for (i=0; i < token_1->num_sids; i++) { - status = add_sid_to_array_unique(mem_ctx, - &token_1->user_sids[i], - &token->user_sids, - &token->num_sids); - if (!NT_STATUS_IS_OK(status)) { - TALLOC_FREE(token); - return status; - } - } - - for (i=0; i < token_2->num_sids; i++) { - status = add_sid_to_array_unique(mem_ctx, - &token_2->user_sids[i], - &token->user_sids, - &token->num_sids); - if (!NT_STATUS_IS_OK(status)) { - TALLOC_FREE(token); - return status; - } - } - - se_priv_add(&token->privileges, &token_1->privileges); - se_priv_add(&token->privileges, &token_2->privileges); - - *token_out = token; - - return NT_STATUS_OK; -} diff --git a/source/lib/util_reg_api.c b/source/lib/util_reg_api.c index 8f28e9c282..60031d97d3 100644 --- a/source/lib/util_reg_api.c +++ b/source/lib/util_reg_api.c @@ -91,15 +91,16 @@ WERROR registry_pull_value(TALLOC_CTX *mem_ctx, goto error; } - if (!convert_string_talloc(value, CH_UTF16LE, CH_UNIX, tmp, - length+2, &value->v.sz.str, - &value->v.sz.len, False)) { - SAFE_FREE(tmp); + value->v.sz.len = convert_string_talloc( + value, CH_UTF16LE, CH_UNIX, tmp, length+2, + &value->v.sz.str, False); + + SAFE_FREE(tmp); + + if (value->v.sz.len == (size_t)-1) { err = WERR_INVALID_PARAM; goto error; } - - SAFE_FREE(tmp); break; } case REG_MULTI_SZ: @@ -142,13 +143,11 @@ WERROR registry_push_value(TALLOC_CTX *mem_ctx, } case REG_SZ: case REG_EXPAND_SZ: { - if (!convert_string_talloc(mem_ctx, CH_UNIX, CH_UTF16LE, - value->v.sz.str, - MIN(value->v.sz.len, - strlen(value->v.sz.str)+1), - (void *)&(presult->data), - &presult->length, False)) - { + presult->length = convert_string_talloc( + mem_ctx, CH_UNIX, CH_UTF16LE, value->v.sz.str, + MIN(value->v.sz.len, strlen(value->v.sz.str)+1), + (void *)&(presult->data), False); + if (presult->length == (size_t)-1) { return WERR_NOMEM; } break; @@ -177,13 +176,12 @@ WERROR registry_push_value(TALLOC_CTX *mem_ctx, /* convert the single strings */ for (count = 0; count < value->v.multi_sz.num_strings; count++) { - if (!convert_string_talloc(strings, CH_UNIX, - CH_UTF16LE, value->v.multi_sz.strings[count], + string_lengths[count] = convert_string_talloc( + strings, CH_UNIX, CH_UTF16LE, + value->v.multi_sz.strings[count], strlen(value->v.multi_sz.strings[count])+1, - (void *)&strings[count], - &string_lengths[count], false)) - { - + (void *)&strings[count], false); + if (string_lengths[count] == (size_t)-1) { TALLOC_FREE(tmp_ctx); return WERR_NOMEM; } diff --git a/source/lib/util_str.c b/source/lib/util_str.c index 9f952abf10..a2458c88b6 100644 --- a/source/lib/util_str.c +++ b/source/lib/util_str.c @@ -208,14 +208,16 @@ int StrCaseCmp(const char *s, const char *t) return +1; } - if (!push_ucs2_allocate(&buffer_s, ps, &size)) { + size = push_ucs2_allocate(&buffer_s, ps); + if (size == (size_t)-1) { return strcmp(ps, pt); /* Not quite the right answer, but finding the right one under this failure case is expensive, and it's pretty close */ } - if (!push_ucs2_allocate(&buffer_t, pt, &size)) { + size = push_ucs2_allocate(&buffer_t, pt); + if (size == (size_t)-1) { SAFE_FREE(buffer_s); return strcmp(ps, pt); /* Not quite the right answer, but finding the right one @@ -269,14 +271,16 @@ int StrnCaseCmp(const char *s, const char *t, size_t len) return 0; } - if (!push_ucs2_allocate(&buffer_s, ps, &size)) { + size = push_ucs2_allocate(&buffer_s, ps); + if (size == (size_t)-1) { return strncmp(ps, pt, len-n); /* Not quite the right answer, but finding the right one under this failure case is expensive, and it's pretty close */ } - if (!push_ucs2_allocate(&buffer_t, pt, &size)) { + size = push_ucs2_allocate(&buffer_t, pt); + if (size == (size_t)-1) { SAFE_FREE(buffer_s); return strncmp(ps, pt, len-n); /* Not quite the right answer, but finding the right one @@ -476,9 +480,9 @@ char *skip_string(const char *base, size_t len, char *buf) size_t str_charnum(const char *s) { - size_t ret, converted_size; + size_t ret; smb_ucs2_t *tmpbuf2 = NULL; - if (!push_ucs2_allocate(&tmpbuf2, s, &converted_size)) { + if (push_ucs2_allocate(&tmpbuf2, s) == (size_t)-1) { return 0; } ret = strlen_w(tmpbuf2); @@ -494,9 +498,9 @@ size_t str_charnum(const char *s) size_t str_ascii_charnum(const char *s) { - size_t ret, converted_size; + size_t ret; char *tmpbuf2 = NULL; - if (!push_ascii_allocate(&tmpbuf2, s, &converted_size)) { + if (push_ascii_allocate(&tmpbuf2, s) == (size_t)-1) { return 0; } ret = strlen(tmpbuf2); @@ -606,9 +610,8 @@ bool strhasupper(const char *s) { smb_ucs2_t *tmp, *p; bool ret; - size_t converted_size; - if (!push_ucs2_allocate(&tmp, s, &converted_size)) { + if (push_ucs2_allocate(&tmp, s) == -1) { return false; } @@ -631,9 +634,8 @@ bool strhaslower(const char *s) { smb_ucs2_t *tmp, *p; bool ret; - size_t converted_size; - if (!push_ucs2_allocate(&tmp, s, &converted_size)) { + if (push_ucs2_allocate(&tmp, s) == -1) { return false; } @@ -657,9 +659,8 @@ size_t count_chars(const char *s,char c) smb_ucs2_t *ptr; int count; smb_ucs2_t *alloc_tmpbuf = NULL; - size_t converted_size; - if (!push_ucs2_allocate(&alloc_tmpbuf, s, &converted_size)) { + if (push_ucs2_allocate(&alloc_tmpbuf, s) == (size_t)-1) { return 0; } @@ -1409,7 +1410,6 @@ char *strchr_m(const char *src, char c) smb_ucs2_t *p; const char *s; char *ret; - size_t converted_size; /* characters below 0x3F are guaranteed to not appear in non-initial position in multi-byte charsets */ @@ -1435,7 +1435,7 @@ char *strchr_m(const char *src, char c) s = src; #endif - if (!push_ucs2_allocate(&ws, s, &converted_size)) { + if (push_ucs2_allocate(&ws, s)==(size_t)-1) { /* Wrong answer, but what can we do... */ return strchr(src, c); } @@ -1445,7 +1445,7 @@ char *strchr_m(const char *src, char c) return NULL; } *p = 0; - if (!pull_ucs2_allocate(&s2, ws, &converted_size)) { + if (pull_ucs2_allocate(&s2, ws)==(size_t)-1) { SAFE_FREE(ws); /* Wrong answer, but what can we do... */ return strchr(src, c); @@ -1504,9 +1504,8 @@ char *strrchr_m(const char *s, char c) char *s2 = NULL; smb_ucs2_t *p; char *ret; - size_t converted_size; - if (!push_ucs2_allocate(&ws, s, &converted_size)) { + if (push_ucs2_allocate(&ws,s)==(size_t)-1) { /* Wrong answer, but what can we do. */ return strrchr(s, c); } @@ -1516,7 +1515,7 @@ char *strrchr_m(const char *s, char c) return NULL; } *p = 0; - if (!pull_ucs2_allocate(&s2, ws, &converted_size)) { + if (pull_ucs2_allocate(&s2,ws)==(size_t)-1) { SAFE_FREE(ws); /* Wrong answer, but what can we do. */ return strrchr(s, c); @@ -1539,9 +1538,8 @@ char *strnrchr_m(const char *s, char c, unsigned int n) char *s2 = NULL; smb_ucs2_t *p; char *ret; - size_t converted_size; - if (!push_ucs2_allocate(&ws, s, &converted_size)) { + if (push_ucs2_allocate(&ws,s)==(size_t)-1) { /* Too hard to try and get right. */ return NULL; } @@ -1551,7 +1549,7 @@ char *strnrchr_m(const char *s, char c, unsigned int n) return NULL; } *p = 0; - if (!pull_ucs2_allocate(&s2, ws, &converted_size)) { + if (pull_ucs2_allocate(&s2,ws)==(size_t)-1) { SAFE_FREE(ws); /* Too hard to try and get right. */ return NULL; @@ -1574,7 +1572,7 @@ char *strstr_m(const char *src, const char *findstr) char *s2; char *retp; - size_t converted_size, findstr_len = 0; + size_t findstr_len = 0; /* for correctness */ if (!findstr[0]) { @@ -1610,12 +1608,12 @@ char *strstr_m(const char *src, const char *findstr) s = src; #endif - if (!push_ucs2_allocate(&src_w, src, &converted_size)) { + if (push_ucs2_allocate(&src_w, src) == (size_t)-1) { DEBUG(0,("strstr_m: src malloc fail\n")); return NULL; } - if (!push_ucs2_allocate(&find_w, findstr, &converted_size)) { + if (push_ucs2_allocate(&find_w, findstr) == (size_t)-1) { SAFE_FREE(src_w); DEBUG(0,("strstr_m: find malloc fail\n")); return NULL; @@ -1630,7 +1628,7 @@ char *strstr_m(const char *src, const char *findstr) } *p = 0; - if (!pull_ucs2_allocate(&s2, src_w, &converted_size)) { + if (pull_ucs2_allocate(&s2, src_w) == (size_t)-1) { SAFE_FREE(src_w); SAFE_FREE(find_w); DEBUG(0,("strstr_m: dest malloc fail\n")); @@ -2618,23 +2616,6 @@ char *talloc_asprintf_strupper_m(TALLOC_CTX *t, const char *fmt, ...) return ret; } -char *talloc_asprintf_strlower_m(TALLOC_CTX *t, const char *fmt, ...) -{ - va_list ap; - char *ret; - - va_start(ap, fmt); - ret = talloc_vasprintf(t, fmt, ap); - va_end(ap); - - if (ret == NULL) { - return NULL; - } - strlower_m(ret); - return ret; -} - - /* Returns the substring from src between the first occurrence of the char "front" and the first occurence of the char "back". diff --git a/source/lib/util_unistr.c b/source/lib/util_unistr.c index 4e78d1b064..5b769dfdda 100644 --- a/source/lib/util_unistr.c +++ b/source/lib/util_unistr.c @@ -313,12 +313,14 @@ int rpcstr_pull_unistr2_fstring(char *dest, UNISTR2 *src) char *rpcstr_pull_unistr2_talloc(TALLOC_CTX *ctx, const UNISTR2 *src) { char *dest = NULL; - size_t dest_len; - - if (!convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, src->buffer, - src->uni_str_len * 2, (void *)&dest, - &dest_len, true)) - { + size_t dest_len = convert_string_talloc(ctx, + CH_UTF16LE, + CH_UNIX, + src->buffer, + src->uni_str_len * 2, + (void *)&dest, + true); + if (dest_len == (size_t)-1) { return NULL; } @@ -363,11 +365,7 @@ int rpcstr_push(void *dest, const char *src, size_t dest_len, int flags) int rpcstr_push_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src) { - size_t size; - if (push_ucs2_talloc(ctx, dest, src, &size)) - return size; - else - return -1; + return push_ucs2_talloc(ctx, dest, src); } /******************************************************************* diff --git a/source/lib/util_uuid.c b/source/lib/util_uuid.c index 3a8f7b3f4f..36c04e9b84 100644 --- a/source/lib/util_uuid.c +++ b/source/lib/util_uuid.c @@ -129,3 +129,5 @@ char *guid_binstring(const struct GUID *guid) return binary_string_rfc2254((char *)guid_flat.info, UUID_FLAT_SIZE); } + + diff --git a/source/lib/version.c b/source/lib/version.c index 3982646f56..3cae02ad2e 100644 --- a/source/lib/version.c +++ b/source/lib/version.c @@ -23,16 +23,39 @@ const char *samba_version_string(void) { -#ifdef SAMBA_VERSION_VENDOR_FUNCTION - return SAMBA_VERSION_VENDOR_FUNCTION; -#else /* SAMBA_VERSION_VENDOR_FUNCTION */ - #ifdef SAMBA_VERSION_VENDOR_SUFFIX - #ifdef SAMBA_VERSION_VENDOR_PATCH - return SAMBA_VERSION_OFFICIAL_STRING "-" SAMBA_VERSION_VENDOR_SUFFIX \ - "-" SAMBA_VERSION_VENDOR_PATCH; - #endif /* SAMBA_VERSION_VENDOR_PATCH */ - return SAMBA_VERSION_OFFICIAL_STRING "-" SAMBA_VERSION_VENDOR_SUFFIX; - #endif /* SAMBA_VERSION_VENDOR_SUFFIX */ -#endif /* SAMBA_VERSION_VENDOR_FUNCTION */ +#ifndef SAMBA_VERSION_VENDOR_SUFFIX return SAMBA_VERSION_OFFICIAL_STRING; +#else + static char *samba_version; + int res; +#ifdef SAMBA_VERSION_VENDOR_PATCH + char *tmp_version; +#endif + + if (samba_version != NULL) + return samba_version; + + res = asprintf(&samba_version, "%s-%s", + SAMBA_VERSION_OFFICIAL_STRING, + SAMBA_VERSION_VENDOR_SUFFIX); + /* + * Can't use smb_panic here due to dependencies + */ + assert(res != -1); + +#ifdef SAMBA_VERSION_VENDOR_PATCH + res = asprintf(&tmp_version, "%s-%d", samba_version, + SAMBA_VERSION_VENDOR_PATCH); + /* + * Can't use smb_panic here due to dependencies + */ + assert(res != -1); + + SAFE_FREE(samba_version); + + samba_version = tmp_version; +#endif + + return samba_version; +#endif } |