diff options
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/charcnv.c | 2 | ||||
-rw-r--r-- | source3/lib/dbwrap_ctdb.c | 12 | ||||
-rw-r--r-- | source3/lib/dbwrap_rbt.c | 8 | ||||
-rw-r--r-- | source3/lib/errmap_unix.c | 3 | ||||
-rw-r--r-- | source3/lib/events.c | 42 | ||||
-rw-r--r-- | source3/lib/iconv.c | 4 | ||||
-rw-r--r-- | source3/lib/interfaces.c | 74 | ||||
-rw-r--r-- | source3/lib/messages.c | 18 | ||||
-rw-r--r-- | source3/lib/netapi/cm.c | 60 | ||||
-rw-r--r-- | source3/lib/netapi/group.c | 12 | ||||
-rw-r--r-- | source3/lib/netapi/user.c | 4 | ||||
-rw-r--r-- | source3/lib/smbconf/smbconf_reg.c | 13 | ||||
-rw-r--r-- | source3/lib/smbconf/testsuite.c | 2 | ||||
-rw-r--r-- | source3/lib/util.c | 67 | ||||
-rw-r--r-- | source3/lib/util_sock.c | 106 | ||||
-rw-r--r-- | source3/lib/util_unistr.c | 16 | ||||
-rw-r--r-- | source3/lib/version_test.c | 26 | ||||
-rw-r--r-- | source3/lib/wb_reqtrans.c | 184 | ||||
-rw-r--r-- | source3/lib/wbclient.c | 394 | ||||
-rw-r--r-- | source3/lib/winbind_util.c | 1 |
20 files changed, 483 insertions, 565 deletions
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 81cb9a5094..c3b345142f 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -763,7 +763,7 @@ bool convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, * converted. */ bool convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, - void const *src, size_t srclen, void **dst, + void const *src, size_t srclen, void *dst, size_t *converted_size, bool allow_bad_conv) { void **dest = (void **)dst; diff --git a/source3/lib/dbwrap_ctdb.c b/source3/lib/dbwrap_ctdb.c index 03667ff355..4a5bf6d81a 100644 --- a/source3/lib/dbwrap_ctdb.c +++ b/source3/lib/dbwrap_ctdb.c @@ -121,9 +121,9 @@ static struct ctdb_marshall_buffer *db_ctdb_marshall_add(TALLOC_CTX *mem_ctx, { struct ctdb_rec_data *r; size_t m_size, r_size; - struct ctdb_marshall_buffer *m2; + struct ctdb_marshall_buffer *m2 = NULL; - r = db_ctdb_marshall_record(mem_ctx, reqid, key, header, data); + r = db_ctdb_marshall_record(talloc_tos(), reqid, key, header, data); if (r == NULL) { talloc_free(m); return NULL; @@ -133,7 +133,7 @@ static struct ctdb_marshall_buffer *db_ctdb_marshall_add(TALLOC_CTX *mem_ctx, m = (struct ctdb_marshall_buffer *)talloc_zero_size( mem_ctx, offsetof(struct ctdb_marshall_buffer, data)); if (m == NULL) { - return NULL; + goto done; } m->db_id = db_id; } @@ -145,15 +145,15 @@ static struct ctdb_marshall_buffer *db_ctdb_marshall_add(TALLOC_CTX *mem_ctx, mem_ctx, m, m_size + r_size); if (m2 == NULL) { talloc_free(m); - return NULL; + goto done; } memcpy(m_size + (uint8_t *)m2, r, r_size); - talloc_free(r); - m2->count++; +done: + talloc_free(r); return m2; } diff --git a/source3/lib/dbwrap_rbt.c b/source3/lib/dbwrap_rbt.c index 6e09627223..cf4faa25b9 100644 --- a/source3/lib/dbwrap_rbt.c +++ b/source3/lib/dbwrap_rbt.c @@ -131,12 +131,12 @@ static NTSTATUS db_rbt_store(struct db_record *rec, TDB_DATA data, int flag) */ } - node = (struct db_rbt_node *)SMB_MALLOC( + node = (struct db_rbt_node *)talloc_size(rec_priv->db_ctx, offsetof(struct db_rbt_node, data) + rec->key.dsize + data.dsize); if (node == NULL) { - SAFE_FREE(rec_priv->node); + TALLOC_FREE(rec_priv->node); return NT_STATUS_NO_MEMORY; } @@ -148,7 +148,7 @@ static NTSTATUS db_rbt_store(struct db_record *rec, TDB_DATA data, int flag) db_rbt_parse_node(node, &this_key, &this_val); memcpy(this_key.dptr, rec->key.dptr, node->keysize); - SAFE_FREE(rec_priv->node); + TALLOC_FREE(rec_priv->node); memcpy(this_val.dptr, data.dptr, node->valuesize); @@ -194,7 +194,7 @@ static NTSTATUS db_rbt_delete(struct db_record *rec) } rb_erase(&rec_priv->node->rb_node, &rec_priv->db_ctx->tree); - SAFE_FREE(rec_priv->node); + TALLOC_FREE(rec_priv->node); return NT_STATUS_OK; } diff --git a/source3/lib/errmap_unix.c b/source3/lib/errmap_unix.c index 9adb237096..bb09726ee0 100644 --- a/source3/lib/errmap_unix.c +++ b/source3/lib/errmap_unix.c @@ -95,6 +95,9 @@ const struct unix_error_map unix_dos_nt_errmap[] = { #ifdef ENOATTR { ENOATTR, ERRDOS, ERRbadfile, NT_STATUS_NOT_FOUND }, #endif +#ifdef ECANCELED + { ECANCELED, ERRDOS, ERRbadfid, NT_STATUS_CANCELLED}, +#endif { 0, 0, 0, NT_STATUS_OK } }; diff --git a/source3/lib/events.c b/source3/lib/events.c index 9e81a47796..90d86c6c79 100644 --- a/source3/lib/events.c +++ b/source3/lib/events.c @@ -91,6 +91,11 @@ bool run_events(struct tevent_context *ev, return true; } + if (ev->immediate_events && + tevent_common_loop_immediate(ev)) { + return true; + } + GetTimeOfDay(&now); if ((ev->timer_events != NULL) @@ -145,7 +150,7 @@ struct timeval *get_timed_events_timeout(struct tevent_context *ev, return to_ret; } -static int s3_event_loop_once(struct tevent_context *ev) +static int s3_event_loop_once(struct tevent_context *ev, const char *location) { struct timeval now, to; fd_set r_fds, w_fds; @@ -181,17 +186,6 @@ static int s3_event_loop_once(struct tevent_context *ev) return 0; } -static int s3_event_loop_wait(struct tevent_context *ev) -{ - int ret = 0; - - while (ret == 0) { - ret = s3_event_loop_once(ev); - } - - return ret; -} - void event_context_reinit(struct tevent_context *ev) { tevent_common_context_destructor(ev); @@ -238,15 +232,16 @@ void dump_event_list(struct tevent_context *ev) } static const struct tevent_ops s3_event_ops = { - .context_init = s3_event_context_init, - .add_fd = tevent_common_add_fd, - .set_fd_close_fn= tevent_common_fd_set_close_fn, - .get_fd_flags = tevent_common_fd_get_flags, - .set_fd_flags = tevent_common_fd_set_flags, - .add_timer = tevent_common_add_timer, - .add_signal = tevent_common_add_signal, - .loop_once = s3_event_loop_once, - .loop_wait = s3_event_loop_wait, + .context_init = s3_event_context_init, + .add_fd = tevent_common_add_fd, + .set_fd_close_fn = tevent_common_fd_set_close_fn, + .get_fd_flags = tevent_common_fd_get_flags, + .set_fd_flags = tevent_common_fd_set_flags, + .add_timer = tevent_common_add_timer, + .schedule_immediate = tevent_common_schedule_immediate, + .add_signal = tevent_common_add_signal, + .loop_once = s3_event_loop_once, + .loop_wait = tevent_common_loop_wait, }; static bool s3_tevent_init(void) @@ -286,8 +281,9 @@ static void s3_event_debug(void *context, enum tevent_debug_level level, break; }; - vasprintf(&s, fmt, ap); - if (!s) return; + if (vasprintf(&s, fmt, ap) == -1) { + return; + } DEBUG(samba_level, ("s3_event: %s", s)); free(s); } diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index fa213a37c0..44500542f2 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -207,12 +207,12 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) from = charsets; to = charsets; - ret = SMB_MALLOC_P(smb_iconv_t); + ret = SMB_MALLOC_P(struct smb_iconv_s); if (!ret) { errno = ENOMEM; return (smb_iconv_t)-1; } - memset(ret, 0, sizeof(smb_iconv_t)); + memset(ret, 0, sizeof(struct smb_iconv_s)); ret->from_name = SMB_STRDUP(fromcode); ret->to_name = SMB_STRDUP(tocode); diff --git a/source3/lib/interfaces.c b/source3/lib/interfaces.c index 4567fe457b..2535418d99 100644 --- a/source3/lib/interfaces.c +++ b/source3/lib/interfaces.c @@ -18,79 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ - -/* working out the interfaces for a OS is an incredibly non-portable - thing. We have several possible implementations below, and autoconf - tries each of them to see what works - - Note that this file does _not_ include includes.h. That is so this code - can be called directly from the autoconf tests. That also means - this code cannot use any of the normal Samba debug stuff or defines. - This is standalone code. - -*/ - -#ifndef AUTOCONF_TEST -#include "config.h" -#endif - -#include <unistd.h> -#include <stdio.h> -#include <sys/types.h> -#include <netdb.h> -#include <sys/ioctl.h> -#include <netdb.h> -#include <sys/ioctl.h> -#include <sys/time.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> - -#ifdef HAVE_IFADDRS_H -#include <ifaddrs.h> -#endif - -#ifdef HAVE_SYS_TIME_H -#include <sys/time.h> -#endif - -#ifndef SIOCGIFCONF -#ifdef HAVE_SYS_SOCKIO_H -#include <sys/sockio.h> -#endif -#endif - -#ifdef HAVE_STDLIB_H -#include <stdlib.h> -#endif - -#ifdef HAVE_STRING_H -#include <string.h> -#endif - -#ifdef HAVE_STRINGS_H -#include <strings.h> -#endif - -#ifdef __COMPAR_FN_T -#define QSORT_CAST (__compar_fn_t) -#endif - -#ifndef QSORT_CAST -#define QSORT_CAST (int (*)(const void *, const void *)) -#endif - -#ifdef HAVE_NET_IF_H -#include <net/if.h> -#endif - -#define SOCKET_WRAPPER_NOT_REPLACE -#include "interfaces.h" -#include "../replace/replace.h" - -/**************************************************************************** - Utility functions. -****************************************************************************/ +#include "includes.h" /**************************************************************************** Create a struct sockaddr_storage with the netmask bits set to 1. diff --git a/source3/lib/messages.c b/source3/lib/messages.c index e4b20c7493..5e11dd4e25 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -286,7 +286,15 @@ NTSTATUS messaging_register(struct messaging_context *msg_ctx, */ for (cb = msg_ctx->callbacks; cb != NULL; cb = cb->next) { - if (cb->msg_type == msg_type) { + /* we allow a second registration of the same message + type if it has a different private pointer. This is + needed in, for example, the internal notify code, + which creates a new notify context for each tree + connect, and expects to receive messages to each of + them. */ + if (cb->msg_type == msg_type && private_data == cb->private_data) { + DEBUG(5,("Overriding messaging pointer for type %u - private_data=%p\n", + (unsigned)msg_type, private_data)); cb->fn = fn; cb->private_data = private_data; return NT_STATUS_OK; @@ -317,6 +325,8 @@ void messaging_deregister(struct messaging_context *ctx, uint32_t msg_type, next = cb->next; if ((cb->msg_type == msg_type) && (cb->private_data == private_data)) { + DEBUG(5,("Deregistering messaging pointer for type %u - private_data=%p\n", + (unsigned)msg_type, private_data)); DLIST_REMOVE(ctx->callbacks, cb); TALLOC_FREE(cb); } @@ -362,7 +372,11 @@ void messaging_dispatch_rec(struct messaging_context *msg_ctx, if (cb->msg_type == rec->msg_type) { cb->fn(msg_ctx, cb->private_data, rec->msg_type, rec->src, &rec->buf); - return; + /* we continue looking for matching messages + after finding one. This matters for + subsystems like the internal notify code + which register more than one handler for + the same message type */ } } return; diff --git a/source3/lib/netapi/cm.c b/source3/lib/netapi/cm.c index 233255fed4..b676ae63dd 100644 --- a/source3/lib/netapi/cm.c +++ b/source3/lib/netapi/cm.c @@ -29,36 +29,36 @@ static WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx, const char *server_name, struct cli_state **cli) { + struct user_auth_info *auth_info = NULL; struct cli_state *cli_ipc = NULL; if (!ctx || !cli || !server_name) { return WERR_INVALID_PARAM; } - cli_cm_set_signing_state(Undefined); - - if (ctx->use_kerberos) { - cli_cm_set_use_kerberos(); - } - - if (ctx->password) { - cli_cm_set_password(ctx->password); - } - if (ctx->username) { - cli_cm_set_username(ctx->username); + auth_info = user_auth_info_init(NULL); + if (!auth_info) { + return WERR_NOMEM; } + auth_info->signing_state = Undefined; + set_cmdline_auth_info_use_kerberos(auth_info, ctx->use_kerberos); + set_cmdline_auth_info_password(auth_info, ctx->password); + set_cmdline_auth_info_username(auth_info, ctx->username); if (ctx->username && ctx->username[0] && ctx->password && ctx->password[0] && ctx->use_kerberos) { - cli_cm_set_fallback_after_kerberos(); + set_cmdline_auth_info_fallback_after_kerberos(auth_info, true); } cli_ipc = cli_cm_open(ctx, NULL, - server_name, "IPC$", - false, false, - PROTOCOL_NT1, - 0, 0x20); + server_name, "IPC$", + auth_info, + false, false, + PROTOCOL_NT1, + 0, 0x20); + TALLOC_FREE(auth_info); + if (!cli_ipc) { libnetapi_set_error_string(ctx, "Failed to connect to IPC$ share on %s", server_name); @@ -73,19 +73,10 @@ static WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx, /******************************************************************** ********************************************************************/ -WERROR libnetapi_shutdown_cm(struct libnetapi_ctx *ctx) -{ - cli_cm_shutdown(); - - return WERR_OK; -} - -/******************************************************************** -********************************************************************/ - struct client_pipe_connection { struct client_pipe_connection *prev, *next; struct rpc_pipe_client *pipe; + struct cli_state *cli; }; static struct client_pipe_connection *pipe_connections; @@ -93,6 +84,20 @@ static struct client_pipe_connection *pipe_connections; /******************************************************************** ********************************************************************/ +WERROR libnetapi_shutdown_cm(struct libnetapi_ctx *ctx) +{ + struct client_pipe_connection *p; + + for (p = pipe_connections; p; p = p->next) { + cli_shutdown(p->cli); + } + + return WERR_OK; +} + +/******************************************************************** +********************************************************************/ + static NTSTATUS pipe_cm_find(struct cli_state *cli, const struct ndr_syntax_id *interface, struct rpc_pipe_client **presult) @@ -138,6 +143,7 @@ static NTSTATUS pipe_cm_connect(TALLOC_CTX *mem_ctx, return status; } + p->cli = cli; DLIST_ADD(pipe_connections, p); *presult = p->pipe; @@ -193,5 +199,3 @@ WERROR libnetapi_open_pipe(struct libnetapi_ctx *ctx, return WERR_OK; } - - diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index 617bde2c9a..189902a78e 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -33,7 +33,7 @@ WERROR NetGroupAdd_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - POLICY_HND connect_handle, domain_handle, group_handle; + struct policy_handle connect_handle, domain_handle, group_handle; struct lsa_String lsa_group_name; struct dom_sid2 *domain_sid = NULL; uint32_t rid = 0; @@ -223,7 +223,7 @@ WERROR NetGroupDel_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - POLICY_HND connect_handle, domain_handle, group_handle; + struct policy_handle connect_handle, domain_handle, group_handle; struct lsa_String lsa_group_name; struct dom_sid2 *domain_sid = NULL; int i = 0; @@ -384,7 +384,7 @@ WERROR NetGroupSetInfo_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - POLICY_HND connect_handle, domain_handle, group_handle; + struct policy_handle connect_handle, domain_handle, group_handle; struct lsa_String lsa_group_name; struct dom_sid2 *domain_sid = NULL; @@ -624,7 +624,7 @@ WERROR NetGroupGetInfo_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - POLICY_HND connect_handle, domain_handle, group_handle; + struct policy_handle connect_handle, domain_handle, group_handle; struct lsa_String lsa_group_name; struct dom_sid2 *domain_sid = NULL; @@ -742,7 +742,7 @@ WERROR NetGroupAddUser_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - POLICY_HND connect_handle, domain_handle, group_handle; + struct policy_handle connect_handle, domain_handle, group_handle; struct lsa_String lsa_group_name, lsa_user_name; struct dom_sid2 *domain_sid = NULL; @@ -863,7 +863,7 @@ WERROR NetGroupDelUser_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - POLICY_HND connect_handle, domain_handle, group_handle; + struct policy_handle connect_handle, domain_handle, group_handle; struct lsa_String lsa_group_name, lsa_user_name; struct dom_sid2 *domain_sid = NULL; diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 9d7f299f59..8cc65a6e9e 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -352,7 +352,7 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - POLICY_HND connect_handle, domain_handle, user_handle; + struct policy_handle connect_handle, domain_handle, user_handle; struct lsa_String lsa_account_name; struct dom_sid2 *domain_sid = NULL; union samr_UserInfo *user_info = NULL; @@ -496,7 +496,7 @@ WERROR NetUserDel_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - POLICY_HND connect_handle, builtin_handle, domain_handle, user_handle; + struct policy_handle connect_handle, builtin_handle, domain_handle, user_handle; struct lsa_String lsa_account_name; struct samr_Ids user_rids, name_types; struct dom_sid2 *domain_sid = NULL; diff --git a/source3/lib/smbconf/smbconf_reg.c b/source3/lib/smbconf/smbconf_reg.c index 5a5c0ead65..ae6a41151d 100644 --- a/source3/lib/smbconf/smbconf_reg.c +++ b/source3/lib/smbconf/smbconf_reg.c @@ -80,12 +80,20 @@ static WERROR smbconf_reg_open_service_key(TALLOC_CTX *mem_ctx, uint32 desired_access, struct registry_key **key) { + WERROR werr; + if (servicename == NULL) { *key = rpd(ctx)->base_key; return WERR_OK; } - return reg_openkey(mem_ctx, rpd(ctx)->base_key, servicename, + werr = reg_openkey(mem_ctx, rpd(ctx)->base_key, servicename, desired_access, key); + + if (W_ERROR_EQUAL(werr, WERR_BADFILE)) { + werr = WERR_NO_SUCH_SERVICE; + } + + return werr; } /** @@ -828,9 +836,6 @@ static WERROR smbconf_reg_get_share(struct smbconf_ctx *ctx, werr = smbconf_reg_open_service_key(tmp_ctx, ctx, servicename, REG_KEY_READ, &key); if (!W_ERROR_IS_OK(werr)) { - if (W_ERROR_EQUAL(werr, WERR_BADFILE)) { - werr = WERR_NO_SUCH_SERVICE; - } goto done; } diff --git a/source3/lib/smbconf/testsuite.c b/source3/lib/smbconf/testsuite.c index b31dec0438..c83eeb805d 100644 --- a/source3/lib/smbconf/testsuite.c +++ b/source3/lib/smbconf/testsuite.c @@ -214,7 +214,7 @@ static bool torture_smbconf_txt(void) printf("TEST: init\n"); werr = smbconf_init_txt(mem_ctx, &conf_ctx, filename); if (!W_ERROR_IS_OK(werr)) { - printf("FAIL: text backend\[ failed: %s\n", win_errstr(werr)); + printf("FAIL: text backend failed: %s\n", win_errstr(werr)); ret = false; goto done; } diff --git a/source3/lib/util.c b/source3/lib/util.c index 89f7be8e6c..75fd82709a 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -290,7 +290,7 @@ struct user_auth_info *user_auth_info_init(TALLOC_CTX *mem_ctx) return result; } -const char *get_cmdline_auth_info_username(struct user_auth_info *auth_info) +const char *get_cmdline_auth_info_username(const struct user_auth_info *auth_info) { if (!auth_info->username) { return ""; @@ -308,7 +308,7 @@ void set_cmdline_auth_info_username(struct user_auth_info *auth_info, } } -const char *get_cmdline_auth_info_password(struct user_auth_info *auth_info) +const char *get_cmdline_auth_info_password(const struct user_auth_info *auth_info) { if (!auth_info->password) { return ""; @@ -320,6 +320,9 @@ void set_cmdline_auth_info_password(struct user_auth_info *auth_info, const char *password) { TALLOC_FREE(auth_info->password); + if (password == NULL) { + password = ""; + } auth_info->password = talloc_strdup(auth_info, password); if (!auth_info->password) { exit(ENOMEM); @@ -346,7 +349,7 @@ bool set_cmdline_auth_info_signing_state(struct user_auth_info *auth_info, return true; } -int get_cmdline_auth_info_signing_state(struct user_auth_info *auth_info) +int get_cmdline_auth_info_signing_state(const struct user_auth_info *auth_info) { return auth_info->signing_state; } @@ -357,11 +360,22 @@ void set_cmdline_auth_info_use_kerberos(struct user_auth_info *auth_info, auth_info->use_kerberos = b; } -bool get_cmdline_auth_info_use_kerberos(struct user_auth_info *auth_info) +bool get_cmdline_auth_info_use_kerberos(const struct user_auth_info *auth_info) { return auth_info->use_kerberos; } +void set_cmdline_auth_info_fallback_after_kerberos(struct user_auth_info *auth_info, + bool b) +{ + auth_info->fallback_after_kerberos = b; +} + +bool get_cmdline_auth_info_fallback_after_kerberos(const struct user_auth_info *auth_info) +{ + return auth_info->fallback_after_kerberos; +} + /* This should only be used by lib/popt_common.c JRA */ void set_cmdline_auth_info_use_krb5_ticket(struct user_auth_info *auth_info) { @@ -380,23 +394,23 @@ void set_cmdline_auth_info_use_machine_account(struct user_auth_info *auth_info) auth_info->use_machine_account = true; } -bool get_cmdline_auth_info_got_pass(struct user_auth_info *auth_info) +bool get_cmdline_auth_info_got_pass(const struct user_auth_info *auth_info) { return auth_info->got_pass; } -bool get_cmdline_auth_info_smb_encrypt(struct user_auth_info *auth_info) +bool get_cmdline_auth_info_smb_encrypt(const struct user_auth_info *auth_info) { return auth_info->smb_encrypt; } -bool get_cmdline_auth_info_use_machine_account(struct user_auth_info *auth_info) +bool get_cmdline_auth_info_use_machine_account(const struct user_auth_info *auth_info) { return auth_info->use_machine_account; } struct user_auth_info *get_cmdline_auth_info_copy(TALLOC_CTX *mem_ctx, - struct user_auth_info *src) + const struct user_auth_info *src) { struct user_auth_info *result; @@ -456,6 +470,32 @@ bool set_cmdline_auth_info_machine_account_creds(struct user_auth_info *auth_inf } /**************************************************************************** + Ensure we have a password if one not given. +****************************************************************************/ + +void set_cmdline_auth_info_getpass(struct user_auth_info *auth_info) +{ + char *label = NULL; + char *pass; + TALLOC_CTX *frame; + + if (get_cmdline_auth_info_got_pass(auth_info) || + get_cmdline_auth_info_use_kerberos(auth_info)) { + /* Already got one... */ + return; + } + + frame = talloc_stackframe(); + label = talloc_asprintf(frame, "Enter %s's password: ", + get_cmdline_auth_info_username(auth_info)); + pass = getpass(label); + if (pass) { + set_cmdline_auth_info_password(auth_info, pass); + } + TALLOC_FREE(frame); +} + +/**************************************************************************** Add a gid to an array of gids if it's not already there. ****************************************************************************/ @@ -899,13 +939,6 @@ bool reinit_after_fork(struct messaging_context *msg_ctx, * numbers as each other */ set_need_random_reseed(); -#ifdef WITH_MADVISE_PROTECTED - /* Protect parent process from being killed by kernel when system - * memory is low. Child processes can still be killed */ - if(!parent_longlived) - madvise(NULL,0,MADV_PROTECT); -#endif - /* tdb needs special fork handling */ if (tdb_reopen_all(parent_longlived ? 1 : 0) == -1) { DEBUG(0,("tdb_reopen_all failed.\n")); @@ -3109,9 +3142,9 @@ NTSTATUS split_ntfs_stream_name(TALLOC_CTX *mem_ctx, const char *fname, return NT_STATUS_OK; } -bool is_valid_policy_hnd(const POLICY_HND *hnd) +bool is_valid_policy_hnd(const struct policy_handle *hnd) { - POLICY_HND tmp; + struct policy_handle tmp; ZERO_STRUCT(tmp); return (memcmp(&tmp, hnd, sizeof(tmp)) != 0); } diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index 6e75a67a85..a0dbca1a00 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -519,7 +519,7 @@ NTSTATUS read_socket_with_timeout(int fd, char *buf, } while (nread < mincnt) { - readret = sys_read(fd, buf + nread, maxcnt - nread); + readret = sys_recv(fd, buf + nread, maxcnt - nread, 0); if (readret == 0) { DEBUG(5,("read_socket_with_timeout: " @@ -588,7 +588,7 @@ NTSTATUS read_socket_with_timeout(int fd, char *buf, return NT_STATUS_IO_TIMEOUT; } - readret = sys_read(fd, buf+nread, maxcnt-nread); + readret = sys_recv(fd, buf+nread, maxcnt-nread, 0); if (readret == 0) { /* we got EOF on the file descriptor */ @@ -1033,8 +1033,7 @@ struct tevent_req *open_socket_out_send(TALLOC_CTX *mem_ctx, timeval_current_ofs(0, state->wait_nsec))) { goto fail; } - subreq->async.fn = open_socket_out_connected; - subreq->async.private_data = result; + tevent_req_set_callback(subreq, open_socket_out_connected, result); return result; post_status: @@ -1047,10 +1046,10 @@ struct tevent_req *open_socket_out_send(TALLOC_CTX *mem_ctx, static void open_socket_out_connected(struct tevent_req *subreq) { - struct tevent_req *req = talloc_get_type_abort( - subreq->async.private_data, struct tevent_req); - struct open_socket_out_state *state = talloc_get_type_abort( - req->private_state, struct open_socket_out_state); + struct tevent_req *req = + tevent_req_callback_data(subreq, struct tevent_req); + struct open_socket_out_state *state = + tevent_req_data(req, struct open_socket_out_state); int ret; int sys_errno; @@ -1089,8 +1088,7 @@ static void open_socket_out_connected(struct tevent_req *subreq) tevent_req_nterror(req, NT_STATUS_NO_MEMORY); return; } - subreq->async.fn = open_socket_out_connected; - subreq->async.private_data = req; + tevent_req_set_callback(subreq, open_socket_out_connected, req); return; } @@ -1107,8 +1105,8 @@ static void open_socket_out_connected(struct tevent_req *subreq) NTSTATUS open_socket_out_recv(struct tevent_req *req, int *pfd) { - struct open_socket_out_state *state = talloc_get_type_abort( - req->private_state, struct open_socket_out_state); + struct open_socket_out_state *state = + tevent_req_data(req, struct open_socket_out_state); NTSTATUS status; if (tevent_req_is_nterror(req, &status)) { @@ -1154,22 +1152,22 @@ struct open_socket_out_defer_state { int fd; }; -static void open_socket_out_defer_waited(struct async_req *subreq); +static void open_socket_out_defer_waited(struct tevent_req *subreq); static void open_socket_out_defer_connected(struct tevent_req *subreq); -struct async_req *open_socket_out_defer_send(TALLOC_CTX *mem_ctx, - struct event_context *ev, - struct timeval wait_time, - const struct sockaddr_storage *pss, - uint16_t port, - int timeout) +struct tevent_req *open_socket_out_defer_send(TALLOC_CTX *mem_ctx, + struct event_context *ev, + struct timeval wait_time, + const struct sockaddr_storage *pss, + uint16_t port, + int timeout) { - struct async_req *result, *subreq; + struct tevent_req *req, *subreq; struct open_socket_out_defer_state *state; - NTSTATUS status; - if (!async_req_setup(mem_ctx, &result, &state, - struct open_socket_out_defer_state)) { + req = tevent_req_create(mem_ctx, &state, + struct open_socket_out_defer_state); + if (req == NULL) { return NULL; } state->ev = ev; @@ -1177,74 +1175,66 @@ struct async_req *open_socket_out_defer_send(TALLOC_CTX *mem_ctx, state->port = port; state->timeout = timeout; - subreq = async_wait_send(state, ev, wait_time); + subreq = tevent_wakeup_send( + state, ev, + timeval_current_ofs(wait_time.tv_sec, wait_time.tv_usec)); if (subreq == NULL) { - status = NT_STATUS_NO_MEMORY; - goto post_status; - } - subreq->async.fn = open_socket_out_defer_waited; - subreq->async.priv = result; - return result; - - post_status: - if (!async_post_ntstatus(result, ev, status)) { goto fail; } - return result; + tevent_req_set_callback(subreq, open_socket_out_defer_waited, req); + return req; fail: - TALLOC_FREE(result); + TALLOC_FREE(req); return NULL; } -static void open_socket_out_defer_waited(struct async_req *subreq) +static void open_socket_out_defer_waited(struct tevent_req *subreq) { - struct async_req *req = talloc_get_type_abort( - subreq->async.priv, struct async_req); - struct open_socket_out_defer_state *state = talloc_get_type_abort( - req->private_data, struct open_socket_out_defer_state); - struct tevent_req *subreq2; + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct open_socket_out_defer_state *state = tevent_req_data( + req, struct open_socket_out_defer_state); bool ret; - ret = async_wait_recv(subreq); + ret = tevent_wakeup_recv(subreq); TALLOC_FREE(subreq); if (!ret) { - async_req_nterror(req, NT_STATUS_INTERNAL_ERROR); + tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR); return; } - subreq2 = open_socket_out_send(state, state->ev, &state->ss, - state->port, state->timeout); - if (async_req_nomem(subreq2, req)) { + subreq = open_socket_out_send(state, state->ev, &state->ss, + state->port, state->timeout); + if (tevent_req_nomem(subreq, req)) { return; } - subreq2->async.fn = open_socket_out_defer_connected; - subreq2->async.private_data = req; + tevent_req_set_callback(subreq, open_socket_out_defer_connected, req); } static void open_socket_out_defer_connected(struct tevent_req *subreq) { - struct async_req *req = talloc_get_type_abort( - subreq->async.private_data, struct async_req); - struct open_socket_out_defer_state *state = talloc_get_type_abort( - req->private_data, struct open_socket_out_defer_state); + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct open_socket_out_defer_state *state = tevent_req_data( + req, struct open_socket_out_defer_state); NTSTATUS status; status = open_socket_out_recv(subreq, &state->fd); TALLOC_FREE(subreq); if (!NT_STATUS_IS_OK(status)) { - async_req_nterror(req, status); + tevent_req_nterror(req, status); return; } - async_req_done(req); + tevent_req_done(req); } -NTSTATUS open_socket_out_defer_recv(struct async_req *req, int *pfd) +NTSTATUS open_socket_out_defer_recv(struct tevent_req *req, int *pfd) { - struct open_socket_out_defer_state *state = talloc_get_type_abort( - req->private_data, struct open_socket_out_defer_state); + struct open_socket_out_defer_state *state = tevent_req_data( + req, struct open_socket_out_defer_state); NTSTATUS status; - if (async_req_is_nterror(req, &status)) { + if (tevent_req_is_nterror(req, &status)) { return status; } *pfd = state->fd; diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c index 4e78d1b064..840e8e06da 100644 --- a/source3/lib/util_unistr.c +++ b/source3/lib/util_unistr.c @@ -383,22 +383,6 @@ void unistr2_to_ascii(char *dest, const UNISTR2 *str, size_t maxlen) pull_ucs2(NULL, dest, str->buffer, maxlen, str->uni_str_len*2, STR_NOALIGN); } -#if 0 -/******************************************************************* - Convert a (little-endian) UNISTR3 structure to an ASCII string. -********************************************************************/ - -void unistr3_to_ascii(char *dest, const UNISTR3 *str, size_t maxlen) -{ - if ((str == NULL) || (str->uni_str_len == 0)) { - *dest='\0'; - return; - } - pull_ucs2(NULL, dest, str->str.buffer, maxlen, str->uni_str_len*2, - STR_NOALIGN); -} -#endif - /******************************************************************* Duplicate a UNISTR2 string into a null terminated char* using a talloc context. diff --git a/source3/lib/version_test.c b/source3/lib/version_test.c new file mode 100644 index 0000000000..880cfeb084 --- /dev/null +++ b/source3/lib/version_test.c @@ -0,0 +1,26 @@ +/* + * Unix SMB/CIFS implementation. + * version_test - test program for samba_version_strion() + * Copyright (C) Michael Adam 2009 + * + * 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" + +int main(void) +{ + printf("%s\n", samba_version_string()); + return 0; +} diff --git a/source3/lib/wb_reqtrans.c b/source3/lib/wb_reqtrans.c index 65906dcb91..dbea8b6686 100644 --- a/source3/lib/wb_reqtrans.c +++ b/source3/lib/wb_reqtrans.c @@ -25,28 +25,37 @@ #undef DBGC_CLASS #define DBGC_CLASS DBGC_WINBIND -struct req_read_state { - struct winbindd_request *wb_req; - size_t max_extra_data; -}; +wbcErr map_wbc_err_from_errno(int error) +{ + switch(error) { + case EPERM: + case EACCES: + return WBC_ERR_AUTH_ERROR; + case ENOMEM: + return WBC_ERR_NO_MEMORY; + case EIO: + default: + return WBC_ERR_UNKNOWN_FAILURE; + } +} -bool async_req_is_wbcerr(struct async_req *req, wbcErr *pwbc_err) +bool tevent_req_is_wbcerr(struct tevent_req *req, wbcErr *pwbc_err) { - enum async_req_state state; + enum tevent_req_state state; uint64_t error; - if (!async_req_is_error(req, &state, &error)) { + if (!tevent_req_is_error(req, &state, &error)) { *pwbc_err = WBC_ERR_SUCCESS; return false; } switch (state) { - case ASYNC_REQ_USER_ERROR: + case TEVENT_REQ_USER_ERROR: *pwbc_err = error; break; - case ASYNC_REQ_TIMED_OUT: + case TEVENT_REQ_TIMED_OUT: *pwbc_err = WBC_ERR_UNKNOWN_FAILURE; break; - case ASYNC_REQ_NO_MEMORY: + case TEVENT_REQ_NO_MEMORY: *pwbc_err = WBC_ERR_NO_MEMORY; break; default: @@ -56,44 +65,34 @@ bool async_req_is_wbcerr(struct async_req *req, wbcErr *pwbc_err) return true; } -wbcErr map_wbc_err_from_errno(int error) -{ - switch(error) { - case EPERM: - case EACCES: - return WBC_ERR_AUTH_ERROR; - case ENOMEM: - return WBC_ERR_NO_MEMORY; - case EIO: - default: - return WBC_ERR_UNKNOWN_FAILURE; - } -} - -wbcErr async_req_simple_recv_wbcerr(struct async_req *req) +wbcErr tevent_req_simple_recv_wbcerr(struct tevent_req *req) { wbcErr wbc_err; - if (async_req_is_wbcerr(req, &wbc_err)) { + if (tevent_req_is_wbcerr(req, &wbc_err)) { return wbc_err; } return WBC_ERR_SUCCESS; } +struct req_read_state { + struct winbindd_request *wb_req; + size_t max_extra_data; +}; + static ssize_t wb_req_more(uint8_t *buf, size_t buflen, void *private_data); static void wb_req_read_done(struct tevent_req *subreq); -struct async_req *wb_req_read_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - int fd, size_t max_extra_data) +struct tevent_req *wb_req_read_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + int fd, size_t max_extra_data) { - struct async_req *result; - struct tevent_req *subreq; + struct tevent_req *result, *subreq; struct req_read_state *state; - if (!async_req_setup(mem_ctx, &result, &state, - struct req_read_state)) { + result = tevent_req_create(mem_ctx, &state, struct req_read_state); + if (result == NULL) { return NULL; } state->max_extra_data = max_extra_data; @@ -103,8 +102,7 @@ struct async_req *wb_req_read_send(TALLOC_CTX *mem_ctx, goto nomem; } - subreq->async.fn = wb_req_read_done; - subreq->async.private_data = result; + tevent_req_set_callback(subreq, wb_req_read_done, result); return result; nomem: TALLOC_FREE(result); @@ -140,10 +138,10 @@ static ssize_t wb_req_more(uint8_t *buf, size_t buflen, void *private_data) static void wb_req_read_done(struct tevent_req *subreq) { - struct async_req *req = talloc_get_type_abort( - subreq->async.private_data, struct async_req); - struct req_read_state *state = talloc_get_type_abort( - req->private_data, struct req_read_state); + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct req_read_state *state = tevent_req_data( + req, struct req_read_state); int err; ssize_t ret; uint8_t *buf; @@ -151,7 +149,7 @@ static void wb_req_read_done(struct tevent_req *subreq) ret = read_packet_recv(subreq, state, &buf, &err); TALLOC_FREE(subreq); if (ret == -1) { - async_req_error(req, map_wbc_err_from_errno(err)); + tevent_req_error(req, map_wbc_err_from_errno(err)); return; } @@ -163,17 +161,17 @@ static void wb_req_read_done(struct tevent_req *subreq) } else { state->wb_req->extra_data.data = NULL; } - async_req_done(req); + tevent_req_done(req); } -wbcErr wb_req_read_recv(struct async_req *req, TALLOC_CTX *mem_ctx, +wbcErr wb_req_read_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, struct winbindd_request **preq) { - struct req_read_state *state = talloc_get_type_abort( - req->private_data, struct req_read_state); + struct req_read_state *state = tevent_req_data( + req, struct req_read_state); wbcErr wbc_err; - if (async_req_is_wbcerr(req, &wbc_err)) { + if (tevent_req_is_wbcerr(req, &wbc_err)) { return wbc_err; } *preq = talloc_move(mem_ctx, &state->wb_req); @@ -186,17 +184,17 @@ struct req_write_state { static void wb_req_write_done(struct tevent_req *subreq); -struct async_req *wb_req_write_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, int fd, - struct winbindd_request *wb_req) +struct tevent_req *wb_req_write_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct tevent_queue *queue, int fd, + struct winbindd_request *wb_req) { - struct async_req *result; - struct tevent_req *subreq; + struct tevent_req *result, *subreq; struct req_write_state *state; int count = 1; - if (!async_req_setup(mem_ctx, &result, &state, - struct req_write_state)) { + result = tevent_req_create(mem_ctx, &state, struct req_write_state); + if (result == NULL) { return NULL; } @@ -209,12 +207,11 @@ struct async_req *wb_req_write_send(TALLOC_CTX *mem_ctx, count = 2; } - subreq = writev_send(state, ev, fd, state->iov, count); + subreq = writev_send(state, ev, queue, fd, state->iov, count); if (subreq == NULL) { goto fail; } - subreq->async.fn = wb_req_write_done; - subreq->async.private_data = result; + tevent_req_set_callback(subreq, wb_req_write_done, result); return result; fail: @@ -224,23 +221,23 @@ struct async_req *wb_req_write_send(TALLOC_CTX *mem_ctx, static void wb_req_write_done(struct tevent_req *subreq) { - struct async_req *req = talloc_get_type_abort( - subreq->async.private_data, struct async_req); + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); int err; ssize_t ret; ret = writev_recv(subreq, &err); TALLOC_FREE(subreq); if (ret < 0) { - async_req_error(req, map_wbc_err_from_errno(err)); + tevent_req_error(req, map_wbc_err_from_errno(err)); return; } - async_req_done(req); + tevent_req_done(req); } -wbcErr wb_req_write_recv(struct async_req *req) +wbcErr wb_req_write_recv(struct tevent_req *req) { - return async_req_simple_recv_wbcerr(req); + return tevent_req_simple_recv_wbcerr(req); } struct resp_read_state { @@ -250,15 +247,14 @@ struct resp_read_state { static ssize_t wb_resp_more(uint8_t *buf, size_t buflen, void *private_data); static void wb_resp_read_done(struct tevent_req *subreq); -struct async_req *wb_resp_read_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, int fd) +struct tevent_req *wb_resp_read_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, int fd) { - struct async_req *result; - struct tevent_req *subreq; + struct tevent_req *result, *subreq; struct resp_read_state *state; - if (!async_req_setup(mem_ctx, &result, &state, - struct resp_read_state)) { + result = tevent_req_create(mem_ctx, &state, struct resp_read_state); + if (result == NULL) { return NULL; } @@ -266,8 +262,7 @@ struct async_req *wb_resp_read_send(TALLOC_CTX *mem_ctx, if (subreq == NULL) { goto nomem; } - subreq->async.fn = wb_resp_read_done; - subreq->async.private_data = result; + tevent_req_set_callback(subreq, wb_resp_read_done, result); return result; nomem: @@ -293,10 +288,10 @@ static ssize_t wb_resp_more(uint8_t *buf, size_t buflen, void *private_data) static void wb_resp_read_done(struct tevent_req *subreq) { - struct async_req *req = talloc_get_type_abort( - subreq->async.private_data, struct async_req); - struct resp_read_state *state = talloc_get_type_abort( - req->private_data, struct resp_read_state); + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct resp_read_state *state = tevent_req_data( + req, struct resp_read_state); uint8_t *buf; int err; ssize_t ret; @@ -304,7 +299,7 @@ static void wb_resp_read_done(struct tevent_req *subreq) ret = read_packet_recv(subreq, state, &buf, &err); TALLOC_FREE(subreq); if (ret == -1) { - async_req_error(req, map_wbc_err_from_errno(err)); + tevent_req_error(req, map_wbc_err_from_errno(err)); return; } @@ -316,17 +311,17 @@ static void wb_resp_read_done(struct tevent_req *subreq) } else { state->wb_resp->extra_data.data = NULL; } - async_req_done(req); + tevent_req_done(req); } -wbcErr wb_resp_read_recv(struct async_req *req, TALLOC_CTX *mem_ctx, +wbcErr wb_resp_read_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, struct winbindd_response **presp) { - struct resp_read_state *state = talloc_get_type_abort( - req->private_data, struct resp_read_state); + struct resp_read_state *state = tevent_req_data( + req, struct resp_read_state); wbcErr wbc_err; - if (async_req_is_wbcerr(req, &wbc_err)) { + if (tevent_req_is_wbcerr(req, &wbc_err)) { return wbc_err; } *presp = talloc_move(mem_ctx, &state->wb_resp); @@ -339,17 +334,17 @@ struct resp_write_state { static void wb_resp_write_done(struct tevent_req *subreq); -struct async_req *wb_resp_write_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, int fd, - struct winbindd_response *wb_resp) +struct tevent_req *wb_resp_write_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct tevent_queue *queue, int fd, + struct winbindd_response *wb_resp) { - struct async_req *result; - struct tevent_req *subreq; + struct tevent_req *result, *subreq; struct resp_write_state *state; int count = 1; - if (!async_req_setup(mem_ctx, &result, &state, - struct resp_write_state)) { + result = tevent_req_create(mem_ctx, &state, struct resp_write_state); + if (result == NULL) { return NULL; } @@ -363,12 +358,11 @@ struct async_req *wb_resp_write_send(TALLOC_CTX *mem_ctx, count = 2; } - subreq = writev_send(state, ev, fd, state->iov, count); + subreq = writev_send(state, ev, queue, fd, state->iov, count); if (subreq == NULL) { goto fail; } - subreq->async.fn = wb_resp_write_done; - subreq->async.private_data = result; + tevent_req_set_callback(subreq, wb_resp_write_done, result); return result; fail: @@ -378,21 +372,21 @@ struct async_req *wb_resp_write_send(TALLOC_CTX *mem_ctx, static void wb_resp_write_done(struct tevent_req *subreq) { - struct async_req *req = talloc_get_type_abort( - subreq->async.private_data, struct async_req); + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); int err; ssize_t ret; ret = writev_recv(subreq, &err); TALLOC_FREE(subreq); if (ret < 0) { - async_req_error(req, map_wbc_err_from_errno(err)); + tevent_req_error(req, map_wbc_err_from_errno(err)); return; } - async_req_done(req); + tevent_req_done(req); } -wbcErr wb_resp_write_recv(struct async_req *req) +wbcErr wb_resp_write_recv(struct tevent_req *req) { - return async_req_simple_recv_wbcerr(req); + return tevent_req_simple_recv_wbcerr(req); } diff --git a/source3/lib/wbclient.c b/source3/lib/wbclient.c index b8d55a944a..3cf992c7de 100644 --- a/source3/lib/wbclient.c +++ b/source3/lib/wbclient.c @@ -20,6 +20,12 @@ #include "includes.h" #include "wbc_async.h" +struct wb_context { + struct tevent_queue *queue; + int fd; + bool is_priv; +}; + static int make_nonstd_fd(int fd) { int i; @@ -138,7 +144,7 @@ struct wb_context *wb_context_init(TALLOC_CTX *mem_ctx) if (result == NULL) { return NULL; } - result->queue = async_req_queue_init(result); + result->queue = tevent_queue_create(result, "wb_trans"); if (result->queue == NULL) { TALLOC_FREE(result); return NULL; @@ -153,21 +159,20 @@ struct wb_connect_state { static void wbc_connect_connected(struct tevent_req *subreq); -static struct async_req *wb_connect_send(TALLOC_CTX *mem_ctx, +static struct tevent_req *wb_connect_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct wb_context *wb_ctx, const char *dir) { - struct async_req *result; - struct tevent_req *subreq; + struct tevent_req *result, *subreq; struct wb_connect_state *state; struct sockaddr_un sunaddr; struct stat st; char *path = NULL; wbcErr wbc_err; - if (!async_req_setup(mem_ctx, &result, &state, - struct wb_connect_state)) { + result = tevent_req_create(mem_ctx, &state, struct wb_connect_state); + if (result == NULL) { return NULL; } @@ -224,8 +229,7 @@ static struct async_req *wb_connect_send(TALLOC_CTX *mem_ctx, if (subreq == NULL) { goto nomem; } - subreq->async.fn = wbc_connect_connected; - subreq->async.private_data = result; + tevent_req_set_callback(subreq, wbc_connect_connected, result); if (!tevent_req_set_endtime(subreq, ev, timeval_current_ofs(30, 0))) { goto nomem; @@ -233,59 +237,32 @@ static struct async_req *wb_connect_send(TALLOC_CTX *mem_ctx, return result; - nomem: - wbc_err = WBC_ERR_NO_MEMORY; post_status: - if (async_post_error(result, ev, wbc_err)) { - return result; - } + tevent_req_error(result, wbc_err); + return tevent_req_post(result, ev); + nomem: TALLOC_FREE(result); return NULL; } static void wbc_connect_connected(struct tevent_req *subreq) { - struct async_req *req = talloc_get_type_abort( - subreq->async.private_data, struct async_req); + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); int res, err; res = async_connect_recv(subreq, &err); TALLOC_FREE(subreq); if (res == -1) { - async_req_error(req, map_wbc_err_from_errno(err)); + tevent_req_error(req, map_wbc_err_from_errno(err)); return; } - async_req_done(req); + tevent_req_done(req); } -static wbcErr wb_connect_recv(struct async_req *req) +static wbcErr wb_connect_recv(struct tevent_req *req) { - return async_req_simple_recv_wbcerr(req); -} - -static struct winbindd_request *winbindd_request_copy( - TALLOC_CTX *mem_ctx, - const struct winbindd_request *req) -{ - struct winbindd_request *result; - - result = (struct winbindd_request *)TALLOC_MEMDUP( - mem_ctx, req, sizeof(struct winbindd_request)); - if (result == NULL) { - return NULL; - } - - if (result->extra_len == 0) { - return result; - } - - result->extra_data.data = (char *)TALLOC_MEMDUP( - result, result->extra_data.data, result->extra_len); - if (result->extra_data.data == NULL) { - TALLOC_FREE(result); - return NULL; - } - return result; + return tevent_req_simple_recv_wbcerr(req); } struct wb_int_trans_state { @@ -295,43 +272,40 @@ struct wb_int_trans_state { struct winbindd_response *wb_resp; }; -static void wb_int_trans_write_done(struct async_req *subreq); -static void wb_int_trans_read_done(struct async_req *subreq); +static void wb_int_trans_write_done(struct tevent_req *subreq); +static void wb_int_trans_read_done(struct tevent_req *subreq); -static struct async_req *wb_int_trans_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, int fd, - struct winbindd_request *wb_req) +static struct tevent_req *wb_int_trans_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct tevent_queue *queue, int fd, + struct winbindd_request *wb_req) { - struct async_req *result; - struct async_req *subreq; + struct tevent_req *result, *subreq; struct wb_int_trans_state *state; - if (!async_req_setup(mem_ctx, &result, &state, - struct wb_int_trans_state)) { + result = tevent_req_create(mem_ctx, &state, + struct wb_int_trans_state); + if (result == NULL) { return NULL; } if (winbind_closed_fd(fd)) { - if (!async_post_error(result, ev, - WBC_ERR_WINBIND_NOT_AVAILABLE)) { - goto fail; - } - return result; + tevent_req_error(result, WBC_ERR_WINBIND_NOT_AVAILABLE); + return tevent_req_post(result, ev); } state->ev = ev; state->fd = fd; state->wb_req = wb_req; - state->wb_req->length = sizeof(struct winbindd_request); state->wb_req->pid = getpid(); - subreq = wb_req_write_send(state, state->ev, state->fd, state->wb_req); + subreq = wb_req_write_send(state, state->ev, queue, state->fd, + state->wb_req); if (subreq == NULL) { goto fail; } - subreq->async.fn = wb_int_trans_write_done; - subreq->async.priv = result; + tevent_req_set_callback(subreq, wb_int_trans_write_done, result); return result; @@ -340,56 +314,55 @@ static struct async_req *wb_int_trans_send(TALLOC_CTX *mem_ctx, return NULL; } -static void wb_int_trans_write_done(struct async_req *subreq) +static void wb_int_trans_write_done(struct tevent_req *subreq) { - struct async_req *req = talloc_get_type_abort( - subreq->async.priv, struct async_req); - struct wb_int_trans_state *state = talloc_get_type_abort( - req->private_data, struct wb_int_trans_state); + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct wb_int_trans_state *state = tevent_req_data( + req, struct wb_int_trans_state); wbcErr wbc_err; wbc_err = wb_req_write_recv(subreq); TALLOC_FREE(subreq); if (!WBC_ERROR_IS_OK(wbc_err)) { - async_req_error(req, wbc_err); + tevent_req_error(req, wbc_err); return; } subreq = wb_resp_read_send(state, state->ev, state->fd); - if (subreq == NULL) { - async_req_error(req, WBC_ERR_NO_MEMORY); + if (tevent_req_nomem(subreq, req)) { + return; } - subreq->async.fn = wb_int_trans_read_done; - subreq->async.priv = req; + tevent_req_set_callback(subreq, wb_int_trans_read_done, req); } -static void wb_int_trans_read_done(struct async_req *subreq) +static void wb_int_trans_read_done(struct tevent_req *subreq) { - struct async_req *req = talloc_get_type_abort( - subreq->async.priv, struct async_req); - struct wb_int_trans_state *state = talloc_get_type_abort( - req->private_data, struct wb_int_trans_state); + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct wb_int_trans_state *state = tevent_req_data( + req, struct wb_int_trans_state); wbcErr wbc_err; wbc_err = wb_resp_read_recv(subreq, state, &state->wb_resp); TALLOC_FREE(subreq); if (!WBC_ERROR_IS_OK(wbc_err)) { - async_req_error(req, wbc_err); + tevent_req_error(req, wbc_err); return; } - async_req_done(req); + tevent_req_done(req); } -static wbcErr wb_int_trans_recv(struct async_req *req, +static wbcErr wb_int_trans_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, struct winbindd_response **presponse) { - struct wb_int_trans_state *state = talloc_get_type_abort( - req->private_data, struct wb_int_trans_state); + struct wb_int_trans_state *state = tevent_req_data( + req, struct wb_int_trans_state); wbcErr wbc_err; - if (async_req_is_wbcerr(req, &wbc_err)) { + if (tevent_req_is_wbcerr(req, &wbc_err)) { return wbc_err; } @@ -418,22 +391,21 @@ struct wb_open_pipe_state { struct winbindd_request wb_req; }; -static void wb_open_pipe_connect_nonpriv_done(struct async_req *subreq); -static void wb_open_pipe_ping_done(struct async_req *subreq); -static void wb_open_pipe_getpriv_done(struct async_req *subreq); -static void wb_open_pipe_connect_priv_done(struct async_req *subreq); +static void wb_open_pipe_connect_nonpriv_done(struct tevent_req *subreq); +static void wb_open_pipe_ping_done(struct tevent_req *subreq); +static void wb_open_pipe_getpriv_done(struct tevent_req *subreq); +static void wb_open_pipe_connect_priv_done(struct tevent_req *subreq); -static struct async_req *wb_open_pipe_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - struct wb_context *wb_ctx, - bool need_priv) +static struct tevent_req *wb_open_pipe_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct wb_context *wb_ctx, + bool need_priv) { - struct async_req *result; - struct async_req *subreq; + struct tevent_req *result, *subreq; struct wb_open_pipe_state *state; - if (!async_req_setup(mem_ctx, &result, &state, - struct wb_open_pipe_state)) { + result = tevent_req_create(mem_ctx, &state, struct wb_open_pipe_state); + if (result == NULL) { return NULL; } state->wb_ctx = wb_ctx; @@ -449,9 +421,8 @@ static struct async_req *wb_open_pipe_send(TALLOC_CTX *mem_ctx, if (subreq == NULL) { goto fail; } - - subreq->async.fn = wb_open_pipe_connect_nonpriv_done; - subreq->async.priv = result; + tevent_req_set_callback(subreq, wb_open_pipe_connect_nonpriv_done, + result); return result; fail: @@ -459,81 +430,77 @@ static struct async_req *wb_open_pipe_send(TALLOC_CTX *mem_ctx, return NULL; } -static void wb_open_pipe_connect_nonpriv_done(struct async_req *subreq) +static void wb_open_pipe_connect_nonpriv_done(struct tevent_req *subreq) { - struct async_req *req = talloc_get_type_abort( - subreq->async.priv, struct async_req); - struct wb_open_pipe_state *state = talloc_get_type_abort( - req->private_data, struct wb_open_pipe_state); + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct wb_open_pipe_state *state = tevent_req_data( + req, struct wb_open_pipe_state); wbcErr wbc_err; wbc_err = wb_connect_recv(subreq); TALLOC_FREE(subreq); if (!WBC_ERROR_IS_OK(wbc_err)) { state->wb_ctx->is_priv = true; - async_req_error(req, wbc_err); + tevent_req_error(req, wbc_err); return; } ZERO_STRUCT(state->wb_req); state->wb_req.cmd = WINBINDD_INTERFACE_VERSION; - subreq = wb_int_trans_send(state, state->ev, state->wb_ctx->fd, + subreq = wb_int_trans_send(state, state->ev, NULL, state->wb_ctx->fd, &state->wb_req); - if (async_req_nomem(subreq, req)) { + if (tevent_req_nomem(subreq, req)) { return; } - - subreq->async.fn = wb_open_pipe_ping_done; - subreq->async.priv = req; + tevent_req_set_callback(subreq, wb_open_pipe_ping_done, req); } -static void wb_open_pipe_ping_done(struct async_req *subreq) +static void wb_open_pipe_ping_done(struct tevent_req *subreq) { - struct async_req *req = talloc_get_type_abort( - subreq->async.priv, struct async_req); - struct wb_open_pipe_state *state = talloc_get_type_abort( - req->private_data, struct wb_open_pipe_state); + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct wb_open_pipe_state *state = tevent_req_data( + req, struct wb_open_pipe_state); struct winbindd_response *wb_resp; wbcErr wbc_err; wbc_err = wb_int_trans_recv(subreq, state, &wb_resp); TALLOC_FREE(subreq); if (!WBC_ERROR_IS_OK(wbc_err)) { - async_req_error(req, wbc_err); + tevent_req_error(req, wbc_err); return; } if (!state->need_priv) { - async_req_done(req); + tevent_req_done(req); return; } state->wb_req.cmd = WINBINDD_PRIV_PIPE_DIR; - subreq = wb_int_trans_send(state, state->ev, state->wb_ctx->fd, + subreq = wb_int_trans_send(state, state->ev, NULL, state->wb_ctx->fd, &state->wb_req); - if (async_req_nomem(subreq, req)) { + if (tevent_req_nomem(subreq, req)) { return; } - - subreq->async.fn = wb_open_pipe_getpriv_done; - subreq->async.priv = req; + tevent_req_set_callback(subreq, wb_open_pipe_getpriv_done, req); } -static void wb_open_pipe_getpriv_done(struct async_req *subreq) +static void wb_open_pipe_getpriv_done(struct tevent_req *subreq) { - struct async_req *req = talloc_get_type_abort( - subreq->async.priv, struct async_req); - struct wb_open_pipe_state *state = talloc_get_type_abort( - req->private_data, struct wb_open_pipe_state); + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct wb_open_pipe_state *state = tevent_req_data( + req, struct wb_open_pipe_state); struct winbindd_response *wb_resp = NULL; wbcErr wbc_err; wbc_err = wb_int_trans_recv(subreq, state, &wb_resp); TALLOC_FREE(subreq); if (!WBC_ERROR_IS_OK(wbc_err)) { - async_req_error(req, wbc_err); + tevent_req_error(req, wbc_err); return; } @@ -541,37 +508,35 @@ static void wb_open_pipe_getpriv_done(struct async_req *subreq) state->wb_ctx->fd = -1; subreq = wb_connect_send(state, state->ev, state->wb_ctx, - (char *)wb_resp->extra_data.data); + (char *)wb_resp->extra_data.data); TALLOC_FREE(wb_resp); - if (async_req_nomem(subreq, req)) { + if (tevent_req_nomem(subreq, req)) { return; } - - subreq->async.fn = wb_open_pipe_connect_priv_done; - subreq->async.priv = req; + tevent_req_set_callback(subreq, wb_open_pipe_connect_priv_done, req); } -static void wb_open_pipe_connect_priv_done(struct async_req *subreq) +static void wb_open_pipe_connect_priv_done(struct tevent_req *subreq) { - struct async_req *req = talloc_get_type_abort( - subreq->async.priv, struct async_req); - struct wb_open_pipe_state *state = talloc_get_type_abort( - req->private_data, struct wb_open_pipe_state); + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct wb_open_pipe_state *state = tevent_req_data( + req, struct wb_open_pipe_state); wbcErr wbc_err; wbc_err = wb_connect_recv(subreq); TALLOC_FREE(subreq); if (!WBC_ERROR_IS_OK(wbc_err)) { - async_req_error(req, wbc_err); + tevent_req_error(req, wbc_err); return; } state->wb_ctx->is_priv = true; - async_req_done(req); + tevent_req_done(req); } -static wbcErr wb_open_pipe_recv(struct async_req *req) +static wbcErr wb_open_pipe_recv(struct tevent_req *req) { - return async_req_simple_recv_wbcerr(req); + return tevent_req_simple_recv_wbcerr(req); } struct wb_trans_state { @@ -584,73 +549,54 @@ struct wb_trans_state { bool need_priv; }; -static void wb_trans_connect_done(struct async_req *subreq); -static void wb_trans_done(struct async_req *subreq); -static void wb_trans_retry_wait_done(struct async_req *subreq); - -static void wb_trigger_trans(struct async_req *req) -{ - struct wb_trans_state *state = talloc_get_type_abort( - req->private_data, struct wb_trans_state); - struct async_req *subreq; - - if ((state->wb_ctx->fd == -1) - || (state->need_priv && !state->wb_ctx->is_priv)) { - - subreq = wb_open_pipe_send(state, state->ev, state->wb_ctx, - state->need_priv); - if (async_req_nomem(subreq, req)) { - return; - } - subreq->async.fn = wb_trans_connect_done; - subreq->async.priv = req; - return; - } - - subreq = wb_int_trans_send(state, state->ev, state->wb_ctx->fd, - state->wb_req); - if (async_req_nomem(subreq, req)) { - return; - } - subreq->async.fn = wb_trans_done; - subreq->async.priv = req; -} +static void wb_trans_connect_done(struct tevent_req *subreq); +static void wb_trans_done(struct tevent_req *subreq); +static void wb_trans_retry_wait_done(struct tevent_req *subreq); -struct async_req *wb_trans_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, - struct wb_context *wb_ctx, bool need_priv, - const struct winbindd_request *wb_req) +struct tevent_req *wb_trans_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct wb_context *wb_ctx, bool need_priv, + struct winbindd_request *wb_req) { - struct async_req *result; + struct tevent_req *req, *subreq; struct wb_trans_state *state; - if (!async_req_setup(mem_ctx, &result, &state, - struct wb_trans_state)) { + req = tevent_req_create(mem_ctx, &state, struct wb_trans_state); + if (req == NULL) { return NULL; } state->wb_ctx = wb_ctx; state->ev = ev; - state->wb_req = winbindd_request_copy(state, wb_req); - if (state->wb_req == NULL) { - goto fail; - } + state->wb_req = wb_req; state->num_retries = 10; state->need_priv = need_priv; - if (!async_req_enqueue(wb_ctx->queue, ev, result, wb_trigger_trans)) { - goto fail; + if ((wb_ctx->fd == -1) || (need_priv && !wb_ctx->is_priv)) { + subreq = wb_open_pipe_send(state, ev, wb_ctx, need_priv); + if (subreq == NULL) { + goto fail; + } + tevent_req_set_callback(subreq, wb_trans_connect_done, req); + return req; } - return result; + subreq = wb_int_trans_send(state, ev, wb_ctx->queue, wb_ctx->fd, + wb_req); + if (subreq == NULL) { + goto fail; + } + tevent_req_set_callback(subreq, wb_trans_done, req); + return req; fail: - TALLOC_FREE(result); + TALLOC_FREE(req); return NULL; } -static bool wb_trans_retry(struct async_req *req, +static bool wb_trans_retry(struct tevent_req *req, struct wb_trans_state *state, wbcErr wbc_err) { - struct async_req *subreq; + struct tevent_req *subreq; if (WBC_ERROR_IS_OK(wbc_err)) { return false; @@ -661,13 +607,13 @@ static bool wb_trans_retry(struct async_req *req, * Winbind not around or we can't connect to the pipe. Fail * immediately. */ - async_req_error(req, wbc_err); + tevent_req_error(req, wbc_err); return true; } state->num_retries -= 1; if (state->num_retries == 0) { - async_req_error(req, wbc_err); + tevent_req_error(req, wbc_err); return true; } @@ -680,46 +626,44 @@ static bool wb_trans_retry(struct async_req *req, state->wb_ctx->fd = -1; } - subreq = async_wait_send(state, state->ev, timeval_set(1, 0)); - if (async_req_nomem(subreq, req)) { + subreq = tevent_wakeup_send(state, state->ev, + timeval_current_ofs(1, 0)); + if (tevent_req_nomem(subreq, req)) { return true; } - - subreq->async.fn = wb_trans_retry_wait_done; - subreq->async.priv = req; + tevent_req_set_callback(subreq, wb_trans_retry_wait_done, req); return true; } -static void wb_trans_retry_wait_done(struct async_req *subreq) +static void wb_trans_retry_wait_done(struct tevent_req *subreq) { - struct async_req *req = talloc_get_type_abort( - subreq->async.priv, struct async_req); - struct wb_trans_state *state = talloc_get_type_abort( - req->private_data, struct wb_trans_state); + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct wb_trans_state *state = tevent_req_data( + req, struct wb_trans_state); bool ret; - ret = async_wait_recv(subreq); + ret = tevent_wakeup_recv(subreq); TALLOC_FREE(subreq); - if (ret) { - async_req_error(req, WBC_ERR_UNKNOWN_FAILURE); + if (!ret) { + tevent_req_error(req, WBC_ERR_UNKNOWN_FAILURE); return; } subreq = wb_open_pipe_send(state, state->ev, state->wb_ctx, state->need_priv); - if (async_req_nomem(subreq, req)) { + if (tevent_req_nomem(subreq, req)) { return; } - subreq->async.fn = wb_trans_connect_done; - subreq->async.priv = req; + tevent_req_set_callback(subreq, wb_trans_connect_done, req); } -static void wb_trans_connect_done(struct async_req *subreq) +static void wb_trans_connect_done(struct tevent_req *subreq) { - struct async_req *req = talloc_get_type_abort( - subreq->async.priv, struct async_req); - struct wb_trans_state *state = talloc_get_type_abort( - req->private_data, struct wb_trans_state); + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct wb_trans_state *state = tevent_req_data( + req, struct wb_trans_state); wbcErr wbc_err; wbc_err = wb_open_pipe_recv(subreq); @@ -729,22 +673,20 @@ static void wb_trans_connect_done(struct async_req *subreq) return; } - subreq = wb_int_trans_send(state, state->ev, state->wb_ctx->fd, + subreq = wb_int_trans_send(state, state->ev, NULL, state->wb_ctx->fd, state->wb_req); - if (async_req_nomem(subreq, req)) { + if (tevent_req_nomem(subreq, req)) { return; } - - subreq->async.fn = wb_trans_done; - subreq->async.priv = req; + tevent_req_set_callback(subreq, wb_trans_done, req); } -static void wb_trans_done(struct async_req *subreq) +static void wb_trans_done(struct tevent_req *subreq) { - struct async_req *req = talloc_get_type_abort( - subreq->async.priv, struct async_req); - struct wb_trans_state *state = talloc_get_type_abort( - req->private_data, struct wb_trans_state); + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct wb_trans_state *state = tevent_req_data( + req, struct wb_trans_state); wbcErr wbc_err; wbc_err = wb_int_trans_recv(subreq, state, &state->wb_resp); @@ -754,17 +696,17 @@ static void wb_trans_done(struct async_req *subreq) return; } - async_req_done(req); + tevent_req_done(req); } -wbcErr wb_trans_recv(struct async_req *req, TALLOC_CTX *mem_ctx, +wbcErr wb_trans_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, struct winbindd_response **presponse) { - struct wb_trans_state *state = talloc_get_type_abort( - req->private_data, struct wb_trans_state); + struct wb_trans_state *state = tevent_req_data( + req, struct wb_trans_state); wbcErr wbc_err; - if (async_req_is_wbcerr(req, &wbc_err)) { + if (tevent_req_is_wbcerr(req, &wbc_err)) { return wbc_err; } diff --git a/source3/lib/winbind_util.c b/source3/lib/winbind_util.c index 64f5fb421a..df095b9e91 100644 --- a/source3/lib/winbind_util.c +++ b/source3/lib/winbind_util.c @@ -322,7 +322,6 @@ bool winbind_get_sid_aliases(TALLOC_CTX *mem_ctx, &rids, &num_rids); if (ret != WBC_ERR_SUCCESS) { - wbcFreeMemory(rids); return false; } |