From 19e4e99bfb02b8fa722883b04237ad714d402cb3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 14 Jan 2008 11:06:46 -0800 Subject: From Alexander Bokovoy names is a 'const char **names' here, passed from upper level. Passing 'names' as a talloc context will break things as 'names' is usually likely is a local variable, not a talloc'd. And we want to have array elements on a context of the array anyway. Jeremy. (This used to be commit 22a4129fabf70e01cc638c2f7347c28201838830) --- source3/lib/winbind_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source3/lib/winbind_util.c b/source3/lib/winbind_util.c index 3cf068a6e0..14356b09cf 100644 --- a/source3/lib/winbind_util.c +++ b/source3/lib/winbind_util.c @@ -201,7 +201,7 @@ bool winbind_lookup_rids(TALLOC_CTX *mem_ctx, *types = TALLOC_ARRAY(mem_ctx, enum lsa_SidType, num_rids); for(i=0; i Date: Tue, 15 Jan 2008 14:48:34 +0100 Subject: Define libnet join interface in IDL. Guenther (This used to be commit 7a48779ee5ec8bdd5e2b5eef94fd465f733b74b4) --- source3/librpc/idl/libnet_join.idl | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 source3/librpc/idl/libnet_join.idl diff --git a/source3/librpc/idl/libnet_join.idl b/source3/librpc/idl/libnet_join.idl new file mode 100644 index 0000000000..2741b7bd7b --- /dev/null +++ b/source3/librpc/idl/libnet_join.idl @@ -0,0 +1,60 @@ +#include "idl_types.h" + +import "wkssvc.idl", "security.idl"; + +/* + libnetjoin interface definition +*/ + +[ + pointer_default(unique) +] +interface libnetjoin +{ + typedef bitmap wkssvc_joinflags wkssvc_joinflags; + + [nopush,nopull] WERROR libnet_JoinCtx( + [in] string dc_name, + [in] string machine_name, + [in,ref] string *domain_name, + [in] string account_ou, + [in] string admin_account, + [in] string admin_password, + [in] string machine_password, + [in] wkssvc_joinflags join_flags, + [in] string os_version, + [in] string os_name, + [in] boolean8 create_upn, + [in] string upn, + [in] boolean8 modify_config, + [in] ads_struct *ads, + [in] boolean8 debug, + [out] string account_name, + [out] string netbios_domain_name, + [out] string dns_domain_name, + [out] string dn, + [out] dom_sid *domain_sid, + [out] boolean8 modified_config, + [out] string error_string, + [out] boolean8 domain_is_ad + ); + + [nopush,nopull] WERROR libnet_UnjoinCtx( + [in] string dc_name, + [in] string machine_name, + [in] string domain_name, + [in] string account_ou, + [in] string admin_account, + [in] string admin_password, + [in] string machine_password, + [in] wkssvc_joinflags unjoin_flags, + [in] boolean8 modify_config, + [in] dom_sid *domain_sid, + [in] ads_struct *ads, + [in] boolean8 debug, + [out] string netbios_domain_name, + [out] string dns_domain_name, + [out] boolean8 modified_config, + [out] string error_string + ); +} -- cgit From 4e2029f25c961dd1cba52cf6ac985915902f1726 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 15 Jan 2008 15:16:24 +0100 Subject: Add ndr_print_sockaddr_storage and ndr_print_bool. Guenther (This used to be commit f44f76415a7ce3ea73b5c52494f3b36feab4c870) --- source3/librpc/ndr/ndr_basic.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/source3/librpc/ndr/ndr_basic.c b/source3/librpc/ndr/ndr_basic.c index 0ef78a2a54..54397c9469 100644 --- a/source3/librpc/ndr/ndr_basic.c +++ b/source3/librpc/ndr/ndr_basic.c @@ -847,3 +847,14 @@ _PUBLIC_ uint32_t ndr_size_DATA_BLOB(int ret, const DATA_BLOB *data, int flags) if (!data) return ret; return ret + data->length; } + +_PUBLIC_ void ndr_print_bool(struct ndr_print *ndr, const char *name, const bool b) +{ + ndr->print(ndr, "%-25s: %s", name, b?"true":"false"); +} + +_PUBLIC_ void ndr_print_sockaddr_storage(struct ndr_print *ndr, const char *name, const struct sockaddr_storage *ss) +{ + char addr[INET6_ADDRSTRLEN]; + ndr->print(ndr, "%-25s: %s", name, print_sockaddr(addr, sizeof(addr), ss)); +} -- cgit From af69a1b43170017bb36bdb20f4c98bfbf95948a1 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 15 Jan 2008 15:20:57 +0100 Subject: Add ndr_print_ads_struct(). Guenther (This used to be commit 0a914a55bab30d765872d72cfdd59889d2afe42a) --- source3/librpc/ndr/ndr_misc.c | 81 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/source3/librpc/ndr/ndr_misc.c b/source3/librpc/ndr/ndr_misc.c index 2ca0cf08e8..245ba45215 100644 --- a/source3/librpc/ndr/ndr_misc.c +++ b/source3/librpc/ndr/ndr_misc.c @@ -153,3 +153,84 @@ void ndr_print_server_id(struct ndr_print *ndr, const char *name, const struct s #endif ndr->depth--; } + +void ndr_print_ads_struct(struct ndr_print *ndr, const char *name, const struct ads_struct *r) +{ + if (!r) { return; } + + ndr_print_struct(ndr, name, "ads_struct"); + ndr->depth++; + ndr_print_bool(ndr, "is_mine", r->is_mine); + ndr_print_struct(ndr, name, "server"); + ndr->depth++; + ndr_print_string(ndr, "realm", r->server.realm); + ndr_print_string(ndr, "workgroup", r->server.workgroup); + ndr_print_string(ndr, "ldap_server", r->server.ldap_server); + ndr_print_bool(ndr, "foreign", r->server.foreign); + ndr->depth--; + ndr_print_struct(ndr, name, "auth"); + ndr->depth++; + ndr_print_string(ndr, "realm", r->auth.realm); +#ifdef DEBUG_PASSWORD + ndr_print_string(ndr, "password", r->auth.password); +#else + ndr_print_string(ndr, "password", "(PASSWORD ommited)"); +#endif + ndr_print_string(ndr, "user_name", r->auth.user_name); + ndr_print_string(ndr, "kdc_server", r->auth.kdc_server); + ndr_print_uint32(ndr, "flags", r->auth.flags); + ndr_print_uint32(ndr, "time_offset", r->auth.time_offset); + ndr_print_time_t(ndr, "tgt_expire", r->auth.tgt_expire); + ndr_print_time_t(ndr, "tgs_expire", r->auth.tgs_expire); + ndr_print_time_t(ndr, "renewable", r->auth.renewable); + ndr->depth--; + ndr_print_struct(ndr, name, "config"); + ndr->depth++; + ndr_print_uint32(ndr, "flags", r->config.flags); + ndr_print_string(ndr, "realm", r->config.realm); + ndr_print_string(ndr, "bind_path", r->config.bind_path); + ndr_print_string(ndr, "ldap_server_name", r->config.ldap_server_name); + ndr_print_string(ndr, "server_site_name", r->config.server_site_name); + ndr_print_string(ndr, "client_site_name", r->config.client_site_name); + ndr_print_time_t(ndr, "current_time", r->config.current_time); + ndr_print_bool(ndr, "tried_closest_dc", r->config.tried_closest_dc); + ndr_print_string(ndr, "schema_path", r->config.schema_path); + ndr_print_string(ndr, "config_path", r->config.config_path); + ndr->depth--; +#ifdef HAVE_LDAP + ndr_print_struct(ndr, name, "ldap"); + ndr->depth++; + ndr_print_ptr(ndr, "ld", r->ldap.ld); + ndr_print_sockaddr_storage(ndr, "ss", &r->ldap.ss); + ndr_print_time_t(ndr, "last_attempt", r->ldap.last_attempt); + ndr_print_uint32(ndr, "port", r->ldap.port); + ndr_print_uint16(ndr, "wrap_type", r->ldap.wrap_type); +#ifdef HAVE_LDAP_SASL_WRAPPING + ndr_print_ptr(ndr, "sbiod", r->ldap.sbiod); +#endif /* HAVE_LDAP_SASL_WRAPPING */ + ndr_print_ptr(ndr, "mem_ctx", r->ldap.mem_ctx); + ndr_print_ptr(ndr, "wrap_ops", r->ldap.wrap_ops); + ndr_print_ptr(ndr, "wrap_private_data", r->ldap.wrap_private_data); + ndr_print_struct(ndr, name, "in"); + ndr->depth++; + ndr_print_uint32(ndr, "ofs", r->ldap.in.ofs); + ndr_print_uint32(ndr, "needed", r->ldap.in.needed); + ndr_print_uint32(ndr, "left", r->ldap.in.left); + ndr_print_uint32(ndr, "max_wrapped", r->ldap.in.max_wrapped); + ndr_print_uint32(ndr, "min_wrapped", r->ldap.in.min_wrapped); + ndr_print_uint32(ndr, "size", r->ldap.in.size); + ndr_print_array_uint8(ndr, "buf", r->ldap.in.buf, r->ldap.in.size); + ndr->depth--; + ndr_print_struct(ndr, name, "out"); + ndr->depth++; + ndr_print_uint32(ndr, "ofs", r->ldap.out.ofs); + ndr_print_uint32(ndr, "left", r->ldap.out.left); + ndr_print_uint32(ndr, "max_unwrapped", r->ldap.out.max_unwrapped); + ndr_print_uint32(ndr, "sig_size", r->ldap.out.sig_size); + ndr_print_uint32(ndr, "size", r->ldap.out.size); + ndr_print_array_uint8(ndr, "buf", r->ldap.out.buf, r->ldap.out.size); + ndr->depth--; + ndr->depth--; +#endif /* HAVE_LDAP */ + ndr->depth--; +} -- cgit From b239612fcf199cfeba5c93535f70d3cdd880a5bf Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 15 Jan 2008 15:28:39 +0100 Subject: Use autogenerated libnet_join header. Guenther (This used to be commit d94bd3a03b574b3fdddd62add25b0c04673500a3) --- source3/Makefile.in | 3 +- source3/libnet/libnet.h | 2 +- source3/libnet/libnet_join.h | 75 ---------------------- source3/librpc/gen_ndr/libnet_join.h | 73 ++++++++++++++++++++++ source3/librpc/gen_ndr/ndr_libnet_join.c | 103 +++++++++++++++++++++++++++++++ source3/librpc/gen_ndr/ndr_libnet_join.h | 20 ++++++ 6 files changed, 199 insertions(+), 77 deletions(-) delete mode 100644 source3/libnet/libnet_join.h create mode 100644 source3/librpc/gen_ndr/libnet_join.h create mode 100644 source3/librpc/gen_ndr/ndr_libnet_join.c create mode 100644 source3/librpc/gen_ndr/ndr_libnet_join.h diff --git a/source3/Makefile.in b/source3/Makefile.in index 53fd669b4c..a734109b41 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -268,7 +268,8 @@ LIBNDR_GEN_OBJ = librpc/gen_ndr/ndr_wkssvc.o \ librpc/gen_ndr/ndr_srvsvc.o \ librpc/gen_ndr/ndr_svcctl.o \ librpc/gen_ndr/ndr_eventlog.o \ - librpc/gen_ndr/ndr_notify.o + librpc/gen_ndr/ndr_notify.o \ + librpc/gen_ndr/ndr_libnet_join.o RPC_PARSE_OBJ0 = rpc_parse/parse_prs.o rpc_parse/parse_misc.o diff --git a/source3/libnet/libnet.h b/source3/libnet/libnet.h index d6238ca982..97e720f617 100644 --- a/source3/libnet/libnet.h +++ b/source3/libnet/libnet.h @@ -20,7 +20,7 @@ #ifndef __LIBNET_H__ #define __LIBNET_H__ -#include "libnet/libnet_join.h" +#include "librpc/gen_ndr/libnet_join.h" #include "libnet/libnet_conf.h" #include "libnet/libnet_proto.h" diff --git a/source3/libnet/libnet_join.h b/source3/libnet/libnet_join.h deleted file mode 100644 index c47e8d934c..0000000000 --- a/source3/libnet/libnet_join.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * libnet Join Support - * Copyright (C) Guenther Deschner 2007-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 . - */ - -#ifndef __LIBNET_JOIN_H__ -#define __LIBNET_JOIN_H__ - -struct libnet_JoinCtx { - struct { - const char *dc_name; - const char *machine_name; - const char *domain_name; - const char *account_ou; - const char *admin_account; - const char *admin_password; - const char *machine_password; - uint32_t join_flags; - const char *os_version; - const char *os_name; - bool create_upn; - const char *upn; - bool modify_config; - struct ads_struct *ads; - bool debug; - } in; - - struct { - char *account_name; - char *netbios_domain_name; - char *dns_domain_name; - char *dn; - struct dom_sid *domain_sid; - bool modified_config; - WERROR result; - char *error_string; - bool domain_is_ad; - } out; -}; - -struct libnet_UnjoinCtx { - struct { - const char *dc_name; - const char *machine_name; - const char *domain_name; - const char *admin_account; - const char *admin_password; - uint32_t unjoin_flags; - bool modify_config; - struct dom_sid *domain_sid; - struct ads_struct *ads; - } in; - - struct { - bool modified_config; - WERROR result; - char *error_string; - } out; -}; - -#endif diff --git a/source3/librpc/gen_ndr/libnet_join.h b/source3/librpc/gen_ndr/libnet_join.h new file mode 100644 index 0000000000..40759cb489 --- /dev/null +++ b/source3/librpc/gen_ndr/libnet_join.h @@ -0,0 +1,73 @@ +/* header auto-generated by pidl */ + +#include + +#include "librpc/gen_ndr/wkssvc.h" +#include "librpc/gen_ndr/security.h" +#ifndef _HEADER_libnetjoin +#define _HEADER_libnetjoin + +; + + +struct libnet_JoinCtx { + struct { + const char * dc_name; + const char * machine_name; + const char * domain_name;/* [ref] */ + const char * account_ou; + const char * admin_account; + const char * admin_password; + const char * machine_password; + uint32_t join_flags; + const char * os_version; + const char * os_name; + uint8_t create_upn; + const char * upn; + uint8_t modify_config; + struct ads_struct *ads;/* [ref] */ + uint8_t debug; + } in; + + struct { + const char * account_name; + const char * netbios_domain_name; + const char * dns_domain_name; + const char * dn; + struct dom_sid *domain_sid;/* [ref] */ + uint8_t modified_config; + const char * error_string; + uint8_t domain_is_ad; + WERROR result; + } out; + +}; + + +struct libnet_UnjoinCtx { + struct { + const char * dc_name; + const char * machine_name; + const char * domain_name; + const char * account_ou; + const char * admin_account; + const char * admin_password; + const char * machine_password; + uint32_t unjoin_flags; + uint8_t modify_config; + struct dom_sid *domain_sid;/* [ref] */ + struct ads_struct *ads;/* [ref] */ + uint8_t debug; + } in; + + struct { + const char * netbios_domain_name; + const char * dns_domain_name; + uint8_t modified_config; + const char * error_string; + WERROR result; + } out; + +}; + +#endif /* _HEADER_libnetjoin */ diff --git a/source3/librpc/gen_ndr/ndr_libnet_join.c b/source3/librpc/gen_ndr/ndr_libnet_join.c new file mode 100644 index 0000000000..5345bc0ad4 --- /dev/null +++ b/source3/librpc/gen_ndr/ndr_libnet_join.c @@ -0,0 +1,103 @@ +/* parser auto-generated by pidl */ + +#include "includes.h" +#include "librpc/gen_ndr/ndr_libnet_join.h" + +#include "librpc/gen_ndr/ndr_wkssvc.h" +#include "librpc/gen_ndr/ndr_security.h" +_PUBLIC_ void ndr_print_libnet_JoinCtx(struct ndr_print *ndr, const char *name, int flags, const struct libnet_JoinCtx *r) +{ + ndr_print_struct(ndr, name, "libnet_JoinCtx"); + ndr->depth++; + if (flags & NDR_SET_VALUES) { + ndr->flags |= LIBNDR_PRINT_SET_VALUES; + } + if (flags & NDR_IN) { + ndr_print_struct(ndr, "in", "libnet_JoinCtx"); + ndr->depth++; + ndr_print_string(ndr, "dc_name", r->in.dc_name); + ndr_print_string(ndr, "machine_name", r->in.machine_name); + ndr_print_ptr(ndr, "domain_name", r->in.domain_name); + ndr->depth++; + ndr_print_string(ndr, "domain_name", r->in.domain_name); + ndr->depth--; + ndr_print_string(ndr, "account_ou", r->in.account_ou); + ndr_print_string(ndr, "admin_account", r->in.admin_account); + ndr_print_string(ndr, "admin_password", r->in.admin_password); + ndr_print_string(ndr, "machine_password", r->in.machine_password); + ndr_print_wkssvc_joinflags(ndr, "join_flags", r->in.join_flags); + ndr_print_string(ndr, "os_version", r->in.os_version); + ndr_print_string(ndr, "os_name", r->in.os_name); + ndr_print_uint8(ndr, "create_upn", r->in.create_upn); + ndr_print_string(ndr, "upn", r->in.upn); + ndr_print_uint8(ndr, "modify_config", r->in.modify_config); + ndr_print_ptr(ndr, "ads", r->in.ads); + ndr->depth++; + ndr_print_ads_struct(ndr, "ads", r->in.ads); + ndr->depth--; + ndr_print_uint8(ndr, "debug", r->in.debug); + ndr->depth--; + } + if (flags & NDR_OUT) { + ndr_print_struct(ndr, "out", "libnet_JoinCtx"); + ndr->depth++; + ndr_print_string(ndr, "account_name", r->out.account_name); + ndr_print_string(ndr, "netbios_domain_name", r->out.netbios_domain_name); + ndr_print_string(ndr, "dns_domain_name", r->out.dns_domain_name); + ndr_print_string(ndr, "dn", r->out.dn); + ndr_print_ptr(ndr, "domain_sid", r->out.domain_sid); + ndr->depth++; + ndr_print_dom_sid(ndr, "domain_sid", r->out.domain_sid); + ndr->depth--; + ndr_print_uint8(ndr, "modified_config", r->out.modified_config); + ndr_print_string(ndr, "error_string", r->out.error_string); + ndr_print_uint8(ndr, "domain_is_ad", r->out.domain_is_ad); + ndr_print_WERROR(ndr, "result", r->out.result); + ndr->depth--; + } + ndr->depth--; +} + +_PUBLIC_ void ndr_print_libnet_UnjoinCtx(struct ndr_print *ndr, const char *name, int flags, const struct libnet_UnjoinCtx *r) +{ + ndr_print_struct(ndr, name, "libnet_UnjoinCtx"); + ndr->depth++; + if (flags & NDR_SET_VALUES) { + ndr->flags |= LIBNDR_PRINT_SET_VALUES; + } + if (flags & NDR_IN) { + ndr_print_struct(ndr, "in", "libnet_UnjoinCtx"); + ndr->depth++; + ndr_print_string(ndr, "dc_name", r->in.dc_name); + ndr_print_string(ndr, "machine_name", r->in.machine_name); + ndr_print_string(ndr, "domain_name", r->in.domain_name); + ndr_print_string(ndr, "account_ou", r->in.account_ou); + ndr_print_string(ndr, "admin_account", r->in.admin_account); + ndr_print_string(ndr, "admin_password", r->in.admin_password); + ndr_print_string(ndr, "machine_password", r->in.machine_password); + ndr_print_wkssvc_joinflags(ndr, "unjoin_flags", r->in.unjoin_flags); + ndr_print_uint8(ndr, "modify_config", r->in.modify_config); + ndr_print_ptr(ndr, "domain_sid", r->in.domain_sid); + ndr->depth++; + ndr_print_dom_sid(ndr, "domain_sid", r->in.domain_sid); + ndr->depth--; + ndr_print_ptr(ndr, "ads", r->in.ads); + ndr->depth++; + ndr_print_ads_struct(ndr, "ads", r->in.ads); + ndr->depth--; + ndr_print_uint8(ndr, "debug", r->in.debug); + ndr->depth--; + } + if (flags & NDR_OUT) { + ndr_print_struct(ndr, "out", "libnet_UnjoinCtx"); + ndr->depth++; + ndr_print_string(ndr, "netbios_domain_name", r->out.netbios_domain_name); + ndr_print_string(ndr, "dns_domain_name", r->out.dns_domain_name); + ndr_print_uint8(ndr, "modified_config", r->out.modified_config); + ndr_print_string(ndr, "error_string", r->out.error_string); + ndr_print_WERROR(ndr, "result", r->out.result); + ndr->depth--; + } + ndr->depth--; +} + diff --git a/source3/librpc/gen_ndr/ndr_libnet_join.h b/source3/librpc/gen_ndr/ndr_libnet_join.h new file mode 100644 index 0000000000..4a5fdf0d50 --- /dev/null +++ b/source3/librpc/gen_ndr/ndr_libnet_join.h @@ -0,0 +1,20 @@ +/* header auto-generated by pidl */ + +#include "librpc/ndr/libndr.h" +#include "librpc/gen_ndr/libnet_join.h" + +#ifndef _HEADER_NDR_libnetjoin +#define _HEADER_NDR_libnetjoin + +#define NDR_LIBNET_JOINCTX (0x00) + +#define NDR_LIBNET_UNJOINCTX (0x01) + +#define NDR_LIBNETJOIN_CALL_COUNT (2) +enum ndr_err_code ndr_push_libnet_JoinCtx(struct ndr_push *ndr, int flags, const struct libnet_JoinCtx *r); +enum ndr_err_code ndr_pull_libnet_JoinCtx(struct ndr_pull *ndr, int flags, struct libnet_JoinCtx *r); +void ndr_print_libnet_JoinCtx(struct ndr_print *ndr, const char *name, int flags, const struct libnet_JoinCtx *r); +enum ndr_err_code ndr_push_libnet_UnjoinCtx(struct ndr_push *ndr, int flags, const struct libnet_UnjoinCtx *r); +enum ndr_err_code ndr_pull_libnet_UnjoinCtx(struct ndr_pull *ndr, int flags, struct libnet_UnjoinCtx *r); +void ndr_print_libnet_UnjoinCtx(struct ndr_print *ndr, const char *name, int flags, const struct libnet_UnjoinCtx *r); +#endif /* _HEADER_NDR_libnetjoin */ -- cgit From 2ae6feb5779788a7e8e0ef0f092043ae0dfb1dcb Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 15 Jan 2008 15:43:19 +0100 Subject: Include libnet_join.h in the right places. Guenther (This used to be commit 586d6cef521cebfd6fe2d433fdef498d4a59cb1b) --- source3/include/smb.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source3/include/smb.h b/source3/include/smb.h index 49245eaa83..744acd719f 100644 --- a/source3/include/smb.h +++ b/source3/include/smb.h @@ -322,6 +322,8 @@ struct id_map { #include "librpc/gen_ndr/wkssvc.h" #include "librpc/gen_ndr/echo.h" #include "librpc/gen_ndr/svcctl.h" +#include "librpc/gen_ndr/libnet_join.h" + struct lsa_dom_info { bool valid; -- cgit From 40222cc8e211c9d82a75d57b802ced11172937e5 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 15 Jan 2008 15:48:48 +0100 Subject: Remove unrequired TALLOC_FREE. Guenther (This used to be commit 15d0e574386e39a4d2fa61cd268b48dfa5c84dcb) --- source3/libnet/libnet_join.c | 1 - 1 file changed, 1 deletion(-) diff --git a/source3/libnet/libnet_join.c b/source3/libnet/libnet_join.c index c60f4c9803..ce3a5969a4 100644 --- a/source3/libnet/libnet_join.c +++ b/source3/libnet/libnet_join.c @@ -236,7 +236,6 @@ static ADS_STATUS libnet_join_find_machine_acct(TALLOC_CTX *mem_ctx, goto done; } - TALLOC_FREE(r->out.dn); r->out.dn = talloc_strdup(mem_ctx, dn); if (!r->out.dn) { status = ADS_ERROR_LDAP(LDAP_NO_MEMORY); -- cgit From 0a21a1ab092cb93066490228808361f6daa619d5 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 15 Jan 2008 15:56:58 +0100 Subject: Revert "libwbclient: don't link talloc.o into libwbclient.a" This reverts commit 9a4b6fd3e21f54a0ff83f1fd0d0d5331a2cfdd0a. Sorry... metze (This used to be commit 58c806dbf85fd634c8f3559a035751a4cd0b5c4b) --- source3/Makefile.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source3/Makefile.in b/source3/Makefile.in index a734109b41..fe873f5c70 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -1434,9 +1434,9 @@ bin/libsmbclient.@SHLIBEXT@: $(BINARY_PREREQS) $(LIBSMBCLIENT_OBJ) $(KRB5LIBS) $(LDAP_LIBS) $(NSCD_LIBS) \ @SONAMEFLAG@`basename $@`.$(SONAME_VER) -bin/libsmbclient.a: $(BINARY_PREREQS) $(LIBSMBCLIENT_OBJ0) +bin/libsmbclient.a: $(BINARY_PREREQS) $(LIBSMBCLIENT_OBJ) @echo Linking non-shared library $@ - @-$(AR) -rc $@ $(LIBSMBCLIENT_OBJ0) + @-$(AR) -rc $@ $(LIBSMBCLIENT_OBJ) bin/libsmbsharemodes.@SHLIBEXT@: $(BINARY_PREREQS) $(LIBSMBSHAREMODES_OBJ) @echo Linking shared library $@ -- cgit From bd8f1f71ac1a8031cd8aa213c2201013860e55fc Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 15 Jan 2008 14:59:46 +0100 Subject: libwbclient: don't link talloc.o into libwbclient.a hopefully fix the build...(and hopefully the correct fix) metze (This used to be commit 561e529a711338b2a3191f1b04f384f5ab3413ac) --- source3/Makefile.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source3/Makefile.in b/source3/Makefile.in index fe873f5c70..d65b10e1bb 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -1404,9 +1404,9 @@ bin/libwbclient.@SHLIBEXT@: $(BINARY_PREREQS) $(LIBWBCLIENT_OBJ) @SONAMEFLAG@`basename $@`.$(SONAME_VER) @ln -s -f `basename $@` $@.$(SONAME_VER) -bin/libwbclient.a: $(BINARY_PREREQS) $(LIBWBCLIENT_OBJ) +bin/libwbclient.a: $(BINARY_PREREQS) $(LIBWBCLIENT_OBJ0) @echo Linking non-shared library $@ - @-$(AR) -rc $@ $(LIBWBCLIENT_OBJ) + @-$(AR) -rc $@ $(LIBWBCLIENT_OBJ0) bin/libaddns.@SHLIBEXT@: $(BINARY_PREREQS) $(LIBADDNS_OBJ) @echo Linking shared library $@ -- cgit From c920764b1960f86482a24d4b4462664b07d4f1a9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 15 Jan 2008 16:40:02 +0100 Subject: Apply const to rpccli_lsa_query_info_policy() and rpccli_lsa_query_info_policy2(). Guenther (This used to be commit 7a3fe68bef7acde9d9f8a7a44ce7e9432f3c5a95) --- source3/rpc_client/cli_lsarpc.c | 8 +++++--- source3/rpcclient/rpcclient.c | 2 +- source3/utils/net.h | 2 +- source3/utils/net_ads.c | 7 ++++--- source3/utils/net_domain.c | 2 +- source3/utils/net_rpc.c | 11 ++++++----- source3/utils/net_rpc_join.c | 4 ++-- source3/winbindd/winbindd_cm.c | 6 +++--- 8 files changed, 23 insertions(+), 19 deletions(-) diff --git a/source3/rpc_client/cli_lsarpc.c b/source3/rpc_client/cli_lsarpc.c index 77ade5cba1..286cc210e2 100644 --- a/source3/rpc_client/cli_lsarpc.c +++ b/source3/rpc_client/cli_lsarpc.c @@ -542,7 +542,8 @@ NTSTATUS rpccli_lsa_query_info_policy2_new(struct rpc_pipe_client *cli, TALLOC_C NTSTATUS rpccli_lsa_query_info_policy(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *pol, uint16 info_class, - char **domain_name, DOM_SID **domain_sid) + const char **domain_name, + DOM_SID **domain_sid) { prs_struct qbuf, rbuf; LSA_Q_QUERY_INFO q; @@ -632,8 +633,9 @@ NTSTATUS rpccli_lsa_query_info_policy(struct rpc_pipe_client *cli, NTSTATUS rpccli_lsa_query_info_policy2(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *pol, uint16 info_class, - char **domain_name, char **dns_name, - char **forest_name, + const char **domain_name, + const char **dns_name, + const char **forest_name, struct GUID **domain_guid, DOM_SID **domain_sid) { diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c index dd8b911bb8..081e0fb15e 100644 --- a/source3/rpcclient/rpcclient.c +++ b/source3/rpcclient/rpcclient.c @@ -134,7 +134,7 @@ static void fetch_machine_sid(struct cli_state *cli) POLICY_HND pol; NTSTATUS result = NT_STATUS_OK; uint32 info_class = 5; - char *domain_name = NULL; + const char *domain_name = NULL; static bool got_domain_sid; TALLOC_CTX *mem_ctx; DOM_SID *dom_sid = NULL; diff --git a/source3/utils/net.h b/source3/utils/net.h index 2ffa4d77b1..3a4b1da7b0 100644 --- a/source3/utils/net.h +++ b/source3/utils/net.h @@ -42,7 +42,7 @@ struct rpc_sh_ctx { struct cli_state *cli; DOM_SID *domain_sid; - char *domain_name; + const char *domain_name; const char *whoami; const char *thiscmd; diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c index 0a9020bcfd..732ba8d8b6 100644 --- a/source3/utils/net_ads.c +++ b/source3/utils/net_ads.c @@ -817,7 +817,7 @@ static int net_ads_leave(int argc, const char **argv) struct cli_state *cli = NULL; TALLOC_CTX *ctx; DOM_SID *dom_sid = NULL; - char *short_domain_name = NULL; + const char *short_domain_name = NULL; if (!secrets_init()) { DEBUG(1,("Failed to initialise secrets database\n")); @@ -961,7 +961,8 @@ static NTSTATUS check_ads_config( void ) ********************************************************************/ static NTSTATUS net_join_domain(TALLOC_CTX *ctx, const char *servername, - struct sockaddr_storage *pss, char **domain, + struct sockaddr_storage *pss, + const char **domain, DOM_SID **dom_sid, const char *password) { @@ -1445,7 +1446,7 @@ int net_ads_join(int argc, const char **argv) ADS_STRUCT *ads = NULL; ADS_STATUS status; NTSTATUS nt_status; - char *short_domain_name = NULL; + const char *short_domain_name = NULL; char *tmp_password, *password; TALLOC_CTX *ctx = NULL; DOM_SID *domain_sid = NULL; diff --git a/source3/utils/net_domain.c b/source3/utils/net_domain.c index 3f1908e242..da5e61caf0 100644 --- a/source3/utils/net_domain.c +++ b/source3/utils/net_domain.c @@ -157,7 +157,7 @@ int netdom_store_machine_account( const char *domain, DOM_SID *sid, const char * ********************************************************************/ NTSTATUS netdom_get_domain_sid( TALLOC_CTX *mem_ctx, struct cli_state *cli, - char **domain, DOM_SID **sid ) + const char **domain, DOM_SID **sid ) { struct rpc_pipe_client *pipe_hnd = NULL; POLICY_HND lsa_pol; diff --git a/source3/utils/net_rpc.c b/source3/utils/net_rpc.c index 2bd867fff3..677924649c 100644 --- a/source3/utils/net_rpc.c +++ b/source3/utils/net_rpc.c @@ -51,7 +51,8 @@ static bool sync_files(struct copy_clistate *cp_clistate, const char *mask); **/ NTSTATUS net_get_remote_domain_sid(struct cli_state *cli, TALLOC_CTX *mem_ctx, - DOM_SID **domain_sid, char **domain_name) + DOM_SID **domain_sid, + const char **domain_name) { struct rpc_pipe_client *lsa_pipe; POLICY_HND pol; @@ -112,7 +113,7 @@ int run_rpc_command(struct cli_state *cli_arg, TALLOC_CTX *mem_ctx; NTSTATUS nt_status; DOM_SID *domain_sid; - char *domain_name; + const char *domain_name; /* make use of cli_state handed over as an argument, if possible */ if (!cli_arg) { @@ -5607,7 +5608,7 @@ static int rpc_trustdom_establish(int argc, const char **argv) DOM_SID *domain_sid; char* domain_name; - char* domain_name_pol; + const char* domain_name_pol; char* acct_name; fstring pdc_name; char *dc_name; @@ -5917,7 +5918,7 @@ static int rpc_trustdom_vampire(int argc, const char **argv) DOM_SID *domain_sids; char **trusted_dom_names; fstring pdc_name; - char *dummy; + const char *dummy; /* * Listing trusted domains (stored in secrets.tdb, if local) @@ -6057,7 +6058,7 @@ static int rpc_trustdom_list(int argc, const char **argv) DOM_SID *domain_sids; char **trusted_dom_names; fstring pdc_name; - char *dummy; + const char *dummy; /* trusting domains listing variables */ POLICY_HND domain_hnd; diff --git a/source3/utils/net_rpc_join.c b/source3/utils/net_rpc_join.c index 0c25a53365..6e37f3c84c 100644 --- a/source3/utils/net_rpc_join.c +++ b/source3/utils/net_rpc_join.c @@ -155,7 +155,7 @@ int net_rpc_join_newstyle(int argc, const char **argv) NTSTATUS result; int retval = 1; - char *domain = NULL; + const char *domain = NULL; uint32 num_rids, *name_types, *user_rids; uint32 flags = 0x3e8; char *acct_name; @@ -413,7 +413,7 @@ int net_rpc_join_newstyle(int argc, const char **argv) /* Now store the secret in the secrets database */ - strupper_m(domain); + strupper_m(CONST_DISCARD(char *, domain)); if (!secrets_store_domain_sid(domain, domain_sid)) { DEBUG(0, ("error storing domain sid for %s\n", domain)); diff --git a/source3/winbindd/winbindd_cm.c b/source3/winbindd/winbindd_cm.c index a9155a5763..908228717e 100644 --- a/source3/winbindd/winbindd_cm.c +++ b/source3/winbindd/winbindd_cm.c @@ -1799,9 +1799,9 @@ static void set_dc_type_and_flags_connect( struct winbindd_domain *domain ) struct rpc_pipe_client *cli; POLICY_HND pol; - char *domain_name = NULL; - char *dns_name = NULL; - char *forest_name = NULL; + const char *domain_name = NULL; + const char *dns_name = NULL; + const char *forest_name = NULL; DOM_SID *dom_sid = NULL; ZERO_STRUCT( ctr ); -- cgit From fe165e4a9f9d203d66aef15075a7ca89098a720c Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 15 Jan 2008 17:00:14 +0100 Subject: Use autogenerated debugging functions in libnetjoin when requested. Guenther (This used to be commit 08c1720509dffa2886ed057e2d14907699122f3c) --- source3/libnet/libnet_join.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source3/libnet/libnet_join.c b/source3/libnet/libnet_join.c index ce3a5969a4..a189a38ea3 100644 --- a/source3/libnet/libnet_join.c +++ b/source3/libnet/libnet_join.c @@ -1213,6 +1213,10 @@ WERROR libnet_Join(TALLOC_CTX *mem_ctx, { WERROR werr; + if (r->in.debug) { + NDR_PRINT_IN_DEBUG(libnet_JoinCtx, r); + } + werr = libnet_join_pre_processing(mem_ctx, r); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -1230,6 +1234,9 @@ WERROR libnet_Join(TALLOC_CTX *mem_ctx, goto done; } done: + if (r->in.debug) { + NDR_PRINT_OUT_DEBUG(libnet_JoinCtx, r); + } return werr; } @@ -1320,6 +1327,10 @@ WERROR libnet_Unjoin(TALLOC_CTX *mem_ctx, { WERROR werr; + if (r->in.debug) { + NDR_PRINT_IN_DEBUG(libnet_UnjoinCtx, r); + } + werr = libnet_unjoin_pre_processing(mem_ctx, r); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -1338,5 +1349,9 @@ WERROR libnet_Unjoin(TALLOC_CTX *mem_ctx, } done: + if (r->in.debug) { + NDR_PRINT_OUT_DEBUG(libnet_UnjoinCtx, r); + } + return werr; } -- cgit From c2acec43aed4fe9cca51a4227457accafeeb950b Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 15 Jan 2008 17:03:17 +0100 Subject: rename vfs_ea_tdb to vfs_xattr_tdb (This used to be commit 151b42a150a17f566e7b4055bbdbc0564a3c106d) --- source3/Makefile.in | 6 +- source3/configure.in | 4 +- source3/modules/vfs_ea_tdb.c | 736 --------------------------------------- source3/modules/vfs_xattr_tdb.c | 736 +++++++++++++++++++++++++++++++++++++++ source3/script/tests/selftest.sh | 2 +- 5 files changed, 742 insertions(+), 742 deletions(-) delete mode 100644 source3/modules/vfs_ea_tdb.c create mode 100644 source3/modules/vfs_xattr_tdb.c diff --git a/source3/Makefile.in b/source3/Makefile.in index d65b10e1bb..46f733c0bc 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -504,7 +504,7 @@ VFS_CAP_OBJ = modules/vfs_cap.o VFS_EXPAND_MSDFS_OBJ = modules/vfs_expand_msdfs.o VFS_SHADOW_COPY_OBJ = modules/vfs_shadow_copy.o VFS_AFSACL_OBJ = modules/vfs_afsacl.o -VFS_EA_TDB_OBJ = modules/vfs_ea_tdb.o librpc/gen_ndr/ndr_xattr.o +VFS_XATTR_TDB_OBJ = modules/vfs_xattr_tdb.o librpc/gen_ndr/ndr_xattr.o VFS_POSIXACL_OBJ = modules/vfs_posixacl.o VFS_AIXACL_OBJ = modules/vfs_aixacl.o modules/vfs_aixacl_util.o VFS_AIXACL2_OBJ = modules/vfs_aixacl2.o modules/vfs_aixacl_util.o modules/nfs4_acls.o @@ -1686,9 +1686,9 @@ bin/afsacl.@SHLIBEXT@: $(BINARY_PREREQS) $(VFS_AFSACL_OBJ) @echo "Building plugin $@" @$(SHLD_MODULE) $(VFS_AFSACL_OBJ) -bin/ea_tdb.@SHLIBEXT@: $(BINARY_PREREQS) $(VFS_EA_TDB_OBJ) +bin/xattr_tdb.@SHLIBEXT@: $(BINARY_PREREQS) $(VFS_XATTR_TDB_OBJ) @echo "Building plugin $@" - @$(SHLD_MODULE) $(VFS_EA_TDB_OBJ) + @$(SHLD_MODULE) $(VFS_XATTR_TDB_OBJ) bin/posixacl.@SHLIBEXT@: $(BINARY_PREREQS) $(VFS_POSIXACL_OBJ) @echo "Building plugin $@" diff --git a/source3/configure.in b/source3/configure.in index 4ddc64407c..cd04b598c0 100644 --- a/source3/configure.in +++ b/source3/configure.in @@ -707,7 +707,7 @@ dnl These have to be built static: default_static_modules="pdb_smbpasswd pdb_tdbsam rpc_lsa rpc_samr rpc_winreg rpc_initshutdown rpc_lsa_ds rpc_wkssvc rpc_svcctl2 rpc_ntsvcs rpc_net rpc_netdfs rpc_srvsvc2 rpc_spoolss rpc_eventlog2 auth_sam auth_unix auth_winbind auth_server auth_domain auth_builtin vfs_default nss_info_template" dnl These are preferably build shared, and static if dlopen() is not available -default_shared_modules="vfs_recycle vfs_audit vfs_extd_audit vfs_full_audit vfs_netatalk vfs_fake_perms vfs_default_quota vfs_readonly vfs_cap vfs_expand_msdfs vfs_shadow_copy charset_CP850 charset_CP437 auth_script vfs_readahead vfs_syncops vfs_ea_tdb" +default_shared_modules="vfs_recycle vfs_audit vfs_extd_audit vfs_full_audit vfs_netatalk vfs_fake_perms vfs_default_quota vfs_readonly vfs_cap vfs_expand_msdfs vfs_shadow_copy charset_CP850 charset_CP437 auth_script vfs_readahead vfs_syncops vfs_xattr_tdb" if test "x$developer" = xyes; then default_static_modules="$default_static_modules rpc_rpcecho" @@ -6489,7 +6489,7 @@ SMB_MODULE(vfs_cap, \$(VFS_CAP_OBJ), "bin/cap.$SHLIBEXT", VFS) SMB_MODULE(vfs_expand_msdfs, \$(VFS_EXPAND_MSDFS_OBJ), "bin/expand_msdfs.$SHLIBEXT", VFS) SMB_MODULE(vfs_shadow_copy, \$(VFS_SHADOW_COPY_OBJ), "bin/shadow_copy.$SHLIBEXT", VFS) SMB_MODULE(vfs_afsacl, \$(VFS_AFSACL_OBJ), "bin/afsacl.$SHLIBEXT", VFS) -SMB_MODULE(vfs_ea_tdb, \$(VFS_EA_TDB_OBJ), "bin/ea_tdb.$SHLIBEXT", VFS) +SMB_MODULE(vfs_xattr_tdb, \$(VFS_XATTR_TDB_OBJ), "bin/xattr_tdb.$SHLIBEXT", VFS) SMB_MODULE(vfs_posixacl, \$(VFS_POSIXACL_OBJ), "bin/posixacl.$SHLIBEXT", VFS) SMB_MODULE(vfs_aixacl, \$(VFS_AIXACL_OBJ), "bin/aixacl.$SHLIBEXT", VFS) SMB_MODULE(vfs_aixacl2, \$(VFS_AIXACL2_OBJ), "bin/aixacl2.$SHLIBEXT", VFS) diff --git a/source3/modules/vfs_ea_tdb.c b/source3/modules/vfs_ea_tdb.c deleted file mode 100644 index 8cf04d79ad..0000000000 --- a/source3/modules/vfs_ea_tdb.c +++ /dev/null @@ -1,736 +0,0 @@ -/* - * Store posix-level xattrs in a tdb - * - * Copyright (C) Volker Lendecke, 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 . - */ - -#include "includes.h" -#include "librpc/gen_ndr/xattr.h" -#include "librpc/gen_ndr/ndr_xattr.h" - -#undef DBGC_CLASS -#define DBGC_CLASS DBGC_VFS - -/* - * unmarshall tdb_xattrs - */ - -static NTSTATUS ea_tdb_pull_attrs(TALLOC_CTX *mem_ctx, - const TDB_DATA *data, - struct tdb_xattrs **presult) -{ - DATA_BLOB blob; - enum ndr_err_code ndr_err; - struct tdb_xattrs *result; - - if (!(result = TALLOC_ZERO_P(mem_ctx, struct tdb_xattrs))) { - return NT_STATUS_NO_MEMORY; - } - - if (data->dsize == 0) { - *presult = result; - return NT_STATUS_OK; - } - - blob = data_blob_const(data->dptr, data->dsize); - - ndr_err = ndr_pull_struct_blob( - &blob, result, result, - (ndr_pull_flags_fn_t)ndr_pull_tdb_xattrs); - - if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { - DEBUG(0, ("ndr_pull_tdb_xattrs failed: %s\n", - ndr_errstr(ndr_err))); - TALLOC_FREE(result); - return ndr_map_error2ntstatus(ndr_err);; - } - - *presult = result; - return NT_STATUS_OK; -} - -/* - * marshall tdb_xattrs - */ - -static NTSTATUS ea_tdb_push_attrs(TALLOC_CTX *mem_ctx, - const struct tdb_xattrs *attribs, - TDB_DATA *data) -{ - DATA_BLOB blob; - enum ndr_err_code ndr_err; - - ndr_err = ndr_push_struct_blob( - &blob, mem_ctx, attribs, - (ndr_push_flags_fn_t)ndr_push_tdb_xattrs); - - if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { - DEBUG(0, ("ndr_push_tdb_xattrs failed: %s\n", - ndr_errstr(ndr_err))); - return ndr_map_error2ntstatus(ndr_err);; - } - - *data = make_tdb_data(blob.data, blob.length); - return NT_STATUS_OK; -} - -/* - * Load tdb_xattrs for a file from the tdb - */ - -static NTSTATUS ea_tdb_load_attrs(TALLOC_CTX *mem_ctx, - struct db_context *db_ctx, - const struct file_id *id, - struct tdb_xattrs **presult) -{ - uint8 id_buf[16]; - NTSTATUS status; - TDB_DATA data; - - push_file_id_16((char *)id_buf, id); - - if (db_ctx->fetch(db_ctx, mem_ctx, - make_tdb_data(id_buf, sizeof(id_buf)), - &data) == -1) { - return NT_STATUS_INTERNAL_DB_CORRUPTION; - } - - status = ea_tdb_pull_attrs(mem_ctx, &data, presult); - TALLOC_FREE(data.dptr); - return NT_STATUS_OK; -} - -/* - * fetch_lock the tdb_ea record for a file - */ - -static struct db_record *ea_tdb_lock_attrs(TALLOC_CTX *mem_ctx, - struct db_context *db_ctx, - const struct file_id *id) -{ - uint8 id_buf[16]; - push_file_id_16((char *)id_buf, id); - return db_ctx->fetch_locked(db_ctx, mem_ctx, - make_tdb_data(id_buf, sizeof(id_buf))); -} - -/* - * Save tdb_xattrs to a previously fetch_locked record - */ - -static NTSTATUS ea_tdb_save_attrs(struct db_record *rec, - const struct tdb_xattrs *attribs) -{ - TDB_DATA data; - NTSTATUS status; - - status = ea_tdb_push_attrs(talloc_tos(), attribs, &data); - - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("ea_tdb_push_attrs failed: %s\n", - nt_errstr(status))); - return status; - } - - status = rec->store(rec, data, 0); - - TALLOC_FREE(data.dptr); - - return status; -} - -/* - * Worker routine for getxattr and fgetxattr - */ - -static ssize_t ea_tdb_getattr(struct db_context *db_ctx, - const struct file_id *id, - const char *name, void *value, size_t size) -{ - struct tdb_xattrs *attribs; - uint32_t i; - ssize_t result = -1; - NTSTATUS status; - - status = ea_tdb_load_attrs(talloc_tos(), db_ctx, id, &attribs); - - if (!NT_STATUS_IS_OK(status)) { - DEBUG(10, ("ea_tdb_fetch_attrs failed: %s\n", - nt_errstr(status))); - errno = EINVAL; - return -1; - } - - for (i=0; inum_xattrs; i++) { - if (strcmp(attribs->xattrs[i].name, name) == 0) { - break; - } - } - - if (i == attribs->num_xattrs) { - errno = ENOATTR; - goto fail; - } - - if (attribs->xattrs[i].value.length > size) { - errno = ERANGE; - goto fail; - } - - memcpy(value, attribs->xattrs[i].value.data, - attribs->xattrs[i].value.length); - result = attribs->xattrs[i].value.length; - - fail: - TALLOC_FREE(attribs); - return result; -} - -static ssize_t ea_tdb_getxattr(struct vfs_handle_struct *handle, - const char *path, const char *name, - void *value, size_t size) -{ - SMB_STRUCT_STAT sbuf; - struct file_id id; - struct db_context *db; - - SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1); - - if (SMB_VFS_STAT(handle->conn, path, &sbuf) == -1) { - return -1; - } - - id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino); - - return ea_tdb_getattr(db, &id, name, value, size); -} - -static ssize_t ea_tdb_fgetxattr(struct vfs_handle_struct *handle, - struct files_struct *fsp, - const char *name, void *value, size_t size) -{ - SMB_STRUCT_STAT sbuf; - struct file_id id; - struct db_context *db; - - SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1); - - if (SMB_VFS_FSTAT(fsp, &sbuf) == -1) { - return -1; - } - - id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino); - - return ea_tdb_getattr(db, &id, name, value, size); -} - -/* - * Worker routine for setxattr and fsetxattr - */ - -static int ea_tdb_setattr(struct db_context *db_ctx, - const struct file_id *id, const char *name, - const void *value, size_t size, int flags) -{ - NTSTATUS status; - struct db_record *rec; - struct tdb_xattrs *attribs; - uint32_t i; - - rec = ea_tdb_lock_attrs(talloc_tos(), db_ctx, id); - - if (rec == NULL) { - DEBUG(0, ("ea_tdb_lock_attrs failed\n")); - errno = EINVAL; - return -1; - } - - status = ea_tdb_pull_attrs(rec, &rec->value, &attribs); - - if (!NT_STATUS_IS_OK(status)) { - DEBUG(10, ("ea_tdb_fetch_attrs failed: %s\n", - nt_errstr(status))); - TALLOC_FREE(rec); - return -1; - } - - for (i=0; inum_xattrs; i++) { - if (strcmp(attribs->xattrs[i].name, name) == 0) { - break; - } - } - - if (i == attribs->num_xattrs) { - struct tdb_xattr *tmp; - - tmp = TALLOC_REALLOC_ARRAY( - attribs, attribs->xattrs, struct tdb_xattr, - attribs->num_xattrs + 1); - - if (tmp == NULL) { - DEBUG(0, ("TALLOC_REALLOC_ARRAY failed\n")); - TALLOC_FREE(rec); - errno = ENOMEM; - return -1; - } - - attribs->xattrs = tmp; - attribs->num_xattrs += 1; - } - - attribs->xattrs[i].name = name; - attribs->xattrs[i].value.data = CONST_DISCARD(uint8 *, value); - attribs->xattrs[i].value.length = size; - - status = ea_tdb_save_attrs(rec, attribs); - - TALLOC_FREE(rec); - - if (!NT_STATUS_IS_OK(status)) { - DEBUG(1, ("save failed: %s\n", nt_errstr(status))); - return -1; - } - - return 0; -} - -static int ea_tdb_setxattr(struct vfs_handle_struct *handle, - const char *path, const char *name, - const void *value, size_t size, int flags) -{ - SMB_STRUCT_STAT sbuf; - struct file_id id; - struct db_context *db; - - SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1); - - if (SMB_VFS_STAT(handle->conn, path, &sbuf) == -1) { - return -1; - } - - id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino); - - return ea_tdb_setattr(db, &id, name, value, size, flags); -} - -static int ea_tdb_fsetxattr(struct vfs_handle_struct *handle, - struct files_struct *fsp, - const char *name, const void *value, - size_t size, int flags) -{ - SMB_STRUCT_STAT sbuf; - struct file_id id; - struct db_context *db; - - SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1); - - if (SMB_VFS_FSTAT(fsp, &sbuf) == -1) { - return -1; - } - - id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino); - - return ea_tdb_setattr(db, &id, name, value, size, flags); -} - -/* - * Worker routine for listxattr and flistxattr - */ - -static ssize_t ea_tdb_listattr(struct db_context *db_ctx, - const struct file_id *id, char *list, - size_t size) -{ - NTSTATUS status; - struct tdb_xattrs *attribs; - uint32_t i; - size_t len = 0; - - status = ea_tdb_load_attrs(talloc_tos(), db_ctx, id, &attribs); - - if (!NT_STATUS_IS_OK(status)) { - DEBUG(10, ("ea_tdb_fetch_attrs failed: %s\n", - nt_errstr(status))); - errno = EINVAL; - return -1; - } - - DEBUG(10, ("ea_tdb_listattr: Found %d xattrs\n", attribs->num_xattrs)); - - for (i=0; inum_xattrs; i++) { - size_t tmp; - - DEBUG(10, ("ea_tdb_listattr: xattrs[i].name: %s\n", - attribs->xattrs[i].name)); - - tmp = strlen(attribs->xattrs[i].name); - - /* - * Try to protect against overflow - */ - - if (len + (tmp+1) < len) { - TALLOC_FREE(attribs); - errno = EINVAL; - return -1; - } - - /* - * Take care of the terminating NULL - */ - len += (tmp + 1); - } - - if (len > size) { - TALLOC_FREE(attribs); - errno = ERANGE; - return -1; - } - - len = 0; - - for (i=0; inum_xattrs; i++) { - strlcpy(list+len, attribs->xattrs[i].name, - size-len); - len += (strlen(attribs->xattrs[i].name) + 1); - } - - TALLOC_FREE(attribs); - return len; -} - -static ssize_t ea_tdb_listxattr(struct vfs_handle_struct *handle, - const char *path, char *list, size_t size) -{ - SMB_STRUCT_STAT sbuf; - struct file_id id; - struct db_context *db; - - SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1); - - if (SMB_VFS_STAT(handle->conn, path, &sbuf) == -1) { - return -1; - } - - id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino); - - return ea_tdb_listattr(db, &id, list, size); -} - -static ssize_t ea_tdb_flistxattr(struct vfs_handle_struct *handle, - struct files_struct *fsp, char *list, - size_t size) -{ - SMB_STRUCT_STAT sbuf; - struct file_id id; - struct db_context *db; - - SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1); - - if (SMB_VFS_FSTAT(fsp, &sbuf) == -1) { - return -1; - } - - id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino); - - return ea_tdb_listattr(db, &id, list, size); -} - -/* - * Worker routine for removexattr and fremovexattr - */ - -static int ea_tdb_removeattr(struct db_context *db_ctx, - const struct file_id *id, const char *name) -{ - NTSTATUS status; - struct db_record *rec; - struct tdb_xattrs *attribs; - uint32_t i; - - rec = ea_tdb_lock_attrs(talloc_tos(), db_ctx, id); - - if (rec == NULL) { - DEBUG(0, ("ea_tdb_lock_attrs failed\n")); - errno = EINVAL; - return -1; - } - - status = ea_tdb_pull_attrs(rec, &rec->value, &attribs); - - if (!NT_STATUS_IS_OK(status)) { - DEBUG(10, ("ea_tdb_fetch_attrs failed: %s\n", - nt_errstr(status))); - TALLOC_FREE(rec); - return -1; - } - - for (i=0; inum_xattrs; i++) { - if (strcmp(attribs->xattrs[i].name, name) == 0) { - break; - } - } - - if (i == attribs->num_xattrs) { - TALLOC_FREE(rec); - errno = ENOATTR; - return -1; - } - - attribs->xattrs[i] = - attribs->xattrs[attribs->num_xattrs-1]; - attribs->num_xattrs -= 1; - - if (attribs->num_xattrs == 0) { - rec->delete_rec(rec); - TALLOC_FREE(rec); - return 0; - } - - status = ea_tdb_save_attrs(rec, attribs); - - TALLOC_FREE(rec); - - if (!NT_STATUS_IS_OK(status)) { - DEBUG(1, ("save failed: %s\n", nt_errstr(status))); - return -1; - } - - return 0; -} - -static int ea_tdb_removexattr(struct vfs_handle_struct *handle, - const char *path, const char *name) -{ - SMB_STRUCT_STAT sbuf; - struct file_id id; - struct db_context *db; - - SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1); - - if (SMB_VFS_STAT(handle->conn, path, &sbuf) == -1) { - return -1; - } - - id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino); - - return ea_tdb_removeattr(db, &id, name); -} - -static int ea_tdb_fremovexattr(struct vfs_handle_struct *handle, - struct files_struct *fsp, const char *name) -{ - SMB_STRUCT_STAT sbuf; - struct file_id id; - struct db_context *db; - - SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1); - - if (SMB_VFS_FSTAT(fsp, &sbuf) == -1) { - return -1; - } - - id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino); - - return ea_tdb_removeattr(db, &id, name); -} - -/* - * Open the tdb file upon VFS_CONNECT - */ - -static bool ea_tdb_init(int snum, struct db_context **p_db) -{ - struct db_context *db; - const char *dbname; - - dbname = lp_parm_const_string(snum, "ea", "tdb", lock_path("eas.tdb")); - - if (dbname == NULL) { - errno = ENOTSUP; - return false; - } - - become_root(); - db = db_open(NULL, dbname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600); - unbecome_root(); - - if (db == NULL) { - errno = ENOTSUP; - return false; - } - - *p_db = db; - return true; -} - -/* - * On unlink we need to delete the tdb record - */ -static int ea_tdb_unlink(vfs_handle_struct *handle, const char *path) -{ - SMB_STRUCT_STAT sbuf; - struct file_id id; - struct db_context *db; - struct db_record *rec; - int ret; - - SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1); - - if (SMB_VFS_STAT(handle->conn, path, &sbuf) == -1) { - return -1; - } - - ret = SMB_VFS_NEXT_UNLINK(handle, path); - - if (ret == -1) { - return -1; - } - - id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino); - - rec = ea_tdb_lock_attrs(talloc_tos(), db, &id); - - /* - * If rec == NULL there's not much we can do about it - */ - - if (rec != NULL) { - rec->delete_rec(rec); - TALLOC_FREE(rec); - } - - return 0; -} - -/* - * On rmdir we need to delete the tdb record - */ -static int ea_tdb_rmdir(vfs_handle_struct *handle, const char *path) -{ - SMB_STRUCT_STAT sbuf; - struct file_id id; - struct db_context *db; - struct db_record *rec; - int ret; - - SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1); - - if (SMB_VFS_STAT(handle->conn, path, &sbuf) == -1) { - return -1; - } - - ret = SMB_VFS_NEXT_RMDIR(handle, path); - - if (ret == -1) { - return -1; - } - - id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino); - - rec = ea_tdb_lock_attrs(talloc_tos(), db, &id); - - /* - * If rec == NULL there's not much we can do about it - */ - - if (rec != NULL) { - rec->delete_rec(rec); - TALLOC_FREE(rec); - } - - return 0; -} - -/* - * Destructor for the VFS private data - */ - -static void close_ea_db(void **data) -{ - struct db_context **p_db = (struct db_context **)data; - TALLOC_FREE(*p_db); -} - -static int ea_tdb_connect(vfs_handle_struct *handle, const char *service, - const char *user) -{ - fstring sname; - int res, snum; - struct db_context *db; - - res = SMB_VFS_NEXT_CONNECT(handle, service, user); - if (res < 0) { - return res; - } - - fstrcpy(sname, service); - snum = find_service(sname); - if (snum == -1) { - /* - * Should not happen, but we should not fail just *here*. - */ - return 0; - } - - if (!ea_tdb_init(snum, &db)) { - DEBUG(5, ("Could not init ea tdb\n")); - lp_do_parameter(snum, "ea support", "False"); - return 0; - } - - lp_do_parameter(snum, "ea support", "True"); - - SMB_VFS_HANDLE_SET_DATA(handle, db, close_ea_db, - struct db_context, return -1); - - return 0; -} - -/* VFS operations structure */ - -static const vfs_op_tuple ea_tdb_ops[] = { - {SMB_VFS_OP(ea_tdb_getxattr), SMB_VFS_OP_GETXATTR, - SMB_VFS_LAYER_TRANSPARENT}, - {SMB_VFS_OP(ea_tdb_fgetxattr), SMB_VFS_OP_FGETXATTR, - SMB_VFS_LAYER_TRANSPARENT}, - {SMB_VFS_OP(ea_tdb_setxattr), SMB_VFS_OP_SETXATTR, - SMB_VFS_LAYER_TRANSPARENT}, - {SMB_VFS_OP(ea_tdb_fsetxattr), SMB_VFS_OP_FSETXATTR, - SMB_VFS_LAYER_TRANSPARENT}, - {SMB_VFS_OP(ea_tdb_listxattr), SMB_VFS_OP_LISTXATTR, - SMB_VFS_LAYER_TRANSPARENT}, - {SMB_VFS_OP(ea_tdb_flistxattr), SMB_VFS_OP_FLISTXATTR, - SMB_VFS_LAYER_TRANSPARENT}, - {SMB_VFS_OP(ea_tdb_removexattr), SMB_VFS_OP_REMOVEXATTR, - SMB_VFS_LAYER_TRANSPARENT}, - {SMB_VFS_OP(ea_tdb_fremovexattr), SMB_VFS_OP_FREMOVEXATTR, - SMB_VFS_LAYER_TRANSPARENT}, - {SMB_VFS_OP(ea_tdb_unlink), SMB_VFS_OP_UNLINK, - SMB_VFS_LAYER_TRANSPARENT}, - {SMB_VFS_OP(ea_tdb_rmdir), SMB_VFS_OP_RMDIR, - SMB_VFS_LAYER_TRANSPARENT}, - {SMB_VFS_OP(ea_tdb_connect), SMB_VFS_OP_CONNECT, - SMB_VFS_LAYER_TRANSPARENT}, - {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} -}; - -NTSTATUS vfs_ea_tdb_init(void); -NTSTATUS vfs_ea_tdb_init(void) -{ - return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "ea_tdb", - ea_tdb_ops); -} diff --git a/source3/modules/vfs_xattr_tdb.c b/source3/modules/vfs_xattr_tdb.c new file mode 100644 index 0000000000..8cf04d79ad --- /dev/null +++ b/source3/modules/vfs_xattr_tdb.c @@ -0,0 +1,736 @@ +/* + * Store posix-level xattrs in a tdb + * + * Copyright (C) Volker Lendecke, 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 . + */ + +#include "includes.h" +#include "librpc/gen_ndr/xattr.h" +#include "librpc/gen_ndr/ndr_xattr.h" + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_VFS + +/* + * unmarshall tdb_xattrs + */ + +static NTSTATUS ea_tdb_pull_attrs(TALLOC_CTX *mem_ctx, + const TDB_DATA *data, + struct tdb_xattrs **presult) +{ + DATA_BLOB blob; + enum ndr_err_code ndr_err; + struct tdb_xattrs *result; + + if (!(result = TALLOC_ZERO_P(mem_ctx, struct tdb_xattrs))) { + return NT_STATUS_NO_MEMORY; + } + + if (data->dsize == 0) { + *presult = result; + return NT_STATUS_OK; + } + + blob = data_blob_const(data->dptr, data->dsize); + + ndr_err = ndr_pull_struct_blob( + &blob, result, result, + (ndr_pull_flags_fn_t)ndr_pull_tdb_xattrs); + + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { + DEBUG(0, ("ndr_pull_tdb_xattrs failed: %s\n", + ndr_errstr(ndr_err))); + TALLOC_FREE(result); + return ndr_map_error2ntstatus(ndr_err);; + } + + *presult = result; + return NT_STATUS_OK; +} + +/* + * marshall tdb_xattrs + */ + +static NTSTATUS ea_tdb_push_attrs(TALLOC_CTX *mem_ctx, + const struct tdb_xattrs *attribs, + TDB_DATA *data) +{ + DATA_BLOB blob; + enum ndr_err_code ndr_err; + + ndr_err = ndr_push_struct_blob( + &blob, mem_ctx, attribs, + (ndr_push_flags_fn_t)ndr_push_tdb_xattrs); + + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { + DEBUG(0, ("ndr_push_tdb_xattrs failed: %s\n", + ndr_errstr(ndr_err))); + return ndr_map_error2ntstatus(ndr_err);; + } + + *data = make_tdb_data(blob.data, blob.length); + return NT_STATUS_OK; +} + +/* + * Load tdb_xattrs for a file from the tdb + */ + +static NTSTATUS ea_tdb_load_attrs(TALLOC_CTX *mem_ctx, + struct db_context *db_ctx, + const struct file_id *id, + struct tdb_xattrs **presult) +{ + uint8 id_buf[16]; + NTSTATUS status; + TDB_DATA data; + + push_file_id_16((char *)id_buf, id); + + if (db_ctx->fetch(db_ctx, mem_ctx, + make_tdb_data(id_buf, sizeof(id_buf)), + &data) == -1) { + return NT_STATUS_INTERNAL_DB_CORRUPTION; + } + + status = ea_tdb_pull_attrs(mem_ctx, &data, presult); + TALLOC_FREE(data.dptr); + return NT_STATUS_OK; +} + +/* + * fetch_lock the tdb_ea record for a file + */ + +static struct db_record *ea_tdb_lock_attrs(TALLOC_CTX *mem_ctx, + struct db_context *db_ctx, + const struct file_id *id) +{ + uint8 id_buf[16]; + push_file_id_16((char *)id_buf, id); + return db_ctx->fetch_locked(db_ctx, mem_ctx, + make_tdb_data(id_buf, sizeof(id_buf))); +} + +/* + * Save tdb_xattrs to a previously fetch_locked record + */ + +static NTSTATUS ea_tdb_save_attrs(struct db_record *rec, + const struct tdb_xattrs *attribs) +{ + TDB_DATA data; + NTSTATUS status; + + status = ea_tdb_push_attrs(talloc_tos(), attribs, &data); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("ea_tdb_push_attrs failed: %s\n", + nt_errstr(status))); + return status; + } + + status = rec->store(rec, data, 0); + + TALLOC_FREE(data.dptr); + + return status; +} + +/* + * Worker routine for getxattr and fgetxattr + */ + +static ssize_t ea_tdb_getattr(struct db_context *db_ctx, + const struct file_id *id, + const char *name, void *value, size_t size) +{ + struct tdb_xattrs *attribs; + uint32_t i; + ssize_t result = -1; + NTSTATUS status; + + status = ea_tdb_load_attrs(talloc_tos(), db_ctx, id, &attribs); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(10, ("ea_tdb_fetch_attrs failed: %s\n", + nt_errstr(status))); + errno = EINVAL; + return -1; + } + + for (i=0; inum_xattrs; i++) { + if (strcmp(attribs->xattrs[i].name, name) == 0) { + break; + } + } + + if (i == attribs->num_xattrs) { + errno = ENOATTR; + goto fail; + } + + if (attribs->xattrs[i].value.length > size) { + errno = ERANGE; + goto fail; + } + + memcpy(value, attribs->xattrs[i].value.data, + attribs->xattrs[i].value.length); + result = attribs->xattrs[i].value.length; + + fail: + TALLOC_FREE(attribs); + return result; +} + +static ssize_t ea_tdb_getxattr(struct vfs_handle_struct *handle, + const char *path, const char *name, + void *value, size_t size) +{ + SMB_STRUCT_STAT sbuf; + struct file_id id; + struct db_context *db; + + SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1); + + if (SMB_VFS_STAT(handle->conn, path, &sbuf) == -1) { + return -1; + } + + id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino); + + return ea_tdb_getattr(db, &id, name, value, size); +} + +static ssize_t ea_tdb_fgetxattr(struct vfs_handle_struct *handle, + struct files_struct *fsp, + const char *name, void *value, size_t size) +{ + SMB_STRUCT_STAT sbuf; + struct file_id id; + struct db_context *db; + + SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1); + + if (SMB_VFS_FSTAT(fsp, &sbuf) == -1) { + return -1; + } + + id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino); + + return ea_tdb_getattr(db, &id, name, value, size); +} + +/* + * Worker routine for setxattr and fsetxattr + */ + +static int ea_tdb_setattr(struct db_context *db_ctx, + const struct file_id *id, const char *name, + const void *value, size_t size, int flags) +{ + NTSTATUS status; + struct db_record *rec; + struct tdb_xattrs *attribs; + uint32_t i; + + rec = ea_tdb_lock_attrs(talloc_tos(), db_ctx, id); + + if (rec == NULL) { + DEBUG(0, ("ea_tdb_lock_attrs failed\n")); + errno = EINVAL; + return -1; + } + + status = ea_tdb_pull_attrs(rec, &rec->value, &attribs); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(10, ("ea_tdb_fetch_attrs failed: %s\n", + nt_errstr(status))); + TALLOC_FREE(rec); + return -1; + } + + for (i=0; inum_xattrs; i++) { + if (strcmp(attribs->xattrs[i].name, name) == 0) { + break; + } + } + + if (i == attribs->num_xattrs) { + struct tdb_xattr *tmp; + + tmp = TALLOC_REALLOC_ARRAY( + attribs, attribs->xattrs, struct tdb_xattr, + attribs->num_xattrs + 1); + + if (tmp == NULL) { + DEBUG(0, ("TALLOC_REALLOC_ARRAY failed\n")); + TALLOC_FREE(rec); + errno = ENOMEM; + return -1; + } + + attribs->xattrs = tmp; + attribs->num_xattrs += 1; + } + + attribs->xattrs[i].name = name; + attribs->xattrs[i].value.data = CONST_DISCARD(uint8 *, value); + attribs->xattrs[i].value.length = size; + + status = ea_tdb_save_attrs(rec, attribs); + + TALLOC_FREE(rec); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(1, ("save failed: %s\n", nt_errstr(status))); + return -1; + } + + return 0; +} + +static int ea_tdb_setxattr(struct vfs_handle_struct *handle, + const char *path, const char *name, + const void *value, size_t size, int flags) +{ + SMB_STRUCT_STAT sbuf; + struct file_id id; + struct db_context *db; + + SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1); + + if (SMB_VFS_STAT(handle->conn, path, &sbuf) == -1) { + return -1; + } + + id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino); + + return ea_tdb_setattr(db, &id, name, value, size, flags); +} + +static int ea_tdb_fsetxattr(struct vfs_handle_struct *handle, + struct files_struct *fsp, + const char *name, const void *value, + size_t size, int flags) +{ + SMB_STRUCT_STAT sbuf; + struct file_id id; + struct db_context *db; + + SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1); + + if (SMB_VFS_FSTAT(fsp, &sbuf) == -1) { + return -1; + } + + id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino); + + return ea_tdb_setattr(db, &id, name, value, size, flags); +} + +/* + * Worker routine for listxattr and flistxattr + */ + +static ssize_t ea_tdb_listattr(struct db_context *db_ctx, + const struct file_id *id, char *list, + size_t size) +{ + NTSTATUS status; + struct tdb_xattrs *attribs; + uint32_t i; + size_t len = 0; + + status = ea_tdb_load_attrs(talloc_tos(), db_ctx, id, &attribs); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(10, ("ea_tdb_fetch_attrs failed: %s\n", + nt_errstr(status))); + errno = EINVAL; + return -1; + } + + DEBUG(10, ("ea_tdb_listattr: Found %d xattrs\n", attribs->num_xattrs)); + + for (i=0; inum_xattrs; i++) { + size_t tmp; + + DEBUG(10, ("ea_tdb_listattr: xattrs[i].name: %s\n", + attribs->xattrs[i].name)); + + tmp = strlen(attribs->xattrs[i].name); + + /* + * Try to protect against overflow + */ + + if (len + (tmp+1) < len) { + TALLOC_FREE(attribs); + errno = EINVAL; + return -1; + } + + /* + * Take care of the terminating NULL + */ + len += (tmp + 1); + } + + if (len > size) { + TALLOC_FREE(attribs); + errno = ERANGE; + return -1; + } + + len = 0; + + for (i=0; inum_xattrs; i++) { + strlcpy(list+len, attribs->xattrs[i].name, + size-len); + len += (strlen(attribs->xattrs[i].name) + 1); + } + + TALLOC_FREE(attribs); + return len; +} + +static ssize_t ea_tdb_listxattr(struct vfs_handle_struct *handle, + const char *path, char *list, size_t size) +{ + SMB_STRUCT_STAT sbuf; + struct file_id id; + struct db_context *db; + + SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1); + + if (SMB_VFS_STAT(handle->conn, path, &sbuf) == -1) { + return -1; + } + + id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino); + + return ea_tdb_listattr(db, &id, list, size); +} + +static ssize_t ea_tdb_flistxattr(struct vfs_handle_struct *handle, + struct files_struct *fsp, char *list, + size_t size) +{ + SMB_STRUCT_STAT sbuf; + struct file_id id; + struct db_context *db; + + SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1); + + if (SMB_VFS_FSTAT(fsp, &sbuf) == -1) { + return -1; + } + + id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino); + + return ea_tdb_listattr(db, &id, list, size); +} + +/* + * Worker routine for removexattr and fremovexattr + */ + +static int ea_tdb_removeattr(struct db_context *db_ctx, + const struct file_id *id, const char *name) +{ + NTSTATUS status; + struct db_record *rec; + struct tdb_xattrs *attribs; + uint32_t i; + + rec = ea_tdb_lock_attrs(talloc_tos(), db_ctx, id); + + if (rec == NULL) { + DEBUG(0, ("ea_tdb_lock_attrs failed\n")); + errno = EINVAL; + return -1; + } + + status = ea_tdb_pull_attrs(rec, &rec->value, &attribs); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(10, ("ea_tdb_fetch_attrs failed: %s\n", + nt_errstr(status))); + TALLOC_FREE(rec); + return -1; + } + + for (i=0; inum_xattrs; i++) { + if (strcmp(attribs->xattrs[i].name, name) == 0) { + break; + } + } + + if (i == attribs->num_xattrs) { + TALLOC_FREE(rec); + errno = ENOATTR; + return -1; + } + + attribs->xattrs[i] = + attribs->xattrs[attribs->num_xattrs-1]; + attribs->num_xattrs -= 1; + + if (attribs->num_xattrs == 0) { + rec->delete_rec(rec); + TALLOC_FREE(rec); + return 0; + } + + status = ea_tdb_save_attrs(rec, attribs); + + TALLOC_FREE(rec); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(1, ("save failed: %s\n", nt_errstr(status))); + return -1; + } + + return 0; +} + +static int ea_tdb_removexattr(struct vfs_handle_struct *handle, + const char *path, const char *name) +{ + SMB_STRUCT_STAT sbuf; + struct file_id id; + struct db_context *db; + + SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1); + + if (SMB_VFS_STAT(handle->conn, path, &sbuf) == -1) { + return -1; + } + + id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino); + + return ea_tdb_removeattr(db, &id, name); +} + +static int ea_tdb_fremovexattr(struct vfs_handle_struct *handle, + struct files_struct *fsp, const char *name) +{ + SMB_STRUCT_STAT sbuf; + struct file_id id; + struct db_context *db; + + SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1); + + if (SMB_VFS_FSTAT(fsp, &sbuf) == -1) { + return -1; + } + + id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino); + + return ea_tdb_removeattr(db, &id, name); +} + +/* + * Open the tdb file upon VFS_CONNECT + */ + +static bool ea_tdb_init(int snum, struct db_context **p_db) +{ + struct db_context *db; + const char *dbname; + + dbname = lp_parm_const_string(snum, "ea", "tdb", lock_path("eas.tdb")); + + if (dbname == NULL) { + errno = ENOTSUP; + return false; + } + + become_root(); + db = db_open(NULL, dbname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600); + unbecome_root(); + + if (db == NULL) { + errno = ENOTSUP; + return false; + } + + *p_db = db; + return true; +} + +/* + * On unlink we need to delete the tdb record + */ +static int ea_tdb_unlink(vfs_handle_struct *handle, const char *path) +{ + SMB_STRUCT_STAT sbuf; + struct file_id id; + struct db_context *db; + struct db_record *rec; + int ret; + + SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1); + + if (SMB_VFS_STAT(handle->conn, path, &sbuf) == -1) { + return -1; + } + + ret = SMB_VFS_NEXT_UNLINK(handle, path); + + if (ret == -1) { + return -1; + } + + id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino); + + rec = ea_tdb_lock_attrs(talloc_tos(), db, &id); + + /* + * If rec == NULL there's not much we can do about it + */ + + if (rec != NULL) { + rec->delete_rec(rec); + TALLOC_FREE(rec); + } + + return 0; +} + +/* + * On rmdir we need to delete the tdb record + */ +static int ea_tdb_rmdir(vfs_handle_struct *handle, const char *path) +{ + SMB_STRUCT_STAT sbuf; + struct file_id id; + struct db_context *db; + struct db_record *rec; + int ret; + + SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1); + + if (SMB_VFS_STAT(handle->conn, path, &sbuf) == -1) { + return -1; + } + + ret = SMB_VFS_NEXT_RMDIR(handle, path); + + if (ret == -1) { + return -1; + } + + id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino); + + rec = ea_tdb_lock_attrs(talloc_tos(), db, &id); + + /* + * If rec == NULL there's not much we can do about it + */ + + if (rec != NULL) { + rec->delete_rec(rec); + TALLOC_FREE(rec); + } + + return 0; +} + +/* + * Destructor for the VFS private data + */ + +static void close_ea_db(void **data) +{ + struct db_context **p_db = (struct db_context **)data; + TALLOC_FREE(*p_db); +} + +static int ea_tdb_connect(vfs_handle_struct *handle, const char *service, + const char *user) +{ + fstring sname; + int res, snum; + struct db_context *db; + + res = SMB_VFS_NEXT_CONNECT(handle, service, user); + if (res < 0) { + return res; + } + + fstrcpy(sname, service); + snum = find_service(sname); + if (snum == -1) { + /* + * Should not happen, but we should not fail just *here*. + */ + return 0; + } + + if (!ea_tdb_init(snum, &db)) { + DEBUG(5, ("Could not init ea tdb\n")); + lp_do_parameter(snum, "ea support", "False"); + return 0; + } + + lp_do_parameter(snum, "ea support", "True"); + + SMB_VFS_HANDLE_SET_DATA(handle, db, close_ea_db, + struct db_context, return -1); + + return 0; +} + +/* VFS operations structure */ + +static const vfs_op_tuple ea_tdb_ops[] = { + {SMB_VFS_OP(ea_tdb_getxattr), SMB_VFS_OP_GETXATTR, + SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(ea_tdb_fgetxattr), SMB_VFS_OP_FGETXATTR, + SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(ea_tdb_setxattr), SMB_VFS_OP_SETXATTR, + SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(ea_tdb_fsetxattr), SMB_VFS_OP_FSETXATTR, + SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(ea_tdb_listxattr), SMB_VFS_OP_LISTXATTR, + SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(ea_tdb_flistxattr), SMB_VFS_OP_FLISTXATTR, + SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(ea_tdb_removexattr), SMB_VFS_OP_REMOVEXATTR, + SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(ea_tdb_fremovexattr), SMB_VFS_OP_FREMOVEXATTR, + SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(ea_tdb_unlink), SMB_VFS_OP_UNLINK, + SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(ea_tdb_rmdir), SMB_VFS_OP_RMDIR, + SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(ea_tdb_connect), SMB_VFS_OP_CONNECT, + SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} +}; + +NTSTATUS vfs_ea_tdb_init(void); +NTSTATUS vfs_ea_tdb_init(void) +{ + return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "ea_tdb", + ea_tdb_ops); +} diff --git a/source3/script/tests/selftest.sh b/source3/script/tests/selftest.sh index 08bfdf601c..5a170b2117 100755 --- a/source3/script/tests/selftest.sh +++ b/source3/script/tests/selftest.sh @@ -186,7 +186,7 @@ cat >$SERVERCONFFILE<