diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 17:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 17:47:29 +0000 |
commit | 4f5791ebd03eaec1c7da0865a383175b05102712 (patch) | |
tree | 8ce7b00f7a76baa386372422adebbe64510812d4 /source3/include | |
parent | Initial commit. (diff) | |
download | samba-upstream.tar.xz samba-upstream.zip |
Adding upstream version 2:4.17.12+dfsg.upstream/2%4.17.12+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
59 files changed, 15944 insertions, 0 deletions
diff --git a/source3/include/MacExtensions.h b/source3/include/MacExtensions.h new file mode 100644 index 0000000..0d98df7 --- /dev/null +++ b/source3/include/MacExtensions.h @@ -0,0 +1,255 @@ +/* + Unix SMB/CIFS implementation. + SMB parameters and setup + Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) John H Terpstra 1996-1998 + Copyright (C) Luke Kenneth Casson Leighton 1996-1998 + Copyright (C) Paul Ashton 1998 + + 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/>. +*/ +#ifndef _MAC_EXTENSIONS_H +#define _MAC_EXTENSIONS_H + +/* Folder that holds the stream info */ +#define STREAM_FOLDER ".streams" +#define STREAM_FOLDER_SLASH ".streams/" + +/* Common Streams Names*/ +#define DefaultStreamTestLen 6 +#define DefaultStreamTest ":$DATA" +#define AFPDATA_STREAM "::$DATA" + +#define AFPINFO_STREAM_NAME ":AFP_AfpInfo" +#define AFPRESOURCE_STREAM_NAME ":AFP_Resource" +#define AFPCOMMENTS_STREAM_NAME ":Comments" +#define AFPDESKTOP_STREAM_NAME ":AFP_DeskTop" +#define AFPIDINDEX_STREAM_NAME ":AFP_IdIndex" + +#define AFPINFO_STREAM AFPINFO_STREAM_NAME ":$DATA" +#define AFPRESOURCE_STREAM AFPRESOURCE_STREAM_NAME ":$DATA" +#define AFPCOMMENTS_STREAM AFPCOMMENTS_STREAM_NAME ":$DATA" +#define AFPDESKTOP_STREAM AFPDESKTOP_STREAM_NAME ":$DATA" +#define AFPIDINDEX_STREAM AFPIDINDEX_STREAM_NAME ":$DATA" + +/* +** NT's AFP_AfpInfo stream structure +*/ +#define AFP_INFO_SIZE 0x3c +#define AFP_Signature 0x41465000 +#define AFP_Version 0x00000100 +#define AFP_BackupTime 0x80000000 +#define AFP_FinderSize 32 + +#define AFP_OFF_FinderInfo 16 + +/* +** Original AFP_AfpInfo stream used by NT +** We needed a way to store the create date so SAMBA +** AFP_AfpInfo adds for bytes to this structrure +** and call's it _SambaAfpInfo +*/ +typedef struct _AfpInfo +{ + uint32_t afpi_Signature; /* Must be *(PDWORD)"AFP" */ + uint32_t afpi_Version; /* Must be 0x00010000 */ + uint32_t afpi_Reserved1; + uint32_t afpi_BackupTime; /* Backup time for the file/dir */ + unsigned char afpi_FinderInfo[AFP_FinderSize]; /* Finder Info (32 bytes) */ + unsigned char afpi_ProDosInfo[6]; /* ProDos Info (6 bytes) # */ + unsigned char afpi_Reserved2[6]; +} AfpInfo; + +typedef struct _SambaAfpInfo +{ + AfpInfo afp; + unsigned long createtime; +} SambaAfpInfo; + +/* +** On SAMBA this structure is followed by 4 bytes that store the create +** date of the file or folder asociated with it. +*/ + +/* +** These extensions are only supported with the NT LM 0.12 Dialect. These extensions +** will be process on a share by share bases. +*/ + +/* +** Trans2_Query_FS_Information Call is used by the MacCIFS extensions for three reasons. +** First to see if the remote server share supports the basic Macintosh CIFS extensions. +** Second to return some basic need information about the share to the Macintosh. +** Third to see if this share support any other Macintosh extensions. +** +** We will be using information levels that are between 0x300 and 0x399 for all Macintosh +** extensions calls. The first of these will be the SMB_MAC_QUERY_FS_INFO level which +** will allow the server to return the MacQueryFSInfo structure. All fields are Little +** Endian unless otherwise specified. +*/ +#define SMB_MAC_QUERY_FS_INFO 0x301 + + + +/* +** The server will return folder access control in the Trans2_Find_First2 +** and Trans2_Find_Next2 message described later in this document. +*/ +#define SUPPORT_MAC_ACCESS_CNTRL 0x0010 +/* +** The server supports setting/getting comments using the mechanism in this +** document instead of using the NTFS format described in the Introduction. +*/ +#define SUPPORT_MAC_GETSETCOMMENTS 0x0020 +/* +** The Server supports setting and getting Macintosh desktop database information +** using the mechanism in this document. +*/ +#define SUPPORT_MAC_DESKTOPDB_CALLS 0x0040 +/* +** The server will return a unique id for files and directories in the +** Trans2_Find_First2 and Trans2_Find_Next2 message described later in this document. +*/ +#define SUPPORT_MAC_UNIQUE_IDS 0x0080 +/* +** The server will return this flag telling the client that the server does +** not support streams or the Macintosh extensions. The rest of this message +** will be ignored by the client. +*/ +#define NO_STREAMS_OR_MAC_SUPPORT 0x0100 + +/* +** We will be adding a new info level to the Trans2_Find_First2 and Trans2_Find_Next2. +** This info level will be SMB_MAC_FIND_BOTH_HFS_INFO and will support the server +** return additional information need by the Macintosh. All fields are Little +** Endian unless other wise specified. +*/ + +#define SMB_MAC_FIND_BOTH_HFS_INFO 0x302 + +enum { + ownerRead = 0x0400, + ownerWrite = 0x0200, + ownerSearch = 0x0100, + groupRead = 0x0040, + groupWrite = 0x0020, + groupSearch = 0x0010, + otherRead = 0x0004, + otherWrite = 0x0002, + otherSearch = 0x0001, + Owner = 0x0800 +}; + + +/* +** We will be adding a new info level to the Trans2_Set_Path_Information. +** This info level will be SMB_MAC_SET_FINDER_INFO and will support the client +** setting information on the server need by the Macintosh. All fields are Little +** Endian unless other wise specified. +*/ + +#define SMB_MAC_SET_FINDER_INFO 0x303 + +enum { + SetCreateDate = 0x01, /* If this is set then set the create date of the file/folder */ + SetModDate = 0x02, /* If this is set then set the modify date of the file/folder */ + SetFLAttrib = 0x04, /* If this is set then set the Macintosh lock bit of the file/folder */ + FndrInfo1 = 0x08, /* If this is set then set the first 16 bytes of finder info */ + FndrInfo2 = 0x10, /* If this is set then set the second 16 bytes of finder info */ + SetHidden = 0x20 /* We are either setting or unsetting the hidden bit */ +}; + + +/* +** We will be adding some new info level to the Trans2_Set_Path_Information and Trans2_Query_Path_Information. +** These info levels will allow the client to add, get, and remove desktop inforamtion from the +** server. How the server stores this information is up to them. +*/ + +/* +** We need to be able to store an application name and its creator in a database. We send a +** Trans2_Set_Path_Information call with the full path of the application in the path field. +** We will send an info level that represents adding an application name and creator to the database. +** We will pass the File Creator in the data message. +** +** The server should just respond with no error or an error. +*/ +#define SMB_MAC_DT_ADD_APPL 0x304 + +/* +** We need to be able to remove an application name and its creator from a database. We send a +** Trans2_Set_Path_Information call with the full path of the application in the path field. +** We will send an info level that represents removing an application name and creator from the database. +** We will pass the File Creator in the data message. +** +** The server should just respond with no error or an error. +*/ +#define SMB_MAC_DT_REMOVE_APPL 0x305 + + +/* +** We need to be able to get an application name and its creator from a database. We send a +** Trans2_Query_Path_Information call in which the name field is just ignore. +** We will send an info level that represents getting an application name with a structure that +** contains the File Creator and index. Were index has the following meaning. +** Index = 0; Get the application path from the database with the most current date. +** Index > 0; Use the index to find the application path from the database. +** e.g. index of 5 means get the fifth entry of this application name in the database. +** if not entry return an error. +** +** The server returns with a structure that contains the full path to the appication and +** its creator's date. +*/ +#define SMB_MAC_DT_GET_APPL 0x306 + + +/* +** We need to be able to get an icon from a database. We send a Trans2_Query_Path_Information call in +** which the path name is ignore. We will send an info level that represents getting an icon with a structure +** that contains the Requested size of the icon, the Icon type, File Creator, and File Type. +** +** The server returns with a structure that contains the actual size of the icon +** (must be less than requested length) and the icon bit map. +*/ +#define SMB_MAC_DT_GET_ICON 0x307 + + +/* +** We need to be able to get an icon from a database. We send a Trans2_Query_Path_Information call in +** which the path name is ignore. We will send an info level that represents getting an icon with a structure +** that contains the index and File Creator. The index allows the client to make repeated calls to the server +** gathering all icon stored by this file creator. +** +** +** The server returns with a structure that contains the actual size of the icon +** (must be less than requested length) and the icon bit map, File Type, and Icon Type. +*/ +#define SMB_MAC_DT_GET_ICON_INFO 0x308 + + + +/* +** We need to be able to add an icon to a database. We send a Trans2_Set_Path_Information call in +** which the path name is ignore. We will send an info level that represents setting an icon with a structure +** that contains the icon data, icon size, icon type, the file type, and file creator. +** +** +** The server returns only that the call was successful or not. +*/ +#define SMB_MAC_DT_ADD_ICON 0x309 + +#endif /* _MAC_EXTENSIONS_H */ + +/* _MAC_EXTENSIONS_H */ + diff --git a/source3/include/ads.h b/source3/include/ads.h new file mode 100644 index 0000000..8085543 --- /dev/null +++ b/source3/include/ads.h @@ -0,0 +1,154 @@ +#ifndef _INCLUDE_ADS_H_ +#define _INCLUDE_ADS_H_ +/* + header for ads (active directory) library routines + + basically this is a wrapper around ldap +*/ + +#include "libads/ads_status.h" +#include "smb_ldap.h" + +struct ads_saslwrap; + +struct ads_saslwrap_ops { + const char *name; + ADS_STATUS (*wrap)(struct ads_saslwrap *, uint8_t *buf, uint32_t len); + ADS_STATUS (*unwrap)(struct ads_saslwrap *); + void (*disconnect)(struct ads_saslwrap *); +}; + +enum ads_saslwrap_type { + ADS_SASLWRAP_TYPE_PLAIN = 1, + ADS_SASLWRAP_TYPE_SIGN = 2, + ADS_SASLWRAP_TYPE_SEAL = 4 +}; + +struct ads_saslwrap { + /* expected SASL wrapping type */ + enum ads_saslwrap_type wrap_type; + /* SASL wrapping operations */ + const struct ads_saslwrap_ops *wrap_ops; +#ifdef HAVE_LDAP_SASL_WRAPPING + Sockbuf_IO_Desc *sbiod; /* lowlevel state for LDAP wrapping */ +#endif /* HAVE_LDAP_SASL_WRAPPING */ + TALLOC_CTX *mem_ctx; + void *wrap_private_data; + struct { + uint32_t ofs; + uint32_t needed; + uint32_t left; +#define ADS_SASL_WRAPPING_IN_MAX_WRAPPED 0x0FFFFFFF + uint32_t max_wrapped; + uint32_t min_wrapped; + uint32_t size; + uint8_t *buf; + } in; + struct { + uint32_t ofs; + uint32_t left; +#define ADS_SASL_WRAPPING_OUT_MAX_WRAPPED 0x00A00000 + uint32_t max_unwrapped; + uint32_t sig_size; + uint32_t size; + uint8_t *buf; + } out; +}; + +typedef struct ads_struct { + /* info needed to find the server */ + struct { + char *realm; + char *workgroup; + char *ldap_server; + bool gc; /* Is this a global catalog server? */ + bool no_fallback; /* Bail if the ldap_server is not available */ + } server; + + /* info needed to authenticate */ + struct { + char *realm; + char *password; + char *user_name; + char *kdc_server; + unsigned flags; + int time_offset; + char *ccache_name; + time_t tgt_expire; + time_t tgs_expire; + time_t renewable; + } auth; + + /* info derived from the servers config */ + struct { + uint32_t flags; /* cldap flags identifying the services. */ + char *realm; + char *bind_path; + char *ldap_server_name; + char *server_site_name; + char *client_site_name; + time_t current_time; + char *schema_path; + char *config_path; + int ldap_page_size; + } config; + + /* info about the current LDAP connection */ +#ifdef HAVE_LDAP + struct ads_saslwrap ldap_wrap_data; + struct { + LDAP *ld; + struct sockaddr_storage ss; /* the ip of the active connection, if any */ + time_t last_attempt; /* last attempt to reconnect, monotonic clock */ + int port; + } ldap; +#endif /* HAVE_LDAP */ +} ADS_STRUCT; + +#ifdef HAVE_ADS +typedef LDAPMod **ADS_MODLIST; +#else +typedef void **ADS_MODLIST; +#endif + +/* time between reconnect attempts */ +#define ADS_RECONNECT_TIME 5 + +/* ldap control oids */ +#define ADS_PAGE_CTL_OID "1.2.840.113556.1.4.319" +#define ADS_NO_REFERRALS_OID "1.2.840.113556.1.4.1339" +#define ADS_SERVER_SORT_OID "1.2.840.113556.1.4.473" +#define ADS_PERMIT_MODIFY_OID "1.2.840.113556.1.4.1413" +#define ADS_ASQ_OID "1.2.840.113556.1.4.1504" +#define ADS_EXTENDED_DN_OID "1.2.840.113556.1.4.529" +#define ADS_SD_FLAGS_OID "1.2.840.113556.1.4.801" + +/* ldap bitwise searches */ +#define ADS_LDAP_MATCHING_RULE_BIT_AND "1.2.840.113556.1.4.803" +#define ADS_LDAP_MATCHING_RULE_BIT_OR "1.2.840.113556.1.4.804" + +#define ADS_PINGS 0x0000FFFF /* Ping response */ + +enum ads_extended_dn_flags { + ADS_EXTENDED_DN_HEX_STRING = 0, + ADS_EXTENDED_DN_STRING = 1 /* not supported on win2k */ +}; + +/* this is probably not very well suited to pass other controls generically but + * is good enough for the extended dn control where it is only used for atm */ + +typedef struct { + const char *control; + int val; + int critical; +} ads_control; + +#include "libads/ads_proto.h" + +#ifdef HAVE_LDAP +#include "libads/ads_ldap_protos.h" +#endif + +#include "libads/kerberos_proto.h" + +#endif /* _INCLUDE_ADS_H_ */ diff --git a/source3/include/adt_tree.h b/source3/include/adt_tree.h new file mode 100644 index 0000000..7e43fa6 --- /dev/null +++ b/source3/include/adt_tree.h @@ -0,0 +1,46 @@ +/* + * Unix SMB/CIFS implementation. + * Generic Abstract Data Types + * Copyright (C) Gerald Carter 2002-2005. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef ADT_TREE_H +#define ADT_TREE_H + +struct sorted_tree; + +/* + * API + */ + +/* create a new tree, talloc_free() to throw it away */ + +struct sorted_tree *pathtree_init(void *data_p); + +/* add a new path component */ + +bool pathtree_add(struct sorted_tree *tree, const char *path, void *data_p ); + +/* search path */ + +void *pathtree_find(struct sorted_tree *tree, char *key ); + +/* debug (print) functions */ + +void pathtree_print_keys(struct sorted_tree *tree, int debug ); + + +#endif diff --git a/source3/include/async_smb.h b/source3/include/async_smb.h new file mode 100644 index 0000000..3c64d08 --- /dev/null +++ b/source3/include/async_smb.h @@ -0,0 +1,47 @@ +/* + Unix SMB/CIFS implementation. + Infrastructure for async SMB client requests + Copyright (C) Volker Lendecke 2008 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef __ASYNC_SMB_H__ +#define __ASYNC_SMB_H__ + +struct cli_state; + +struct tevent_req *cli_smb_req_create(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct cli_state *cli, + uint8_t smb_command, + uint8_t additional_flags, + uint16_t additional_flags2, + uint8_t wct, uint16_t *vwv, + int iov_count, + struct iovec *bytes_iov); +struct tevent_req *cli_smb_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, + struct cli_state *cli, + uint8_t smb_command, + uint8_t additional_flags, + uint16_t additional_flags2, + uint8_t wct, uint16_t *vwv, + uint32_t num_bytes, + const uint8_t *bytes); +NTSTATUS cli_smb_recv(struct tevent_req *req, + TALLOC_CTX *mem_ctx, uint8_t **pinbuf, + uint8_t min_wct, uint8_t *pwct, uint16_t **pvwv, + uint32_t *pnum_bytes, uint8_t **pbytes); + +#endif diff --git a/source3/include/auth.h b/source3/include/auth.h new file mode 100644 index 0000000..69e53bb --- /dev/null +++ b/source3/include/auth.h @@ -0,0 +1,149 @@ +#ifndef _SMBAUTH_H_ +#define _SMBAUTH_H_ +/* + Unix SMB/CIFS implementation. + Standardised Authentication types + Copyright (C) Andrew Bartlett 2001 + + 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 "../auth/common_auth.h" + +struct gensec_security; + +struct extra_auth_info { + struct dom_sid user_sid; + struct dom_sid pgid_sid; +}; + +struct auth_serversupplied_info { + bool guest; + + struct security_unix_token utok; + + /* + * A complete auth_session_info + * + * This is not normally filled in, during the typical + * authentication process. If filled in, it has already been + * finalised by a nasty hack to support a cached guest/system + * session_info + */ + const struct auth_session_info *cached_session_info; + + /* These are the intermediate session keys, as provided by a + * NETLOGON server and used by NTLMSSP to negotiate key + * exchange etc (which will provide the session_key in the + * auth_session_info). It is usually the same as the keys in + * the info3, but is a variable length structure here to allow + * it to be omitted if the auth module does not know it. + */ + + DATA_BLOB session_key; + DATA_BLOB lm_session_key; + + struct netr_SamInfo3 *info3; + + /* this structure is filled *only* in pathological cases where the user + * sid or the primary group sid are not sids of the domain. Normally + * this happens only for unix accounts that have unix domain sids. + * This is checked only when info3.rid and/or info3.primary_gid are set + * to the special invalid value of 0xFFFFFFFF */ + struct extra_auth_info extra; + + /* + * This is a token from /etc/passwd and /etc/group + */ + bool nss_token; + + char *unix_name; +}; + +struct auth_context; + +typedef NTSTATUS (*prepare_gensec_fn)(const struct auth_context *auth_context, + TALLOC_CTX *mem_ctx, + struct gensec_security **gensec_context); + +typedef NTSTATUS (*make_auth4_context_fn)(const struct auth_context *auth_context, + TALLOC_CTX *mem_ctx, + struct auth4_context **auth4_context); + +struct auth_context { + DATA_BLOB challenge; + + /* What time did this start */ + struct timeval start_time; + + /* Who set this up in the first place? */ + const char *challenge_set_by; + + /* What order are the various methods in? Try to stop it changing under us */ + struct auth_methods *auth_method_list; + + prepare_gensec_fn prepare_gensec; + make_auth4_context_fn make_auth4_context; + const char *forced_samba4_methods; +}; + +struct auth_methods +{ + struct auth_methods *prev, *next; + const char *name; /* What name got this module */ + + NTSTATUS (*auth)(const struct auth_context *auth_context, + void *my_private_data, + TALLOC_CTX *mem_ctx, + const struct auth_usersupplied_info *user_info, + struct auth_serversupplied_info **server_info); + + /* Optional methods allowing this module to provide a way to get a gensec context and an auth4_context */ + prepare_gensec_fn prepare_gensec; + make_auth4_context_fn make_auth4_context; + /* Used to keep tabs on things like the cli for SMB server authentication */ + void *private_data; + + uint32_t flags; + +}; + +typedef NTSTATUS (*auth_init_function)(struct auth_context *, const char *, struct auth_methods **); + +struct auth_init_function_entry { + const char *name; + /* Function to create a member of the authmethods list */ + + auth_init_function init; + + struct auth_init_function_entry *prev, *next; +}; + +extern const struct gensec_security_ops gensec_ntlmssp3_server_ops; + +/* Intent of use for session key. LSA and SAMR pipes use 16 bytes of session key when doing create/modify calls */ +enum session_key_use_intent { + KEY_USE_FULL = 0, + KEY_USE_16BYTES +}; + +/* Changed from 1 -> 2 to add the logon_parameters field. */ +/* Changed from 2 -> 3 when we reworked many auth structures to use IDL or be in common with Samba4 */ +/* Changed from 3 -> 4 when we reworked added the flags */ +/* Changed from 4 -> 5 as module init functions now take a TALLOC_CTX * */ +#define AUTH_INTERFACE_VERSION 5 + +#include "auth/proto.h" + +#endif /* _SMBAUTH_H_ */ diff --git a/source3/include/auth_generic.h b/source3/include/auth_generic.h new file mode 100644 index 0000000..0911182 --- /dev/null +++ b/source3/include/auth_generic.h @@ -0,0 +1,53 @@ +/* + NLTMSSP wrappers + + Copyright (C) Andrew Tridgell 2001 + Copyright (C) Andrew Bartlett 2001-2011 + + 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/>. +*/ + +#ifndef _AUTH_GENERIC_ +#define _AUTH_GENERIC_ + +struct gensec_security; + +struct auth_generic_state { + /* used only by the client implementation */ + struct cli_credentials *credentials; + + /* used by both */ + struct gensec_security *gensec_security; +}; + +NTSTATUS auth_generic_set_username(struct auth_generic_state *ans, + const char *user); +NTSTATUS auth_generic_set_domain(struct auth_generic_state *ans, + const char *domain); +NTSTATUS auth_generic_set_password(struct auth_generic_state *ans, + const char *password); +NTSTATUS auth_generic_set_creds(struct auth_generic_state *ans, + struct cli_credentials *creds); +NTSTATUS auth_generic_client_prepare(TALLOC_CTX *mem_ctx, + struct auth_generic_state **_ans); +NTSTATUS auth_generic_client_start(struct auth_generic_state *ans, const char *oid); +NTSTATUS auth_generic_client_start_by_name(struct auth_generic_state *ans, + const char *name); +NTSTATUS auth_generic_client_start_by_authtype(struct auth_generic_state *ans, + uint8_t auth_type, + uint8_t auth_level); +NTSTATUS auth_generic_client_start_by_sasl(struct auth_generic_state *ans, + const char **sasl_list); + +#endif /* _AUTH_GENERIC_ */ diff --git a/source3/include/client.h b/source3/include/client.h new file mode 100644 index 0000000..14be20e --- /dev/null +++ b/source3/include/client.h @@ -0,0 +1,123 @@ +/* + Unix SMB/CIFS implementation. + SMB parameters and setup + Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Luke Kenneth Casson Leighton 1996-1998 + Copyright (C) Jeremy Allison 1998 + + 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/>. +*/ + +#ifndef _CLIENT_H +#define _CLIENT_H + +#define CLI_BUFFER_SIZE SMB_BUFFER_SIZE_MAX + +/* default client timeout to 20 seconds on most commands */ +#define CLIENT_TIMEOUT (20 * 1000) + +/* + * These definitions depend on smb.h + */ + +struct print_job_info { + uint16_t id; + uint16_t priority; + size_t size; + fstring user; + fstring name; + time_t t; +}; + +struct smbXcli_conn; +struct smbXcli_session; + +struct cli_state { + /** + * A list of subsidiary connections for DFS. + */ + struct cli_state *prev, *next; + int rap_error; + NTSTATUS raw_status; /* maybe via NT_STATUS_DOS() */ + bool map_dos_errors; + + /* + * The following strings are the + * ones returned by the server if + * the protocol > NT1. + */ + char *server_type; + char *server_os; + char *server_domain; + + char *share; + char *dev; + + int timeout; /* in milliseconds. */ + int initialised; + int win95; + /* What the server offered. */ + uint32_t server_posix_capabilities; + /* What the client requested. */ + uint32_t requested_posix_capabilities; + bool backup_intent; + + /* The list of pipes currently open on this connection. */ + struct rpc_pipe_client *pipe_list; + + bool use_oplocks; /* should we use oplocks? */ + + struct smbXcli_conn *conn; + + struct { + uint32_t pid; + uint16_t vc_num; + struct smbXcli_session *session; + struct smbXcli_tcon *tcon; + } smb1; + + struct { + struct smbXcli_session *session; + struct smbXcli_tcon *tcon; + struct idr_context *open_handles; + } smb2; +}; + +struct file_info { + uint64_t size; + uint64_t allocated_size; + uint32_t attr; + uid_t uid; + gid_t gid; + uint64_t ino; + /* these times are normally kept in GMT */ + struct timespec btime_ts; /* Birth-time if supported by system */ + struct timespec mtime_ts; + struct timespec atime_ts; + struct timespec ctime_ts; + char *name; + char *short_name; +}; + +#define CLI_FULL_CONNECTION_DONT_SPNEGO 0x0001 +#define CLI_FULL_CONNECTION_ANONYMOUS_FALLBACK 0x0004 +#define CLI_FULL_CONNECTION_OPLOCKS 0x0010 +#define CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS 0x0020 +#define CLI_FULL_CONNECTION_FORCE_DOS_ERRORS 0x0080 +#define CLI_FULL_CONNECTION_FORCE_ASCII 0x0100 +#define CLI_FULL_CONNECTION_FORCE_SMB1 0x0400 +#define CLI_FULL_CONNECTION_DISABLE_SMB1 0x0800 +#define CLI_FULL_CONNECTION_IPC 0x1000 + +#endif /* _CLIENT_H */ diff --git a/source3/include/ctdb_srvids.h b/source3/include/ctdb_srvids.h new file mode 100644 index 0000000..b51a458 --- /dev/null +++ b/source3/include/ctdb_srvids.h @@ -0,0 +1,46 @@ +/* + Unix SMB/CIFS implementation. + Samba3 ctdb srvid assignments + Copyright (C) Volker Lendecke 2012 + + 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/>. +*/ + +/* + * ctdb has reserved all srvids starting with 0xFE for Samba. Here we list our + * static assignments that are supposed to be globally unique. + */ + +/* + * ctdb_protocol.h already has the following definition, used in the g_lock + * implementation. Waiters for a g_lock register this to receive notifications + * when g_lock holders die. + */ + +#if 0 +#define CTDB_SRVID_SAMBA_NOTIFY 0xFE00000000000000LL +#endif + +/* + * SRVID for notify_internal.c: On every node, one process registers this + * SRVID. It receives filechangenotify notifications and multicasts them + * locally according to the non-clustered local notify.tdb + */ +#define CTDB_SRVID_SAMBA_NOTIFY_PROXY 0xFE00000000000001LL + +/* + * SRVID for all processes that come from Samba. Used to be + * MSG_SRVID_SAMBA in the past. Now used for message_send_all. + */ +#define CTDB_SRVID_SAMBA_PROCESS 0xFE00000000000002LL diff --git a/source3/include/ctdbd_conn.h b/source3/include/ctdbd_conn.h new file mode 100644 index 0000000..74db96e --- /dev/null +++ b/source3/include/ctdbd_conn.h @@ -0,0 +1,153 @@ +/* + Unix SMB/CIFS implementation. + Samba3 ctdb connection handling + 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 <http://www.gnu.org/licenses/>. +*/ + +#ifndef _CTDBD_CONN_H +#define _CTDBD_CONN_H + +#include "replace.h" +#include "system/filesys.h" +#include "system/network.h" +#include "lib/dbwrap/dbwrap.h" +#include <tdb.h> +#include <tevent.h> + +struct ctdbd_connection; +struct messaging_context; +struct messaging_rec; + +int ctdbd_init_connection(TALLOC_CTX *mem_ctx, + const char *sockname, int timeout, + struct ctdbd_connection **pconn); +int ctdbd_init_async_connection( + TALLOC_CTX *mem_ctx, + const char *sockname, + int timeout, + struct ctdbd_connection **pconn); +int ctdbd_reinit_connection(TALLOC_CTX *mem_ctx, + const char *sockname, int timeout, + struct ctdbd_connection *conn); + +uint32_t ctdbd_vnn(const struct ctdbd_connection *conn); + +int ctdbd_conn_get_fd(struct ctdbd_connection *conn); +void ctdbd_socket_readable(struct tevent_context *ev, + struct ctdbd_connection *conn); + +int ctdbd_messaging_send_iov(struct ctdbd_connection *conn, + uint32_t dst_vnn, uint64_t dst_srvid, + const struct iovec *iov, int iovlen); + +bool ctdbd_process_exists(struct ctdbd_connection *conn, uint32_t vnn, + pid_t pid, uint64_t unique_id); + +char *ctdbd_dbpath(struct ctdbd_connection *conn, + TALLOC_CTX *mem_ctx, uint32_t db_id); + +int ctdbd_db_attach(struct ctdbd_connection *conn, const char *name, + uint32_t *db_id, bool persistent); + +int ctdbd_migrate(struct ctdbd_connection *conn, uint32_t db_id, TDB_DATA key); + +int ctdbd_parse(struct ctdbd_connection *conn, uint32_t db_id, + TDB_DATA key, bool local_copy, + void (*parser)(TDB_DATA key, TDB_DATA data, + void *private_data), + void *private_data); + +int ctdbd_traverse(struct ctdbd_connection *master, uint32_t db_id, + void (*fn)(TDB_DATA key, TDB_DATA data, + void *private_data), + void *private_data); + +int ctdbd_register_ips(struct ctdbd_connection *conn, + const struct sockaddr_storage *server, + const struct sockaddr_storage *client, + int (*cb)(struct tevent_context *ev, + uint32_t src_vnn, uint32_t dst_vnn, + uint64_t dst_srvid, + const uint8_t *msg, size_t msglen, + void *private_data), + void *private_data); + +/* + * call @cb for each public IP. If @cb returns non-zero, then break the loop + * and propagate the return value upwards. + * @returns: 0 on success, where all @cb invocations also returned zero + * ENOMEM on memory allocation failure + * EIO on ctdbd connection failure + * @cb() return value if non-zero + */ +int ctdbd_public_ip_foreach(struct ctdbd_connection *conn, + int (*cb)(uint32_t total_ip_count, + const struct sockaddr_storage *ip, + bool is_movable_ip, + void *private_data), + void *private_data); + +int ctdbd_control_local(struct ctdbd_connection *conn, uint32_t opcode, + uint64_t srvid, uint32_t flags, TDB_DATA data, + TALLOC_CTX *mem_ctx, TDB_DATA *outdata, + int32_t *cstatus); +int ctdb_watch_us(struct ctdbd_connection *conn); +int ctdb_unwatch(struct ctdbd_connection *conn); + +struct ctdb_req_message_old; + +int register_with_ctdbd(struct ctdbd_connection *conn, uint64_t srvid, + int (*cb)(struct tevent_context *ev, + uint32_t src_vnn, uint32_t dst_vnn, + uint64_t dst_srvid, + const uint8_t *msg, size_t msglen, + void *private_data), + void *private_data); +int ctdbd_probe(const char *sockname, int timeout); + +struct ctdb_req_header; +void ctdbd_prep_hdr_next_reqid( + struct ctdbd_connection *conn, struct ctdb_req_header *hdr); + +/* + * Async ctdb_request. iov[0] must start with an initialized + * struct ctdb_req_header + */ +struct tevent_req *ctdbd_req_send( + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct ctdbd_connection *conn, + struct iovec *iov, + size_t num_iov); +int ctdbd_req_recv( + struct tevent_req *req, + TALLOC_CTX *mem_ctx, + struct ctdb_req_header **reply); + +struct tevent_req *ctdbd_parse_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct ctdbd_connection *conn, + uint32_t db_id, + TDB_DATA key, + bool local_copy, + void (*parser)(TDB_DATA key, + TDB_DATA data, + void *private_data), + void *private_data, + enum dbwrap_req_state *req_state); +int ctdbd_parse_recv(struct tevent_req *req); + +#endif /* _CTDBD_CONN_H */ diff --git a/source3/include/fake_file.h b/source3/include/fake_file.h new file mode 100644 index 0000000..c267df2 --- /dev/null +++ b/source3/include/fake_file.h @@ -0,0 +1,52 @@ +/* + Unix SMB/CIFS implementation. + FAKE FILE suppport, for faking up special files windows want access to + Copyright (C) Stefan (metze) Metzmacher 2003 + + 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/>. +*/ + +#ifndef _FAKE_FILE_H +#define _FAKE_FILE_H + +enum FAKE_FILE_TYPE { + FAKE_FILE_TYPE_NONE = 0, + FAKE_FILE_TYPE_QUOTA, + FAKE_FILE_TYPE_NAMED_PIPE, + FAKE_FILE_TYPE_NAMED_PIPE_PROXY +}; + +/* +we now get the unix name --metze +*/ +#define FAKE_FILE_NAME_QUOTA_WIN32 "\\$Extend\\$Quota:$Q:$INDEX_ALLOCATION" +#define FAKE_FILE_NAME_QUOTA_UNIX "$Extend/$Quota:$Q:$INDEX_ALLOCATION" + +struct fake_file_handle { + enum FAKE_FILE_TYPE type; + void *private_data; +}; + +enum FAKE_FILE_TYPE is_fake_file_path(const char *path); +enum FAKE_FILE_TYPE is_fake_file(const struct smb_filename *smb_fname); +NTSTATUS open_fake_file(struct smb_request *req, connection_struct *conn, + uint64_t current_vuid, + enum FAKE_FILE_TYPE fake_file_type, + const struct smb_filename *smb_fname, + uint32_t access_mask, + files_struct **result); +NTSTATUS close_fake_file(struct smb_request *req, files_struct *fsp); +uint32_t dosmode_from_fake_filehandle(const struct fake_file_handle *ffh); + +#endif /* _FAKE_FILE_H */ diff --git a/source3/include/g_lock.h b/source3/include/g_lock.h new file mode 100644 index 0000000..749cb57 --- /dev/null +++ b/source3/include/g_lock.h @@ -0,0 +1,103 @@ +/* + Unix SMB/CIFS implementation. + global locks based on dbwrap and messaging + Copyright (C) 2009 by Volker Lendecke + + 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/>. +*/ + +#ifndef _G_LOCK_H_ +#define _G_LOCK_H_ + +#include "replace.h" +#include "librpc/gen_ndr/server_id.h" +#include "dbwrap/dbwrap.h" + +struct g_lock_ctx; +struct messaging_context; + +enum g_lock_type { + G_LOCK_READ, + G_LOCK_WRITE, + G_LOCK_UPGRADE, + G_LOCK_DOWNGRADE, +}; + +struct g_lock_ctx *g_lock_ctx_init_backend( + TALLOC_CTX *mem_ctx, + struct messaging_context *msg, + struct db_context **backend); +void g_lock_set_lock_order(struct g_lock_ctx *ctx, + enum dbwrap_lock_order lock_order); +struct g_lock_ctx *g_lock_ctx_init(TALLOC_CTX *mem_ctx, + struct messaging_context *msg); + +struct tevent_req *g_lock_lock_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct g_lock_ctx *ctx, + TDB_DATA key, + enum g_lock_type type); +NTSTATUS g_lock_lock_recv(struct tevent_req *req); +NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, TDB_DATA key, + enum g_lock_type lock_type, struct timeval timeout); +NTSTATUS g_lock_unlock(struct g_lock_ctx *ctx, TDB_DATA key); + +NTSTATUS g_lock_writev_data( + struct g_lock_ctx *ctx, + TDB_DATA key, + const TDB_DATA *dbufs, + size_t num_dbufs); +NTSTATUS g_lock_write_data(struct g_lock_ctx *ctx, TDB_DATA key, + const uint8_t *buf, size_t buflen); + +int g_lock_locks(struct g_lock_ctx *ctx, + int (*fn)(TDB_DATA key, void *private_data), + void *private_data); +struct tevent_req *g_lock_dump_send( + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct g_lock_ctx *ctx, + TDB_DATA key, + void (*fn)(struct server_id exclusive, + size_t num_shared, + const struct server_id *shared, + const uint8_t *data, + size_t datalen, + void *private_data), + void *private_data); +NTSTATUS g_lock_dump_recv(struct tevent_req *req); +NTSTATUS g_lock_dump(struct g_lock_ctx *ctx, + TDB_DATA key, + void (*fn)(struct server_id exclusive, + size_t num_shared, + const struct server_id *shared, + const uint8_t *data, + size_t datalen, + void *private_data), + void *private_data); +int g_lock_seqnum(struct g_lock_ctx *ctx); + +struct tevent_req *g_lock_watch_data_send( + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct g_lock_ctx *ctx, + TDB_DATA key, + struct server_id blocker); +NTSTATUS g_lock_watch_data_recv( + struct tevent_req *req, + bool *blockerdead, + struct server_id *blocker); +void g_lock_wake_watchers(struct g_lock_ctx *ctx, TDB_DATA key); + +#endif diff --git a/source3/include/idmap.h b/source3/include/idmap.h new file mode 100644 index 0000000..dce60f1 --- /dev/null +++ b/source3/include/idmap.h @@ -0,0 +1,74 @@ +#ifndef _IDMAP_H_ +#define _IDMAP_H_ +/* + Unix SMB/CIFS implementation. + + Idmap headers + + Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2003 + Copyright (C) Simo Sorce 2003 + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/* The interface version specifier. + Updated to 3 for enum types by JRA. */ + +/* Updated to 4, completely new interface, SSS */ +/* Updated to 5, simplified interface by Volker */ +/* Updated to 6, modules now take TALLOC_CTX * init parameter. */ + +#define SMB_IDMAP_INTERFACE_VERSION 6 + +#include "librpc/gen_ndr/idmap.h" + +struct wbint_userinfo; + +struct idmap_domain { + const char *name; + /* + * dom_sid is currently only initialized in the unixids_to_sids request, + * so don't rely on this being filled out everywhere! + */ + struct dom_sid dom_sid; + const struct idmap_methods *methods; + NTSTATUS (*query_user)(struct idmap_domain *domain, + struct wbint_userinfo *info); + uint32_t low_id; + uint32_t high_id; + bool read_only; + void *private_data; +}; + +/* Filled out by IDMAP backends */ +struct idmap_methods { + + /* Called when backend is first loaded */ + NTSTATUS (*init)(struct idmap_domain *dom); + + /* Map an array of uids/gids to SIDs. The caller specifies + the uid/gid and type. Gets back the SID. */ + NTSTATUS (*unixids_to_sids)(struct idmap_domain *dom, struct id_map **ids); + + /* Map an arry of SIDs to uids/gids. The caller sets the SID + and type and gets back a uid or gid. */ + NTSTATUS (*sids_to_unixids)(struct idmap_domain *dom, struct id_map **ids); + + /* Allocate a Unix-ID. */ + NTSTATUS (*allocate_id)(struct idmap_domain *dom, struct unixid *id); +}; + +#include "winbindd/idmap_proto.h" + +#endif /* _IDMAP_H_ */ diff --git a/source3/include/idmap_autorid_tdb.h b/source3/include/idmap_autorid_tdb.h new file mode 100644 index 0000000..36a595f --- /dev/null +++ b/source3/include/idmap_autorid_tdb.h @@ -0,0 +1,214 @@ +/* + * idmap_autorid: static map between Active Directory/NT RIDs + * and RFC 2307 accounts. This file contains common functions + * and structures used by idmap_autorid and net idmap autorid utilities + * + * Copyright (C) Christian Ambach, 2010-2012 + * Copyright (C) Atul Kulkarni, 2013 + * Copyright (C) Michael Adam, 2012-2013 + * + * 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/>. + * + */ + +#ifndef _IDMAP_AUTORID_H_ +#define _IDMAP_AUTORID_H_ + +#include "includes.h" +#include "system/filesys.h" +#include "dbwrap/dbwrap.h" +#include "dbwrap/dbwrap_open.h" +#include "../lib/util/util_tdb.h" +#include "winbindd/idmap_tdb_common.h" + +#define HWM "NEXT RANGE" +#define ALLOC_HWM_UID "NEXT ALLOC UID" +#define ALLOC_HWM_GID "NEXT ALLOC GID" +#define ALLOC_RANGE "ALLOC" +#define CONFIGKEY "CONFIG" + +struct autorid_global_config { + uint32_t minvalue; + uint32_t rangesize; + uint32_t maxranges; +}; + +struct autorid_range_config { + fstring domsid; + uint32_t rangenum; + uint32_t domain_range_index; + uint32_t low_id; + uint32_t high_id; +}; + +/** + * Get the range for a pair consisting of the domain sid + * and a domain range. If there is no stored range for + * this pair and read_only == false, a new range is + * acquired by incrementing that range HWM counter in the + * database. + */ +NTSTATUS idmap_autorid_get_domainrange(struct db_context *db, + struct autorid_range_config *range, + bool read_only); + +/** + * get the domain range and low_id for the domain + * identified by domsid and domain_range_index + */ +NTSTATUS idmap_autorid_getrange(struct db_context *db, + const char *domsid, + uint32_t domain_range_index, + uint32_t *rangenum, + uint32_t *low_id); + +/** + * Set a range for a domain#index pair to a given + * number. Fail if a different range was already stored. + */ +NTSTATUS idmap_autorid_setrange(struct db_context *db, + const char *domsid, + uint32_t domain_range_index, + uint32_t rangenum); + +NTSTATUS idmap_autorid_acquire_range(struct db_context *db, + struct autorid_range_config *range); + +/** + * Delete a domain#index <-> range maping from the database. + * The mapping is specified by the sid and index. + * If force == true, invalid mapping records are deleted as far + * as possible, otherwise they are left untouched. + */ +NTSTATUS idmap_autorid_delete_range_by_sid(struct db_context *db, + const char *domsid, + uint32_t domain_range_index, + bool force); + +/** + * Delete a domain#index <-> range maping from the database. + * The mapping is specified by the range number. + * If force == true, invalid mapping records are deleted as far + * as possible, otherwise they are left untouched. + */ +NTSTATUS idmap_autorid_delete_range_by_num(struct db_context *db, + uint32_t rangenum, + bool force); + +/** + * Initialize a specified HWM value to 0 if it is not + * yet present in the database. + */ +NTSTATUS idmap_autorid_init_hwm(struct db_context *db, const char *hwm); + +/** + * Open and possibly create the autorid database. + */ +NTSTATUS idmap_autorid_db_open(const char *path, + TALLOC_CTX *mem_ctx, + struct db_context **db); + +/** + * Initialize the high watermark records in the database. + */ +NTSTATUS idmap_autorid_init_hwms(struct db_context *db); + +/** + * Initialize an idmap_autorid database. + * After this function has successfully completed, the following are true: + * - the database exists + * - the required HWM keys exist (range, alloc-uid, alloc-gid) + */ +NTSTATUS idmap_autorid_db_init(const char *path, + TALLOC_CTX *mem_ctx, + struct db_context **db); + +/** + * Load the configuration stored in the autorid database. + */ +NTSTATUS idmap_autorid_loadconfig(struct db_context *db, + struct autorid_global_config *result); + +/** + * Save the global autorid configuration into the autorid database. + * The stored configuration consists of: + * - the low value of the idmap range + * - the rangesize + * - the maximum number of ranges + */ +NTSTATUS idmap_autorid_saveconfig(struct db_context *db, + struct autorid_global_config *cfg); + +/** + * get the range config string stored in the database + */ +NTSTATUS idmap_autorid_getconfigstr(struct db_context *db, TALLOC_CTX *mem_ctx, + char **result); + +/** + * parse the handed in config string and fill the provided config structure. + * return false if the string could not be parsed. + */ +bool idmap_autorid_parse_configstr(const char *configstr, + struct autorid_global_config *cfg); + + +/** + * Save the global autorid configuration into the autorid database + * as provided in the config string. + * First parse the configstr and validate it. + */ +NTSTATUS idmap_autorid_saveconfigstr(struct db_context *db, + const char *configstr); + + +/** + * idmap_autorid_iterate_domain_ranges: + * perform an action on all domain range mappings for a given domain + * specified by domain sid. + */ +NTSTATUS idmap_autorid_iterate_domain_ranges(struct db_context *db, + const char *domsid, + NTSTATUS (*fn)(struct db_context *db, + const char *domsid, + uint32_t index, + uint32_t rangenum, + void *private_data), + void *private_data, + int *count); + +/** + * idmap_autorid_iterate_domain_ranges_read: + * perform a read only action on all domain range mappings for a given domain + * specified by domain sid. + */ +NTSTATUS idmap_autorid_iterate_domain_ranges_read(struct db_context *db, + const char *domsid, + NTSTATUS (*fn)(struct db_context *db, + const char *domsid, + uint32_t index, + uint32_t rangenum, + void *private_data), + void *private_data, + int *count); + +/** + * delete all range mappings for a given domain + */ +NTSTATUS idmap_autorid_delete_domain_ranges(struct db_context *db, + const char *domsid, + bool force, + int *count); + +#endif /* _IDMAP_AUTORID_H_ */ diff --git a/source3/include/includes.h b/source3/include/includes.h new file mode 100644 index 0000000..bb93aad --- /dev/null +++ b/source3/include/includes.h @@ -0,0 +1,360 @@ +#ifndef _INCLUDES_H +#define _INCLUDES_H +/* + Unix SMB/CIFS implementation. + Machine customisation and include handling + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) 2002 by Martin Pool <mbp@samba.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "../replace/replace.h" + +/* make sure we have included the correct config.h */ +#ifndef NO_CONFIG_H /* for some tests */ +#ifndef CONFIG_H_IS_FROM_SAMBA +#error "make sure you have removed all config.h files from standalone builds!" +#error "the included config.h isn't from samba!" +#endif +#endif /* NO_CONFIG_H */ + +/* only do the C++ reserved word check when we compile + to include --with-developer since too many systems + still have comflicts with their header files (e.g. IRIX 6.4) */ + +#if !defined(__cplusplus) && defined(DEVELOPER) && defined(__linux__) +#define class #error DONT_USE_CPLUSPLUS_RESERVED_NAMES +#define private #error DONT_USE_CPLUSPLUS_RESERVED_NAMES +#define public #error DONT_USE_CPLUSPLUS_RESERVED_NAMES +#define protected #error DONT_USE_CPLUSPLUS_RESERVED_NAMES +#define template #error DONT_USE_CPLUSPLUS_RESERVED_NAMES +#define this #error DONT_USE_CPLUSPLUS_RESERVED_NAMES +#define new #error DONT_USE_CPLUSPLUS_RESERVED_NAMES +#define delete #error DONT_USE_CPLUSPLUS_RESERVED_NAMES +#define friend #error DONT_USE_CPLUSPLUS_RESERVED_NAMES +#endif + +#include "local.h" + +#ifdef SUNOS4 +/* on SUNOS4 termios.h conflicts with sys/ioctl.h */ +#undef HAVE_TERMIOS_H +#endif + +#ifdef RELIANTUNIX +/* + * <unistd.h> has to be included before any other to get + * large file support on Reliant UNIX. Yes, it's broken :-). + */ +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif +#endif /* RELIANTUNIX */ + +#include "system/dir.h" +#include "system/locale.h" +#include "system/time.h" +#include "system/wait.h" + +#ifndef HAVE_KRB5_H +#undef HAVE_KRB5 +#endif + +#ifndef HAVE_LDAP_H +#undef HAVE_LDAP +#endif + +#ifdef HAVE_SYS_ATTRIBUTES_H +#include <sys/attributes.h> +#endif + +#ifndef ENOATTR +#if defined(ENODATA) +#define ENOATTR ENODATA +#else +#define ENOATTR ENOENT +#endif +#endif + +#ifdef HAVE_SYS_UIO_H +#include <sys/uio.h> +#endif + +#ifdef HAVE_LANGINFO_H +#include <langinfo.h> +#endif + +/* Special macros that are no-ops except when run under Valgrind on + * x86. They've moved a little bit from valgrind 1.0.4 to 1.9.4 */ +#ifdef HAVE_VALGRIND_MEMCHECK_H + /* memcheck.h includes valgrind.h */ +#include <valgrind/memcheck.h> +#elif defined(HAVE_VALGRIND_H) +#include <valgrind.h> +#endif + +/* we support ADS if we want it and have krb5 and ldap libs */ +#if defined(WITH_ADS) && defined(HAVE_KRB5) && defined(HAVE_LDAP) +#define HAVE_ADS +#endif + +/* + * Define additional missing types + */ +#if defined(AIX) +typedef sig_atomic_t SIG_ATOMIC_T; +#else +typedef sig_atomic_t volatile SIG_ATOMIC_T; +#endif + +#ifndef uchar +#define uchar unsigned char +#endif + +/* + * Types for devices, inodes and offsets. + */ + +#ifndef SMB_DEV_T +# define SMB_DEV_T dev_t +#endif + +#ifndef LARGE_SMB_DEV_T +# if (defined(SIZEOF_DEV_T) && (SIZEOF_DEV_T == 8)) +# define LARGE_SMB_DEV_T 1 +# endif +#endif + +#ifdef LARGE_SMB_DEV_T +#define SDEV_T_VAL(p, ofs, v) (SIVAL((p),(ofs),(v)&0xFFFFFFFF), SIVAL((p),(ofs)+4,(v)>>32)) +#define DEV_T_VAL(p, ofs) ((SMB_DEV_T)(((uint64_t)(IVAL((p),(ofs))))| (((uint64_t)(IVAL((p),(ofs)+4))) << 32))) +#else +#define SDEV_T_VAL(p, ofs, v) (SIVAL((p),(ofs),v),SIVAL((p),(ofs)+4,0)) +#define DEV_T_VAL(p, ofs) ((SMB_DEV_T)(IVAL((p),(ofs)))) +#endif + +/* + * Setup the correctly sized inode type. + */ + +#ifndef SMB_INO_T +# define SMB_INO_T ino_t +#endif + +#ifndef LARGE_SMB_INO_T +# if (defined(SIZEOF_INO_T) && (SIZEOF_INO_T == 8)) +# define LARGE_SMB_INO_T 1 +# endif +#endif + +#ifdef LARGE_SMB_INO_T +#define SINO_T_VAL(p, ofs, v) SBVAL(p, ofs, v) +#define INO_T_VAL(p, ofs) ((SMB_INO_T)BVAL(p, ofs)) +#else +#define SINO_T_VAL(p, ofs, v) SBVAL(p, ofs, ((uint64_t)(v)) & UINT32_MAX) +#define INO_T_VAL(p, ofs) ((SMB_INO_T)(IVAL((p),(ofs)))) +#endif + +/* TODO: remove this macros */ +#define SBIG_UINT(p, ofs, v) SBVAL(p, ofs, v) +#define BIG_UINT(p, ofs) BVAL(p, ofs) +#define IVAL2_TO_SMB_BIG_UINT(p, ofs) BVAL(p, ofs) + +/* + * Set the define that tells us if we can do 64 bit + * NT SMB calls. + */ + +#define SOFF_T(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32)) +#define SOFF_T_R(p, ofs, v) (SIVAL(p,(ofs)+4,(v)&0xFFFFFFFF), SIVAL(p,ofs,(v)>>32)) +#define IVAL_TO_SMB_OFF_T(buf,off) ((off_t)(( ((uint64_t)(IVAL((buf),(off)))) & ((uint64_t)0xFFFFFFFF) ))) + +/* Is birthtime real, or was it calculated ? */ +#define ST_EX_IFLAG_CALCULATED_BTIME (1 << 0) + +/* + * Type for stat structure. + */ + +struct stat_ex { + dev_t st_ex_dev; + ino_t st_ex_ino; + mode_t st_ex_mode; + nlink_t st_ex_nlink; + uid_t st_ex_uid; + gid_t st_ex_gid; + dev_t st_ex_rdev; + off_t st_ex_size; + struct timespec st_ex_atime; + struct timespec st_ex_mtime; + struct timespec st_ex_ctime; + struct timespec st_ex_btime; /* birthtime */ + + blksize_t st_ex_blksize; + blkcnt_t st_ex_blocks; + + uint32_t st_ex_flags; + uint32_t st_ex_iflags; +}; + +typedef struct stat_ex SMB_STRUCT_STAT; + +enum timestamp_set_resolution { + TIMESTAMP_SET_SECONDS = 0, + TIMESTAMP_SET_MSEC, + TIMESTAMP_SET_NT_OR_BETTER +}; + +/* Our own fstrings */ + +/* + -------------- + / \ + / REST \ + / IN \ + / PEACE \ + / \ + | The infamous pstring | + | | + | | + | 7 December | + | | + | 2007 | + *| * * * | * + _________)/\\_//(\/(/\)/\//\/\///|_)_______ +*/ + +#ifndef FSTRING_LEN +#define FSTRING_LEN 256 +typedef char fstring[FSTRING_LEN]; +#endif + +/* debug.h need to be included before samba_util.h for the macro SMB_ASSERT */ +#include "../lib/util/debug.h" + +/* Lists, trees, caching, database... */ +#include "../lib/util/samba_util.h" +#include "../lib/util/util_net.h" +#include "../lib/util/attr.h" +#include "../lib/util/tsort.h" +#include "../lib/util/dlinklist.h" + +#include <talloc.h> +#include <tevent.h> + +#include "../lib/util/data_blob.h" +#include "../lib/util/time.h" +#include "../lib/util/debug_s3.h" + +#include "../libcli/util/ntstatus.h" +#include "../libcli/util/error.h" +#include "../lib/util/charset/charset.h" +#include "dynconfig/dynconfig.h" +#include "locking.h" +#include "smb_perfcount.h" +#include "smb.h" +#include "../lib/util/byteorder.h" + +#include "../lib/util/samba_modules.h" +#include "../lib/util/talloc_stack.h" + +/* samba_setXXid functions. */ +#include "../lib/util/setid.h" + +/***** prototypes *****/ +#ifndef NO_PROTO_H +#include "proto.h" +#endif + +#include "lib/param/loadparm.h" +#include "source3/param/loadparm.h" +/* Automatically generated by generate_param.py. */ +#include "source3/param/param_proto.h" + +/* String routines */ + +#include "srvstr.h" +#include "lib/util/safe_string.h" + +#ifndef SIGCLD +#define SIGCLD SIGCHLD +#endif + +#ifndef SIGRTMIN +#define SIGRTMIN NSIG +#endif + + +#if defined(HAVE_CRYPT16) && defined(HAVE_GETAUTHUID) +#define ULTRIX_AUTH 1 +#endif + +/* yuck, I'd like a better way of doing this */ +#define DIRP_SIZE (256 + 32) + +/* default socket options. Dave Miller thinks we should default to TCP_NODELAY + given the socket IO pattern that Samba uses */ +#ifdef TCP_NODELAY +#define DEFAULT_SOCKET_OPTIONS "TCP_NODELAY" +#else +#define DEFAULT_SOCKET_OPTIONS "" +#endif + +/* dmalloc -- free heap debugger (dmalloc.org). This should be near + * the *bottom* of include files so as not to conflict. */ +#ifdef ENABLE_DMALLOC +# include <dmalloc.h> +#endif + + +#define MAX_SEC_CTX_DEPTH 8 /* Maximum number of security contexts */ + + +/* add varargs prototypes with printf checking */ +/*PRINTFLIKE1 */ +int d_printf(const char *, ...) PRINTF_ATTRIBUTE(1,2); +/*PRINTFLIKE2 */ +int d_fprintf(FILE *f, const char *, ...) PRINTF_ATTRIBUTE(2,3); + +/* PRINTFLIKE2 */ +int fstr_sprintf(fstring s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3); + +char *talloc_asprintf_strupper_m(TALLOC_CTX *t, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3); + +/* + * Veritas File System. Often in addition to native. + * Quotas different. + */ +#if defined(HAVE_SYS_FS_VX_QUOTA_H) +#define VXFS_QUOTA +#endif + +#ifdef TRUE +#undef TRUE +#endif +#define TRUE __ERROR__XX__DONT_USE_TRUE + +#ifdef FALSE +#undef FALSE +#endif +#define FALSE __ERROR__XX__DONT_USE_FALSE + +void dump_core(void) _NORETURN_; +void exit_server(const char *const reason) _NORETURN_; +void exit_server_cleanly(const char *const reason) _NORETURN_; + +#define BASE_RID (0x000003E8L) + +#endif /* _INCLUDES_H */ diff --git a/source3/include/intl.h b/source3/include/intl.h new file mode 100644 index 0000000..cb0dc34 --- /dev/null +++ b/source3/include/intl.h @@ -0,0 +1,23 @@ +/* + Unix SMB/CIFS implementation. + internationalisation headers + Copyright (C) Andrew Tridgell 2001 + + 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/>. +*/ + + +/* ideally we would have a static mapping, but that precludes + dynamic loading. This is a reasonable compromise */ +#define N_(x) (x) diff --git a/source3/include/krb5_env.h b/source3/include/krb5_env.h new file mode 100644 index 0000000..0022da8 --- /dev/null +++ b/source3/include/krb5_env.h @@ -0,0 +1,26 @@ +/* + Samba Unix/Linux SMB client library + + Copyright (C) 2010 Günther Deschner + + 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/>. +*/ + +#ifndef _INCLUDE_KRB5_ENV_H_ +#define _INCLUDE_KRB5_ENV_H_ + +/* Kerberos environment variable names */ +#define KRB5_ENV_CCNAME "KRB5CCNAME" + +#endif /* _INCLUDE_KRB5_ENV_H_ */ diff --git a/source3/include/libsmb_internal.h b/source3/include/libsmb_internal.h new file mode 100644 index 0000000..5588f9d --- /dev/null +++ b/source3/include/libsmb_internal.h @@ -0,0 +1,585 @@ +/* + Unix SMB/Netbios implementation. + SMB client library implementation + Copyright (C) Andrew Tridgell 1998 + Copyright (C) Richard Sharpe 2000, 2002 + Copyright (C) John Terpstra 2000 + Copyright (C) Tom Jansen (Ninja ISD) 2002 + Copyright (C) Derrell Lipman 2003-2008 + Copyright (C) Jeremy Allison 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 <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" + + +#ifndef _LIBSMB_INTERNAL_H_ +#define _LIBSMB_INTERNAL_H_ + +#include "../include/libsmbclient.h" +#include "libsmb/clirap.h" + +#define SMBC_MAX_NAME 1023 +#define SMBC_FILE_MODE (S_IFREG | 0444) +#define SMBC_DIR_MODE (S_IFDIR | 0555) + +/* + * DOS Attribute values (used internally) + */ +struct DOS_ATTR_DESC { + int mode; + off_t size; + time_t create_time; + time_t access_time; + time_t write_time; + time_t change_time; + SMB_INO_T inode; +}; + +/* + * Extension of libsmbclient.h's #defines + */ +#define SMB_CTX_FLAG_USE_NT_HASH (1 << 4) + +/* + * Internal flags for extended attributes + */ + +/* internal mode values */ +#define SMBC_XATTR_MODE_ADD 1 +#define SMBC_XATTR_MODE_REMOVE 2 +#define SMBC_XATTR_MODE_REMOVE_ALL 3 +#define SMBC_XATTR_MODE_SET 4 +#define SMBC_XATTR_MODE_CHOWN 5 +#define SMBC_XATTR_MODE_CHGRP 6 + +/*We should test for this in configure ... */ +#ifndef ENOTSUP +#define ENOTSUP EOPNOTSUPP +#endif + + +struct _SMBCSRV { + struct cli_state *cli; + dev_t dev; + bool no_pathinfo; + bool no_pathinfo2; + bool no_pathinfo3; + bool no_nt_session; + struct policy_handle pol; + time_t last_echo_time; + + struct _SMBCSRV *next, *prev; +}; + +/* + * Keep directory entries in a list + */ +struct smbc_dir_list { + struct smbc_dir_list *next; + struct smbc_dirent *dirent; +}; + +struct smbc_dirplus_list { + struct smbc_dirplus_list *next; + struct libsmb_file_info *smb_finfo; + uint64_t ino; +}; + +/* + * Structure for open file management + */ +struct _SMBCFILE { + int cli_fd; + /* + * cache of cli_state we opened cli_fd on. + * Due to DFS can be a subsidiary connection to srv->cli + */ + struct cli_state *targetcli; + char *fname; + off_t offset; + struct _SMBCSRV *srv; + bool file; + struct smbc_dir_list *dir_list, *dir_end, *dir_next; + struct smbc_dirplus_list *dirplus_list, *dirplus_end, *dirplus_next; + int dir_type, dir_error; + + struct _SMBCFILE *next, *prev; +}; + + +/* + * Context structure + */ +struct SMBC_internal_data { + + /* True when this handle is initialized */ + bool initialized; + + /* dirent pointer location */ + struct smbc_dirent dirent; + /* + * Leave room for any urlencoded filename and the comment field. + * + * We use (NAME_MAX * 3) plus whatever the max length of a comment is, + * plus a couple of null terminators (one after the filename, + * one after the comment). + * + * According to <linux/limits.h>, NAME_MAX is 255. Is it longer + * anyplace else? + */ + char _dirent_name[1024]; + + /* + * server connection list + */ + SMBCSRV * servers; + + /* + * open file/dir list + */ + SMBCFILE * files; + + /* + * Support "Create Time" in get/set with the *xattr() functions, if + * true. This replaces the dos attribute strings C_TIME, A_TIME and + * M_TIME with CHANGE_TIME, ACCESS_TIME and WRITE_TIME, and adds + * CREATE_TIME. Default is FALSE, i.e. to use the old-style shorter + * names and to not support CREATE time, for backward compatibility. + */ + bool full_time_names; + + /* + * The share mode of a file being opened. To match POSIX semantics + * (and maintain backward compatibility), DENY_NONE is the default. + */ + smbc_share_mode share_mode; + + /* + * Authentication function which includes the context. This will be + * used if set; otherwise context->callbacks.auth_fn() will be used. + */ + smbc_get_auth_data_with_context_fn auth_fn_with_context; + + /* + * An opaque (to this library) user data handle which can be set + * and retrieved with smbc_option_set() and smbc_option_get(). + */ + void * user_data; + + /* + * Should we attempt UNIX smb encryption ? + * Set to 0 if we should never attempt, set to 1 if + * encryption requested, set to 2 if encryption required. + */ + smbc_smb_encrypt_level smb_encryption_level; + + /* + * Should we request case sensitivity of file names? + */ + bool case_sensitive; + + /* + * Credentials needed for DFS traversal. + */ + struct cli_credentials *creds; + + struct smbc_server_cache * server_cache; + + /* POSIX emulation functions */ + struct + { +#if 0 /* Left in libsmbclient.h for backward compatibility */ + smbc_open_fn open_fn; + smbc_creat_fn creat_fn; + smbc_read_fn read_fn; + smbc_write_fn write_fn; + smbc_unlink_fn unlink_fn; + smbc_rename_fn rename_fn; + smbc_lseek_fn lseek_fn; + smbc_stat_fn stat_fn; + smbc_fstat_fn fstat_fn; +#endif + smbc_statvfs_fn statvfs_fn; + smbc_fstatvfs_fn fstatvfs_fn; + smbc_ftruncate_fn ftruncate_fn; +#if 0 /* Left in libsmbclient.h for backward compatibility */ + smbc_close_fn close_fn; + smbc_opendir_fn opendir_fn; + smbc_closedir_fn closedir_fn; + smbc_readdir_fn readdir_fn; + smbc_getdents_fn getdents_fn; + smbc_mkdir_fn mkdir_fn; + smbc_rmdir_fn rmdir_fn; + smbc_telldir_fn telldir_fn; + smbc_lseekdir_fn lseekdir_fn; + smbc_fstatdir_fn fstatdir_fn; + smbc_chmod_fn chmod_fn; + smbc_utimes_fn utimes_fn; + smbc_setxattr_fn setxattr_fn; + smbc_getxattr_fn getxattr_fn; + smbc_removexattr_fn removexattr_fn; + smbc_listxattr_fn listxattr_fn; +#endif + } posix_emu; + +#if 0 /* Left in libsmbclient.h for backward compatibility */ + /* Printing-related functions */ + struct + { + smbc_print_file_fn print_file_fn; + smbc_open_print_job_fn open_print_job_fn; + smbc_list_print_jobs_fn list_print_jobs_fn; + smbc_unlink_print_job_fn unlink_print_job_fn; + } printing; +#endif + + /* SMB high-level functions */ + struct + { + smbc_splice_fn splice_fn; + smbc_notify_fn notify_fn; + } smb; + + uint16_t port; +}; + +/* Functions in libsmb_cache.c */ +int +SMBC_add_cached_server(SMBCCTX * context, + SMBCSRV * newsrv, + const char * server, + const char * share, + const char * workgroup, + const char * username); + +SMBCSRV * +SMBC_get_cached_server(SMBCCTX * context, + const char * server, + const char * share, + const char * workgroup, + const char * user); + +int +SMBC_remove_cached_server(SMBCCTX * context, + SMBCSRV * server); + +int +SMBC_purge_cached_servers(SMBCCTX * context); + + +/* Functions in libsmb_dir.c */ +int +SMBC_check_options(char *server, + char *share, + char *path, + char *options); + +SMBCFILE * +SMBC_opendir_ctx(SMBCCTX *context, + const char *fname); + +int +SMBC_closedir_ctx(SMBCCTX *context, + SMBCFILE *dir); + +struct smbc_dirent * +SMBC_readdir_ctx(SMBCCTX *context, + SMBCFILE *dir); + +const struct libsmb_file_info * +SMBC_readdirplus_ctx(SMBCCTX *context, + SMBCFILE *dir); + +const struct libsmb_file_info * +SMBC_readdirplus2_ctx(SMBCCTX *context, + SMBCFILE *dir, + struct stat *st); + +int +SMBC_getdents_ctx(SMBCCTX *context, + SMBCFILE *dir, + struct smbc_dirent *dirp, + int count); + +int +SMBC_mkdir_ctx(SMBCCTX *context, + const char *fname, + mode_t mode); + +int +SMBC_rmdir_ctx(SMBCCTX *context, + const char *fname); + +off_t +SMBC_telldir_ctx(SMBCCTX *context, + SMBCFILE *dir); + +int +SMBC_lseekdir_ctx(SMBCCTX *context, + SMBCFILE *dir, + off_t offset); + +int +SMBC_fstatdir_ctx(SMBCCTX *context, + SMBCFILE *dir, + struct stat *st); + +int +SMBC_chmod_ctx(SMBCCTX *context, + const char *fname, + mode_t newmode); + +int +SMBC_utimes_ctx(SMBCCTX *context, + const char *fname, + struct timeval *tbuf); + +int +SMBC_unlink_ctx(SMBCCTX *context, + const char *fname); + +int +SMBC_rename_ctx(SMBCCTX *ocontext, + const char *oname, + SMBCCTX *ncontext, + const char *nname); + +int +SMBC_notify_ctx(SMBCCTX *c, SMBCFILE *dir, smbc_bool recursive, + uint32_t completion_filter, unsigned callback_timeout_ms, + smbc_notify_callback_fn cb, void *private_data); + + + +/* Functions in libsmb_file.c */ +SMBCFILE * +SMBC_open_ctx(SMBCCTX *context, + const char *fname, + int flags, + mode_t mode); + +SMBCFILE * +SMBC_creat_ctx(SMBCCTX *context, + const char *path, + mode_t mode); + +ssize_t +SMBC_read_ctx(SMBCCTX *context, + SMBCFILE *file, + void *buf, + size_t count); + +ssize_t +SMBC_write_ctx(SMBCCTX *context, + SMBCFILE *file, + const void *buf, + size_t count); + +off_t +SMBC_splice_ctx(SMBCCTX *context, + SMBCFILE *srcfile, + SMBCFILE *dstfile, + off_t count, + int (*splice_cb)(off_t n, void *priv), + void *priv); + +int +SMBC_close_ctx(SMBCCTX *context, + SMBCFILE *file); + +NTSTATUS +SMBC_getatr(SMBCCTX * context, + SMBCSRV *srv, + const char *path, + struct stat *sbuf); + +bool +SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path, + struct timespec create_time, + struct timespec access_time, + struct timespec write_time, + struct timespec change_time, + uint16_t mode); + +off_t +SMBC_lseek_ctx(SMBCCTX *context, + SMBCFILE *file, + off_t offset, + int whence); + +int +SMBC_ftruncate_ctx(SMBCCTX *context, + SMBCFILE *file, + off_t length); + + +/* Functions in libsmb_misc.c */ +bool SMBC_dlist_contains(SMBCFILE * list, SMBCFILE *p); + +int +SMBC_errno(SMBCCTX *context, + struct cli_state *c); + + +/* Functions in libsmb_path.c */ +int +SMBC_parse_path(TALLOC_CTX *ctx, + SMBCCTX *context, + const char *fname, + char **pp_workgroup, + char **pp_server, + uint16_t *p_port, + char **pp_share, + char **pp_path, + char **pp_user, + char **pp_password, + char **pp_options); + + +/* Functions in libsmb_printjob.c */ +SMBCFILE * +SMBC_open_print_job_ctx(SMBCCTX *context, + const char *fname); + +int +SMBC_print_file_ctx(SMBCCTX *c_file, + const char *fname, + SMBCCTX *c_print, + const char *printq); + +int +SMBC_list_print_jobs_ctx(SMBCCTX *context, + const char *fname, + smbc_list_print_job_fn fn); + +int +SMBC_unlink_print_job_ctx(SMBCCTX *context, + const char *fname, + int id); + + +/* Functions in libsmb_server.c */ +int +SMBC_check_server(SMBCCTX * context, + SMBCSRV * server); + +int +SMBC_remove_unused_server(SMBCCTX * context, + SMBCSRV * srv); + +void +SMBC_get_auth_data(const char *server, const char *share, + char *workgroup_buf, int workgroup_buf_len, + char *username_buf, int username_buf_len, + char *password_buf, int password_buf_len); + +SMBCSRV * +SMBC_find_server(TALLOC_CTX *ctx, + SMBCCTX *context, + const char *server, + const char *share, + char **pp_workgroup, + char **pp_username, + char **pp_password); + +SMBCSRV * +SMBC_server(TALLOC_CTX *ctx, + SMBCCTX *context, + bool connect_if_not_found, + const char *server, + uint16_t port, + const char *share, + char **pp_workgroup, + char **pp_username, + char **pp_password); + +SMBCSRV * +SMBC_attr_server(TALLOC_CTX *ctx, + SMBCCTX *context, + const char *server, + uint16_t port, + const char *share, + char **pp_workgroup, + char **pp_username, + char **pp_password); + + +/* Functions in libsmb_stat.c */ +void setup_stat(struct stat *st, + const char *fname, + off_t size, + int mode, + ino_t ino, + dev_t dev, + struct timespec access_time_ts, + struct timespec change_time_ts, + struct timespec write_time_ts); +void setup_stat_from_stat_ex(const struct stat_ex *stex, + const char *fname, + struct stat *st); + +int +SMBC_stat_ctx(SMBCCTX *context, + const char *fname, + struct stat *st); + +int +SMBC_fstat_ctx(SMBCCTX *context, + SMBCFILE *file, + struct stat *st); + + +int +SMBC_statvfs_ctx(SMBCCTX *context, + char *path, + struct statvfs *st); + + +int +SMBC_fstatvfs_ctx(SMBCCTX *context, + SMBCFILE *file, + struct statvfs *st); + + +/* Functions in libsmb_xattr.c */ +int +SMBC_setxattr_ctx(SMBCCTX *context, + const char *fname, + const char *name, + const void *value, + size_t size, + int flags); + +int +SMBC_getxattr_ctx(SMBCCTX *context, + const char *fname, + const char *name, + const void *value, + size_t size); + +int +SMBC_removexattr_ctx(SMBCCTX *context, + const char *fname, + const char *name); + +int +SMBC_listxattr_ctx(SMBCCTX *context, + const char *fname, + char *list, + size_t size); + + +#endif diff --git a/source3/include/libsmbclient.h b/source3/include/libsmbclient.h new file mode 100644 index 0000000..84c9808 --- /dev/null +++ b/source3/include/libsmbclient.h @@ -0,0 +1,3280 @@ +/*===================================================================== + Unix SMB/Netbios implementation. + SMB client library API definitions + Copyright (C) Andrew Tridgell 1998 + Copyright (C) Richard Sharpe 2000 + Copyright (C) John Terpsra 2000 + Copyright (C) Tom Jansen (Ninja ISD) 2002 + Copyright (C) Derrell Lipman 2003-2008 + + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see <http://www.gnu.org/licenses/>. + =====================================================================*/ + +#ifndef SMBCLIENT_H_INCLUDED +#define SMBCLIENT_H_INCLUDED + +#undef DEPRECATED_SMBC_INTERFACE +#if ! defined(__LIBSMBCLIENT_INTERNAL__) && defined(__GNUC__) +# define DEPRECATED_SMBC_INTERFACE __attribute__ ((deprecated)) +#else +# define DEPRECATED_SMBC_INTERFACE +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/*-------------------------------------------------------------------*/ +/* The following are special comments to instruct DOXYGEN (automated + * documentation tool: +*/ +/** \defgroup libsmbclient +*/ +/** \defgroup structure Data Structures Type and Constants +* \ingroup libsmbclient +* Data structures, types, and constants +*/ +/** \defgroup callback Callback function types +* \ingroup libsmbclient +* Callback functions +*/ +/** \defgroup file File Functions +* \ingroup libsmbclient +* Functions used to access individual file contents +*/ +/** \defgroup directory Directory Functions +* \ingroup libsmbclient +* Functions used to access directory entries +*/ +/** \defgroup attribute Attributes Functions +* \ingroup libsmbclient +* Functions used to view or change file and directory attributes +*/ +/** \defgroup print Print Functions +* \ingroup libsmbclient +* Functions used to access printing functionality +*/ +/** \defgroup misc Miscellaneous Functions +* \ingroup libsmbclient +* Functions that don't fit in to other categories +*/ +/*-------------------------------------------------------------------*/ + +/* Make sure we have the following includes for now ... */ +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/statvfs.h> +#include <stdint.h> +#include <fcntl.h> +#include <time.h> +#include <utime.h> + +#define SMBC_BASE_FD 10000 /* smallest file descriptor returned */ + +#define SMBC_WORKGROUP 1 +#define SMBC_SERVER 2 +#define SMBC_FILE_SHARE 3 +#define SMBC_PRINTER_SHARE 4 +#define SMBC_COMMS_SHARE 5 +#define SMBC_IPC_SHARE 6 +#define SMBC_DIR 7 +#define SMBC_FILE 8 +#define SMBC_LINK 9 + +/**@ingroup structure + * Structure that represents a directory entry. + * + */ +struct smbc_dirent +{ + /** Type of entity. + SMBC_WORKGROUP=1, + SMBC_SERVER=2, + SMBC_FILE_SHARE=3, + SMBC_PRINTER_SHARE=4, + SMBC_COMMS_SHARE=5, + SMBC_IPC_SHARE=6, + SMBC_DIR=7, + SMBC_FILE=8, + SMBC_LINK=9,*/ + unsigned int smbc_type; + + /** Length of this smbc_dirent in bytes + */ + unsigned int dirlen; + /** The length of the comment string in bytes (does not include + * null terminator) + */ + unsigned int commentlen; + /** Points to the null terminated comment string + */ + char *comment; + /** The length of the name string in bytes (does not include + * null terminator) + */ + unsigned int namelen; + /** Points to the null terminated name string + */ + char name[1]; +}; + +/**@ingroup structure + * Structure that represents all attributes of a directory entry. + * + */ +struct libsmb_file_info +{ + /** + * Size of file + */ + uint64_t size; + /** + * DOS attributes of file + */ + uint16_t attrs; + /** + * User ID of file + */ + uid_t uid; + /** + * Group ID of file + */ + gid_t gid; + /** + * Birth/Create time of file (if supported by system) + * Otherwise the value will be 0 + */ + struct timespec btime_ts; + /** + * Modified time for the file + */ + struct timespec mtime_ts; + /** + * Access time for the file + */ + struct timespec atime_ts; + /** + * Change time for the file + */ + struct timespec ctime_ts; + /** + * Name of file + */ + char *name; + /** + * Short name of file + */ + char *short_name; +}; + +/* + * Logging callback function + */ +typedef void (*smbc_debug_callback_fn)(void *private_ptr, int level, const char *msg); + +/* + * Flags for smbc_setxattr() + * Specify a bitwise OR of these, or 0 to add or replace as necessary + */ +#define SMBC_XATTR_FLAG_CREATE 0x1 /* fail if attr already exists */ +#define SMBC_XATTR_FLAG_REPLACE 0x2 /* fail if attr does not exist */ + + +/* + * Mappings of the DOS mode bits, as returned by smbc_getxattr() when the + * attribute name "system.dos_attr.mode" (or "system.dos_attr.*" or + * "system.*") is specified. + */ +#define SMBC_DOS_MODE_READONLY 0x01 +#define SMBC_DOS_MODE_HIDDEN 0x02 +#define SMBC_DOS_MODE_SYSTEM 0x04 +#define SMBC_DOS_MODE_VOLUME_ID 0x08 +#define SMBC_DOS_MODE_DIRECTORY 0x10 +#define SMBC_DOS_MODE_ARCHIVE 0x20 + +/* + * Valid values for the option "open_share_mode", when calling + * smbc_setOptionOpenShareMode() + */ +typedef enum smbc_share_mode +{ + SMBC_SHAREMODE_DENY_DOS = 0, + SMBC_SHAREMODE_DENY_ALL = 1, + SMBC_SHAREMODE_DENY_WRITE = 2, + SMBC_SHAREMODE_DENY_READ = 3, + SMBC_SHAREMODE_DENY_NONE = 4, + SMBC_SHAREMODE_DENY_FCB = 7 +} smbc_share_mode; + + +/** + * Values for option SMB Encryption Level, as set and retrieved with + * smbc_setOptionSmbEncryptionLevel() and smbc_getOptionSmbEncryptionLevel() + */ +typedef enum smbc_smb_encrypt_level +{ + SMBC_ENCRYPTLEVEL_DEFAULT = -1, + SMBC_ENCRYPTLEVEL_NONE = 0, + SMBC_ENCRYPTLEVEL_REQUEST = 1, + SMBC_ENCRYPTLEVEL_REQUIRE = 2 +} smbc_smb_encrypt_level; + + +/** + * Capabilities set in the f_flag field of struct statvfs, from + * smbc_statvfs(). These may be OR-ed together to reflect a full set of + * available capabilities. + */ +typedef enum smbc_vfs_feature +{ + /* Defined by POSIX or in Linux include files (low-order bits) */ + SMBC_VFS_FEATURE_RDONLY = (1 << 0), + + /* Specific to libsmbclient (high-order bits) */ + SMBC_VFS_FEATURE_DFS = (1 << 28), + SMBC_VFS_FEATURE_CASE_INSENSITIVE = (1 << 29), + SMBC_VFS_FEATURE_NO_UNIXCIFS = (1 << 30) +} smbc_vfs_feature; + +typedef int smbc_bool; + + +#ifndef ENOATTR +# define ENOATTR ENOENT /* No such attribute */ +#endif + + + + +/**@ingroup structure + * Structure that represents a print job. + * + */ +#ifndef _CLIENT_H +struct print_job_info +{ + /** numeric ID of the print job + */ + unsigned short id; + + /** represents print job priority (lower numbers mean higher priority) + */ + unsigned short priority; + + /** Size of the print job + */ + size_t size; + + /** Name of the user that owns the print job + */ + char user[128]; + + /** Name of the print job. This will have no name if an anonymous print + * file was opened. Ie smb://server/printer + */ + char name[128]; + + /** Time the print job was spooled + */ + time_t t; +}; +#endif /* _CLIENT_H */ + + +/**@ingroup structure + * Server handle + */ +typedef struct _SMBCSRV SMBCSRV; + +/**@ingroup structure + * File or directory handle + */ +typedef struct _SMBCFILE SMBCFILE; + +/**@ingroup structure + * File or directory handle + */ +typedef struct _SMBCCTX SMBCCTX; + + +/* + * Flags for SMBCCTX->flags + * + * NEW CODE SHOULD NOT DIRECTLY MANIPULATE THE CONTEXT STRUCTURE. + * Instead, use: + * smbc_setOptionUseKerberos() + * smbc_getOptionUseKerberos() + * smbc_setOptionFallbackAfterKerberos() + * smbc_getOptionFallbackAFterKerberos() + * smbc_setOptionNoAutoAnonymousLogin() + * smbc_getOptionNoAutoAnonymousLogin() + * smbc_setOptionUseCCache() + * smbc_getOptionUseCCache() + */ +# define SMB_CTX_FLAG_USE_KERBEROS (1 << 0) +# define SMB_CTX_FLAG_FALLBACK_AFTER_KERBEROS (1 << 1) +# define SMBCCTX_FLAG_NO_AUTO_ANONYMOUS_LOGON (1 << 2) +# define SMB_CTX_FLAG_USE_CCACHE (1 << 3) + + + +/**@ingroup callback + * Authentication callback function type (traditional method) + * + * Type for the the authentication function called by the library to + * obtain authentication credentials + * + * For kerberos support the function should just be called without + * prompting the user for credentials. Which means a simple 'return' + * should work. Take a look at examples/libsmbclient/get_auth_data_fn.h + * and examples/libsmbclient/testbrowse.c. + * + * @param srv Server being authenticated to + * + * @param shr Share being authenticated to + * + * @param wg Pointer to buffer containing a "hint" for the + * workgroup to be authenticated. Should be filled in + * with the correct workgroup if the hint is wrong. + * + * @param wglen The size of the workgroup buffer in bytes + * + * @param un Pointer to buffer containing a "hint" for the + * user name to be use for authentication. Should be + * filled in with the correct workgroup if the hint is + * wrong. + * + * @param unlen The size of the username buffer in bytes + * + * @param pw Pointer to buffer containing to which password + * copied + * + * @param pwlen The size of the password buffer in bytes + * + */ +typedef void (*smbc_get_auth_data_fn)(const char *srv, + const char *shr, + char *wg, int wglen, + char *un, int unlen, + char *pw, int pwlen); +/**@ingroup callback + * Authentication callback function type (method that includes context) + * + * Type for the the authentication function called by the library to + * obtain authentication credentials + * + * For kerberos support the function should just be called without + * prompting the user for credentials. Which means a simple 'return' + * should work. Take a look at examples/libsmbclient/get_auth_data_fn.h + * and examples/libsmbclient/testbrowse.c. + * + * @param c Pointer to the smb context + * + * @param srv Server being authenticated to + * + * @param shr Share being authenticated to + * + * @param wg Pointer to buffer containing a "hint" for the + * workgroup to be authenticated. Should be filled in + * with the correct workgroup if the hint is wrong. + * + * @param wglen The size of the workgroup buffer in bytes + * + * @param un Pointer to buffer containing a "hint" for the + * user name to be use for authentication. Should be + * filled in with the correct workgroup if the hint is + * wrong. + * + * @param unlen The size of the username buffer in bytes + * + * @param pw Pointer to buffer containing to which password + * copied + * + * @param pwlen The size of the password buffer in bytes + * + */ +typedef void (*smbc_get_auth_data_with_context_fn)(SMBCCTX *c, + const char *srv, + const char *shr, + char *wg, int wglen, + char *un, int unlen, + char *pw, int pwlen); + + +/**@ingroup callback + * Print job info callback function type. + * + * @param i pointer to print job information structure + * + */ +typedef void (*smbc_list_print_job_fn)(struct print_job_info *i); + + +/**@ingroup callback + * Check if a server is still good + * + * @param c pointer to smb context + * + * @param srv pointer to server to check + * + * @return 0 when connection is good. 1 on error. + * + */ +typedef int (*smbc_check_server_fn)(SMBCCTX * c, SMBCSRV *srv); + +/**@ingroup callback + * Remove a server if unused + * + * @param c pointer to smb context + * + * @param srv pointer to server to remove + * + * @return 0 on success. 1 on failure. + * + */ +typedef int (*smbc_remove_unused_server_fn)(SMBCCTX * c, SMBCSRV *srv); + + +/**@ingroup callback + * Add a server to the cache system + * + * @param c pointer to smb context + * + * @param srv pointer to server to add + * + * @param server server name + * + * @param share share name + * + * @param workgroup workgroup used to connect + * + * @param username username used to connect + * + * @return 0 on success. 1 on failure. + * + */ +typedef int (*smbc_add_cached_srv_fn) (SMBCCTX * c, SMBCSRV *srv, + const char * server, const char * share, + const char * workgroup, const char * username); + +/**@ingroup callback + * Look up a server in the cache system + * + * @param c pointer to smb context + * + * @param server server name to match + * + * @param share share name to match + * + * @param workgroup workgroup to match + * + * @param username username to match + * + * @return pointer to SMBCSRV on success. NULL on failure. + * + */ +typedef SMBCSRV * (*smbc_get_cached_srv_fn) (SMBCCTX * c, const char * server, + const char * share, const char * workgroup, + const char * username); + +/**@ingroup callback + * Check if a server is still good + * + * @param c pointer to smb context + * + * @param srv pointer to server to remove + * + * @return 0 when found and removed. 1 on failure. + * + */ +typedef int (*smbc_remove_cached_srv_fn)(SMBCCTX * c, SMBCSRV *srv); + + +/**@ingroup callback + * Try to remove all servers from the cache system and disconnect + * + * @param c pointer to smb context + * + * @return 0 when found and removed. 1 on failure. + * + */ +typedef int (*smbc_purge_cached_fn) (SMBCCTX * c); + + + +/***************************************** + * Getters and setters for CONFIGURATION * + *****************************************/ + +/** Get the debug level */ +int +smbc_getDebug(SMBCCTX *c); + +/** Set the debug level */ +void +smbc_setDebug(SMBCCTX *c, int debug); + +/** + * set log callback function to capture logs from libsmbclient, this + * is applied at global level + */ +void +smbc_setLogCallback(SMBCCTX *c, void *private_ptr, + smbc_debug_callback_fn fn); + +/** set configuration file, this is applied at global level */ +int +smbc_setConfiguration(SMBCCTX *c, const char *file); + +/** Get the netbios name used for making connections */ +const char * +smbc_getNetbiosName(SMBCCTX *c); + +/** Set the netbios name used for making connections */ +void +smbc_setNetbiosName(SMBCCTX *c, const char *netbios_name); + +/** Get the workgroup used for making connections */ +const char * +smbc_getWorkgroup(SMBCCTX *c); + +/** Set the workgroup used for making connections */ +void smbc_setWorkgroup(SMBCCTX *c, const char *workgroup); + +/** Get the username used for making connections */ +const char * +smbc_getUser(SMBCCTX *c); + +/** Set the username used for making connections */ +void +smbc_setUser(SMBCCTX *c, const char *user); + +/** + * Get the timeout used for waiting on connections and response data + * (in milliseconds) + */ +int +smbc_getTimeout(SMBCCTX *c); + +/** + * Set the timeout used for waiting on connections and response data + * (in milliseconds) + */ +void +smbc_setTimeout(SMBCCTX *c, int timeout); + + +/** + * Get the TCP port used to connect (0 means default). + */ +uint16_t +smbc_getPort(SMBCCTX *c); + +/** + * Set the TCP port used to connect (0 means default). + */ +void +smbc_setPort(SMBCCTX *c, uint16_t port); + + + +/*********************************** + * Getters and setters for OPTIONS * + ***********************************/ + +/** Get whether to log to standard error instead of standard output */ +smbc_bool +smbc_getOptionDebugToStderr(SMBCCTX *c); + +/** Set whether to log to standard error instead of standard output */ +void +smbc_setOptionDebugToStderr(SMBCCTX *c, smbc_bool b); + +/** + * Get whether to use new-style time attribute names, e.g. WRITE_TIME rather + * than the old-style names such as M_TIME. This allows also setting/getting + * CREATE_TIME which was previously unimplemented. (Note that the old C_TIME + * was supposed to be CHANGE_TIME but was confused and sometimes referred to + * CREATE_TIME.) + */ +smbc_bool +smbc_getOptionFullTimeNames(SMBCCTX *c); + +/** + * Set whether to use new-style time attribute names, e.g. WRITE_TIME rather + * than the old-style names such as M_TIME. This allows also setting/getting + * CREATE_TIME which was previously unimplemented. (Note that the old C_TIME + * was supposed to be CHANGE_TIME but was confused and sometimes referred to + * CREATE_TIME.) + */ +void +smbc_setOptionFullTimeNames(SMBCCTX *c, smbc_bool b); + +/** + * Get the share mode to use for files opened with SMBC_open_ctx(). The + * default is SMBC_SHAREMODE_DENY_NONE. + */ +smbc_share_mode +smbc_getOptionOpenShareMode(SMBCCTX *c); + +/** + * Set the share mode to use for files opened with SMBC_open_ctx(). The + * default is SMBC_SHAREMODE_DENY_NONE. + */ +void +smbc_setOptionOpenShareMode(SMBCCTX *c, smbc_share_mode share_mode); + +/** Retrieve a previously saved user data handle */ +void * +smbc_getOptionUserData(SMBCCTX *c); + +/** Save a user data handle */ +void +smbc_setOptionUserData(SMBCCTX *c, void *user_data); + +/** Get the encoded value for encryption level. */ +smbc_smb_encrypt_level +smbc_getOptionSmbEncryptionLevel(SMBCCTX *c); + +/** Set the encoded value for encryption level. */ +void +smbc_setOptionSmbEncryptionLevel(SMBCCTX *c, smbc_smb_encrypt_level level); + +/** + * Get whether to treat file names as case-sensitive if we can't determine + * when connecting to the remote share whether the file system is case + * sensitive. This defaults to FALSE since it's most likely that if we can't + * retrieve the file system attributes, it's a very old file system that does + * not support case sensitivity. + */ +smbc_bool +smbc_getOptionCaseSensitive(SMBCCTX *c); + +/** + * Set whether to treat file names as case-sensitive if we can't determine + * when connecting to the remote share whether the file system is case + * sensitive. This defaults to FALSE since it's most likely that if we can't + * retrieve the file system attributes, it's a very old file system that does + * not support case sensitivity. + */ +void +smbc_setOptionCaseSensitive(SMBCCTX *c, smbc_bool b); + + +/** + * Get from how many local master browsers should the list of workgroups be + * retrieved. It can take up to 12 minutes or longer after a server becomes a + * local master browser, for it to have the entire browse list (the list of + * workgroups/domains) from an entire network. Since a client never knows + * which local master browser will be found first, the one which is found + * first and used to retrieve a browse list may have an incomplete or empty + * browse list. By requesting the browse list from multiple local master + * browsers, a more complete list can be generated. For small networks (few + * workgroups), it is recommended that this value be set to 0, causing the + * browse lists from all found local master browsers to be retrieved and + * merged. For networks with many workgroups, a suitable value for this + * variable is probably somewhere around 3. (Default: 3). + */ +int +smbc_getOptionBrowseMaxLmbCount(SMBCCTX *c); + +/** + * Set from how many local master browsers should the list of workgroups be + * retrieved. It can take up to 12 minutes or longer after a server becomes a + * local master browser, for it to have the entire browse list (the list of + * workgroups/domains) from an entire network. Since a client never knows + * which local master browser will be found first, the one which is found + * first and used to retrieve a browse list may have an incomplete or empty + * browse list. By requesting the browse list from multiple local master + * browsers, a more complete list can be generated. For small networks (few + * workgroups), it is recommended that this value be set to 0, causing the + * browse lists from all found local master browsers to be retrieved and + * merged. For networks with many workgroups, a suitable value for this + * variable is probably somewhere around 3. (Default: 3). + */ +void +smbc_setOptionBrowseMaxLmbCount(SMBCCTX *c, int count); + +/** + * Get whether to url-encode readdir entries. + * + * There is a difference in the desired return strings from + * smbc_readdir() depending upon whether the filenames are to + * be displayed to the user, or whether they are to be + * appended to the path name passed to smbc_opendir() to call + * a further smbc_ function (e.g. open the file with + * smbc_open()). In the former case, the filename should be + * in "human readable" form. In the latter case, the smbc_ + * functions expect a URL which must be url-encoded. Those + * functions decode the URL. If, for example, smbc_readdir() + * returned a file name of "abc%20def.txt", passing a path + * with this file name attached to smbc_open() would cause + * smbc_open to attempt to open the file "abc def.txt" since + * the %20 is decoded into a space. + * + * Set this option to True if the names returned by + * smbc_readdir() should be url-encoded such that they can be + * passed back to another smbc_ call. Set it to False if the + * names returned by smbc_readdir() are to be presented to the + * user. + * + * For backwards compatibility, this option defaults to False. + */ +smbc_bool +smbc_getOptionUrlEncodeReaddirEntries(SMBCCTX *c); + +/** + * Set whether to url-encode readdir entries. + * + * There is a difference in the desired return strings from + * smbc_readdir() depending upon whether the filenames are to + * be displayed to the user, or whether they are to be + * appended to the path name passed to smbc_opendir() to call + * a further smbc_ function (e.g. open the file with + * smbc_open()). In the former case, the filename should be + * in "human readable" form. In the latter case, the smbc_ + * functions expect a URL which must be url-encoded. Those + * functions decode the URL. If, for example, smbc_readdir() + * returned a file name of "abc%20def.txt", passing a path + * with this file name attached to smbc_open() would cause + * smbc_open to attempt to open the file "abc def.txt" since + * the %20 is decoded into a space. + * + * Set this option to True if the names returned by + * smbc_readdir() should be url-encoded such that they can be + * passed back to another smbc_ call. Set it to False if the + * names returned by smbc_readdir() are to be presented to the + * user. + * + * For backwards compatibility, this option defaults to False. + */ +void +smbc_setOptionUrlEncodeReaddirEntries(SMBCCTX *c, smbc_bool b); + +/** + * Get whether to use the same connection for all shares on a server. + * + * Some Windows versions appear to have a limit to the number + * of concurrent SESSIONs and/or TREE CONNECTions. In + * one-shot programs (i.e. the program runs and then quickly + * ends, thereby shutting down all connections), it is + * probably reasonable to establish a new connection for each + * share. In long-running applications, the limitation can be + * avoided by using only a single connection to each server, + * and issuing a new TREE CONNECT when the share is accessed. + */ +smbc_bool +smbc_getOptionOneSharePerServer(SMBCCTX *c); + +/** + * Set whether to use the same connection for all shares on a server. + * + * Some Windows versions appear to have a limit to the number + * of concurrent SESSIONs and/or TREE CONNECTions. In + * one-shot programs (i.e. the program runs and then quickly + * ends, thereby shutting down all connections), it is + * probably reasonable to establish a new connection for each + * share. In long-running applications, the limitation can be + * avoided by using only a single connection to each server, + * and issuing a new TREE CONNECT when the share is accessed. + */ +void +smbc_setOptionOneSharePerServer(SMBCCTX *c, smbc_bool b); + +/** Get whether to enable use of kerberos */ +smbc_bool +smbc_getOptionUseKerberos(SMBCCTX *c); + +/** Set whether to enable use of kerberos */ +void +smbc_setOptionUseKerberos(SMBCCTX *c, smbc_bool b); + +/** Get whether to fallback after kerberos */ +smbc_bool +smbc_getOptionFallbackAfterKerberos(SMBCCTX *c); + +/** Set whether to fallback after kerberos */ +void +smbc_setOptionFallbackAfterKerberos(SMBCCTX *c, smbc_bool b); + +/** Get whether to automatically select anonymous login */ +smbc_bool +smbc_getOptionNoAutoAnonymousLogin(SMBCCTX *c); + +/** Set whether to automatically select anonymous login */ +void +smbc_setOptionNoAutoAnonymousLogin(SMBCCTX *c, smbc_bool b); + +/** Get whether to enable use of the winbind ccache */ +smbc_bool +smbc_getOptionUseCCache(SMBCCTX *c); + +/** Set whether to enable use of the winbind ccache */ +void +smbc_setOptionUseCCache(SMBCCTX *c, smbc_bool b); + +/** Get indication that the password supplied is the NT hash */ +smbc_bool +smbc_getOptionUseNTHash(SMBCCTX *c); + +/** Set indication that the password supplied is the NT hash */ +void +smbc_setOptionUseNTHash(SMBCCTX *c, smbc_bool b); + +/** + * @brief Set the 'client min protocol' and the 'client max protocol'. + * + * IMPORTANT: This overrrides the values 'client min protocol' and 'client max + * protocol' set in the smb.conf file! + * + * @param[in] c The smbc context to use. + * + * @param[in] min_proto The minimal protocol to use or NULL for leaving it + * untouched. + * + * @param[in] max_proto The maximum protocol to use or NULL for leaving it + * untouched. + * + * @returns true for success, false otherwise + */ +smbc_bool +smbc_setOptionProtocols(SMBCCTX *c, const char *min_proto, const char *max_proto); + +/************************************* + * Getters and setters for FUNCTIONS * + *************************************/ + +/** Get the function for obtaining authentication data */ +smbc_get_auth_data_fn smbc_getFunctionAuthData(SMBCCTX *c); + +/** Set the function for obtaining authentication data */ +void smbc_setFunctionAuthData(SMBCCTX *c, smbc_get_auth_data_fn fn); + +/** Get the new-style authentication function which includes the context. */ +smbc_get_auth_data_with_context_fn +smbc_getFunctionAuthDataWithContext(SMBCCTX *c); + +/** Set the new-style authentication function which includes the context. */ +void +smbc_setFunctionAuthDataWithContext(SMBCCTX *c, + smbc_get_auth_data_with_context_fn fn); + +/** Get the function for checking if a server is still good */ +smbc_check_server_fn smbc_getFunctionCheckServer(SMBCCTX *c); + +/** Set the function for checking if a server is still good */ +void smbc_setFunctionCheckServer(SMBCCTX *c, smbc_check_server_fn fn); + +/** Get the function for removing a server if unused */ +smbc_remove_unused_server_fn smbc_getFunctionRemoveUnusedServer(SMBCCTX *c); + +/** Set the function for removing a server if unused */ +void smbc_setFunctionRemoveUnusedServer(SMBCCTX *c, + smbc_remove_unused_server_fn fn); + +/** Get the function for adding a cached server */ +smbc_add_cached_srv_fn smbc_getFunctionAddCachedServer(SMBCCTX *c); + +/** Set the function for adding a cached server */ +void smbc_setFunctionAddCachedServer(SMBCCTX *c, smbc_add_cached_srv_fn fn); + +/** Get the function for server cache lookup */ +smbc_get_cached_srv_fn smbc_getFunctionGetCachedServer(SMBCCTX *c); + +/** Set the function for server cache lookup */ +void smbc_setFunctionGetCachedServer(SMBCCTX *c, smbc_get_cached_srv_fn fn); + +/** Get the function for server cache removal */ +smbc_remove_cached_srv_fn smbc_getFunctionRemoveCachedServer(SMBCCTX *c); + +/** Set the function for server cache removal */ +void smbc_setFunctionRemoveCachedServer(SMBCCTX *c, + smbc_remove_cached_srv_fn fn); + +/** + * Get the function for server cache purging. This function tries to + * remove all cached servers (e.g. on disconnect) + */ +smbc_purge_cached_fn smbc_getFunctionPurgeCachedServers(SMBCCTX *c); + +/** + * Set the function for server cache purging. This function tries to + * remove all cached servers (e.g. on disconnect) + */ +void smbc_setFunctionPurgeCachedServers(SMBCCTX *c, + smbc_purge_cached_fn fn); + +/** Get the function to store private data of the server cache */ +struct smbc_server_cache * smbc_getServerCacheData(SMBCCTX *c); + +/** Set the function to store private data of the server cache */ +void smbc_setServerCacheData(SMBCCTX *c, struct smbc_server_cache * cache); + + + +/***************************************************************** + * Callable functions for files. * + * Each callable has a function signature typedef, a declaration * + * for the getter, and a declaration for the setter. * + *****************************************************************/ + +typedef SMBCFILE * (*smbc_open_fn)(SMBCCTX *c, + const char *fname, + int flags, + mode_t mode); +smbc_open_fn smbc_getFunctionOpen(SMBCCTX *c); +void smbc_setFunctionOpen(SMBCCTX *c, smbc_open_fn fn); + +typedef SMBCFILE * (*smbc_creat_fn)(SMBCCTX *c, + const char *path, + mode_t mode); +smbc_creat_fn smbc_getFunctionCreat(SMBCCTX *c); +void smbc_setFunctionCreat(SMBCCTX *c, smbc_creat_fn); + +typedef ssize_t (*smbc_read_fn)(SMBCCTX *c, + SMBCFILE *file, + void *buf, + size_t count); +smbc_read_fn smbc_getFunctionRead(SMBCCTX *c); +void smbc_setFunctionRead(SMBCCTX *c, smbc_read_fn fn); + +typedef ssize_t (*smbc_write_fn)(SMBCCTX *c, + SMBCFILE *file, + const void *buf, + size_t count); +smbc_write_fn smbc_getFunctionWrite(SMBCCTX *c); +void smbc_setFunctionWrite(SMBCCTX *c, smbc_write_fn fn); + +typedef off_t (*smbc_splice_fn)(SMBCCTX *c, + SMBCFILE *srcfile, + SMBCFILE *dstfile, + off_t count, + int (*splice_cb)(off_t n, void *priv), + void *priv); +smbc_splice_fn smbc_getFunctionSplice(SMBCCTX *c); +void smbc_setFunctionSplice(SMBCCTX *c, smbc_splice_fn fn); + +typedef int (*smbc_unlink_fn)(SMBCCTX *c, + const char *fname); +smbc_unlink_fn smbc_getFunctionUnlink(SMBCCTX *c); +void smbc_setFunctionUnlink(SMBCCTX *c, smbc_unlink_fn fn); + +typedef int (*smbc_rename_fn)(SMBCCTX *ocontext, + const char *oname, + SMBCCTX *ncontext, + const char *nname); +smbc_rename_fn smbc_getFunctionRename(SMBCCTX *c); +void smbc_setFunctionRename(SMBCCTX *c, smbc_rename_fn fn); + +typedef off_t (*smbc_lseek_fn)(SMBCCTX *c, + SMBCFILE * file, + off_t offset, + int whence); +smbc_lseek_fn smbc_getFunctionLseek(SMBCCTX *c); +void smbc_setFunctionLseek(SMBCCTX *c, smbc_lseek_fn fn); + +typedef int (*smbc_stat_fn)(SMBCCTX *c, + const char *fname, + struct stat *st); +smbc_stat_fn smbc_getFunctionStat(SMBCCTX *c); +void smbc_setFunctionStat(SMBCCTX *c, smbc_stat_fn fn); + +typedef int (*smbc_fstat_fn)(SMBCCTX *c, + SMBCFILE *file, + struct stat *st); +smbc_fstat_fn smbc_getFunctionFstat(SMBCCTX *c); +void smbc_setFunctionFstat(SMBCCTX *c, smbc_fstat_fn fn); + +typedef int (*smbc_statvfs_fn)(SMBCCTX *c, + char *path, + struct statvfs *st); +smbc_statvfs_fn smbc_getFunctionStatVFS(SMBCCTX *c); +void smbc_setFunctionStatVFS(SMBCCTX *c, smbc_statvfs_fn fn); + +typedef int (*smbc_fstatvfs_fn)(SMBCCTX *c, + SMBCFILE *file, + struct statvfs *st); +smbc_fstatvfs_fn smbc_getFunctionFstatVFS(SMBCCTX *c); +void smbc_setFunctionFstatVFS(SMBCCTX *c, smbc_fstatvfs_fn fn); + +typedef int (*smbc_ftruncate_fn)(SMBCCTX *c, + SMBCFILE *f, + off_t size); +smbc_ftruncate_fn smbc_getFunctionFtruncate(SMBCCTX *c); +void smbc_setFunctionFtruncate(SMBCCTX *c, smbc_ftruncate_fn fn); + +typedef int (*smbc_close_fn)(SMBCCTX *c, + SMBCFILE *file); +smbc_close_fn smbc_getFunctionClose(SMBCCTX *c); +void smbc_setFunctionClose(SMBCCTX *c, smbc_close_fn fn); + + + +/***************************************************************** + * Callable functions for directories. * + * Each callable has a function signature typedef, a declaration * + * for the getter, and a declaration for the setter. * + *****************************************************************/ + +typedef SMBCFILE * (*smbc_opendir_fn)(SMBCCTX *c, + const char *fname); +smbc_opendir_fn smbc_getFunctionOpendir(SMBCCTX *c); +void smbc_setFunctionOpendir(SMBCCTX *c, smbc_opendir_fn fn); + +typedef int (*smbc_closedir_fn)(SMBCCTX *c, + SMBCFILE *dir); +smbc_closedir_fn smbc_getFunctionClosedir(SMBCCTX *c); +void smbc_setFunctionClosedir(SMBCCTX *c, smbc_closedir_fn fn); + +typedef struct smbc_dirent * (*smbc_readdir_fn)(SMBCCTX *c, + SMBCFILE *dir); +smbc_readdir_fn smbc_getFunctionReaddir(SMBCCTX *c); +void smbc_setFunctionReaddir(SMBCCTX *c, smbc_readdir_fn fn); + +typedef const struct libsmb_file_info * (*smbc_readdirplus_fn)(SMBCCTX *c, + SMBCFILE *dir); +smbc_readdirplus_fn smbc_getFunctionReaddirPlus(SMBCCTX *c); +void smbc_setFunctionReaddirPlus(SMBCCTX *c, smbc_readdirplus_fn fn); + +typedef const struct libsmb_file_info * (*smbc_readdirplus2_fn)(SMBCCTX *c, + SMBCFILE *dir, + struct stat *st); +smbc_readdirplus2_fn smbc_getFunctionReaddirPlus2(SMBCCTX *c); +void smbc_setFunctionReaddirPlus2(SMBCCTX *c, smbc_readdirplus2_fn fn); + +typedef int (*smbc_getdents_fn)(SMBCCTX *c, + SMBCFILE *dir, + struct smbc_dirent *dirp, + int count); +smbc_getdents_fn smbc_getFunctionGetdents(SMBCCTX *c); +void smbc_setFunctionGetdents(SMBCCTX *c, smbc_getdents_fn fn); + +typedef int (*smbc_mkdir_fn)(SMBCCTX *c, + const char *fname, + mode_t mode); +smbc_mkdir_fn smbc_getFunctionMkdir(SMBCCTX *c); +void smbc_setFunctionMkdir(SMBCCTX *c, smbc_mkdir_fn fn); + +typedef int (*smbc_rmdir_fn)(SMBCCTX *c, + const char *fname); +smbc_rmdir_fn smbc_getFunctionRmdir(SMBCCTX *c); +void smbc_setFunctionRmdir(SMBCCTX *c, smbc_rmdir_fn fn); + +typedef off_t (*smbc_telldir_fn)(SMBCCTX *c, + SMBCFILE *dir); +smbc_telldir_fn smbc_getFunctionTelldir(SMBCCTX *c); +void smbc_setFunctionTelldir(SMBCCTX *c, smbc_telldir_fn fn); + +typedef int (*smbc_lseekdir_fn)(SMBCCTX *c, + SMBCFILE *dir, + off_t offset); +smbc_lseekdir_fn smbc_getFunctionLseekdir(SMBCCTX *c); +void smbc_setFunctionLseekdir(SMBCCTX *c, smbc_lseekdir_fn fn); + +typedef int (*smbc_fstatdir_fn)(SMBCCTX *c, + SMBCFILE *dir, + struct stat *st); +smbc_fstatdir_fn smbc_getFunctionFstatdir(SMBCCTX *c); +void smbc_setFunctionFstatdir(SMBCCTX *c, smbc_fstatdir_fn fn); + +#define SMBC_NOTIFY_ACTION_ADDED 1 +#define SMBC_NOTIFY_ACTION_REMOVED 2 +#define SMBC_NOTIFY_ACTION_MODIFIED 3 +#define SMBC_NOTIFY_ACTION_OLD_NAME 4 +#define SMBC_NOTIFY_ACTION_NEW_NAME 5 +#define SMBC_NOTIFY_ACTION_ADDED_STREAM 6 +#define SMBC_NOTIFY_ACTION_REMOVED_STREAM 7 +#define SMBC_NOTIFY_ACTION_MODIFIED_STREAM 8 + +struct smbc_notify_callback_action { + uint32_t action; + const char *filename; +}; + +typedef int (*smbc_notify_callback_fn)( + const struct smbc_notify_callback_action *actions, + size_t num_actions, void *private_data); + +typedef int (*smbc_notify_fn)(SMBCCTX *c, SMBCFILE *dir, smbc_bool recursive, + uint32_t completion_filter, + unsigned callback_timeout_ms, + smbc_notify_callback_fn cb, void *private_data); +smbc_notify_fn smbc_getFunctionNotify(SMBCCTX *c); +void smbc_setFunctionNotify(SMBCCTX *c, smbc_notify_fn fn); + + +/***************************************************************** + * Callable functions applicable to both files and directories. * + * Each callable has a function signature typedef, a declaration * + * for the getter, and a declaration for the setter. * + *****************************************************************/ + +typedef int (*smbc_chmod_fn)(SMBCCTX *c, + const char *fname, + mode_t mode); +smbc_chmod_fn smbc_getFunctionChmod(SMBCCTX *c); +void smbc_setFunctionChmod(SMBCCTX *c, smbc_chmod_fn fn); + +typedef int (*smbc_utimes_fn)(SMBCCTX *c, + const char *fname, + struct timeval *tbuf); +smbc_utimes_fn smbc_getFunctionUtimes(SMBCCTX *c); +void smbc_setFunctionUtimes(SMBCCTX *c, smbc_utimes_fn fn); + +typedef int (*smbc_setxattr_fn)(SMBCCTX *context, + const char *fname, + const char *name, + const void *value, + size_t size, + int flags); +smbc_setxattr_fn smbc_getFunctionSetxattr(SMBCCTX *c); +void smbc_setFunctionSetxattr(SMBCCTX *c, smbc_setxattr_fn fn); + +typedef int (*smbc_getxattr_fn)(SMBCCTX *context, + const char *fname, + const char *name, + const void *value, + size_t size); +smbc_getxattr_fn smbc_getFunctionGetxattr(SMBCCTX *c); +void smbc_setFunctionGetxattr(SMBCCTX *c, smbc_getxattr_fn fn); + +typedef int (*smbc_removexattr_fn)(SMBCCTX *context, + const char *fname, + const char *name); +smbc_removexattr_fn smbc_getFunctionRemovexattr(SMBCCTX *c); +void smbc_setFunctionRemovexattr(SMBCCTX *c, smbc_removexattr_fn fn); + +typedef int (*smbc_listxattr_fn)(SMBCCTX *context, + const char *fname, + char *list, + size_t size); +smbc_listxattr_fn smbc_getFunctionListxattr(SMBCCTX *c); +void smbc_setFunctionListxattr(SMBCCTX *c, smbc_listxattr_fn fn); + + + +/***************************************************************** + * Callable functions for printing. * + * Each callable has a function signature typedef, a declaration * + * for the getter, and a declaration for the setter. * + *****************************************************************/ + +typedef int (*smbc_print_file_fn)(SMBCCTX *c_file, + const char *fname, + SMBCCTX *c_print, + const char *printq); +smbc_print_file_fn smbc_getFunctionPrintFile(SMBCCTX *c); +void smbc_setFunctionPrintFile(SMBCCTX *c, smbc_print_file_fn fn); + +typedef SMBCFILE * (*smbc_open_print_job_fn)(SMBCCTX *c, + const char *fname); +smbc_open_print_job_fn smbc_getFunctionOpenPrintJob(SMBCCTX *c); +void smbc_setFunctionOpenPrintJob(SMBCCTX *c, + smbc_open_print_job_fn fn); + +typedef int (*smbc_list_print_jobs_fn)(SMBCCTX *c, + const char *fname, + smbc_list_print_job_fn fn); +smbc_list_print_jobs_fn smbc_getFunctionListPrintJobs(SMBCCTX *c); +void smbc_setFunctionListPrintJobs(SMBCCTX *c, + smbc_list_print_jobs_fn fn); + +typedef int (*smbc_unlink_print_job_fn)(SMBCCTX *c, + const char *fname, + int id); +smbc_unlink_print_job_fn smbc_getFunctionUnlinkPrintJob(SMBCCTX *c); +void smbc_setFunctionUnlinkPrintJob(SMBCCTX *c, + smbc_unlink_print_job_fn fn); + + +/**@ingroup misc + * Create a new SBMCCTX (a context). + * + * Must be called before the context is passed to smbc_context_init() + * + * @return The given SMBCCTX pointer on success, NULL on error with errno set: + * - ENOMEM Out of memory + * + * @see smbc_free_context(), smbc_init_context() + * + * @note Do not forget to smbc_init_context() the returned SMBCCTX pointer ! + */ +SMBCCTX * smbc_new_context(void); + +/**@ingroup misc + * Delete a SBMCCTX (a context) acquired from smbc_new_context(). + * + * The context will be deleted if possible. + * + * @param context A pointer to a SMBCCTX obtained from smbc_new_context() + * + * @param shutdown_ctx If 1, all connections and files will be closed even if they are busy. + * + * + * @return Returns 0 on succes. Returns 1 on failure with errno set: + * - EBUSY Server connections are still used, Files are open or cache + * could not be purged + * - EBADF context == NULL + * + * @see smbc_new_context() + * + * @note It is advised to clean up all the contexts with shutdown_ctx set to 1 + * just before exit()'ing. When shutdown_ctx is 0, this function can be + * use in periodical cleanup functions for example. + */ +int smbc_free_context(SMBCCTX * context, int shutdown_ctx); + + +/**@ingroup misc + * + * @deprecated. Use smbc_setOption*() functions instead. + */ +void +smbc_option_set(SMBCCTX *context, + char *option_name, + ... /* option_value */); + +/* + * @deprecated. Use smbc_getOption*() functions instead. + */ +void * +smbc_option_get(SMBCCTX *context, + char *option_name); + +/**@ingroup misc + * Initialize a SBMCCTX (a context). + * + * Must be called before using any SMBCCTX API function + * + * @param context A pointer to a SMBCCTX obtained from smbc_new_context() + * + * @return A pointer to the given SMBCCTX on success, + * NULL on error with errno set: + * - EBADF NULL context given + * - ENOMEM Out of memory + * - ENOENT The smb.conf file would not load + * + * @see smbc_new_context() + * + * @note my_context = smbc_init_context(smbc_new_context()) + * is perfectly safe, but it might leak memory on + * smbc_context_init() failure. Avoid this. + * You'll have to call smbc_free_context() yourself + * on failure. + */ + +SMBCCTX * smbc_init_context(SMBCCTX * context); + +/**@ingroup misc + * Initialize the samba client library. + * + * Must be called before using any of the smbclient API function + * + * @param fn The function that will be called to obtaion + * authentication credentials. + * + * @param debug Allows caller to set the debug level. Can be + * changed in smb.conf file. Allows caller to set + * debugging if no smb.conf. + * + * @return 0 on success, < 0 on error with errno set: + * - ENOMEM Out of memory + * - ENOENT The smb.conf file would not load + * + */ + +int smbc_init(smbc_get_auth_data_fn fn, int debug); + +/**@ingroup misc + * Set or retrieve the compatibility library's context pointer + * + * @param context New context to use, or NULL. If a new context is provided, + * it must have allocated with smbc_new_context() and + * initialized with smbc_init_context(), followed, optionally, + * by some manual changes to some of the non-internal fields. + * + * @return The old context. + * + * @see smbc_new_context(), smbc_init_context(), smbc_init() + * + * @note This function may be called prior to smbc_init() to force + * use of the next context without any internal calls to + * smbc_new_context() or smbc_init_context(). It may also + * be called after smbc_init() has already called those two + * functions, to replace the existing context with a new one. + * Care should be taken, in this latter case, to ensure that + * the server cache and any data allocated by the + * authentication functions have been freed, if necessary. + */ + +SMBCCTX * smbc_set_context(SMBCCTX * new_context); + +/**@ingroup file + * Open a file on an SMB server. + * + * @param furl The smb url of the file to be opened. + * + * @param flags Is one of O_RDONLY, O_WRONLY or O_RDWR which + * request opening the file read-only,write-only + * or read/write. flags may also be bitwise-or'd with + * one or more of the following: + * O_CREAT - If the file does not exist it will be + * created. + * O_EXCL - When used with O_CREAT, if the file + * already exists it is an error and the open will + * fail. + * O_TRUNC - If the file already exists it will be + * truncated. + * O_APPEND The file is opened in append mode + * + * @param mode mode specifies the permissions to use if a new + * file is created. It is modified by the + * process's umask in the usual way: the permissions + * of the created file are (mode & ~umask) + * + * Not currently use, but there for future use. + * We will map this to SYSTEM, HIDDEN, etc bits + * that reverses the mapping that smbc_fstat does. + * + * @return Valid file handle, < 0 on error with errno set: + * - ENOMEM Out of memory + * - EINVAL if an invalid parameter passed, like no + * file, or smbc_init not called. + * - EEXIST pathname already exists and O_CREAT and + * O_EXCL were used. + * - EISDIR pathname refers to a directory and + * the access requested involved writing. + * - EACCES The requested access to the file is not + * allowed + * - ENODEV The requested share does not exist + * - ENOTDIR A file on the path is not a directory + * - ENOENT A directory component in pathname does + * not exist. + * + * @see smbc_creat() + * + * @note This call uses an underlying routine that may create + * a new connection to the server specified in the URL. + * If the credentials supplied in the URL, or via the + * auth_fn in the smbc_init call, fail, this call will + * try again with an empty username and password. This + * often gets mapped to the guest account on some machines. + */ + +int smbc_open(const char *furl, int flags, mode_t mode); + +/**@ingroup file + * Create a file on an SMB server. + * + * Same as calling smbc_open() with flags = O_CREAT|O_WRONLY|O_TRUNC + * + * @param furl The smb url of the file to be created + * + * @param mode mode specifies the permissions to use if a new + * file is created. It is modified by the + * process's umask in the usual way: the permissions + * of the created file are (mode & ~umask) + * + * NOTE, the above is not true. We are dealing with + * an SMB server, which has no concept of a umask! + * + * @return Valid file handle, < 0 on error with errno set: + * - ENOMEM Out of memory + * - EINVAL if an invalid parameter passed, like no + * file, or smbc_init not called. + * - EEXIST pathname already exists and O_CREAT and + * O_EXCL were used. + * - EISDIR pathname refers to a directory and + * the access requested involved writing. + * - EACCES The requested access to the file is not + * allowed + * - ENOENT A directory component in pathname does + * not exist. + * - ENODEV The requested share does not exist. + * @see smbc_open() + * + */ + +int smbc_creat(const char *furl, mode_t mode); + +/**@ingroup file + * Read from a file using an opened file handle. + * + * @param fd Open file handle from smbc_open() or smbc_creat() + * + * @param buf Pointer to buffer to receive read data + * + * @param bufsize Size of buf in bytes + * + * @return Number of bytes read; + * 0 upon EOF; + * < 0 on error, with errno set: + * - EISDIR fd refers to a directory + * - EBADF fd is not a valid file descriptor or + * is not open for reading. + * - EINVAL fd is attached to an object which is + * unsuitable for reading, or no buffer passed or + * smbc_init not called. + * + * @see smbc_open(), smbc_write() + * + */ +ssize_t smbc_read(int fd, void *buf, size_t bufsize); + + +/**@ingroup file + * Write to a file using an opened file handle. + * + * @param fd Open file handle from smbc_open() or smbc_creat() + * + * @param buf Pointer to buffer to recieve read data + * + * @param bufsize Size of buf in bytes + * + * @return Number of bytes written, < 0 on error with errno set: + * - EISDIR fd refers to a directory. + * - EBADF fd is not a valid file descriptor or + * is not open for reading. + * - EINVAL fd is attached to an object which is + * unsuitable for reading, or no buffer passed or + * smbc_init not called. + * + * @see smbc_open(), smbc_read() + * + */ +ssize_t smbc_write(int fd, const void *buf, size_t bufsize); + + +/**@ingroup file + * Seek to a specific location in a file. + * + * @param fd Open file handle from smbc_open() or smbc_creat() + * + * @param offset Offset in bytes from whence + * + * @param whence A location in the file: + * - SEEK_SET The offset is set to offset bytes from + * the beginning of the file + * - SEEK_CUR The offset is set to current location + * plus offset bytes. + * - SEEK_END The offset is set to the size of the + * file plus offset bytes. + * + * @return Upon successful completion, lseek returns the + * resulting offset location as measured in bytes + * from the beginning of the file. Otherwise, a value + * of (off_t)-1 is returned and errno is set to + * indicate the error: + * - EBADF Fildes is not an open file descriptor. + * - EINVAL Whence is not a proper value or smbc_init + * not called. + * + * @todo Are all the whence values really supported? + * + * @todo Are errno values complete and correct? + */ +off_t smbc_lseek(int fd, off_t offset, int whence); + + +/**@ingroup file + * Close an open file handle. + * + * @param fd The file handle to close + * + * @return 0 on success, < 0 on error with errno set: + * - EBADF fd isn't a valid open file descriptor + * - EINVAL smbc_init() failed or has not been called + * + * @see smbc_open(), smbc_creat() + */ +int smbc_close(int fd); + + +/**@ingroup directory + * Unlink (delete) a file or directory. + * + * @param furl The smb url of the file to delete + * + * @return 0 on success, < 0 on error with errno set: + * - EACCES or EPERM Write access to the directory + * containing pathname is not allowed or one + * of the directories in pathname did not allow + * search (execute) permission + * - ENOENT A directory component in pathname does + * not exist + * - EINVAL NULL was passed in the file param or + * smbc_init not called. + * - EACCES You do not have access to the file + * - ENOMEM Insufficient kernel memory was available + * + * @see smbc_rmdir()s + * + * @todo Are errno values complete and correct? + */ +int smbc_unlink(const char *furl); + + +/**@ingroup directory + * Rename or move a file or directory. + * + * @param ourl The original smb url (source url) of file or + * directory to be moved + * + * @param nurl The new smb url (destination url) of the file + * or directory after the move. Currently nurl must + * be on the same share as ourl. + * + * @return 0 on success, < 0 on error with errno set: + * - EISDIR nurl is an existing directory, but ourl is + * not a directory. + * - EEXIST nurl is a non-empty directory, + * i.e., contains entries other than "." and ".." + * - EINVAL The new url contained a path prefix + * of the old, or, more generally, an attempt was + * made to make a directory a subdirectory of itself + * or smbc_init not called. + * - ENOTDIR A component used as a directory in ourl + * or nurl path is not, in fact, a directory. Or, + * ourl is a directory, and newpath exists but is not + * a directory. + * - EACCES or EPERM Write access to the directory + * containing ourl or nurl is not allowed for the + * process's effective uid, or one of the + * directories in ourl or nurl did not allow search + * (execute) permission, or ourl was a directory + * and did not allow write permission. + * - ENOENT A directory component in ourl or nurl + * does not exist. + * - EXDEV Rename across shares not supported. + * - ENOMEM Insufficient kernel memory was available. + * - EEXIST The target file, nurl, already exists. + * + * + * @todo Are we going to support copying when urls are not on the same + * share? I say no... NOTE. I agree for the moment. + * + */ +int smbc_rename(const char *ourl, const char *nurl); + + +/**@ingroup directory + * Open a directory used to obtain directory entries. + * + * @param durl The smb url of the directory to open + * + * @return Valid directory handle. < 0 on error with errno set: + * - EACCES Permission denied. + * - EINVAL A NULL file/URL was passed, or the URL would + * not parse, or was of incorrect form or smbc_init not + * called. + * - ENOENT durl does not exist, or name is an + * - ENOMEM Insufficient memory to complete the + * operation. + * - ENOTDIR name is not a directory. + * - EPERM the workgroup could not be found. + * - ENODEV the workgroup or server could not be found. + * + * @see smbc_getdents(), smbc_readdir(), smbc_closedir() + * + */ +int smbc_opendir(const char *durl); + + +/**@ingroup directory + * Close a directory handle opened by smbc_opendir(). + * + * @param dh Directory handle to close + * + * @return 0 on success, < 0 on error with errno set: + * - EBADF dh is an invalid directory handle + * + * @see smbc_opendir() + */ +int smbc_closedir(int dh); + + +/**@ingroup directory + * Get multiple directory entries. + * + * smbc_getdents() reads as many dirent structures from the an open + * directory handle into a specified memory area as will fit. + * + * @param dh Valid directory as returned by smbc_opendir() + * + * @param dirp pointer to buffer that will receive the directory + * entries. + * + * @param count The size of the dirp buffer in bytes + * + * @returns If any dirents returned, return will indicate the + * total size. If there were no more dirents available, + * 0 is returned. < 0 indicates an error. + * - EBADF Invalid directory handle + * - EINVAL Result buffer is too small or smbc_init + * not called. + * - ENOENT No such directory. + * @see , smbc_dirent, smbc_readdir(), smbc_open() + * + * @todo Are errno values complete and correct? + * + * @todo Add example code so people know how to parse buffers. + */ +int smbc_getdents(unsigned int dh, struct smbc_dirent *dirp, int count); + + +/**@ingroup directory + * Get a single directory entry. + * + * @param dh Valid directory as returned by smbc_opendir() + * + * @return A pointer to a smbc_dirent structure, or NULL if an + * error occurs or end-of-directory is reached: + * - EBADF Invalid directory handle + * - EINVAL smbc_init() failed or has not been called + * + * @see smbc_dirent, smbc_getdents(), smbc_open() + */ +struct smbc_dirent* smbc_readdir(unsigned int dh); + +/**@ingroup directory + * Works similar as smbc_readdir() but returns more information about file. + * + * @param dh Valid directory as returned by smbc_opendir() + * + * @return A const pointer to a libsmb_file_info structure, + * or NULL if an error occurs or end-of-directory is reached: + * - EBADF Invalid directory handle + * - EINVAL smbc_init() failed or has not been called + * + * @see smbc_open(), smbc_readdir() + */ +const struct libsmb_file_info *smbc_readdirplus(unsigned int dh); + +/**@ingroup directory + * Works similar as smbc_readdirplus() as well as fills up stat structure if + * provided. + * + * @param dh Valid directory as returned by smbc_opendir() + * + * @param stat Pointer to stat structure which will receive the + * information. If this pointer is null the call + * is identical to smbc_readdirplus. + * + * @return A const pointer to a libsmb_file_info structure, + * or NULL if an error occurs or end-of-directory is reached: + * - EBADF Invalid directory handle + * - EINVAL smbc_init() failed or has not been called + * + * @see smbc_open(), smbc_readdir(), smbc_readdirplus2() + */ +const struct libsmb_file_info *smbc_readdirplus2(unsigned int dh, + struct stat *st); + +/**@ingroup directory + * Get the current directory offset. + * + * smbc_telldir() may be used in conjunction with smbc_readdir() and + * smbc_lseekdir(). + * + * @param dh Valid directory as returned by smbc_opendir() + * + * @return The current location in the directory stream or -1 + * if an error occur. The current location is not + * an offset. Becuase of the implementation, it is a + * handle that allows the library to find the entry + * later. + * - EBADF dh is not a valid directory handle + * - EINVAL smbc_init() failed or has not been called + * - ENOTDIR if dh is not a directory + * + * @see smbc_readdir() + * + */ +off_t smbc_telldir(int dh); + + +/**@ingroup directory + * lseek on directories. + * + * smbc_lseekdir() may be used in conjunction with smbc_readdir() and + * smbc_telldir(). (rewind by smbc_lseekdir(fd, NULL)) + * + * @param fd Valid directory as returned by smbc_opendir() + * + * @param offset The offset (as returned by smbc_telldir). Can be + * NULL, in which case we will rewind + * + * @return 0 on success, -1 on failure + * - EBADF dh is not a valid directory handle + * - ENOTDIR if dh is not a directory + * - EINVAL offset did not refer to a valid dirent or + * smbc_init not called. + * + * @see smbc_telldir() + * + * + * @todo In what does the reture and errno values mean? + */ +int smbc_lseekdir(int fd, off_t offset); + +/**@ingroup directory + * Create a directory. + * + * @param durl The url of the directory to create + * + * @param mode Specifies the permissions to use. It is modified + * by the process's umask in the usual way: the + * permissions of the created file are (mode & ~umask). + * + * @return 0 on success, < 0 on error with errno set: + * - EEXIST directory url already exists + * - EACCES The parent directory does not allow write + * permission to the process, or one of the directories + * - ENOENT A directory component in pathname does not + * exist. + * - EINVAL NULL durl passed or smbc_init not called. + * - ENOMEM Insufficient memory was available. + * + * @see smbc_rmdir() + * + */ +int smbc_mkdir(const char *durl, mode_t mode); + + +/**@ingroup directory + * Remove a directory. + * + * @param durl The smb url of the directory to remove + * + * @return 0 on success, < 0 on error with errno set: + * - EACCES or EPERM Write access to the directory + * containing pathname was not allowed. + * - EINVAL durl is NULL or smbc_init not called. + * - ENOENT A directory component in pathname does not + * exist. + * - ENOTEMPTY directory contains entries. + * - ENOMEM Insufficient kernel memory was available. + * + * @see smbc_mkdir(), smbc_unlink() + * + * @todo Are errno values complete and correct? + */ +int smbc_rmdir(const char *durl); + +/**@ingroup directory + * Request directory notifications + * + * @param dh Valid directory as returned by smbc_opendir() + * + * @param recursive Are changes in subdirectories wanted? + * + * @param completion_filter Bitwise-or of the SMBC_NOTIFY_CHANGE_* + * events that are interesting + * + * @param callback_timeout_ms If set to non-zero, interval in milliseconds + * that "cb" will be called with 0 actions. + * This gives "cb" the chance to cancel the + * smbc_notify call. + * + * @param cb Callback functions taking events. If "cb" + * returns nonzero, smbc_notify will return. + * + * @param private_data Pointer given to "cb" + * + * @return 0 on success, -1 on error with errno set + * + * @see smbc_opendir(), smbc_closedir() + */ + +#define SMBC_NOTIFY_CHANGE_FILE_NAME 0x001 +#define SMBC_NOTIFY_CHANGE_DIR_NAME 0x002 +#define SMBC_NOTIFY_CHANGE_ATTRIBUTES 0x004 +#define SMBC_NOTIFY_CHANGE_SIZE 0x008 +#define SMBC_NOTIFY_CHANGE_LAST_WRITE 0x010 +#define SMBC_NOTIFY_CHANGE_LAST_ACCESS 0x020 +#define SMBC_NOTIFY_CHANGE_CREATION 0x040 +#define SMBC_NOTIFY_CHANGE_EA 0x080 +#define SMBC_NOTIFY_CHANGE_SECURITY 0x100 +#define SMBC_NOTIFY_CHANGE_STREAM_NAME 0x200 +#define SMBC_NOTIFY_CHANGE_STREAM_SIZE 0x400 +#define SMBC_NOTIFY_CHANGE_STREAM_WRITE 0x800 + +int smbc_notify(int dh, smbc_bool recursive, uint32_t completion_filter, + unsigned callback_timeout_ms, + smbc_notify_callback_fn cb, void *private_data); + +/**@ingroup attribute + * Get information about a file or directory. + * + * @param url The smb url to get information for + * + * @param st pointer to a buffer that will be filled with + * standard Unix struct stat information. + * + * @return 0 on success, < 0 on error with errno set: + * - ENOENT A component of the path file_name does not + * exist. + * - EINVAL a NULL url was passed or smbc_init not called. + * - EACCES Permission denied. + * - ENOMEM Out of memory + * - ENOTDIR The target dir, url, is not a directory. + * + * @see Unix stat() + * + */ +int smbc_stat(const char *url, struct stat *st); + + +/**@ingroup attribute + * Get file information via an file descriptor. + * + * @param fd Open file handle from smbc_open() or smbc_creat() + * + * @param st pointer to a buffer that will be filled with + * standard Unix struct stat information. + * + * @return 0 on success, < 0 on error with errno set: + * - EBADF filedes is bad. + * - EACCES Permission denied. + * - EBADF fd is not a valid file descriptor + * - EINVAL Problems occurred in the underlying routines + * or smbc_init not called. + * - ENOMEM Out of memory + * + * @see smbc_stat(), Unix stat() + * + */ +int smbc_fstat(int fd, struct stat *st); + + +/**@ingroup attribute + * Get file system information for a specified path. + * + * @param url The smb url to get information for + * + * @param st pointer to a buffer that will be filled with + * standard Unix struct statvfs information. + * + * @return 0 on success, < 0 on error with errno set: + * - EBADF filedes is bad. + * - EACCES Permission denied. + * - EBADF fd is not a valid file descriptor + * - EINVAL Problems occurred in the underlying routines + * or smbc_init not called. + * - ENOMEM Out of memory + * + * @see Unix fstatvfs() + * + */ +int +smbc_statvfs(char *url, + struct statvfs *st); + +/**@ingroup attribute + * Get file system information via an file descriptor. + * + * @param fd Open file handle from smbc_open(), smbc_creat(), + * or smbc_opendir() + * + * @param st pointer to a buffer that will be filled with + * standard Unix struct statvfs information. + * + * @return 0 on success, < 0 on error with errno set: + * - EBADF filedes is bad. + * - EACCES Permission denied. + * - EBADF fd is not a valid file descriptor + * - EINVAL Problems occurred in the underlying routines + * or smbc_init not called. + * - ENOMEM Out of memory + * + * @see Unix fstatvfs() + * + */ +int +smbc_fstatvfs(int fd, + struct statvfs *st); + + +/**@ingroup attribute + * Truncate a file given a file descriptor + * + * @param fd Open file handle from smbc_open() or smbc_creat() + * + * @param size size to truncate the file to + * + * @return 0 on success, < 0 on error with errno set: + * - EBADF filedes is bad. + * - EACCES Permission denied. + * - EBADF fd is not a valid file descriptor + * - EINVAL Problems occurred in the underlying routines + * or smbc_init not called. + * - ENOMEM Out of memory + * + * @see , Unix ftruncate() + * + */ +int smbc_ftruncate(int fd, off_t size); + + +/**@ingroup attribute + * Change the permissions of a file. + * + * @param url The smb url of the file or directory to change + * permissions of + * + * @param mode The permissions to set: + * - Put good explaination of permissions here! + * + * @return 0 on success, < 0 on error with errno set: + * - EPERM The effective UID does not match the owner + * of the file, and is not zero + * - ENOENT The file does not exist. + * - ENOMEM Insufficient was available. + * - ENOENT file or directory does not exist + * + * @todo Actually implement this fuction? + * + * @todo Are errno values complete and correct? + */ +int smbc_chmod(const char *url, mode_t mode); + +/** + * @ingroup attribute + * Change the last modification time on a file + * + * @param url The smb url of the file or directory to change + * the modification time of + * + * @param tbuf An array of two timeval structures which contains, + * respectively, the desired access and modification times. + * NOTE: Only the tv_sec field off each timeval structure is + * used. The tv_usec (microseconds) portion is ignored. + * + * @return 0 on success, < 0 on error with errno set: + * - EINVAL The client library is not properly initialized + * - EPERM Permission was denied. + * + */ +int smbc_utimes(const char *url, struct timeval *tbuf); + +#ifdef HAVE_UTIME_H +/** + * @ingroup attribute + * Change the last modification time on a file + * + * @param url The smb url of the file or directory to change + * the modification time of + * + * @param utbuf A pointer to a utimebuf structure which contains the + * desired access and modification times. + * + * @return 0 on success, < 0 on error with errno set: + * - EINVAL The client library is not properly initialized + * - ENOMEM No memory was available for internal needs + * - EPERM Permission was denied. + * + */ +int smbc_utime(const char *fname, struct utimbuf *utbuf); +#endif + +/**@ingroup attribute + * Set extended attributes for a file. This is used for modifying a file's + * security descriptor (i.e. owner, group, and access control list) + * + * @param url The smb url of the file or directory to set extended + * attributes for. + * + * @param name The name of an attribute to be changed. Names are of + * one of the following forms: + * + * system.nt_sec_desc.<attribute name> + * system.nt_sec_desc.* + * system.nt_sec_desc.*+ + * + * where <attribute name> is one of: + * + * revision + * owner + * owner+ + * group + * group+ + * acl:<name or sid> + * acl+:<name or sid> + * + * In the forms "system.nt_sec_desc.*" and + * "system.nt_sec_desc.*+", the asterisk and plus signs are + * literal, i.e. the string is provided exactly as shown, and + * the value parameter should contain a complete security + * descriptor with name:value pairs separated by tabs, + * commas, or newlines (not spaces!). + * + * The plus sign ('+') indicates that SIDs should be mapped + * to names. Without the plus sign, SIDs are not mapped; + * rather they are simply converted to a string format. + * + * @param value The value to be assigned to the specified attribute name. + * This buffer should contain only the attribute value if the + * name was of the "system.nt_sec_desc.<attribute_name>" + * form. If the name was of the "system.nt_sec_desc.*" form + * then a complete security descriptor, with name:value pairs + * separated by tabs, commas, or newlines (not spaces!), + * should be provided in this value buffer. A complete + * security descriptor will contain one or more entries + * selected from the following: + * + * REVISION:<revision number> + * OWNER:<sid or name> + * GROUP:<sid or name> + * ACL:<sid or name>:<type>/<flags>/<mask> + * + * The revision of the ACL specifies the internal Windows NT + * ACL revision for the security descriptor. If not specified + * it defaults to 1. Using values other than 1 may cause + * strange behaviour. + * + * The owner and group specify the owner and group sids for + * the object. If the attribute name (either '*+' with a + * complete security descriptor, or individual 'owner+' or + * 'group+' attribute names) ended with a plus sign, the + * specified name is resolved to a SID value, using the + * server on which the file or directory resides. Otherwise, + * the value should be provided in SID-printable format as + * S-1-x-y-z, and is used directly. The <sid or name> + * associated with the ACL: attribute should be provided + * similarly. + * + * @param size The number of the bytes of data in the value buffer + * + * @param flags A bit-wise OR of zero or more of the following: + * SMBC_XATTR_FLAG_CREATE - + * fail if the named attribute already exists + * SMBC_XATTR_FLAG_REPLACE - + * fail if the attribute does not already exist + * + * If neither flag is specified, the specified attributes + * will be added or replace existing attributes of the same + * name, as necessary. + * + * @return 0 on success, < 0 on error with errno set: + * - EINVAL The client library is not properly initialized + * or one of the parameters is not of a correct + * form + * - ENOMEM No memory was available for internal needs + * - EEXIST If the attribute already exists and the flag + * SMBC_XATTR_FLAG_CREAT was specified + * - ENOATTR If the attribute does not exist and the flag + * SMBC_XATTR_FLAG_REPLACE was specified + * - EPERM Permission was denied. + * - ENOTSUP The referenced file system does not support + * extended attributes + * + * @note Attribute names are compared in a case-insensitive + * fashion. All of the following are equivalent, although + * the all-lower-case name is the preferred format: + * system.nt_sec_desc.owner + * SYSTEM.NT_SEC_DESC.OWNER + * sYsTeM.nt_sEc_desc.owNER + * + */ +int smbc_setxattr(const char *url, + const char *name, + const void *value, + size_t size, + int flags); + + +/**@ingroup attribute + * Set extended attributes for a file. This is used for modifying a file's + * security descriptor (i.e. owner, group, and access control list). The + * POSIX function which this maps to would act on a symbolic link rather than + * acting on what the symbolic link points to, but with no symbolic links in + * SMB file systems, this function is functionally identical to + * smbc_setxattr(). + * + * @param url The smb url of the file or directory to set extended + * attributes for. + * + * @param name The name of an attribute to be changed. Names are of + * one of the following forms: + * + * system.nt_sec_desc.<attribute name> + * system.nt_sec_desc.* + * system.nt_sec_desc.*+ + * + * where <attribute name> is one of: + * + * revision + * owner + * owner+ + * group + * group+ + * acl:<name or sid> + * acl+:<name or sid> + * + * In the forms "system.nt_sec_desc.*" and + * "system.nt_sec_desc.*+", the asterisk and plus signs are + * literal, i.e. the string is provided exactly as shown, and + * the value parameter should contain a complete security + * descriptor with name:value pairs separated by tabs, + * commas, or newlines (not spaces!). + * + * The plus sign ('+') indicates that SIDs should be mapped + * to names. Without the plus sign, SIDs are not mapped; + * rather they are simply converted to a string format. + * + * @param value The value to be assigned to the specified attribute name. + * This buffer should contain only the attribute value if the + * name was of the "system.nt_sec_desc.<attribute_name>" + * form. If the name was of the "system.nt_sec_desc.*" form + * then a complete security descriptor, with name:value pairs + * separated by tabs, commas, or newlines (not spaces!), + * should be provided in this value buffer. A complete + * security descriptor will contain one or more entries + * selected from the following: + * + * REVISION:<revision number> + * OWNER:<sid or name> + * GROUP:<sid or name> + * ACL:<sid or name>:<type>/<flags>/<mask> + * + * The revision of the ACL specifies the internal Windows NT + * ACL revision for the security descriptor. If not specified + * it defaults to 1. Using values other than 1 may cause + * strange behaviour. + * + * The owner and group specify the owner and group sids for + * the object. If the attribute name (either '*+' with a + * complete security descriptor, or individual 'owner+' or + * 'group+' attribute names) ended with a plus sign, the + * specified name is resolved to a SID value, using the + * server on which the file or directory resides. Otherwise, + * the value should be provided in SID-printable format as + * S-1-x-y-z, and is used directly. The <sid or name> + * associated with the ACL: attribute should be provided + * similarly. + * + * @param size The number of the bytes of data in the value buffer + * + * @param flags A bit-wise OR of zero or more of the following: + * SMBC_XATTR_FLAG_CREATE - + * fail if the named attribute already exists + * SMBC_XATTR_FLAG_REPLACE - + * fail if the attribute does not already exist + * + * If neither flag is specified, the specified attributes + * will be added or replace existing attributes of the same + * name, as necessary. + * + * @return 0 on success, < 0 on error with errno set: + * - EINVAL The client library is not properly initialized + * or one of the parameters is not of a correct + * form + * - ENOMEM No memory was available for internal needs + * - EEXIST If the attribute already exists and the flag + * SMBC_XATTR_FLAG_CREAT was specified + * - ENOATTR If the attribute does not exist and the flag + * SMBC_XATTR_FLAG_REPLACE was specified + * - EPERM Permission was denied. + * - ENOTSUP The referenced file system does not support + * extended attributes + * + * @note Attribute names are compared in a case-insensitive + * fashion. All of the following are equivalent, although + * the all-lower-case name is the preferred format: + * system.nt_sec_desc.owner + * SYSTEM.NT_SEC_DESC.OWNER + * sYsTeM.nt_sEc_desc.owNER + * + */ +int smbc_lsetxattr(const char *url, + const char *name, + const void *value, + size_t size, + int flags); + + +/**@ingroup attribute + * Set extended attributes for a file. This is used for modifying a file's + * security descriptor (i.e. owner, group, and access control list) + * + * @param fd A file descriptor associated with an open file (as + * previously returned by smbc_open(), to get extended + * attributes for. + * + * @param name The name of an attribute to be changed. Names are of + * one of the following forms: + * + * system.nt_sec_desc.<attribute name> + * system.nt_sec_desc.* + * system.nt_sec_desc.*+ + * + * where <attribute name> is one of: + * + * revision + * owner + * owner+ + * group + * group+ + * acl:<name or sid> + * acl+:<name or sid> + * + * In the forms "system.nt_sec_desc.*" and + * "system.nt_sec_desc.*+", the asterisk and plus signs are + * literal, i.e. the string is provided exactly as shown, and + * the value parameter should contain a complete security + * descriptor with name:value pairs separated by tabs, + * commas, or newlines (not spaces!). + * + * The plus sign ('+') indicates that SIDs should be mapped + * to names. Without the plus sign, SIDs are not mapped; + * rather they are simply converted to a string format. + * + * @param value The value to be assigned to the specified attribute name. + * This buffer should contain only the attribute value if the + * name was of the "system.nt_sec_desc.<attribute_name>" + * form. If the name was of the "system.nt_sec_desc.*" form + * then a complete security descriptor, with name:value pairs + * separated by tabs, commas, or newlines (not spaces!), + * should be provided in this value buffer. A complete + * security descriptor will contain one or more entries + * selected from the following: + * + * REVISION:<revision number> + * OWNER:<sid or name> + * GROUP:<sid or name> + * ACL:<sid or name>:<type>/<flags>/<mask> + * + * The revision of the ACL specifies the internal Windows NT + * ACL revision for the security descriptor. If not specified + * it defaults to 1. Using values other than 1 may cause + * strange behaviour. + * + * The owner and group specify the owner and group sids for + * the object. If the attribute name (either '*+' with a + * complete security descriptor, or individual 'owner+' or + * 'group+' attribute names) ended with a plus sign, the + * specified name is resolved to a SID value, using the + * server on which the file or directory resides. Otherwise, + * the value should be provided in SID-printable format as + * S-1-x-y-z, and is used directly. The <sid or name> + * associated with the ACL: attribute should be provided + * similarly. + * + * @param size The number of the bytes of data in the value buffer + * + * @param flags A bit-wise OR of zero or more of the following: + * SMBC_XATTR_FLAG_CREATE - + * fail if the named attribute already exists + * SMBC_XATTR_FLAG_REPLACE - + * fail if the attribute does not already exist + * + * If neither flag is specified, the specified attributes + * will be added or replace existing attributes of the same + * name, as necessary. + * + * @return 0 on success, < 0 on error with errno set: + * - EINVAL The client library is not properly initialized + * or one of the parameters is not of a correct + * form + * - ENOMEM No memory was available for internal needs + * - EEXIST If the attribute already exists and the flag + * SMBC_XATTR_FLAG_CREAT was specified + * - ENOATTR If the attribute does not exist and the flag + * SMBC_XATTR_FLAG_REPLACE was specified + * - EPERM Permission was denied. + * - ENOTSUP The referenced file system does not support + * extended attributes + * + * @note Attribute names are compared in a case-insensitive + * fashion. All of the following are equivalent, although + * the all-lower-case name is the preferred format: + * system.nt_sec_desc.owner + * SYSTEM.NT_SEC_DESC.OWNER + * sYsTeM.nt_sEc_desc.owNER + * + */ +int smbc_fsetxattr(int fd, + const char *name, + const void *value, + size_t size, + int flags); + + +/**@ingroup attribute + * Get extended attributes for a file. + * + * @param url The smb url of the file or directory to get extended + * attributes for. + * + * @param name The name of an attribute to be retrieved. Names are of + * one of the following forms: + * + * system.nt_sec_desc.<attribute name> + * system.nt_sec_desc.* + * system.nt_sec_desc.*+ + * + * where <attribute name> is one of: + * + * revision + * owner + * owner+ + * group + * group+ + * acl:<name or sid> + * acl+:<name or sid> + * + * In the forms "system.nt_sec_desc.*" and + * "system.nt_sec_desc.*+", the asterisk and plus signs are + * literal, i.e. the string is provided exactly as shown, and + * the value parameter will return a complete security + * descriptor with name:value pairs separated by tabs, + * commas, or newlines (not spaces!). + * + * The plus sign ('+') indicates that SIDs should be mapped + * to names. Without the plus sign, SIDs are not mapped; + * rather they are simply converted to a string format. + * + * @param value A pointer to a buffer in which the value of the specified + * attribute will be placed (unless size is zero). + * + * @param size The size of the buffer pointed to by value. This parameter + * may also be zero, in which case the size of the buffer + * required to hold the attribute value will be returned, + * but nothing will be placed into the value buffer. + * + * @return 0 on success, < 0 on error with errno set: + * - EINVAL The client library is not properly initialized + * or one of the parameters is not of a correct + * form + * - ENOMEM No memory was available for internal needs + * - EEXIST If the attribute already exists and the flag + * SMBC_XATTR_FLAG_CREAT was specified + * - ENOATTR If the attribute does not exist and the flag + * SMBC_XATTR_FLAG_REPLACE was specified + * - EPERM Permission was denied. + * - ENOTSUP The referenced file system does not support + * extended attributes + * + */ +int smbc_getxattr(const char *url, + const char *name, + const void *value, + size_t size); + + +/**@ingroup attribute + * Get extended attributes for a file. The POSIX function which this maps to + * would act on a symbolic link rather than acting on what the symbolic link + * points to, but with no symbolic links in SMB file systems, this function + * is functionally identical to smbc_getxattr(). + * + * @param url The smb url of the file or directory to get extended + * attributes for. + * + * @param name The name of an attribute to be retrieved. Names are of + * one of the following forms: + * + * system.nt_sec_desc.<attribute name> + * system.nt_sec_desc.* + * system.nt_sec_desc.*+ + * + * where <attribute name> is one of: + * + * revision + * owner + * owner+ + * group + * group+ + * acl:<name or sid> + * acl+:<name or sid> + * + * In the forms "system.nt_sec_desc.*" and + * "system.nt_sec_desc.*+", the asterisk and plus signs are + * literal, i.e. the string is provided exactly as shown, and + * the value parameter will return a complete security + * descriptor with name:value pairs separated by tabs, + * commas, or newlines (not spaces!). + * + * The plus sign ('+') indicates that SIDs should be mapped + * to names. Without the plus sign, SIDs are not mapped; + * rather they are simply converted to a string format. + * + * @param value A pointer to a buffer in which the value of the specified + * attribute will be placed (unless size is zero). + * + * @param size The size of the buffer pointed to by value. This parameter + * may also be zero, in which case the size of the buffer + * required to hold the attribute value will be returned, + * but nothing will be placed into the value buffer. + * + * @return 0 on success, < 0 on error with errno set: + * - EINVAL The client library is not properly initialized + * or one of the parameters is not of a correct + * form + * - ENOMEM No memory was available for internal needs + * - EEXIST If the attribute already exists and the flag + * SMBC_XATTR_FLAG_CREAT was specified + * - ENOATTR If the attribute does not exist and the flag + * SMBC_XATTR_FLAG_REPLACE was specified + * - EPERM Permission was denied. + * - ENOTSUP The referenced file system does not support + * extended attributes + * + */ +int smbc_lgetxattr(const char *url, + const char *name, + const void *value, + size_t size); + + +/**@ingroup attribute + * Get extended attributes for a file. + * + * @param fd A file descriptor associated with an open file (as + * previously returned by smbc_open(), to get extended + * attributes for. + * + * @param name The name of an attribute to be retrieved. Names are of + * one of the following forms: + * + * system.nt_sec_desc.<attribute name> + * system.nt_sec_desc.* + * system.nt_sec_desc.*+ + * + * where <attribute name> is one of: + * + * revision + * owner + * owner+ + * group + * group+ + * acl:<name or sid> + * acl+:<name or sid> + * + * In the forms "system.nt_sec_desc.*" and + * "system.nt_sec_desc.*+", the asterisk and plus signs are + * literal, i.e. the string is provided exactly as shown, and + * the value parameter will return a complete security + * descriptor with name:value pairs separated by tabs, + * commas, or newlines (not spaces!). + * + * The plus sign ('+') indicates that SIDs should be mapped + * to names. Without the plus sign, SIDs are not mapped; + * rather they are simply converted to a string format. + * + * @param value A pointer to a buffer in which the value of the specified + * attribute will be placed (unless size is zero). + * + * @param size The size of the buffer pointed to by value. This parameter + * may also be zero, in which case the size of the buffer + * required to hold the attribute value will be returned, + * but nothing will be placed into the value buffer. + * + * @return 0 on success, < 0 on error with errno set: + * - EINVAL The client library is not properly initialized + * or one of the parameters is not of a correct + * form + * - ENOMEM No memory was available for internal needs + * - EEXIST If the attribute already exists and the flag + * SMBC_XATTR_FLAG_CREAT was specified + * - ENOATTR If the attribute does not exist and the flag + * SMBC_XATTR_FLAG_REPLACE was specified + * - EPERM Permission was denied. + * - ENOTSUP The referenced file system does not support + * extended attributes + * + */ +int smbc_fgetxattr(int fd, + const char *name, + const void *value, + size_t size); + + +/**@ingroup attribute + * Remove extended attributes for a file. This is used for modifying a file's + * security descriptor (i.e. owner, group, and access control list) + * + * @param url The smb url of the file or directory to remove the extended + * attributes for. + * + * @param name The name of an attribute to be removed. Names are of + * one of the following forms: + * + * system.nt_sec_desc.<attribute name> + * system.nt_sec_desc.* + * system.nt_sec_desc.*+ + * + * where <attribute name> is one of: + * + * revision + * owner + * owner+ + * group + * group+ + * acl:<name or sid> + * acl+:<name or sid> + * + * In the forms "system.nt_sec_desc.*" and + * "system.nt_sec_desc.*+", the asterisk and plus signs are + * literal, i.e. the string is provided exactly as shown, and + * the value parameter will return a complete security + * descriptor with name:value pairs separated by tabs, + * commas, or newlines (not spaces!). + * + * The plus sign ('+') indicates that SIDs should be mapped + * to names. Without the plus sign, SIDs are not mapped; + * rather they are simply converted to a string format. + * + * @return 0 on success, < 0 on error with errno set: + * - EINVAL The client library is not properly initialized + * - ENOMEM No memory was available for internal needs + * - EPERM Permission was denied. + * - ENOTSUP The referenced file system does not support + * extended attributes + * + */ +int smbc_removexattr(const char *url, + const char *name); + + +/**@ingroup attribute + * Remove extended attributes for a file. This is used for modifying a file's + * security descriptor (i.e. owner, group, and access control list) The POSIX + * function which this maps to would act on a symbolic link rather than acting + * on what the symbolic link points to, but with no symbolic links in SMB file + * systems, this function is functionally identical to smbc_removexattr(). + * + * @param url The smb url of the file or directory to remove the extended + * attributes for. + * + * @param name The name of an attribute to be removed. Names are of + * one of the following forms: + * + * system.nt_sec_desc.<attribute name> + * system.nt_sec_desc.* + * system.nt_sec_desc.*+ + * + * where <attribute name> is one of: + * + * revision + * owner + * owner+ + * group + * group+ + * acl:<name or sid> + * acl+:<name or sid> + * + * In the forms "system.nt_sec_desc.*" and + * "system.nt_sec_desc.*+", the asterisk and plus signs are + * literal, i.e. the string is provided exactly as shown, and + * the value parameter will return a complete security + * descriptor with name:value pairs separated by tabs, + * commas, or newlines (not spaces!). + * + * The plus sign ('+') indicates that SIDs should be mapped + * to names. Without the plus sign, SIDs are not mapped; + * rather they are simply converted to a string format. + * + * @return 0 on success, < 0 on error with errno set: + * - EINVAL The client library is not properly initialized + * - ENOMEM No memory was available for internal needs + * - EPERM Permission was denied. + * - ENOTSUP The referenced file system does not support + * extended attributes + * + */ +int smbc_lremovexattr(const char *url, + const char *name); + + +/**@ingroup attribute + * Remove extended attributes for a file. This is used for modifying a file's + * security descriptor (i.e. owner, group, and access control list) + * + * @param fd A file descriptor associated with an open file (as + * previously returned by smbc_open(), to get extended + * attributes for. + * + * @param name The name of an attribute to be removed. Names are of + * one of the following forms: + * + * system.nt_sec_desc.<attribute name> + * system.nt_sec_desc.* + * system.nt_sec_desc.*+ + * + * where <attribute name> is one of: + * + * revision + * owner + * owner+ + * group + * group+ + * acl:<name or sid> + * acl+:<name or sid> + * + * In the forms "system.nt_sec_desc.*" and + * "system.nt_sec_desc.*+", the asterisk and plus signs are + * literal, i.e. the string is provided exactly as shown, and + * the value parameter will return a complete security + * descriptor with name:value pairs separated by tabs, + * commas, or newlines (not spaces!). + * + * The plus sign ('+') indicates that SIDs should be mapped + * to names. Without the plus sign, SIDs are not mapped; + * rather they are simply converted to a string format. + * + * @return 0 on success, < 0 on error with errno set: + * - EINVAL The client library is not properly initialized + * - ENOMEM No memory was available for internal needs + * - EPERM Permission was denied. + * - ENOTSUP The referenced file system does not support + * extended attributes + * + */ +int smbc_fremovexattr(int fd, + const char *name); + + +/**@ingroup attribute + * List the supported extended attribute names associated with a file + * + * @param url The smb url of the file or directory to list the extended + * attributes for. + * + * @param list A pointer to a buffer in which the list of attributes for + * the specified file or directory will be placed (unless + * size is zero). + * + * @param size The size of the buffer pointed to by list. This parameter + * may also be zero, in which case the size of the buffer + * required to hold all of the attribute names will be + * returned, but nothing will be placed into the list buffer. + * + * @return 0 on success, < 0 on error with errno set: + * - EINVAL The client library is not properly initialized + * - ENOMEM No memory was available for internal needs + * - EPERM Permission was denied. + * - ENOTSUP The referenced file system does not support + * extended attributes + * + * @note This function always returns all attribute names supported + * by NT file systems, regardless of whether the referenced + * file system supports extended attributes (e.g. a Windows + * 2000 machine supports extended attributes if NTFS is used, + * but not if FAT is used, and Windows 98 doesn't support + * extended attributes at all. Whether this is a feature or + * a bug is yet to be decided. + */ +int smbc_listxattr(const char *url, + char *list, + size_t size); + +/**@ingroup attribute + * List the supported extended attribute names associated with a file The + * POSIX function which this maps to would act on a symbolic link rather than + * acting on what the symbolic link points to, but with no symbolic links in + * SMB file systems, this function is functionally identical to + * smbc_listxattr(). + * + * @param url The smb url of the file or directory to list the extended + * attributes for. + * + * @param list A pointer to a buffer in which the list of attributes for + * the specified file or directory will be placed (unless + * size is zero). + * + * @param size The size of the buffer pointed to by list. This parameter + * may also be zero, in which case the size of the buffer + * required to hold all of the attribute names will be + * returned, but nothing will be placed into the list buffer. + * + * @return 0 on success, < 0 on error with errno set: + * - EINVAL The client library is not properly initialized + * - ENOMEM No memory was available for internal needs + * - EPERM Permission was denied. + * - ENOTSUP The referenced file system does not support + * extended attributes + * + * @note This function always returns all attribute names supported + * by NT file systems, regardless of whether the referenced + * file system supports extended attributes (e.g. a Windows + * 2000 machine supports extended attributes if NTFS is used, + * but not if FAT is used, and Windows 98 doesn't support + * extended attributes at all. Whether this is a feature or + * a bug is yet to be decided. + */ +int smbc_llistxattr(const char *url, + char *list, + size_t size); + +/**@ingroup attribute + * List the supported extended attribute names associated with a file + * + * @param fd A file descriptor associated with an open file (as + * previously returned by smbc_open(), to get extended + * attributes for. + * + * @param list A pointer to a buffer in which the list of attributes for + * the specified file or directory will be placed (unless + * size is zero). + * + * @param size The size of the buffer pointed to by list. This parameter + * may also be zero, in which case the size of the buffer + * required to hold all of the attribute names will be + * returned, but nothing will be placed into the list buffer. + * + * @return 0 on success, < 0 on error with errno set: + * - EINVAL The client library is not properly initialized + * - ENOMEM No memory was available for internal needs + * - EPERM Permission was denied. + * - ENOTSUP The referenced file system does not support + * extended attributes + * + * @note This function always returns all attribute names supported + * by NT file systems, regardless of whether the referenced + * file system supports extended attributes (e.g. a Windows + * 2000 machine supports extended attributes if NTFS is used, + * but not if FAT is used, and Windows 98 doesn't support + * extended attributes at all. Whether this is a feature or + * a bug is yet to be decided. + */ +int smbc_flistxattr(int fd, + char *list, + size_t size); + +/**@ingroup print + * Print a file given the name in fname. It would be a URL ... + * + * @param fname The URL of a file on a remote SMB server that the + * caller wants printed + * + * @param printq The URL of the print share to print the file to. + * + * @return 0 on success, < 0 on error with errno set: + * + * - EINVAL fname or printq was NULL or smbc_init not + * not called. + * and errors returned by smbc_open + * + */ +int smbc_print_file(const char *fname, const char *printq); + +/**@ingroup print + * Open a print file that can be written to by other calls. This simply + * does an smbc_open call after checking if there is a file name on the + * URI. If not, a temporary name is added ... + * + * @param fname The URL of the print share to print to? + * + * @returns A file handle for the print file if successful. + * Returns -1 if an error ocurred and errno has the values + * - EINVAL fname was NULL or smbc_init not called. + * - all errors returned by smbc_open + * + */ +int smbc_open_print_job(const char *fname); + +/**@ingroup print + * List the print jobs on a print share, for the moment, pass a callback + * + * @param purl The url of the print share to list the jobs of + * + * @param fn Callback function the receives printjob info + * + * @return 0 on success, < 0 on error with errno set: + * - EINVAL fname was NULL or smbc_init not called + * - EACCES ??? + */ +int smbc_list_print_jobs(const char *purl, smbc_list_print_job_fn fn); + +/**@ingroup print + * Delete a print job + * + * @param purl Url of the print share + * + * @param id The id of the job to delete + * + * @return 0 on success, < 0 on error with errno set: + * - EINVAL fname was NULL or smbc_init not called + * + * @todo what errno values are possible here? + */ +int smbc_unlink_print_job(const char *purl, int id); + +/**@ingroup callback + * Remove a server from the cached server list it's unused. + * + * @param context pointer to smb context + * + * @param srv pointer to server to remove + * + * @return On success, 0 is returned. 1 is returned if the server could not + * be removed. Also useable outside libsmbclient. + */ +int smbc_remove_unused_server(SMBCCTX * context, SMBCSRV * srv); + +#ifdef __cplusplus +} +#endif + +/**@ingroup directory + * Convert strings of %xx to their single character equivalent. + * + * @param dest A pointer to a buffer in which the resulting decoded + * string should be placed. This may be a pointer to the + * same buffer as src_segment. + * + * @param src A pointer to the buffer containing the URL to be decoded. + * Any %xx sequences herein are converted to their single + * character equivalent. Each 'x' must be a valid hexadecimal + * digit, or that % sequence is left undecoded. + * + * @param max_dest_len + * The size of the buffer pointed to by dest_segment. + * + * @return The number of % sequences which could not be converted + * due to lack of two following hexadecimal digits. + */ +#ifdef __cplusplus +extern "C" { +#endif +int +smbc_urldecode(char *dest, char * src, size_t max_dest_len); +#ifdef __cplusplus +} +#endif + + +/* + * Convert any characters not specifically allowed in a URL into their %xx + * equivalent. + * + * @param dest A pointer to a buffer in which the resulting encoded + * string should be placed. Unlike smbc_urldecode(), this + * must be a buffer unique from src. + * + * @param src A pointer to the buffer containing the string to be encoded. + * Any character not specifically allowed in a URL is converted + * into its hexadecimal value and encoded as %xx. + * + * @param max_dest_len + * The size of the buffer pointed to by dest_segment. + * + * @returns The remaining buffer length. + */ +#ifdef __cplusplus +extern "C" { +#endif +int +smbc_urlencode(char * dest, char * src, int max_dest_len); +#ifdef __cplusplus +} +#endif + + +/**@ingroup directory + * Return the version of the linked Samba code, and thus the version of the + * libsmbclient code. + * + * @return The version string. + */ +#ifdef __cplusplus +extern "C" { +#endif +const char * +smbc_version(void); +#ifdef __cplusplus +} +#endif + +/**@ingroup misc + * Set the users credentials globally so they can be used for DFS + * referrals. Probably best to use this function in the smbc_get_auth_data_fn + * callback. + * + * @param workgroup Workgroup of the user. + * + * @param user Username of user. + * + * @param password Password of user. + * + * @param use_kerberos Whether to use Kerberos + * + * @param signing_state One of these strings (all equivalents on same line): + * "off", "no", "false" + * "on", "yes", "true", "auto" + * "force", "required", "forced" + */ + +void +smbc_set_credentials(const char *workgroup, + const char *user, + const char *password, + smbc_bool use_kerberos, + const char *signing_state); + +/* + * Wrapper around smbc_set_credentials. + * Used to set correct credentials that will + * be used to connect to DFS target share + * in libsmbclient + */ + +void +smbc_set_credentials_with_fallback(SMBCCTX *ctx, + const char *workgroup, + const char *user, + const char *password); + + +/** + * @ingroup threads + * + * Initialize for threads using the Posix Threads (pthread) + * implementation. This is a built-in implementation, avoiding the need to + * implement the component functions of the thread interface. If this function + * is used, it is not necessary to call smbc_thread_impl(). + * + * @return {void} + */ +void +smbc_thread_posix(void); + +/** + * @ingroup threads + * + * Initialize for an arbitrary thread implementation. The caller should + * provide, as parameters, pointers to functions to implement the requisite + * low-level thread functionality. A function must be provided for each + * parameter; none may be null. + * + * If the thread implementation is POSIX Threads (pthreads), then the much + * simpler smbc_thread_pthread() function may be used instead of this one. + * + * @param create_mutex + * Create a mutex. This function should expect three parameters: lockname, + * pplock, and location. It should create a unique mutex for each unique + * lockname it is provided, and return the mutex identifier in *pplock. The + * location parameter can be used for debugging, as it contains the + * compiler-provided __location__ of the call. + * + * @param destroy_mutex + * Destroy a mutex. This function should expect two parameters: plock and + * location. It should destroy the mutex associated with the identifier + * plock. The location parameter can be used for debugging, as it contains + * the compiler-provided __location__ of the call. + * + * @param lock_mutex + * Lock a mutex. This function should expect three parameters: plock, + * lock_type, and location. The mutex aassociated with identifier plock + * should be locked if lock_type is 1, and unlocked if lock_type is 2. The + * location parameter can be used for debugging, as it contains the + * compiler-provided __location__ of the call. + * + * @param create_tls + * Create thread local storage. This function should expect three + * parameters: keyname, ppkey, and location. It should allocate an + * implementation-specific amount of memory and assign the pointer to that + * allocated memory to *ppkey. The location parameter can be used for + * debugging, as it contains the compiler-provided __location__ of the + * call. This function should return 0 upon success, non-zero upon failure. + * + * @param destroy_tls + * Destroy thread local storage. This function should expect two parameters: + * ppkey and location. The ppkey parameter points to a variable containing a + * thread local storage key previously provided by the create_tls + * function. The location parameter can be used for debugging, as it + * contains the compiler-provided __location__ of the call. + * + * @param set_tls + * Set a thread local storage variable's value. This function should expect + * three parameters: pkey, pval, and location. The pkey parameter is a + * thread local storage key previously provided by the create_tls + * function. The (void *) pval parameter contains the value to be placed in + * the thread local storage variable identified by pkey. The location + * parameter can be used for debugging, as it contains the compiler-provided + * __location__ of the call. This function should return 0 upon success; + * non-zero otherwise. + * + * @param get_tls + * Retrieve a thread local storage variable's value. This function should + * expect two parameters: pkey and location. The pkey parameter is a thread + * local storage key previously provided by the create_tls function, and + * which has previously been used in a call to the set_tls function to + * initialize a thread local storage variable. The location parameter can be + * used for debugging, as it contains the compiler-provided __location__ of + * the call. This function should return the (void *) value stored in the + * variable identified by pkey. + * + * @return {void} + */ +void +smbc_thread_impl( + /* Mutex functions. */ + int (*create_mutex)(const char *lockname, + void **pplock, + const char *location), + void (*destroy_mutex)(void *plock, + const char *location), + int (*lock_mutex)(void *plock, + int lock_type, + const char *location), + + /* Thread local storage. */ + int (*create_tls)(const char *keyname, + void **ppkey, + const char *location), + void (*destroy_tls)(void **ppkey, + const char *location), + int (*set_tls)(void *pkey, + const void *pval, + const char *location), + void *(*get_tls)(void *pkey, + const char *location) + ); + + + +/** + * @ingroup structure + * Structure that contains a client context information + * This structure is known as SMBCCTX + * + * DO NOT DIRECTLY MANIPULATE THE CONTEXT STRUCTURE! The data in the context + * structure should all be considered private to the library. It remains here + * only for backward compatibility. + * + * See the comments herein for use of the setter and getter functions which + * should now be used for manipulating these values. New features, functions, + * etc., are not added here but rather in _internal where they are not + * directly visible to applications. This makes it much easier to maintain + * ABI compatibility. + */ +struct _SMBCCTX +{ + /** + * debug level + * + * DEPRECATED: + * Use smbc_getDebug() and smbc_setDebug() + */ + int debug DEPRECATED_SMBC_INTERFACE; + + /** + * netbios name used for making connections + * + * DEPRECATED: + * Use smbc_getNetbiosName() and smbc_setNetbiosName() + */ + char * netbios_name DEPRECATED_SMBC_INTERFACE; + + /** + * workgroup name used for making connections + * + * DEPRECATED: + * Use smbc_getWorkgroup() and smbc_setWorkgroup() + */ + char * workgroup DEPRECATED_SMBC_INTERFACE; + + /** + * username used for making connections + * + * DEPRECATED: + * Use smbc_getUser() and smbc_setUser() + */ + char * user DEPRECATED_SMBC_INTERFACE; + + /** + * timeout used for waiting on connections / response data (in + * milliseconds) + * + * DEPRECATED: + * Use smbc_getTimeout() and smbc_setTimeout() + */ + int timeout DEPRECATED_SMBC_INTERFACE; + + /** + * callable functions for files: + * For usage and return values see the SMBC_* functions + * + * DEPRECATED: + * + * Use smbc_getFunction*() and smbc_setFunction*(), e.g. + * smbc_getFunctionOpen(), smbc_setFunctionUnlink(), etc. + */ + smbc_open_fn open DEPRECATED_SMBC_INTERFACE; + smbc_creat_fn creat DEPRECATED_SMBC_INTERFACE; + smbc_read_fn read DEPRECATED_SMBC_INTERFACE; + smbc_write_fn write DEPRECATED_SMBC_INTERFACE; + smbc_unlink_fn unlink DEPRECATED_SMBC_INTERFACE; + smbc_rename_fn rename DEPRECATED_SMBC_INTERFACE; + smbc_lseek_fn lseek DEPRECATED_SMBC_INTERFACE; + smbc_stat_fn stat DEPRECATED_SMBC_INTERFACE; + smbc_fstat_fn fstat DEPRECATED_SMBC_INTERFACE; +#if 0 /* internal */ + smbc_ftruncate_fn ftruncate_fn; +#endif + smbc_close_fn close_fn DEPRECATED_SMBC_INTERFACE; + smbc_opendir_fn opendir DEPRECATED_SMBC_INTERFACE; + smbc_closedir_fn closedir DEPRECATED_SMBC_INTERFACE; + smbc_readdir_fn readdir DEPRECATED_SMBC_INTERFACE; + smbc_readdirplus_fn readdirplus DEPRECATED_SMBC_INTERFACE; + smbc_readdirplus2_fn readdirplus2 DEPRECATED_SMBC_INTERFACE; + smbc_getdents_fn getdents DEPRECATED_SMBC_INTERFACE; + smbc_mkdir_fn mkdir DEPRECATED_SMBC_INTERFACE; + smbc_rmdir_fn rmdir DEPRECATED_SMBC_INTERFACE; + smbc_telldir_fn telldir DEPRECATED_SMBC_INTERFACE; + smbc_lseekdir_fn lseekdir DEPRECATED_SMBC_INTERFACE; + smbc_fstatdir_fn fstatdir DEPRECATED_SMBC_INTERFACE; + smbc_chmod_fn chmod DEPRECATED_SMBC_INTERFACE; + smbc_utimes_fn utimes DEPRECATED_SMBC_INTERFACE; + smbc_setxattr_fn setxattr DEPRECATED_SMBC_INTERFACE; + smbc_getxattr_fn getxattr DEPRECATED_SMBC_INTERFACE; + smbc_removexattr_fn removexattr DEPRECATED_SMBC_INTERFACE; + smbc_listxattr_fn listxattr DEPRECATED_SMBC_INTERFACE; + + /* Printing-related functions */ + smbc_print_file_fn print_file DEPRECATED_SMBC_INTERFACE; + smbc_open_print_job_fn open_print_job DEPRECATED_SMBC_INTERFACE; + smbc_list_print_jobs_fn list_print_jobs DEPRECATED_SMBC_INTERFACE; + smbc_unlink_print_job_fn unlink_print_job DEPRECATED_SMBC_INTERFACE; + + /* + ** Callbacks + * + * DEPRECATED: + * + * See the comment above each field, for the getter and setter + * functions that should now be used. + */ + struct _smbc_callbacks + { + /** + * authentication function callback: called upon auth requests + * + * DEPRECATED: + * Use smbc_getFunctionAuthData(), smbc_setFunctionAuthData() + */ + smbc_get_auth_data_fn auth_fn DEPRECATED_SMBC_INTERFACE; + + /** + * check if a server is still good + * + * DEPRECATED: + * Use smbc_getFunctionCheckServer(), + * smbc_setFunctionCheckServer() + */ + smbc_check_server_fn check_server_fn DEPRECATED_SMBC_INTERFACE; + + /** + * remove a server if unused + * + * DEPRECATED: + * Use smbc_getFunctionRemoveUnusedServer(), + * smbc_setFunctionCheckServer() + */ + smbc_remove_unused_server_fn remove_unused_server_fn DEPRECATED_SMBC_INTERFACE; + + /** Cache subsystem + * + * For an example cache system see + * samba/source/libsmb/libsmb_cache.c + * + * Cache subsystem * functions follow. + */ + + /** + * server cache addition + * + * DEPRECATED: + * Use smbc_getFunctionAddCachedServer(), + * smbc_setFunctionAddCachedServer() + */ + smbc_add_cached_srv_fn add_cached_srv_fn DEPRECATED_SMBC_INTERFACE; + + /** + * server cache lookup + * + * DEPRECATED: + * Use smbc_getFunctionGetCachedServer(), + * smbc_setFunctionGetCachedServer() + */ + smbc_get_cached_srv_fn get_cached_srv_fn DEPRECATED_SMBC_INTERFACE; + + /** + * server cache removal + * + * DEPRECATED: + * Use smbc_getFunctionRemoveCachedServer(), + * smbc_setFunctionRemoveCachedServer() + */ + smbc_remove_cached_srv_fn remove_cached_srv_fn DEPRECATED_SMBC_INTERFACE; + + /** + * server cache purging, try to remove all cached servers + * (disconnect) + * + * DEPRECATED: + * Use smbc_getFunctionPurgeCachedServers(), + * smbc_setFunctionPurgeCachedServers() + */ + smbc_purge_cached_fn purge_cached_fn DEPRECATED_SMBC_INTERFACE; + } callbacks; + + /** + * Space where the private data of the server cache used to be + * + * DEPRECATED: + * Use smbc_getServerCacheData(), smbc_setServerCacheData() + */ + void * reserved DEPRECATED_SMBC_INTERFACE; + + /* + * Very old configuration options. + * + * DEPRECATED: + * Use one of the following functions instead: + * smbc_setOptionUseKerberos() + * smbc_getOptionUseKerberos() + * smbc_setOptionFallbackAfterKerberos() + * smbc_getOptionFallbackAfterKerberos() + * smbc_setOptionNoAutoAnonymousLogin() + * smbc_getOptionNoAutoAnonymousLogin() + */ + int flags DEPRECATED_SMBC_INTERFACE; + + /** + * user options selections that apply to this session + * + * NEW OPTIONS ARE NOT ADDED HERE! + * + * DEPRECATED: + * To set and retrieve options, use the smbc_setOption*() and + * smbc_getOption*() functions. + */ + struct _smbc_options { + int browse_max_lmb_count DEPRECATED_SMBC_INTERFACE; + int urlencode_readdir_entries DEPRECATED_SMBC_INTERFACE; + int one_share_per_server DEPRECATED_SMBC_INTERFACE; + } options DEPRECATED_SMBC_INTERFACE; + + /** INTERNAL DATA + * do _NOT_ touch this from your program ! + */ + struct SMBC_internal_data * internal; +}; + + +#endif /* SMBCLIENT_H_INCLUDED */ diff --git a/source3/include/local.h b/source3/include/local.h new file mode 100644 index 0000000..297e557 --- /dev/null +++ b/source3/include/local.h @@ -0,0 +1,198 @@ +/* Copyright (C) 1995-1998 Samba-Team */ +/* Copyright (C) 1998 John H Terpstra <jht@aquasoft.com.au> */ + +/* local definitions for file server */ +#ifndef _LOCAL_H +#define _LOCAL_H + +/* Yves Gaige <yvesg@hptnodur.grenoble.hp.com> requested this set this */ +/* to a maximum of 8 if old smb clients break because of long printer names. */ +#define MAXPRINTERLEN 15 + +/* max number of SMB1 directory handles */ +/* As this now uses the bitmap code this can be + quite large. */ +#define MAX_DIRECTORY_HANDLES 2048 + +/* maximum number of file caches per smbd */ +#define MAX_WRITE_CACHES 10 + +/* + * Fudgefactor required for open tdb's, etc. + */ + +#ifndef MAX_OPEN_FUDGEFACTOR +#define MAX_OPEN_FUDGEFACTOR 40 +#endif + +/* + * Minimum number of open files needed for Windows7 to + * work correctly. A little conservative but better that + * than run out of fd's. + */ + +#ifndef MIN_OPEN_FILES_WINDOWS +#define MIN_OPEN_FILES_WINDOWS 16384 +#endif + +/* + * Default number of maximum open files per smbd. This is + * also limited by the maximum available file descriptors + * per process and can also be set in smb.conf as "max open files" + * in the [global] section. + */ + +#ifndef MAX_OPEN_FILES +#define MAX_OPEN_FILES (MIN_OPEN_FILES_WINDOWS + MAX_OPEN_FUDGEFACTOR) +#endif + +#define WORDMAX 0xFFFF + +/* the maximum password length before we declare a likely attack */ +#define MAX_PASS_LEN 200 + +/* separators for lists */ +#define LIST_SEP " \t,;\n\r" + +/* wchar separators for lists */ +#define LIST_SEP_W wchar_list_sep + +/* this is where browse lists are kept in the lock dir */ +#define SERVER_LIST "browse.dat" + +/* shall filenames with illegal chars in them get mangled in long + filename listings? */ +#define MANGLE_LONG_FILENAMES + +/* define this if you want to stop spoofing with .. and soft links + NOTE: This also slows down the server considerably */ +#define REDUCE_PATHS + +/* the size of the directory cache */ +#define DIRCACHESIZE 20 + +/* what default type of filesystem do we want this to show up as in a + NT file manager window? */ +#define FSTYPE_STRING "NTFS" + +/* user to test password server with as invalid in security=server mode. */ +#ifndef INVALID_USER_PREFIX +#define INVALID_USER_PREFIX "sambatest" +#endif + +/* the default pager to use for the client "more" command. Users can + override this with the PAGER environment variable */ +#ifndef PAGER +#define PAGER "more" +#endif + +/* the size of the uid cache used to reduce valid user checks */ +#define VUID_CACHE_SIZE 32 + +/* the following control timings of various actions. Don't change + them unless you know what you are doing. These are all in seconds */ +#define SMBD_RELOAD_CHECK (180) +#define IDLE_CLOSED_TIMEOUT (60) +#define SMBD_SELECT_TIMEOUT (60) +#define NMBD_SELECT_LOOP (10) +#define BROWSE_INTERVAL (60) +#define REGISTRATION_INTERVAL (10*60) +#define NMBD_INETD_TIMEOUT (120) +#define NMBD_MAX_TTL (24*60*60) +#define LPQ_LOCK_TIMEOUT (5) +#define NMBD_INTERFACES_RELOAD (120) +#define NMBD_UNEXPECTED_TIMEOUT (15) +#define SMBD_HOUSEKEEPING_INTERVAL SMBD_SELECT_TIMEOUT + +/* the following are in milliseconds */ +#define LOCK_RETRY_TIMEOUT (100) + +/* do you want to dump core (carefully!) when an internal error is + encountered? Samba will be careful to make the core file only + accessible to root */ +#define DUMP_CORE 1 + +/* shall we support browse requests via a FIFO to nmbd? */ +#define ENABLE_FIFO 1 + +/* how long (in miliseconds) to wait for a socket connect to happen */ +#define LONG_CONNECT_TIMEOUT 30000 +#define SHORT_CONNECT_TIMEOUT 5000 + +/* the default netbios keepalive timeout */ +#define DEFAULT_KEEPALIVE 300 + +/* the directory to sit in when idle */ +/* #define IDLE_DIR "/" */ + +/* Timout (in seconds) to wait for an oplock break + message to return from the client. */ + +#define OPLOCK_BREAK_TIMEOUT 35 + +/* Timout (in seconds) to add to the oplock break timeout + to wait for the smbd to smbd message to return. */ + +#define OPLOCK_BREAK_TIMEOUT_FUDGEFACTOR 2 + +/* the read preciction code has been disabled until some problems with + it are worked out */ +#define USE_READ_PREDICTION 0 + +/* Minimum length of allowed password when changing UNIX password. */ +#define MINPASSWDLENGTH 5 + +/* the maximum age in seconds of a password. Should be a lp_ parameter */ +#define MAX_PASSWORD_AGE (21*24*60*60) + +/* shall we deny oplocks to clients that get timeouts? */ +#define FASCIST_OPLOCK_BACKOFF 1 + +/* this enables the "rabbit pellet" fix for SMBwritebraw */ +#define RABBIT_PELLET_FIX 1 + +/* Max number of open RPC pipes. */ +#define MAX_OPEN_PIPES 2048 + +/* Tuning for server auth mutex. */ +#define CLI_AUTH_TIMEOUT 5000 /* In milli-seconds. */ +#define NUM_CLI_AUTH_CONNECT_RETRIES 3 +/* Number in seconds to wait for the mutex. This must be less than 30 seconds. */ +#define SERVER_MUTEX_WAIT_TIME ( ((NUM_CLI_AUTH_CONNECT_RETRIES) * ((CLI_AUTH_TIMEOUT)/1000)) + 5) +/* Number in seconds for winbindd to wait for the mutex. Make this 2 * smbd wait time. */ +#define WINBIND_SERVER_MUTEX_WAIT_TIME (( ((NUM_CLI_AUTH_CONNECT_RETRIES) * ((CLI_AUTH_TIMEOUT)/1000)) + 5)*2) + +/* size of listen() backlog in smbd */ +#define SMBD_LISTEN_BACKLOG 50 + +/* Number of microseconds to wait before a sharing violation. */ +#define SHARING_VIOLATION_USEC_WAIT 950000 + +/* Number of microseconds to wait before a updating the write time (2 secs). */ +#define WRITE_TIME_UPDATE_USEC_DELAY 2000000 + +#define MAX_LDAP_REPLICATION_SLEEP_TIME 5000 /* In milliseconds. */ + +/* tdb hash size for the open database. */ +#define SMB_OPEN_DATABASE_TDB_HASH_SIZE 10007 + +/* Characters we disallow in sharenames. */ +#define INVALID_SHARENAME_CHARS "%<>*?|/\\+=;:\"," + +/* Seconds between connection attempts to a remote server. */ +#define FAILED_CONNECTION_CACHE_TIMEOUT (LONG_CONNECT_TIMEOUT * 2 / 1000) + +/* Default hash size for the winbindd cache. */ +#define WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE 5000 + +/* Windows minimum lock resolution timeout in ms */ +#define WINDOWS_MINIMUM_LOCK_TIMEOUT_MS 200 + +/* Maximum size of RPC data we will accept for one call. */ +#define MAX_RPC_DATA_SIZE (15*1024*1024) + +/* A guestimate of how many domains winbindd will be contacting */ +#ifndef WINBIND_MAX_DOMAINS_HINT +#define WINBIND_MAX_DOMAINS_HINT 10 +#endif +#endif diff --git a/source3/include/locking.h b/source3/include/locking.h new file mode 100644 index 0000000..f9eb502 --- /dev/null +++ b/source3/include/locking.h @@ -0,0 +1,77 @@ +/* + Unix SMB/CIFS implementation. + SMB parameters and setup, plus a whole lot more. + + Copyright (C) Jeremy Allison 2006 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _LOCKING_H +#define _LOCKING_H + +/* passed to br lock code - the UNLOCK_LOCK should never be stored into the tdb + and is used in calculating POSIX unlock ranges only. We differentiate between + PENDING read and write locks to allow posix lock downgrades to trigger a lock + re-evaluation. */ + +enum brl_type {READ_LOCK, WRITE_LOCK, UNLOCK_LOCK}; +enum brl_flavour {WINDOWS_LOCK = 0, POSIX_LOCK = 1}; + +#include "librpc/gen_ndr/server_id.h" +#include "librpc/gen_ndr/misc.h" + +/* This contains elements that differentiate locks. The smbpid is a + client supplied pid, and is essentially the locking context for + this client */ + +struct lock_context { + uint64_t smblctx; + uint32_t tid; + struct server_id pid; +}; + +struct files_struct; + +#include "lib/file_id.h" + +struct byte_range_lock; +typedef uint64_t br_off; + +/* Internal structure in brlock.tdb. + The data in brlock records is an unsorted linear array of these + records. It is unnecessary to store the count as tdb provides the + size of the record */ + +struct lock_struct { + struct lock_context context; + br_off start; + br_off size; + uint64_t fnum; + enum brl_type lock_type; + enum brl_flavour lock_flav; +}; + +struct smbd_lock_element { + struct GUID req_guid; + uint64_t smblctx; + enum brl_type brltype; + enum brl_flavour lock_flav; + uint64_t offset; + uint64_t count; +}; + +struct share_mode_lock; + +#endif /* _LOCKING_H_ */ diff --git a/source3/include/lsa.h b/source3/include/lsa.h new file mode 100644 index 0000000..c23e942 --- /dev/null +++ b/source3/include/lsa.h @@ -0,0 +1,29 @@ +/* + * Helper functions related to the LSA server + * + * 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/>. + */ +#ifndef LSA_H +#define LSA_H + +int init_lsa_ref_domain_list(TALLOC_CTX *mem_ctx, + struct lsa_RefDomainList *ref, + const char *dom_name, + struct dom_sid *dom_sid); + +#define NT_STATUS_LOOKUP_ERR(status) \ + (!NT_STATUS_IS_OK(status) && \ + !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED) && \ + !NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) +#endif diff --git a/source3/include/mangle.h b/source3/include/mangle.h new file mode 100644 index 0000000..7c4602b --- /dev/null +++ b/source3/include/mangle.h @@ -0,0 +1,42 @@ +/* + Unix SMB/CIFS implementation. + Name mangling interface + Copyright (C) Andrew Tridgell 2002 + + 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/>. +*/ + +#ifndef _MANGLE_H_ +#define _MANGLE_H_ +/* + header for 8.3 name mangling interface +*/ + +struct mangle_fns { + void (*reset)(void); + bool (*is_mangled)(const char *s, const struct share_params *p); + bool (*must_mangle)(const char *s, const struct share_params *p); + bool (*is_8_3)(const char *fname, bool check_case, bool allow_wildcards, + const struct share_params *p); + bool (*lookup_name_from_8_3)(TALLOC_CTX *ctx, + const char *in, + char **out, /* talloced on the given context. */ + const struct share_params *p); + bool (*name_to_8_3)(const char *in, + char out[13], + bool cache83, + int default_case, + const struct share_params *p); +}; +#endif /* _MANGLE_H_ */ diff --git a/source3/include/messages.h b/source3/include/messages.h new file mode 100644 index 0000000..79e63ec --- /dev/null +++ b/source3/include/messages.h @@ -0,0 +1,128 @@ +/* + Unix SMB/CIFS implementation. + messages.c header + Copyright (C) Andrew Tridgell 2000 + Copyright (C) 2001, 2002 by Martin Pool + + 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/>. +*/ + +#ifndef _MESSAGES_H_ +#define _MESSAGES_H_ + +#include "replace.h" +#include <tevent.h> + +/* change the message version with any incompatible changes in the protocol */ +#define MESSAGE_VERSION 2 + +/* + * Special flags passed to message_send. Allocated from the top, lets see when + * it collides with the message types in the lower 16 bits :-) + */ + +/* + * Under high load, this message can be dropped. Use for notify-style + * messages that are not critical for correct operation. + */ +#define MSG_FLAG_LOWPRIORITY 0x80000000 + +#include "librpc/gen_ndr/server_id.h" +#include "lib/util/data_blob.h" +#include "system/network.h" + +#define MSG_BROADCAST_PID_STR "0:0" + +struct messaging_context; +struct messaging_rec; + +struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, + struct tevent_context *ev); + +struct server_id messaging_server_id(const struct messaging_context *msg_ctx); +struct tevent_context *messaging_tevent_context( + struct messaging_context *msg_ctx); +struct server_id_db *messaging_names_db(struct messaging_context *msg_ctx); + +/* + * re-init after a fork + */ +NTSTATUS messaging_reinit(struct messaging_context *msg_ctx); + +NTSTATUS messaging_register(struct messaging_context *msg_ctx, + void *private_data, + uint32_t msg_type, + void (*fn)(struct messaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id server_id, + DATA_BLOB *data)); +void messaging_deregister(struct messaging_context *ctx, uint32_t msg_type, + void *private_data); + +/** + * CAVEAT: + * + * While the messaging_send*() functions are synchronuous by API, + * they trigger a tevent-based loop upon sending bigger messages. + * + * Hence callers should not use these in purely synchonous code, + * but run a tevent_loop instead. + */ +NTSTATUS messaging_send(struct messaging_context *msg_ctx, + struct server_id server, + uint32_t msg_type, const DATA_BLOB *data); + +NTSTATUS messaging_send_buf(struct messaging_context *msg_ctx, + struct server_id server, uint32_t msg_type, + const uint8_t *buf, size_t len); +int messaging_send_iov_from(struct messaging_context *msg_ctx, + struct server_id src, struct server_id dst, + uint32_t msg_type, + const struct iovec *iov, int iovlen, + const int *fds, size_t num_fds); +NTSTATUS messaging_send_iov(struct messaging_context *msg_ctx, + struct server_id server, uint32_t msg_type, + const struct iovec *iov, int iovlen, + const int *fds, size_t num_fds); +void messaging_send_all(struct messaging_context *msg_ctx, + int msg_type, const void *buf, size_t len); + +struct tevent_req *messaging_filtered_read_send( + TALLOC_CTX *mem_ctx, struct tevent_context *ev, + struct messaging_context *msg_ctx, + bool (*filter)(struct messaging_rec *rec, void *private_data), + void *private_data); +int messaging_filtered_read_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, + struct messaging_rec **presult); + +struct tevent_req *messaging_read_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct messaging_context *msg, + uint32_t msg_type); +int messaging_read_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, + struct messaging_rec **presult); + +int messaging_cleanup(struct messaging_context *msg_ctx, pid_t pid); + +bool messaging_parent_dgm_cleanup_init(struct messaging_context *msg); + +struct messaging_rec *messaging_rec_create( + TALLOC_CTX *mem_ctx, struct server_id src, struct server_id dst, + uint32_t msg_type, const struct iovec *iov, int iovlen, + const int *fds, size_t num_fds); + +#include "librpc/gen_ndr/ndr_messaging.h" + +#endif diff --git a/source3/include/msdfs.h b/source3/include/msdfs.h new file mode 100644 index 0000000..892343f --- /dev/null +++ b/source3/include/msdfs.h @@ -0,0 +1,59 @@ +/* + Unix SMB/Netbios implementation. + Version 3.0 + MSDfs services for Samba + Copyright (C) Shirish Kalele 2000 + + 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/>. + +*/ + +#ifndef _MSDFS_H +#define _MSDFS_H + +#define REFERRAL_TTL 600 + +/* Flags used in trans2 Get Referral reply */ +#define DFSREF_REFERRAL_SERVER 0x1 +#define DFSREF_STORAGE_SERVER 0x2 + +/* Referral sizes */ +#define VERSION2_REFERRAL_SIZE 0x16 +#define VERSION3_REFERRAL_SIZE 0x22 +#define REFERRAL_HEADER_SIZE 0x08 + +/* Maximum number of referrals for each Dfs volume */ +#define MAX_REFERRAL_COUNT 256 +#define MAX_MSDFS_JUNCTIONS 256 + +struct client_dfs_referral { + uint32_t proximity; + uint32_t ttl; + char *dfspath; +}; + +struct referral { + char *alternate_path; /* contains the path referred */ + uint32_t proximity; + uint32_t ttl; /* how long should client cache referral */ +}; + +struct junction_map { + char *service_name; + char *volume_name; + const char *comment; + size_t referral_count; + struct referral* referral_list; +}; +#endif /* _MSDFS_H */ diff --git a/source3/include/nameserv.h b/source3/include/nameserv.h new file mode 100644 index 0000000..29b2d87 --- /dev/null +++ b/source3/include/nameserv.h @@ -0,0 +1,629 @@ +#ifndef _NAMESERV_H_ +#define _NAMESERV_H_ +/* + Unix SMB/CIFS implementation. + NBT netbios header - version 2 + Copyright (C) Andrew Tridgell 1994-1998 + + 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/>. + +*/ + +#define INFO_VERSION "INFO/version" +#define INFO_COUNT "INFO/num_entries" +#define INFO_ID_HIGH "INFO/id_high" +#define INFO_ID_LOW "INFO/id_low" +#define ENTRY_PREFIX "ENTRY/" + +#define PERMANENT_TTL 0 + +/* NTAS uses 2, NT uses 1, WfWg uses 0 */ +#define MAINTAIN_LIST 2 +#define ELECTION_VERSION 1 + +#define MAX_DGRAM_SIZE (576) /* tcp/ip datagram limit is 576 bytes */ +#define MIN_DGRAM_SIZE 12 + +/********************************************************* + Types of reply packet. +**********************************************************/ + +enum netbios_reply_type_code { NMB_QUERY, NMB_STATUS, NMB_REG, NMB_REG_REFRESH, + NMB_REL, NMB_WAIT_ACK, NMB_MULTIHOMED_REG, + WINS_REG, WINS_QUERY }; + +/* From rfc1002, 4.2.1.2 */ +/* Question types. */ +#define QUESTION_TYPE_NB_QUERY 0x20 +#define QUESTION_TYPE_NB_STATUS 0x21 + +/* Question class */ +#define QUESTION_CLASS_IN 0x1 + +/* Opcode definitions */ +#define NMB_NAME_QUERY_OPCODE 0x0 +#define NMB_NAME_REG_OPCODE 0x05 /* see rfc1002.txt 4.2.2,3,5,6,7,8 */ +#define NMB_NAME_RELEASE_OPCODE 0x06 /* see rfc1002.txt 4.2.9,10,11 */ +#define NMB_WACK_OPCODE 0x07 /* see rfc1002.txt 4.2.16 */ +/* Ambiguity in rfc1002 about which of these is correct. */ +/* WinNT uses 8 by default but can be made to use 9. */ +#define NMB_NAME_REFRESH_OPCODE_8 0x08 /* see rfc1002.txt 4.2.4 */ +#define NMB_NAME_REFRESH_OPCODE_9 0x09 /* see rfc1002.txt 4.2.4 */ +#define NMB_NAME_MULTIHOMED_REG_OPCODE 0x0F /* Invented by Microsoft. */ + +/* XXXX what about all the other types?? 0x1, 0x2, 0x3, 0x4, 0x8? */ + +/* Resource record types. rfc1002 4.2.1.3 */ +#define RR_TYPE_A 0x1 +#define RR_TYPE_NS 0x2 +#define RR_TYPE_NULL 0xA +#define RR_TYPE_NB 0x20 +#define RR_TYPE_NBSTAT 0x21 + +/* Resource record class. */ +#define RR_CLASS_IN 0x1 + +/* NetBIOS flags */ +#define NB_GROUP 0x80 +#define NB_PERM 0x02 +#define NB_ACTIVE 0x04 +#define NB_CONFL 0x08 +#define NB_DEREG 0x10 +#define NB_BFLAG 0x00 /* Broadcast node type. */ +#define NB_PFLAG 0x20 /* Point-to-point node type. */ +#define NB_MFLAG 0x40 /* Mixed bcast & p-p node type. */ +#define NB_HFLAG 0x60 /* Microsoft 'hybrid' node type. */ +#define NB_NODETYPEMASK 0x60 +/* Mask applied to outgoing NetBIOS flags. */ +#define NB_FLGMSK 0xE0 + +/* The wins flags. Looks like the nbflags ! */ +#define WINS_UNIQUE 0x00 /* Unique record */ +#define WINS_NGROUP 0x01 /* Normal Group eg: 1B */ +#define WINS_SGROUP 0x02 /* Special Group eg: 1C */ +#define WINS_MHOMED 0x03 /* MultiHomed */ + +#define WINS_ACTIVE 0x00 /* active record */ +#define WINS_RELEASED 0x04 /* released record */ +#define WINS_TOMBSTONED 0x08 /* tombstoned record */ +#define WINS_DELETED 0x0C /* deleted record */ + +#define WINS_STATE_MASK 0x0C + +#define WINS_LOCAL 0x00 /* local record */ +#define WINS_REMOTE 0x10 /* remote record */ + +#define WINS_BNODE 0x00 /* Broadcast node */ +#define WINS_PNODE 0x20 /* PtP node */ +#define WINS_MNODE 0x40 /* Mixed node */ +#define WINS_HNODE 0x60 /* Hybrid node */ + +#define WINS_NONSTATIC 0x00 /* dynamic record */ +#define WINS_STATIC 0x80 /* static record */ + +#define WINS_STATE_ACTIVE(p) (((p)->data.wins_flags & WINS_STATE_MASK) == WINS_ACTIVE) + + +/* NetBIOS flag identifier. */ +#define NAME_GROUP(p) ((p)->data.nb_flags & NB_GROUP) +#define NAME_BFLAG(p) (((p)->data.nb_flags & NB_NODETYPEMASK) == NB_BFLAG) +#define NAME_PFLAG(p) (((p)->data.nb_flags & NB_NODETYPEMASK) == NB_PFLAG) +#define NAME_MFLAG(p) (((p)->data.nb_flags & NB_NODETYPEMASK) == NB_MFLAG) +#define NAME_HFLAG(p) (((p)->data.nb_flags & NB_NODETYPEMASK) == NB_HFLAG) + +/* Samba name state for a name in a namelist. */ +#define NAME_IS_ACTIVE(p) ((p)->data.nb_flags & NB_ACTIVE) +#define NAME_IN_CONFLICT(p) ((p)->data.nb_flags & NB_CONFL) +#define NAME_IS_DEREGISTERING(p) ((p)->data.nb_flags & NB_DEREG) + +/* Error codes for NetBIOS requests. */ +#define FMT_ERR 0x1 /* Packet format error. */ +#define SRV_ERR 0x2 /* Internal server error. */ +#define NAM_ERR 0x3 /* Name does not exist. */ +#define IMP_ERR 0x4 /* Request not implemented. */ +#define RFS_ERR 0x5 /* Request refused. */ +#define ACT_ERR 0x6 /* Active error - name owned by another host. */ +#define CFT_ERR 0x7 /* Name in conflict error. */ + +#define REFRESH_TIME (15*60) +#define NAME_POLL_REFRESH_TIME (5*60) +#define NAME_POLL_INTERVAL 15 + +/* Workgroup state identifiers. */ +#define AM_POTENTIAL_MASTER_BROWSER(work) ((work)->mst_state == MST_POTENTIAL) +#define AM_LOCAL_MASTER_BROWSER(work) ((work)->mst_state == MST_BROWSER) +#define AM_DOMAIN_MASTER_BROWSER(work) ((work)->dom_state == DOMAIN_MST) +#define AM_DOMAIN_MEMBER(work) ((work)->log_state == LOGON_SRV) + +/* Microsoft browser NetBIOS name. */ +#define MSBROWSE "\001\002__MSBROWSE__\002" + +/* Mail slots. */ +#define BROWSE_MAILSLOT "\\MAILSLOT\\BROWSE" +#define NET_LOGON_MAILSLOT "\\MAILSLOT\\NET\\NETLOGON" +#define NT_LOGON_MAILSLOT "\\MAILSLOT\\NET\\NTLOGON" +#define LANMAN_MAILSLOT "\\MAILSLOT\\LANMAN" + +/* Samba definitions for find_name_on_subnet(). */ +#define FIND_ANY_NAME 0 +#define FIND_SELF_NAME 1 + +/* + * The different name types that can be in namelists. + * + * SELF_NAME should only be on the broadcast and unicast subnets. + * LMHOSTS_NAME should only be in the remote_broadcast_subnet. + * REGISTER_NAME, DNS_NAME, DNSFAIL_NAME should only be in the wins_server_subnet. + * WINS_PROXY_NAME should only be on the broadcast subnets. + * PERMANENT_NAME can be on all subnets except remote_broadcast_subnet. + * + */ + +enum name_source {LMHOSTS_NAME, REGISTER_NAME, SELF_NAME, DNS_NAME, + DNSFAIL_NAME, PERMANENT_NAME, WINS_PROXY_NAME}; +enum node_type {B_NODE=0, P_NODE=1, M_NODE=2, NBDD_NODE=3}; +enum packet_type {NMB_PACKET, DGRAM_PACKET}; + +enum master_state { + MST_NONE, + MST_POTENTIAL, + MST_BACKUP, + MST_MSB, + MST_BROWSER, + MST_UNBECOMING_MASTER +}; + +enum domain_state { + DOMAIN_NONE, + DOMAIN_WAIT, + DOMAIN_MST +}; + +enum logon_state { + LOGON_NONE, + LOGON_WAIT, + LOGON_SRV +}; + +struct subnet_record; + +struct nmb_data { + uint16_t nb_flags; /* Netbios flags. */ + int num_ips; /* Number of ip entries. */ + struct in_addr *ip; /* The ip list for this name. */ + + enum name_source source; /* Where the name came from. */ + + time_t death_time; /* The time the record must be removed (do not remove if 0). */ + time_t refresh_time; /* The time the record should be refreshed. */ + + uint64_t id; /* unique id */ + struct in_addr wins_ip; /* the adress of the wins server this record comes from */ + + int wins_flags; /* similar to the netbios flags but different ! */ +}; + +/* This structure represents an entry in a local netbios name list. */ +struct name_record { + struct name_record *prev, *next; + struct subnet_record *subnet; + struct nmb_name name; /* The netbios name. */ + struct nmb_data data; /* The netbios data. */ +}; + +/* Browser cache for synchronising browse lists. */ +struct browse_cache_record { + struct browse_cache_record *prev, *next; + unstring lmb_name; + unstring work_group; + struct in_addr ip; + time_t sync_time; + time_t death_time; /* The time the record must be removed. */ +}; + +/* used for server information: client, nameserv and ipc */ +struct server_info_struct { + fstring name; + uint32_t type; + fstring comment; + fstring domain; /* used ONLY in ipc.c NOT namework.c */ + bool server_added; /* used ONLY in ipc.c NOT namework.c */ +}; + +/* This is used to hold the list of servers in my domain, and is + contained within lists of domains. */ + +struct server_record { + struct server_record *next; + struct server_record *prev; + + struct subnet_record *subnet; + + struct server_info_struct serv; + time_t death_time; +}; + +/* A workgroup structure. It contains a list of servers. */ +struct work_record { + struct work_record *next; + struct work_record *prev; + + struct subnet_record *subnet; + + struct server_record *serverlist; + + /* Stage of development from non-local-master up to local-master browser. */ + enum master_state mst_state; + + /* Stage of development from non-domain-master to domain-master browser. */ + enum domain_state dom_state; + + /* Stage of development from non-logon-server to logon server. */ + enum logon_state log_state; + + /* Work group info. */ + unstring work_group; + int token; /* Used when communicating with backup browsers. */ + unstring local_master_browser_name; /* Current local master browser. */ + + /* Announce info. */ + time_t lastannounce_time; + int announce_interval; + bool needannounce; + + /* Timeout time for this workgroup. 0 means permanent. */ + time_t death_time; + + /* Election info */ + bool RunningElection; + bool needelection; + int ElectionCount; + uint32_t ElectionCriterion; + + /* Domain master browser info. Used for efficient syncs. */ + struct nmb_name dmb_name; + struct in_addr dmb_addr; +}; + +/* typedefs needed to define copy & free functions for userdata. */ +struct userdata_struct; + +typedef struct userdata_struct * (*userdata_copy_fn)(struct userdata_struct *); +typedef void (*userdata_free_fn)(struct userdata_struct *); + +/* Structure to define any userdata passed around. */ + +struct userdata_struct { + userdata_copy_fn copy_fn; + userdata_free_fn free_fn; + unsigned int userdata_len; + char data[16]; /* 16 is to ensure alignment/padding on all systems */ +}; + +struct response_record; +struct packet_struct; +struct res_rec; + +/* typedef to define the function called when this response packet comes in. */ +typedef void (*response_function)(struct subnet_record *, struct response_record *, + struct packet_struct *); + +/* typedef to define the function called when this response record times out. */ +typedef void (*timeout_response_function)(struct subnet_record *, + struct response_record *); + +/* typedef to define the function called when the request that caused this + response record to be created is successful. */ +typedef void (*success_function)(struct subnet_record *, struct userdata_struct *, ...); + +/* typedef to define the function called when the request that caused this + response record to be created is unsuccessful. */ +typedef void (*fail_function)(struct subnet_record *, struct response_record *, ...); + +/* List of typedefs for success and fail functions of the different query + types. Used to catch any compile time prototype errors. */ + +typedef void (*register_name_success_function)( struct subnet_record *, + struct userdata_struct *, + struct nmb_name *, + uint16_t, + int, + struct in_addr); +typedef void (*register_name_fail_function)( struct subnet_record *, + struct response_record *, + struct nmb_name *); + +typedef void (*release_name_success_function)( struct subnet_record *, + struct userdata_struct *, + struct nmb_name *, + struct in_addr); +typedef void (*release_name_fail_function)( struct subnet_record *, + struct response_record *, + struct nmb_name *); + +typedef void (*refresh_name_success_function)( struct subnet_record *, + struct userdata_struct *, + struct nmb_name *, + uint16_t, + int, + struct in_addr); +typedef void (*refresh_name_fail_function)( struct subnet_record *, + struct response_record *, + struct nmb_name *); + +typedef void (*query_name_success_function)( struct subnet_record *, + struct userdata_struct *, + struct nmb_name *, + struct in_addr, + struct res_rec *answers); + +typedef void (*query_name_fail_function)( struct subnet_record *, + struct response_record *, + struct nmb_name *, + int); + +typedef void (*node_status_success_function)( struct subnet_record *, + struct userdata_struct *, + struct res_rec *, + struct in_addr); +typedef void (*node_status_fail_function)( struct subnet_record *, + struct response_record *); + +/* Initiated name queries are recorded in this list to track any responses. */ + +struct response_record { + struct response_record *next; + struct response_record *prev; + + uint16_t response_id; + + /* Callbacks for packets received or not. */ + response_function resp_fn; + timeout_response_function timeout_fn; + + /* Callbacks for the request succeeding or not. */ + success_function success_fn; + fail_function fail_fn; + + struct packet_struct *packet; + + struct userdata_struct *userdata; + + int num_msgs; + + time_t repeat_time; + time_t repeat_interval; + int repeat_count; + + /* Recursion protection. */ + bool in_expiration_processing; +}; + +/* A subnet structure. It contains a list of workgroups and netbios names. */ + +/* + B nodes will have their own, totally separate subnet record, with their + own netbios name set. These do NOT interact with other subnet records' + netbios names. +*/ + +enum subnet_type { + NORMAL_SUBNET = 0, /* Subnet listed in interfaces list. */ + UNICAST_SUBNET = 1, /* Subnet for unicast packets. */ + REMOTE_BROADCAST_SUBNET = 2, /* Subnet for remote broadcasts. */ + WINS_SERVER_SUBNET = 3 /* Only created if we are a WINS server. */ +}; + +struct subnet_record { + struct subnet_record *next; + struct subnet_record *prev; + + char *subnet_name; /* For Debug identification. */ + enum subnet_type type; /* To catagorize the subnet. */ + + struct work_record *workgrouplist; /* List of workgroups. */ + struct name_record *namelist; /* List of netbios names. */ + struct response_record *responselist; /* List of responses expected. */ + + bool namelist_changed; + bool work_changed; + + struct in_addr bcast_ip; + struct in_addr mask_ip; + struct in_addr myip; + int nmb_sock; /* socket to listen for unicast 137. */ + int nmb_bcast; /* socket to listen for broadcast 137. */ + int dgram_sock; /* socket to listen for unicast 138. */ + int dgram_bcast; /* socket to listen for broadcast 138. */ +}; + +/* A resource record. */ +struct res_rec { + struct nmb_name rr_name; + int rr_type; + int rr_class; + int ttl; + int rdlength; + char rdata[MAX_DGRAM_SIZE]; +}; + +/* Define these so we can pass info back to caller of name_query */ +#define NM_FLAGS_RS 0x80 /* Response. Cheat */ +#define NM_FLAGS_AA 0x40 /* Authoritative */ +#define NM_FLAGS_TC 0x20 /* Truncated */ +#define NM_FLAGS_RD 0x10 /* Recursion Desired */ +#define NM_FLAGS_RA 0x08 /* Recursion Available */ +#define NM_FLAGS_B 0x01 /* Broadcast */ + +/* An nmb packet. */ +struct nmb_packet { + struct { + int name_trn_id; + int opcode; + bool response; + struct { + bool bcast; + bool recursion_available; + bool recursion_desired; + bool trunc; + bool authoritative; + } nm_flags; + int rcode; + int qdcount; + int ancount; + int nscount; + int arcount; + } header; + + struct { + struct nmb_name question_name; + int question_type; + int question_class; + } question; + + struct res_rec *answers; + struct res_rec *nsrecs; + struct res_rec *additional; +}; + +/* msg_type field options - from rfc1002. */ + +#define DGRAM_UNIQUE 0x10 +#define DGRAM_GROUP 0x11 +#define DGRAM_BROADCAST 0x12 +/* defined in IDL +#define DGRAM_ERROR 0x13 +*/ +#define DGRAM_QUERY_REQUEST 0x14 +#define DGRAM_POSITIVE_QUERY_RESPONSE 0x15 +#define DGRAM_NEGATIVE_QUERT_RESPONSE 0x16 + +/* A datagram - this normally contains SMB data in the data[] array. */ + +struct dgram_packet { + struct { + int msg_type; + struct { + enum node_type node_type; + bool first; + bool more; + } flags; + int dgm_id; + struct in_addr source_ip; + int source_port; + int dgm_length; + int packet_offset; + } header; + struct nmb_name source_name; + struct nmb_name dest_name; + int datasize; + char data[MAX_DGRAM_SIZE]; +}; + +/* Define a structure used to queue packets. This will be a linked + list of nmb packets. */ + +struct packet_struct +{ + struct packet_struct *next; + struct packet_struct *prev; + bool locked; + struct in_addr ip; + int port; + int recv_fd; + int send_fd; + time_t timestamp; + enum packet_type packet_type; + union { + struct nmb_packet nmb; + struct dgram_packet dgram; + } packet; +}; + +/* Ids for netbios packet types. */ + +#define ANN_HostAnnouncement 1 +#define ANN_AnnouncementRequest 2 +#define ANN_Election 8 +#define ANN_GetBackupListReq 9 +#define ANN_GetBackupListResp 10 +#define ANN_BecomeBackup 11 +#define ANN_DomainAnnouncement 12 +#define ANN_MasterAnnouncement 13 +#define ANN_ResetBrowserState 14 +#define ANN_LocalMasterAnnouncement 15 + + +/* Broadcast packet announcement intervals, in minutes. */ + +/* Attempt to add domain logon and domain master names. */ +#define CHECK_TIME_ADD_DOM_NAMES 5 + +/* Search for master browsers of workgroups samba knows about, + except default. */ +#define CHECK_TIME_MST_BROWSE 5 + +/* Request backup browser announcements from other servers. */ +#define CHECK_TIME_ANNOUNCE_BACKUP 15 + +/* Request host announcements from other servers: min and max of interval. */ +#define CHECK_TIME_MIN_HOST_ANNCE 3 +#define CHECK_TIME_MAX_HOST_ANNCE 12 + +/* Announce as master to WINS server and any Primary Domain Controllers. */ +#define CHECK_TIME_MST_ANNOUNCE 15 + +/* Time between syncs from domain master browser to local master browsers. */ +#define CHECK_TIME_DMB_TO_LMB_SYNC 15 + +/* Do all remote announcements this often. */ +#define REMOTE_ANNOUNCE_INTERVAL 180 + +/* what is the maximum period between name refreshes. Note that this only + affects non-permanent self names (in seconds) */ +#define MAX_REFRESH_TIME (60*20) + +/* The Extinction interval: 4 days, time a node will stay in released state */ +#define EXTINCTION_INTERVAL (4*24*60*60) + +/* The Extinction time-out: 1 day, time a node will stay in deleted state */ +#define EXTINCTION_TIMEOUT (24*60*60) + +/* Macro's to enumerate subnets either with or without + the UNICAST subnet. */ + +extern struct subnet_record *subnetlist; +extern struct subnet_record *unicast_subnet; +extern struct subnet_record *wins_server_subnet; +extern struct subnet_record *remote_broadcast_subnet; + +#define FIRST_SUBNET subnetlist +#define NEXT_SUBNET_EXCLUDING_UNICAST(x) ((x)->next) +#define NEXT_SUBNET_INCLUDING_UNICAST(x) (get_next_subnet_maybe_unicast((x))) + +/* wins replication record used between nmbd and wrepld */ +typedef struct _WINS_RECORD { + char name[17]; + char type; + int nb_flags; + int wins_flags; + uint64_t id; + int num_ips; + struct in_addr ip[25]; + struct in_addr wins_ip; +} WINS_RECORD; + +/* To be removed. */ +enum state_type { TEST }; +#endif /* _NAMESERV_H_ */ diff --git a/source3/include/nss_info.h b/source3/include/nss_info.h new file mode 100644 index 0000000..94df56e --- /dev/null +++ b/source3/include/nss_info.h @@ -0,0 +1,96 @@ +/* + Unix SMB/CIFS implementation. + Idmap NSS headers + + Copyright (C) Gerald Carter 2006 + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _IDMAP_NSS_H +#define _IDMAP_NSS_H + +#ifndef HAVE_LDAP +# ifndef LDAPMessage +# define LDAPMessage void +# endif +#endif + +/* The interface version specifier */ + +#define SMB_NSS_INFO_INTERFACE_VERSION 1 + +/* List of available backends. All backends must + register themselves */ + +struct nss_function_entry { + struct nss_function_entry *prev, *next; + + const char *name; + const struct nss_info_methods *methods; +}; + +/* List of configured domains. Each domain points + back to its configured backend. */ + +struct nss_domain_entry { + struct nss_domain_entry *prev, *next; + + const char *domain; + + NTSTATUS init_status; + const struct nss_function_entry *backend; + + /* hold state on a per domain basis */ + + void *state; +}; + +/* API */ + +struct nss_info_methods { + NTSTATUS (*init)( struct nss_domain_entry *e ); + NTSTATUS (*map_to_alias)(TALLOC_CTX *mem_ctx, + struct nss_domain_entry *e, + const char *name, char **alias); + NTSTATUS (*map_from_alias)(TALLOC_CTX *mem_ctx, + struct nss_domain_entry *e, + const char *alias, char **name); + NTSTATUS (*close_fn)( void ); +}; + + +/* The following definitions come from nsswitch/nss_info.c */ + +NTSTATUS smb_register_idmap_nss(int version, + const char *name, + const struct nss_info_methods *methods); + +NTSTATUS nss_map_to_alias( TALLOC_CTX *mem_ctx, const char *domain, + const char *name, char **alias ); + +NTSTATUS nss_map_from_alias( TALLOC_CTX *mem_ctx, const char *domain, + const char *alias, char **name ); + +NTSTATUS nss_close( const char *parameters ); + +/* The following definitions come from winbindd/nss_info.c */ + + +/* The following definitions come from winbindd/nss_info_template.c */ + +NTSTATUS nss_info_template_init(TALLOC_CTX *mem_ctx); + +#endif /* _IDMAP_NSS_H_ */ + diff --git a/source3/include/nt_printing.h b/source3/include/nt_printing.h new file mode 100644 index 0000000..b89c3bd --- /dev/null +++ b/source3/include/nt_printing.h @@ -0,0 +1,211 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + SMB parameters and setup + Copyright (C) Andrew Tridgell 1992-2000, + Copyright (C) Jean Francois Micouleau 1998-2000. + + 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/>. +*/ + +#ifndef NT_PRINTING_H_ +#define NT_PRINTING_H_ + +#include "../librpc/gen_ndr/spoolss.h" + +#ifndef SAMBA_PRINTER_PORT_NAME +#define SAMBA_PRINTER_PORT_NAME "Samba Printer Port" +#endif + +/* DOS header format */ +#define DOS_HEADER_SIZE 64 +#define DOS_HEADER_MAGIC_OFFSET 0 +#define DOS_HEADER_MAGIC 0x5A4D +#define DOS_HEADER_LFANEW_OFFSET 60 + +/* New Executable format (Win or OS/2 1.x segmented) */ +#define NE_HEADER_SIZE 64 +#define NE_HEADER_SIGNATURE_OFFSET 0 +#define NE_HEADER_SIGNATURE 0x454E +#define NE_HEADER_TARGET_OS_OFFSET 54 +#define NE_HEADER_TARGOS_WIN 0x02 +#define NE_HEADER_MINOR_VER_OFFSET 62 +#define NE_HEADER_MAJOR_VER_OFFSET 63 + +/* Portable Executable format */ +#define PE_HEADER_SIZE 24 +#define PE_HEADER_SIGNATURE_OFFSET 0 +#define PE_HEADER_SIGNATURE 0x00004550 +#define PE_HEADER_MACHINE_OFFSET 4 +#define PE_HEADER_MACHINE_I386 0x14c +#define PE_HEADER_NUMBER_OF_SECTIONS 6 +#define PE_HEADER_OPTIONAL_HEADER_SIZE 20 +#define PE_HEADER_SECT_HEADER_SIZE 40 +#define PE_HEADER_SECT_NAME_OFFSET 0 +#define PE_HEADER_SECT_SIZE_DATA_OFFSET 16 +#define PE_HEADER_SECT_PTR_DATA_OFFSET 20 + +/* Microsoft file version format */ +#define VS_SIGNATURE "VS_VERSION_INFO" +#define VS_MAGIC_VALUE 0xfeef04bd +#define VS_MAJOR_OFFSET 8 +#define VS_MINOR_OFFSET 12 +#define VS_VERSION_INFO_UNICODE_SIZE (sizeof(VS_SIGNATURE)*2+4+VS_MINOR_OFFSET+4) /* not true size! */ +#define VS_VERSION_INFO_SIZE (sizeof(VS_SIGNATURE)+4+VS_MINOR_OFFSET+4) /* not true size! */ +#define VS_NE_BUF_SIZE 4096 /* Must be > 2*VS_VERSION_INFO_SIZE */ + +/* Notify spoolss clients that something has changed. The + notification data is either stored in two uint32_t values or a + variable length array. */ + +#define SPOOLSS_NOTIFY_MSG_UNIX_JOBID 0x0001 /* Job id is unix */ + +typedef struct spoolss_notify_msg { + fstring printer; /* Name of printer notified */ + uint32_t type; /* Printer or job notify */ + uint32_t field; /* Notify field changed */ + uint32_t id; /* Job id */ + uint32_t len; /* Length of data, 0 for two uint32_t value */ + uint32_t flags; + union { + uint32_t value[2]; + char *data; + } notify; +} SPOOLSS_NOTIFY_MSG; + +typedef struct { + fstring printername; + uint32_t num_msgs; + SPOOLSS_NOTIFY_MSG *msgs; +} SPOOLSS_NOTIFY_MSG_GROUP; + +typedef struct { + TALLOC_CTX *ctx; + uint32_t num_groups; + SPOOLSS_NOTIFY_MSG_GROUP *msg_groups; +} SPOOLSS_NOTIFY_MSG_CTR; + +/* + * The printer attributes. + * I #defined all of them (grabbed form MSDN) + * I'm only using: + * ( SHARED | NETWORK | RAW_ONLY ) + * RAW_ONLY _MUST_ be present otherwise NT will send an EMF file + */ + +#define PRINTER_ATTRIBUTE_SAMBA (PRINTER_ATTRIBUTE_RAW_ONLY|\ + PRINTER_ATTRIBUTE_SHARED|\ + PRINTER_ATTRIBUTE_LOCAL) +#define PRINTER_ATTRIBUTE_NOT_SAMBA (PRINTER_ATTRIBUTE_NETWORK) + +#define DRIVER_ANY_VERSION 0xffffffff +#define DRIVER_MAX_VERSION 4 + +struct print_architecture_table_node { + const char *long_archi; + const char *short_archi; + int version; +}; + +bool nt_printing_init(struct messaging_context *msg_ctx); + +const char *get_short_archi(const char *long_archi); + +WERROR print_access_check(const struct auth_session_info *server_info, + struct messaging_context *msg_ctx, int snum, + int access_type); + +WERROR nt_printer_guid_retrieve(TALLOC_CTX *mem_ctx, const char *printer, + struct GUID *pguid); + +WERROR nt_printer_guid_store(struct messaging_context *msg_ctx, + const char *printer, struct GUID guid); + +WERROR nt_printer_guid_get(TALLOC_CTX *mem_ctx, + const struct auth_session_info *session_info, + struct messaging_context *msg_ctx, + const char *printer, struct GUID *guid); + +WERROR nt_printer_publish(TALLOC_CTX *mem_ctx, + const struct auth_session_info *server_info, + struct messaging_context *msg_ctx, + struct spoolss_PrinterInfo2 *pinfo2, + int action); + +bool is_printer_published(TALLOC_CTX *mem_ctx, + const struct auth_session_info *server_info, + struct messaging_context *msg_ctx, + const char *servername, + const char *printer, + struct spoolss_PrinterInfo2 **info2); + +WERROR check_published_printers(struct messaging_context *msg_ctx); + +struct dcerpc_binding_handle; + +bool printer_driver_in_use(TALLOC_CTX *mem_ctx, + struct dcerpc_binding_handle *b, + const struct spoolss_DriverInfo8 *r); +bool printer_driver_files_in_use(TALLOC_CTX *mem_ctx, + struct dcerpc_binding_handle *b, + struct spoolss_DriverInfo8 *r); +bool delete_driver_files(const struct auth_session_info *server_info, + const struct spoolss_DriverInfo8 *r); + +WERROR move_driver_to_download_area(const struct auth_session_info *session_info, + const struct spoolss_AddDriverInfoCtr *r, + const char *driver_directory); + +WERROR clean_up_driver_struct(TALLOC_CTX *mem_ctx, + const struct auth_session_info *session_info, + const struct spoolss_AddDriverInfoCtr *r, + uint32_t flags, + const char **driver_directory); + +void map_printer_permissions(struct security_descriptor *sd); + +void map_job_permissions(struct security_descriptor *sd); + +bool print_time_access_check(const struct auth_session_info *server_info, + struct messaging_context *msg_ctx, + const char *servicename); + +void nt_printer_remove(TALLOC_CTX *mem_ctx, + const struct auth_session_info *server_info, + struct messaging_context *msg_ctx, + const char *printer); +void nt_printer_add(TALLOC_CTX *mem_ctx, + const struct auth_session_info *server_info, + struct messaging_context *msg_ctx, + const char *printer); + +/* The version int is used by getdrivers. Note that + all architecture strings that support multiple + versions must be grouped together since enumdrivers + uses this property to prevent issuing multiple + enumdriver calls for the same arch */ +static const struct print_architecture_table_node archi_table[]= { + {SPOOLSS_ARCHITECTURE_4_0, SPL_ARCH_WIN40, 0 }, + {SPOOLSS_ARCHITECTURE_NT_X86, SPL_ARCH_W32X86, 2 }, + {SPOOLSS_ARCHITECTURE_NT_X86, SPL_ARCH_W32X86, 3 }, + {SPOOLSS_ARCHITECTURE_W32MIPS, SPL_ARCH_W32MIPS, 2 }, + {SPOOLSS_ARCHITECTURE_W32ALPHA, SPL_ARCH_W32ALPHA, 2 }, + {SPOOLSS_ARCHITECTURE_W32PPC, SPL_ARCH_W32PPC, 2 }, + {SPOOLSS_ARCHITECTURE_IA_64, SPL_ARCH_IA64, 3 }, + {SPOOLSS_ARCHITECTURE_x64, SPL_ARCH_X64, 3 }, + {SPOOLSS_ARCHITECTURE_ARM64, SPL_ARCH_ARM64, 3 }, + {NULL, "", -1 } +}; + +#endif /* NT_PRINTING_H_ */ diff --git a/source3/include/ntdomain.h b/source3/include/ntdomain.h new file mode 100644 index 0000000..9076c11 --- /dev/null +++ b/source3/include/ntdomain.h @@ -0,0 +1,35 @@ +/* + Unix SMB/CIFS implementation. + SMB parameters and setup + Copyright (C) Andrew Tridgell 1992-1997 + Copyright (C) Luke Kenneth Casson Leighton 1996-1997 + Copyright (C) Paul Ashton 1997 + Copyright (C) Jeremy Allison 2000-2004 + + 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/>. +*/ + +#ifndef _NT_DOMAIN_H /* _NT_DOMAIN_H */ +#define _NT_DOMAIN_H + +/* + * A bunch of stuff that was put into smb.h + * in the NTDOM branch - it didn't belong there. + */ + +struct gse_context; + +#include "rpc_server/rpc_pipes.h" + +#endif /* _NT_DOMAIN_H */ diff --git a/source3/include/ntioctl.h b/source3/include/ntioctl.h new file mode 100644 index 0000000..1c2e5d5 --- /dev/null +++ b/source3/include/ntioctl.h @@ -0,0 +1,41 @@ +/* + Unix SMB/CIFS implementation. + NT ioctl code constants + Copyright (C) Andrew Tridgell 2002 + + 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/>. +*/ + +#ifndef _NTIOCTL_H +#define _NTIOCTL_H + +/* Sub-types for IO_REPARSE_TAG_NFS */ +#define NFS_SPECFILE_LNK 0x00000000014B4E4C +#define NFS_SPECFILE_CHR 0x0000000000524843 +#define NFS_SPECFILE_BLK 0x00000000004B4C42 +#define NFS_SPECFILE_FIFO 0x000000004F464946 +#define NFS_SPECFILE_SOCK 0x000000004B434F53 + +/* For FSCTL_GET_SHADOW_COPY_DATA ...*/ +typedef char SHADOW_COPY_LABEL[25]; /* sizeof("@GMT-2004.02.18-15.44.00") + 1 */ + +struct shadow_copy_data { + /* Total number of shadow volumes currently mounted */ + uint32_t num_volumes; + /* Concatenated list of labels */ + SHADOW_COPY_LABEL *labels; +}; + + +#endif /* _NTIOCTL_H */ diff --git a/source3/include/ntquotas.h b/source3/include/ntquotas.h new file mode 100644 index 0000000..6fbbbb9 --- /dev/null +++ b/source3/include/ntquotas.h @@ -0,0 +1,91 @@ +/* + Unix SMB/CIFS implementation. + NT QUOTA code constants + Copyright (C) Stefan (metze) Metzmacher 2003 + + 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/>. +*/ + +#ifndef _NTQUOTAS_H +#define _NTQUOTAS_H + +/* + * details for Quota Flags: + * + * 0x20 Log Limit: log if the user exceeds his Hard Quota + * 0x10 Log Warn: log if the user exceeds his Soft Quota + * 0x02 Deny Disk: deny disk access when the user exceeds his Hard Quota + * 0x01 Enable Quotas: enable quota for this fs + * + */ + +#define QUOTAS_ENABLED 0x0001 +#define QUOTAS_DENY_DISK 0x0002 +#define QUOTAS_LOG_VIOLATIONS 0x0004 +#define CONTENT_INDEX_DISABLED 0x0008 +#define QUOTAS_LOG_THRESHOLD 0x0010 +#define QUOTAS_LOG_LIMIT 0x0020 +#define LOG_VOLUME_THRESHOLD 0x0040 +#define LOG_VOLUME_LIMIT 0x0080 +#define QUOTAS_INCOMPLETE 0x0100 +#define QUOTAS_REBUILDING 0x0200 +#define QUOTAS_0400 0x0400 +#define QUOTAS_0800 0x0800 +#define QUOTAS_1000 0x1000 +#define QUOTAS_2000 0x2000 +#define QUOTAS_4000 0x4000 +#define QUOTAS_8000 0x8000 + +#define SMB_NTQUOTAS_NO_LIMIT ((uint64_t)(-1)) +#define SMB_NTQUOTAS_NO_ENTRY ((uint64_t)(-2)) +#define SMB_NTQUOTAS_NO_SPACE ((uint64_t)(0)) +#define SMB_NTQUOTAS_1_B (uint64_t)0x0000000000000001 +#define SMB_NTQUOTAS_1KB (uint64_t)0x0000000000000400 +#define SMB_NTQUOTAS_1MB (uint64_t)0x0000000000100000 +#define SMB_NTQUOTAS_1GB (uint64_t)0x0000000040000000 +#define SMB_NTQUOTAS_1TB (uint64_t)0x0000010000000000 +#define SMB_NTQUOTAS_1PB (uint64_t)0x0004000000000000 +#define SMB_NTQUOTAS_1EB (uint64_t)0x1000000000000000 + +enum SMB_QUOTA_TYPE { + SMB_INVALID_QUOTA_TYPE = -1, + SMB_USER_FS_QUOTA_TYPE = 1, + SMB_USER_QUOTA_TYPE = 2, + SMB_GROUP_FS_QUOTA_TYPE = 3,/* not used yet */ + SMB_GROUP_QUOTA_TYPE = 4 /* used by disk_free queries */ +}; + +typedef struct _SMB_NTQUOTA_STRUCT { + enum SMB_QUOTA_TYPE qtype; + uint64_t usedspace; + uint64_t softlim; + uint64_t hardlim; + uint32_t qflags; + struct dom_sid sid; +} SMB_NTQUOTA_STRUCT; + +typedef struct _SMB_NTQUOTA_LIST { + struct _SMB_NTQUOTA_LIST *prev,*next; + TALLOC_CTX *mem_ctx; + uid_t uid; + SMB_NTQUOTA_STRUCT *quotas; +} SMB_NTQUOTA_LIST; + +typedef struct _SMB_NTQUOTA_HANDLE { + bool valid; + SMB_NTQUOTA_LIST *quota_list; + SMB_NTQUOTA_LIST *tmp_list; +} SMB_NTQUOTA_HANDLE; + +#endif /*_NTQUOTAS_H */ diff --git a/source3/include/passdb.h b/source3/include/passdb.h new file mode 100644 index 0000000..57f1b50 --- /dev/null +++ b/source3/include/passdb.h @@ -0,0 +1,990 @@ +/* + Unix SMB/CIFS implementation. + passdb structures and parameters + Copyright (C) Gerald Carter 2001 + Copyright (C) Luke Kenneth Casson Leighton 1998 - 2000 + Copyright (C) Andrew Bartlett 2002 + Copyright (C) Simo Sorce 2003 + + 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/>. +*/ + +#ifndef _PASSDB_H +#define _PASSDB_H + +#ifndef NT_HASH_LEN +#define NT_HASH_LEN 16 +#endif + +#ifndef LM_HASH_LEN +#define LM_HASH_LEN 16 +#endif + +#include "../librpc/gen_ndr/lsa.h" +#include <tevent.h> +struct unixid; +struct cli_credentials; + +/* group mapping headers */ + +#define ENUM_ONLY_MAPPED True +#define ENUM_ALL_MAPPED False + +typedef struct _GROUP_MAP { + struct pdb_methods *methods; + gid_t gid; + struct dom_sid sid; + enum lsa_SidType sid_name_use; + char *nt_name; + char *comment; +} GROUP_MAP; + +struct acct_info { + char *acct_name; /* account name */ + char *acct_desc; /* account name */ + uint32_t rid; /* domain-relative RID */ +}; + +/* The following definitions come from groupdb/mapping.c */ + +NTSTATUS add_initial_entry(gid_t gid, const char *sid, enum lsa_SidType sid_name_use, const char *nt_name, const char *comment); +bool get_domain_group_from_sid(struct dom_sid sid, GROUP_MAP *map); +int smb_create_group(const char *unix_group, gid_t *new_gid); +int smb_delete_group(const char *unix_group); +int smb_set_primary_group(const char *unix_group, const char* unix_user); +int smb_add_user_group(const char *unix_group, const char *unix_user); +int smb_delete_user_group(const char *unix_group, const char *unix_user); +NTSTATUS pdb_default_getgrsid(struct pdb_methods *methods, GROUP_MAP *map, + struct dom_sid sid); +NTSTATUS pdb_default_getgrgid(struct pdb_methods *methods, GROUP_MAP *map, + gid_t gid); +NTSTATUS pdb_default_getgrnam(struct pdb_methods *methods, GROUP_MAP *map, + const char *name); +NTSTATUS pdb_default_add_group_mapping_entry(struct pdb_methods *methods, + GROUP_MAP *map); +NTSTATUS pdb_default_update_group_mapping_entry(struct pdb_methods *methods, + GROUP_MAP *map); +NTSTATUS pdb_default_delete_group_mapping_entry(struct pdb_methods *methods, + struct dom_sid sid); +NTSTATUS pdb_default_enum_group_mapping(struct pdb_methods *methods, + const struct dom_sid *sid, + enum lsa_SidType sid_name_use, + GROUP_MAP ***pp_rmap, + size_t *p_num_entries, + bool unix_only); +NTSTATUS pdb_default_create_alias(struct pdb_methods *methods, + const char *name, uint32_t *rid); +NTSTATUS pdb_default_delete_alias(struct pdb_methods *methods, + const struct dom_sid *sid); +NTSTATUS pdb_default_get_aliasinfo(struct pdb_methods *methods, + const struct dom_sid *sid, + struct acct_info *info); +NTSTATUS pdb_default_set_aliasinfo(struct pdb_methods *methods, + const struct dom_sid *sid, + struct acct_info *info); +NTSTATUS pdb_default_add_aliasmem(struct pdb_methods *methods, + const struct dom_sid *alias, const struct dom_sid *member); +NTSTATUS pdb_default_del_aliasmem(struct pdb_methods *methods, + const struct dom_sid *alias, const struct dom_sid *member); +NTSTATUS pdb_default_enum_aliasmem(struct pdb_methods *methods, + const struct dom_sid *alias, TALLOC_CTX *mem_ctx, + struct dom_sid **pp_members, + size_t *p_num_members); +NTSTATUS pdb_default_alias_memberships(struct pdb_methods *methods, + TALLOC_CTX *mem_ctx, + const struct dom_sid *domain_sid, + const struct dom_sid *members, + size_t num_members, + uint32_t **pp_alias_rids, + size_t *p_num_alias_rids); +NTSTATUS pdb_nop_getgrsid(struct pdb_methods *methods, GROUP_MAP *map, + struct dom_sid sid); +NTSTATUS pdb_nop_getgrgid(struct pdb_methods *methods, GROUP_MAP *map, + gid_t gid); +NTSTATUS pdb_nop_getgrnam(struct pdb_methods *methods, GROUP_MAP *map, + const char *name); +NTSTATUS pdb_nop_add_group_mapping_entry(struct pdb_methods *methods, + GROUP_MAP *map); +NTSTATUS pdb_nop_update_group_mapping_entry(struct pdb_methods *methods, + GROUP_MAP *map); +NTSTATUS pdb_nop_delete_group_mapping_entry(struct pdb_methods *methods, + struct dom_sid sid); +NTSTATUS pdb_nop_enum_group_mapping(struct pdb_methods *methods, + enum lsa_SidType sid_name_use, + GROUP_MAP **rmap, size_t *num_entries, + bool unix_only); +NTSTATUS pdb_create_builtin_alias(uint32_t rid, gid_t gid); + + +/* passdb headers */ + +/********************************************************************** + * Masks for mappings between unix uid and gid types and + * NT RIDS. + **********************************************************************/ + +/* Take the bottom bit. */ +#define RID_TYPE_MASK 1 +#define RID_MULTIPLIER 2 + +/* The two common types. */ +#define USER_RID_TYPE 0 +#define GROUP_RID_TYPE 1 + +/* + * Flags for local user manipulation. + */ + +#define LOCAL_ADD_USER 0x1 +#define LOCAL_DELETE_USER 0x2 +#define LOCAL_DISABLE_USER 0x4 +#define LOCAL_ENABLE_USER 0x8 +#define LOCAL_TRUST_ACCOUNT 0x10 +#define LOCAL_SET_NO_PASSWORD 0x20 +#define LOCAL_SET_PASSWORD 0x40 +#define LOCAL_SET_LDAP_ADMIN_PW 0x80 +#define LOCAL_INTERDOM_ACCOUNT 0x100 +#define LOCAL_AM_ROOT 0x200 /* Act as root */ + +/* + * Size of new password account encoding string. This is enough space to + * hold 11 ACB characters, plus the surrounding [] and a terminating null. + * Do not change unless you are adding new ACB bits! + */ + +#define NEW_PW_FORMAT_SPACE_PADDED_LEN 14 + +/* Password history contants. */ +#define PW_HISTORY_SALT_LEN 16 +#define SALTED_MD5_HASH_LEN 16 +#define PW_HISTORY_ENTRY_LEN (PW_HISTORY_SALT_LEN+SALTED_MD5_HASH_LEN) +#define MAX_PW_HISTORY_LEN 24 + +/* + * bit flags representing initialized fields in struct samu + */ +enum pdb_elements { + PDB_UNINIT, + PDB_SMBHOME, + PDB_PROFILE, + PDB_DRIVE, + PDB_LOGONSCRIPT, + PDB_LOGONTIME, + PDB_LOGOFFTIME, + PDB_KICKOFFTIME, + PDB_BAD_PASSWORD_TIME, + PDB_CANCHANGETIME, + PDB_PLAINTEXT_PW, + PDB_USERNAME, + PDB_FULLNAME, + PDB_DOMAIN, + PDB_NTUSERNAME, + PDB_HOURSLEN, + PDB_LOGONDIVS, + PDB_USERSID, + PDB_GROUPSID, + PDB_ACCTCTRL, + PDB_PASSLASTSET, + PDB_ACCTDESC, + PDB_WORKSTATIONS, + PDB_COMMENT, + PDB_MUNGEDDIAL, + PDB_HOURS, + PDB_FIELDS_PRESENT, + PDB_BAD_PASSWORD_COUNT, + PDB_LOGON_COUNT, + PDB_COUNTRY_CODE, + PDB_CODE_PAGE, + PDB_UNKNOWN6, + PDB_LMPASSWD, + PDB_NTPASSWD, + PDB_PWHISTORY, + PDB_BACKEND_PRIVATE_DATA, + + /* this must be the last element */ + PDB_COUNT +}; + +enum pdb_group_elements { + PDB_GROUP_NAME, + PDB_GROUP_SID, + PDB_GROUP_SID_NAME_USE, + PDB_GROUP_MEMBERS, + + /* this must be the last element */ + PDB_GROUP_COUNT +}; + + +enum pdb_value_state { + PDB_DEFAULT=0, + PDB_SET, + PDB_CHANGED +}; + +#define IS_SAM_SET(x, flag) (pdb_get_init_flags(x, flag) == PDB_SET) +#define IS_SAM_CHANGED(x, flag) (pdb_get_init_flags(x, flag) == PDB_CHANGED) +#define IS_SAM_DEFAULT(x, flag) (pdb_get_init_flags(x, flag) == PDB_DEFAULT) + +/* cache for bad password lockout data, to be used on replicated SAMs */ +struct login_cache { + time_t entry_timestamp; + uint32_t acct_ctrl; + uint16_t bad_password_count; + time_t bad_password_time; +}; + +#define SAMU_BUFFER_V0 0 +#define SAMU_BUFFER_V1 1 +#define SAMU_BUFFER_V2 2 +#define SAMU_BUFFER_V3 3 +/* nothing changed from V3 to V4 */ +#define SAMU_BUFFER_V4 4 +#define SAMU_BUFFER_LATEST SAMU_BUFFER_V4 + +#define MAX_HOURS_LEN 32 + +struct samu { + struct pdb_methods *methods; + + /* initialization flags */ + struct bitmap *change_flags; + struct bitmap *set_flags; + + time_t logon_time; /* logon time */ + time_t logoff_time; /* logoff time */ + time_t kickoff_time; /* kickoff time */ + time_t bad_password_time; /* last bad password entered */ + time_t pass_last_set_time; /* password last set time */ + time_t pass_can_change_time; /* password can change time */ + + const char *username; /* UNIX username string */ + const char *domain; /* Windows Domain name */ + const char *nt_username; /* Windows username string */ + const char *full_name; /* user's full name string */ + const char *home_dir; /* home directory string */ + const char *dir_drive; /* home directory drive string */ + const char *logon_script; /* logon script string */ + const char *profile_path; /* profile path string */ + const char *acct_desc; /* user description string */ + const char *workstations; /* login from workstations string */ + const char *comment; + const char *munged_dial; /* munged path name and dial-back tel number */ + + struct dom_sid user_sid; + struct dom_sid *group_sid; + + DATA_BLOB lm_pw; /* .data is Null if no password */ + DATA_BLOB nt_pw; /* .data is Null if no password */ + DATA_BLOB nt_pw_his; /* nt hashed password history .data is Null if not available */ + char* plaintext_pw; /* is Null if not available */ + + uint32_t acct_ctrl; /* account info (ACB_xxxx bit-mask) */ + uint32_t fields_present; /* 0x00ff ffff */ + + uint16_t logon_divs; /* 168 - number of hours in a week */ + uint32_t hours_len; /* normally 21 bytes */ + uint8_t hours[MAX_HOURS_LEN]; + + /* Was unknown_5. */ + uint16_t bad_password_count; + uint16_t logon_count; + + uint16_t country_code; + uint16_t code_page; + + uint32_t unknown_6; /* 0x0000 04ec */ + + /* a tag for who added the private methods */ + + const struct pdb_methods *backend_private_methods; + void *backend_private_data; + void (*backend_private_data_free_fn)(void **); + + /* maintain a copy of the user's struct passwd */ + + struct passwd *unix_pw; +}; + +struct samr_displayentry { + uint32_t idx; + uint32_t rid; + uint32_t acct_flags; + const char *account_name; + const char *fullname; + const char *description; +}; + +enum pdb_search_type { + PDB_USER_SEARCH, + PDB_GROUP_SEARCH, + PDB_ALIAS_SEARCH +}; + +struct pdb_search { + enum pdb_search_type type; + struct samr_displayentry *cache; + uint32_t num_entries; + ssize_t cache_size; + bool search_ended; + void *private_data; + bool (*next_entry)(struct pdb_search *search, + struct samr_displayentry *entry); + void (*search_end)(struct pdb_search *search); +}; + +struct pdb_domain_info { + char *name; + char *dns_domain; + char *dns_forest; + struct dom_sid sid; + struct GUID guid; +}; + +struct pdb_trusted_domain { + char *domain_name; + char *netbios_name; + struct dom_sid security_identifier; + DATA_BLOB trust_auth_incoming; + DATA_BLOB trust_auth_outgoing; + uint32_t trust_direction; + uint32_t trust_type; + uint32_t trust_attributes; + uint32_t *trust_posix_offset; + uint32_t *supported_enc_type; + DATA_BLOB trust_forest_trust_info; +}; + +/* + * trusted domain entry/entries returned by secrets_get_trusted_domains + * (used in _lsa_enum_trust_dom call) + */ +struct trustdom_info { + char *name; + struct dom_sid sid; +}; + +/* + * Types of account policy. + */ +enum pdb_policy_type { + PDB_POLICY_MIN_PASSWORD_LEN = 1, + PDB_POLICY_PASSWORD_HISTORY = 2, + PDB_POLICY_USER_MUST_LOGON_TO_CHG_PASS = 3, + PDB_POLICY_MAX_PASSWORD_AGE = 4, + PDB_POLICY_MIN_PASSWORD_AGE = 5, + PDB_POLICY_LOCK_ACCOUNT_DURATION = 6, + PDB_POLICY_RESET_COUNT_TIME = 7, + PDB_POLICY_BAD_ATTEMPT_LOCKOUT = 8, + PDB_POLICY_TIME_TO_LOGOUT = 9, + PDB_POLICY_REFUSE_MACHINE_PW_CHANGE = 10 +}; + +#define PDB_CAP_STORE_RIDS 0x0001 +#define PDB_CAP_ADS 0x0002 +#define PDB_CAP_TRUSTED_DOMAINS_EX 0x0004 + +/***************************************************************** + Functions to be implemented by the new (v2) passdb API +****************************************************************/ + +/* + * This next constant specifies the version number of the PASSDB interface + * this SAMBA will load. Increment this if *ANY* changes are made to the interface. + * Changed interface to fix int -> size_t problems. JRA. + * There's no point in allocating arrays in + * samr_lookup_rids twice. It was done in the srv_samr_nt.c code as well as in + * the pdb module. Remove the latter, this might happen more often. VL. + * changed to version 14 to move lookup_rids and lookup_names to return + * enum lsa_SidType rather than uint32_t. + * Changed to 16 for access to the trusted domain passwords (obnox). + * Changed to 17, the sampwent interface is gone. + * Changed to 18, pdb_rid_algorithm -> pdb_capabilities + * Changed to 19, removed uid_to_rid + * Changed to 20, pdb_secret calls + * Changed to 21, set/enum_upn_suffixes. AB. + * Changed to 22, idmap control functions + * Changed to 23, new idmap control functions + * Changed to 24, removed uid_to_sid and gid_to_sid, replaced with id_to_sid + * Leave at 24, add optional get_trusteddom_creds() + * Change to 25, loadable modules now have a TALLOC_CTX * parameter in init. + */ + +#define PASSDB_INTERFACE_VERSION 25 + +struct pdb_methods +{ + const char *name; /* What name got this module */ + + struct pdb_domain_info *(*get_domain_info)(struct pdb_methods *, + TALLOC_CTX *mem_ctx); + + NTSTATUS (*getsampwnam)(struct pdb_methods *, struct samu *sam_acct, const char *username); + + NTSTATUS (*getsampwsid)(struct pdb_methods *, struct samu *sam_acct, const struct dom_sid *sid); + + NTSTATUS (*create_user)(struct pdb_methods *, TALLOC_CTX *tmp_ctx, + const char *name, uint32_t acct_flags, + uint32_t *rid); + + NTSTATUS (*delete_user)(struct pdb_methods *, TALLOC_CTX *tmp_ctx, + struct samu *sam_acct); + + NTSTATUS (*add_sam_account)(struct pdb_methods *, struct samu *sampass); + + NTSTATUS (*update_sam_account)(struct pdb_methods *, struct samu *sampass); + + NTSTATUS (*delete_sam_account)(struct pdb_methods *, struct samu *username); + + NTSTATUS (*rename_sam_account)(struct pdb_methods *, struct samu *oldname, const char *newname); + + NTSTATUS (*update_login_attempts)(struct pdb_methods *methods, struct samu *sam_acct, bool success); + + NTSTATUS (*getgrsid)(struct pdb_methods *methods, GROUP_MAP *map, struct dom_sid sid); + + NTSTATUS (*getgrgid)(struct pdb_methods *methods, GROUP_MAP *map, gid_t gid); + + NTSTATUS (*getgrnam)(struct pdb_methods *methods, GROUP_MAP *map, const char *name); + + NTSTATUS (*create_dom_group)(struct pdb_methods *methods, + TALLOC_CTX *mem_ctx, const char *name, + uint32_t *rid); + + NTSTATUS (*delete_dom_group)(struct pdb_methods *methods, + TALLOC_CTX *mem_ctx, uint32_t rid); + + NTSTATUS (*add_group_mapping_entry)(struct pdb_methods *methods, + GROUP_MAP *map); + + NTSTATUS (*update_group_mapping_entry)(struct pdb_methods *methods, + GROUP_MAP *map); + + NTSTATUS (*delete_group_mapping_entry)(struct pdb_methods *methods, + struct dom_sid sid); + + NTSTATUS (*enum_group_mapping)(struct pdb_methods *methods, + const struct dom_sid *sid, enum lsa_SidType sid_name_use, + GROUP_MAP ***pp_rmap, size_t *p_num_entries, + bool unix_only); + + NTSTATUS (*enum_group_members)(struct pdb_methods *methods, + TALLOC_CTX *mem_ctx, + const struct dom_sid *group, + uint32_t **pp_member_rids, + size_t *p_num_members); + + NTSTATUS (*enum_group_memberships)(struct pdb_methods *methods, + TALLOC_CTX *mem_ctx, + struct samu *user, + struct dom_sid **pp_sids, gid_t **pp_gids, + uint32_t *p_num_groups); + + NTSTATUS (*set_unix_primary_group)(struct pdb_methods *methods, + TALLOC_CTX *mem_ctx, + struct samu *user); + + NTSTATUS (*add_groupmem)(struct pdb_methods *methods, + TALLOC_CTX *mem_ctx, + uint32_t group_rid, uint32_t member_rid); + + NTSTATUS (*del_groupmem)(struct pdb_methods *methods, + TALLOC_CTX *mem_ctx, + uint32_t group_rid, uint32_t member_rid); + + NTSTATUS (*create_alias)(struct pdb_methods *methods, + const char *name, uint32_t *rid); + + NTSTATUS (*delete_alias)(struct pdb_methods *methods, + const struct dom_sid *sid); + + NTSTATUS (*get_aliasinfo)(struct pdb_methods *methods, + const struct dom_sid *sid, + struct acct_info *info); + + NTSTATUS (*set_aliasinfo)(struct pdb_methods *methods, + const struct dom_sid *sid, + struct acct_info *info); + + NTSTATUS (*add_aliasmem)(struct pdb_methods *methods, + const struct dom_sid *alias, const struct dom_sid *member); + NTSTATUS (*del_aliasmem)(struct pdb_methods *methods, + const struct dom_sid *alias, const struct dom_sid *member); + NTSTATUS (*enum_aliasmem)(struct pdb_methods *methods, + const struct dom_sid *alias, TALLOC_CTX *mem_ctx, + struct dom_sid **members, size_t *p_num_members); + NTSTATUS (*enum_alias_memberships)(struct pdb_methods *methods, + TALLOC_CTX *mem_ctx, + const struct dom_sid *domain_sid, + const struct dom_sid *members, + size_t num_members, + uint32_t **pp_alias_rids, + size_t *p_num_alias_rids); + + NTSTATUS (*lookup_rids)(struct pdb_methods *methods, + const struct dom_sid *domain_sid, + int num_rids, + uint32_t *rids, + const char **pp_names, + enum lsa_SidType *attrs); + + NTSTATUS (*lookup_names)(struct pdb_methods *methods, + const struct dom_sid *domain_sid, + int num_names, + const char **pp_names, + uint32_t *rids, + enum lsa_SidType *attrs); + + NTSTATUS (*get_account_policy)(struct pdb_methods *methods, + enum pdb_policy_type type, + uint32_t *value); + + NTSTATUS (*set_account_policy)(struct pdb_methods *methods, + enum pdb_policy_type type, + uint32_t value); + + NTSTATUS (*get_seq_num)(struct pdb_methods *methods, time_t *seq_num); + + bool (*search_users)(struct pdb_methods *methods, + struct pdb_search *search, + uint32_t acct_flags); + bool (*search_groups)(struct pdb_methods *methods, + struct pdb_search *search); + bool (*search_aliases)(struct pdb_methods *methods, + struct pdb_search *search, + const struct dom_sid *sid); + + /* + * Instead of passing down a gid or uid, this function sends down a pointer + * to a unixid. + * + * This acts as an in-out variable so that the idmap functions can correctly + * receive ID_TYPE_BOTH, filling in cache details correctly rather than forcing + * the cache to store ID_TYPE_UID or ID_TYPE_GID. + */ + bool (*id_to_sid)(struct pdb_methods *methods, struct unixid *id, + struct dom_sid *sid); + bool (*sid_to_id)(struct pdb_methods *methods, const struct dom_sid *sid, + struct unixid *id); + + uint32_t (*capabilities)(struct pdb_methods *methods); + bool (*new_rid)(struct pdb_methods *methods, uint32_t *rid); + + + bool (*get_trusteddom_pw)(struct pdb_methods *methods, + const char *domain, char** pwd, + struct dom_sid *sid, time_t *pass_last_set_time); + NTSTATUS (*get_trusteddom_creds)(struct pdb_methods *methods, + const char *domain, + TALLOC_CTX *mem_ctx, + struct cli_credentials **creds); + bool (*set_trusteddom_pw)(struct pdb_methods *methods, + const char* domain, const char* pwd, + const struct dom_sid *sid); + bool (*del_trusteddom_pw)(struct pdb_methods *methods, + const char *domain); + NTSTATUS (*enum_trusteddoms)(struct pdb_methods *methods, + TALLOC_CTX *mem_ctx, uint32_t *num_domains, + struct trustdom_info ***domains); + + NTSTATUS (*get_trusted_domain)(struct pdb_methods *methods, + TALLOC_CTX *mem_ctx, + const char *domain, + struct pdb_trusted_domain **td); + NTSTATUS (*get_trusted_domain_by_sid)(struct pdb_methods *methods, + TALLOC_CTX *mem_ctx, + struct dom_sid *sid, + struct pdb_trusted_domain **td); + NTSTATUS (*set_trusted_domain)(struct pdb_methods *methods, + const char* domain, + const struct pdb_trusted_domain *td); + NTSTATUS (*del_trusted_domain)(struct pdb_methods *methods, + const char *domain); + NTSTATUS (*enum_trusted_domains)(struct pdb_methods *methods, + TALLOC_CTX *mem_ctx, + uint32_t *num_domains, + struct pdb_trusted_domain ***domains); + + NTSTATUS (*get_secret)(struct pdb_methods *methods, + TALLOC_CTX *mem_ctx, + const char *secret_name, + DATA_BLOB *secret_current, + NTTIME *secret_current_lastchange, + DATA_BLOB *secret_old, + NTTIME *secret_old_lastchange, + struct security_descriptor **sd); + NTSTATUS (*set_secret)(struct pdb_methods *methods, + const char *secret_name, + DATA_BLOB *secret_current, + DATA_BLOB *secret_old, + struct security_descriptor *sd); + NTSTATUS (*delete_secret)(struct pdb_methods *methods, + const char *secret_name); + + NTSTATUS (*enum_upn_suffixes)(struct pdb_methods *methods, + TALLOC_CTX *mem_ctx, + uint32_t *num_suffixes, + char ***suffixes); + + NTSTATUS (*set_upn_suffixes)(struct pdb_methods *methods, + uint32_t num_suffixes, + const char **suffixes); + + bool (*is_responsible_for_our_sam)(struct pdb_methods *methods); + bool (*is_responsible_for_builtin)(struct pdb_methods *methods); + bool (*is_responsible_for_wellknown)(struct pdb_methods *methods); + bool (*is_responsible_for_unix_users)(struct pdb_methods *methods); + bool (*is_responsible_for_unix_groups)(struct pdb_methods *methods); + bool (*is_responsible_for_everything_else)(struct pdb_methods *methods); + + void *private_data; /* Private data of some kind */ + + void (*free_private_data)(void **); +}; + +typedef NTSTATUS (*pdb_init_function)(struct pdb_methods **, const char *); + +struct pdb_init_function_entry { + const char *name; + + /* Function to create a member of the pdb_methods list */ + pdb_init_function init; + + struct pdb_init_function_entry *prev, *next; +}; + +/* The following definitions come from passdb/account_pol.c */ + +void account_policy_names_list(TALLOC_CTX *mem_ctx, const char ***names, int *num_names); +const char *decode_account_policy_name(enum pdb_policy_type type); +const char *get_account_policy_attr(enum pdb_policy_type type); +const char *account_policy_get_desc(enum pdb_policy_type type); +enum pdb_policy_type account_policy_name_to_typenum(const char *name); +bool account_policy_get_default(enum pdb_policy_type type, uint32_t *val); +bool init_account_policy(void); +bool account_policy_get(enum pdb_policy_type type, uint32_t *value); +bool account_policy_set(enum pdb_policy_type type, uint32_t value); +bool cache_account_policy_set(enum pdb_policy_type type, uint32_t value); +bool cache_account_policy_get(enum pdb_policy_type type, uint32_t *value); +struct db_context *get_account_pol_db( void ); + +/* The following definitions come from passdb/login_cache.c */ + +bool login_cache_init(void); +bool login_cache_shutdown(void); +bool login_cache_read(struct samu *sampass, struct login_cache *entry); +bool login_cache_write(const struct samu *sampass, + const struct login_cache *entry); +bool login_cache_delentry(const struct samu *sampass); + +/* The following definitions come from passdb/passdb.c */ + +struct samu *samu_new( TALLOC_CTX *ctx ); +NTSTATUS samu_set_unix(struct samu *user, const struct passwd *pwd); +NTSTATUS samu_alloc_rid_unix(struct pdb_methods *methods, + struct samu *user, const struct passwd *pwd); +char *pdb_encode_acct_ctrl(uint32_t acct_ctrl, size_t length); +uint32_t pdb_decode_acct_ctrl(const char *p); +void pdb_sethexpwd(char p[33], const unsigned char *pwd, uint32_t acct_ctrl); +bool pdb_gethexpwd(const char *p, unsigned char *pwd); +void pdb_sethexhours(char *p, const unsigned char *hours); +bool pdb_gethexhours(const char *p, unsigned char *hours); +int algorithmic_rid_base(void); +uid_t algorithmic_pdb_user_rid_to_uid(uint32_t user_rid); +uid_t max_algorithmic_uid(void); +uint32_t algorithmic_pdb_uid_to_user_rid(uid_t uid); +gid_t pdb_group_rid_to_gid(uint32_t group_rid); +gid_t max_algorithmic_gid(void); +uint32_t algorithmic_pdb_gid_to_group_rid(gid_t gid); +bool algorithmic_pdb_rid_is_user(uint32_t rid); +bool lookup_global_sam_name(const char *name, int flags, uint32_t *rid, + enum lsa_SidType *type); +NTSTATUS local_password_change(const char *user_name, + int local_flags, + const char *new_passwd, + char **pp_err_str, + char **pp_msg_str); +bool init_samu_from_buffer(struct samu *sampass, uint32_t level, + uint8_t *buf, uint32_t buflen); +uint32_t init_buffer_from_samu (uint8_t **buf, struct samu *sampass, bool size_only); +bool pdb_copy_sam_account(struct samu *dst, struct samu *src ); +bool pdb_update_bad_password_count(struct samu *sampass, bool *updated); +bool pdb_update_autolock_flag(struct samu *sampass, bool *updated); +bool pdb_increment_bad_password_count(struct samu *sampass); +bool is_dc_trusted_domain_situation(const char *domain_name); +bool get_trust_pw_clear(const char *domain, char **ret_pwd, + const char **account_name, + enum netr_SchannelType *channel); +bool get_trust_pw_hash(const char *domain, uint8_t ret_pwd[16], + const char **account_name, + enum netr_SchannelType *channel); +struct cli_credentials; +NTSTATUS pdb_get_trust_credentials(const char *netbios_domain, + const char *dns_domain, /* optional */ + TALLOC_CTX *mem_ctx, + struct cli_credentials **_creds); + +/* The following definitions come from passdb/pdb_compat.c */ + +uint32_t pdb_get_user_rid (const struct samu *sampass); +uint32_t pdb_get_group_rid (struct samu *sampass); +bool pdb_set_user_sid_from_rid (struct samu *sampass, uint32_t rid, enum pdb_value_state flag); +bool pdb_set_group_sid_from_rid (struct samu *sampass, uint32_t grid, enum pdb_value_state flag); + +/* The following definitions come from passdb/pdb_get_set.c */ + +bool pdb_is_password_change_time_max(time_t test_time); +uint32_t pdb_get_acct_ctrl(const struct samu *sampass); +time_t pdb_get_logon_time(const struct samu *sampass); +time_t pdb_get_logoff_time(const struct samu *sampass); +time_t pdb_get_kickoff_time(const struct samu *sampass); +time_t pdb_get_bad_password_time(const struct samu *sampass); +time_t pdb_get_pass_last_set_time(const struct samu *sampass); +time_t pdb_get_pass_can_change_time(const struct samu *sampass); +time_t pdb_get_pass_can_change_time_noncalc(const struct samu *sampass); +time_t pdb_get_pass_must_change_time(const struct samu *sampass); +bool pdb_get_pass_can_change(const struct samu *sampass); +uint16_t pdb_get_logon_divs(const struct samu *sampass); +uint32_t pdb_get_hours_len(const struct samu *sampass); +const uint8_t *pdb_get_hours(const struct samu *sampass); +const uint8_t *pdb_get_nt_passwd(const struct samu *sampass); +const uint8_t *pdb_get_lanman_passwd(const struct samu *sampass); +const uint8_t *pdb_get_pw_history(const struct samu *sampass, uint32_t *current_hist_len); +const char *pdb_get_plaintext_passwd(const struct samu *sampass); +const struct dom_sid *pdb_get_user_sid(const struct samu *sampass); +const struct dom_sid *pdb_get_group_sid(struct samu *sampass); +enum pdb_value_state pdb_get_init_flags(const struct samu *sampass, enum pdb_elements element); +const char *pdb_get_username(const struct samu *sampass); +const char *pdb_get_domain(const struct samu *sampass); +const char *pdb_get_nt_username(const struct samu *sampass); +const char *pdb_get_fullname(const struct samu *sampass); +const char *pdb_get_homedir(const struct samu *sampass); +const char *pdb_get_dir_drive(const struct samu *sampass); +const char *pdb_get_logon_script(const struct samu *sampass); +const char *pdb_get_profile_path(const struct samu *sampass); +const char *pdb_get_acct_desc(const struct samu *sampass); +const char *pdb_get_workstations(const struct samu *sampass); +const char *pdb_get_comment(const struct samu *sampass); +const char *pdb_get_munged_dial(const struct samu *sampass); +uint16_t pdb_get_bad_password_count(const struct samu *sampass); +uint16_t pdb_get_logon_count(const struct samu *sampass); +uint16_t pdb_get_country_code(const struct samu *sampass); +uint16_t pdb_get_code_page(const struct samu *sampass); +uint32_t pdb_get_unknown_6(const struct samu *sampass); +void *pdb_get_backend_private_data(const struct samu *sampass, const struct pdb_methods *my_methods); +bool pdb_set_acct_ctrl(struct samu *sampass, uint32_t acct_ctrl, enum pdb_value_state flag); +bool pdb_set_logon_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag); +bool pdb_set_logoff_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag); +bool pdb_set_kickoff_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag); +bool pdb_set_bad_password_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag); +bool pdb_set_pass_can_change_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag); +bool pdb_set_pass_last_set_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag); +bool pdb_set_hours_len(struct samu *sampass, uint32_t len, enum pdb_value_state flag); +bool pdb_set_logon_divs(struct samu *sampass, uint16_t hours, enum pdb_value_state flag); +bool pdb_set_init_flags(struct samu *sampass, enum pdb_elements element, enum pdb_value_state value_flag); +bool pdb_set_user_sid(struct samu *sampass, const struct dom_sid *u_sid, enum pdb_value_state flag); +bool pdb_set_user_sid_from_string(struct samu *sampass, const char *u_sid, enum pdb_value_state flag); +bool pdb_set_group_sid(struct samu *sampass, const struct dom_sid *g_sid, enum pdb_value_state flag); +bool pdb_set_username(struct samu *sampass, const char *username, enum pdb_value_state flag); +bool pdb_set_domain(struct samu *sampass, const char *domain, enum pdb_value_state flag); +bool pdb_set_nt_username(struct samu *sampass, const char *nt_username, enum pdb_value_state flag); +bool pdb_set_fullname(struct samu *sampass, const char *full_name, enum pdb_value_state flag); +bool pdb_set_logon_script(struct samu *sampass, const char *logon_script, enum pdb_value_state flag); +bool pdb_set_profile_path(struct samu *sampass, const char *profile_path, enum pdb_value_state flag); +bool pdb_set_dir_drive(struct samu *sampass, const char *dir_drive, enum pdb_value_state flag); +bool pdb_set_homedir(struct samu *sampass, const char *home_dir, enum pdb_value_state flag); +bool pdb_set_acct_desc(struct samu *sampass, const char *acct_desc, enum pdb_value_state flag); +bool pdb_set_workstations(struct samu *sampass, const char *workstations, enum pdb_value_state flag); +bool pdb_set_comment(struct samu *sampass, const char *comment, enum pdb_value_state flag); +bool pdb_set_munged_dial(struct samu *sampass, const char *munged_dial, enum pdb_value_state flag); +bool pdb_set_nt_passwd(struct samu *sampass, const uint8_t pwd[NT_HASH_LEN], enum pdb_value_state flag); +bool pdb_set_lanman_passwd(struct samu *sampass, const uint8_t pwd[LM_HASH_LEN], enum pdb_value_state flag); +bool pdb_set_pw_history(struct samu *sampass, const uint8_t *pwd, uint32_t historyLen, enum pdb_value_state flag); +bool pdb_set_plaintext_pw_only(struct samu *sampass, const char *password, enum pdb_value_state flag); +bool pdb_update_history(struct samu *sampass, const uint8_t new_nt[NT_HASH_LEN]); +bool pdb_set_bad_password_count(struct samu *sampass, uint16_t bad_password_count, enum pdb_value_state flag); +bool pdb_set_logon_count(struct samu *sampass, uint16_t logon_count, enum pdb_value_state flag); +bool pdb_set_country_code(struct samu *sampass, uint16_t country_code, + enum pdb_value_state flag); +bool pdb_set_code_page(struct samu *sampass, uint16_t code_page, + enum pdb_value_state flag); +bool pdb_set_unknown_6(struct samu *sampass, uint32_t unkn, enum pdb_value_state flag); +bool pdb_set_hours(struct samu *sampass, const uint8_t *hours, int hours_len, + enum pdb_value_state flag); +bool pdb_set_backend_private_data(struct samu *sampass, void *private_data, + void (*free_fn)(void **), + const struct pdb_methods *my_methods, + enum pdb_value_state flag); +bool pdb_set_pass_can_change(struct samu *sampass, bool canchange); +bool pdb_set_plaintext_passwd(struct samu *sampass, const char *plaintext); +uint32_t pdb_build_fields_present(struct samu *sampass); +bool pdb_element_is_changed(const struct samu *sampass, + enum pdb_elements element); +bool pdb_element_is_set_or_changed(const struct samu *sampass, + enum pdb_elements element); + +/* The following definitions come from passdb/pdb_interface.c */ + +NTSTATUS smb_register_passdb(int version, const char *name, pdb_init_function init) ; +struct pdb_init_function_entry *pdb_find_backend_entry(const char *name); +const struct pdb_init_function_entry *pdb_get_backends(void); +struct tevent_context *pdb_get_tevent_context(void); +NTSTATUS make_pdb_method_name(struct pdb_methods **methods, const char *selected); +struct pdb_domain_info *pdb_get_domain_info(TALLOC_CTX *mem_ctx); +bool pdb_getsampwnam(struct samu *sam_acct, const char *username) ; +bool pdb_getsampwsid(struct samu *sam_acct, const struct dom_sid *sid) ; +NTSTATUS pdb_create_user(TALLOC_CTX *mem_ctx, const char *name, uint32_t flags, + uint32_t *rid); +NTSTATUS pdb_delete_user(TALLOC_CTX *mem_ctx, struct samu *sam_acct); +NTSTATUS pdb_add_sam_account(struct samu *sam_acct) ; +NTSTATUS pdb_update_sam_account(struct samu *sam_acct) ; +NTSTATUS pdb_delete_sam_account(struct samu *sam_acct) ; +NTSTATUS pdb_rename_sam_account(struct samu *oldname, const char *newname); +NTSTATUS pdb_update_login_attempts(struct samu *sam_acct, bool success); +bool pdb_getgrsid(GROUP_MAP *map, struct dom_sid sid); +bool pdb_getgrgid(GROUP_MAP *map, gid_t gid); +bool pdb_getgrnam(GROUP_MAP *map, const char *name); +NTSTATUS pdb_create_dom_group(TALLOC_CTX *mem_ctx, const char *name, + uint32_t *rid); +NTSTATUS pdb_delete_dom_group(TALLOC_CTX *mem_ctx, uint32_t rid); +NTSTATUS pdb_add_group_mapping_entry(GROUP_MAP *map); +NTSTATUS pdb_update_group_mapping_entry(GROUP_MAP *map); +NTSTATUS pdb_delete_group_mapping_entry(struct dom_sid sid); +bool pdb_enum_group_mapping(const struct dom_sid *sid, + enum lsa_SidType sid_name_use, + GROUP_MAP ***pp_rmap, + size_t *p_num_entries, + bool unix_only); +NTSTATUS pdb_enum_group_members(TALLOC_CTX *mem_ctx, + const struct dom_sid *sid, + uint32_t **pp_member_rids, + size_t *p_num_members); +NTSTATUS pdb_enum_group_memberships(TALLOC_CTX *mem_ctx, struct samu *user, + struct dom_sid **pp_sids, gid_t **pp_gids, + uint32_t *p_num_groups); +NTSTATUS pdb_set_unix_primary_group(TALLOC_CTX *mem_ctx, struct samu *user); +NTSTATUS pdb_add_groupmem(TALLOC_CTX *mem_ctx, uint32_t group_rid, + uint32_t member_rid); +NTSTATUS pdb_del_groupmem(TALLOC_CTX *mem_ctx, uint32_t group_rid, + uint32_t member_rid); +NTSTATUS pdb_create_alias(const char *name, uint32_t *rid); +NTSTATUS pdb_delete_alias(const struct dom_sid *sid); +NTSTATUS pdb_get_aliasinfo(const struct dom_sid *sid, struct acct_info *info); +NTSTATUS pdb_set_aliasinfo(const struct dom_sid *sid, struct acct_info *info); +NTSTATUS pdb_add_aliasmem(const struct dom_sid *alias, const struct dom_sid *member); +NTSTATUS pdb_del_aliasmem(const struct dom_sid *alias, const struct dom_sid *member); +NTSTATUS pdb_enum_aliasmem(const struct dom_sid *alias, TALLOC_CTX *mem_ctx, + struct dom_sid **pp_members, size_t *p_num_members); +NTSTATUS pdb_enum_alias_memberships(TALLOC_CTX *mem_ctx, + const struct dom_sid *domain_sid, + const struct dom_sid *members, size_t num_members, + uint32_t **pp_alias_rids, + size_t *p_num_alias_rids); +NTSTATUS pdb_lookup_rids(const struct dom_sid *domain_sid, + int num_rids, + uint32_t *rids, + const char **names, + enum lsa_SidType *attrs); +bool pdb_get_account_policy(enum pdb_policy_type type, uint32_t *value); +bool pdb_set_account_policy(enum pdb_policy_type type, uint32_t value); +bool pdb_get_seq_num(time_t *seq_num); +/* + * Instead of passing down a gid or uid, this function sends down a pointer + * to a unixid. + * + * This acts as an in-out variable so that the idmap functions can correctly + * receive ID_TYPE_BOTH, filling in cache details correctly rather than forcing + * the cache to store ID_TYPE_UID or ID_TYPE_GID. + */ +bool pdb_id_to_sid(struct unixid *id, struct dom_sid *sid); +bool pdb_sid_to_id(const struct dom_sid *sid, struct unixid *id); +uint32_t pdb_capabilities(void); +bool pdb_new_rid(uint32_t *rid); +bool initialize_password_db(bool reload, struct tevent_context *tevent_ctx); +struct pdb_search *pdb_search_init(TALLOC_CTX *mem_ctx, + enum pdb_search_type type); +struct pdb_search *pdb_search_users(TALLOC_CTX *mem_ctx, uint32_t acct_flags); +struct pdb_search *pdb_search_groups(TALLOC_CTX *mem_ctx); +struct pdb_search *pdb_search_aliases(TALLOC_CTX *mem_ctx, const struct dom_sid *sid); +uint32_t pdb_search_entries(struct pdb_search *search, + uint32_t start_idx, uint32_t max_entries, + struct samr_displayentry **result); +bool pdb_get_trusteddom_pw(const char *domain, char** pwd, struct dom_sid *sid, + time_t *pass_last_set_time); +NTSTATUS pdb_get_trusteddom_creds(const char *domain, TALLOC_CTX *mem_ctx, + struct cli_credentials **creds); +bool pdb_set_trusteddom_pw(const char* domain, const char* pwd, + const struct dom_sid *sid); +bool pdb_del_trusteddom_pw(const char *domain); +NTSTATUS pdb_enum_trusteddoms(TALLOC_CTX *mem_ctx, uint32_t *num_domains, + struct trustdom_info ***domains); +NTSTATUS pdb_get_trusted_domain(TALLOC_CTX *mem_ctx, const char *domain, + struct pdb_trusted_domain **td); +NTSTATUS pdb_get_trusted_domain_by_sid(TALLOC_CTX *mem_ctx, struct dom_sid *sid, + struct pdb_trusted_domain **td); +NTSTATUS pdb_set_trusted_domain(const char* domain, + const struct pdb_trusted_domain *td); +NTSTATUS pdb_del_trusted_domain(const char *domain); +NTSTATUS pdb_enum_trusted_domains(TALLOC_CTX *mem_ctx, uint32_t *num_domains, + struct pdb_trusted_domain ***domains); +NTSTATUS make_pdb_method( struct pdb_methods **methods ) ; +NTSTATUS pdb_get_secret(TALLOC_CTX *mem_ctx, + const char *secret_name, + DATA_BLOB *secret_current, + NTTIME *secret_current_lastchange, + DATA_BLOB *secret_old, + NTTIME *secret_old_lastchange, + struct security_descriptor **sd); +NTSTATUS pdb_set_secret(const char *secret_name, + DATA_BLOB *secret_current, + DATA_BLOB *secret_old, + struct security_descriptor *sd); +NTSTATUS pdb_delete_secret(const char *secret_name); +bool pdb_sid_to_id_unix_users_and_groups(const struct dom_sid *sid, + struct unixid *id); + +NTSTATUS pdb_enum_upn_suffixes(TALLOC_CTX *mem_ctx, + uint32_t *num_suffixes, + char ***suffixes); + +NTSTATUS pdb_set_upn_suffixes(uint32_t num_suffixes, + const char **suffixes); +bool pdb_is_responsible_for_our_sam(void); +bool pdb_is_responsible_for_builtin(void); +bool pdb_is_responsible_for_wellknown(void); +bool pdb_is_responsible_for_unix_users(void); +bool pdb_is_responsible_for_unix_groups(void); +bool pdb_is_responsible_for_everything_else(void); + +/* The following definitions come from passdb/pdb_util.c */ + +NTSTATUS pdb_create_builtin(uint32_t rid); +NTSTATUS create_builtin_users(const struct dom_sid *sid); +NTSTATUS create_builtin_administrators(const struct dom_sid *sid); +NTSTATUS create_builtin_guests(const struct dom_sid *dom_sid); + +#include "passdb/machine_sid.h" +#include "passdb/lookup_sid.h" + +/* The following definitions come from passdb/pdb_secrets.c + * and should be used by PDB modules if they need to store + * sid/guid information for the domain in secrets database + */ +bool PDB_secrets_mark_domain_protected(const char *domain); +bool PDB_secrets_clear_domain_protection(const char *domain); +bool PDB_secrets_store_domain_sid(const char *domain, const struct dom_sid *sid); +bool PDB_secrets_fetch_domain_sid(const char *domain, struct dom_sid *sid); +bool PDB_secrets_store_domain_guid(const char *domain, struct GUID *guid); +bool PDB_secrets_fetch_domain_guid(const char *domain, struct GUID *guid); + +#endif /* _PASSDB_H */ diff --git a/source3/include/printing.h b/source3/include/printing.h new file mode 100644 index 0000000..20a2eb3 --- /dev/null +++ b/source3/include/printing.h @@ -0,0 +1,262 @@ +/* + Unix SMB/CIFS implementation. + printing definitions + Copyright (C) Andrew Tridgell 1992-2000 + + 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/>. +*/ + +/* + This file defines the low-level printing system interfaces used by the + SAMBA printing subsystem. +*/ +#ifndef PRINTING_H_ +#define PRINTING_H_ + +#include <tdb.h> +#include "lib/param/loadparm.h" + +/* Extra fields above "LPQ_PRINTING" are used to map extra NT status codes. */ + +enum { + LPQ_QUEUED = 0, + LPQ_PAUSED, + LPQ_SPOOLING, + LPQ_PRINTING, + LPQ_ERROR, + LPQ_DELETING, + LPQ_OFFLINE, + LPQ_PAPEROUT, + LPQ_PRINTED, + LPQ_DELETED, + LPQ_BLOCKED, + LPQ_USER_INTERVENTION, + + /* smbd is dooing the file spooling before passing control to spoolss */ + PJOB_SMBD_SPOOLING +}; + +typedef struct _print_queue_struct { + int sysjob; /* normally the UNIX jobid -- see note in + printing.c:traverse_fn_delete() */ + int size; + int page_count; + int status; + int priority; + time_t time; + fstring fs_user; + fstring fs_file; +} print_queue_struct; + +enum {LPSTAT_OK, LPSTAT_STOPPED, LPSTAT_ERROR}; + +typedef struct { + fstring message; + size_t qcount; + int status; +} print_status_struct; + +/* Information for print jobs */ +struct printjob { + pid_t pid; /* which process launched the job */ + uint32_t jobid; /* the spoolss print job identifier */ + int sysjob; /* the system (lp) job number */ + int fd; /* file descriptor of open file if open */ + time_t starttime; /* when the job started spooling */ + int status; /* the status of this job */ + size_t size; /* the size of the job so far */ + int page_count; /* then number of pages so far */ + bool spooled; /* has it been sent to the spooler yet? */ + bool smbjob; /* set if the job is a SMB job */ + fstring filename; /* the filename used to spool the file */ + fstring jobname; /* the job name given to us by the client */ + fstring user; /* the user who started the job */ + fstring clientmachine; /* The client machine which started this job */ + fstring queuename; /* service number of printer for this job */ + struct spoolss_DeviceMode *devmode; +}; + +/* Information for print interfaces */ +struct printif +{ + /* value of the 'printing' option for this service */ + enum printing_types type; + + int (*queue_get)(const char *printer_name, + enum printing_types printing_type, + char *lpq_command, + print_queue_struct **q, + print_status_struct *status); + int (*queue_pause)(int snum); + int (*queue_resume)(int snum); + int (*job_delete)(const char *sharename, const char *lprm_command, struct printjob *pjob); + int (*job_pause)(int snum, struct printjob *pjob); + int (*job_resume)(int snum, struct printjob *pjob); + int (*job_submit)(int snum, struct printjob *pjob, + enum printing_types printing_type, + char *lpq_command); +}; + +extern struct printif generic_printif; + +#ifdef HAVE_CUPS +extern struct printif cups_printif; +#endif /* HAVE_CUPS */ + +#ifdef HAVE_IPRINT +extern struct printif iprint_printif; +#endif /* HAVE_IPRINT */ + +/* PRINT_MAX_JOBID is now defined in local.h */ +#define UNIX_JOB_START PRINT_MAX_JOBID +#define NEXT_JOBID(j) ((j+1) % PRINT_MAX_JOBID > 0 ? (j+1) % PRINT_MAX_JOBID : 1) + +#define MAX_CACHE_VALID_TIME 3600 +#define CUPS_DEFAULT_CONNECTION_TIMEOUT 30 + +#ifndef PRINT_SPOOL_PREFIX +#define PRINT_SPOOL_PREFIX "smbprn." +#endif +#define PRINT_DATABASE_VERSION 8 + +#ifdef AIX +#define DEFAULT_PRINTING PRINT_AIX +#define PRINTCAP_NAME "/etc/qconfig" +#endif + +#ifdef HPUX +#define DEFAULT_PRINTING PRINT_HPUX +#endif + +#ifdef QNX +#define DEFAULT_PRINTING PRINT_QNX +#endif + +#ifndef DEFAULT_PRINTING +#ifdef HAVE_CUPS +#define DEFAULT_PRINTING PRINT_CUPS +#define PRINTCAP_NAME "cups" +#elif defined(SYSV) +#define DEFAULT_PRINTING PRINT_SYSV +#define PRINTCAP_NAME "lpstat" +#else +#define DEFAULT_PRINTING PRINT_BSD +#define PRINTCAP_NAME "/etc/printcap" +#endif +#endif + +#ifndef PRINTCAP_NAME +#define PRINTCAP_NAME "/etc/printcap" +#endif + +/* There can be this many printing tdb's open, plus any locked ones. */ +#define MAX_PRINT_DBS_OPEN 1 + +struct tdb_print_db { + struct tdb_print_db *next, *prev; + struct tdb_context *tdb; + int ref_count; + fstring printer_name; +}; + +/* + * Used for print notify + */ + +#define NOTIFY_PID_LIST_KEY "NOTIFY_PID_LIST" + +/* The following definitions come from printing/printspoolss.c */ + +NTSTATUS print_spool_open(files_struct *fsp, + const char *fname, + uint64_t current_vuid); + +int print_spool_write(files_struct *fsp, const char *data, uint32_t size, + off_t offset, uint32_t *written); + +void print_spool_end(files_struct *fsp, enum file_close_type close_type); + +void print_spool_terminate(struct connection_struct *conn, + struct print_file_data *print_file); +uint16_t print_spool_rap_jobid(struct print_file_data *print_file); + +/* The following definitions come from printing/printing.c */ + +uint32_t sysjob_to_jobid_pdb(struct tdb_print_db *pdb, int sysjob); +uint32_t sysjob_to_jobid(int unix_jobid); +int jobid_to_sysjob_pdb(struct tdb_print_db *pdb, uint32_t jobid); +bool print_notify_register_pid(int snum); +bool print_notify_deregister_pid(int snum); +bool print_job_exists(const char* sharename, uint32_t jobid); +struct spoolss_DeviceMode *print_job_devmode(TALLOC_CTX *mem_ctx, + const char *sharename, + uint32_t jobid); +bool print_job_set_name(struct tevent_context *ev, + struct messaging_context *msg_ctx, + const char *sharename, uint32_t jobid, const char *name); +bool print_job_get_name(TALLOC_CTX *mem_ctx, const char *sharename, uint32_t jobid, char **name); +WERROR print_job_delete(const struct auth_session_info *server_info, + struct messaging_context *msg_ctx, + int snum, uint32_t jobid); +WERROR print_job_pause(const struct auth_session_info *server_info, + struct messaging_context *msg_ctx, + int snum, uint32_t jobid); +WERROR print_job_resume(const struct auth_session_info *server_info, + struct messaging_context *msg_ctx, + int snum, uint32_t jobid); +ssize_t print_job_write(struct tevent_context *ev, + struct messaging_context *msg_ctx, + int snum, uint32_t jobid, const char *buf, size_t size); +int print_queue_length(struct messaging_context *msg_ctx, int snum, + print_status_struct *pstatus); +WERROR print_job_start(const struct auth_session_info *server_info, + struct messaging_context *msg_ctx, + const char *clientmachine, + int snum, const char *docname, const char *filename, + struct spoolss_DeviceMode *devmode, uint32_t *_jobid); +void print_job_endpage(struct messaging_context *msg_ctx, + int snum, uint32_t jobid); +NTSTATUS print_job_end(struct messaging_context *msg_ctx, int snum, + uint32_t jobid, enum file_close_type close_type); +int print_queue_status(struct messaging_context *msg_ctx, int snum, + print_queue_struct **ppqueue, + print_status_struct *status); +WERROR print_queue_pause(const struct auth_session_info *server_info, + struct messaging_context *msg_ctx, int snum); +WERROR print_queue_resume(const struct auth_session_info *server_info, + struct messaging_context *msg_ctx, int snum); +WERROR print_queue_purge(const struct auth_session_info *server_info, + struct messaging_context *msg_ctx, int snum); +bool print_backend_init(struct messaging_context *msg_ctx); +void printing_end(void); + +/* The following definitions come from printing/lpq_parse.c */ + +bool parse_lpq_entry(enum printing_types printing_type,char *line, + print_queue_struct *buf, + print_status_struct *status,bool first); + +/* The following definitions come from printing/printing_db.c */ + +struct tdb_print_db *get_print_db_byname(const char *printername); +void release_print_db( struct tdb_print_db *pdb); +void close_all_print_db(void); +TDB_DATA get_printer_notify_pid_list(struct tdb_context *tdb, const char *printer_name, bool cleanlist); + +void print_queue_receive(struct messaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id server_id, + DATA_BLOB *data); +#endif /* PRINTING_H_ */ diff --git a/source3/include/proto.h b/source3/include/proto.h new file mode 100644 index 0000000..032e7aa --- /dev/null +++ b/source3/include/proto.h @@ -0,0 +1,790 @@ +/* + * Unix SMB/CIFS implementation. + * collected prototypes header + * + * frozen from "make proto" in May 2008 + * + * Copyright (C) Michael Adam 2008 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef _PROTO_H_ +#define _PROTO_H_ + +#include <sys/types.h> +#include <regex.h> + +#include "lib/util/access.h" + +/* The following definitions come from lib/adt_tree.c */ + +/* The following definitions come from lib/audit.c */ + +const char *audit_category_str(uint32_t category); +const char *audit_param_str(uint32_t category); +const char *audit_description_str(uint32_t category); +bool get_audit_category_from_param(const char *param, uint32_t *audit_category); +const char *audit_policy_str(TALLOC_CTX *mem_ctx, uint32_t policy); + +/* The following definitions come from lib/charcnv.c */ + +void gfree_charcnv(void); +size_t push_ascii(void *dest, const char *src, size_t dest_len, int flags); +size_t push_ascii_fstring(void *dest, const char *src); +size_t push_ascii_nstring(void *dest, const char *src); +size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, int flags); +size_t pull_ascii_fstring(char *dest, const void *src); +size_t pull_ascii_nstring(char *dest, size_t dest_len, const void *src); +size_t push_string_check_fn(void *dest, const char *src, + size_t dest_len, int flags); +size_t push_string_base(const char *base, uint16_t flags2, + void *dest, const char *src, + size_t dest_len, int flags); +size_t pull_string_talloc(TALLOC_CTX *ctx, + const void *base_ptr, + uint16_t smb_flags2, + char **ppdest, + const void *src, + size_t src_len, + int flags); +size_t dos_PutUniCode(char *dst,const char *src, size_t len, bool null_terminate); +int rpcstr_push_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src); + +/* The following definitions come from lib/dmallocmsg.c */ + +void register_dmalloc_msgs(struct messaging_context *msg_ctx); + +/* The following definitions come from lib/dprintf.c */ + +void display_set_stderr(void); + +/* The following definitions come from lib/errmap_unix.c */ + +NTSTATUS map_nt_error_from_unix(int unix_error); + +/* The following definitions come from lib/file_id.c */ + +struct file_id vfs_file_id_from_sbuf(connection_struct *conn, const SMB_STRUCT_STAT *sbuf); + +NTSTATUS vfs_at_fspcwd(TALLOC_CTX *mem_ctx, + struct connection_struct *conn, + struct files_struct **_fsp); + +NTSTATUS vfs_fget_dos_attributes(struct files_struct *fsp, + uint32_t *dosmode); + +#include "source3/lib/interface.h" + +/* The following definitions come from lib/ldap_debug_handler.c */ + +void init_ldap_debugging(void); + +/* The following definitions come from lib/ldap_escape.c */ + +char *escape_ldap_string(TALLOC_CTX *mem_ctx, const char *s); +char *escape_rdn_val_string_alloc(const char *s); + +/* The following definitions come from lib/ms_fnmatch.c */ + +int ms_fnmatch(const char *pattern, const char *string, bool translate_pattern, + bool is_case_sensitive); + +/* The following definitions come from lib/recvfile.c */ + +ssize_t sys_recvfile(int fromfd, + int tofd, + off_t offset, + size_t count); +ssize_t sys_recvfile(int fromfd, + int tofd, + off_t offset, + size_t count); +ssize_t drain_socket(int sockfd, size_t count); + +/* The following definitions come from lib/sendfile.c */ + +ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, off_t offset, size_t count); + +/* The following definitions come from lib/server_mutex.c */ + +struct named_mutex *grab_named_mutex(TALLOC_CTX *mem_ctx, const char *name, + int timeout); + +/* The following definitions come from lib/sharesec.c */ + +NTSTATUS share_info_db_init(void); +struct security_descriptor *get_share_security( TALLOC_CTX *ctx, const char *servicename, + size_t *psize); +NTSTATUS set_share_security(const char *share_name, + struct security_descriptor *psd); +NTSTATUS delete_share_security(const char *servicename); +bool share_access_check(const struct security_token *token, + const char *sharename, + uint32_t desired_access, + uint32_t *pgranted); +bool parse_usershare_acl(TALLOC_CTX *ctx, const char *acl_str, struct security_descriptor **ppsd); + +/* The following definitions come from lib/smbrun.c */ + +int smbrun_no_sanitize(const char *cmd, int *outfd, char * const *env); +int smbrun(const char *cmd, int *outfd, char * const *env); +int smbrunsecret(const char *cmd, const char *secret); + +/* The following definitions come from lib/sysquotas.c */ + +int sys_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp); +int sys_set_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp); + +/* The following definitions come from lib/sysquotas_*.c */ + +int sys_get_vfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp); +int sys_set_vfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp); + +int sys_get_xfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp); +int sys_set_xfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp); + +int sys_get_jfs2_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp); +int sys_set_jfs2_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp); + +int sys_get_nfs_quota(const char *path, const char *bdev, + enum SMB_QUOTA_TYPE qtype, + unid_t id, SMB_DISK_QUOTA *dp); +int sys_set_nfs_quota(const char *path, const char *bdev, + enum SMB_QUOTA_TYPE qtype, + unid_t id, SMB_DISK_QUOTA *dp); + +/* The following definitions come from lib/system.c */ + +ssize_t sys_send(int s, const void *msg, size_t len, int flags); +ssize_t sys_recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen); +int sys_fcntl_ptr(int fd, int cmd, void *arg); +int sys_fcntl_long(int fd, int cmd, long arg); +int sys_fcntl_int(int fd, int cmd, int arg); +void update_stat_ex_mtime(struct stat_ex *dst, struct timespec write_ts); +void update_stat_ex_create_time(struct stat_ex *dst, struct timespec create_time); +void update_stat_ex_from_saved_stat(struct stat_ex *dst, + const struct stat_ex *src); +int sys_stat(const char *fname, SMB_STRUCT_STAT *sbuf, + bool fake_dir_create_times); +int sys_fstat(int fd, SMB_STRUCT_STAT *sbuf, + bool fake_dir_create_times); +int sys_lstat(const char *fname,SMB_STRUCT_STAT *sbuf, + bool fake_dir_create_times); +int sys_fstatat(int fd, + const char *pathname, + SMB_STRUCT_STAT *sbuf, + int flags, + bool fake_dir_create_times); +int sys_posix_fallocate(int fd, off_t offset, off_t len); +int sys_fallocate(int fd, uint32_t mode, off_t offset, off_t len); +DIR *sys_fdopendir(int fd); +int sys_mknod(const char *path, mode_t mode, SMB_DEV_T dev); +int sys_mknodat(int dirfd, const char *path, mode_t mode, SMB_DEV_T dev); +char *sys_getwd(void); +void set_effective_capability(enum smbd_capability capability); +void drop_effective_capability(enum smbd_capability capability); +long sys_random(void); +void sys_srandom(unsigned int seed); +int getgroups_max(void); +int setgroups_max(void); +int sys_getgroups(int setlen, gid_t *gidset); +int sys_setgroups(gid_t UNUSED(primary_gid), int setlen, gid_t *gidset); +uint32_t unix_dev_major(SMB_DEV_T dev); +uint32_t unix_dev_minor(SMB_DEV_T dev); +char *sys_realpath(const char *path); +#if 0 +int sys_get_number_of_cores(void); +#endif + +bool sys_have_proc_fds(void); +const char *sys_proc_fd_path(int fd, char *buf, size_t bufsize); + +struct stat; +void init_stat_ex_from_stat (struct stat_ex *dst, + const struct stat *src, + bool fake_dir_create_times); + +/* The following definitions come from lib/system_smbd.c */ + +bool getgroups_unix_user(TALLOC_CTX *mem_ctx, const char *user, + gid_t primary_gid, + gid_t **ret_groups, uint32_t *p_ngroups); + +/* The following definitions come from lib/tallocmsg.c */ + +void register_msg_pool_usage(TALLOC_CTX *mem_ctx, + struct messaging_context *msg_ctx); + +/* The following definitions come from lib/time.c */ + +void push_dos_date(uint8_t *buf, int offset, time_t unixdate, int zone_offset); +void push_dos_date2(uint8_t *buf,int offset,time_t unixdate, int zone_offset); +void push_dos_date3(uint8_t *buf,int offset,time_t unixdate, int zone_offset); +uint32_t convert_time_t_to_uint32_t(time_t t); +time_t convert_uint32_t_to_time_t(uint32_t u); +bool nt_time_is_zero(const NTTIME *nt); +time_t generalized_to_unix_time(const char *str); +int get_server_zone_offset(void); +int set_server_zone_offset(time_t t); +char *timeval_string(TALLOC_CTX *ctx, const struct timeval *tp, bool hires); +char *current_timestring(TALLOC_CTX *ctx, bool hires); +void srv_put_dos_date(char *buf,int offset,time_t unixdate); +void srv_put_dos_date2(char *buf,int offset, time_t unixdate); +void srv_put_dos_date3(char *buf,int offset,time_t unixdate); +void round_timespec(enum timestamp_set_resolution res, struct timespec *ts); +void put_long_date_timespec(enum timestamp_set_resolution res, char *p, struct timespec ts); +void put_long_date_full_timespec(enum timestamp_set_resolution res, + char *p, + const struct timespec *ts); +struct timespec pull_long_date_full_timespec(const char *p); +void put_long_date(char *p, time_t t); +void dos_filetime_timespec(struct timespec *tsp); +time_t make_unix_date(const void *date_ptr, int zone_offset); +time_t make_unix_date2(const void *date_ptr, int zone_offset); +time_t make_unix_date3(const void *date_ptr, int zone_offset); +time_t srv_make_unix_date(const void *date_ptr); +time_t srv_make_unix_date2(const void *date_ptr); +time_t srv_make_unix_date3(const void *date_ptr); +struct timespec interpret_long_date(const char *p); +void TimeInit(void); +void get_process_uptime(struct timeval *ret_time); +void get_startup_time(struct timeval *ret_time); +time_t nt_time_to_unix_abs(const NTTIME *nt); +void unix_to_nt_time_abs(NTTIME *nt, time_t t); +const char *time_to_asc(const time_t t); +const char *display_time(NTTIME nttime); +bool nt_time_is_set(const NTTIME *nt); + +/* The following definitions come from lib/username.c */ + +void flush_pwnam_cache(void); +char *get_user_home_dir(TALLOC_CTX *mem_ctx, const char *user); +struct passwd *Get_Pwnam_alloc(TALLOC_CTX *mem_ctx, const char *user); + +/* The following definitions come from lib/util_names.c */ +const char *get_global_sam_name(void); +const char *my_sam_name(void); +bool is_allowed_domain(const char *domain_name); + +/* The following definitions come from lib/util.c */ + +enum protocol_types get_Protocol(void); +void set_Protocol(enum protocol_types p); +void gfree_all( void ); +bool file_exist_stat(const char *fname,SMB_STRUCT_STAT *sbuf, + bool fake_dir_create_times); +bool socket_exist(const char *fname); +uint64_t get_file_size_stat(const SMB_STRUCT_STAT *sbuf); +bool check_same_dev_ino(const SMB_STRUCT_STAT *sbuf1, + const SMB_STRUCT_STAT *sbuf2); +bool check_same_stat(const SMB_STRUCT_STAT *sbuf1, + const SMB_STRUCT_STAT *sbuf2); +void show_msg(const char *buf); +int set_message_bcc(char *buf,int num_bytes); +ssize_t message_push_blob(uint8_t **outbuf, DATA_BLOB blob); +char *unix_clean_name(TALLOC_CTX *ctx, const char *s); +char *clean_name(TALLOC_CTX *ctx, const char *s); +ssize_t write_data_at_offset(int fd, const char *buffer, size_t N, off_t pos); +NTSTATUS init_before_fork(void); +int parent_watch_fd(void); +NTSTATUS reinit_after_fork(struct messaging_context *msg_ctx, + struct tevent_context *ev_ctx, + bool parent_longlived, + const char *comment); +NTSTATUS smbd_reinit_after_fork(struct messaging_context *msg_ctx, + struct tevent_context *ev_ctx, + bool parent_longlived, + const char *comment); +void *malloc_(size_t size); +void *Realloc(void *p, size_t size, bool free_old_on_error); +void add_to_large_array(TALLOC_CTX *mem_ctx, size_t element_size, + void *element, void *_array, uint32_t *num_elements, + ssize_t *array_size); +char *get_myname(TALLOC_CTX *ctx); +char *get_mydnsdomname(TALLOC_CTX *ctx); +char *automount_lookup(TALLOC_CTX *ctx, const char *user_name); +char *automount_lookup(TALLOC_CTX *ctx, const char *user_name); +bool process_exists(const struct server_id pid); +const char *uidtoname(uid_t uid); +char *gidtoname(gid_t gid); +uid_t nametouid(const char *name); +gid_t nametogid(const char *name); +void smb_panic_s3(const char *why); +const char *readdirname(DIR *p); +bool is_in_path(const char *name, name_compare_entry *namelist, bool case_sensitive); +void set_namearray(name_compare_entry **ppname_array, const char *namelist); +void free_namearray(name_compare_entry *name_array); +bool fcntl_lock(int fd, int op, off_t offset, off_t count, int type); +bool fcntl_getlock(int fd, int op, off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid); +int map_process_lock_to_ofd_lock(int op); +bool is_myname(const char *s); +void ra_lanman_string( const char *native_lanman ); +const char *get_remote_arch_str(void); +enum remote_arch_types get_remote_arch_from_str(const char *remote_arch_string); +void set_remote_arch(enum remote_arch_types type); +enum remote_arch_types get_remote_arch(void); +bool remote_arch_cache_update(const struct GUID *client_guid); +bool remote_arch_cache_delete(const struct GUID *client_guid); +const char *tab_depth(int level, int depth); +int str_checksum(const char *s); +void zero_free(void *p, size_t size); +int set_maxfiles(int requested_max); +int smb_mkstemp(char *name_template); +void *smb_xmalloc_array(size_t size, unsigned int count); +char *myhostname(void); +char *myhostname_upper(void); +#include "lib/util_path.h" +bool parent_dirname(TALLOC_CTX *mem_ctx, const char *dir, char **parent, + const char **name); +bool ms_has_wild(const char *s); +bool ms_has_wild_w(const smb_ucs2_t *s); +bool mask_match(const char *string, const char *pattern, bool is_case_sensitive); +bool mask_match_search(const char *string, const char *pattern, bool is_case_sensitive); +bool mask_match_list(const char *string, char **list, int listLen, bool is_case_sensitive); +#include "lib/util/unix_match.h" +bool name_to_fqdn(fstring fqdn, const char *name); +uint32_t map_share_mode_to_deny_mode(uint32_t share_access, uint32_t private_options); + +#include "lib/util_procid.h" + +struct server_id interpret_pid(const char *pid_string); +bool is_offset_safe(const char *buf_base, size_t buf_len, char *ptr, size_t off); +char *get_safe_ptr(const char *buf_base, size_t buf_len, char *ptr, size_t off); +char *get_safe_str_ptr(const char *buf_base, size_t buf_len, char *ptr, size_t off); +int get_safe_SVAL(const char *buf_base, size_t buf_len, char *ptr, size_t off, int failval); +int get_safe_IVAL(const char *buf_base, size_t buf_len, char *ptr, size_t off, int failval); +bool split_domain_user(TALLOC_CTX *mem_ctx, + const char *full_name, + char **domain, + char **user); +const char *strip_hostname(const char *s); +bool any_nt_status_not_ok(NTSTATUS err1, NTSTATUS err2, NTSTATUS *result); +int timeval_to_msec(struct timeval t); +char *valid_share_pathname(TALLOC_CTX *ctx, const char *dos_pathname); +bool is_executable(const char *fname); +bool map_open_params_to_ntcreate(const char *smb_base_fname, + int deny_mode, int open_func, + uint32_t *paccess_mask, + uint32_t *pshare_mode, + uint32_t *pcreate_disposition, + uint32_t *pcreate_options, + uint32_t *pprivate_flags); +struct security_unix_token *copy_unix_token(TALLOC_CTX *ctx, const struct security_unix_token *tok); +struct security_unix_token *root_unix_token(TALLOC_CTX *mem_ctx); +char *utok_string(TALLOC_CTX *mem_ctx, const struct security_unix_token *tok); +bool dir_check_ftype(uint32_t mode, uint32_t dirtype); + +/* The following definitions come from lib/util_builtin.c */ + +bool lookup_builtin_rid(TALLOC_CTX *mem_ctx, uint32_t rid, const char **name); +bool lookup_builtin_name(const char *name, uint32_t *rid); +const char *builtin_domain_name(void); +bool sid_check_is_builtin(const struct dom_sid *sid); +bool sid_check_is_in_builtin(const struct dom_sid *sid); +bool sid_check_is_wellknown_builtin(const struct dom_sid *sid); + +/* The following definitions come from lib/util_nscd.c */ + +void smb_nscd_flush_user_cache(void); +void smb_nscd_flush_group_cache(void); + +/* The following definitions come from lib/util_nttoken.c */ + +struct security_token *dup_nt_token(TALLOC_CTX *mem_ctx, const struct security_token *ptoken); +NTSTATUS merge_nt_token(TALLOC_CTX *mem_ctx, + const struct security_token *token_1, + const struct security_token *token_2, + struct security_token **token_out); +bool token_sid_in_ace(const struct security_token *token, const struct security_ace *ace); + +/* The following definitions come from lib/util_sec.c */ + +void sec_init(void); +uid_t sec_initial_uid(void); +gid_t sec_initial_gid(void); +bool root_mode(void); +bool non_root_mode(void); +void gain_root_privilege(void); +void gain_root_group_privilege(void); +void set_effective_uid(uid_t uid); +void set_effective_gid(gid_t gid); +void save_re_uid(void); +void restore_re_uid_fromroot(void); +void restore_re_uid(void); +void save_re_gid(void); +void restore_re_gid(void); +int set_re_uid(void); +void become_user_permanently(uid_t uid, gid_t gid); +int set_thread_credentials(uid_t uid, + gid_t gid, + size_t setlen, + const gid_t *gidset); +bool is_setuid_root(void) ; + +/* The following definitions come from lib/util_sid.c */ + +char *sid_to_fstring(fstring sidstr_out, const struct dom_sid *sid); +bool sid_linearize(uint8_t *outbuf, size_t len, const struct dom_sid *sid); +bool non_mappable_sid(struct dom_sid *sid); +char *sid_binstring_hex_talloc(TALLOC_CTX *mem_ctx, const struct dom_sid *sid); +struct netr_SamInfo3; +NTSTATUS sid_array_from_info3(TALLOC_CTX *mem_ctx, + const struct netr_SamInfo3 *info3, + struct dom_sid **user_sids, + uint32_t *num_user_sids, + bool include_user_group_rid); +bool security_token_find_npa_flags(const struct security_token *token, + uint32_t *_flags); +void security_token_del_npa_flags(struct security_token *token); + +/* The following definitions come from lib/util_sock.c */ + +bool is_broadcast_addr(const struct sockaddr *pss); +bool is_loopback_ip_v4(struct in_addr ip); +bool is_loopback_addr(const struct sockaddr *pss); +bool is_zero_addr(const struct sockaddr_storage *pss); +void zero_ip_v4(struct in_addr *ip); +void in_addr_to_sockaddr_storage(struct sockaddr_storage *ss, + struct in_addr ip); +bool same_net(const struct sockaddr *ip1, + const struct sockaddr *ip2, + const struct sockaddr *mask); +bool sockaddr_equal(const struct sockaddr *ip1, + const struct sockaddr *ip2); +bool is_address_any(const struct sockaddr *psa); +uint16_t get_sockaddr_port(const struct sockaddr_storage *pss); +char *print_sockaddr(char *dest, + size_t destlen, + const struct sockaddr_storage *psa); +char *print_canonical_sockaddr(TALLOC_CTX *ctx, + const struct sockaddr_storage *pss); +bool is_a_socket(int fd); +void set_socket_options(int fd, const char *options); +NTSTATUS read_fd_with_timeout(int fd, char *buf, + size_t mincnt, size_t maxcnt, + unsigned int time_out, + size_t *size_ret); +NTSTATUS read_data_ntstatus(int fd, char *buffer, size_t N); + +NTSTATUS read_smb_length_return_keepalive(int fd, char *inbuf, + unsigned int timeout, + size_t *len); +NTSTATUS receive_smb_raw(int fd, + char *buffer, + size_t buflen, + unsigned int timeout, + size_t maxlen, + size_t *p_len); +int open_socket_in( + int type, + const struct sockaddr_storage *paddr, + uint16_t port, + bool rebind); +NTSTATUS open_socket_out(const struct sockaddr_storage *pss, uint16_t port, + int timeout, int *pfd); +struct tevent_req *open_socket_out_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + const struct sockaddr_storage *pss, + uint16_t port, + int timeout); +NTSTATUS open_socket_out_recv(struct tevent_req *req, int *pfd); +struct tevent_req *open_socket_out_defer_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct timeval wait_time, + const struct sockaddr_storage *pss, + uint16_t port, + int timeout); +NTSTATUS open_socket_out_defer_recv(struct tevent_req *req, int *pfd); +const char *get_peer_addr(int fd, char *addr, size_t addr_len); + +struct tsocket_address; + +int get_remote_hostname(const struct tsocket_address *remote_address, + char **name, + TALLOC_CTX *mem_ctx); + +int create_pipe_sock(const char *socket_dir, + const char *socket_name, + mode_t dir_perms); +const char *get_mydnsfullname(void); +bool is_myname_or_ipaddr(const char *s); +int poll_one_fd(int fd, int events, int timeout, int *revents); +int poll_intr_one_fd(int fd, int events, int timeout, int *revents); + +/* The following definitions come from lib/util_str.c */ + +bool next_token(const char **ptr, char *buff, const char *sep, size_t bufsize); +bool strnequal(const char *s1,const char *s2,size_t n); +bool strcsequal(const char *s1,const char *s2); +char *skip_string(const char *base, size_t len, char *buf); +size_t str_charnum(const char *s); +bool trim_char(char *s,char cfront,char cback); +bool strhasupper(const char *s); +bool strhaslower(const char *s); +bool in_list(const char *s, const char *list, bool casesensitive); +void fstring_sub(char *s,const char *pattern,const char *insert); +char *realloc_string_sub2(char *string, + const char *pattern, + const char *insert, + bool remove_unsafe_characters, + bool allow_trailing_dollar); +char *realloc_string_sub(char *string, + const char *pattern, + const char *insert); +void all_string_sub(char *s,const char *pattern,const char *insert, size_t len); +char *octal_string(int i); +char *string_truncate(char *s, unsigned int length); +char *strchr_m(const char *src, char c); +char *strrchr_m(const char *s, char c); +char *strnrchr_m(const char *s, char c, unsigned int n); +char *strstr_m(const char *src, const char *findstr); +bool strlower_m(char *s); +bool strupper_m(char *s); +size_t strlen_m(const char *s); +size_t strlen_m_term(const char *s); +size_t strlen_m_term_null(const char *s); +int fstr_sprintf(fstring s, const char *fmt, ...); + +uint64_t STR_TO_SMB_BIG_UINT(const char *nptr, const char **entptr); +uint64_t conv_str_size(const char * str); +char *talloc_asprintf_strupper_m(TALLOC_CTX *t, const char *fmt, ...) + PRINTF_ATTRIBUTE(2,3); +char *talloc_asprintf_strlower_m(TALLOC_CTX *t, const char *fmt, ...) + PRINTF_ATTRIBUTE(2,3); +bool validate_net_name( const char *name, + const char *invalid_chars, + int max_len); +char *escape_shell_string(const char *src); +ssize_t full_path_tos(const char *dir, const char *name, + char *tmpbuf, size_t tmpbuf_len, + char **pdst, char **to_free); + +/* The following definitions come from lib/version.c */ + +const char *samba_version_string(void); + +/* The following definitions come from lib/wins_srv.c */ + +bool wins_srv_is_dead(struct in_addr wins_ip, struct in_addr src_ip); +void wins_srv_alive(struct in_addr wins_ip, struct in_addr src_ip); +void wins_srv_died(struct in_addr wins_ip, struct in_addr src_ip); +unsigned wins_srv_count(void); +char **wins_srv_tags(void); +void wins_srv_tags_free(char **list); +struct in_addr wins_srv_ip_tag(const char *tag, struct in_addr src_ip); +bool wins_server_tag_ips(const char *tag, TALLOC_CTX *mem_ctx, + struct in_addr **pservers, size_t *pnum_servers); +unsigned wins_srv_count_tag(const char *tag); + +#ifndef ASN1_MAX_OIDS +#define ASN1_MAX_OIDS 20 +#endif +bool spnego_parse_negTokenInit(TALLOC_CTX *ctx, + DATA_BLOB blob, + char *OIDs[ASN1_MAX_OIDS], + char **principal, + DATA_BLOB *secblob); +DATA_BLOB spnego_gen_krb5_wrap(TALLOC_CTX *ctx, const DATA_BLOB ticket, const uint8_t tok_id[2]); + +/* The following definitions come from libsmb/conncache.c */ + +NTSTATUS check_negative_conn_cache( const char *domain, const char *server); +void add_failed_connection_entry(const char *domain, const char *server, NTSTATUS result) ; +void flush_negative_conn_cache_for_domain(const char *domain); + +/* The following definitions come from libsmb/errormap.c */ + +NTSTATUS dos_to_ntstatus(uint8_t eclass, uint32_t ecode); + +/* The following definitions come from libsmb/namecache.c */ + +bool namecache_store(const char *name, + int name_type, + size_t num_names, + struct samba_sockaddr *sa_list); +bool namecache_fetch(TALLOC_CTX *ctx, + const char *name, + int name_type, + struct samba_sockaddr **sa_list, + size_t *num_names); +bool namecache_delete(const char *name, int name_type); +void namecache_flush(void); +bool namecache_status_store(const char *keyname, int keyname_type, + int name_type, const struct sockaddr_storage *keyip, + const char *srvname); +bool namecache_status_fetch(const char *keyname, + int keyname_type, + int name_type, + const struct sockaddr_storage *keyip, + char *srvname_out); + +/* The following definitions come from libsmb/namequery_dc.c */ + +bool get_dc_name(const char *domain, + const char *realm, + fstring srv_name, + struct sockaddr_storage *ss_out); + +/* The following definitions come from libsmb/smberr.c */ + +const char *smb_dos_err_name(uint8_t e_class, uint16_t num); +const char *get_dos_error_msg(WERROR result); +const char *smb_dos_err_class(uint8_t e_class); +WERROR map_werror_from_unix(int error); + +/* The following definitions come from libsmb/trusts_util.c */ + +struct netlogon_creds_cli_context; +struct messaging_context; +struct dcerpc_binding_handle; +char *trust_pw_new_value(TALLOC_CTX *mem_ctx, + enum netr_SchannelType sec_channel_type, + int security); +NTSTATUS trust_pw_change(struct netlogon_creds_cli_context *context, + struct messaging_context *msg_ctx, + struct dcerpc_binding_handle *b, + const char *domain, + const char *dcname, + bool force); + +/* The following definitions come from lib/sessionid_tdb.c */ +struct sessionid; +NTSTATUS sessionid_traverse_read(int (*fn)(const char *key, + struct sessionid *session, + void *private_data), + void *private_data); + +/* The following definitions come from lib/avahi.c */ + +struct AvahiPoll *tevent_avahi_poll(TALLOC_CTX *mem_ctx, + struct tevent_context *ev); + +/* The following definitions come from libsmb/smbsock_connect.c */ + +struct tevent_req *smbsock_connect_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + const struct sockaddr_storage *addr, + uint16_t port, + const char *called_name, + int called_type, + const char *calling_name, + int calling_type); +NTSTATUS smbsock_connect_recv(struct tevent_req *req, int *sock, + uint16_t *ret_port); +NTSTATUS smbsock_connect(const struct sockaddr_storage *addr, uint16_t port, + const char *called_name, int called_type, + const char *calling_name, int calling_type, + int *pfd, uint16_t *ret_port, int sec_timeout); + +struct tevent_req *smbsock_any_connect_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + const struct sockaddr_storage *addrs, + const char **called_names, + int *called_types, + const char **calling_names, + int *calling_types, + size_t num_addrs, uint16_t port); +NTSTATUS smbsock_any_connect_recv(struct tevent_req *req, int *pfd, + size_t *chosen_index, uint16_t *chosen_port); +NTSTATUS smbsock_any_connect(const struct sockaddr_storage *addrs, + const char **called_names, + int *called_types, + const char **calling_names, + int *calling_types, + size_t num_addrs, + uint16_t port, + int sec_timeout, + int *pfd, size_t *chosen_index, + uint16_t *chosen_port); + +/* The following definitions come from lib/util_wellknown.c */ + +bool sid_check_is_wellknown_domain(const struct dom_sid *sid, const char **name); +bool sid_check_is_in_wellknown_domain(const struct dom_sid *sid); +bool lookup_wellknown_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid, + const char **domain, const char **name); +bool lookup_wellknown_name(TALLOC_CTX *mem_ctx, const char *name, + struct dom_sid *sid, const char **domain); + +/* The following definitions come from lib/filename_util.c */ + +NTSTATUS get_full_smb_filename(TALLOC_CTX *ctx, const struct smb_filename *smb_fname, + char **full_name); +struct smb_filename *synthetic_smb_fname(TALLOC_CTX *mem_ctx, + const char *base_name, + const char *stream_name, + const SMB_STRUCT_STAT *psbuf, + NTTIME twrp, + uint32_t flags); +NTSTATUS filename_convert_dirfsp( + TALLOC_CTX *ctx, + connection_struct *conn, + const char *name_in, + uint32_t ucf_flags, + NTTIME twrp, + struct files_struct **pdirfsp, + struct smb_filename **psmb_name_rel); +struct smb_filename *full_path_from_dirfsp_atname( + TALLOC_CTX *mem_ctx, + const struct files_struct *dirfsp, + const struct smb_filename *atname); +struct smb_filename *synthetic_smb_fname_split(TALLOC_CTX *ctx, + const char *fname, + bool posix_path); +const char *smb_fname_str_dbg(const struct smb_filename *smb_fname); +const char *fsp_str_dbg(const struct files_struct *fsp); +const char *fsp_fnum_dbg(const struct files_struct *fsp); +struct smb_filename *cp_smb_filename(TALLOC_CTX *mem_ctx, + const struct smb_filename *in); +struct smb_filename *cp_smb_filename_nostream(TALLOC_CTX *mem_ctx, + const struct smb_filename *in); +bool is_ntfs_stream_smb_fname(const struct smb_filename *smb_fname); +bool is_ntfs_default_stream_smb_fname(const struct smb_filename *smb_fname); +bool is_named_stream(const struct smb_filename *smb_fname); +bool is_invalid_windows_ea_name(const char *name); +bool ea_list_has_invalid_name(struct ea_list *ea_list); +bool split_stream_filename(TALLOC_CTX *ctx, + const char *filename_in, + char **filename_out, + char **streamname_out); + +/* The following definitions come from lib/dummyroot.c */ + +void become_root(void); +void unbecome_root(void); + +/* The following definitions come from lib/smbd_shim.c */ + +int find_service(TALLOC_CTX *ctx, const char *service_in, char **p_service_out); +void send_stat_cache_delete_message(struct messaging_context *msg_ctx, + const char *name); +NTSTATUS can_delete_directory_fsp(files_struct *fsp); +bool change_to_root_user(void); +bool become_authenticated_pipe_user(struct auth_session_info *session_info); +bool unbecome_authenticated_pipe_user(void); + +void contend_level2_oplocks_begin(files_struct *fsp, + enum level2_contention_type type); +void contend_level2_oplocks_end(files_struct *fsp, + enum level2_contention_type type); + +/* The following definitions come from lib/per_thread_cwd.c */ + +void per_thread_cwd_check(void); +bool per_thread_cwd_supported(void); +void per_thread_cwd_disable(void); +void per_thread_cwd_activate(void); + +#endif /* _PROTO_H_ */ diff --git a/source3/include/registry.h b/source3/include/registry.h new file mode 100644 index 0000000..7d2aad9 --- /dev/null +++ b/source3/include/registry.h @@ -0,0 +1,133 @@ +/* + * Unix SMB/CIFS implementation. + * Virtual Windows Registry Layer + * + * Copyright (C) Gerald Carter 2002-2005 + * Copyright (C) Volker Lendecke 2006 + * Copyright (C) Michael Adam 2006-2010 + * + * 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/>. + */ + +#ifndef _REGISTRY_H +#define _REGISTRY_H + +#include "../librpc/gen_ndr/winreg.h" + +struct registry_value { + enum winreg_Type type; + DATA_BLOB data; +}; + +/* forward declarations. definitions in reg_objects.c */ +struct regval_ctr; +struct regsubkey_ctr; + +/* + * container for function pointers to enumeration routines + * for virtual registry view + */ + +struct registry_ops { + /* functions for enumerating subkeys and values */ + int (*fetch_subkeys)( const char *key, struct regsubkey_ctr *subkeys); + int (*fetch_values) ( const char *key, struct regval_ctr *val ); + bool (*store_subkeys)( const char *key, struct regsubkey_ctr *subkeys ); + WERROR (*create_subkey)(const char *key, const char *subkey); + WERROR (*delete_subkey)(const char *key, const char *subkey, bool lazy); + bool (*store_values)( const char *key, struct regval_ctr *val ); + bool (*reg_access_check)( const char *keyname, uint32_t requested, + uint32_t *granted, + const struct security_token *token ); + WERROR (*get_secdesc)(TALLOC_CTX *mem_ctx, const char *key, + struct security_descriptor **psecdesc); + WERROR (*set_secdesc)(const char *key, + struct security_descriptor *sec_desc); + bool (*subkeys_need_update)(struct regsubkey_ctr *subkeys); + bool (*values_need_update)(struct regval_ctr *values); +}; + +/* structure to store the registry handles */ + +struct registry_key_handle { + uint32_t type; + char *name; /* full name of registry key */ + uint32_t access_granted; + struct registry_ops *ops; +}; + +struct registry_key { + struct registry_key_handle *key; + struct regsubkey_ctr *subkeys; + struct regval_ctr *values; + struct security_token *token; +}; + + +/* + * + * Macros that used to reside in rpc_reg.h + * + */ + +#define HKEY_CLASSES_ROOT 0x80000000 +#define HKEY_CURRENT_USER 0x80000001 +#define HKEY_LOCAL_MACHINE 0x80000002 +#define HKEY_USERS 0x80000003 +#define HKEY_PERFORMANCE_DATA 0x80000004 + +#define KEY_HKLM "HKLM" +#define KEY_HKU "HKU" +#define KEY_HKCC "HKCC" +#define KEY_HKCR "HKCR" +#define KEY_HKPD "HKPD" +#define KEY_HKPT "HKPT" +#define KEY_HKPN "HKPN" +#define KEY_HKCU "HKCU" +#define KEY_HKDD "HKDD" +#define KEY_SERVICES "HKLM\\SYSTEM\\CurrentControlSet\\Services" +#define KEY_EVENTLOG "HKLM\\SYSTEM\\CurrentControlSet\\Services\\Eventlog" +#define KEY_SHARES "HKLM\\SYSTEM\\CurrentControlSet\\Services\\LanmanServer\\Shares" +#define KEY_NETLOGON_PARAMS "HKLM\\SYSTEM\\CurrentControlSet\\Services\\Netlogon\\Parameters" +#define KEY_TCPIP_PARAMS "HKLM\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters" +#define KEY_PROD_OPTIONS "HKLM\\SYSTEM\\CurrentControlSet\\Control\\ProductOptions" +#define KEY_PRINTING "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Print" +#define KEY_PCC "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print\\PackageInstallation" +#define KEY_PRINTING_2K "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Printers" +#define KEY_PRINTING_PORTS "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Ports" +#define KEY_CURRENT_VERSION "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion" +#define KEY_PERFLIB "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Perflib" +#define KEY_PERFLIB_009 "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Perflib\\009" +#define KEY_GROUP_POLICY "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Group Policy" +#define KEY_WINLOGON "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon" +#define KEY_SMBCONF "HKLM\\SOFTWARE\\Samba\\smbconf" +#define KEY_SAMBA_GROUP_POLICY "HKLM\\SOFTWARE\\Samba\\Group Policy" +#define KEY_TREE_ROOT "" + +#define KEY_GP_MACHINE_POLICY "HKLM\\Software\\Policies" +#define KEY_GP_MACHINE_WIN_POLICY "HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies" +#define KEY_GP_USER_POLICY "HKCU\\Software\\Policies" +#define KEY_GP_USER_WIN_POLICY "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies" + +/* + * Registry key types + * Most keys are going to be GENERIC -- may need a better name? + * HKPD and HKPT are used by reg_perfcount.c + * they are special keys that contain performance data + */ +#define REG_KEY_GENERIC 0 +#define REG_KEY_HKPD 1 +#define REG_KEY_HKPT 2 + +#endif /* _REGISTRY_H */ diff --git a/source3/include/rpc_dce.h b/source3/include/rpc_dce.h new file mode 100644 index 0000000..2cc770e --- /dev/null +++ b/source3/include/rpc_dce.h @@ -0,0 +1,37 @@ +/* + Unix SMB/CIFS implementation. + SMB parameters and setup + Copyright (C) Andrew Tridgell 1992-1997 + Copyright (C) Luke Kenneth Casson Leighton 1996-1997 + Copyright (C) Paul Ashton 1997 + + 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/>. +*/ + +#ifndef _DCE_RPC_H /* _DCE_RPC_H */ +#define _DCE_RPC_H + +/* Maximum size of the signing data in a fragment. */ +#define RPC_MAX_SIGN_SIZE 0x38 /* 56 */ + +/* Maximum PDU fragment size. */ +/* #define MAX_PDU_FRAG_LEN 0x1630 this is what wnt sets */ +#define RPC_MAX_PDU_FRAG_LEN 0x10b8 /* this is what w2k sets */ + +#define RPC_HEADER_LEN 16 + +#define RPC_BIG_ENDIAN 1 +#define RPC_LITTLE_ENDIAN 0 + +#endif /* _DCE_RPC_H */ diff --git a/source3/include/rpc_misc.h b/source3/include/rpc_misc.h new file mode 100644 index 0000000..06d4b49 --- /dev/null +++ b/source3/include/rpc_misc.h @@ -0,0 +1,35 @@ +/* + Unix SMB/CIFS implementation. + + Copyright (C) Andrew Tridgell 1992-1997 + Copyright (C) Luke Kenneth Casson Leighton 1996-1997 + Copyright (C) Paul Ashton 1997 + Copyright (C) Gerald (Jerry) Carter 2005 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _RPC_MISC_H /* _RPC_MISC_H */ +#define _RPC_MISC_H + +/********************************************************************** + * RPC policy handle used pretty much everywhere + **********************************************************************/ + +#define OUR_HANDLE(hnd) (((hnd)==NULL) ? "NULL" :\ + ( IVAL((hnd)->uuid.node,2) == (uint32_t)getpid() ? "OURS" : \ + "OTHER")), ((unsigned int)IVAL((hnd)->uuid.node,2)),\ + ((unsigned int)getpid() ) + +#endif /* _RPC_MISC_H */ diff --git a/source3/include/secrets.h b/source3/include/secrets.h new file mode 100644 index 0000000..1abfbb0 --- /dev/null +++ b/source3/include/secrets.h @@ -0,0 +1,188 @@ +/* + * Unix SMB/CIFS implementation. + * secrets.tdb file format info + * Copyright (C) Andrew Tridgell 2000 + * + * 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/>. + */ + +#ifndef _SECRETS_H +#define _SECRETS_H + +#include "replace.h" +#include "librpc/gen_ndr/security.h" + +/* the first one is for the hashed password (NT4 style) the latter + for plaintext (ADS) +*/ +#define SECRETS_MACHINE_ACCT_PASS "SECRETS/$MACHINE.ACC" +#define SECRETS_MACHINE_PASSWORD "SECRETS/MACHINE_PASSWORD" +#define SECRETS_MACHINE_PASSWORD_PREV "SECRETS/MACHINE_PASSWORD.PREV" +#define SECRETS_MACHINE_LAST_CHANGE_TIME "SECRETS/MACHINE_LAST_CHANGE_TIME" +#define SECRETS_MACHINE_SEC_CHANNEL_TYPE "SECRETS/MACHINE_SEC_CHANNEL_TYPE" +#define SECRETS_MACHINE_TRUST_ACCOUNT_NAME "SECRETS/SECRETS_MACHINE_TRUST_ACCOUNT_NAME" +#define SECRETS_MACHINE_DOMAIN_INFO "SECRETS/MACHINE_DOMAIN_INFO" +/* this one is for storing trusted domain account password */ +#define SECRETS_DOMTRUST_ACCT_PASS "SECRETS/$DOMTRUST.ACC" + +/* Store the principal name used for Kerberos DES key salt under this key name. */ +#define SECRETS_SALTING_PRINCIPAL "SECRETS/SALTING_PRINCIPAL" + +/* The domain sid and our sid are stored here even though they aren't + really secret. */ +#define SECRETS_DOMAIN_SID "SECRETS/SID" +#define SECRETS_SAM_SID "SAM/SID" +#define SECRETS_PROTECT_IDS "SECRETS/PROTECT/IDS" + +/* The domain GUID and server GUID (NOT the same) are also not secret */ +#define SECRETS_DOMAIN_GUID "SECRETS/DOMGUID" +#define SECRETS_SERVER_GUID "SECRETS/GUID" + +#define SECRETS_LDAP_BIND_PW "SECRETS/LDAP_BIND_PW" + +#define SECRETS_LOCAL_SCHANNEL_KEY "SECRETS/LOCAL_SCHANNEL_KEY" + +/* Authenticated user info is stored in secrets.tdb under these keys */ + +#define SECRETS_AUTH_USER "SECRETS/AUTH_USER" +#define SECRETS_AUTH_DOMAIN "SECRETS/AUTH_DOMAIN" +#define SECRETS_AUTH_PASSWORD "SECRETS/AUTH_PASSWORD" + +struct cli_credentials; + +/* structure for storing machine account password + (ie. when samba server is member of a domain */ +struct machine_acct_pass { + uint8_t hash[16]; + time_t mod_time; +}; + +/* + * Format of an OpenAFS keyfile + */ + +#define SECRETS_AFS_MAXKEYS 8 + +struct afs_key { + uint32_t kvno; + char key[8]; +}; + +struct afs_keyfile { + uint32_t nkeys; + struct afs_key entry[SECRETS_AFS_MAXKEYS]; +}; + +#define SECRETS_AFS_KEYFILE "SECRETS/AFS_KEYFILE" + +/* The following definitions come from passdb/secrets.c */ + +bool secrets_init_path(const char *private_dir); +bool secrets_init(void); +struct db_context *secrets_db_ctx(void); +void secrets_shutdown(void); +void *secrets_fetch(const char *key, size_t *size); +bool secrets_store(const char *key, const void *data, size_t size); +bool secrets_store_creds(struct cli_credentials *creds); +bool secrets_delete_entry(const char *key); +bool secrets_delete(const char *key); + +/* The following definitions come from passdb/machine_account_secrets.c */ +bool secrets_mark_domain_protected(const char *domain); +bool secrets_clear_domain_protection(const char *domain); +bool secrets_store_domain_sid(const char *domain, const struct dom_sid *sid); +bool secrets_fetch_domain_sid(const char *domain, struct dom_sid *sid); +bool secrets_store_domain_guid(const char *domain, const struct GUID *guid); +bool secrets_fetch_domain_guid(const char *domain, struct GUID *guid); +enum netr_SchannelType get_default_sec_channel(void); +bool secrets_fetch_trust_account_password_legacy(const char *domain, + uint8_t ret_pwd[16], + time_t *pass_last_set_time, + enum netr_SchannelType *channel); +bool secrets_fetch_trust_account_password(const char *domain, uint8_t ret_pwd[16], + time_t *pass_last_set_time, + enum netr_SchannelType *channel); +bool secrets_fetch_trusted_domain_password(const char *domain, char** pwd, + struct dom_sid *sid, time_t *pass_last_set_time); +bool secrets_store_trusted_domain_password(const char* domain, const char* pwd, + const struct dom_sid *sid); +struct libnet_JoinCtx; +NTSTATUS secrets_store_JoinCtx(const struct libnet_JoinCtx *r); +struct secrets_domain_info1; +struct secrets_domain_info1_change; +void secrets_debug_domain_info(int lvl, const struct secrets_domain_info1 *info, + const char *name); +char *secrets_domain_info_string(TALLOC_CTX *mem_ctx, const struct secrets_domain_info1 *info1, + const char *name, bool include_secrets); +NTSTATUS secrets_fetch_or_upgrade_domain_info(const char *domain, + TALLOC_CTX *mem_ctx, + struct secrets_domain_info1 **pinfo); +NTSTATUS secrets_prepare_password_change(const char *domain, const char *dcname, + const char *cleartext_unix, + TALLOC_CTX *mem_ctx, + struct secrets_domain_info1 **pinfo, + struct secrets_domain_info1_change **pprev); +NTSTATUS secrets_failed_password_change(const char *change_server, + NTSTATUS local_status, + NTSTATUS remote_status, + const struct secrets_domain_info1 *info); +NTSTATUS secrets_defer_password_change(const char *change_server, + NTSTATUS local_status, + NTSTATUS remote_status, + const struct secrets_domain_info1 *info); +NTSTATUS secrets_finish_password_change(const char *change_server, + NTTIME change_time, + const struct secrets_domain_info1 *info); +bool secrets_delete_machine_password_ex(const char *domain, const char *realm); +bool secrets_delete_domain_sid(const char *domain); +char *secrets_fetch_prev_machine_password(const char *domain); +time_t secrets_fetch_pass_last_set_time(const char *domain); +char *secrets_fetch_machine_password(const char *domain, + time_t *pass_last_set_time, + enum netr_SchannelType *channel); +bool trusted_domain_password_delete(const char *domain); +bool secrets_store_ldap_pw(const char* dn, char* pw); +bool fetch_ldap_pw(char **dn, char** pw); +bool secrets_store_afs_keyfile(const char *cell, const struct afs_keyfile *keyfile); +bool secrets_fetch_afs_key(const char *cell, struct afs_key *result); +void secrets_fetch_ipc_userpass(char **username, char **domain, char **password); +bool secrets_store_generic(const char *owner, const char *key, const char *secret); +char *secrets_fetch_generic(const char *owner, const char *key); + +bool secrets_store_machine_pw_sync(const char *pass, const char *oldpass, const char *domain, + const char *realm, + const char *salting_principal, uint32_t supported_enc_types, + const struct dom_sid *domain_sid, uint32_t last_change_time, + uint32_t secure_channel, + bool delete_join); + +char* kerberos_standard_des_salt( void ); +bool kerberos_secrets_store_des_salt( const char* salt ); +char *kerberos_secrets_fetch_salt_princ(void); + +/* The following definitions come from passdb/secrets_lsa.c */ +NTSTATUS lsa_secret_get(TALLOC_CTX *mem_ctx, + const char *secret_name, + DATA_BLOB *secret_current, + NTTIME *secret_current_lastchange, + DATA_BLOB *secret_old, + NTTIME *secret_old_lastchange, + struct security_descriptor **sd); +NTSTATUS lsa_secret_set(const char *secret_name, + DATA_BLOB *secret_current, + DATA_BLOB *secret_old, + struct security_descriptor *sd); +NTSTATUS lsa_secret_delete(const char *secret_name); + +#endif /* _SECRETS_H */ diff --git a/source3/include/serverid.h b/source3/include/serverid.h new file mode 100644 index 0000000..89487cf --- /dev/null +++ b/source3/include/serverid.h @@ -0,0 +1,31 @@ +/* + Unix SMB/CIFS implementation. + Implementation of a reliable server_exists() + Copyright (C) Volker Lendecke 2010 + + 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/>. +*/ + +#ifndef __SERVERID_H__ +#define __SERVERID_H__ + +#include "replace.h" +#include "librpc/gen_ndr/server_id.h" + +/* + * Check existence of a server id + */ +bool serverid_exists(const struct server_id *id); + +#endif diff --git a/source3/include/session.h b/source3/include/session.h new file mode 100644 index 0000000..268c059 --- /dev/null +++ b/source3/include/session.h @@ -0,0 +1,47 @@ +/* + Unix SMB/CIFS implementation. + session handling for recording currently vailid vuids + + Copyright (C) tridge@samba.org 2001 + Copyright (C) Andew Bartlett <abartlet@samba.org> 2001 + Copyright (C) Gerald (Jerry) Carter 2006 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/* a "session" is claimed when we do a SessionSetupX operation + and is yielded when the corresponding vuid is destroyed. + + sessions are used to populate utmp and PAM session structures +*/ + +struct sessionid { + uid_t uid; + gid_t gid; + fstring username; + fstring hostname; + fstring netbios_name; + fstring remote_machine; + fstring id_str; + uint32_t id_num; + struct server_id pid; + fstring ip_addr_str; + time_t connect_start; + uint16_t connection_dialect; + uint8_t encryption_flags; + uint16_t cipher; + uint16_t signing; + uint8_t signing_flags; +}; + diff --git a/source3/include/smb.h b/source3/include/smb.h new file mode 100644 index 0000000..6363bdc --- /dev/null +++ b/source3/include/smb.h @@ -0,0 +1,738 @@ +/* + Unix SMB/CIFS implementation. + SMB parameters and setup, plus a whole lot more. + + Copyright (C) Andrew Tridgell 1992-2000 + Copyright (C) John H Terpstra 1996-2002 + Copyright (C) Luke Kenneth Casson Leighton 1996-2000 + Copyright (C) Paul Ashton 1998-2000 + Copyright (C) Simo Sorce 2001-2002 + Copyright (C) Martin Pool 2002 + + 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/>. +*/ + +#ifndef _SMB_H +#define _SMB_H + +#include "libcli/smb/smb_common.h" +#include "libds/common/roles.h" + +/* logged when starting the various Samba daemons */ +#define COPYRIGHT_STARTUP_MESSAGE "Copyright Andrew Tridgell and the Samba Team 1992-2022" + +#define SAFETY_MARGIN 1024 +#define LARGE_WRITEX_HDR_SIZE 65 +#define LARGE_WRITEX_BUFFER_SIZE (128*1024) + +#define NMB_PORT 137 +#define DGRAM_PORT 138 +#define NBT_SMB_PORT 139 /* Port for SMB over NBT transport (IETF STD#19). */ +#define TCP_SMB_PORT 445 /* Port for SMB over naked TCP transport. */ +#define SMB_PORTS "445 139" + +#define Undefined (-1) +#define False false +#define True true +#define Auto (2) +#define Required (3) + +#define SIZEOFWORD 2 + +/* string manipulation flags - see clistr.c and srvstr.c */ +#define STR_TERMINATE 1 +#define STR_UPPER 2 +#define STR_ASCII 4 +#define STR_UNICODE 8 +#define STR_NOALIGN 16 +#define STR_TERMINATE_ASCII 128 + +/* how long to wait for secondary SMB packets (milli-seconds) */ +#define SMB_SECONDARY_WAIT (60*1000) + +#define DIR_STRUCT_SIZE 43 + +/* deny modes */ +#define DENY_DOS 0 +#define DENY_ALL 1 +#define DENY_WRITE 2 +#define DENY_READ 3 +#define DENY_NONE 4 +#define DENY_FCB 7 + +/* open modes */ +#define DOS_OPEN_RDONLY 0 +#define DOS_OPEN_WRONLY 1 +#define DOS_OPEN_RDWR 2 +#define DOS_OPEN_EXEC 3 +#define DOS_OPEN_FCB 0xF + +/* define shifts and masks for share and open modes. */ +#define OPENX_MODE_MASK 0xF +#define DENY_MODE_SHIFT 4 +#define DENY_MODE_MASK 0x7 +#define GET_OPENX_MODE(x) ((x) & OPENX_MODE_MASK) +#define SET_OPENX_MODE(x) ((x) & OPENX_MODE_MASK) +#define GET_DENY_MODE(x) (((x)>>DENY_MODE_SHIFT) & DENY_MODE_MASK) +#define SET_DENY_MODE(x) (((x) & DENY_MODE_MASK) <<DENY_MODE_SHIFT) + +/* Sync on open file (not sure if used anymore... ?) */ +#define FILE_SYNC_OPENMODE (1<<14) +#define GET_FILE_SYNC_OPENMODE(x) (((x) & FILE_SYNC_OPENMODE) ? True : False) + +/* open disposition values */ +#define OPENX_FILE_EXISTS_FAIL 0 +#define OPENX_FILE_EXISTS_OPEN 1 +#define OPENX_FILE_EXISTS_TRUNCATE 2 + +/* mask for open disposition. */ +#define OPENX_FILE_OPEN_MASK 0x3 + +#define GET_FILE_OPENX_DISPOSITION(x) ((x) & FILE_OPEN_MASK) +#define SET_FILE_OPENX_DISPOSITION(x) ((x) & FILE_OPEN_MASK) + +/* The above can be OR'ed with... */ +#define OPENX_FILE_CREATE_IF_NOT_EXIST 0x10 +#define OPENX_FILE_FAIL_IF_NOT_EXIST 0 + +/* pipe string names */ + +#ifndef MAXSUBAUTHS +#define MAXSUBAUTHS 15 /* max sub authorities in a SID */ +#endif + +#define SID_MAX_SIZE ((size_t)(8+(MAXSUBAUTHS*4))) + +#include "librpc/gen_ndr/security.h" + +struct share_mode_entry; +struct uuid; +struct named_mutex; +struct wb_context; +struct rpc_cli_smbd_conn; + +/* the basic packet size, assuming no words or bytes */ +#define smb_size 39 + +struct notify_change { + uint32_t action; + const char *name; +}; + +struct notify_mid_map; +struct notify_db_entry; +struct notify_event; +struct notify_change_request; +struct sys_notify_context { + struct tevent_context *ev; + void *private_data; /* For use by the system backend */ +}; + +#include "ntquotas.h" +#include "sysquotas.h" + +/* Include VFS stuff */ + +#include "smb_acls.h" +#include "lib/readdir_attr.h" +#include "vfs.h" + +struct current_user { + struct connection_struct *conn; + uint64_t vuid; /* SMB2 compat */ + struct security_unix_token ut; + struct security_token *nt_user_token; +}; + +/* Defines for the sent_oplock_break field above. */ +#define NO_BREAK_SENT 0 +#define BREAK_TO_NONE_SENT 1 +#define LEVEL_II_BREAK_SENT 2 + +typedef struct { + fstring smb_name; /* user name from the client */ + fstring unix_name; /* unix user name of a validated user */ + fstring domain; /* domain that the client specified */ +} userdom_struct; + +/* used for network interfaces */ +struct interface { + struct interface *next, *prev; + char *name; + int flags; + struct sockaddr_storage ip; + struct sockaddr_storage netmask; + struct sockaddr_storage bcast; + uint32_t if_index; + uint64_t linkspeed; + uint32_t capability; +}; + +#define SHARE_MODE_FLAG_POSIX_OPEN 0x1 + +#include "librpc/gen_ndr/server_id.h" + +/* oplock break message definition - linearization of share_mode_entry. + +Offset Data length. +0 struct server_id pid 4 +4 uint16_t op_mid 8 +12 uint16_t op_type 2 +14 uint32_t access_mask 4 +18 uint32_t share_access 4 +22 uint32_t private_options 4 +26 uint32_t time sec 4 +30 uint32_t time usec 4 +34 uint64_t dev 8 bytes +42 uint64_t inode 8 bytes +50 uint64_t extid 8 bytes +58 unsigned long file_id 4 bytes +62 uint32_t uid 4 bytes +66 uint16_t flags 2 bytes +68 uint32_t name_hash 4 bytes +72 + +*/ + +#define OP_BREAK_MSG_PID_OFFSET 0 +#define OP_BREAK_MSG_MID_OFFSET 4 +#define OP_BREAK_MSG_OP_TYPE_OFFSET 12 +#define OP_BREAK_MSG_ACCESS_MASK_OFFSET 14 +#define OP_BREAK_MSG_SHARE_ACCESS_OFFSET 18 +#define OP_BREAK_MSG_PRIV_OFFSET 22 +#define OP_BREAK_MSG_TIME_SEC_OFFSET 26 +#define OP_BREAK_MSG_TIME_USEC_OFFSET 30 +#define OP_BREAK_MSG_DEV_OFFSET 34 +#define OP_BREAK_MSG_INO_OFFSET 42 +#define OP_BREAK_MSG_EXTID_OFFSET 50 +#define OP_BREAK_MSG_FILE_ID_OFFSET 58 +#define OP_BREAK_MSG_UID_OFFSET 62 +#define OP_BREAK_MSG_FLAGS_OFFSET 66 +#define OP_BREAK_MSG_NAME_HASH_OFFSET 68 + +#define OP_BREAK_MSG_VNN_OFFSET 72 +#define MSG_SMB_SHARE_MODE_ENTRY_SIZE 76 + +#define NT_HASH_LEN 16 +#define LM_HASH_LEN 16 + +/* offsets into message for common items */ +#define smb_com (NBT_HDR_SIZE+HDR_COM) +#define smb_rcls (NBT_HDR_SIZE+HDR_RCLS) +#define smb_reh (NBT_HDR_SIZE+HDR_REH) +#define smb_err (NBT_HDR_SIZE+HDR_ERR) +#define smb_flg (NBT_HDR_SIZE+HDR_FLG) +#define smb_flg2 (NBT_HDR_SIZE+HDR_FLG2) +#define smb_pidhigh (NBT_HDR_SIZE+HDR_PIDHIGH) +#define smb_ss_field (NBT_HDR_SIZE+HDR_SS_FIELD) +#define smb_tid (NBT_HDR_SIZE+HDR_TID) +#define smb_pid (NBT_HDR_SIZE+HDR_PID) +#define smb_uid (NBT_HDR_SIZE+HDR_UID) +#define smb_mid (NBT_HDR_SIZE+HDR_MID) +#define smb_wct (NBT_HDR_SIZE+HDR_WCT) +#define smb_vwv (NBT_HDR_SIZE+HDR_VWV) +#define smb_vwv0 (smb_vwv+( 0*2)) +#define smb_vwv1 (smb_vwv+( 1*2)) +#define smb_vwv2 (smb_vwv+( 2*2)) +#define smb_vwv3 (smb_vwv+( 3*2)) +#define smb_vwv4 (smb_vwv+( 4*2)) +#define smb_vwv5 (smb_vwv+( 5*2)) +#define smb_vwv6 (smb_vwv+( 6*2)) +#define smb_vwv7 (smb_vwv+( 7*2)) +#define smb_vwv8 (smb_vwv+( 8*2)) +#define smb_vwv9 (smb_vwv+( 9*2)) +#define smb_vwv10 (smb_vwv+(10*2)) +#define smb_vwv11 (smb_vwv+(11*2)) +#define smb_vwv12 (smb_vwv+(12*2)) +#define smb_vwv13 (smb_vwv+(13*2)) +#define smb_vwv14 (smb_vwv+(14*2)) +#define smb_vwv15 (smb_vwv+(15*2)) +#define smb_vwv16 (smb_vwv+(16*2)) +#define smb_vwv17 (smb_vwv+(17*2)) + +/* These are the NT transact_get_user_quota sub commands */ +#define TRANSACT_GET_USER_QUOTA_LIST_CONTINUE 0x0000 +#define TRANSACT_GET_USER_QUOTA_LIST_START 0x0100 +#define TRANSACT_GET_USER_QUOTA_FOR_SID 0x0101 + +/* Relevant IOCTL codes */ +#define IOCTL_QUERY_JOB_INFO 0x530060 + +/* these are the trans2 sub fields for primary requests */ +#define smb_tpscnt smb_vwv0 +#define smb_tdscnt smb_vwv1 +#define smb_mprcnt smb_vwv2 +#define smb_mdrcnt smb_vwv3 +#define smb_msrcnt smb_vwv4 +#define smb_flags smb_vwv5 +#define smb_timeout smb_vwv6 +#define smb_pscnt smb_vwv9 +#define smb_psoff smb_vwv10 +#define smb_dscnt smb_vwv11 +#define smb_dsoff smb_vwv12 +#define smb_suwcnt smb_vwv13 +#define smb_setup smb_vwv14 +#define smb_setup0 smb_setup +#define smb_setup1 (smb_setup+2) +#define smb_setup2 (smb_setup+4) + +/* these are for the secondary requests */ +#define smb_spscnt smb_vwv2 +#define smb_spsoff smb_vwv3 +#define smb_spsdisp smb_vwv4 +#define smb_sdscnt smb_vwv5 +#define smb_sdsoff smb_vwv6 +#define smb_sdsdisp smb_vwv7 +#define smb_sfid smb_vwv8 + +/* and these for responses */ +#define smb_tprcnt smb_vwv0 +#define smb_tdrcnt smb_vwv1 +#define smb_prcnt smb_vwv3 +#define smb_proff smb_vwv4 +#define smb_prdisp smb_vwv5 +#define smb_drcnt smb_vwv6 +#define smb_droff smb_vwv7 +#define smb_drdisp smb_vwv8 + +/* these are for the NT trans primary request. */ +#define smb_nt_MaxSetupCount smb_vwv0 +#define smb_nt_Flags (smb_vwv0 + 1) +#define smb_nt_TotalParameterCount (smb_vwv0 + 3) +#define smb_nt_TotalDataCount (smb_vwv0 + 7) +#define smb_nt_MaxParameterCount (smb_vwv0 + 11) +#define smb_nt_MaxDataCount (smb_vwv0 + 15) +#define smb_nt_ParameterCount (smb_vwv0 + 19) +#define smb_nt_ParameterOffset (smb_vwv0 + 23) +#define smb_nt_DataCount (smb_vwv0 + 27) +#define smb_nt_DataOffset (smb_vwv0 + 31) +#define smb_nt_SetupCount (smb_vwv0 + 35) +#define smb_nt_Function (smb_vwv0 + 36) +#define smb_nt_SetupStart (smb_vwv0 + 38) + +/* these are for the NT trans secondary request. */ +#define smb_nts_TotalParameterCount (smb_vwv0 + 3) +#define smb_nts_TotalDataCount (smb_vwv0 + 7) +#define smb_nts_ParameterCount (smb_vwv0 + 11) +#define smb_nts_ParameterOffset (smb_vwv0 + 15) +#define smb_nts_ParameterDisplacement (smb_vwv0 + 19) +#define smb_nts_DataCount (smb_vwv0 + 23) +#define smb_nts_DataOffset (smb_vwv0 + 27) +#define smb_nts_DataDisplacement (smb_vwv0 + 31) + +/* these are for the NT trans reply. */ +#define smb_ntr_TotalParameterCount (smb_vwv0 + 3) +#define smb_ntr_TotalDataCount (smb_vwv0 + 7) +#define smb_ntr_ParameterCount (smb_vwv0 + 11) +#define smb_ntr_ParameterOffset (smb_vwv0 + 15) +#define smb_ntr_ParameterDisplacement (smb_vwv0 + 19) +#define smb_ntr_DataCount (smb_vwv0 + 23) +#define smb_ntr_DataOffset (smb_vwv0 + 27) +#define smb_ntr_DataDisplacement (smb_vwv0 + 31) + +/* these are for the NT create_and_X */ +#define smb_ntcreate_NameLength (smb_vwv0 + 5) +#define smb_ntcreate_Flags (smb_vwv0 + 7) +#define smb_ntcreate_RootDirectoryFid (smb_vwv0 + 11) +#define smb_ntcreate_DesiredAccess (smb_vwv0 + 15) +#define smb_ntcreate_AllocationSize (smb_vwv0 + 19) +#define smb_ntcreate_FileAttributes (smb_vwv0 + 27) +#define smb_ntcreate_ShareAccess (smb_vwv0 + 31) +#define smb_ntcreate_CreateDisposition (smb_vwv0 + 35) +#define smb_ntcreate_CreateOptions (smb_vwv0 + 39) +#define smb_ntcreate_ImpersonationLevel (smb_vwv0 + 43) +#define smb_ntcreate_SecurityFlags (smb_vwv0 + 47) + +/* Named pipe write mode flags. Used in writeX calls. */ +#define PIPE_RAW_MODE 0x4 +#define PIPE_START_MESSAGE 0x8 + +/* the desired access to use when opening a pipe */ +#define DESIRED_ACCESS_PIPE 0x2019f + +/* Mapping of access rights to UNIX perms. */ +#define UNIX_ACCESS_RWX FILE_GENERIC_ALL +#define UNIX_ACCESS_R FILE_GENERIC_READ +#define UNIX_ACCESS_W FILE_GENERIC_WRITE +#define UNIX_ACCESS_X FILE_GENERIC_EXECUTE + +/* Mapping of access rights to UNIX perms. for a UNIX directory. */ +#define UNIX_DIRECTORY_ACCESS_RWX FILE_GENERIC_ALL +#define UNIX_DIRECTORY_ACCESS_R FILE_GENERIC_READ +#define UNIX_DIRECTORY_ACCESS_W (FILE_GENERIC_WRITE|FILE_DELETE_CHILD) +#define UNIX_DIRECTORY_ACCESS_X FILE_GENERIC_EXECUTE + +#if 0 +/* + * This is the old mapping we used to use. To get W2KSP2 profiles + * working we need to map to the canonical file perms. + */ +#define UNIX_ACCESS_RWX (UNIX_ACCESS_R|UNIX_ACCESS_W|UNIX_ACCESS_X) +#define UNIX_ACCESS_R (READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS|\ + FILE_READ_ATTRIBUTES|FILE_READ_EA|FILE_READ_DATA) +#define UNIX_ACCESS_W (READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS|\ + FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA|\ + FILE_APPEND_DATA|FILE_WRITE_DATA) +#define UNIX_ACCESS_X (READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS|\ + FILE_EXECUTE|FILE_READ_ATTRIBUTES) +#endif + +#define UNIX_ACCESS_NONE (WRITE_OWNER_ACCESS) + +/* Flags field. */ +#define REQUEST_OPLOCK 2 +#define REQUEST_BATCH_OPLOCK 4 +#define OPEN_DIRECTORY 8 +#define EXTENDED_RESPONSE_REQUIRED 0x10 + +#define NTCREATEX_OPTIONS_MUST_IGNORE_MASK (0x008F0480) + +#define NTCREATEX_OPTIONS_INVALID_PARAM_MASK (0xFF100030) + +/* + * Private flags used by the ntcreatex processing + * code. Passed in the private_flags argument. + */ +#define NTCREATEX_FLAG_DENY_DOS 0x0001 +#define NTCREATEX_FLAG_DENY_FCB 0x0002 + +/* Private flag for streams support */ +#define NTCREATEX_FLAG_STREAM_BASEOPEN 0x0010 + +/* Flag for NT transact rename call. */ +#define RENAME_REPLACE_IF_EXISTS 1 + +/* flags for SMBntrename call (from Samba4) */ +#define RENAME_FLAG_MOVE_CLUSTER_INFORMATION 0x102 /* ???? */ +#define RENAME_FLAG_HARD_LINK 0x103 +#define RENAME_FLAG_RENAME 0x104 +#define RENAME_FLAG_COPY 0x105 + +/* ChangeNotify flags. */ +#define FILE_NOTIFY_CHANGE_FILE_NAME 0x001 +#define FILE_NOTIFY_CHANGE_DIR_NAME 0x002 +#define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x004 +#define FILE_NOTIFY_CHANGE_SIZE 0x008 +#define FILE_NOTIFY_CHANGE_LAST_WRITE 0x010 +#define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x020 +#define FILE_NOTIFY_CHANGE_CREATION 0x040 +#define FILE_NOTIFY_CHANGE_EA 0x080 +#define FILE_NOTIFY_CHANGE_SECURITY 0x100 +#define FILE_NOTIFY_CHANGE_STREAM_NAME 0x00000200 +#define FILE_NOTIFY_CHANGE_STREAM_SIZE 0x00000400 +#define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800 + +#define FILE_NOTIFY_CHANGE_NAME \ + (FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_DIR_NAME) + +#define FILE_NOTIFY_CHANGE_ALL \ + (FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME | \ + FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_SIZE | \ + FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_LAST_ACCESS | \ + FILE_NOTIFY_CHANGE_CREATION | FILE_NOTIFY_CHANGE_EA | \ + FILE_NOTIFY_CHANGE_SECURITY | FILE_NOTIFY_CHANGE_STREAM_NAME | \ + FILE_NOTIFY_CHANGE_STREAM_SIZE | FILE_NOTIFY_CHANGE_STREAM_WRITE) + +/* change notify action results */ +#define NOTIFY_ACTION_ADDED 1 +#define NOTIFY_ACTION_REMOVED 2 +#define NOTIFY_ACTION_MODIFIED 3 +#define NOTIFY_ACTION_OLD_NAME 4 +#define NOTIFY_ACTION_NEW_NAME 5 +#define NOTIFY_ACTION_ADDED_STREAM 6 +#define NOTIFY_ACTION_REMOVED_STREAM 7 +#define NOTIFY_ACTION_MODIFIED_STREAM 8 + +/* + * Timestamp format used in "previous versions": + * This is the windows-level format of the @GMT- token. + * It is a fixed format not to be confused with the + * format for the POSIX-Level token of the shadow_copy2 + * VFS module that can be configured via the "shadow:format" + * configuration option but defaults to the same format. + * See the shadow_copy2 module. + */ +#define GMT_NAME_LEN 24 /* length of a @GMT- name */ +#define GMT_FORMAT "@GMT-%Y.%m.%d-%H.%M.%S" + +/* where to find the base of the SMB packet proper */ +#define smb_base(buf) (((const char *)(buf))+4) + +/* we don't allow server strings to be longer than 48 characters as + otherwise NT will not honour the announce packets */ +#define MAX_SERVER_STRING_LENGTH 48 + +#ifdef NOSTRDUP +char *strdup(char *s); +#endif + +#ifndef SELECT_CAST +#define SELECT_CAST +#endif + +/* This was set by JHT in liaison with Jeremy Allison early 1997 + * History: + * Version 4.0 - never made public + * Version 4.10 - New to 1.9.16p2, lost in space 1.9.16p3 to 1.9.16p9 + * - Reappeared in 1.9.16p11 with fixed smbd services + * Version 4.20 - To indicate that nmbd and browsing now works better + * Version 4.50 - Set at release of samba-2.2.0 by JHT + * + * Note: In the presence of NT4.X do not set above 4.9 + * Setting this above 4.9 can have undesired side-effects. + * This may change again in Samba-3.0 after further testing. JHT + * + * Version 6.1 - For older smb server versions, MMC doesn't let offline + * settings to be configured during share creation. Changing + * it to 6.1 to mimic Win2K8R2. + * + */ + +#define SAMBA_MAJOR_NBT_ANNOUNCE_VERSION 0x06 +#define SAMBA_MINOR_NBT_ANNOUNCE_VERSION 0x01 + +/* Browser Election Values */ +#define BROWSER_ELECTION_VERSION 0x010f +#define BROWSER_CONSTANT 0xaa55 + +/* File Status Flags. See: + +http://msdn.microsoft.com/en-us/library/cc246334(PROT.13).aspx +*/ + +#define NO_EAS 0x1 +#define NO_SUBSTREAMS 0x2 +#define NO_REPARSETAG 0x4 + +/* Remote architectures we know about, keep in sync with remote_arch_strings */ +enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, + RA_WIN2K, RA_WINXP, RA_WIN2K3, RA_VISTA, + RA_SAMBA, RA_CIFSFS, RA_WINXP64, RA_OSX}; + +/* + * Global value meaning that the smb_uid field should be + * ingored (in share level security and protocol level == CORE) + */ + +#define UID_FIELD_INVALID 0 +#define VUID_OFFSET 100 /* Amount to bias returned vuid numbers */ + +#define TID_FIELD_INVALID 0 + +#define FNUM_FIELD_INVALID 0 + +/* + * Map the Core and Extended Oplock request bits down + * to common bits (EXCLUSIVE_OPLOCK & BATCH_OPLOCK). + */ + +/* + * Core protocol. + */ +#define CORE_OPLOCK_REQUEST(inbuf) \ + ((CVAL(inbuf,smb_flg)&(FLAG_REQUEST_OPLOCK|FLAG_REQUEST_BATCH_OPLOCK))>>5) + +/* + * Extended protocol. + */ +#define EXTENDED_OPLOCK_REQUEST(inbuf) ((SVAL(inbuf,smb_vwv2)&((1<<1)|(1<<2)))>>1) + +/* + * Bits we test with. + * Note these must fit into 16-bits. + */ + +#define NO_OPLOCK OPLOCK_NONE +#define EXCLUSIVE_OPLOCK OPLOCK_EXCLUSIVE +#define BATCH_OPLOCK OPLOCK_BATCH +#define LEVEL_II_OPLOCK OPLOCK_LEVEL_II +#define LEASE_OPLOCK 0x100 + +/* The following are Samba-private. */ +#define INTERNAL_OPEN_ONLY 0x8 +/* #define FAKE_LEVEL_II_OPLOCK 0x10 */ /* Not used anymore */ + /* Client requested no_oplock, but we have to + * inform potential level2 holders on + * write. */ +/* #define DEFERRED_OPEN_ENTRY 0x20 */ /* Not used anymore */ +/* #define UNUSED_SHARE_MODE_ENTRY 0x40 */ /* Not used anymore */ +/* #define FORCE_OPLOCK_BREAK_TO_NONE 0x80 */ /* Not used anymore */ + +/* None of the following should ever appear in fsp->oplock_request. */ +#define SAMBA_PRIVATE_OPLOCK_MASK (INTERNAL_OPEN_ONLY) + +#define EXCLUSIVE_OPLOCK_TYPE(lck) ((lck) & ((unsigned int)EXCLUSIVE_OPLOCK|(unsigned int)BATCH_OPLOCK)) +#define BATCH_OPLOCK_TYPE(lck) ((lck) & (unsigned int)BATCH_OPLOCK) +#define LEVEL_II_OPLOCK_TYPE(lck) ((lck) & (unsigned int)LEVEL_II_OPLOCK) + +/* kernel_oplock_message definition. + +struct kernel_oplock_message { + uint64_t dev; + uint64_t inode; + unit64_t extid; + unsigned long file_id; +}; + +Offset Data length. +0 uint64_t dev 8 bytes +8 uint64_t inode 8 bytes +16 uint64_t extid 8 bytes +24 unsigned long file_id 4 bytes +28 + +*/ +#define MSG_SMB_KERNEL_BREAK_SIZE 28 + +/* + * On the wire return values for oplock types. + */ + +#define CORE_OPLOCK_GRANTED (1<<5) +#define EXTENDED_OPLOCK_GRANTED (1<<15) + +#define NO_OPLOCK_RETURN 0 +#define EXCLUSIVE_OPLOCK_RETURN 1 +#define BATCH_OPLOCK_RETURN 2 +#define LEVEL_II_OPLOCK_RETURN 3 + +/* Oplock levels */ +#define OPLOCKLEVEL_NONE 0 +#define OPLOCKLEVEL_II 1 + +/* + * Capabilities abstracted for different systems. + */ + +enum smbd_capability { + KERNEL_OPLOCK_CAPABILITY, + DMAPI_ACCESS_CAPABILITY, + LEASE_CAPABILITY, + DAC_OVERRIDE_CAPABILITY +}; + +struct kernel_oplocks_ops; +struct kernel_oplocks { + const struct kernel_oplocks_ops *ops; + void *private_data; +}; + +enum level2_contention_type { + LEVEL2_CONTEND_ALLOC_SHRINK, + LEVEL2_CONTEND_ALLOC_GROW, + LEVEL2_CONTEND_SET_FILE_LEN, + LEVEL2_CONTEND_FILL_SPARSE, + LEVEL2_CONTEND_WRITE, + LEVEL2_CONTEND_WINDOWS_BRL, + LEVEL2_CONTEND_POSIX_BRL +}; + +/* if a kernel does support oplocks then a structure of the following + typee is used to describe how to interact with the kernel */ +struct kernel_oplocks_ops { + bool (*set_oplock)(struct kernel_oplocks *ctx, + files_struct *fsp, int oplock_type); + void (*release_oplock)(struct kernel_oplocks *ctx, + files_struct *fsp, int oplock_type); +}; + +#include "smb_macros.h" + +#define MAX_NETBIOSNAME_LEN 16 +/* DOS character, NetBIOS namestring. Type used on the wire. */ +typedef char nstring[MAX_NETBIOSNAME_LEN]; +/* Unix character, NetBIOS namestring. Type used to manipulate name in nmbd. */ +typedef char unstring[MAX_NETBIOSNAME_LEN*4]; + +/* A netbios name structure. */ +struct nmb_name { + nstring name; + char scope[64]; + unsigned int name_type; +}; + +/* A netbios node status array element. */ +struct node_status { + nstring name; + unsigned char type; + unsigned char flags; +}; + +/* The extra info from a NetBIOS node status query */ +struct node_status_extra { + unsigned char mac_addr[6]; + /* There really is more here ... */ +}; + +#define SAFE_NETBIOS_CHARS ". -_" + +#define PORT_NONE 0 +#ifndef LDAP_PORT +#define LDAP_PORT 389 +#endif +#define LDAP_GC_PORT 3268 + +struct ea_struct { + uint8_t flags; + char *name; + DATA_BLOB value; +}; + +struct ea_list { + struct ea_list *next, *prev; + struct ea_struct ea; +}; + +/* EA names used internally in Samba. KEEP UP TO DATE with prohibited_ea_names in trans2.c !. */ +#define SAMBA_POSIX_INHERITANCE_EA_NAME "user.SAMBA_PAI" +/* EA to use for DOS attributes */ +#define SAMBA_XATTR_DOS_ATTRIB "user.DOSATTRIB" +/* Prefix for DosStreams in the vfs_streams_xattr module */ +#define SAMBA_XATTR_DOSSTREAM_PREFIX "user.DosStream." +/* Prefix for xattrs storing streams. */ +#define SAMBA_XATTR_MARKER "user.SAMBA_STREAMS" + +/* usershare error codes. */ +enum usershare_err { + USERSHARE_OK=0, + USERSHARE_MALFORMED_FILE, + USERSHARE_BAD_VERSION, + USERSHARE_MALFORMED_PATH, + USERSHARE_MALFORMED_COMMENT_DEF, + USERSHARE_MALFORMED_ACL_DEF, + USERSHARE_ACL_ERR, + USERSHARE_PATH_NOT_ABSOLUTE, + USERSHARE_PATH_IS_DENIED, + USERSHARE_PATH_NOT_ALLOWED, + USERSHARE_PATH_NOT_DIRECTORY, + USERSHARE_POSIX_ERR, + USERSHARE_MALFORMED_SHARENAME_DEF, + USERSHARE_BAD_SHARENAME +}; + +/* Different reasons for closing a file. */ +enum file_close_type {NORMAL_CLOSE=0,SHUTDOWN_CLOSE,ERROR_CLOSE}; + +/* Used in SMB_FS_OBJECTID_INFORMATION requests. Must be exactly 48 bytes. */ +#define SAMBA_EXTENDED_INFO_MAGIC 0x536d4261 /* "SmBa" */ +#define SAMBA_EXTENDED_INFO_VERSION_STRING_LENGTH 28 +struct smb_extended_info { + uint32_t samba_magic; /* Always SAMBA_EXTRA_INFO_MAGIC */ + uint32_t samba_version; /* Major/Minor/Release/Revision */ + uint32_t samba_subversion; /* Prerelease/RC/Vendor patch */ + NTTIME samba_gitcommitdate; + char samba_version_string[SAMBA_EXTENDED_INFO_VERSION_STRING_LENGTH]; +}; + +#endif /* _SMB_H */ diff --git a/source3/include/smb_acls.h b/source3/include/smb_acls.h new file mode 100644 index 0000000..7203dd2 --- /dev/null +++ b/source3/include/smb_acls.h @@ -0,0 +1,73 @@ +/* + Unix SMB/CIFS implementation. + Portable SMB ACL interface + Copyright (C) Jeremy Allison 2000 + + 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/>. +*/ + +#ifndef _SMB_ACLS_H +#define _SMB_ACLS_H + +#include "librpc/gen_ndr/smb_acl.h" + +struct vfs_handle_struct; +struct files_struct; +struct smb_filename; + +typedef int SMB_ACL_TYPE_T; +/* + * struct smb_acl_entry is defined in IDL as + * using mode_t values, pidl always converts these + * to uint32_t. Ensure the external type definitions + * match. + */ +typedef uint32_t *SMB_ACL_PERMSET_T; +typedef uint32_t SMB_ACL_PERM_T; + +typedef enum smb_acl_tag_t SMB_ACL_TAG_T; +typedef struct smb_acl_t *SMB_ACL_T; + +typedef struct smb_acl_entry *SMB_ACL_ENTRY_T; + +/* The following definitions come from lib/sysacls.c */ + +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p); +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p); +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p); +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d); +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d); +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm); +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm); +char *sys_acl_to_text(const struct smb_acl_t *acl_d, ssize_t *len_p); +SMB_ACL_T sys_acl_init(TALLOC_CTX *mem_ctx); +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p); +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type); +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p); +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d); +int sys_acl_free_text(char *text); +int sys_acl_valid(SMB_ACL_T acl_d); +SMB_ACL_T sys_acl_get_fd(struct vfs_handle_struct *handle, + struct files_struct *fsp, + SMB_ACL_TYPE_T type, + TALLOC_CTX *mem_ctx); +int sys_acl_set_fd(struct vfs_handle_struct *handle, + struct files_struct *fsp, + SMB_ACL_TYPE_T type, + SMB_ACL_T acl_d); +int sys_acl_delete_def_fd(struct vfs_handle_struct *handle, + struct files_struct *fsp); +int no_acl_syscall_error(int err); + +#endif /* _SMB_ACLS_H */ diff --git a/source3/include/smb_krb5.h b/source3/include/smb_krb5.h new file mode 100644 index 0000000..743b67f --- /dev/null +++ b/source3/include/smb_krb5.h @@ -0,0 +1,2 @@ +#include "lib/krb5_wrap/krb5_samba.h" +#include "lib/krb5_wrap/gss_samba.h" diff --git a/source3/include/smb_ldap.h b/source3/include/smb_ldap.h new file mode 100644 index 0000000..5786638 --- /dev/null +++ b/source3/include/smb_ldap.h @@ -0,0 +1,110 @@ +/* + Unix SMB/CIFS implementation. + Copyright (C) Andrew Tridgell 2001 + Copyright (C) Remus Koos 2001 + Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002 + Copyright (C) Guenther Deschner 2005 + Copyright (C) Gerald Carter 2006 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _SMB_LDAP_H +#define _SMB_LDAP_H + +#ifdef HAVE_LBER_H +#include <lber.h> +#if defined(HPUX) && !defined(_LBER_TYPES_H) +/* Define ber_tag_t and ber_int_t for using + * HP LDAP-UX Integration products' LDAP libraries. +*/ +#ifndef ber_tag_t +typedef unsigned long ber_tag_t; +typedef int ber_int_t; +#endif +#endif /* defined(HPUX) && !defined(_LBER_TYPES_H) */ +#ifndef LBER_USE_DER +#define LBER_USE_DER 0x01 +#endif +#endif /* HAVE_LBER_H */ + +#ifdef HAVE_LDAP_H +#include <ldap.h> +#ifndef LDAP_CONST +#define LDAP_CONST const +#endif + +#ifdef HAVE_LDAP_PVT_H +#include <ldap_pvt.h> +#endif /* HAVE_LDAP_PVT_H */ + +/* Solaris 8 and maybe other LDAP implementations spell this "..._INPROGRESS": */ +#if defined(LDAP_SASL_BIND_INPROGRESS) && !defined(LDAP_SASL_BIND_IN_PROGRESS) +#define LDAP_SASL_BIND_IN_PROGRESS LDAP_SASL_BIND_INPROGRESS +#endif +/* Solaris 8 defines SSL_LDAP_PORT, not LDAPS_PORT and it only does so if + LDAP_SSL is defined - but SSL is not working. We just want the + port number! Let's just define LDAPS_PORT correct. */ +#if !defined(LDAPS_PORT) +#define LDAPS_PORT 636 +#endif + +#endif /* HAVE_LDAP_H */ + +#ifndef HAVE_LDAP +#define LDAP void +#define LDAPMessage void +#define LDAPMod void +#define LDAP_CONST const +#define LDAPControl void +struct berval; +struct ldapsam_privates; +#endif /* HAVE_LDAP */ + +#ifndef LDAP_OPT_SUCCESS +#define LDAP_OPT_SUCCESS 0 +#endif + +#define LDAP_DEFAULT_TIMEOUT 15 +#define LDAP_CONNECTION_DEFAULT_TIMEOUT 2 +#define LDAP_PAGE_SIZE 1000 + +#define ADS_PAGE_CTL_OID "1.2.840.113556.1.4.319" + +/* + * Work around versions of the LDAP client libs that don't have the OIDs + * defined, or have them defined under the old name. + * This functionality is really a factor of the server, not the client + * + */ + +#if defined(LDAP_EXOP_X_MODIFY_PASSWD) && !defined(LDAP_EXOP_MODIFY_PASSWD) +#define LDAP_EXOP_MODIFY_PASSWD LDAP_EXOP_X_MODIFY_PASSWD +#elif !defined(LDAP_EXOP_MODIFY_PASSWD) +#define LDAP_EXOP_MODIFY_PASSWD "1.3.6.1.4.1.4203.1.11.1" +#endif + +#if defined(LDAP_EXOP_X_MODIFY_PASSWD_ID) && !defined(LDAP_EXOP_MODIFY_PASSWD_ID) +#define LDAP_TAG_EXOP_MODIFY_PASSWD_ID LDAP_EXOP_X_MODIFY_PASSWD_ID +#elif !defined(LDAP_EXOP_MODIFY_PASSWD_ID) +#define LDAP_TAG_EXOP_MODIFY_PASSWD_ID ((ber_tag_t) 0x80U) +#endif + +#if defined(LDAP_EXOP_X_MODIFY_PASSWD_NEW) && !defined(LDAP_EXOP_MODIFY_PASSWD_NEW) +#define LDAP_TAG_EXOP_MODIFY_PASSWD_NEW LDAP_EXOP_X_MODIFY_PASSWD_NEW +#elif !defined(LDAP_EXOP_MODIFY_PASSWD_NEW) +#define LDAP_TAG_EXOP_MODIFY_PASSWD_NEW ((ber_tag_t) 0x82U) +#endif + +#endif /* _SMB_LDAP_H */ diff --git a/source3/include/smb_macros.h b/source3/include/smb_macros.h new file mode 100644 index 0000000..8271dbd --- /dev/null +++ b/source3/include/smb_macros.h @@ -0,0 +1,304 @@ +/* + Unix SMB/CIFS implementation. + SMB parameters and setup + Copyright (C) Andrew Tridgell 1992-1999 + Copyright (C) John H Terpstra 1996-1999 + Copyright (C) Luke Kenneth Casson Leighton 1996-1999 + Copyright (C) Paul Ashton 1998 - 1999 + + 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/>. +*/ + +#ifndef _SMB_MACROS_H +#define _SMB_MACROS_H + +/* Misc bit macros */ +#define BOOLSTR(b) ((b) ? "Yes" : "No") +#define BITSETW(ptr,bit) ((SVAL(ptr,0) & (1<<(bit)))!=0) + +/* for readability... */ +#define IS_DOS_READONLY(test_mode) (((test_mode) & FILE_ATTRIBUTE_READONLY) != 0) +#define IS_DOS_DIR(test_mode) (((test_mode) & FILE_ATTRIBUTE_DIRECTORY) != 0) +#define IS_DOS_ARCHIVE(test_mode) (((test_mode) & FILE_ATTRIBUTE_ARCHIVE) != 0) +#define IS_DOS_SYSTEM(test_mode) (((test_mode) & FILE_ATTRIBUTE_SYSTEM) != 0) +#define IS_DOS_HIDDEN(test_mode) (((test_mode) & FILE_ATTRIBUTE_HIDDEN) != 0) + +#define SMB_WARN(condition, message) \ + ((condition) ? (void)0 : \ + DEBUG(0, ("WARNING: %s: %s\n", #condition, message))) + +#define SMB_ASSERT_ARRAY(a,n) SMB_ASSERT((sizeof(a)/sizeof((a)[0])) >= (n)) + +/* these are useful macros for checking validity of handles */ +#define IS_IPC(conn) ((conn) && (conn)->ipc) +#define IS_PRINT(conn) ((conn) && (conn)->printer) + +#define CHECK_READ(fsp,req) \ + ((!(fsp)->fsp_flags.is_pathref) && \ + (fsp_get_io_fd(fsp) != -1) && \ + (((fsp)->fsp_flags.can_read) || \ + ((req->flags2 & FLAGS2_READ_PERMIT_EXECUTE) && \ + (fsp->access_mask & FILE_EXECUTE)))) + +/* + * This is not documented in revision 49 of [MS-SMB2] but should be added in a + * later revision (and torture test smb2.read.access as well as + * smb2.ioctl_copy_chunk_bad_access against Server 2012R2 confirms this) + * + * If FILE_EXECUTE is granted to a handle then the SMB2 server acts as if + * FILE_READ_DATA has also been granted. We must still keep the original granted + * mask, because with ioctl requests, access checks are made on the file handle, + * "below" the SMB2 server, and the object store below the SMB layer is not + * aware of this arrangement (see smb2.ioctl.copy_chunk_bad_access torture + * test). + */ +#define CHECK_READ_SMB2(fsp) \ + ((!(fsp)->fsp_flags.is_pathref) && \ + (fsp_get_io_fd(fsp) != -1) && \ + (((fsp)->fsp_flags.can_read) || \ + (fsp->access_mask & FILE_EXECUTE))) + +/* An IOCTL readability check (validating read access + * when the IOCTL code requires it) + * http://social.technet.microsoft.com/wiki/contents/articles/24653.decoding-io-control-codes-ioctl-fsctl-and-deviceiocodes-with-table-of-known-values.aspx + * ). On Windows servers, this is done by the IO manager, which is unaware of + * the "if execute is granted then also grant read" arrangement. + */ +#define CHECK_READ_IOCTL(fsp) \ + ((!(fsp)->fsp_flags.is_pathref) && \ + (fsp_get_io_fd(fsp) != -1) && \ + (((fsp)->fsp_flags.can_read))) + +#define CHECK_WRITE(fsp) \ + ((fsp)->fsp_flags.can_write && \ + (!(fsp)->fsp_flags.is_pathref) && \ + (fsp_get_io_fd(fsp) != -1)) + +#define ERROR_WAS_LOCK_DENIED(status) (NT_STATUS_EQUAL((status), NT_STATUS_LOCK_NOT_GRANTED) || \ + NT_STATUS_EQUAL((status), NT_STATUS_FILE_LOCK_CONFLICT) ) + +/* the service number for the [globals] defaults */ +#define GLOBAL_SECTION_SNUM (-1) +/* translates a connection number into a service number */ +#define SNUM(conn) ((conn)?(conn)->params->service:GLOBAL_SECTION_SNUM) + + +/* access various service details */ +#define CAN_WRITE(conn) (!conn->read_only) +#define VALID_SNUM(snum) (lp_snum_ok(snum)) +#define GUEST_OK(snum) (VALID_SNUM(snum) && lp_guest_ok(snum)) +#define GUEST_ONLY(snum) (VALID_SNUM(snum) && lp_guest_only(snum)) +#define CAN_PRINT(conn) ((conn) && lp_printable(SNUM(conn))) +#define MAP_HIDDEN(conn) ((conn) && lp_map_hidden(SNUM(conn))) +#define MAP_SYSTEM(conn) ((conn) && lp_map_system(SNUM(conn))) +#define MAP_ARCHIVE(conn) ((conn) && lp_map_archive(SNUM(conn))) +#define IS_HIDDEN_PATH(conn,path) ((conn) && is_in_path((path),(conn)->hide_list,(conn)->case_sensitive)) +#define IS_VETO_PATH(conn,path) ((conn) && is_in_path((path),(conn)->veto_list,(conn)->case_sensitive)) +#define IS_VETO_OPLOCK_PATH(conn,path) ((conn) && is_in_path((path),(conn)->veto_oplock_list,(conn)->case_sensitive)) + +/* + * Used by the stat cache code to check if a returned + * stat structure is valid. + */ + +#define VALID_STAT(st) ((st).st_ex_nlink != 0) +#define VALID_STAT_OF_DIR(st) (VALID_STAT(st) && S_ISDIR((st).st_ex_mode)) +#define SET_STAT_INVALID(st) ((st).st_ex_nlink = 0) + +/* Macros to get at offsets within smb_lkrng and smb_unlkrng + structures. We cannot define these as actual structures + due to possible differences in structure packing + on different machines/compilers. */ + +#define SMB_LPID_OFFSET(indx) (10 * (indx)) +#define SMB_LKOFF_OFFSET(indx) ( 2 + (10 * (indx))) +#define SMB_LKLEN_OFFSET(indx) ( 6 + (10 * (indx))) +#define SMB_LARGE_LPID_OFFSET(indx) (20 * (indx)) +#define SMB_LARGE_LKOFF_OFFSET_HIGH(indx) (4 + (20 * (indx))) +#define SMB_LARGE_LKOFF_OFFSET_LOW(indx) (8 + (20 * (indx))) +#define SMB_LARGE_LKLEN_OFFSET_HIGH(indx) (12 + (20 * (indx))) +#define SMB_LARGE_LKLEN_OFFSET_LOW(indx) (16 + (20 * (indx))) + +#define ERROR_NT(status) error_packet(outbuf,0,0,status,__LINE__,__FILE__) +#define ERROR_BOTH(status,class,code) error_packet(outbuf,class,code,status,__LINE__,__FILE__) + +#define reply_nterror(req,status) reply_nt_error(req,status,__LINE__,__FILE__) +#define reply_force_doserror(req,eclass,ecode) reply_force_dos_error(req,eclass,ecode,__LINE__,__FILE__) +#define reply_botherror(req,status,eclass,ecode) reply_both_error(req,eclass,ecode,status,__LINE__,__FILE__) + +#if 0 +/* defined in IDL */ +/* these are the datagram types */ +#define DGRAM_DIRECT_UNIQUE 0x10 +#endif + +#define SMB_ROUNDUP(x,r) ( ((x)%(r)) ? ( (((x)+(r))/(r))*(r) ) : (x)) + +/* Extra macros added by Ying Chen at IBM - speed increase by inlining. */ +#define smb_buf(buf) (((char *)(buf)) + smb_size + CVAL(buf,smb_wct)*2) +#define smb_buf_const(buf) (((const char *)(buf)) + smb_size + CVAL(buf,smb_wct)*2) +#define smb_buflen(buf) (SVAL(buf,smb_vwv0 + (int)CVAL(buf, smb_wct)*2)) + +/* the remaining number of bytes in smb buffer 'buf' from pointer 'p'. */ +#define smbreq_bufrem(req, p) ((req)->buflen < PTR_DIFF((p), (req)->buf) ? 0 : (req)->buflen - PTR_DIFF((p), (req)->buf)) + + +/* Note that chain_size must be available as an extern int to this macro. */ +#define smb_offset(p,buf) (PTR_DIFF(p,buf+4)) + +#define smb_len(buf) smb_len_nbt(buf) +#define _smb_setlen(buf, len) _smb_setlen_nbt(buf, len) +#define smb_setlen(buf, len) smb_setlen_nbt(buf, len) + +#define smb_len_large(buf) smb_len_tcp(buf) +#define _smb_setlen_large(buf, len) _smb_setlen_tcp(buf, len) + +#define ENCRYPTION_REQUIRED(conn) ((conn) ? ((conn)->encrypt_level == SMB_SIGNING_REQUIRED) : false) +#define IS_CONN_ENCRYPTED(conn) ((conn) ? (conn)->encrypted_tid : false) + +/**************************************************************************** + Return True if the offset is at zero. +****************************************************************************/ + +#define dptr_zero(buf) (IVAL(buf,1) == 0) + +/******************************************************************* +copy an IP address from one buffer to another +********************************************************************/ + +#define putip(dest,src) memcpy(dest,src,4) + +/******************************************************************* + Return True if a server has CIFS UNIX capabilities. +********************************************************************/ + +#define SERVER_HAS_UNIX_CIFS(c) (smb1cli_conn_capabilities(c->conn) & CAP_UNIX) + +/**************************************************************************** + Make a filename into unix format. +****************************************************************************/ + +#define IS_DIRECTORY_SEP(c) ((c) == '\\' || (c) == '/') +#define unix_format(fname) string_replace(fname,'\\','/') + +/**************************************************************************** + Make a file into DOS format. +****************************************************************************/ + +#define dos_format(fname) string_replace(fname,'/','\\') + +/***************************************************************************** + Check to see if we are a DC for this domain +*****************************************************************************/ + +#define IS_DC (lp_server_role()==ROLE_DOMAIN_PDC || lp_server_role()==ROLE_DOMAIN_BDC || lp_server_role() == ROLE_ACTIVE_DIRECTORY_DC || lp_server_role() == ROLE_IPA_DC) +#define IS_AD_DC (lp_server_role() == ROLE_ACTIVE_DIRECTORY_DC) + +/* + * If you add any entries to KERBEROS_VERIFY defines, please modify the below expressions + * so they remain accurate. + */ +#define USE_KERBEROS_KEYTAB (KERBEROS_VERIFY_SECRETS != lp_kerberos_method()) +#define USE_SYSTEM_KEYTAB \ + ((KERBEROS_VERIFY_SECRETS_AND_KEYTAB == lp_kerberos_method()) || \ + (KERBEROS_VERIFY_SYSTEM_KEYTAB == lp_kerberos_method())) + +/***************************************************************************** + Safe allocation macros. +*****************************************************************************/ + +#define SMB_MALLOC_ARRAY(type,count) (type *)malloc_array(sizeof(type),(count)) +#define SMB_MEMALIGN_ARRAY(type,align,count) (type *)memalign_array(sizeof(type),align,(count)) +#define SMB_REALLOC(p,s) Realloc((p),(s),True) /* Always frees p on error or s == 0 */ +#define SMB_REALLOC_ARRAY(p,type,count) (type *)realloc_array((p),sizeof(type),(count),True) /* Always frees p on error or s == 0 */ +#define SMB_CALLOC_ARRAY(type,count) (type *)calloc_array(sizeof(type),(count)) +#define SMB_XMALLOC_P(type) (type *)smb_xmalloc_array(sizeof(type),1) +#define SMB_XMALLOC_ARRAY(type,count) (type *)smb_xmalloc_array(sizeof(type),(count)) + +#define TALLOC(ctx, size) talloc_named_const(ctx, size, __location__) +#define TALLOC_SIZE(ctx, size) talloc_named_const(ctx, size, __location__) +#define TALLOC_REALLOC(ctx, ptr, count) _talloc_realloc(ctx, ptr, count, __location__) +#define talloc_destroy(ctx) talloc_free(ctx) +#ifndef TALLOC_FREE +#define TALLOC_FREE(ctx) do { talloc_free(ctx); ctx=NULL; } while(0) +#endif + +/* only define PARANOID_MALLOC_CHECKER with --enable-developer */ + +#if defined(DEVELOPER) +# define PARANOID_MALLOC_CHECKER 1 +#endif + +#if defined(PARANOID_MALLOC_CHECKER) + +/* Get medieval on our ass about malloc.... */ + +/* Restrictions on malloc/realloc/calloc. */ +#ifdef malloc +#undef malloc +#endif +#define malloc(s) __ERROR_DONT_USE_MALLOC_DIRECTLY + +#ifdef realloc +#undef realloc +#endif +#define realloc(p,s) __ERROR_DONT_USE_REALLOC_DIRECTLY + +#ifdef calloc +#undef calloc +#endif +#define calloc(n,s) __ERROR_DONT_USE_CALLOC_DIRECTLY + +#ifdef strndup +#undef strndup +#endif +#define strndup(s,n) __ERROR_DONT_USE_STRNDUP_DIRECTLY + +#ifdef strdup +#undef strdup +#endif +#define strdup(s) __ERROR_DONT_USE_STRDUP_DIRECTLY + +#define SMB_MALLOC(s) malloc_(s) +#define SMB_MALLOC_P(type) (type *)malloc_(sizeof(type)) + +#define SMB_STRDUP(s) smb_xstrdup(s) +#define SMB_STRNDUP(s,n) smb_xstrndup(s,n) + +#else + +/* Regular malloc code. */ + +#define SMB_MALLOC(s) malloc(s) +#define SMB_MALLOC_P(type) (type *)malloc(sizeof(type)) + +#define SMB_STRDUP(s) strdup(s) +#define SMB_STRNDUP(s,n) strndup(s,n) + +#endif + +#define ADD_TO_ARRAY(mem_ctx, type, elem, array, num) \ +do { \ + *(array) = ((mem_ctx) != NULL) ? \ + talloc_realloc(mem_ctx, (*(array)), type, (*(num))+1) : \ + SMB_REALLOC_ARRAY((*(array)), type, (*(num))+1); \ + SMB_ASSERT((*(array)) != NULL); \ + (*(array))[*(num)] = (elem); \ + (*(num)) += 1; \ +} while (0) + +#define ADD_TO_LARGE_ARRAY(mem_ctx, type, elem, array, num, size) \ + add_to_large_array((mem_ctx), sizeof(type), &(elem), (void *)(array), (num), (size)); + +#endif /* _SMB_MACROS_H */ diff --git a/source3/include/smb_perfcount.h b/source3/include/smb_perfcount.h new file mode 100644 index 0000000..efefb3c --- /dev/null +++ b/source3/include/smb_perfcount.h @@ -0,0 +1,105 @@ +/* + Unix SMB/CIFS implementation. + Portable SMB Messaging statistics interfaces + Copyright (C) Todd Stecher (2008) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _SMB_PERFCOUNT_H_ +#define _SMB_PERFCOUNT_H_ + +/* Change to 2, loadable modules now take a TALLOC_CTX * parameter. */ +#define SMB_PERFCOUNTER_INTERFACE_VERSION 2 + +struct smb_perfcount_data{ + struct smb_perfcount_handlers *handlers; + void *context; +}; + +struct smb_perfcount_handlers { + void (*perfcount_start) (struct smb_perfcount_data *pcd); + void (*perfcount_add) (struct smb_perfcount_data *pcd); + void (*perfcount_set_op) (struct smb_perfcount_data *pcd, int op); + void (*perfcount_set_subop) (struct smb_perfcount_data *pcd, int subop); + void (*perfcount_set_ioctl) (struct smb_perfcount_data *pcd, int io_ctl); + void (*perfcount_set_msglen_in) (struct smb_perfcount_data *pcd, + uint64_t in_bytes); + void (*perfcount_set_msglen_out) (struct smb_perfcount_data *pcd, + uint64_t out_bytes); + void (*perfcount_copy_context) (struct smb_perfcount_data *pcd, + struct smb_perfcount_data *new_pcd); + void (*perfcount_defer_op) (struct smb_perfcount_data *pcd, + struct smb_perfcount_data *def_pcd); + void (*perfcount_end) (struct smb_perfcount_data *pcd); +}; + +bool smb_perfcount_init(void); + +NTSTATUS smb_register_perfcounter(int interface_version, const char *name, + const struct smb_perfcount_handlers *handlers); + +void smb_init_perfcount_data(struct smb_perfcount_data *pcd); + +#define SMB_PERFCOUNT_START(_pcd_) \ + do {if((_pcd_) && (_pcd_)->handlers) \ + (_pcd_)->handlers->perfcount_start((_pcd_)); \ + } while (0) + +#define SMB_PERFCOUNT_ADD(_pcd_) \ + do {if((_pcd_) && (_pcd_)->handlers) \ + (_pcd_)->handlers->perfcount_add((_pcd_)); \ + } while (0) + +#define SMB_PERFCOUNT_SET_OP(_pcd_,_op_) \ + do {if((_pcd_) && (_pcd_)->handlers) \ + (_pcd_)->handlers->perfcount_set_op((_pcd_), (_op_)); \ + } while (0) + +#define SMB_PERFCOUNT_SET_SUBOP(_pcd_,_subop_) \ + do {if((_pcd_) && (_pcd_)->handlers) \ + (_pcd_)->handlers->perfcount_set_subop((_pcd_), (_subop_)); \ + } while (0) + +#define SMB_PERFCOUNT_SET_IOCTL(_pcd_,_subop_) \ + do {if((_pcd_) && (_pcd_)->handlers) \ + (_pcd_)->handlers->perfcount_set_ioctl((_pcd_), (_subop_)); \ + } while (0) + +#define SMB_PERFCOUNT_SET_MSGLEN_IN(_pcd_,_in_) \ + do {if((_pcd_) && (_pcd_)->handlers) \ + (_pcd_)->handlers->perfcount_set_msglen_in((_pcd_), (_in_));\ + } while (0) + +#define SMB_PERFCOUNT_SET_MSGLEN_OUT(_pcd_,_out_) \ + do {if((_pcd_) && (_pcd_)->handlers) \ + (_pcd_)->handlers->perfcount_set_msglen_out((_pcd_), (_out_));\ + } while (0) + +#define SMB_PERFCOUNT_COPY_CONTEXT(_pcd_, _new_pcd_) \ + do {if((_pcd_) && (_pcd_)->handlers) \ + (_pcd_)->handlers->perfcount_copy_context((_pcd_), (_new_pcd_)); \ + } while (0) + +#define SMB_PERFCOUNT_DEFER_OP(_pcd_, _def_pcd_) \ + do {if((_pcd_) && (_pcd_)->handlers) \ + (_pcd_)->handlers->perfcount_defer_op((_pcd_), (_def_pcd_)); \ + } while (0) + +#define SMB_PERFCOUNT_END(_pcd_) \ + do {if((_pcd_) && (_pcd_)->handlers) \ + (_pcd_)->handlers->perfcount_end((_pcd_));\ + } while (0) + +#endif /* _SMB_PERFCOUNT_H_ */ diff --git a/source3/include/smbldap.h b/source3/include/smbldap.h new file mode 100644 index 0000000..8820d14 --- /dev/null +++ b/source3/include/smbldap.h @@ -0,0 +1,121 @@ +/* + Unix SMB/CIFS Implementation. + LDAP protocol helper functions for SAMBA + Copyright (C) Gerald Carter 2001-2003 + + 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/>. + +*/ + +#ifndef _SMBLDAP_H +#define _SMBLDAP_H + +#include "include/smb_ldap.h" + +#ifdef HAVE_LDAP + +#include <talloc.h> +#include <tevent.h> + +/** + * Struct to keep the state for all the ldap stuff + * + */ + +struct smbldap_state; +typedef int (*smbldap_bind_callback_fn)(LDAP *ldap_struct, + struct smbldap_state *ldap_state, + void *data); + +/* The following definitions come from lib/smbldap.c */ + +NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx, + struct tevent_context *tevent_ctx, + const char *location, + bool anon, + const char *bind_dn, + const char *bind_secret, + struct smbldap_state **smbldap_state); + +LDAP *smbldap_get_ldap(struct smbldap_state *state); +bool smbldap_get_paged_results(struct smbldap_state *state); +void smbldap_set_paged_results(struct smbldap_state *state, + bool paged_results); + +void smbldap_set_bind_callback(struct smbldap_state *state, + smbldap_bind_callback_fn callback, + void *callback_data); + +void smbldap_set_mod (LDAPMod *** modlist, int modop, const char *attribute, const char *value); +void smbldap_set_mod_blob(LDAPMod *** modlist, int modop, const char *attribute, const DATA_BLOB *newblob); +void smbldap_make_mod(LDAP *ldap_struct, LDAPMessage *existing, + LDAPMod ***mods, + const char *attribute, const char *newval); +void smbldap_make_mod_blob(LDAP *ldap_struct, LDAPMessage *existing, + LDAPMod ***mods, + const char *attribute, const DATA_BLOB *newblob); +bool smbldap_get_single_attribute (LDAP * ldap_struct, LDAPMessage * entry, + const char *attribute, char *value, + int max_len); +int smbldap_modify(struct smbldap_state *ldap_state, + const char *dn, + LDAPMod *attrs[]); +int smbldap_start_tls(LDAP *ldap_struct, int version); +int smbldap_start_tls_start(LDAP *ldap_struct, int version); +int smbldap_setup_full_conn(LDAP **ldap_struct, const char *uri); +int smbldap_search(struct smbldap_state *ldap_state, + const char *base, int scope, const char *filter, + const char *attrs[], int attrsonly, + LDAPMessage **res); +int smbldap_search_paged(struct smbldap_state *ldap_state, + const char *base, int scope, const char *filter, + const char **attrs, int attrsonly, int pagesize, + LDAPMessage **res, void **cookie); +int smbldap_modify(struct smbldap_state *ldap_state, const char *dn, LDAPMod *attrs[]); +int smbldap_add(struct smbldap_state *ldap_state, const char *dn, LDAPMod *attrs[]); +int smbldap_delete(struct smbldap_state *ldap_state, const char *dn); +int smbldap_extended_operation(struct smbldap_state *ldap_state, + LDAP_CONST char *reqoid, struct berval *reqdata, + LDAPControl **serverctrls, LDAPControl **clientctrls, + char **retoidp, struct berval **retdatap); +int smbldap_search_suffix (struct smbldap_state *ldap_state, + const char *filter, const char **search_attr, + LDAPMessage ** result); +void smbldap_free_struct(struct smbldap_state **ldap_state) ; +bool smbldap_has_control(LDAP *ld, const char *control); +bool smbldap_has_extension(LDAP *ld, const char *extension); +bool smbldap_has_naming_context(LDAP *ld, const char *naming_context); +bool smbldap_set_creds(struct smbldap_state *ldap_state, bool anon, const char *dn, const char *secret); +char * smbldap_talloc_single_attribute(LDAP *ldap_struct, LDAPMessage *entry, + const char *attribute, + TALLOC_CTX *mem_ctx); +char * smbldap_talloc_first_attribute(LDAP *ldap_struct, LDAPMessage *entry, + const char *attribute, + TALLOC_CTX *mem_ctx); +char * smbldap_talloc_smallest_attribute(LDAP *ldap_struct, LDAPMessage *entry, + const char *attribute, + TALLOC_CTX *mem_ctx); +bool smbldap_talloc_single_blob(TALLOC_CTX *mem_ctx, LDAP *ld, + LDAPMessage *msg, const char *attrib, + DATA_BLOB *blob); +bool smbldap_pull_sid(LDAP *ld, LDAPMessage *msg, const char *attrib, + struct dom_sid *sid); +void smbldap_talloc_autofree_ldapmsg(TALLOC_CTX *mem_ctx, LDAPMessage *result); +void smbldap_talloc_autofree_ldapmod(TALLOC_CTX *mem_ctx, LDAPMod **mod); +char *smbldap_talloc_dn(TALLOC_CTX *mem_ctx, LDAP *ld, + LDAPMessage *entry); + +#endif /* HAVE_LDAP */ + +#endif /* _SMBLDAP_H */ diff --git a/source3/include/smbprofile.h b/source3/include/smbprofile.h new file mode 100644 index 0000000..ce7a740 --- /dev/null +++ b/source3/include/smbprofile.h @@ -0,0 +1,607 @@ +#ifndef _PROFILE_H_ +#define _PROFILE_H_ +/* + Unix SMB/CIFS implementation. + store smbd profiling information in shared memory + Copyright (C) Andrew Tridgell 1999 + Copyright (C) James Peach 2006 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + +*/ + +struct tevent_context; + +#ifdef WITH_PROFILE + +#define SMBPROFILE_STATS_ALL_SECTIONS \ + SMBPROFILE_STATS_START \ + \ + SMBPROFILE_STATS_SECTION_START(global, "SMBD loop") \ + SMBPROFILE_STATS_COUNT(connect) \ + SMBPROFILE_STATS_COUNT(disconnect) \ + SMBPROFILE_STATS_BASIC(idle) \ + SMBPROFILE_STATS_TIME(cpu_user) \ + SMBPROFILE_STATS_TIME(cpu_system) \ + SMBPROFILE_STATS_COUNT(request) \ + SMBPROFILE_STATS_BASIC(push_sec_ctx) \ + SMBPROFILE_STATS_BASIC(set_sec_ctx) \ + SMBPROFILE_STATS_BASIC(set_root_sec_ctx) \ + SMBPROFILE_STATS_BASIC(pop_sec_ctx) \ + SMBPROFILE_STATS_SECTION_END \ + \ + SMBPROFILE_STATS_SECTION_START(syscall, "System Calls") \ + SMBPROFILE_STATS_BASIC(syscall_opendir) \ + SMBPROFILE_STATS_BASIC(syscall_fdopendir) \ + SMBPROFILE_STATS_BASIC(syscall_readdir) \ + SMBPROFILE_STATS_BASIC(syscall_seekdir) \ + SMBPROFILE_STATS_BASIC(syscall_telldir) \ + SMBPROFILE_STATS_BASIC(syscall_rewinddir) \ + SMBPROFILE_STATS_BASIC(syscall_mkdirat) \ + SMBPROFILE_STATS_BASIC(syscall_closedir) \ + SMBPROFILE_STATS_BASIC(syscall_open) \ + SMBPROFILE_STATS_BASIC(syscall_openat) \ + SMBPROFILE_STATS_BASIC(syscall_createfile) \ + SMBPROFILE_STATS_BASIC(syscall_close) \ + SMBPROFILE_STATS_BYTES(syscall_pread) \ + SMBPROFILE_STATS_BYTES(syscall_asys_pread) \ + SMBPROFILE_STATS_BYTES(syscall_pwrite) \ + SMBPROFILE_STATS_BYTES(syscall_asys_pwrite) \ + SMBPROFILE_STATS_BASIC(syscall_lseek) \ + SMBPROFILE_STATS_BYTES(syscall_sendfile) \ + SMBPROFILE_STATS_BYTES(syscall_recvfile) \ + SMBPROFILE_STATS_BASIC(syscall_renameat) \ + SMBPROFILE_STATS_BYTES(syscall_asys_fsync) \ + SMBPROFILE_STATS_BASIC(syscall_stat) \ + SMBPROFILE_STATS_BASIC(syscall_fstat) \ + SMBPROFILE_STATS_BASIC(syscall_lstat) \ + SMBPROFILE_STATS_BASIC(syscall_fstatat) \ + SMBPROFILE_STATS_BASIC(syscall_get_alloc_size) \ + SMBPROFILE_STATS_BASIC(syscall_unlinkat) \ + SMBPROFILE_STATS_BASIC(syscall_chmod) \ + SMBPROFILE_STATS_BASIC(syscall_fchmod) \ + SMBPROFILE_STATS_BASIC(syscall_fchown) \ + SMBPROFILE_STATS_BASIC(syscall_lchown) \ + SMBPROFILE_STATS_BASIC(syscall_chdir) \ + SMBPROFILE_STATS_BASIC(syscall_getwd) \ + SMBPROFILE_STATS_BASIC(syscall_fntimes) \ + SMBPROFILE_STATS_BASIC(syscall_ftruncate) \ + SMBPROFILE_STATS_BASIC(syscall_fallocate) \ + SMBPROFILE_STATS_BASIC(syscall_fcntl_lock) \ + SMBPROFILE_STATS_BASIC(syscall_fcntl) \ + SMBPROFILE_STATS_BASIC(syscall_linux_setlease) \ + SMBPROFILE_STATS_BASIC(syscall_fcntl_getlock) \ + SMBPROFILE_STATS_BASIC(syscall_readlinkat) \ + SMBPROFILE_STATS_BASIC(syscall_symlinkat) \ + SMBPROFILE_STATS_BASIC(syscall_linkat) \ + SMBPROFILE_STATS_BASIC(syscall_mknodat) \ + SMBPROFILE_STATS_BASIC(syscall_realpath) \ + SMBPROFILE_STATS_BASIC(syscall_get_quota) \ + SMBPROFILE_STATS_BASIC(syscall_set_quota) \ + SMBPROFILE_STATS_BASIC(syscall_get_sd) \ + SMBPROFILE_STATS_BASIC(syscall_set_sd) \ + SMBPROFILE_STATS_BASIC(syscall_brl_lock) \ + SMBPROFILE_STATS_BASIC(syscall_brl_unlock) \ + SMBPROFILE_STATS_BASIC(syscall_brl_cancel) \ + SMBPROFILE_STATS_BYTES(syscall_asys_getxattrat) \ + SMBPROFILE_STATS_SECTION_END \ + \ + SMBPROFILE_STATS_SECTION_START(acl, "ACL Calls") \ + SMBPROFILE_STATS_BASIC(get_nt_acl) \ + SMBPROFILE_STATS_BASIC(get_nt_acl_at) \ + SMBPROFILE_STATS_BASIC(fget_nt_acl) \ + SMBPROFILE_STATS_BASIC(fset_nt_acl) \ + SMBPROFILE_STATS_SECTION_END \ + \ + SMBPROFILE_STATS_SECTION_START(statcache, "Stat Cache") \ + SMBPROFILE_STATS_COUNT(statcache_lookups) \ + SMBPROFILE_STATS_COUNT(statcache_misses) \ + SMBPROFILE_STATS_COUNT(statcache_hits) \ + SMBPROFILE_STATS_SECTION_END \ + \ + SMBPROFILE_STATS_SECTION_START(SMB, "SMB Calls") \ + SMBPROFILE_STATS_BASIC(SMBmkdir) \ + SMBPROFILE_STATS_BASIC(SMBrmdir) \ + SMBPROFILE_STATS_BASIC(SMBopen) \ + SMBPROFILE_STATS_BASIC(SMBcreate) \ + SMBPROFILE_STATS_BASIC(SMBclose) \ + SMBPROFILE_STATS_BASIC(SMBflush) \ + SMBPROFILE_STATS_BASIC(SMBunlink) \ + SMBPROFILE_STATS_BASIC(SMBmv) \ + SMBPROFILE_STATS_BASIC(SMBgetatr) \ + SMBPROFILE_STATS_BASIC(SMBsetatr) \ + SMBPROFILE_STATS_BASIC(SMBread) \ + SMBPROFILE_STATS_BASIC(SMBwrite) \ + SMBPROFILE_STATS_BASIC(SMBlock) \ + SMBPROFILE_STATS_BASIC(SMBunlock) \ + SMBPROFILE_STATS_BASIC(SMBctemp) \ + SMBPROFILE_STATS_BASIC(SMBmknew) \ + SMBPROFILE_STATS_BASIC(SMBcheckpath) \ + SMBPROFILE_STATS_BASIC(SMBexit) \ + SMBPROFILE_STATS_BASIC(SMBlseek) \ + SMBPROFILE_STATS_BASIC(SMBlockread) \ + SMBPROFILE_STATS_BASIC(SMBwriteunlock) \ + SMBPROFILE_STATS_BASIC(SMBreadbraw) \ + SMBPROFILE_STATS_BASIC(SMBreadBmpx) \ + SMBPROFILE_STATS_BASIC(SMBreadBs) \ + SMBPROFILE_STATS_BASIC(SMBwritebraw) \ + SMBPROFILE_STATS_BASIC(SMBwriteBmpx) \ + SMBPROFILE_STATS_BASIC(SMBwriteBs) \ + SMBPROFILE_STATS_BASIC(SMBwritec) \ + SMBPROFILE_STATS_BASIC(SMBsetattrE) \ + SMBPROFILE_STATS_BASIC(SMBgetattrE) \ + SMBPROFILE_STATS_BASIC(SMBlockingX) \ + SMBPROFILE_STATS_BASIC(SMBtrans) \ + SMBPROFILE_STATS_BASIC(SMBtranss) \ + SMBPROFILE_STATS_BASIC(SMBioctl) \ + SMBPROFILE_STATS_BASIC(SMBioctls) \ + SMBPROFILE_STATS_BASIC(SMBcopy) \ + SMBPROFILE_STATS_BASIC(SMBmove) \ + SMBPROFILE_STATS_BASIC(SMBecho) \ + SMBPROFILE_STATS_BASIC(SMBwriteclose) \ + SMBPROFILE_STATS_BASIC(SMBopenX) \ + SMBPROFILE_STATS_BASIC(SMBreadX) \ + SMBPROFILE_STATS_BASIC(SMBwriteX) \ + SMBPROFILE_STATS_BASIC(SMBtrans2) \ + SMBPROFILE_STATS_BASIC(SMBtranss2) \ + SMBPROFILE_STATS_BASIC(SMBfindclose) \ + SMBPROFILE_STATS_BASIC(SMBfindnclose) \ + SMBPROFILE_STATS_BASIC(SMBtcon) \ + SMBPROFILE_STATS_BASIC(SMBtdis) \ + SMBPROFILE_STATS_BASIC(SMBnegprot) \ + SMBPROFILE_STATS_BASIC(SMBsesssetupX) \ + SMBPROFILE_STATS_BASIC(SMBulogoffX) \ + SMBPROFILE_STATS_BASIC(SMBtconX) \ + SMBPROFILE_STATS_BASIC(SMBdskattr) \ + SMBPROFILE_STATS_BASIC(SMBsearch) \ + SMBPROFILE_STATS_BASIC(SMBffirst) \ + SMBPROFILE_STATS_BASIC(SMBfunique) \ + SMBPROFILE_STATS_BASIC(SMBfclose) \ + SMBPROFILE_STATS_BASIC(SMBnttrans) \ + SMBPROFILE_STATS_BASIC(SMBnttranss) \ + SMBPROFILE_STATS_BASIC(SMBntcreateX) \ + SMBPROFILE_STATS_BASIC(SMBntcancel) \ + SMBPROFILE_STATS_BASIC(SMBntrename) \ + SMBPROFILE_STATS_BASIC(SMBsplopen) \ + SMBPROFILE_STATS_BASIC(SMBsplwr) \ + SMBPROFILE_STATS_BASIC(SMBsplclose) \ + SMBPROFILE_STATS_BASIC(SMBsplretq) \ + SMBPROFILE_STATS_BASIC(SMBsends) \ + SMBPROFILE_STATS_BASIC(SMBsendb) \ + SMBPROFILE_STATS_BASIC(SMBfwdname) \ + SMBPROFILE_STATS_BASIC(SMBcancelf) \ + SMBPROFILE_STATS_BASIC(SMBgetmac) \ + SMBPROFILE_STATS_BASIC(SMBsendstrt) \ + SMBPROFILE_STATS_BASIC(SMBsendend) \ + SMBPROFILE_STATS_BASIC(SMBsendtxt) \ + SMBPROFILE_STATS_BASIC(SMBinvalid) \ + SMBPROFILE_STATS_SECTION_END \ + \ + SMBPROFILE_STATS_SECTION_START(Trans2, "Trans2 Calls") \ + SMBPROFILE_STATS_BASIC(Trans2_open) \ + SMBPROFILE_STATS_BASIC(Trans2_findfirst) \ + SMBPROFILE_STATS_BASIC(Trans2_findnext) \ + SMBPROFILE_STATS_BASIC(Trans2_qfsinfo) \ + SMBPROFILE_STATS_BASIC(Trans2_setfsinfo) \ + SMBPROFILE_STATS_BASIC(Trans2_qpathinfo) \ + SMBPROFILE_STATS_BASIC(Trans2_setpathinfo) \ + SMBPROFILE_STATS_BASIC(Trans2_qfileinfo) \ + SMBPROFILE_STATS_BASIC(Trans2_setfileinfo) \ + SMBPROFILE_STATS_BASIC(Trans2_fsctl) \ + SMBPROFILE_STATS_BASIC(Trans2_ioctl) \ + SMBPROFILE_STATS_BASIC(Trans2_findnotifyfirst) \ + SMBPROFILE_STATS_BASIC(Trans2_findnotifynext) \ + SMBPROFILE_STATS_BASIC(Trans2_mkdir) \ + SMBPROFILE_STATS_BASIC(Trans2_session_setup) \ + SMBPROFILE_STATS_BASIC(Trans2_get_dfs_referral) \ + SMBPROFILE_STATS_BASIC(Trans2_report_dfs_inconsistancy) \ + SMBPROFILE_STATS_SECTION_END \ + \ + SMBPROFILE_STATS_SECTION_START(NT_transact, "NT Transact Calls") \ + SMBPROFILE_STATS_BASIC(NT_transact_create) \ + SMBPROFILE_STATS_BASIC(NT_transact_ioctl) \ + SMBPROFILE_STATS_BASIC(NT_transact_set_security_desc) \ + SMBPROFILE_STATS_BASIC(NT_transact_notify_change) \ + SMBPROFILE_STATS_BASIC(NT_transact_rename) \ + SMBPROFILE_STATS_BASIC(NT_transact_query_security_desc) \ + SMBPROFILE_STATS_BASIC(NT_transact_get_user_quota) \ + SMBPROFILE_STATS_BASIC(NT_transact_set_user_quota) \ + SMBPROFILE_STATS_SECTION_END \ + \ + SMBPROFILE_STATS_SECTION_START(smb2, "SMB2 Calls") \ + SMBPROFILE_STATS_IOBYTES(smb2_negprot) \ + SMBPROFILE_STATS_IOBYTES(smb2_sesssetup) \ + SMBPROFILE_STATS_IOBYTES(smb2_logoff) \ + SMBPROFILE_STATS_IOBYTES(smb2_tcon) \ + SMBPROFILE_STATS_IOBYTES(smb2_tdis) \ + SMBPROFILE_STATS_IOBYTES(smb2_create) \ + SMBPROFILE_STATS_IOBYTES(smb2_close) \ + SMBPROFILE_STATS_IOBYTES(smb2_flush) \ + SMBPROFILE_STATS_IOBYTES(smb2_read) \ + SMBPROFILE_STATS_IOBYTES(smb2_write) \ + SMBPROFILE_STATS_IOBYTES(smb2_lock) \ + SMBPROFILE_STATS_IOBYTES(smb2_ioctl) \ + SMBPROFILE_STATS_IOBYTES(smb2_cancel) \ + SMBPROFILE_STATS_IOBYTES(smb2_keepalive) \ + SMBPROFILE_STATS_IOBYTES(smb2_find) \ + SMBPROFILE_STATS_IOBYTES(smb2_notify) \ + SMBPROFILE_STATS_IOBYTES(smb2_getinfo) \ + SMBPROFILE_STATS_IOBYTES(smb2_setinfo) \ + SMBPROFILE_STATS_IOBYTES(smb2_break) \ + SMBPROFILE_STATS_SECTION_END \ + \ + SMBPROFILE_STATS_END + +/* this file defines the profile structure in the profile shared + memory area */ + +/* time values in the following structure are in microseconds */ + +struct smbprofile_stats_count { + uint64_t count; /* number of events */ +}; + +struct smbprofile_stats_time { + uint64_t time; /* microseconds */ +}; + +struct smbprofile_stats_time_async { + uint64_t start; + struct smbprofile_stats_time *stats; +}; + +struct smbprofile_stats_basic { + uint64_t count; /* number of events */ + uint64_t time; /* microseconds */ +}; + +struct smbprofile_stats_basic_async { + uint64_t start; + struct smbprofile_stats_basic *stats; +}; + +struct smbprofile_stats_bytes { + uint64_t count; /* number of events */ + uint64_t time; /* microseconds */ + uint64_t idle; /* idle time compared to 'time' microseconds */ + uint64_t bytes; /* bytes */ +}; + +struct smbprofile_stats_bytes_async { + uint64_t start; + uint64_t idle_start; + uint64_t idle_time; + struct smbprofile_stats_bytes *stats; +}; + +struct smbprofile_stats_iobytes { + uint64_t count; /* number of events */ + uint64_t time; /* microseconds */ + uint64_t idle; /* idle time compared to 'time' microseconds */ + uint64_t inbytes; /* bytes read */ + uint64_t outbytes; /* bytes written */ +}; + +struct smbprofile_stats_iobytes_async { + uint64_t start; + uint64_t idle_start; + uint64_t idle_time; + struct smbprofile_stats_iobytes *stats; +}; + +struct profile_stats { + uint64_t magic; + struct { +#define SMBPROFILE_STATS_START +#define SMBPROFILE_STATS_SECTION_START(name, display) +#define SMBPROFILE_STATS_COUNT(name) \ + struct smbprofile_stats_count name##_stats; +#define SMBPROFILE_STATS_TIME(name) \ + struct smbprofile_stats_time name##_stats; +#define SMBPROFILE_STATS_BASIC(name) \ + struct smbprofile_stats_basic name##_stats; +#define SMBPROFILE_STATS_BYTES(name) \ + struct smbprofile_stats_bytes name##_stats; +#define SMBPROFILE_STATS_IOBYTES(name) \ + struct smbprofile_stats_iobytes name##_stats; +#define SMBPROFILE_STATS_SECTION_END +#define SMBPROFILE_STATS_END + SMBPROFILE_STATS_ALL_SECTIONS +#undef SMBPROFILE_STATS_START +#undef SMBPROFILE_STATS_SECTION_START +#undef SMBPROFILE_STATS_COUNT +#undef SMBPROFILE_STATS_TIME +#undef SMBPROFILE_STATS_BASIC +#undef SMBPROFILE_STATS_BYTES +#undef SMBPROFILE_STATS_IOBYTES +#undef SMBPROFILE_STATS_SECTION_END +#undef SMBPROFILE_STATS_END + } values; +}; + +#define _SMBPROFILE_COUNT_INCREMENT(_stats, _area, _v) do { \ + if (smbprofile_state.config.do_count) { \ + (_area)->values._stats.count += (_v); \ + smbprofile_dump_schedule(); \ + } \ +} while(0) +#define SMBPROFILE_COUNT_INCREMENT(_name, _area, _v) \ + _SMBPROFILE_COUNT_INCREMENT(_name##_stats, _area, _v) + +#define SMBPROFILE_TIME_ASYNC_STATE(_async_name) \ + struct smbprofile_stats_time_async _async_name; +#define _SMBPROFILE_TIME_ASYNC_START(_stats, _area, _async) do { \ + (_async) = (struct smbprofile_stats_time_async) {}; \ + if (smbprofile_state.config.do_times) { \ + (_async).stats = &((_area)->values._stats), \ + (_async).start = profile_timestamp(); \ + } \ +} while(0) +#define SMBPROFILE_TIME_ASYNC_START(_name, _area, _async) \ + _SMBPROFILE_TIME_ASYNC_START(_name##_stats, _area, _async) +#define SMBPROFILE_TIME_ASYNC_END(_async) do { \ + if ((_async).start != 0) { \ + (_async).stats->time += profile_timestamp() - (_async).start; \ + (_async) = (struct smbprofile_stats_basic_async) {}; \ + smbprofile_dump_schedule(); \ + } \ +} while(0) + +#define SMBPROFILE_BASIC_ASYNC_STATE(_async_name) \ + struct smbprofile_stats_basic_async _async_name; +#define _SMBPROFILE_BASIC_ASYNC_START(_stats, _area, _async) do { \ + (_async) = (struct smbprofile_stats_basic_async) {}; \ + if (smbprofile_state.config.do_count) { \ + if (smbprofile_state.config.do_times) { \ + (_async).start = profile_timestamp(); \ + (_async).stats = &((_area)->values._stats); \ + } \ + (_area)->values._stats.count += 1; \ + smbprofile_dump_schedule(); \ + } \ +} while(0) +#define SMBPROFILE_BASIC_ASYNC_START(_name, _area, _async) \ + _SMBPROFILE_BASIC_ASYNC_START(_name##_stats, _area, _async) +#define SMBPROFILE_BASIC_ASYNC_END(_async) do { \ + if ((_async).start != 0) { \ + (_async).stats->time += profile_timestamp() - (_async).start; \ + (_async) = (struct smbprofile_stats_basic_async) {}; \ + smbprofile_dump_schedule(); \ + } \ +} while(0) + +#define _SMBPROFILE_TIMER_ASYNC_START(_stats, _area, _async) do { \ + (_async).stats = &((_area)->values._stats); \ + if (smbprofile_state.config.do_times) { \ + (_async).start = profile_timestamp(); \ + } \ +} while(0) +#define _SMBPROFILE_TIMER_ASYNC_SET_IDLE(_async) do { \ + if ((_async).start != 0) { \ + if ((_async).idle_start == 0) { \ + (_async).idle_start = profile_timestamp(); \ + } \ + } \ +} while(0) +#define _SMBPROFILE_TIMER_ASYNC_SET_BUSY(_async) do { \ + if ((_async).idle_start != 0) { \ + (_async).idle_time += \ + profile_timestamp() - (_async).idle_start; \ + (_async).idle_start = 0; \ + } \ +} while(0) +#define _SMBPROFILE_TIMER_ASYNC_END(_async) do { \ + if ((_async).start != 0) { \ + _SMBPROFILE_TIMER_ASYNC_SET_BUSY(_async); \ + (_async).stats->time += profile_timestamp() - (_async).start; \ + (_async).stats->idle += (_async).idle_time; \ + } \ +} while(0) + +#define SMBPROFILE_BYTES_ASYNC_STATE(_async_name) \ + struct smbprofile_stats_bytes_async _async_name; +#define _SMBPROFILE_BYTES_ASYNC_START(_stats, _area, _async, _bytes) do { \ + (_async) = (struct smbprofile_stats_bytes_async) {}; \ + if (smbprofile_state.config.do_count) { \ + _SMBPROFILE_TIMER_ASYNC_START(_stats, _area, _async); \ + (_area)->values._stats.count += 1; \ + (_area)->values._stats.bytes += (_bytes); \ + smbprofile_dump_schedule(); \ + } \ +} while(0) +#define SMBPROFILE_BYTES_ASYNC_START(_name, _area, _async, _bytes) \ + _SMBPROFILE_BYTES_ASYNC_START(_name##_stats, _area, _async, _bytes) +#define SMBPROFILE_BYTES_ASYNC_SET_IDLE(_async) \ + _SMBPROFILE_TIMER_ASYNC_SET_IDLE(_async) +#define SMBPROFILE_BYTES_ASYNC_SET_BUSY(_async) \ + _SMBPROFILE_TIMER_ASYNC_SET_BUSY(_async) +#define SMBPROFILE_BYTES_ASYNC_END(_async) do { \ + if ((_async).stats != NULL) { \ + _SMBPROFILE_TIMER_ASYNC_END(_async); \ + (_async) = (struct smbprofile_stats_bytes_async) {}; \ + smbprofile_dump_schedule(); \ + } \ +} while(0) + +#define SMBPROFILE_IOBYTES_ASYNC_STATE(_async_name) \ + struct smbprofile_stats_iobytes_async _async_name; +#define _SMBPROFILE_IOBYTES_ASYNC_START(_stats, _area, _async, _inbytes) do { \ + (_async) = (struct smbprofile_stats_iobytes_async) {}; \ + if (smbprofile_state.config.do_count) { \ + _SMBPROFILE_TIMER_ASYNC_START(_stats, _area, _async); \ + (_area)->values._stats.count += 1; \ + (_area)->values._stats.inbytes += (_inbytes); \ + smbprofile_dump_schedule(); \ + } \ +} while(0) +#define SMBPROFILE_IOBYTES_ASYNC_START(_name, _area, _async, _inbytes) \ + _SMBPROFILE_IOBYTES_ASYNC_START(_name##_stats, _area, _async, _inbytes) +#define SMBPROFILE_IOBYTES_ASYNC_SET_IDLE(_async) \ + _SMBPROFILE_TIMER_ASYNC_SET_IDLE(_async) +#define SMBPROFILE_IOBYTES_ASYNC_SET_BUSY(_async) \ + _SMBPROFILE_TIMER_ASYNC_SET_BUSY(_async) +#define SMBPROFILE_IOBYTES_ASYNC_END(_async, _outbytes) do { \ + if ((_async).stats != NULL) { \ + (_async).stats->outbytes += (_outbytes); \ + _SMBPROFILE_TIMER_ASYNC_END(_async); \ + (_async) = (struct smbprofile_stats_iobytes_async) {}; \ + smbprofile_dump_schedule(); \ + } \ +} while(0) + +extern struct profile_stats *profile_p; + +struct smbprofile_global_state { + struct { + struct tdb_wrap *db; + struct tevent_context *ev; + struct tevent_timer *te; + } internal; + + struct { + bool do_count; + bool do_times; + } config; + + struct { + struct profile_stats global; + } stats; +}; + +extern struct smbprofile_global_state smbprofile_state; + +void smbprofile_dump_schedule_timer(void); +void smbprofile_dump_setup(struct tevent_context *ev); + +static inline void smbprofile_dump_schedule(void) +{ + if (likely(smbprofile_state.internal.te != NULL)) { + return; + } + + if (unlikely(smbprofile_state.internal.ev == NULL)) { + return; + } + + smbprofile_dump_schedule_timer(); +} + +static inline bool smbprofile_dump_pending(void) +{ + if (smbprofile_state.internal.te == NULL) { + return false; + } + + return true; +} + +void smbprofile_dump(void); + +void smbprofile_cleanup(pid_t pid, pid_t dst); +void smbprofile_stats_accumulate(struct profile_stats *acc, + const struct profile_stats *add); +void smbprofile_collect(struct profile_stats *stats); + +static inline uint64_t profile_timestamp(void) +{ + struct timespec ts; + + /* we might prefer to use the _COARSE clock variant of CLOCK_MONOTONIC + that one is faster but cached and "just" tick-wise precise */ + clock_gettime_mono(&ts); + return (ts.tv_sec * 1000000) + (ts.tv_nsec / 1000); /* usec */ +} + +#define DO_PROFILE_INC(x) \ + _SMBPROFILE_COUNT_INCREMENT(x##_stats, profile_p, 1); \ + +#define START_PROFILE(x) \ + struct smbprofile_stats_basic_async __profasync_##x = {}; \ + _SMBPROFILE_BASIC_ASYNC_START(x##_stats, profile_p, __profasync_##x); + +#define START_PROFILE_BYTES(x,n) \ + struct smbprofile_stats_bytes_async __profasync_##x = {}; \ + _SMBPROFILE_BYTES_ASYNC_START(x##_stats, profile_p, __profasync_##x, n); + +#define END_PROFILE(x) \ + SMBPROFILE_BASIC_ASYNC_END(__profasync_##x) + +#define END_PROFILE_BYTES(x) \ + SMBPROFILE_BYTES_ASYNC_END(__profasync_##x) + +#define PROFILE_TIMESTAMP(x) clock_gettime_mono(x) + +#else /* WITH_PROFILE */ + +#define SMBPROFILE_COUNT_INCREMENT(_name, _area, _v) + +#define SMBPROFILE_TIME_ASYNC_STATE(_async_name) +#define SMBPROFILE_TIME_ASYNC_START(_name, _area, _async) +#define SMBPROFILE_TIME_ASYNC_END(_async) + +#define SMBPROFILE_BASIC_ASYNC_STATE(_async_name) +#define SMBPROFILE_BASIC_ASYNC_START(_name, _area, _async) +#define SMBPROFILE_BASIC_ASYNC_END(_async) + +#define SMBPROFILE_BYTES_ASYNC_STATE(_async_name) +#define SMBPROFILE_BYTES_ASYNC_START(_name, _area, _async, _inbytes) +#define SMBPROFILE_BYTES_ASYNC_SET_IDLE(_async) +#define SMBPROFILE_BYTES_ASYNC_SET_BUSY(_async) +#define SMBPROFILE_BYTES_ASYNC_END(_async) + +#define SMBPROFILE_IOBYTES_ASYNC_STATE(_async_name) +#define SMBPROFILE_IOBYTES_ASYNC_START(_name, _area, _async, _inbytes) +#define SMBPROFILE_IOBYTES_ASYNC_SET_IDLE(_async) +#define SMBPROFILE_IOBYTES_ASYNC_SET_BUSY(_async) +#define SMBPROFILE_IOBYTES_ASYNC_END(_async, _outbytes) + +#define DO_PROFILE_INC(x) +#define START_PROFILE(x) +#define START_PROFILE_BYTES(x,n) +#define END_PROFILE(x) +#define END_PROFILE_BYTES(x) + +#define PROFILE_TIMESTAMP(x) (*(x)=(struct timespec){0}) + +static inline bool smbprofile_dump_pending(void) +{ + return false; +} + +static inline void smbprofile_dump_setup(struct tevent_context *ev) +{ + return; +} + +static inline void smbprofile_dump(void) +{ + return; +} + +static inline void smbprofile_cleanup(pid_t pid, pid_t dst) +{ + return; +} + +#endif /* WITH_PROFILE */ + +/* The following definitions come from profile/profile.c */ +struct server_id; + +void set_profile_level(int level, const struct server_id *src); + +struct messaging_context; +bool profile_setup(struct messaging_context *msg_ctx, bool rdonly); + +#endif diff --git a/source3/include/srvstr.h b/source3/include/srvstr.h new file mode 100644 index 0000000..2c6e7ef --- /dev/null +++ b/source3/include/srvstr.h @@ -0,0 +1,21 @@ +/* + Unix SMB/CIFS implementation. + server specific string routines + Copyright (C) Andrew Tridgell 2001 + + 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/>. +*/ + +#define srvstr_pull_talloc(ctx, base_ptr, smb_flags2, dest, src, src_len, flags) \ + pull_string_talloc(ctx, base_ptr, smb_flags2, dest, src, src_len, flags) diff --git a/source3/include/stamp-h.in b/source3/include/stamp-h.in new file mode 100644 index 0000000..c9061b3 --- /dev/null +++ b/source3/include/stamp-h.in @@ -0,0 +1 @@ +Sun Jul 18 20:32:29 UTC 1999 diff --git a/source3/include/sysquotas.h b/source3/include/sysquotas.h new file mode 100644 index 0000000..7ba631e --- /dev/null +++ b/source3/include/sysquotas.h @@ -0,0 +1,85 @@ +/* + Unix SMB/CIFS implementation. + SYS QUOTA code constants + Copyright (C) Stefan (metze) Metzmacher 2003 + + 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/>. +*/ + +#ifndef _SYSQUOTAS_H +#define _SYSQUOTAS_H + +#ifdef HAVE_SYS_QUOTAS + +#if defined(HAVE_MNTENT_H)&&defined(HAVE_SETMNTENT)&&defined(HAVE_GETMNTENT)&&defined(HAVE_ENDMNTENT) +#include <mntent.h> +#define HAVE_MNTENT 1 +/*#endif defined(HAVE_MNTENT_H)&&defined(HAVE_SETMNTENT)&&defined(HAVE_GETMNTENT)&&defined(HAVE_ENDMNTENT) */ +#elif defined(HAVE_DEVNM_H)&&defined(HAVE_DEVNM) +#include <devnm.h> +#endif /* defined(HAVE_DEVNM_H)&&defined(HAVE_DEVNM) */ + +#endif /* HAVE_SYS_QUOTAS */ + + +/************************************************** + Some stuff for the sys_quota api. + **************************************************/ + +#define SMB_QUOTAS_NO_LIMIT ((uint64_t)(0)) +#define SMB_QUOTAS_NO_SPACE ((uint64_t)(1)) + +#define SMB_QUOTAS_SET_NO_LIMIT(dp) \ +{\ + (dp)->softlimit = SMB_QUOTAS_NO_LIMIT;\ + (dp)->hardlimit = SMB_QUOTAS_NO_LIMIT;\ + (dp)->isoftlimit = SMB_QUOTAS_NO_LIMIT;\ + (dp)->ihardlimit = SMB_QUOTAS_NO_LIMIT;\ +} + +#define SMB_QUOTAS_SET_NO_SPACE(dp) \ +{\ + (dp)->softlimit = SMB_QUOTAS_NO_SPACE;\ + (dp)->hardlimit = SMB_QUOTAS_NO_SPACE;\ + (dp)->isoftlimit = SMB_QUOTAS_NO_SPACE;\ + (dp)->ihardlimit = SMB_QUOTAS_NO_SPACE;\ +} + +typedef struct _SMB_DISK_QUOTA { + enum SMB_QUOTA_TYPE qtype; + uint64_t bsize; + uint64_t hardlimit; /* In bsize units. */ + uint64_t softlimit; /* In bsize units. */ + uint64_t curblocks; /* In bsize units. */ + uint64_t ihardlimit; /* inode hard limit. */ + uint64_t isoftlimit; /* inode soft limit. */ + uint64_t curinodes; /* Current used inodes. */ + uint32_t qflags; +} SMB_DISK_QUOTA; + +#ifndef QUOTABLOCK_SIZE +#if defined(DQBSIZE) /* AIX */ +#define QUOTABLOCK_SIZE DQBSIZE +#elif defined(QIF_DQBLKSIZE) /* Linux */ +#define QUOTABLOCK_SIZE QIF_DQBLKSIZE +#elif defined(HAVE_STRUCT_DQBLK_DQB_CURBYTES) /*Darwin */ +#define QUOTABLOCK_SIZE 1 +#elif defined(HAVE_UFS_UFS_QUOTA_H) /* BSDs */ +#define QUOTABLOCK_SIZE 512 +#else +#define QUOTABLOCK_SIZE 1024 +#endif +#endif /* QUOTABLOCK_SIZE */ + +#endif /*_SYSQUOTAS_H */ diff --git a/source3/include/tldap.h b/source3/include/tldap.h new file mode 100644 index 0000000..23e3f1b --- /dev/null +++ b/source3/include/tldap.h @@ -0,0 +1,315 @@ +/* + Unix SMB/CIFS implementation. + Infrastructure for async ldap client requests + Copyright (C) Volker Lendecke 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/>. +*/ + +#ifndef __TLDAP_H__ +#define __TLDAP_H__ + +#include "replace.h" +#include <talloc.h> +#include <tevent.h> +#include "lib/util/data_blob.h" + +struct tldap_context; +struct tldap_message; + +struct tldap_control { + const char *oid; + DATA_BLOB value; + bool critical; +}; + +struct tldap_attribute { + char *name; + int num_values; + DATA_BLOB *values; +}; + +struct tldap_mod { + int mod_op; + char *attribute; + int num_values; + DATA_BLOB *values; +}; + +#if defined(HAVE_IMMEDIATE_STRUCTURES) +typedef struct { uint8_t rc; } TLDAPRC; +#define TLDAP_RC(x) ((TLDAPRC){.rc = x}) +#define TLDAP_RC_V(x) ((x).rc) +#else +typedef uint8_t TLDAPRC; +#define TLDAP_RC(x) (x) +#define TLDAP_RC_V(x) (x) +#endif + +#define TLDAP_RC_EQUAL(x,y) (TLDAP_RC_V(x)==TLDAP_RC_V(y)) +#define TLDAP_RC_IS_SUCCESS(x) TLDAP_RC_EQUAL(x,TLDAP_SUCCESS) + +#define TLDAP_SUCCESS TLDAP_RC(0x00) +#define TLDAP_OPERATIONS_ERROR TLDAP_RC(0x01) +#define TLDAP_PROTOCOL_ERROR TLDAP_RC(0x02) +#define TLDAP_TIMELIMIT_EXCEEDED TLDAP_RC(0x03) +#define TLDAP_SIZELIMIT_EXCEEDED TLDAP_RC(0x04) +#define TLDAP_COMPARE_FALSE TLDAP_RC(0x05) +#define TLDAP_COMPARE_TRUE TLDAP_RC(0x06) +#define TLDAP_STRONG_AUTH_NOT_SUPPORTED TLDAP_RC(0x07) +#define TLDAP_STRONG_AUTH_REQUIRED TLDAP_RC(0x08) +#define TLDAP_REFERRAL TLDAP_RC(0x0a) +#define TLDAP_ADMINLIMIT_EXCEEDED TLDAP_RC(0x0b) +#define TLDAP_UNAVAILABLE_CRITICAL_EXTENSION TLDAP_RC(0x0c) +#define TLDAP_CONFIDENTIALITY_REQUIRED TLDAP_RC(0x0d) +#define TLDAP_SASL_BIND_IN_PROGRESS TLDAP_RC(0x0e) +#define TLDAP_NO_SUCH_ATTRIBUTE TLDAP_RC(0x10) +#define TLDAP_UNDEFINED_TYPE TLDAP_RC(0x11) +#define TLDAP_INAPPROPRIATE_MATCHING TLDAP_RC(0x12) +#define TLDAP_CONSTRAINT_VIOLATION TLDAP_RC(0x13) +#define TLDAP_TYPE_OR_VALUE_EXISTS TLDAP_RC(0x14) +#define TLDAP_INVALID_SYNTAX TLDAP_RC(0x15) +#define TLDAP_NO_SUCH_OBJECT TLDAP_RC(0x20) +#define TLDAP_ALIAS_PROBLEM TLDAP_RC(0x21) +#define TLDAP_INVALID_DN_SYNTAX TLDAP_RC(0x22) +#define TLDAP_IS_LEAF TLDAP_RC(0x23) +#define TLDAP_ALIAS_DEREF_PROBLEM TLDAP_RC(0x24) +#define TLDAP_INAPPROPRIATE_AUTH TLDAP_RC(0x30) +#define TLDAP_INVALID_CREDENTIALS TLDAP_RC(0x31) +#define TLDAP_INSUFFICIENT_ACCESS TLDAP_RC(0x32) +#define TLDAP_BUSY TLDAP_RC(0x33) +#define TLDAP_UNAVAILABLE TLDAP_RC(0x34) +#define TLDAP_UNWILLING_TO_PERFORM TLDAP_RC(0x35) +#define TLDAP_LOOP_DETECT TLDAP_RC(0x36) +#define TLDAP_NAMING_VIOLATION TLDAP_RC(0x40) +#define TLDAP_OBJECT_CLASS_VIOLATION TLDAP_RC(0x41) +#define TLDAP_NOT_ALLOWED_ON_NONLEAF TLDAP_RC(0x42) +#define TLDAP_NOT_ALLOWED_ON_RDN TLDAP_RC(0x43) +#define TLDAP_ALREADY_EXISTS TLDAP_RC(0x44) +#define TLDAP_NO_OBJECT_CLASS_MODS TLDAP_RC(0x45) +#define TLDAP_RESULTS_TOO_LARGE TLDAP_RC(0x46) +#define TLDAP_AFFECTS_MULTIPLE_DSAS TLDAP_RC(0x47) +#define TLDAP_OTHER TLDAP_RC(0x50) +#define TLDAP_SERVER_DOWN TLDAP_RC(0x51) +#define TLDAP_LOCAL_ERROR TLDAP_RC(0x52) +#define TLDAP_ENCODING_ERROR TLDAP_RC(0x53) +#define TLDAP_DECODING_ERROR TLDAP_RC(0x54) +#define TLDAP_TIMEOUT TLDAP_RC(0x55) +#define TLDAP_AUTH_UNKNOWN TLDAP_RC(0x56) +#define TLDAP_FILTER_ERROR TLDAP_RC(0x57) +#define TLDAP_USER_CANCELLED TLDAP_RC(0x58) +#define TLDAP_PARAM_ERROR TLDAP_RC(0x59) +#define TLDAP_NO_MEMORY TLDAP_RC(0x5a) +#define TLDAP_CONNECT_ERROR TLDAP_RC(0x5b) +#define TLDAP_NOT_SUPPORTED TLDAP_RC(0x5c) +#define TLDAP_CONTROL_NOT_FOUND TLDAP_RC(0x5d) +#define TLDAP_NO_RESULTS_RETURNED TLDAP_RC(0x5e) +#define TLDAP_MORE_RESULTS_TO_RETURN TLDAP_RC(0x5f) +#define TLDAP_CLIENT_LOOP TLDAP_RC(0x60) +#define TLDAP_REFERRAL_LIMIT_EXCEEDED TLDAP_RC(0x61) + +bool tevent_req_ldap_error(struct tevent_req *req, TLDAPRC rc); +bool tevent_req_is_ldap_error(struct tevent_req *req, TLDAPRC *perr); + +struct tldap_context *tldap_context_create(TALLOC_CTX *mem_ctx, int fd); +struct tstream_context *tldap_get_tstream(struct tldap_context *ld); +void tldap_set_tstream(struct tldap_context *ld, + struct tstream_context *stream); + +bool tldap_connection_ok(struct tldap_context *ld); +bool tldap_context_setattr(struct tldap_context *ld, + const char *name, const void *pptr); +void *tldap_context_getattr(struct tldap_context *ld, const char *name); + +struct tevent_req *tldap_sasl_bind_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct tldap_context *ld, + const char *dn, + const char *mechanism, + DATA_BLOB *creds, + struct tldap_control *sctrls, + int num_sctrls, + struct tldap_control *cctrls, + int num_cctrls); +TLDAPRC tldap_sasl_bind_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, + DATA_BLOB *serverSaslCreds); +TLDAPRC tldap_sasl_bind(struct tldap_context *ldap, + const char *dn, + const char *mechanism, + DATA_BLOB *creds, + struct tldap_control *sctrls, + int num_sctrls, + struct tldap_control *cctrls, + int num_cctrls, + TALLOC_CTX *mem_ctx, + DATA_BLOB *serverSaslCreds); + +struct tevent_req *tldap_simple_bind_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct tldap_context *ldap, + const char *dn, + const char *passwd); +TLDAPRC tldap_simple_bind_recv(struct tevent_req *req); +TLDAPRC tldap_simple_bind(struct tldap_context *ldap, const char *dn, + const char *passwd); + +struct tevent_req *tldap_search_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct tldap_context *ld, + const char *base, int scope, + const char *filter, + const char **attrs, + int num_attrs, + int attrsonly, + struct tldap_control *sctrls, + int num_sctrls, + struct tldap_control *cctrls, + int num_cctrls, + int timelimit, + int sizelimit, + int deref); +TLDAPRC tldap_search_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, + struct tldap_message **pmsg); + +struct tevent_req *tldap_search_all_send( + TALLOC_CTX *mem_ctx, struct tevent_context *ev, + struct tldap_context *ld, const char *base, int scope, + const char *filter, const char **attrs, int num_attrs, int attrsonly, + struct tldap_control *sctrls, int num_sctrls, + struct tldap_control *cctrls, int num_cctrls, + int timelimit, int sizelimit, int deref); +TLDAPRC tldap_search_all_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, + struct tldap_message ***msgs, + struct tldap_message **result); + +TLDAPRC tldap_search(struct tldap_context *ld, + const char *base, int scope, const char *filter, + const char **attrs, int num_attrs, int attrsonly, + struct tldap_control *sctrls, int num_sctrls, + struct tldap_control *cctrls, int num_cctrls, + int timelimit, int sizelimit, int deref, + TALLOC_CTX *mem_ctx, struct tldap_message ***pmsgs); + +bool tldap_entry_dn(struct tldap_message *msg, char **dn); +bool tldap_entry_attributes(struct tldap_message *msg, + struct tldap_attribute **attributes, + int *num_attributes); + +struct tevent_req *tldap_add_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct tldap_context *ld, + const char *dn, + struct tldap_mod *attributes, + int num_attributes, + struct tldap_control *sctrls, + int num_sctrls, + struct tldap_control *cctrls, + int num_cctrls); +TLDAPRC tldap_add_recv(struct tevent_req *req); +TLDAPRC tldap_add(struct tldap_context *ld, const char *dn, + struct tldap_mod *attributes, int num_attributes, + struct tldap_control *sctrls, int num_sctrls, + struct tldap_control *cctrls, int num_cctrls); + +struct tevent_req *tldap_modify_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct tldap_context *ld, + const char *dn, + struct tldap_mod *mods, int num_mods, + struct tldap_control *sctrls, + int num_sctrls, + struct tldap_control *cctrls, + int num_cctrls); +TLDAPRC tldap_modify_recv(struct tevent_req *req); +TLDAPRC tldap_modify(struct tldap_context *ld, const char *dn, + struct tldap_mod *mods, int num_mods, + struct tldap_control *sctrls, int num_sctrls, + struct tldap_control *cctrls, int num_cctrls); + +struct tevent_req *tldap_delete_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct tldap_context *ld, + const char *dn, + struct tldap_control *sctrls, + int num_sctrls, + struct tldap_control *cctrls, + int num_cctrls); +TLDAPRC tldap_delete_recv(struct tevent_req *req); +TLDAPRC tldap_delete(struct tldap_context *ld, const char *dn, + struct tldap_control *sctrls, int num_sctrls, + struct tldap_control *cctrls, int num_cctrls); + +int tldap_msg_id(const struct tldap_message *msg); +int tldap_msg_type(const struct tldap_message *msg); +const char *tldap_msg_matcheddn(struct tldap_message *msg); +const char *tldap_msg_diagnosticmessage(struct tldap_message *msg); +const char *tldap_msg_referral(struct tldap_message *msg); +void tldap_msg_sctrls(struct tldap_message *msg, int *num_sctrls, + struct tldap_control **sctrls); +struct tldap_message *tldap_ctx_lastmsg(struct tldap_context *ld); +const char *tldap_rc2string(TLDAPRC rc); + +/* DEBUG */ +enum tldap_debug_level { + TLDAP_DEBUG_FATAL, + TLDAP_DEBUG_ERROR, + TLDAP_DEBUG_WARNING, + TLDAP_DEBUG_TRACE +}; + +void tldap_set_debug(struct tldap_context *ld, + void (*log_fn)(void *log_private, + enum tldap_debug_level level, + const char *fmt, + va_list ap) PRINTF_ATTRIBUTE(3,0), + void *log_private); + +/* + * "+ 0x60" is from ASN1_APPLICATION + */ +#define TLDAP_REQ_BIND (0 + 0x60) +#define TLDAP_RES_BIND (1 + 0x60) +#define TLDAP_REQ_UNBIND (2 + 0x60) +#define TLDAP_REQ_SEARCH (3 + 0x60) +#define TLDAP_RES_SEARCH_ENTRY (4 + 0x60) +#define TLDAP_RES_SEARCH_RESULT (5 + 0x60) +#define TLDAP_REQ_MODIFY (6 + 0x60) +#define TLDAP_RES_MODIFY (7 + 0x60) +#define TLDAP_REQ_ADD (8 + 0x60) +#define TLDAP_RES_ADD (9 + 0x60) +/* ASN1_APPLICATION_SIMPLE instead of ASN1_APPLICATION */ +#define TLDAP_REQ_DELETE (10 + 0x40) +#define TLDAP_RES_DELETE (11 + 0x60) +#define TLDAP_REQ_MODDN (12 + 0x60) +#define TLDAP_RES_MODDN (13 + 0x60) +#define TLDAP_REQ_COMPARE (14 + 0x60) +#define TLDAP_RES_COMPARE (15 + 0x60) +/* ASN1_APPLICATION_SIMPLE instead of ASN1_APPLICATION */ +#define TLDAP_REQ_ABANDON (16 + 0x40) +#define TLDAP_RES_SEARCH_REFERENCE (19 + 0x60) +#define TLDAP_REQ_EXTENDED (23 + 0x60) +#define TLDAP_RES_EXTENDED (24 + 0x60) +#define TLDAP_RES_INTERMEDIATE (25 + 0x60) + +#define TLDAP_MOD_ADD (0) +#define TLDAP_MOD_DELETE (1) +#define TLDAP_MOD_REPLACE (2) + +#define TLDAP_SCOPE_BASE (0) +#define TLDAP_SCOPE_ONE (1) +#define TLDAP_SCOPE_SUB (2) + +#define TLDAP_CONTROL_PAGEDRESULTS "1.2.840.113556.1.4.319" + +#endif diff --git a/source3/include/tldap_util.h b/source3/include/tldap_util.h new file mode 100644 index 0000000..5da0c94 --- /dev/null +++ b/source3/include/tldap_util.h @@ -0,0 +1,105 @@ +/* + Unix SMB/CIFS implementation. + Infrastructure for async ldap client requests + Copyright (C) Volker Lendecke 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/>. +*/ + +#ifndef __TLDAP_UTIL_H__ +#define __TLDAP_UTIL_H__ + +#include "includes.h" + +bool tldap_entry_values(struct tldap_message *msg, const char *attribute, + DATA_BLOB **values, int *num_values); +bool tldap_get_single_valueblob(struct tldap_message *msg, + const char *attribute, DATA_BLOB *blob); +char *tldap_talloc_single_attribute(struct tldap_message *msg, + const char *attribute, + TALLOC_CTX *mem_ctx); +bool tldap_pull_binsid(struct tldap_message *msg, const char *attribute, + struct dom_sid *sid); +bool tldap_pull_guid(struct tldap_message *msg, const char *attribute, + struct GUID *guid); +bool tldap_add_mod_blobs(TALLOC_CTX *mem_ctx, + struct tldap_mod **pmods, int *pnum_mods, + int mod_op, const char *attrib, + DATA_BLOB *newvals, int num_newvals); +bool tldap_add_mod_str(TALLOC_CTX *mem_ctx, + struct tldap_mod **pmods, int *pnum_mods, + int mod_op, const char *attrib, const char *str); +bool tldap_make_mod_blob(struct tldap_message *existing, TALLOC_CTX *mem_ctx, + struct tldap_mod **pmods, int *pnum_mods, + const char *attrib, DATA_BLOB newval); +bool tldap_make_mod_fmt(struct tldap_message *existing, TALLOC_CTX *mem_ctx, + struct tldap_mod **pmods, int *pnum_mods, + const char *attrib, const char *fmt, ...) + PRINTF_ATTRIBUTE(6,7); + +const char *tldap_errstr(TALLOC_CTX *mem_ctx, struct tldap_context *ld, + TLDAPRC rc); +TLDAPRC tldap_search_va(struct tldap_context *ld, const char *base, int scope, + const char *attrs[], int num_attrs, int attrsonly, + TALLOC_CTX *mem_ctx, struct tldap_message ***res, + const char *fmt, va_list ap) PRINTF_ATTRIBUTE(9,0); +TLDAPRC tldap_search_fmt(struct tldap_context *ld, const char *base, int scope, + const char *attrs[], int num_attrs, int attrsonly, + TALLOC_CTX *mem_ctx, struct tldap_message ***res, + const char *fmt, ...) PRINTF_ATTRIBUTE(9,10); +bool tldap_pull_uint64(struct tldap_message *msg, const char *attr, + uint64_t *presult); +bool tldap_pull_uint32(struct tldap_message *msg, const char *attr, + uint32_t *presult); + +struct tevent_req *tldap_fetch_rootdse_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct tldap_context *ld); +TLDAPRC tldap_fetch_rootdse_recv(struct tevent_req *req); +TLDAPRC tldap_fetch_rootdse(struct tldap_context *ld); +struct tldap_message *tldap_rootdse(struct tldap_context *ld); + +bool tldap_entry_has_attrvalue(struct tldap_message *msg, + const char *attribute, + const DATA_BLOB blob); +bool tldap_supports_control(struct tldap_context *ld, const char *oid); + +struct tldap_control *tldap_add_control(TALLOC_CTX *mem_ctx, + struct tldap_control *ctrls, + int num_ctrls, + struct tldap_control *ctrl); +struct tldap_control *tldap_msg_findcontrol(struct tldap_message *msg, + const char *oid); + +struct tevent_req *tldap_search_paged_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct tldap_context *ld, + const char *base, int scope, + const char *filter, + const char **attrs, + int num_attrs, + int attrsonly, + struct tldap_control *sctrls, + int num_sctrls, + struct tldap_control *cctrls, + int num_cctrls, + int timelimit, + int sizelimit, + int deref, + int page_size); +TLDAPRC tldap_search_paged_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, + struct tldap_message **pmsg); + + +#endif diff --git a/source3/include/trans2.h b/source3/include/trans2.h new file mode 100644 index 0000000..dfc5980 --- /dev/null +++ b/source3/include/trans2.h @@ -0,0 +1,449 @@ +/* + Unix SMB/CIFS implementation. + SMB transaction2 handling + + Copyright (C) James Peach 2007 + Copyright (C) Jeremy Allison 1994-2002. + + Extensively modified by Andrew Tridgell, 1995 + + 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/>. +*/ + +#ifndef _TRANS2_H_ +#define _TRANS2_H_ + +/* Define the structures needed for the trans2 calls. */ + +/******************************************************* + For DosFindFirst/DosFindNext - level 1 + +MAXFILENAMELEN = 255; +FDATE == uint16 +FTIME == uint16 +ULONG == uint32 +USHORT == uint16 + +typedef struct _FILEFINDBUF { +Byte offset Type name description +-------------+-------+-------------------+-------------- +0 FDATE fdateCreation; +2 FTIME ftimeCreation; +4 FDATE fdateLastAccess; +6 FTIME ftimeLastAccess; +8 FDATE fdateLastWrite; +10 FTIME ftimeLastWrite; +12 ULONG cbFile file length in bytes +16 ULONG cbFileAlloc size of file allocation unit +20 USHORT attrFile +22 UCHAR cchName length of name to follow (not including zero) +23 UCHAR achName[MAXFILENAMELEN]; Null terminated name +} FILEFINDBUF; +*********************************************************/ + +#define l1_fdateCreation 0 +#define l1_fdateLastAccess 4 +#define l1_fdateLastWrite 8 +#define l1_cbFile 12 +#define l1_cbFileAlloc 16 +#define l1_attrFile 20 +#define l1_cchName 22 +#define l1_achName 23 + +/********************************************************** +For DosFindFirst/DosFindNext - level 2 + +typedef struct _FILEFINDBUF2 { +Byte offset Type name description +-------------+-------+-------------------+-------------- +0 FDATE fdateCreation; +2 FTIME ftimeCreation; +4 FDATE fdateLastAccess; +6 FTIME ftimeLastAccess; +8 FDATE fdateLastWrite; +10 FTIME ftimeLastWrite; +12 ULONG cbFile file length in bytes +16 ULONG cbFileAlloc size of file allocation unit +20 USHORT attrFile +22 ULONG cbList Extended attribute list (always 0) +26 UCHAR cchName length of name to follow (not including zero) +27 UCHAR achName[MAXFILENAMELEN]; Null terminated name +} FILEFINDBUF2; +*************************************************************/ + +#define l2_fdateCreation 0 +#define l2_fdateLastAccess 4 +#define l2_fdateLastWrite 8 +#define l2_cbFile 12 +#define l2_cbFileAlloc 16 +#define l2_attrFile 20 +#define l2_cbList 22 +#define l2_cchName 26 +#define l2_achName 27 + + +/********************************************************** +For DosFindFirst/DosFindNext - level 260 + +typedef struct _FILEFINDBUF260 { +Byte offset Type name description +-------------+-------+-------------------+-------------- +0 ULONG NextEntryOffset; +4 ULONG FileIndex; +8 LARGE_INTEGER CreationTime; +16 LARGE_INTEGER LastAccessTime; +24 LARGE_INTEGER LastWriteTime; +32 LARGE_INTEGER ChangeTime; +40 LARGE_INTEGER EndOfFile; +48 LARGE_INTEGER AllocationSize; +56 ULONG FileAttributes; +60 ULONG FileNameLength; +64 ULONG EaSize; +68 CHAR ShortNameLength; +70 UNICODE ShortName[12]; +94 UNICODE FileName[]; +*************************************************************/ + +#define l260_achName 94 + + +/********************************************************** +For DosQueryPathInfo/DosQueryFileInfo/DosSetPathInfo/ +DosSetFileInfo - level 1 + +typedef struct _FILESTATUS { +Byte offset Type name description +-------------+-------+-------------------+-------------- +0 FDATE fdateCreation; +2 FTIME ftimeCreation; +4 FDATE fdateLastAccess; +6 FTIME ftimeLastAccess; +8 FDATE fdateLastWrite; +10 FTIME ftimeLastWrite; +12 ULONG cbFile file length in bytes +16 ULONG cbFileAlloc size of file allocation unit +20 USHORT attrFile +} FILESTATUS; +*************************************************************/ + +/* Use the l1_ defines from DosFindFirst */ + +/********************************************************** +For DosQueryPathInfo/DosQueryFileInfo/DosSetPathInfo/ +DosSetFileInfo - level 2 + +typedef struct _FILESTATUS2 { +Byte offset Type name description +-------------+-------+-------------------+-------------- +0 FDATE fdateCreation; +2 FTIME ftimeCreation; +4 FDATE fdateLastAccess; +6 FTIME ftimeLastAccess; +8 FDATE fdateLastWrite; +10 FTIME ftimeLastWrite; +12 ULONG cbFile file length in bytes +16 ULONG cbFileAlloc size of file allocation unit +20 USHORT attrFile +22 ULONG cbList Length of EA's (0) +} FILESTATUS2; +*************************************************************/ + +/* Use the l2_ #defines from DosFindFirst */ + +/********************************************************** +For DosQFSInfo/DosSetFSInfo - level 1 + +typedef struct _FSALLOCATE { +Byte offset Type name description +-------------+-------+-------------------+-------------- +0 ULONG idFileSystem id of file system +4 ULONG cSectorUnit number of sectors per allocation unit +8 ULONG cUnit number of allocation units +12 ULONG cUnitAvail Available allocation units +16 USHORT cbSector bytes per sector +} FSALLOCATE; +*************************************************************/ + +#define l1_idFileSystem 0 +#define l1_cSectorUnit 4 +#define l1_cUnit 8 +#define l1_cUnitAvail 12 +#define l1_cbSector 16 + +/********************************************************** +For DosQFSInfo/DosSetFSInfo - level 2 + +typedef struct _FSINFO { +Byte offset Type name description +-------------+-------+-------------------+-------------- +0 FDATE vol_fdateCreation +2 FTIME vol_ftimeCreation +4 UCHAR vol_cch length of volume name (excluding NULL) +5 UCHAR vol_szVolLabel[12] volume name +} FSINFO; +*************************************************************/ + +#define SMB_INFO_STANDARD 1 /* FILESTATUS3 struct */ +#define SMB_INFO_SET_EA 2 /* EAOP2 struct, only valid on set not query */ +#define SMB_INFO_QUERY_EA_SIZE 2 /* FILESTATUS4 struct, only valid on query not set */ +#define SMB_INFO_QUERY_EAS_FROM_LIST 3 /* only valid on query not set */ +#define SMB_INFO_QUERY_ALL_EAS 4 /* only valid on query not set */ +#define SMB_INFO_IS_NAME_VALID 6 +#define SMB_INFO_STANDARD_LONG 11 /* similar to level 1, ie struct FileStatus3 */ +#define SMB_QUERY_EA_SIZE_LONG 12 /* similar to level 2, ie struct FileStatus4 */ +#define SMB_QUERY_FS_LABEL_INFO 0x101 +#define SMB_QUERY_FS_VOLUME_INFO 0x102 +#define SMB_QUERY_FS_SIZE_INFO 0x103 +#define SMB_QUERY_FS_DEVICE_INFO 0x104 +#define SMB_QUERY_FS_ATTRIBUTE_INFO 0x105 +#if 0 +#define SMB_QUERY_FS_QUOTA_INFO +#endif + +#define l2_vol_fdateCreation 0 +#define l2_vol_cch 4 +#define l2_vol_szVolLabel 5 + + +#define SMB_QUERY_FILE_BASIC_INFO 0x101 +#define SMB_QUERY_FILE_STANDARD_INFO 0x102 +#define SMB_QUERY_FILE_EA_INFO 0x103 +#define SMB_QUERY_FILE_NAME_INFO 0x104 +#define SMB_QUERY_FILE_ALLOCATION_INFO 0x105 +#define SMB_QUERY_FILE_END_OF_FILEINFO 0x106 +#define SMB_QUERY_FILE_ALL_INFO 0x107 +#define SMB_QUERY_FILE_ALT_NAME_INFO 0x108 +#define SMB_QUERY_FILE_STREAM_INFO 0x109 +#define SMB_QUERY_COMPRESSION_INFO 0x10b + +#define SMB_FIND_INFO_STANDARD 1 +#define SMB_FIND_EA_SIZE 2 +#define SMB_FIND_EA_LIST 3 +#define SMB_FIND_FILE_DIRECTORY_INFO 0x101 +#define SMB_FIND_FILE_FULL_DIRECTORY_INFO 0x102 +#define SMB_FIND_FILE_NAMES_INFO 0x103 +#define SMB_FIND_FILE_BOTH_DIRECTORY_INFO 0x104 +#define SMB_FIND_ID_FULL_DIRECTORY_INFO 0x105 +#define SMB_FIND_ID_BOTH_DIRECTORY_INFO 0x106 + +#define SMB_SET_FILE_BASIC_INFO 0x101 +#define SMB_SET_FILE_DISPOSITION_INFO 0x102 +#define SMB_SET_FILE_ALLOCATION_INFO 0x103 +#define SMB_SET_FILE_END_OF_FILE_INFO 0x104 + +/* Query FS info. */ +#define SMB_INFO_ALLOCATION 1 +#define SMB_INFO_VOLUME 2 + +/* + * Thursby MAC extensions.... + */ + +/* + * MAC CIFS Extensions have the range 0x300 - 0x2FF reserved. + * Supposedly Microsoft have agreed to this. + */ + +#define MIN_MAC_INFO_LEVEL 0x300 +#define MAX_MAC_INFO_LEVEL 0x3FF + +#define SMB_MAC_QUERY_FS_INFO 0x301 + +#define DIRLEN_GUESS (45+MAX(l1_achName,l2_achName)) + +/* + * DeviceType and Characteristics returned in a + * SMB_QUERY_FS_DEVICE_INFO call. + */ + +#define DEVICETYPE_CD_ROM 0x2 +#define DEVICETYPE_CD_ROM_FILE_SYSTEM 0x3 +#define DEVICETYPE_DISK 0x7 +#define DEVICETYPE_DISK_FILE_SYSTEM 0x8 +#define DEVICETYPE_FILE_SYSTEM 0x9 + +/* Characteristics. */ +#define TYPE_REMOVABLE_MEDIA 0x1 +#define TYPE_READ_ONLY_DEVICE 0x2 +#define TYPE_FLOPPY 0x4 +#define TYPE_WORM 0x8 +#define TYPE_REMOTE 0x10 +#define TYPE_MOUNTED 0x20 +#define TYPE_VIRTUAL 0x40 + +/* SMB_FS_SECTOR_SIZE_INFORMATION values */ +#define SSINFO_FLAGS_ALIGNED_DEVICE 0x00000001 +#define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002 +#define SSINFO_FLAGS_NO_SEEK_PENALTY 0x00000004 +#define SSINFO_FLAGS_TRIM_ENABLED 0x00000008 + +#define SSINFO_OFFSET_UNKNOWN 0xffffffff + +/* MS-FSCC 2.4 File Information Classes */ + +#define FSCC_FILE_DIRECTORY_INFORMATION 1 +#define FSCC_FILE_FULL_DIRECTORY_INFORMATION 2 +#define FSCC_FILE_BOTH_DIRECTORY_INFORMATION 3 +#define FSCC_FILE_BASIC_INFORMATION 4 +#define FSCC_FILE_STANDARD_INFORMATION 5 +#define FSCC_FILE_INTERNAL_INFORMATION 6 +#define FSCC_FILE_EA_INFORMATION 7 +#define FSCC_FILE_ACCESS_INFORMATION 8 +#define FSCC_FILE_NAME_INFORMATION 9 +#define FSCC_FILE_RENAME_INFORMATION 10 +#define FSCC_FILE_LINK_INFORMATION 11 +#define FSCC_FILE_NAMES_INFORMATION 12 +#define FSCC_FILE_DISPOSITION_INFORMATION 13 +#define FSCC_FILE_POSITION_INFORMATION 14 +#define FSCC_FILE_FULL_EA_INFORMATION 15 +#define FSCC_FILE_MODE_INFORMATION 16 +#define FSCC_FILE_ALIGNMENT_INFORMATION 17 +#define FSCC_FILE_ALL_INFORMATION 18 +#define FSCC_FILE_ALLOCATION_INFORMATION 19 +#define FSCC_FILE_END_OF_FILE_INFORMATION 20 +#define FSCC_FILE_ALTERNATE_NAME_INFORMATION 21 +#define FSCC_FILE_STREAM_INFORMATION 22 +#define FSCC_FILE_PIPE_INFORMATION 23 +#define FSCC_FILE_PIPE_LOCAL_INFORMATION 24 +#define FSCC_FILE_PIPE_REMOTE_INFORMATION 25 +#define FSCC_FILE_MAILSLOT_QUERY_INFORMATION 26 +#define FSCC_FILE_MAILSLOT_SET_INFORMATION 27 +#define FSCC_FILE_COMPRESSION_INFORMATION 28 +#define FSCC_FILE_OBJECTID_INFORMATION 29 +#define FSCC_FILE_COMPLETION_INFORMATION 30 +#define FSCC_FILE_MOVE_CLUSTER_INFORMATION 31 +#define FSCC_FILE_QUOTA_INFORMATION 32 +#define FSCC_FILE_REPARSEPOINT_INFORMATION 33 +#define FSCC_FILE_NETWORK_OPEN_INFORMATION 34 +#define FSCC_FILE_ATTRIBUTE_TAG_INFORMATION 35 +#define FSCC_FILE_TRACKING_INFORMATION 36 +#define FSCC_FILE_ID_BOTH_DIRECTORY_INFORMATION 37 +#define FSCC_FILE_ID_FULL_DIRECTORY_INFORMATION 38 +#define FSCC_FILE_VALID_DATA_LENGTH_INFORMATION 39 +#define FSCC_FILE_SHORT_NAME_INFORMATION 40 +#define FSCC_FILE_SFIO_RESERVE_INFORMATION 44 +#define FSCC_FILE_SFIO_VOLUME_INFORMATION 45 +#define FSCC_FILE_HARD_LINK_INFORMATION 46 +#define FSCC_FILE_NORMALIZED_NAME_INFORMATION 48 +#define FSCC_FILE_ID_GLOBAL_TX_DIRECTORY_INFORMATION 50 +#define FSCC_FILE_STANDARD_LINK_INFORMATION 54 +#define FSCC_FILE_MAXIMUM_INFORMATION 55 + +/* As yet undefined FSCC_ code for POSIX info level. */ +#define SMB2_FILE_POSIX_INFORMATION 100 + +/* MS-FSCC 2.4 File System Information Classes */ + +#define FSCC_FS_VOLUME_INFORMATION 1 +#define FSCC_FS_LABEL_INFORMATION 2 +#define FSCC_FS_SIZE_INFORMATION 3 +#define FSCC_FS_DEVICE_INFORMATION 4 +#define FSCC_FS_ATTRIBUTE_INFORMATION 5 +#define FSCC_FS_QUOTA_INFORMATION 6 +#define FSCC_FS_FULL_SIZE_INFORMATION 7 +#define FSCC_FS_OBJECTID_INFORMATION 8 +#define FSCC_FS_SECTOR_SIZE_INFORMATION 11 + +/* NT passthrough levels... */ + +#define NT_PASSTHROUGH_OFFSET 1000 +#define SMB2_INFO_SPECIAL 0xFF00 + +#define SMB_FILE_DIRECTORY_INFORMATION (FSCC_FILE_DIRECTORY_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_FULL_DIRECTORY_INFORMATION (FSCC_FILE_FULL_DIRECTORY_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_BOTH_DIRECTORY_INFORMATION (FSCC_FILE_BOTH_DIRECTORY_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_BASIC_INFORMATION (FSCC_FILE_BASIC_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_STANDARD_INFORMATION (FSCC_FILE_STANDARD_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_INTERNAL_INFORMATION (FSCC_FILE_INTERNAL_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_EA_INFORMATION (FSCC_FILE_EA_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_ACCESS_INFORMATION (FSCC_FILE_ACCESS_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_NAME_INFORMATION (FSCC_FILE_NAME_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_RENAME_INFORMATION (FSCC_FILE_RENAME_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_LINK_INFORMATION (FSCC_FILE_LINK_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_NAMES_INFORMATION (FSCC_FILE_NAMES_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_DISPOSITION_INFORMATION (FSCC_FILE_DISPOSITION_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_POSITION_INFORMATION (FSCC_FILE_POSITION_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_FULL_EA_INFORMATION (FSCC_FILE_FULL_EA_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_MODE_INFORMATION (FSCC_FILE_MODE_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_ALIGNMENT_INFORMATION (FSCC_FILE_ALIGNMENT_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_ALL_INFORMATION (FSCC_FILE_ALL_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_ALLOCATION_INFORMATION (FSCC_FILE_ALLOCATION_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_END_OF_FILE_INFORMATION (FSCC_FILE_END_OF_FILE_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_ALTERNATE_NAME_INFORMATION (FSCC_FILE_ALTERNATE_NAME_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_STREAM_INFORMATION (FSCC_FILE_STREAM_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_PIPE_INFORMATION (FSCC_FILE_PIPE_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_PIPE_LOCAL_INFORMATION (FSCC_FILE_PIPE_LOCAL_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_PIPE_REMOTE_INFORMATION (FSCC_FILE_PIPE_REMOTE_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_MAILSLOT_QUERY_INFORMATION (FSCC_FILE_MAILSLOT_QUERY_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_MAILSLOT_SET_INFORMATION (FSCC_FILE_MAILSLOT_SET_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_COMPRESSION_INFORMATION (FSCC_FILE_COMPRESSION_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_OBJECTID_INFORMATION (FSCC_FILE_OBJECTID_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_COMPLETION_INFORMATION (FSCC_FILE_COMPLETION_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_MOVE_CLUSTER_INFORMATION (FSCC_FILE_MOVE_CLUSTER_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_QUOTA_INFORMATION (FSCC_FILE_QUOTA_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_REPARSEPOINT_INFORMATION (FSCC_FILE_REPARSEPOINT_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_NETWORK_OPEN_INFORMATION (FSCC_FILE_NETWORK_OPEN_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_ATTRIBUTE_TAG_INFORMATION (FSCC_FILE_ATTRIBUTE_TAG_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_TRACKING_INFORMATION (FSCC_FILE_TRACKING_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_ID_BOTH_DIRECTORY_INFORMATION (FSCC_FILE_ID_BOTH_DIRECTORY_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_ID_FULL_DIRECTORY_INFORMATION (FSCC_FILE_ID_FULL_DIRECTORY_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_VALID_DATA_LENGTH_INFORMATION (FSCC_FILE_VALID_DATA_LENGTH_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_SHORT_NAME_INFORMATION (FSCC_FILE_SHORT_NAME_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_SFIO_RESERVE_INFORMATION (FSCC_FILE_SFIO_RESERVE_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_SFIO_VOLUME_INFORMATION (FSCC_FILE_SFIO_VOLUME_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_HARD_LINK_INFORMATION (FSCC_FILE_HARD_LINK_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_NORMALIZED_NAME_INFORMATION (FSCC_FILE_NORMALIZED_NAME_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_ID_GLOBAL_TX_DIRECTORY_INFORMATION (FSCC_FILE_ID_GLOBAL_TX_DIRECTORY_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_STANDARD_LINK_INFORMATION (FSCC_FILE_STANDARD_LINK_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FILE_MAXIMUM_INFORMATION (FSCC_FILE_MAXIMUM_INFORMATION + NT_PASSTHROUGH_OFFSET) +/* Internal mapped versions. */ +#define SMB2_FILE_RENAME_INFORMATION_INTERNAL (FSCC_FILE_RENAME_INFORMATION + SMB2_INFO_SPECIAL) +#define SMB2_FILE_FULL_EA_INFORMATION (FSCC_FILE_FULL_EA_INFORMATION + SMB2_INFO_SPECIAL) +#define SMB2_FILE_ALL_INFORMATION (FSCC_FILE_ALL_INFORMATION + SMB2_INFO_SPECIAL) +#define SMB2_FILE_POSIX_INFORMATION_INTERNAL (SMB2_FILE_POSIX_INFORMATION + SMB2_INFO_SPECIAL) + +/* NT passthrough levels for qfsinfo. */ + +#define SMB_FS_VOLUME_INFORMATION (FSCC_FS_VOLUME_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FS_LABEL_INFORMATION (FSCC_FS_LABEL_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FS_SIZE_INFORMATION (FSCC_FS_SIZE_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FS_DEVICE_INFORMATION (FSCC_FS_DEVICE_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FS_ATTRIBUTE_INFORMATION (FSCC_FS_ATTRIBUTE_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FS_QUOTA_INFORMATION (FSCC_FS_QUOTA_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FS_FULL_SIZE_INFORMATION (FSCC_FS_FULL_SIZE_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FS_OBJECTID_INFORMATION (FSCC_FS_OBJECTID_INFORMATION + NT_PASSTHROUGH_OFFSET) +#define SMB_FS_SECTOR_SIZE_INFORMATION (FSCC_FS_SECTOR_SIZE_INFORMATION + NT_PASSTHROUGH_OFFSET) + +/* SMB_FS_DEVICE_INFORMATION device types. */ +#define FILE_DEVICE_CD_ROM 0x2 +#define FILE_DEVICE_DISK 0x7 + +/* SMB_FS_DEVICE_INFORMATION characteristics. */ +#define FILE_REMOVABLE_MEDIA 0x001 +#define FILE_READ_ONLY_DEVICE 0x002 +#define FILE_FLOPPY_DISKETTE 0x004 +#define FILE_WRITE_ONCE_MEDIA 0x008 +#define FILE_REMOTE_DEVICE 0x010 +#define FILE_DEVICE_IS_MOUNTED 0x020 +#define FILE_VIRTUAL_VOLUME 0x040 +#define FILE_DEVICE_SECURE_OPEN 0x100 + +/* flags on trans2 findfirst/findnext that control search */ +#define FLAG_TRANS2_FIND_CLOSE 0x1 +#define FLAG_TRANS2_FIND_CLOSE_IF_END 0x2 +#define FLAG_TRANS2_FIND_REQUIRE_RESUME 0x4 +#define FLAG_TRANS2_FIND_CONTINUE 0x8 +#define FLAG_TRANS2_FIND_BACKUP_INTENT 0x10 + +#endif diff --git a/source3/include/transfer_file.h b/source3/include/transfer_file.h new file mode 100644 index 0000000..2f1bff4 --- /dev/null +++ b/source3/include/transfer_file.h @@ -0,0 +1,32 @@ +/* + * Unix SMB/CIFS implementation. + * Utility functions to transfer files. + * + * Copyright (C) Michael Adam 2008 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __TRANSFER_FILE_H__ +#define __TRANSFER_FILE_H__ + +ssize_t transfer_file_internal(void *in_file, + void *out_file, + size_t n, + ssize_t (*pread_fn)(void *, void *, size_t, off_t), + ssize_t (*pwrite_fn)(void *, const void *, size_t, off_t)); + +off_t transfer_file(int infd, int outfd, off_t n); + +#endif /* __TRANSFER_FILE_H__ */ diff --git a/source3/include/util_event.h b/source3/include/util_event.h new file mode 100644 index 0000000..d19678e --- /dev/null +++ b/source3/include/util_event.h @@ -0,0 +1,34 @@ +/* + Unix SMB/CIFS implementation. + event handling + Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Volker Lendecke 2005-2007 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/* The following definitions come from lib/util_event.c */ + +#include "replace.h" +#include <tevent.h> + +struct idle_event; + +struct idle_event *event_add_idle(struct tevent_context *event_ctx, + TALLOC_CTX *mem_ctx, + struct timeval interval, + const char *name, + bool (*handler)(const struct timeval *now, + void *private_data), + void *private_data); diff --git a/source3/include/util_sd.h b/source3/include/util_sd.h new file mode 100644 index 0000000..7f82969 --- /dev/null +++ b/source3/include/util_sd.h @@ -0,0 +1,37 @@ +/* + Unix SMB/CIFS implementation. + Security Descriptor (SD) helper functions + + Copyright (C) Andrew Tridgell 2000 + Copyright (C) Tim Potter 2000 + Copyright (C) Jeremy Allison 2000 + Copyright (C) Jelmer Vernooij 2003 + + 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/>. +*/ + +#ifndef __UTIL_SD_H__ +#define __UTIL_SD_H__ + +void SidToString(struct cli_state *cli, fstring str, const struct dom_sid *sid, + bool numeric); +bool StringToSid(struct cli_state *cli, struct dom_sid *sid, const char *str); +void print_ace(struct cli_state *cli, FILE *f, struct security_ace *ace, + bool numeric); +bool parse_ace(struct cli_state *cli, struct security_ace *ace, + const char *orig_str); +void sec_desc_print(struct cli_state *cli, FILE *f, + struct security_descriptor *sd, bool numeric); + +#endif diff --git a/source3/include/util_tdb.h b/source3/include/util_tdb.h new file mode 100644 index 0000000..d4efb0c --- /dev/null +++ b/source3/include/util_tdb.h @@ -0,0 +1,64 @@ +/* + Unix SMB/CIFS implementation. + tdb utility functions + Copyright (C) Andrew Tridgell 1999 + + 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/>. +*/ + +#ifndef __TDBUTIL_H__ +#define __TDBUTIL_H__ + +#include <tdb.h> + +#include <talloc.h> /* for tdb_wrap_open() */ +#include "../libcli/util/ntstatus.h" /* for map_nt_error_from_tdb() */ +#include "../../lib/util/util_tdb.h" + +/* + * The tdb_unpack() and tdb_pack[_append]() helpers are deprecated. Consider + * using idl/ndr for marshalling of complex data types instead. + */ +int tdb_unpack(const uint8_t *buf, int bufsize, const char *fmt, ...); +size_t tdb_pack(uint8_t *buf, int bufsize, const char *fmt, ...); + +struct tdb_context *tdb_open_log(const char *name, int hash_size, + int tdb_flags, int open_flags, mode_t mode); + +NTSTATUS map_nt_error_from_tdb(enum TDB_ERROR err); + +int tdb_data_cmp(TDB_DATA t1, TDB_DATA t2); + +char *tdb_data_string(TALLOC_CTX *mem_ctx, TDB_DATA d); + +/**************************************************************************** + Lock a chain, with timeout. +****************************************************************************/ +int tdb_chainlock_with_timeout( struct tdb_context *tdb, TDB_DATA key, + unsigned int timeout); + +/**************************************************************************** + Lock a chain by string, with timeout Return non-zero if lock failed. +****************************************************************************/ +int tdb_lock_bystring_with_timeout(struct tdb_context *tdb, const char *keyval, + int timeout); + +/**************************************************************************** + Readlock a chain by string, with timeout Return non-zero if lock failed. +****************************************************************************/ +int tdb_read_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval, + unsigned int timeout); + + +#endif /* __TDBUTIL_H__ */ diff --git a/source3/include/vfs.h b/source3/include/vfs.h new file mode 100644 index 0000000..61360b3 --- /dev/null +++ b/source3/include/vfs.h @@ -0,0 +1,2247 @@ +/* + Unix SMB/CIFS implementation. + VFS structures and parameters + Copyright (C) Jeremy Allison 1999-2005 + Copyright (C) Tim Potter 1999 + Copyright (C) Alexander Bokovoy 2002-2005 + Copyright (C) Stefan (metze) Metzmacher 2003 + Copyright (C) Volker Lendecke 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/>. + + This work was sponsored by Optifacio Software Services, Inc. +*/ + +#ifndef _VFS_H +#define _VFS_H + +/* Avoid conflict with an AIX include file */ + +#ifdef vfs_ops +#undef vfs_ops +#endif + +/* + * As we're now (thanks Andrew ! :-) using file_structs and connection + * structs in the vfs - then anyone writing a vfs must include includes.h... + */ + +/* + * This next constant specifies the version number of the VFS interface + * this smbd will load. Increment this if *ANY* changes are made to the + * vfs_ops below. JRA. + * + * If you change anything here, please also update modules/vfs_full_audit.c. + * VL. + */ + +/* + * Changed to version 2 for CIFS UNIX extensions (mknod and link added). JRA. + * Changed to version 3 for POSIX acl extensions. JRA. + * Changed to version 4 for cascaded VFS interface. Alexander Bokovoy. + * Changed to version 5 for sendfile addition. JRA. + * Changed to version 6 for the new module system, fixed cascading and quota functions. --metze + * Changed to version 7 to include the get_nt_acl info parameter. JRA. + * Changed to version 8 includes EA calls. JRA. + * Changed to version 9 to include the get_shadow_data call. --metze + * Changed to version 10 to include pread pwrite calls. + * Changed to version 11 to include seekdir telldir rewinddir calls. JRA + * Changed to version 12 to add mask and attributes to opendir(). JRA + * Also include aio calls. JRA. + * Changed to version 13 as the internal structure of files_struct has changed. JRA + * Changed to version 14 as we had to change DIR to SMB_STRUCT_DIR. JRA + * Changed to version 15 as we added the statvfs call. JRA + * Changed to version 16 as we added the getlock call. JRA + * Changed to version 17 as we removed redundant connection_struct parameters. --jpeach + * Changed to version 18 to add fsp parameter to the open call -- jpeach + * Also include kernel_flock call - jmcd + * Changed to version 19, kernel change notify has been merged + * Also included linux setlease call - jmcd + * Changed to version 20, use ntimes call instead of utime (greater + * timestamp resolition. JRA. + * Changed to version21 to add chflags operation -- jpeach + * Changed to version22 to add lchown operation -- jra + * Leave at 22 - not yet released. But change set_nt_acl to return an NTSTATUS. jra. + * Leave at 22 - not yet released. Add file_id_create operation. --metze + * Leave at 22 - not yet released. Change all BOOL parameters (int) to bool. jra. + * Leave at 22 - not yet released. Added recvfile. + * Leave at 22 - not yet released. Change get_nt_acl to return NTSTATUS - vl + * Leave at 22 - not yet released. Change get_nt_acl to *not* take a + * files_struct. - obnox. + * Leave at 22 - not yet released. Remove parameter fd from fget_nt_acl. - obnox + * Leave at 22 - not yet released. Remove parameter fd from gset_nt_acl. - obnox + * Leave at 22 - not yet released. Remove parameter fd from pread. - obnox + * Leave at 22 - not yet released. Remove parameter fd from pwrite. - obnox + * Leave at 22 - not yet released. Remove parameter fd from lseek. - obnox + * Leave at 22 - not yet released. Remove parameter fd from fsync. - obnox + * Leave at 22 - not yet released. Remove parameter fd from fstat. - obnox + * Leave at 22 - not yet released. Remove parameter fd from fchmod. - obnox + * Leave at 22 - not yet released. Remove parameter fd from fchown. - obnox + * Leave at 22 - not yet released. Remove parameter fd from ftruncate. - obnox + * Leave at 22 - not yet released. Remove parameter fd from lock. - obnox + * Leave at 22 - not yet released. Remove parameter fd from kernel_flock. - obnox + * Leave at 22 - not yet released. Remove parameter fd from linux_setlease. - obnox + * Leave at 22 - not yet released. Remove parameter fd from getlock. - obnox + * Leave at 22 - not yet released. Remove parameter fd from sys_acl_get_fd. - obnox + * Leave at 22 - not yet released. Remove parameter fd from fchmod_acl. - obnox + * Leave at 22 - not yet released. Remove parameter fd from sys_acl_set_fd. - obnox + * Leave at 22 - not yet released. Remove parameter fd from fgetxattr. - obnox + * Leave at 22 - not yet released. Remove parameter fd from flistxattr. - obnox + * Leave at 22 - not yet released. Remove parameter fd from fremovexattr. - obnox + * Leave at 22 - not yet released. Remove parameter fd from fsetxattr. - obnox + * Leave at 22 - not yet released. Remove parameter fd from aio_cancel. - obnox + * Leave at 22 - not yet released. Remove parameter fd from read. - obnox + * Leave at 22 - not yet released. Remove parameter fd from write. - obnox + * Leave at 22 - not yet released. Remove parameter fromfd from sendfile. - obnox + * Leave at 22 - not yet released. Remove parameter fromfd from recvfile. - obnox + * Leave at 22 - not yet released. Additional change: add operations for offline files -- ab + * Leave at 22 - not yet released. Add the streaminfo call. -- jpeach, vl + * Leave at 22 - not yet released. Remove parameter fd from close_fn. - obnox + * Changed to version 23 - remove set_nt_acl call. This can only be done via an + * open handle. JRA. + * Changed to version 24 - make security descriptor const in fset_nt_acl. JRA. + * Changed to version 25 - Jelmer's change from SMB_BIG_UINT to uint64_t. + * Leave at 25 - not yet released. Add create_file call. -- tprouty. + * Leave at 25 - not yet released. Add create time to ntimes. -- tstecher. + * Leave at 25 - not yet released. Add get_alloc_size call. -- tprouty. + * Leave at 25 - not yet released. Add SMB_STRUCT_STAT to readdir. - sdann + * Leave at 25 - not yet released. Add init_search_op call. - sdann + * Leave at 25 - not yet released. Add locking calls. -- zkirsch. + * Leave at 25 - not yet released. Add strict locking calls. -- drichards. + * Changed to version 26 - Plumb struct smb_filename to SMB_VFS_CREATE_FILE, + * SMB_VFS_OPEN, SMB_VFS_STAT, SMB_VFS_LSTAT, + * SMB_VFS_RENAME, SMB_VFS_UNLINK, SMB_VFS_NTIMES. + * Changed to version 27 - not yet released. Added enum timestamp_set_resolution + * return to fs_capabilities call. JRA. + * Leave at 27 - not yet released. Add translate_name VFS call to convert + * UNIX names to Windows supported names -- asrinivasan. + * Changed to version 28 - Add private_flags uint32_t to CREATE call. + * Leave at 28 - not yet released. Change realpath to assume NULL and return a + * malloc'ed path. JRA. + * Leave at 28 - not yet released. Move posix_fallocate into the VFS + * where it belongs. JRA. + * Leave at 28 - not yet released. Rename posix_fallocate to fallocate + * to split out the two possible uses. JRA. + * Leave at 28 - not yet released. Add fdopendir. JRA. + * Leave at 28 - not yet released. Rename open function to open_fn. - gd + * Leave at 28 - not yet released. Make getwd function always return malloced memory. JRA. + * Bump to version 29 - Samba 3.6.0 will ship with interface version 28. + * Leave at 29 - not yet releases. Add fsctl. Richard Sharpe + * Leave at 29 - not yet released. add SMB_VFS_GET_DFS_REFERRAL() - metze + * Leave at 29 - not yet released. Remove l{list,get,set,remove}xattr - abartlet + * Leave at 29 - not yet released. move to plain off_t - abartlet + * Leave at 29 - not yet released. Remove sys_acl functions other than set and get - abartlet + * Leave at 29 - not yet released. Added backup_intent bool to files_struct - JRA + * Leave at 29 - not yet released. Add durable handle functions - metze obnox + * Leave at 29 - not yet released. Added sys_acl_blob_get_file and sys_acl_blob_get_fd + * Bump to version 30 - Samba 4.0.0 will ship with interface version 30 + * Leave at 30 - not yet released. Added conn->cwd to save vfs_GetWd() calls. + * Leave at 30 - not yet released. Changed sys_acl_blob_get_file interface to remove type + * Bump to version 31 - Samba 4.1.0 will ship with interface version 31 + * Leave at 31 - not yet released. Make struct vuid_cache_entry in + * connection_struct a pointer. + * Leave at 31 - not yet released. Add share_access to vuid_cache_entry. + * Leave at 31 - not yet released. add SMB_VFS_COPY_CHUNK() + * Leave at 31 - not yet released. Remove the unused + * fsp->pending_break_messages array + * Leave at 31 - not yet released. add SMB_VFS_[GET SET]_COMPRESSION() + * + * Bump to version 32 - Samba 4.2 will ship with that. + * Version 32 - Add "lease" to CREATE_FILE operation + * Version 32 - Add "lease" to struct files_struct + * Version 32 - Add SMB_VFS_READDIR_ATTR() + * Version 32 - Add in and out create context blobs to create_file + * Version 32 - Remove unnecessary SMB_VFS_DISK_FREE() small_query parameter + * Bump to version 33 - Samba 4.3 will ship with that. + * Version 33 - change fallocate mode flags param from enum->uint32_t + * Version 33 - Add snapshot create delete calls + * Version 33 - Add OS X SMB2 AAPL copyfile extension flag to fsp + * Version 33 - Remove notify_watch_fn + * Bump to version 34 - Samba 4.4 will ship with that + * Version 34 - Remove bool posix_open, add uint64_t posix_flags + * Version 34 - Added bool posix_pathnames to struct smb_request + * Bump to version 35 - Samba 4.5 will ship with that + * Version 35 - Change get_nt_acl_fn from const char *, to + * const struct smb_filename * + * Version 35 - Change mkdir from const char *, to + * const struct smb_filename * + * Version 35 - Change rmdir from const char *, to + * const struct smb_filename * + * Version 35 - Change opendir from const char *, to + * const struct smb_filename * + * Version 35 - Wrap aio async funtions args in a struct vfs_aio_state + * Version 35 - Change chmod from const char *, to + * const struct smb_filename * + * Version 35 - Change chmod_acl from const char *, to + * const struct smb_filename * + * Version 35 - Change chown from const char *, to + * const struct smb_filename * + * Version 35 - Change lchown from const char *, to + * const struct smb_filename * + * Version 35 - Change streaminfo from const char *, to + * const struct smb_filename * + * Version 35 - Add uint32_t flags to struct smb_filename + * Version 35 - Add get set fget fset dos attribute functions. + * Version 35 - Add bool use_ofd_locks to struct files_struct + * Bump to version 36 - Samba 4.6 will ship with that + * Version 36 - Remove is_offline and set_offline + * Version 37 - Module init functions now take a TALLOC_CTX * parameter. + * Version 37 - Add vfs_copy_chunk_flags for DUP_EXTENTS_TO_FILE + * Version 37 - Change sys_acl_delete_def_file from const char * + * to const struct smb_filename * + * Version 37 - Change sys_acl_get_file from const char * + * to const struct smb_filename * + * Version 37 - Change sys_acl_blob_get_file from const char * + * to const struct smb_filename * + * Version 37 - Change sys_acl_set_file from const char * + * to const struct smb_filename * + * Version 37 - Change listxattr from const char * + * to const struct smb_filename * + * Version 37 - Change removexattr from const char * + * to const struct smb_filename * + * Version 37 - Change setxattr from const char * + * to const struct smb_filename * + * Version 37 - Change getxattr from const char * + * to const struct smb_filename * + * Version 37 - Change mknod from const char * to const struct smb_filename * + * Version 37 - Change chflags from const char * + * to const struct smb_filename * + * Version 37 - Change disk_free from const char * + * to const struct smb_filename * + * Version 37 - Change get_quota from const char * + * to const struct smb_filename * + * Version 37 - Change link from const char * + * to const struct smb_filename * + * Version 37 - Change statvfs from const char * + * to const struct smb_filename * + * Version 37 - Change readlink from const char * + * to const struct smb_filename * + * Version 37 - Change symlink from const char * + * to const struct smb_filename * + * Version 37 - Change chdir from const char * + * to const struct smb_filename * + * Version 37 - Change getwd from char * + * to const struct smb_filename * + * Version 37 - Change conn->cwd from char * + * to struct smb_filename * + * Version 37 - Change realpath from char * + * to struct smb_filename * + * Version 37 - Change connectpath from char * + * to struct smb_filename * + * Version 37 - Add SMB_VFS_OFFLOAD_READ_SEND RECV + * Version 37 - Rename SMB_VFS_COPY_CHUNK_SEND RECV to + * SMB_VFS_OFFLOAD_READ_SEND RECV + * Version 37 - Remove SMB_VFS_STRICT_UNLOCK + * Version 37 - Rename SMB_VFS_STRICT_LOCK to + * SMB_VFS_STRICT_LOCK_CHECK + * Version 38 - Remove SMB_VFS_INIT_SEARCH_OP + * Bump to version 39, Samba 4.9 will ship with that + * Version 39 - Remove SMB_VFS_FSYNC + * Only implement async versions. + * Version 39 - Remove SMB_VFS_READ + * All users are now pread or async versions. + * Version 39 - Remove SMB_VFS_WRITE + * All users are now pwrite or async versions. + * Version 39 - Remove SMB_VFS_CHMOD_ACL - no longer used. + * Version 39 - Remove SMB_VFS_FCHMOD_ACL - no longer used. + * Version 39 - Remove struct dfree_cached_info pointer from + * connection struct + * Bump to version 40, Samba 4.10 will ship with that + * Version 40 - Add SMB_VFS_GETXATTRAT_SEND RECV + * Version 40 - Add SMB_VFS_GET_DOS_ATTRIBUTES_SEND RECV + * Bump to version 41, Samba 4.11 will ship with that + * Version 41 - Remove SMB_VFS_BRL_CANCEL_WINDOWS + * Version 41 - Remove unused st_ex_mask from struct stat_ex + * Version 41 - convert struct stat_ex.st_ex_calculated_birthtime to flags + * Version 41 - add st_ex_itime to struct stat_ex + * Version 41 - add st_ex_file_id to struct stat_ex + * Version 41 - add SMB_VFS_FS_FILE_ID + * Version 41 - Remove "blocking_lock" parameter from + * SMB_VFS_BRL_LOCK_WINDOWS + * Version 41 - Remove "msg_ctx" parameter from SMB_VFS_BRL_UNLOCK_WINDOWS + * Bump to version 42, Samba 4.12 will ship with that + * Version 42 - Remove share_access member from struct files_struct + * Version 42 - Make "lease" a const* in create_file_fn + * Version 42 - Move SMB_VFS_RENAME -> SMB_VFS_RENAMEAT + * Version 42 - Move SMB_VFS_LINK -> SMB_VFS_LINKAT. + * Version 42 - Move SMB_VFS_MKNOD -> SMB_VFS_MKDNODAT. + * Version 42 - Move SMB_VFS_READLINK -> SMB_VFS_READLINKAT. + * Version 42 - Move SMB_VFS_SYMLINK -> SMB_VFS_SYMLINKAT. + * Version 42 - Move SMB_VFS_MKDIR -> SMB_VFS_MKDIRAT. + * Version 42 - Move change_to_user() -> change_to_user_and_service() + * Version 42 - Move change_to_user_by_fsp() -> change_to_user_and_service_by_fsp() + * Version 42 - Move [un]become_user*() -> [un]become_user_without_service*() + * Version 42 - Move SMB_VFS_UNLINK -> SMB_VFS_UNLINKAT. + * Version 42 - Add SMB_VFS_FCNTL + * Version 42 - Remove SMB_VFS_RMDIR. + * Use SMB_VFS_UNLINKAT(.., AT_REMOVEDIR) instead. + * Version 42 - Remove SMB_VFS_CHOWN + * Version 42 - Remove struct write_cache *wcp from files_struct + * Version 42 - SMB_VFS_NTIMES() receives null times based on UTIMES_OMIT + * Version 42 - Add SMB_VFS_CREATE_DFS_PATHAT() + * Version 42 - Add SMB_VFS_READ_DFS_PATHAT() + * Change to Version 43 - will ship with 4.13. + * Version 43 - Remove deferred_close from struct files_struct + * Version 43 - Remove SMB_VFS_OPENDIR() + * Version 43 - Remove original_lcomp from struct smb_filename + * Version 43 - files_struct flags: + * bool kernel_share_modes_taken + * bool update_write_time_triggered + * bool update_write_time_on_close + * bool write_time_forced + * bool can_lock + * bool can_read + * bool can_write + * bool modified + * bool is_directory + * bool aio_write_behind + * bool initial_delete_on_close + * bool delete_on_close + * bool is_sparse + * bool backup_intent + * bool use_ofd_locks + * bool closing + * bool lock_failure_seen + * changed to bitfields. + * Version 43 - convert SMB_VFS_GET_REAL_FILENAME() arg path + * to be a struct smb_filename + * Version 43 - convert link_contents arg of SMB_VFS_SYMLINKAT() + * to struct smb_filename + * Version 43 - Move SMB_VFS_GET_NT_ACL() -> SMB_VFS_GET_NT_ACL_AT(). + * Version 43 - Remove root_dir_fid from SMB_VFS_CREATE_FILE(). + * Version 43 - Add dirfsp to struct files_struct + * Version 43 - Add dirfsp args to SMB_VFS_CREATE_FILE() + * Version 43 - Add SMB_VFS_OPENAT() + * Version 43 - Remove SMB_VFS_OPEN() + * Version 43 - SMB_VFS_READ_DFS_PATHAT() should take a non-const name. + There's no easy way to return stat info for a DFS link + otherwise. + * Change to Version 44 - will ship with 4.14. + * Version 44 - Remove dirfsp arg from struct files_struct + * Version 44 - Remove dirfsp arg to SMB_VFS_CREATE_FILE() + * Version 44 - Make dirfsp arg to SMB_VFS_READLINKAT() const + * Version 44 - Add a flag 'encryption_required' to files_struct that that + * prevents that encrypted connections can be downgraded. + * Version 44 - Add a flag 'is_pathref' to struct files_struct. + * Version 44 - Add 'is_fsa' flag to struct files_struct. + * Version 44 - Add 'have_proc_fds' flag to struct connection_struct. + * Version 44 - Add 'have_proc_fds' flag to struct files_struct. + * Version 44 - Add dirfsp arg to SMB_VFS_READDIR() + * Version 44 - Replace SMB_VFS_GET_COMPRESSION() with SMB_VFS_FGET_COMPRESSION() + * Version 44 - Add type argument to SMB_VFS_SYS_ACL_SET_FD() + * Version 44 - Remove SMB_VFS_SYS_ACL_SET_FILE() + * Change to Version 45 - will ship with 4.15 + * Version 45 - Remove SMB_VFS_LISTXATTR + * Version 45 - Remove SMB_VFS_SETXATTR + * Version 45 - Remove SMB_VFS_REMOVEXATTR + * Version 45 - Remove SMB_VFS_GET_DOS_ATTRIBUTES() + * Version 45 - Remove SMB_VFS_CHMOD + * Version 45 - Add SMB_VFS_FNTIMES + * Version 45 - Remove SMB_VFS_NTIMES + * Version 45 - ADD SMB_VFS_FSTREAMINFO + * Version 45 - Add SMB_VFS_FREADDIR_ATTR + * Version 45 - Remove SMB_VFS_READDIR_ATTR + * Version 45 - Add SMB_VFS_SYS_ACL_DELETE_DEF_FD + * Version 45 - Remove SMB_VFS_SYS_ACL_DELETE_DEF_FILE + * Version 45 - Add SMB_VFS_PARENT_PATHNAME + * Version 45 - Remove SMB_VFS_GET_NT_ACL_AT + * Version 45 - Remove SYS_ACL_GET_FILE + * Version 45 - Remove SYS_ACL_BLOB_GET_FILE + * Version 45 - Add SMB_VFS_FCHFLAGS + * Version 45 - Remove SMB_VFS_GETXATTR + * Change to Version 46 - will ship with 4.16 + * Version 46 - Rename SMB_VFS_KERNEL_FLOCK to SMB_VFS_FILESYSTEM_SHAREMODE + * Version 46 - Add flags and xferlen args to SMB_VFS_OFFLOAD_READ_RECV + * Change to Version 47 - will ship with 4.17 + * Version 47 - Add SMB_VFS_FSTATAT + * Version 47 - Change SMB_VFS_GET_REAL_FILENAME to return NTSTATUS + * Version 47 - remove st_ex_itime from struct stat_ex + * Version 47 - remove (unused) struct lock_struct last_lock_failure + from files_struct. + * Version 47 - Add SMB_VFS_GET_REAL_FILENAME_AT + * Version 47 - Replace SMB_VFS_GET_REAL_FILENAME with SMB_VFS_GET_REAL_FILENAME_AT + * Version 47 - Re-add dirfsp to CREATE_FILE + * Version 47 - Add fsp flag fstat_before_close + * Version 47 - Change SMB_VFS_OPENAT() to match the Linux openat2 prototype, add vfs_open_how + * Version 47 - Add VFS_OPEN_HOW_RESOLVE_NO_SYMLINKS for SMB_VFS_OPENAT() + */ + +#define SMB_VFS_INTERFACE_VERSION 47 + +/* + All intercepted VFS operations must be declared as static functions inside module source + in order to keep smbd namespace unpolluted. See source of audit, extd_audit, fake_perms and recycle + example VFS modules for more details. +*/ + +/* VFS operations structure */ + +struct vfs_handle_struct; +struct connection_struct; +struct files_struct; +struct security_descriptor; +struct vfs_statvfs_struct; +struct smb_request; +struct ea_list; +struct smb_file_time; +struct smb_filename; +struct dfs_GetDFSReferral; + +typedef union unid_t { + uid_t uid; + gid_t gid; +} unid_t; + +struct fd_handle; + +struct fsp_lease { + size_t ref_count; + struct smbd_server_connection *sconn; + struct tevent_timer *timeout; + struct smb2_lease lease; +}; + +typedef struct files_struct { + struct files_struct *next, *prev; + uint64_t fnum; + struct smbXsrv_open *op; + struct connection_struct *conn; + struct fd_handle *fh; + unsigned int num_smb_operations; + struct file_id file_id; + uint64_t initial_allocation_size; /* Faked up initial allocation on disk. */ + uint16_t file_pid; + uint64_t vuid; /* SMB2 compat */ + struct timeval open_time; + uint32_t access_mask; /* NTCreateX access bits (FILE_READ_DATA etc.) */ + struct { + bool is_pathref : 1; /* See below */ + bool is_fsa : 1; /* See below */ + bool have_proc_fds : 1; + bool kernel_share_modes_taken : 1; + bool update_write_time_triggered : 1; + bool update_write_time_on_close : 1; + bool write_time_forced : 1; + bool can_lock : 1; + bool can_read : 1; + bool can_write : 1; + bool modified : 1; + bool is_directory : 1; + bool is_dirfsp : 1; + bool aio_write_behind : 1; + bool initial_delete_on_close : 1; + bool delete_on_close : 1; + bool is_sparse : 1; + bool backup_intent : 1; + bool use_ofd_locks : 1; + bool closing : 1; + bool lock_failure_seen : 1; + bool encryption_required : 1; + bool fstat_before_close : 1; + } fsp_flags; + + struct tevent_timer *update_write_time_event; + struct timespec close_write_time; + + int oplock_type; + + /* + * Cache of our lease_type, stored as "current_state" in + * leases.tdb + */ + int leases_db_seqnum; + uint32_t lease_type; + + struct fsp_lease *lease; + int sent_oplock_break; + struct tevent_timer *oplock_timeout; + int current_lock_count; /* Count the number of outstanding locks and pending locks. */ + + uint64_t posix_flags; + struct smb_filename *fsp_name; + uint32_t name_hash; /* Jenkins hash of full pathname. */ + uint64_t mid; /* Mid of the operation that created us. */ + + struct vfs_fsp_data *vfs_extension; + struct fake_file_handle *fake_file_handle; + + struct notify_change_buf *notify; + + struct files_struct *base_fsp; /* placeholder for delete on close */ + struct files_struct *stream_fsp; /* backlink from base_fsp */ + + /* + * Cache of share_mode_data->flags + */ + int share_mode_flags_seqnum; + uint16_t share_mode_flags; + + /* + * Read-only cached brlock record, thrown away when the + * brlock.tdb seqnum changes. This avoids fetching data from + * the brlock.tdb on every read/write call. + */ + int brlock_seqnum; + struct byte_range_lock *brlock_rec; + + struct dptr_struct *dptr; + + /* if not NULL, means this is a print file */ + struct print_file_data *print_file; + + /* + * Optimize the aio_requests array for high performance: Never + * shrink it, maintain num_aio_requests separately + */ + unsigned num_aio_requests; + struct tevent_req **aio_requests; + + /* + * Requests waiting for smb1 byte range locks. They are + * generated by smbd_smb1_do_locks_send and are required here, + * because lock cancel operations index through reply_lockingX + * not based on mid but on the lock type and range. + */ + struct tevent_req **blocked_smb1_lock_reqs; + + /* + * SMB1 remembers lock failures and delays repeated blocking + * lock attempts on the same offset. + */ + uint64_t lock_failure_offset; +} files_struct; + +/* + * The fsp flags "is_pathref" and "is_fsa" + * ======================================= + * + * Summary + * ------- + * + * The flag "is_pathref" is a property of the low-level VFS-layer file + * handle. If "is_pathref" is true, only a subset of VFS calls are allowed + * on the handle and on systems that support it, the low-level fd is open + * with O_PATH. If "is_pathref" is false, the low-level fd is a "normal" + * file descriptor that can be used with all VFS calls. + * + * The flag "is_fsa" is a property of the FSA layer in Samba. The term FSA + * layer refers to the parts of smbd that implement Windows NTFS semantics + * on-top of a POSIX filesystem. If "is_fsa" is true, the fsp was + * processed by the SMB_VFS_CREATE_FILE() VFS call, otherwise the fsp was + * created by openat_pathref_fsp() which only connected the low-level + * handle by calling into VFS SMB_VFS_OPENAT(), but the whole FSA layer + * logic is skipped. + * + * Note that only three possible combinations of "is_pathref" and "is_fsa" + * are possible: + * + * | is_fsa \ is_pathref | + | - | + * |---------------------+---+---| + * | + | + | + | + * | - | + | - | + * + * So a fsp can't be a full low-level fd (is_pathref=false) and not be + * processed by the FSA layer. + * + * Details + * ------- + * + * On Linux the O_PATH flag to open() can be used to open a filehandle on + * a file or directory with interesting properties: + * + * - the file-handle indicates a location in the filesystem tree, + * - no permission checks are done by the kernel and + * - only operations that act purely at the file descriptor level are + * allowed. + * + * The file itself is not opened, and other file operations (e.g., + * read(2), write(2), fchmod(2), fchown(2), fgetxattr(2), ioctl(2), + * mmap(2)) fail with the error EBADF. + * + * The following subset of operations that is relevant to Samba is allowed: + * + * - close(2), + * - fchdir(2), if the file descriptor refers to a directory, + * - fstat(2), + * - fstatfs(2) and + * - passing the file descriptor as the dirfd argument of openat() and the + * other "*at()" system calls. This includes linkat(2) with + * AT_EMPTY_PATH (or via procfs using AT_SYMLINK_FOLLOW) even if the + * file is not a directory. + * + * Opening a file or directory with the O_PATH flag requires no + * permissions on the object itself (but does require execute permission + * on the directories in the path prefix). By contrast, obtaining a + * reference to a filesystem object by opening it with the O_RDONLY flag + * requires that the caller have read permission on the object, even when + * the subsequent operation (e.g., fchdir(2), fstat(2)) does not require + * read permission on the object. [1] + * + * If for example Samba receives an SMB request to open a file requesting + * SEC_FILE_READ_ATTRIBUTE access rights because the client wants to read + * the file's metadata from the handle, Samba will have to call POSIX + * open() with at least O_RDONLY access rights. + * + * Usecase for O_PATH in Samba + * --------------------------- + * + * By leveraging this Linux specific flags we can avoid permission + * mismatches as described above. Additionally O_PATH allows basing all + * filesystem accesses done by the fileserver on handle based syscalls by + * opening all client pathnames with O_PATH and consistently using for + * example fstat() instead of stat() throughout the codebase. + * + * Subsequently we will refer to Samba file-handles (fsp's) opened with + * O_PATH "path referencing fsp's" or "pathref" fsp's for short. + * + * Currently Samba bases the decision whether to call POSIX open() on a + * client pathname or whether to leave the low-level handle at -1, what we + * call a stat-open, in the function open_file() and it is based on the + * client requested SMB acccess mask. + * + * The set of rights that trigger an open() include READ_CONTROL_ACCESS, + * resulting in a call to open() with at least O_RDONLY. If the filesystem + * supports NT style ACLs natively (like GPFS or ZFS), the filesystem may + * grant the user requested right READ_CONTROL_ACCESS, but it may not + * grant READ_DATA (O_RDONLY), resulting in a permission denied error. + * + * Historically the set of access rights that triggered opening a file was: + * + * FILE_READ_DATA + * FILE_WRITE_DATA + * FILE_APPEND_DATA + * FILE_EXECUTE + * WRITE_DAC_ACCESS + * WRITE_OWNER_ACCESS + * SEC_FLAG_SYSTEM_SECURITY + * READ_CONTROL_ACCESS + * + * By using O_PATH this can be trimmed down to + * + * FILE_READ_DATA + * FILE_WRITE_DATA + * FILE_APPEND_DATA + * FILE_EXECUTE + * + * Fallback on systems without O_PATH support + * ------------------------------------------ + * + * A fallback is needed that allows opening a file-handle with the same + * higher level semantics even if the system doesn't support O_PATH. This + * is implemented by impersonating the root user for the open() + * syscall. To avoid bypassing restrictive permissions on intermediate + * directories components of a path, the root user is only impersonated + * after changing directory to the parent directory of the client + * requested pathname. + * + * In order to avoid privilege escalation security issues with these root + * opened file-handles we must carefully control their usage throughout + * the codebase. Therefore we + * + * - tag the pathref fsp's with the flag "is_pathref" and + * + * - control access to the file-handle by making the structure private and only + * allowing access with accessor functions. + * + * Two functions are used to fetch the low-level system file-handle from an fsp + * + * - fsp_get_io_fd(fsp): enforces fsp is NOT a pathref file-handle and + * + * - fsp_get_pathref_fd(fsp): allows fsp to be either a pathref file-handle or a + * traditional POSIX file-handle opened with O_RDONLY or any other POSIX open + * flag. + * + * The general guideline when to use which function is: + * + * - if you do something like fstat(fd), use fsp_get_pathref_fd(fsp), + * - if you do something like *at(dirfd, ...), use fsp_get_pathref_fd(fsp), + * - if you want to print the fd for example in DEBUG messages, use + * fsp_get_pathref_fd(fsp), + * - if you want to call close(fd), use fsp_get_pathref_fd(fsp), + * - if you're doing a logical comparison of fd values, use + * fsp_get_pathref_fd(). + * + * In any other case use fsp_get_io_fd(). + */ + +#define FSP_POSIX_FLAGS_OPEN 0x01 +#define FSP_POSIX_FLAGS_RENAME 0x02 +#define FSP_POSIX_FLAGS_PATHNAMES 0x04 + +#define FSP_POSIX_FLAGS_ALL \ + (FSP_POSIX_FLAGS_OPEN | \ + FSP_POSIX_FLAGS_PATHNAMES | \ + FSP_POSIX_FLAGS_RENAME) + +struct vuid_cache_entry { + struct auth_session_info *session_info; + uint64_t vuid; /* SMB2 compat */ + bool read_only; + uint32_t share_access; +}; + +struct vuid_cache { + unsigned int next_entry; + struct vuid_cache_entry array[VUID_CACHE_SIZE]; +}; + +typedef struct { + char *name; + bool is_wild; +} name_compare_entry; + +struct share_params { + int service; +}; + +typedef struct connection_struct { + struct connection_struct *next, *prev; + struct smbd_server_connection *sconn; /* can be NULL */ + struct smbXsrv_tcon *tcon; /* can be NULL */ + uint32_t cnum; /* an index passed over the wire */ + struct share_params *params; + bool force_user; + struct vuid_cache *vuid_cache; + bool printer; + bool ipc; + bool read_only; /* Attributes for the current user of the share. */ + bool have_proc_fds; + uint64_t open_how_resolve; /* supported vfs_open_how.resolve features */ + uint32_t share_access; + /* Does this filesystem honor + sub second timestamps on files + and directories when setting time ? */ + enum timestamp_set_resolution ts_res; + char *connectpath; + struct files_struct *cwd_fsp; /* Working directory. */ + bool tcon_done; + + struct vfs_handle_struct *vfs_handles; /* for the new plugins */ + + /* + * This represents the user information on this connection. Depending + * on the vuid using this tid, this might change per SMB request. + */ + struct auth_session_info *session_info; + + /* + * If the "force group" parameter is set, this is the primary gid that + * may be used in the users token, depending on the vuid using this tid. + */ + gid_t force_group_gid; + + uint64_t vuid; /* vuid of user who *opened* this connection, or UID_FIELD_INVALID */ + + time_t lastused; + time_t lastused_count; + int num_files_open; + unsigned int num_smb_operations; /* Count of smb operations on this tree. */ + int encrypt_level; + bool encrypted_tid; + + /* Semantics requested by the client or forced by the server config. */ + bool case_sensitive; + bool case_preserve; + bool short_case_preserve; + + /* Semantics provided by the underlying filesystem. */ + int fs_capabilities; + /* Device number of the directory of the share mount. + Used to ensure unique FileIndex returns. */ + SMB_DEV_T base_share_dev; + + name_compare_entry *hide_list; /* Per-share list of files to return as hidden. */ + name_compare_entry *veto_list; /* Per-share list of files to veto (never show). */ + name_compare_entry *veto_oplock_list; /* Per-share list of files to refuse oplocks on. */ + name_compare_entry *aio_write_behind_list; /* Per-share list of files to use aio write behind on. */ + struct trans_state *pending_trans; + + struct rpc_pipe_client *spoolss_pipe; + +} connection_struct; + +struct smbd_smb2_request; +struct referral; + +struct smb_request { + uint8_t cmd; + uint16_t flags2; + uint16_t smbpid; + uint64_t mid; /* For compatibility with SMB2. */ + uint32_t seqnum; + uint64_t vuid; /* For compatibility with SMB2. */ + uint32_t tid; + uint8_t wct; + const uint16_t *vwv; + uint16_t buflen; + const uint8_t *buf; + const uint8_t *inbuf; + + /* + * Async handling in the main smb processing loop is directed by + * outbuf: reply_xxx routines indicate sync behaviour by putting their + * reply into "outbuf". If they leave it as NULL, they take care of it + * themselves, possibly later. + * + * If async handling is wanted, the reply_xxx routine must make sure + * that it talloc_move()s the smb_req somewhere else. + */ + uint8_t *outbuf; + + size_t unread_bytes; + bool encrypted; + connection_struct *conn; + struct smbd_server_connection *sconn; + struct smbXsrv_connection *xconn; + + /* + * Pointer to session, can be NULL, + * eg during negprot and session setup. + */ + struct smbXsrv_session *session; + + struct smb_perfcount_data pcd; + + /* + * Chained request handling + */ + struct files_struct *chain_fsp; + + /* + * state information for async smb handling + */ + void *async_priv; + + /* + * Back pointer to smb2 request. + */ + struct smbd_smb2_request *smb2req; + + /* + * Request list for chained requests, we're part of it. + */ + struct smb_request **chain; + + struct timeval request_time; + + bool posix_pathnames; +}; + +/* + * Info about an alternate data stream + */ + +struct stream_struct { + off_t size; + off_t alloc_size; + char *name; +}; + +/* time info */ +struct smb_file_time { + struct timespec mtime; + struct timespec atime; + struct timespec ctime; + struct timespec create_time; +}; + +/* + * smb_filename + */ +struct smb_filename { + char *base_name; + char *stream_name; + uint32_t flags; + SMB_STRUCT_STAT st; + NTTIME twrp; + + /* + * Internal file handle, O_PATH based if available, + * otherwise O_RDONLY as root. + */ + struct files_struct *fsp; + + /* + * Link between the struct smb_filename and the above + * fsp. fsp_link is a talloc child of the fsp. Ensures a possible + * talloc_free(fsp) resets the smb_fname->fsp pointer to NULL in + * the is fsp_link talloc destructor. + */ + struct fsp_smb_fname_link *fsp_link; +}; + +/* + * smb_filename flags. Define in terms of the FSP_POSIX_FLAGS_XX + * to keep the numeric values consistent. + */ + +#define SMB_FILENAME_POSIX_PATH FSP_POSIX_FLAGS_PATHNAMES + +#define VFS_FIND(__fn__) while (handle->fns->__fn__##_fn==NULL) { \ + handle = handle->next; \ + } + +enum vfs_translate_direction { + vfs_translate_to_unix = 0, + vfs_translate_to_windows +}; + +enum vfs_fallocate_flags { + VFS_FALLOCATE_FL_KEEP_SIZE = 0x0001, + VFS_FALLOCATE_FL_PUNCH_HOLE = 0x0002, +}; + +struct vfs_aio_state { + int error; + uint64_t duration; +}; + +#define VFS_OPEN_HOW_RESOLVE_NO_SYMLINKS 1 + +struct vfs_open_how { + int flags; + mode_t mode; + uint64_t resolve; +}; + +/* + Available VFS operations. These values must be in sync with vfs_ops struct + (struct vfs_fn_pointers and struct vfs_handle_pointers inside of struct vfs_ops). + In particular, if new operations are added to vfs_ops, appropriate constants + should be added to vfs_op_type so that order of them kept same as in vfs_ops. +*/ +struct shadow_copy_data; + +struct vfs_fn_pointers { + /* Disk operations */ + + int (*connect_fn)(struct vfs_handle_struct *handle, const char *service, const char *user); + void (*disconnect_fn)(struct vfs_handle_struct *handle); + uint64_t (*disk_free_fn)(struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + uint64_t *bsize, + uint64_t *dfree, + uint64_t *dsize); + int (*get_quota_fn)(struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + enum SMB_QUOTA_TYPE qtype, + unid_t id, + SMB_DISK_QUOTA *qt); + int (*set_quota_fn)(struct vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt); + int (*get_shadow_copy_data_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, struct shadow_copy_data *shadow_copy_data, bool labels); + int (*statvfs_fn)(struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + struct vfs_statvfs_struct *statbuf); + uint32_t (*fs_capabilities_fn)(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res); + + /* + * Note: that "struct dfs_GetDFSReferral *r" + * needs to be a valid TALLOC_CTX + */ + NTSTATUS (*get_dfs_referrals_fn)(struct vfs_handle_struct *handle, + struct dfs_GetDFSReferral *r); + NTSTATUS (*create_dfs_pathat_fn)(struct vfs_handle_struct *handle, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + const struct referral *reflist, + size_t referral_count); + NTSTATUS (*read_dfs_pathat_fn)(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *dirfsp, + struct smb_filename *smb_fname, + struct referral **ppreflist, + size_t *preferral_count); + + /* Directory operations */ + + DIR *(*fdopendir_fn)(struct vfs_handle_struct *handle, files_struct *fsp, const char *mask, uint32_t attributes); + struct dirent *(*readdir_fn)(struct vfs_handle_struct *handle, + struct files_struct *dirfsp, + DIR *dirp, + SMB_STRUCT_STAT *sbuf); + void (*seekdir_fn)(struct vfs_handle_struct *handle, DIR *dirp, long offset); + long (*telldir_fn)(struct vfs_handle_struct *handle, DIR *dirp); + void (*rewind_dir_fn)(struct vfs_handle_struct *handle, DIR *dirp); + int (*mkdirat_fn)(struct vfs_handle_struct *handle, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + mode_t mode); + int (*closedir_fn)(struct vfs_handle_struct *handle, DIR *dir); + + /* File operations */ + + int (*openat_fn)(struct vfs_handle_struct *handle, + const struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + struct files_struct *fsp, + const struct vfs_open_how *how); + NTSTATUS (*create_file_fn)(struct vfs_handle_struct *handle, + struct smb_request *req, + struct files_struct *dirfsp, + struct smb_filename *smb_fname, + uint32_t access_mask, + uint32_t share_access, + uint32_t create_disposition, + uint32_t create_options, + uint32_t file_attributes, + uint32_t oplock_request, + const struct smb2_lease *lease, + uint64_t allocation_size, + uint32_t private_flags, + struct security_descriptor *sd, + struct ea_list *ea_list, + files_struct **result, + int *pinfo, + const struct smb2_create_blobs *in_context_blobs, + struct smb2_create_blobs *out_context_blobs); + int (*close_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp); + ssize_t (*pread_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, void *data, size_t n, off_t offset); + struct tevent_req *(*pread_send_fn)(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct files_struct *fsp, + void *data, + size_t n, off_t offset); + ssize_t (*pread_recv_fn)(struct tevent_req *req, struct vfs_aio_state *state); + ssize_t (*pwrite_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, const void *data, size_t n, off_t offset); + struct tevent_req *(*pwrite_send_fn)(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct files_struct *fsp, + const void *data, + size_t n, off_t offset); + ssize_t (*pwrite_recv_fn)(struct tevent_req *req, struct vfs_aio_state *state); + off_t (*lseek_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, off_t offset, int whence); + ssize_t (*sendfile_fn)(struct vfs_handle_struct *handle, int tofd, files_struct *fromfsp, const DATA_BLOB *header, off_t offset, size_t count); + ssize_t (*recvfile_fn)(struct vfs_handle_struct *handle, int fromfd, files_struct *tofsp, off_t offset, size_t count); + int (*renameat_fn)(struct vfs_handle_struct *handle, + struct files_struct *srcdir_fsp, + const struct smb_filename *smb_fname_src, + struct files_struct *dstdir_fsp, + const struct smb_filename *smb_fname_dst); + struct tevent_req *(*fsync_send_fn)(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct files_struct *fsp); + int (*fsync_recv_fn)(struct tevent_req *req, struct vfs_aio_state *state); + int (*stat_fn)(struct vfs_handle_struct *handle, struct smb_filename *smb_fname); + int (*fstat_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_STAT *sbuf); + int (*lstat_fn)(struct vfs_handle_struct *handle, struct smb_filename *smb_filename); + int (*fstatat_fn)( + struct vfs_handle_struct *handle, + const struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + SMB_STRUCT_STAT *sbuf, + int flags); + uint64_t (*get_alloc_size_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, const SMB_STRUCT_STAT *sbuf); + int (*unlinkat_fn)(struct vfs_handle_struct *handle, + struct files_struct *srcdir_fsp, + const struct smb_filename *smb_fname, + int flags); + int (*fchmod_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, mode_t mode); + int (*fchown_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, uid_t uid, gid_t gid); + int (*lchown_fn)(struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + uid_t uid, + gid_t gid); + int (*chdir_fn)(struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname); + struct smb_filename *(*getwd_fn)(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx); + int (*fntimes_fn)(struct vfs_handle_struct *handle, + struct files_struct *fsp, + struct smb_file_time *ft); + int (*ftruncate_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, off_t offset); + int (*fallocate_fn)(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t mode, + off_t offset, + off_t len); + bool (*lock_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, off_t offset, off_t count, int type); + int (*filesystem_sharemode_fn)(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t share_access, uint32_t + access_mask); + int (*fcntl_fn)(struct vfs_handle_struct *handle, + struct files_struct *fsp, int cmd, va_list cmd_arg); + int (*linux_setlease_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, int leasetype); + bool (*getlock_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid); + int (*symlinkat_fn)(struct vfs_handle_struct *handle, + const struct smb_filename *link_contents, + struct files_struct *dirfsp, + const struct smb_filename *new_smb_fname); + int (*readlinkat_fn)(struct vfs_handle_struct *handle, + const struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + char *buf, + size_t bufsiz); + int (*linkat_fn)(struct vfs_handle_struct *handle, + struct files_struct *srcfsp, + const struct smb_filename *old_smb_fname, + struct files_struct *dstfsp, + const struct smb_filename *new_smb_fname, + int flags); + int (*mknodat_fn)(struct vfs_handle_struct *handle, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + mode_t mode, + SMB_DEV_T dev); + struct smb_filename *(*realpath_fn)(struct vfs_handle_struct *handle, + TALLOC_CTX *ctx, + const struct smb_filename *smb_fname); + int (*fchflags_fn)(struct vfs_handle_struct *handle, + struct files_struct *fsp, + unsigned int flags); + struct file_id (*file_id_create_fn)(struct vfs_handle_struct *handle, + const SMB_STRUCT_STAT *sbuf); + uint64_t (*fs_file_id_fn)(struct vfs_handle_struct *handle, + const SMB_STRUCT_STAT *sbuf); + struct tevent_req *(*offload_read_send_fn)(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t fsctl, + uint32_t ttl, + off_t offset, + size_t to_copy); + NTSTATUS (*offload_read_recv_fn)(struct tevent_req *req, + struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + uint32_t *flags, + uint64_t *xferlen, + DATA_BLOB *token_blob); + struct tevent_req *(*offload_write_send_fn)(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + uint32_t fsctl, + DATA_BLOB *token, + off_t transfer_offset, + struct files_struct *dest_fsp, + off_t dest_off, + off_t to_copy); + NTSTATUS (*offload_write_recv_fn)(struct vfs_handle_struct *handle, + struct tevent_req *req, + off_t *copied); + NTSTATUS (*fget_compression_fn)(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *fsp, + uint16_t *_compression_fmt); + NTSTATUS (*set_compression_fn)(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *fsp, + uint16_t compression_fmt); + NTSTATUS (*snap_check_path_fn)(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + const char *service_path, + char **base_volume); + NTSTATUS (*snap_create_fn)(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + const char *base_volume, + time_t *tstamp, + bool rw, + char **base_path, + char **snap_path); + NTSTATUS (*snap_delete_fn)(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + char *base_path, + char *snap_path); + + NTSTATUS (*fstreaminfo_fn)(struct vfs_handle_struct *handle, + struct files_struct *fsp, + TALLOC_CTX *mem_ctx, + unsigned int *num_streams, + struct stream_struct **streams); + + NTSTATUS (*get_real_filename_at_fn)(struct vfs_handle_struct *handle, + struct files_struct *dirfsp, + const char *name, + TALLOC_CTX *mem_ctx, + char **found_name); + + const char *(*connectpath_fn)(struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname); + + NTSTATUS (*brl_lock_windows_fn)(struct vfs_handle_struct *handle, + struct byte_range_lock *br_lck, + struct lock_struct *plock); + + bool (*brl_unlock_windows_fn)(struct vfs_handle_struct *handle, + struct byte_range_lock *br_lck, + const struct lock_struct *plock); + + bool (*strict_lock_check_fn)(struct vfs_handle_struct *handle, + struct files_struct *fsp, + struct lock_struct *plock); + + NTSTATUS (*translate_name_fn)(struct vfs_handle_struct *handle, + const char *name, + enum vfs_translate_direction direction, + TALLOC_CTX *mem_ctx, + char **mapped_name); + + NTSTATUS (*parent_pathname_fn)(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + const struct smb_filename *smb_fname_in, + struct smb_filename **parent_dir_out, + struct smb_filename **atname_out); + + NTSTATUS (*fsctl_fn)(struct vfs_handle_struct *handle, + struct files_struct *fsp, + TALLOC_CTX *ctx, + uint32_t function, + uint16_t req_flags, + const uint8_t *_in_data, + uint32_t in_len, + uint8_t **_out_data, + uint32_t max_out_len, + uint32_t *out_len); + + NTSTATUS (*fget_dos_attributes_fn)(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t *dosmode); + + NTSTATUS (*fset_dos_attributes_fn)(struct vfs_handle_struct *hande, + struct files_struct *fsp, + uint32_t dosmode); + + struct tevent_req *(*get_dos_attributes_send_fn)( + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct vfs_handle_struct *handle, + files_struct *dir_fsp, + struct smb_filename *smb_fname); + + NTSTATUS (*get_dos_attributes_recv_fn)( + struct tevent_req *req, + struct vfs_aio_state *aio_state, + uint32_t *dosmode); + + /* NT ACL operations. */ + + NTSTATUS (*fget_nt_acl_fn)(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t security_info, + TALLOC_CTX *mem_ctx, + struct security_descriptor **ppdesc); + NTSTATUS (*fset_nt_acl_fn)(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t security_info_sent, + const struct security_descriptor *psd); + + NTSTATUS (*audit_file_fn)(struct vfs_handle_struct *handle, + struct smb_filename *file, + struct security_acl *sacl, + uint32_t access_requested, + uint32_t access_denied); + + /* POSIX ACL operations. */ + + SMB_ACL_T (*sys_acl_get_fd_fn)(struct vfs_handle_struct *handle, + struct files_struct *fsp, + SMB_ACL_TYPE_T type, + TALLOC_CTX *mem_ctx); + int (*sys_acl_blob_get_fd_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, + TALLOC_CTX *mem_ctx, char **blob_description, + DATA_BLOB *blob); + int (*sys_acl_set_fd_fn)(struct vfs_handle_struct *handle, + struct files_struct *fsp, + SMB_ACL_TYPE_T type, + SMB_ACL_T theacl); + int (*sys_acl_delete_def_fd_fn)(struct vfs_handle_struct *handle, + struct files_struct *fsp); + + /* EA operations. */ + struct tevent_req *(*getxattrat_send_fn)( + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct vfs_handle_struct *handle, + files_struct *dir_fsp, + const struct smb_filename *smb_fname, + const char *xattr_name, + size_t alloc_hint); + ssize_t (*getxattrat_recv_fn)(struct tevent_req *req, + struct vfs_aio_state *aio_state, + TALLOC_CTX *mem_ctx, + uint8_t **xattr_value); + ssize_t (*fgetxattr_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, const char *name, void *value, size_t size); + ssize_t (*flistxattr_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, char *list, size_t size); + int (*fremovexattr_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, const char *name); + int (*fsetxattr_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, const char *name, const void *value, size_t size, int flags); + + /* aio operations */ + bool (*aio_force_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp); + + /* durable handle operations */ + NTSTATUS (*durable_cookie_fn)(struct vfs_handle_struct *handle, + struct files_struct *fsp, + TALLOC_CTX *mem_ctx, + DATA_BLOB *cookie); + NTSTATUS (*durable_disconnect_fn)(struct vfs_handle_struct *handle, + struct files_struct *fsp, + const DATA_BLOB old_cookie, + TALLOC_CTX *mem_ctx, + DATA_BLOB *new_cookie); + NTSTATUS (*durable_reconnect_fn)(struct vfs_handle_struct *handle, + struct smb_request *smb1req, + struct smbXsrv_open *op, + const DATA_BLOB old_cookie, + TALLOC_CTX *mem_ctx, + struct files_struct **fsp, + DATA_BLOB *new_cookie); + + NTSTATUS (*freaddir_attr_fn)(struct vfs_handle_struct *handle, + struct files_struct *fsp, + TALLOC_CTX *mem_ctx, + struct readdir_attr_data **attr_data); +}; + +/* + VFS operation description. Each VFS module registers an array of vfs_op_tuple to VFS subsystem, + which describes all operations this module is willing to intercept. + VFS subsystem initializes then the conn->vfs_ops and conn->vfs_opaque_ops structs + using this information. +*/ + +typedef struct vfs_handle_struct { + struct vfs_handle_struct *next, *prev; + const char *param; + struct connection_struct *conn; + const struct vfs_fn_pointers *fns; + void *data; + void (*free_data)(void **data); +} vfs_handle_struct; + + +struct vfs_statvfs_struct { + /* For undefined recommended transfer size return -1 in that field */ + uint32_t OptimalTransferSize; /* bsize on some os, iosize on other os */ + uint32_t BlockSize; + + /* + The next three fields are in terms of the block size. + (above). If block size is unknown, 4096 would be a + reasonable block size for a server to report. + Note that returning the blocks/blocksavail removes need + to make a second call (to QFSInfo level 0x103 to get this info. + UserBlockAvail is typically less than or equal to BlocksAvail, + if no distinction is made return the same value in each. + */ + + uint64_t TotalBlocks; + uint64_t BlocksAvail; /* bfree */ + uint64_t UserBlocksAvail; /* bavail */ + + /* For undefined Node fields or FSID return -1 */ + uint64_t TotalFileNodes; + uint64_t FreeFileNodes; + uint64_t FsIdentifier; /* fsid */ + /* NB Namelen comes from FILE_SYSTEM_ATTRIBUTE_INFO call */ + /* NB flags can come from FILE_SYSTEM_DEVICE_INFO call */ + + int FsCapabilities; +}; + +/* Add a new FSP extension of the given type. Returns a pointer to the + * extenstion data. + */ +#define VFS_ADD_FSP_EXTENSION(handle, fsp, type, destroy_fn) \ + (type *)vfs_add_fsp_extension_notype(handle, (fsp), sizeof(type), (destroy_fn)) + +/* Return a pointer to the existing FSP extension data. */ +#define VFS_FETCH_FSP_EXTENSION(handle, fsp) \ + vfs_fetch_fsp_extension(handle, (fsp)) + +/* Return the talloc context associated with an FSP extension. */ +#define VFS_MEMCTX_FSP_EXTENSION(handle, fsp) \ + vfs_memctx_fsp_extension(handle, (fsp)) + +/* Remove and destroy an FSP extension. */ +#define VFS_REMOVE_FSP_EXTENSION(handle, fsp) \ + vfs_remove_fsp_extension((handle), (fsp)) + +#define SMB_VFS_HANDLE_GET_DATA(handle, datap, type, ret) { \ + if (!(handle)||((datap=(type *)(handle)->data)==NULL)) { \ + DEBUG(0,("%s() failed to get vfs_handle->data!\n",__FUNCTION__)); \ + ret; \ + } \ +} + +#define SMB_VFS_HANDLE_SET_DATA(handle, datap, free_fn, type, ret) { \ + if (!(handle)) { \ + DEBUG(0,("%s() failed to set handle->data!\n",__FUNCTION__)); \ + ret; \ + } else { \ + if ((handle)->free_data) { \ + (handle)->free_data(&(handle)->data); \ + } \ + (handle)->data = (void *)datap; \ + (handle)->free_data = free_fn; \ + } \ +} + +#define SMB_VFS_HANDLE_FREE_DATA(handle) { \ + if ((handle) && (handle)->free_data) { \ + (handle)->free_data(&(handle)->data); \ + } \ +} + +/* Check whether module-specific data handle was already allocated or not */ +#define SMB_VFS_HANDLE_TEST_DATA(handle) ( !(handle) || !(handle)->data ? False : True ) + +#define SMB_VFS_OP(x) ((void *) x) + +#define DEFAULT_VFS_MODULE_NAME "/[Default VFS]/" + +#include "vfs_macros.h" + +int smb_vfs_call_connect(struct vfs_handle_struct *handle, + const char *service, const char *user); +void smb_vfs_call_disconnect(struct vfs_handle_struct *handle); +uint64_t smb_vfs_call_disk_free(struct vfs_handle_struct *handle, + const struct smb_filename *smb_filename, + uint64_t *bsize, + uint64_t *dfree, + uint64_t *dsize); +int smb_vfs_call_get_quota(struct vfs_handle_struct *handle, + const struct smb_filename *smb_filename, + enum SMB_QUOTA_TYPE qtype, + unid_t id, + SMB_DISK_QUOTA *qt); +int smb_vfs_call_set_quota(struct vfs_handle_struct *handle, + enum SMB_QUOTA_TYPE qtype, unid_t id, + SMB_DISK_QUOTA *qt); +int smb_vfs_call_get_shadow_copy_data(struct vfs_handle_struct *handle, + struct files_struct *fsp, + struct shadow_copy_data *shadow_copy_data, + bool labels); +int smb_vfs_call_statvfs(struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + struct vfs_statvfs_struct *statbuf); +uint32_t smb_vfs_call_fs_capabilities(struct vfs_handle_struct *handle, + enum timestamp_set_resolution *p_ts_res); +/* + * Note: that "struct dfs_GetDFSReferral *r" needs to be a valid TALLOC_CTX + */ +NTSTATUS smb_vfs_call_get_dfs_referrals(struct vfs_handle_struct *handle, + struct dfs_GetDFSReferral *r); +NTSTATUS smb_vfs_call_create_dfs_pathat(struct vfs_handle_struct *handle, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + const struct referral *reflist, + size_t referral_count); +NTSTATUS smb_vfs_call_read_dfs_pathat(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *dirfsp, + struct smb_filename *smb_fname, + struct referral **ppreflist, + size_t *preferral_count); +DIR *smb_vfs_call_fdopendir(struct vfs_handle_struct *handle, + struct files_struct *fsp, + const char *mask, + uint32_t attributes); +struct dirent *smb_vfs_call_readdir(struct vfs_handle_struct *handle, + struct files_struct *dirfsp, + DIR *dirp, + SMB_STRUCT_STAT *sbuf); +void smb_vfs_call_seekdir(struct vfs_handle_struct *handle, + DIR *dirp, long offset); +long smb_vfs_call_telldir(struct vfs_handle_struct *handle, + DIR *dirp); +void smb_vfs_call_rewind_dir(struct vfs_handle_struct *handle, + DIR *dirp); +int smb_vfs_call_mkdirat(struct vfs_handle_struct *handle, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + mode_t mode); +int smb_vfs_call_closedir(struct vfs_handle_struct *handle, + DIR *dir); +int smb_vfs_call_openat(struct vfs_handle_struct *handle, + const struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + struct files_struct *fsp, + const struct vfs_open_how *how); +NTSTATUS smb_vfs_call_create_file(struct vfs_handle_struct *handle, + struct smb_request *req, + struct files_struct *dirfsp, + struct smb_filename *smb_fname, + uint32_t access_mask, + uint32_t share_access, + uint32_t create_disposition, + uint32_t create_options, + uint32_t file_attributes, + uint32_t oplock_request, + const struct smb2_lease *lease, + uint64_t allocation_size, + uint32_t private_flags, + struct security_descriptor *sd, + struct ea_list *ea_list, + files_struct **result, + int *pinfo, + const struct smb2_create_blobs *in_context_blobs, + struct smb2_create_blobs *out_context_blobs); +int smb_vfs_call_close(struct vfs_handle_struct *handle, + struct files_struct *fsp); +ssize_t smb_vfs_call_pread(struct vfs_handle_struct *handle, + struct files_struct *fsp, void *data, size_t n, + off_t offset); +struct tevent_req *smb_vfs_call_pread_send(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct files_struct *fsp, + void *data, + size_t n, off_t offset); +ssize_t SMB_VFS_PREAD_RECV(struct tevent_req *req, struct vfs_aio_state *state); + +ssize_t smb_vfs_call_pwrite(struct vfs_handle_struct *handle, + struct files_struct *fsp, const void *data, + size_t n, off_t offset); +struct tevent_req *smb_vfs_call_pwrite_send(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct files_struct *fsp, + const void *data, + size_t n, off_t offset); +ssize_t SMB_VFS_PWRITE_RECV(struct tevent_req *req, struct vfs_aio_state *state); + +off_t smb_vfs_call_lseek(struct vfs_handle_struct *handle, + struct files_struct *fsp, off_t offset, + int whence); +ssize_t smb_vfs_call_sendfile(struct vfs_handle_struct *handle, int tofd, + files_struct *fromfsp, const DATA_BLOB *header, + off_t offset, size_t count); +ssize_t smb_vfs_call_recvfile(struct vfs_handle_struct *handle, int fromfd, + files_struct *tofsp, off_t offset, + size_t count); +int smb_vfs_call_renameat(struct vfs_handle_struct *handle, + struct files_struct *srcfsp, + const struct smb_filename *smb_fname_src, + struct files_struct *dstfsp, + const struct smb_filename *smb_fname_dst); + +struct tevent_req *smb_vfs_call_fsync_send(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct files_struct *fsp); +int SMB_VFS_FSYNC_RECV(struct tevent_req *req, struct vfs_aio_state *state); + +int smb_vfs_fsync_sync(files_struct *fsp); +int smb_vfs_call_stat(struct vfs_handle_struct *handle, + struct smb_filename *smb_fname); +int smb_vfs_call_fstat(struct vfs_handle_struct *handle, + struct files_struct *fsp, SMB_STRUCT_STAT *sbuf); +int smb_vfs_call_lstat(struct vfs_handle_struct *handle, + struct smb_filename *smb_filename); +int smb_vfs_call_fstatat( + struct vfs_handle_struct *handle, + const struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + SMB_STRUCT_STAT *sbuf, + int flags); +uint64_t smb_vfs_call_get_alloc_size(struct vfs_handle_struct *handle, + struct files_struct *fsp, + const SMB_STRUCT_STAT *sbuf); +int smb_vfs_call_unlinkat(struct vfs_handle_struct *handle, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + int flags); +int smb_vfs_call_fchmod(struct vfs_handle_struct *handle, + struct files_struct *fsp, mode_t mode); +int smb_vfs_call_fchown(struct vfs_handle_struct *handle, + struct files_struct *fsp, uid_t uid, gid_t gid); +int smb_vfs_call_lchown(struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + uid_t uid, + gid_t gid); +int smb_vfs_call_chdir(struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname); +struct smb_filename *smb_vfs_call_getwd(struct vfs_handle_struct *handle, + TALLOC_CTX *ctx); +int smb_vfs_call_ntimes(struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + struct smb_file_time *ft); +int smb_vfs_call_fntimes(struct vfs_handle_struct *handle, + struct files_struct *fsp, + struct smb_file_time *ft); +int smb_vfs_call_ftruncate(struct vfs_handle_struct *handle, + struct files_struct *fsp, off_t offset); +int smb_vfs_call_fallocate(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t mode, + off_t offset, + off_t len); +bool smb_vfs_call_lock(struct vfs_handle_struct *handle, + struct files_struct *fsp, int op, off_t offset, + off_t count, int type); +int smb_vfs_call_filesystem_sharemode(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t share_access, + uint32_t access_mask); +int smb_vfs_call_fcntl(struct vfs_handle_struct *handle, + struct files_struct *fsp, int cmd, ...); +int smb_vfs_call_linux_setlease(struct vfs_handle_struct *handle, + struct files_struct *fsp, int leasetype); +bool smb_vfs_call_getlock(struct vfs_handle_struct *handle, + struct files_struct *fsp, off_t *poffset, + off_t *pcount, int *ptype, pid_t *ppid); +int smb_vfs_call_symlinkat(struct vfs_handle_struct *handle, + const struct smb_filename *link_contents, + struct files_struct *dirfsp, + const struct smb_filename *new_smb_fname); +int smb_vfs_call_readlinkat(struct vfs_handle_struct *handle, + const struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + char *buf, + size_t bufsiz); +int smb_vfs_call_linkat(struct vfs_handle_struct *handle, + struct files_struct *srcfsp, + const struct smb_filename *old_smb_fname, + struct files_struct *dstfsp, + const struct smb_filename *new_smb_fname, + int flags); +int smb_vfs_call_mknodat(struct vfs_handle_struct *handle, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + mode_t mode, + SMB_DEV_T dev); +struct smb_filename *smb_vfs_call_realpath(struct vfs_handle_struct *handle, + TALLOC_CTX *ctx, + const struct smb_filename *smb_fname); +int smb_vfs_call_chflags(struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + unsigned int flags); +int smb_vfs_call_fchflags(struct vfs_handle_struct *handle, + struct files_struct *fsp, + unsigned int flags); +struct file_id smb_vfs_call_file_id_create(struct vfs_handle_struct *handle, + const SMB_STRUCT_STAT *sbuf); +uint64_t smb_vfs_call_fs_file_id(struct vfs_handle_struct *handle, + const SMB_STRUCT_STAT *sbuf); +NTSTATUS smb_vfs_call_fstreaminfo(struct vfs_handle_struct *handle, + struct files_struct *fsp, + TALLOC_CTX *mem_ctx, + unsigned int *num_streams, + struct stream_struct **streams); +NTSTATUS smb_vfs_call_get_real_filename_at(struct vfs_handle_struct *handle, + struct files_struct *dirfsp, + const char *name, + TALLOC_CTX *mem_ctx, + char **found_name); +const char *smb_vfs_call_connectpath(struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname); +NTSTATUS smb_vfs_call_brl_lock_windows(struct vfs_handle_struct *handle, + struct byte_range_lock *br_lck, + struct lock_struct *plock); +bool smb_vfs_call_brl_unlock_windows(struct vfs_handle_struct *handle, + struct byte_range_lock *br_lck, + const struct lock_struct *plock); +bool smb_vfs_call_strict_lock_check(struct vfs_handle_struct *handle, + struct files_struct *fsp, + struct lock_struct *plock); +NTSTATUS smb_vfs_call_translate_name(struct vfs_handle_struct *handle, + const char *name, + enum vfs_translate_direction direction, + TALLOC_CTX *mem_ctx, + char **mapped_name); +NTSTATUS smb_vfs_call_parent_pathname(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + const struct smb_filename *smb_fname_in, + struct smb_filename **parent_dir_out, + struct smb_filename **atname_out); +NTSTATUS smb_vfs_call_fsctl(struct vfs_handle_struct *handle, + struct files_struct *fsp, + TALLOC_CTX *ctx, + uint32_t function, + uint16_t req_flags, + const uint8_t *_in_data, + uint32_t in_len, + uint8_t **_out_data, + uint32_t max_out_len, + uint32_t *out_len); +NTSTATUS smb_vfs_call_fget_dos_attributes(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t *dosmode); +NTSTATUS smb_vfs_call_fset_dos_attributes(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t dosmode); +struct tevent_req *smb_vfs_call_get_dos_attributes_send( + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct vfs_handle_struct *handle, + files_struct *dir_fsp, + struct smb_filename *smb_fname); +NTSTATUS smb_vfs_call_get_dos_attributes_recv( + struct tevent_req *req, + struct vfs_aio_state *aio_state, + uint32_t *dosmode); +struct tevent_req *smb_vfs_call_offload_read_send( + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t fsctl, + uint32_t ttl, + off_t offset, + size_t to_copy); +NTSTATUS smb_vfs_call_offload_read_recv(struct tevent_req *req, + struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + uint32_t *flags, + uint64_t *xferlen, + DATA_BLOB *token_blob); +struct tevent_req *smb_vfs_call_offload_write_send(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + uint32_t fsctl, + DATA_BLOB *token, + off_t transfer_offset, + struct files_struct *dest_fsp, + off_t dest_off, + off_t num); +NTSTATUS smb_vfs_call_offload_write_recv(struct vfs_handle_struct *handle, + struct tevent_req *req, + off_t *copied); +NTSTATUS smb_vfs_call_fget_compression(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *fsp, + uint16_t *_compression_fmt); +NTSTATUS smb_vfs_call_set_compression(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *fsp, + uint16_t compression_fmt); +NTSTATUS smb_vfs_call_snap_check_path(vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + const char *service_path, + char **base_volume); +NTSTATUS smb_vfs_call_snap_create(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + const char *base_volume, + time_t *tstamp, + bool rw, + char **base_path, + char **snap_path); +NTSTATUS smb_vfs_call_snap_delete(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + char *base_path, + char *snap_path); +NTSTATUS smb_vfs_call_fget_nt_acl(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t security_info, + TALLOC_CTX *mem_ctx, + struct security_descriptor **ppdesc); +NTSTATUS smb_vfs_call_get_nt_acl_at(struct vfs_handle_struct *handle, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + uint32_t security_info, + TALLOC_CTX *mem_ctx, + struct security_descriptor **ppdesc); +NTSTATUS smb_vfs_call_fset_nt_acl(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t security_info_sent, + const struct security_descriptor *psd); +NTSTATUS smb_vfs_call_audit_file(struct vfs_handle_struct *handle, + struct smb_filename *file, + struct security_acl *sacl, + uint32_t access_requested, + uint32_t access_denied); +int smb_vfs_call_chmod_acl(struct vfs_handle_struct *handle, + const struct smb_filename *file, + mode_t mode); +SMB_ACL_T smb_vfs_call_sys_acl_get_fd(struct vfs_handle_struct *handle, + struct files_struct *fsp, + SMB_ACL_TYPE_T type, + TALLOC_CTX *mem_ctx); +int smb_vfs_call_sys_acl_blob_get_fd(struct vfs_handle_struct *handle, + struct files_struct *fsp, + TALLOC_CTX *mem_ctx, + char **blob_description, + DATA_BLOB *blob); +int smb_vfs_call_sys_acl_set_fd(struct vfs_handle_struct *handle, + struct files_struct *fsp, + SMB_ACL_TYPE_T type, + SMB_ACL_T theacl); +int smb_vfs_call_sys_acl_delete_def_fd(struct vfs_handle_struct *handle, + struct files_struct *fsp); +struct tevent_req *smb_vfs_call_getxattrat_send( + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct vfs_handle_struct *handle, + files_struct *dir_fsp, + const struct smb_filename *smb_fname, + const char *xattr_name, + size_t alloc_hint); +ssize_t smb_vfs_call_getxattrat_recv(struct tevent_req *req, + struct vfs_aio_state *aio_state, + TALLOC_CTX *mem_ctx, + uint8_t **xattr_value); +ssize_t smb_vfs_call_fgetxattr(struct vfs_handle_struct *handle, + struct files_struct *fsp, const char *name, + void *value, size_t size); +ssize_t smb_vfs_call_flistxattr(struct vfs_handle_struct *handle, + struct files_struct *fsp, char *list, + size_t size); +int smb_vfs_call_fremovexattr(struct vfs_handle_struct *handle, + struct files_struct *fsp, const char *name); +int smb_vfs_call_lsetxattr(struct vfs_handle_struct *handle, const char *path, + const char *name, const void *value, size_t size, + int flags); +int smb_vfs_call_fsetxattr(struct vfs_handle_struct *handle, + struct files_struct *fsp, const char *name, + const void *value, size_t size, int flags); +bool smb_vfs_call_aio_force(struct vfs_handle_struct *handle, + struct files_struct *fsp); +NTSTATUS smb_vfs_call_durable_cookie(struct vfs_handle_struct *handle, + struct files_struct *fsp, + TALLOC_CTX *mem_ctx, + DATA_BLOB *cookie); +NTSTATUS smb_vfs_call_durable_disconnect(struct vfs_handle_struct *handle, + struct files_struct *fsp, + const DATA_BLOB old_cookie, + TALLOC_CTX *mem_ctx, + DATA_BLOB *new_cookie); +NTSTATUS smb_vfs_call_durable_reconnect(struct vfs_handle_struct *handle, + struct smb_request *smb1req, + struct smbXsrv_open *op, + const DATA_BLOB old_cookie, + TALLOC_CTX *mem_ctx, + struct files_struct **fsp, + DATA_BLOB *new_cookie); +NTSTATUS smb_vfs_call_freaddir_attr(struct vfs_handle_struct *handle, + struct files_struct *fsp, + TALLOC_CTX *mem_ctx, + struct readdir_attr_data **attr_data); + +NTSTATUS smb_register_vfs(int version, const char *name, + const struct vfs_fn_pointers *fns); +void *vfs_add_fsp_extension_notype(vfs_handle_struct *handle, + files_struct *fsp, size_t ext_size, + void (*destroy_fn)(void *p_data)); +void vfs_remove_fsp_extension(vfs_handle_struct *handle, files_struct *fsp); +void vfs_remove_all_fsp_extensions(struct files_struct *fsp); +void *vfs_memctx_fsp_extension(vfs_handle_struct *handle, + const struct files_struct *fsp); +void *vfs_fetch_fsp_extension(vfs_handle_struct *handle, const struct files_struct *fsp); + +void smb_vfs_assert_all_fns(const struct vfs_fn_pointers* fns, + const char *module); + +/* + * Helper functions from source3/modules/vfs_not_implemented.c + */ +int vfs_not_implemented_connect( + vfs_handle_struct *handle, + const char *service, + const char *user); +void vfs_not_implemented_disconnect(vfs_handle_struct *handle); +uint64_t vfs_not_implemented_disk_free(vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + uint64_t *bsize, + uint64_t *dfree, + uint64_t *dsize); +int vfs_not_implemented_get_quota(vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + enum SMB_QUOTA_TYPE qtype, + unid_t id, + SMB_DISK_QUOTA *dq); +int vfs_not_implemented_set_quota(vfs_handle_struct *handle, + enum SMB_QUOTA_TYPE qtype, + unid_t id, SMB_DISK_QUOTA *dq); +int vfs_not_implemented_get_shadow_copy_data(vfs_handle_struct *handle, + files_struct *fsp, + struct shadow_copy_data *shadow_copy_data, + bool labels); +int vfs_not_implemented_statvfs(struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + struct vfs_statvfs_struct *statbuf); +uint32_t vfs_not_implemented_fs_capabilities(struct vfs_handle_struct *handle, + enum timestamp_set_resolution *p_ts_res); +NTSTATUS vfs_not_implemented_get_dfs_referrals(struct vfs_handle_struct *handle, + struct dfs_GetDFSReferral *r); +NTSTATUS vfs_not_implemented_create_dfs_pathat(struct vfs_handle_struct *handle, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + const struct referral *reflist, + size_t referral_count); +NTSTATUS vfs_not_implemented_read_dfs_pathat(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *dirfsp, + struct smb_filename *smb_fname, + struct referral **ppreflist, + size_t *preferral_count); +NTSTATUS vfs_not_implemented_snap_check_path(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + const char *service_path, + char **base_volume); +NTSTATUS vfs_not_implemented_snap_create(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + const char *base_volume, + time_t *tstamp, + bool rw, + char **base_path, + char **snap_path); +NTSTATUS vfs_not_implemented_snap_delete(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + char *base_path, + char *snap_path); +DIR *vfs_not_implemented_fdopendir(vfs_handle_struct *handle, files_struct *fsp, + const char *mask, uint32_t attr); +struct dirent *vfs_not_implemented_readdir(vfs_handle_struct *handle, + struct files_struct *dirfsp, + DIR *dirp, + SMB_STRUCT_STAT *sbuf); +void vfs_not_implemented_seekdir(vfs_handle_struct *handle, DIR *dirp, long offset); +long vfs_not_implemented_telldir(vfs_handle_struct *handle, DIR *dirp); +void vfs_not_implemented_rewind_dir(vfs_handle_struct *handle, DIR *dirp); +int vfs_not_implemented_mkdirat(vfs_handle_struct *handle, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + mode_t mode); +int vfs_not_implemented_closedir(vfs_handle_struct *handle, DIR *dir); +int vfs_not_implemented_open(vfs_handle_struct *handle, + struct smb_filename *smb_fname, + files_struct *fsp, int flags, mode_t mode); +int vfs_not_implemented_openat(vfs_handle_struct *handle, + const struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + struct files_struct *fsp, + const struct vfs_open_how *how); +NTSTATUS vfs_not_implemented_create_file(struct vfs_handle_struct *handle, + struct smb_request *req, + struct files_struct *dirfsp, + struct smb_filename *smb_fname, + uint32_t access_mask, + uint32_t share_access, + uint32_t create_disposition, + uint32_t create_options, + uint32_t file_attributes, + uint32_t oplock_request, + const struct smb2_lease *lease, + uint64_t allocation_size, + uint32_t private_flags, + struct security_descriptor *sd, + struct ea_list *ea_list, + files_struct **result, int *pinfo, + const struct smb2_create_blobs *in_context_blobs, + struct smb2_create_blobs *out_context_blobs); +int vfs_not_implemented_close_fn(vfs_handle_struct *handle, files_struct *fsp); +ssize_t vfs_not_implemented_pread(vfs_handle_struct *handle, files_struct *fsp, + void *data, size_t n, off_t offset); +struct tevent_req *vfs_not_implemented_pread_send(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct files_struct *fsp, + void *data, size_t n, off_t offset); +ssize_t vfs_not_implemented_pread_recv(struct tevent_req *req, + struct vfs_aio_state *vfs_aio_state); +ssize_t vfs_not_implemented_pwrite(vfs_handle_struct *handle, files_struct *fsp, + const void *data, size_t n, off_t offset); +struct tevent_req *vfs_not_implemented_pwrite_send(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct files_struct *fsp, + const void *data, + size_t n, off_t offset); +ssize_t vfs_not_implemented_pwrite_recv(struct tevent_req *req, + struct vfs_aio_state *vfs_aio_state); +off_t vfs_not_implemented_lseek(vfs_handle_struct *handle, files_struct *fsp, + off_t offset, int whence); +ssize_t vfs_not_implemented_sendfile(vfs_handle_struct *handle, int tofd, + files_struct *fromfsp, const DATA_BLOB *hdr, + off_t offset, size_t n); +ssize_t vfs_not_implemented_recvfile(vfs_handle_struct *handle, int fromfd, + files_struct *tofsp, off_t offset, size_t n); +int vfs_not_implemented_renameat(vfs_handle_struct *handle, + files_struct *srcfsp, + const struct smb_filename *smb_fname_src, + files_struct *dstfsp, + const struct smb_filename *smb_fname_dst); +struct tevent_req *vfs_not_implemented_fsync_send(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct files_struct *fsp); +int vfs_not_implemented_fsync_recv(struct tevent_req *req, + struct vfs_aio_state *vfs_aio_state); +int vfs_not_implemented_stat(vfs_handle_struct *handle, struct smb_filename *smb_fname); +int vfs_not_implemented_fstat(vfs_handle_struct *handle, files_struct *fsp, + SMB_STRUCT_STAT *sbuf); +int vfs_not_implemented_lstat(vfs_handle_struct *handle, + struct smb_filename *smb_fname); +int vfs_not_implemented_fstatat( + struct vfs_handle_struct *handle, + const struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + SMB_STRUCT_STAT *sbuf, + int flags); +uint64_t vfs_not_implemented_get_alloc_size(struct vfs_handle_struct *handle, + struct files_struct *fsp, + const SMB_STRUCT_STAT *sbuf); +int vfs_not_implemented_unlinkat(vfs_handle_struct *handle, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + int flags); +int vfs_not_implemented_fchmod(vfs_handle_struct *handle, files_struct *fsp, + mode_t mode); +int vfs_not_implemented_fchown(vfs_handle_struct *handle, files_struct *fsp, + uid_t uid, gid_t gid); +int vfs_not_implemented_lchown(vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + uid_t uid, + gid_t gid); +int vfs_not_implemented_chdir(vfs_handle_struct *handle, + const struct smb_filename *smb_fname); +struct smb_filename *vfs_not_implemented_getwd(vfs_handle_struct *handle, + TALLOC_CTX *ctx); +int vfs_not_implemented_ntimes(vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + struct smb_file_time *ft); +int vfs_not_implemented_fntimes(vfs_handle_struct *handle, + files_struct *fsp, + struct smb_file_time *ft); +int vfs_not_implemented_ftruncate(vfs_handle_struct *handle, files_struct *fsp, + off_t offset); +int vfs_not_implemented_fallocate(vfs_handle_struct *handle, files_struct *fsp, + uint32_t mode, off_t offset, off_t len); +bool vfs_not_implemented_lock(vfs_handle_struct *handle, files_struct *fsp, int op, + off_t offset, off_t count, int type); +int vfs_not_implemented_filesystem_sharemode(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t share_access, + uint32_t access_mask); +int vfs_not_implemented_fcntl(struct vfs_handle_struct *handle, + struct files_struct *fsp, int cmd, va_list cmd_arg); +int vfs_not_implemented_linux_setlease(struct vfs_handle_struct *handle, + struct files_struct *fsp, int leasetype); +bool vfs_not_implemented_getlock(vfs_handle_struct *handle, files_struct *fsp, + off_t *poffset, off_t *pcount, int *ptype, + pid_t *ppid); +int vfs_not_implemented_symlinkat(vfs_handle_struct *handle, + const struct smb_filename *link_contents, + struct files_struct *dirfsp, + const struct smb_filename *new_smb_fname); +int vfs_not_implemented_vfs_readlinkat(vfs_handle_struct *handle, + const struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + char *buf, + size_t bufsiz); +int vfs_not_implemented_linkat(vfs_handle_struct *handle, + struct files_struct *srcfsp, + const struct smb_filename *old_smb_fname, + struct files_struct *dstfsp, + const struct smb_filename *new_smb_fname, + int flags); +int vfs_not_implemented_mknodat(vfs_handle_struct *handle, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + mode_t mode, + SMB_DEV_T dev); +struct smb_filename *vfs_not_implemented_realpath(vfs_handle_struct *handle, + TALLOC_CTX *ctx, + const struct smb_filename *smb_fname); +int vfs_not_implemented_chflags(vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + uint flags); +int vfs_not_implemented_fchflags(vfs_handle_struct *handle, + struct files_struct *fst, + uint flags); +struct file_id vfs_not_implemented_file_id_create(vfs_handle_struct *handle, + const SMB_STRUCT_STAT *sbuf); +uint64_t vfs_not_implemented_fs_file_id(vfs_handle_struct *handle, + const SMB_STRUCT_STAT *sbuf); +struct tevent_req *vfs_not_implemented_offload_read_send( + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t fsctl, + uint32_t ttl, + off_t offset, + size_t to_copy); +NTSTATUS vfs_not_implemented_offload_read_recv(struct tevent_req *req, + struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + uint32_t *flags, + uint64_t *xferlen, + DATA_BLOB *_token_blob); +struct tevent_req *vfs_not_implemented_offload_write_send( + struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + uint32_t fsctl, + DATA_BLOB *token, + off_t transfer_offset, + struct files_struct *dest_fsp, + off_t dest_off, + off_t num); +NTSTATUS vfs_not_implemented_offload_write_recv(struct vfs_handle_struct *handle, + struct tevent_req *req, + off_t *copied); +NTSTATUS vfs_not_implemented_fget_compression(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *fsp, + uint16_t *_compression_fmt); +NTSTATUS vfs_not_implemented_set_compression(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *fsp, + uint16_t compression_fmt); +NTSTATUS vfs_not_implemented_fstreaminfo(struct vfs_handle_struct *handle, + struct files_struct *fsp, + TALLOC_CTX *mem_ctx, + unsigned int *num_streams, + struct stream_struct **streams); +NTSTATUS vfs_not_implemented_get_real_filename( + struct vfs_handle_struct *handle, + const struct smb_filename *path, + const char *name, + TALLOC_CTX *mem_ctx, + char **found_name); +NTSTATUS vfs_not_implemented_get_real_filename_at( + struct vfs_handle_struct *handle, + struct files_struct *dirfsp, + const char *name, + TALLOC_CTX *mem_ctx, + char **found_name); +const char *vfs_not_implemented_connectpath(struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname); +NTSTATUS vfs_not_implemented_brl_lock_windows(struct vfs_handle_struct *handle, + struct byte_range_lock *br_lck, + struct lock_struct *plock); +bool vfs_not_implemented_brl_unlock_windows(struct vfs_handle_struct *handle, + struct byte_range_lock *br_lck, + const struct lock_struct *plock); +bool vfs_not_implemented_strict_lock_check(struct vfs_handle_struct *handle, + struct files_struct *fsp, + struct lock_struct *plock); +NTSTATUS vfs_not_implemented_translate_name(struct vfs_handle_struct *handle, + const char *mapped_name, + enum vfs_translate_direction direction, + TALLOC_CTX *mem_ctx, char **pmapped_name); +NTSTATUS vfs_not_implemented_parent_pathname(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + const struct smb_filename *smb_fname_in, + struct smb_filename **parent_dir_out, + struct smb_filename **atname_out); +NTSTATUS vfs_not_implemented_fsctl(struct vfs_handle_struct *handle, + struct files_struct *fsp, + TALLOC_CTX *ctx, + uint32_t function, + uint16_t req_flags, /* Needed for UNICODE ... */ + const uint8_t *_in_data, + uint32_t in_len, + uint8_t **_out_data, + uint32_t max_out_len, uint32_t *out_len); +NTSTATUS vfs_not_implemented_freaddir_attr(struct vfs_handle_struct *handle, + struct files_struct *dirfsp, + TALLOC_CTX *mem_ctx, + struct readdir_attr_data **pattr_data); +struct tevent_req *vfs_not_implemented_get_dos_attributes_send( + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct vfs_handle_struct *handle, + files_struct *dir_fsp, + struct smb_filename *smb_fname); +NTSTATUS vfs_not_implemented_get_dos_attributes_recv( + struct tevent_req *req, + struct vfs_aio_state *aio_state, + uint32_t *dosmode); +NTSTATUS vfs_not_implemented_fget_dos_attributes(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t *dosmode); +NTSTATUS vfs_not_implemented_set_dos_attributes(struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + uint32_t dosmode); +NTSTATUS vfs_not_implemented_fset_dos_attributes(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t dosmode); +NTSTATUS vfs_not_implemented_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp, + uint32_t security_info, + TALLOC_CTX *mem_ctx, + struct security_descriptor **ppdesc); +NTSTATUS vfs_not_implemented_get_nt_acl_at(vfs_handle_struct *handle, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + uint32_t security_info, + TALLOC_CTX *mem_ctx, + struct security_descriptor **ppdesc); +NTSTATUS vfs_not_implemented_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, + uint32_t security_info_sent, + const struct security_descriptor *psd); +SMB_ACL_T vfs_not_implemented_sys_acl_get_fd(vfs_handle_struct *handle, + files_struct *fsp, + SMB_ACL_TYPE_T type, + TALLOC_CTX *mem_ctx); +int vfs_not_implemented_sys_acl_blob_get_fd(vfs_handle_struct *handle, + files_struct *fsp, TALLOC_CTX *mem_ctx, + char **blob_description, DATA_BLOB *blob); +int vfs_not_implemented_sys_acl_set_fd(vfs_handle_struct *handle, + struct files_struct *fsp, + SMB_ACL_TYPE_T type, + SMB_ACL_T theacl); +int vfs_not_implemented_sys_acl_delete_def_fd(vfs_handle_struct *handle, + files_struct *fsp); +struct tevent_req *vfs_not_implemented_getxattrat_send( + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct vfs_handle_struct *handle, + files_struct *dir_fsp, + const struct smb_filename *smb_fname, + const char *xattr_name, + size_t alloc_hint); +ssize_t vfs_not_implemented_getxattrat_recv(struct tevent_req *req, + struct vfs_aio_state *aio_state, + TALLOC_CTX *mem_ctx, + uint8_t **xattr_value); +ssize_t vfs_not_implemented_fgetxattr(vfs_handle_struct *handle, + struct files_struct *fsp, const char *name, + void *value, size_t size); +ssize_t vfs_not_implemented_listxattr(vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + char *list, + size_t size); +ssize_t vfs_not_implemented_flistxattr(vfs_handle_struct *handle, + struct files_struct *fsp, char *list, + size_t size); +int vfs_not_implemented_fremovexattr(vfs_handle_struct *handle, + struct files_struct *fsp, const char *name); +int vfs_not_implemented_setxattr(vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + const char *name, + const void *value, + size_t size, + int flags); +int vfs_not_implemented_fsetxattr(vfs_handle_struct *handle, struct files_struct *fsp, + const char *name, const void *value, size_t size, + int flags); +bool vfs_not_implemented_aio_force(struct vfs_handle_struct *handle, + struct files_struct *fsp); +NTSTATUS vfs_not_implemented_audit_file(struct vfs_handle_struct *handle, + struct smb_filename *file, + struct security_acl *sacl, + uint32_t access_requested, + uint32_t access_denied); +NTSTATUS vfs_not_implemented_durable_cookie(struct vfs_handle_struct *handle, + struct files_struct *fsp, + TALLOC_CTX *mem_ctx, + DATA_BLOB *cookie); +NTSTATUS vfs_not_implemented_durable_disconnect(struct vfs_handle_struct *handle, + struct files_struct *fsp, + const DATA_BLOB old_cookie, + TALLOC_CTX *mem_ctx, + DATA_BLOB *new_cookie); +NTSTATUS vfs_not_implemented_durable_reconnect(struct vfs_handle_struct *handle, + struct smb_request *smb1req, + struct smbXsrv_open *op, + const DATA_BLOB old_cookie, + TALLOC_CTX *mem_ctx, + struct files_struct **fsp, + DATA_BLOB *new_cookie); +#endif /* _VFS_H */ diff --git a/source3/include/vfs_macros.h b/source3/include/vfs_macros.h new file mode 100644 index 0000000..c7089b6 --- /dev/null +++ b/source3/include/vfs_macros.h @@ -0,0 +1,602 @@ +/* + Unix SMB/CIFS implementation. + VFS wrapper macros + Copyright (C) Stefan (metze) Metzmacher 2003 + Copyright (C) Volker Lendecke 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/>. +*/ + +#ifndef _VFS_MACROS_H +#define _VFS_MACROS_H + +/* + * These macros SMB_VFS_<FOO> (and SMB_VFS_NEXT_<FOO>) are our + * interface for the VFS. + * + * Don't access conn->vfs_handles[->next]->fns->* directly! + */ + +/* Disk operations */ +#define SMB_VFS_CONNECT(conn, service, user) \ + smb_vfs_call_connect((conn)->vfs_handles, (service), (user)) +#define SMB_VFS_NEXT_CONNECT(handle, service, user) \ + smb_vfs_call_connect((handle)->next, (service), (user)) + +#define SMB_VFS_DISCONNECT(conn) \ + smb_vfs_call_disconnect((conn)->vfs_handles) +#define SMB_VFS_NEXT_DISCONNECT(handle) \ + smb_vfs_call_disconnect((handle)->next) + +#define SMB_VFS_DISK_FREE(conn, smb_fname, bsize, dfree ,dsize) \ + smb_vfs_call_disk_free((conn)->vfs_handles, (smb_fname), (bsize), (dfree), (dsize)) +#define SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree ,dsize)\ + smb_vfs_call_disk_free((handle)->next, (smb_fname), (bsize), (dfree), (dsize)) + +#define SMB_VFS_GET_QUOTA(conn, smb_fname, qtype, id, qt) \ + smb_vfs_call_get_quota((conn)->vfs_handles, (smb_fname), (qtype), (id), (qt)) +#define SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt) \ + smb_vfs_call_get_quota((handle)->next, (smb_fname), (qtype), (id), (qt)) + +#define SMB_VFS_SET_QUOTA(conn, qtype, id, qt) \ + smb_vfs_call_set_quota((conn)->vfs_handles, (qtype), (id), (qt)) +#define SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt) \ + smb_vfs_call_set_quota((handle)->next, (qtype), (id), (qt)) + +#define SMB_VFS_GET_SHADOW_COPY_DATA(fsp,shadow_copy_data,labels) \ + smb_vfs_call_get_shadow_copy_data((fsp)->conn->vfs_handles, (fsp), (shadow_copy_data), (labels)) +#define SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data ,labels) \ + smb_vfs_call_get_shadow_copy_data((handle)->next, (fsp), (shadow_copy_data), (labels)) + +#define SMB_VFS_STATVFS(conn, smb_fname, statbuf) \ + smb_vfs_call_statvfs((conn)->vfs_handles, (smb_fname), (statbuf)) +#define SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf) \ + smb_vfs_call_statvfs((handle)->next, (smb_fname), (statbuf)) + +#define SMB_VFS_FS_CAPABILITIES(conn, p_ts_res) \ + smb_vfs_call_fs_capabilities((conn)->vfs_handles, (p_ts_res)) +#define SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res) \ + smb_vfs_call_fs_capabilities((handle)->next, (p_ts_res)) + +/* + * Note: that "struct dfs_GetDFSReferral *r" + * needs to be a valid TALLOC_CTX + */ +#define SMB_VFS_GET_DFS_REFERRALS(conn, r) \ + smb_vfs_call_get_dfs_referrals((conn)->vfs_handles, (r)) +#define SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r) \ + smb_vfs_call_get_dfs_referrals((handle)->next, (r)) + +#define SMB_VFS_CREATE_DFS_PATHAT(conn, dirfsp, smb_fname, reflist, count) \ + smb_vfs_call_create_dfs_pathat((conn)->vfs_handles, \ + (dirfsp), \ + (smb_fname), \ + (reflist), \ + (count)) +#define SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle, dirfsp, smb_fname, reflist, count) \ + smb_vfs_call_create_dfs_pathat((handle)->next, \ + (dirfsp), \ + (smb_fname), \ + (reflist), \ + (count)) +#define SMB_VFS_READ_DFS_PATHAT(conn, mem_ctx, dirfsp, smb_fname, ppreflist, pcount) \ + smb_vfs_call_read_dfs_pathat((conn)->vfs_handles, \ + (mem_ctx), \ + (dirfsp), \ + (smb_fname), \ + (ppreflist), \ + (pcount)) +#define SMB_VFS_NEXT_READ_DFS_PATHAT(handle, mem_ctx, dirfsp, smb_fname, ppreflist, pcount) \ + smb_vfs_call_read_dfs_pathat((handle)->next, \ + (mem_ctx), \ + (dirfsp), \ + (smb_fname), \ + (ppreflist), \ + (pcount)) + +/* Directory operations */ +#define SMB_VFS_FDOPENDIR(fsp, mask, attr) \ + smb_vfs_call_fdopendir((fsp)->conn->vfs_handles, (fsp), (mask), (attr)) +#define SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr) \ + smb_vfs_call_fdopendir((handle)->next, (fsp), (mask), (attr)) + +#define SMB_VFS_READDIR(conn, dirfsp, dirp, sbuf) \ + smb_vfs_call_readdir((conn)->vfs_handles, (dirfsp), (dirp), (sbuf)) +#define SMB_VFS_NEXT_READDIR(handle, dirfsp, dirp, sbuf) \ + smb_vfs_call_readdir((handle)->next, (dirfsp), (dirp), (sbuf)) + +#define SMB_VFS_SEEKDIR(conn, dirp, offset) \ + smb_vfs_call_seekdir((conn)->vfs_handles, (dirp), (offset)) +#define SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset) \ + smb_vfs_call_seekdir((handle)->next, (dirp), (offset)) + +#define SMB_VFS_TELLDIR(conn, dirp) \ + smb_vfs_call_telldir((conn)->vfs_handles, (dirp)) +#define SMB_VFS_NEXT_TELLDIR(handle, dirp) \ + smb_vfs_call_telldir((handle)->next, (dirp)) + +#define SMB_VFS_REWINDDIR(conn, dirp) \ + smb_vfs_call_rewind_dir((conn)->vfs_handles, (dirp)) +#define SMB_VFS_NEXT_REWINDDIR(handle, dirp) \ + smb_vfs_call_rewind_dir((handle)->next, (dirp)) + +#define SMB_VFS_MKDIRAT(conn, dirfsp, smb_fname, mode) \ + smb_vfs_call_mkdirat((conn)->vfs_handles,(dirfsp), (smb_fname), (mode)) +#define SMB_VFS_NEXT_MKDIRAT(handle, dirfsp, smb_fname, mode) \ + smb_vfs_call_mkdirat((handle)->next,(dirfsp), (smb_fname), (mode)) + +#define SMB_VFS_CLOSEDIR(conn, dir) \ + smb_vfs_call_closedir((conn)->vfs_handles, dir) +#define SMB_VFS_NEXT_CLOSEDIR(handle, dir) \ + smb_vfs_call_closedir((handle)->next, (dir)) + +/* File operations */ +#define SMB_VFS_OPENAT(conn, dirfsp, smb_fname, fsp, how) \ + smb_vfs_call_openat( \ + (conn)->vfs_handles, (dirfsp), (smb_fname), (fsp), (how)) +#define SMB_VFS_NEXT_OPENAT(handle, dirfsp, smb_fname, fsp, how) \ + smb_vfs_call_openat( \ + (handle)->next, (dirfsp), (smb_fname), (fsp), (how)) + +#define SMB_VFS_CREATE_FILE(conn, req, dirfsp, smb_fname, access_mask, share_access, create_disposition, \ + create_options, file_attributes, oplock_request, lease, allocation_size, private_flags, sd, ea_list, result, pinfo, in_context_blobs, out_context_blobs) \ + smb_vfs_call_create_file((conn)->vfs_handles, (req), (dirfsp), (smb_fname), (access_mask), (share_access), (create_disposition), \ + (create_options), (file_attributes), (oplock_request), (lease), (allocation_size), (private_flags), (sd), (ea_list), (result), (pinfo), \ + (in_context_blobs), (out_context_blobs)) +#define SMB_VFS_NEXT_CREATE_FILE(handle, req, dirfsp, smb_fname, access_mask, share_access, create_disposition, \ + create_options, file_attributes, oplock_request, lease, allocation_size, private_flags, sd, ea_list, result, pinfo, in_context_blobs, out_context_blobs) \ + smb_vfs_call_create_file((handle)->next, (req), (dirfsp), (smb_fname), (access_mask), (share_access), (create_disposition), \ + (create_options), (file_attributes), (oplock_request), (lease), (allocation_size), (private_flags), (sd), (ea_list), (result), (pinfo), \ + (in_context_blobs), (out_context_blobs)) + +#define SMB_VFS_CLOSE(fsp) \ + smb_vfs_call_close((fsp)->conn->vfs_handles, (fsp)) +#define SMB_VFS_NEXT_CLOSE(handle, fsp) \ + smb_vfs_call_close((handle)->next, (fsp)) + +#define SMB_VFS_PREAD(fsp, data, n, off) \ + smb_vfs_call_pread((fsp)->conn->vfs_handles, (fsp), (data), (n), (off)) +#define SMB_VFS_NEXT_PREAD(handle, fsp, data, n, off) \ + smb_vfs_call_pread((handle)->next, (fsp), (data), (n), (off)) + +#define SMB_VFS_PREAD_SEND(mem_ctx, ev, fsp, data, n, off) \ + smb_vfs_call_pread_send((fsp)->conn->vfs_handles, (mem_ctx), (ev), \ + (fsp), (data), (n), (off)) +#define SMB_VFS_NEXT_PREAD_SEND(mem_ctx, ev, handle, fsp, data, n, off) \ + smb_vfs_call_pread_send((handle)->next, (mem_ctx), (ev), (fsp), \ + (data), (n), (off)) + +#define SMB_VFS_PWRITE(fsp, data, n, off) \ + smb_vfs_call_pwrite((fsp)->conn->vfs_handles, (fsp), (data), (n), (off)) +#define SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, off) \ + smb_vfs_call_pwrite((handle)->next, (fsp), (data), (n), (off)) + +#define SMB_VFS_PWRITE_SEND(mem_ctx, ev, fsp, data, n, off) \ + smb_vfs_call_pwrite_send((fsp)->conn->vfs_handles, (mem_ctx), (ev), \ + (fsp), (data), (n), (off)) +#define SMB_VFS_NEXT_PWRITE_SEND(mem_ctx, ev, handle, fsp, data, n, off) \ + smb_vfs_call_pwrite_send((handle)->next, (mem_ctx), (ev), (fsp), \ + (data), (n), (off)) + +#define SMB_VFS_LSEEK(fsp, offset, whence) \ + smb_vfs_call_lseek((fsp)->conn->vfs_handles, (fsp), (offset), (whence)) +#define SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence) \ + smb_vfs_call_lseek((handle)->next, (fsp), (offset), (whence)) + +#define SMB_VFS_SENDFILE(tofd, fromfsp, header, offset, count) \ + smb_vfs_call_sendfile((fromfsp)->conn->vfs_handles, (tofd), (fromfsp), (header), (offset), (count)) +#define SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, header, offset, count) \ + smb_vfs_call_sendfile((handle)->next, (tofd), (fromfsp), (header), (offset), (count)) + +#define SMB_VFS_RECVFILE(fromfd, tofsp, offset, count) \ + smb_vfs_call_recvfile((tofsp)->conn->vfs_handles, (fromfd), (tofsp), (offset), (count)) +#define SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, count) \ + smb_vfs_call_recvfile((handle)->next, (fromfd), (tofsp), (offset), (count)) + +#define SMB_VFS_RENAMEAT(conn, oldfsp, old, newfsp, new) \ + smb_vfs_call_renameat((conn)->vfs_handles, (oldfsp), (old), (newfsp), (new)) +#define SMB_VFS_NEXT_RENAMEAT(handle, oldfsp, old, newfsp, new) \ + smb_vfs_call_renameat((handle)->next, (oldfsp), (old), (newfsp), (new)) + +#define SMB_VFS_FSYNC_SEND(mem_ctx, ev, fsp) \ + smb_vfs_call_fsync_send((fsp)->conn->vfs_handles, (mem_ctx), (ev), \ + (fsp)) +#define SMB_VFS_NEXT_FSYNC_SEND(mem_ctx, ev, handle, fsp) \ + smb_vfs_call_fsync_send((handle)->next, (mem_ctx), (ev), (fsp)) + +#define SMB_VFS_STAT(conn, smb_fname) \ + smb_vfs_call_stat((conn)->vfs_handles, (smb_fname)) +#define SMB_VFS_NEXT_STAT(handle, smb_fname) \ + smb_vfs_call_stat((handle)->next, (smb_fname)) + +#define SMB_VFS_FSTAT(fsp, sbuf) \ + smb_vfs_call_fstat((fsp)->conn->vfs_handles, (fsp), (sbuf)) +#define SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf) \ + smb_vfs_call_fstat((handle)->next, (fsp), (sbuf)) + +#define SMB_VFS_LSTAT(conn, smb_fname) \ + smb_vfs_call_lstat((conn)->vfs_handles, (smb_fname)) +#define SMB_VFS_NEXT_LSTAT(handle, smb_fname) \ + smb_vfs_call_lstat((handle)->next, (smb_fname)) + +#define SMB_VFS_FSTATAT(conn, dirfsp, smb_fname, sbuf, flags) \ + smb_vfs_call_fstatat((conn)->vfs_handles, (dirfsp), (smb_fname), \ + (sbuf), (flags)) +#define SMB_VFS_NEXT_FSTATAT(conn, dirfsp, smb_fname, sbuf, flags) \ + smb_vfs_call_fstatat((handle)->next, (dirfsp), (smb_fname), \ + (sbuf), (flags)) + +#define SMB_VFS_GET_ALLOC_SIZE(conn, fsp, sbuf) \ + smb_vfs_call_get_alloc_size((conn)->vfs_handles, (fsp), (sbuf)) +#define SMB_VFS_NEXT_GET_ALLOC_SIZE(conn, fsp, sbuf) \ + smb_vfs_call_get_alloc_size((conn)->next, (fsp), (sbuf)) + +#define SMB_VFS_UNLINKAT(conn, dirfsp, path, flags) \ + smb_vfs_call_unlinkat((conn)->vfs_handles, (dirfsp), (path), (flags)) +#define SMB_VFS_NEXT_UNLINKAT(handle, dirfsp, path, flags) \ + smb_vfs_call_unlinkat((handle)->next, (dirfsp), (path), (flags)) + +#define SMB_VFS_FCHMOD(fsp, mode) \ + smb_vfs_call_fchmod((fsp)->conn->vfs_handles, (fsp), (mode)) +#define SMB_VFS_NEXT_FCHMOD(handle, fsp, mode) \ + smb_vfs_call_fchmod((handle)->next, (fsp), (mode)) + +#define SMB_VFS_FCHOWN(fsp, uid, gid) \ + smb_vfs_call_fchown((fsp)->conn->vfs_handles, (fsp), (uid), (gid)) +#define SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid) \ + smb_vfs_call_fchown((handle)->next, (fsp), (uid), (gid)) + +#define SMB_VFS_LCHOWN(conn, smb_fname, uid, gid) \ + smb_vfs_call_lchown((conn)->vfs_handles, (smb_fname), (uid), (gid)) +#define SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid) \ + smb_vfs_call_lchown((handle)->next, (smb_fname), (uid), (gid)) + +#define SMB_VFS_CHDIR(conn, smb_fname) \ + smb_vfs_call_chdir((conn)->vfs_handles, (smb_fname)) +#define SMB_VFS_NEXT_CHDIR(handle, smb_fname) \ + smb_vfs_call_chdir((handle)->next, (smb_fname)) + +#define SMB_VFS_GETWD(conn, ctx) \ + smb_vfs_call_getwd((conn)->vfs_handles, (ctx)) +#define SMB_VFS_NEXT_GETWD(handle, ctx) \ + smb_vfs_call_getwd((handle)->next, (ctx)) + +#define SMB_VFS_FNTIMES(fsp, ts) \ + smb_vfs_call_fntimes((fsp)->conn->vfs_handles, (fsp), (ts)) +#define SMB_VFS_NEXT_FNTIMES(handle, fsp, ts) \ + smb_vfs_call_fntimes((handle)->next, (fsp), (ts)) + +#define SMB_VFS_FTRUNCATE(fsp, offset) \ + smb_vfs_call_ftruncate((fsp)->conn->vfs_handles, (fsp), (offset)) +#define SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset) \ + smb_vfs_call_ftruncate((handle)->next, (fsp), (offset)) + +#define SMB_VFS_FALLOCATE(fsp, mode, offset, len) \ + smb_vfs_call_fallocate((fsp)->conn->vfs_handles, (fsp), (mode), (offset), (len)) +#define SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len) \ + smb_vfs_call_fallocate((handle)->next, (fsp), (mode), (offset), (len)) + +#define SMB_VFS_LOCK(fsp, op, offset, count, type) \ + smb_vfs_call_lock((fsp)->conn->vfs_handles, (fsp), (op), (offset), (count), (type)) +#define SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type) \ + smb_vfs_call_lock((handle)->next, (fsp), (op), (offset), (count), (type)) + +#define SMB_VFS_FILESYSTEM_SHAREMODE(fsp, share_access, access_mask) \ + smb_vfs_call_filesystem_sharemode((fsp)->conn->vfs_handles, \ + (fsp), \ + (share_access), \ + (access_mask)) +#define SMB_VFS_NEXT_FILESYSTEM_SHAREMODE(handle, fsp, share_access, \ + access_mask) \ + smb_vfs_call_filesystem_sharemode((handle)->next, \ + (fsp), \ + (share_access), \ + (access_mask)) + +#define SMB_VFS_FCNTL(fsp, cmd, ...) \ + smb_vfs_call_fcntl((fsp)->conn->vfs_handles, (fsp), (cmd), (__VA_ARGS__)) +#define SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, ...) \ + smb_vfs_call_fcntl((handle)->next, (fsp), (cmd), (__VA_ARGS__)) + +#define SMB_VFS_LINUX_SETLEASE(fsp, leasetype) \ + smb_vfs_call_linux_setlease((fsp)->conn->vfs_handles, (fsp), (leasetype)) +#define SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype) \ + smb_vfs_call_linux_setlease((handle)->next, (fsp), (leasetype)) + +#define SMB_VFS_GETLOCK(fsp, poffset, pcount, ptype, ppid) \ + smb_vfs_call_getlock((fsp)->conn->vfs_handles, (fsp), (poffset), (pcount), (ptype), (ppid)) +#define SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid) \ + smb_vfs_call_getlock((handle)->next, (fsp), (poffset), (pcount), (ptype), (ppid)) + +#define SMB_VFS_SYMLINKAT(conn, oldpath, dirfsp, newpath) \ + smb_vfs_call_symlinkat((conn)->vfs_handles, (oldpath), (dirfsp), (newpath)) +#define SMB_VFS_NEXT_SYMLINKAT(handle, oldpath, dirfsp, newpath) \ + smb_vfs_call_symlinkat((handle)->next, (oldpath), (dirfsp), (newpath)) + +#define SMB_VFS_READLINKAT(conn, dirfsp, smb_fname, buf, bufsiz) \ + smb_vfs_call_readlinkat((conn)->vfs_handles, (dirfsp), (smb_fname), (buf), (bufsiz)) +#define SMB_VFS_NEXT_READLINKAT(handle, dirfsp, smb_fname, buf, bufsiz) \ + smb_vfs_call_readlinkat((handle)->next, (dirfsp), (smb_fname), (buf), (bufsiz)) + +#define SMB_VFS_LINKAT(conn, srcfsp, oldpath, dstfsp, newpath, flags) \ + smb_vfs_call_linkat((conn)->vfs_handles, (srcfsp), (oldpath), (dstfsp), (newpath), (flags)) +#define SMB_VFS_NEXT_LINKAT(handle, srcfsp, oldpath, dstfsp, newpath, flags) \ + smb_vfs_call_linkat((handle)->next, (srcfsp), (oldpath), (dstfsp), (newpath), (flags)) + +#define SMB_VFS_MKNODAT(conn, dirfsp, smb_fname, mode, dev) \ + smb_vfs_call_mknodat((conn)->vfs_handles, (dirfsp), (smb_fname), (mode), (dev)) +#define SMB_VFS_NEXT_MKNODAT(handle, dirfsp, smb_fname, mode, dev) \ + smb_vfs_call_mknodat((handle)->next, (dirfsp), (smb_fname), (mode), (dev)) + +#define SMB_VFS_REALPATH(conn, ctx, smb_fname) \ + smb_vfs_call_realpath((conn)->vfs_handles, (ctx), (smb_fname)) +#define SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname) \ + smb_vfs_call_realpath((handle)->next, (ctx), (smb_fname)) + +#define SMB_VFS_FCHFLAGS(fsp, flags) \ + smb_vfs_call_fchflags((fsp)->conn->vfs_handles, (fsp), (flags)) +#define SMB_VFS_NEXT_FCHFLAGS(handle, fsp, flags) \ + smb_vfs_call_fchflags((handle)->next, (fsp), (flags)) + +#define SMB_VFS_FILE_ID_CREATE(conn, sbuf) \ + smb_vfs_call_file_id_create((conn)->vfs_handles, (sbuf)) +#define SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf) \ + smb_vfs_call_file_id_create((handle)->next, (sbuf)) + +#define SMB_VFS_FS_FILE_ID(conn, sbuf) \ + smb_vfs_call_fs_file_id((conn)->vfs_handles, (sbuf)) +#define SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf) \ + smb_vfs_call_fs_file_id((handle)->next, (sbuf)) + +#define SMB_VFS_STREAMINFO(conn, fsp, smb_fname, mem_ctx, num_streams, streams) \ + smb_vfs_call_streaminfo((conn)->vfs_handles, (fsp), (smb_fname), (mem_ctx), (num_streams), (streams)) +#define SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx, num_streams, streams) \ + smb_vfs_call_streaminfo((handle)->next, (fsp), (smb_fname), (mem_ctx), (num_streams), (streams)) + +#define SMB_VFS_FSTREAMINFO(fsp, mem_ctx, num_streams, streams) \ + smb_vfs_call_fstreaminfo((fsp)->conn->vfs_handles, (fsp), (mem_ctx), (num_streams), (streams)) +#define SMB_VFS_NEXT_FSTREAMINFO(handle, fsp, mem_ctx, num_streams, streams) \ + smb_vfs_call_fstreaminfo(handle->next, (fsp), (mem_ctx), (num_streams), (streams)) + +#define SMB_VFS_GET_REAL_FILENAME_AT(conn, dirfsp, name, mem_ctx, found_name) \ + smb_vfs_call_get_real_filename_at( \ + (conn)->vfs_handles, \ + (dirfsp), \ + (name), \ + (mem_ctx), \ + (found_name)) +#define SMB_VFS_NEXT_GET_REAL_FILENAME_AT( \ + handle, dirfsp, name, mem_ctx, found_name) \ + smb_vfs_call_get_real_filename_at( \ + (handle)->next, \ + (dirfsp), \ + (name), \ + (mem_ctx), \ + (found_name)) + +#define SMB_VFS_CONNECTPATH(conn, smb_fname) \ + smb_vfs_call_connectpath((conn)->vfs_handles, (smb_fname)) +#define SMB_VFS_NEXT_CONNECTPATH(conn, smb_fname) \ + smb_vfs_call_connectpath((conn)->next, (smb_fname)) + +#define SMB_VFS_BRL_LOCK_WINDOWS(conn, br_lck, plock) \ + smb_vfs_call_brl_lock_windows((conn)->vfs_handles, (br_lck), (plock)) +#define SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock) \ + smb_vfs_call_brl_lock_windows((handle)->next, (br_lck), (plock)) + +#define SMB_VFS_BRL_UNLOCK_WINDOWS(conn, br_lck, plock) \ + smb_vfs_call_brl_unlock_windows((conn)->vfs_handles, (br_lck), (plock)) +#define SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock) \ + smb_vfs_call_brl_unlock_windows((handle)->next, (br_lck), (plock)) + +#define SMB_VFS_STRICT_LOCK_CHECK(conn, fsp, plock) \ + smb_vfs_call_strict_lock_check((conn)->vfs_handles, (fsp), (plock)) +#define SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock) \ + smb_vfs_call_strict_lock_check((handle)->next, (fsp), (plock)) + +#define SMB_VFS_TRANSLATE_NAME(conn, name, direction, mem_ctx, mapped_name) \ + smb_vfs_call_translate_name((conn)->vfs_handles, (name), (direction), (mem_ctx), (mapped_name)) +#define SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx, mapped_name) \ + smb_vfs_call_translate_name((handle)->next, (name), (direction), (mem_ctx), (mapped_name)) + +#define SMB_VFS_PARENT_PATHNAME(conn, mem_ctx, smb_fname_in, parent_dir_out, atname_out) \ + smb_vfs_call_parent_pathname((conn)->vfs_handles, (mem_ctx), (smb_fname_in), (parent_dir_out), (atname_out)) +#define SMB_VFS_NEXT_PARENT_PATHNAME(handle, mem_ctx, smb_fname_in, parent_dir_out, atname_out) \ + smb_vfs_call_parent_pathname((handle)->next, (mem_ctx), (smb_fname_in), (parent_dir_out), (atname_out)) + +#define SMB_VFS_FSCTL(fsp, ctx, function, req_flags, in_data, in_len, out_data, max_out_len, out_len) \ + smb_vfs_call_fsctl((fsp)->conn->vfs_handles, (fsp), (ctx), (function), (req_flags), (in_data), (in_len), (out_data), (max_out_len), (out_len)) + +#define SMB_VFS_NEXT_FSCTL(handle, fsp, ctx, function, req_flags, in_data, in_len, out_data, max_out_len, out_len) \ + smb_vfs_call_fsctl((handle)->next, (fsp), (ctx), (function), (req_flags), (in_data), (in_len), (out_data), (max_out_len), (out_len)) + +#define SMB_VFS_FGET_DOS_ATTRIBUTES(conn, fsp, attributes) \ + smb_vfs_call_fget_dos_attributes((conn)->vfs_handles, (fsp), (attributes)) +#define SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle, fsp, attributes) \ + smb_vfs_call_fget_dos_attributes((handle)->next, (fsp), (attributes)) + +#define SMB_VFS_GET_DOS_ATTRIBUTES_SEND(mem_ctx, evg, dir_fsp, smb_fname) \ + smb_vfs_call_get_dos_attributes_send((mem_ctx), (evg), \ + (dir_fsp)->conn->vfs_handles, \ + (dir_fsp), (smb_fname)) +#define SMB_VFS_GET_DOS_ATTRIBUTES_RECV(req, aio_state, dosmode) \ + smb_vfs_call_get_dos_attributes_recv((req), (aio_state), (dosmode)) + +#define SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx, evg, handle, dir_fsp, \ + smb_fname) \ + smb_vfs_call_get_dos_attributes_send((mem_ctx), (evg), \ + (handle)->next, \ + (dir_fsp), (smb_fname)) +#define SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(req, aio_state, dosmode) \ + smb_vfs_call_get_dos_attributes_recv((req), (aio_state), (dosmode)) + +#define SMB_VFS_FSET_DOS_ATTRIBUTES(conn, fsp, attributes) \ + smb_vfs_call_fset_dos_attributes((conn)->vfs_handles, (fsp), (attributes)) +#define SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle, fsp, attributes) \ + smb_vfs_call_fset_dos_attributes((handle)->next, (fsp), (attributes)) + +#define SMB_VFS_OFFLOAD_READ_SEND(mem_ctx, ev, fsp, fsctl, ttl, offset, to_copy) \ + smb_vfs_call_offload_read_send((mem_ctx), (ev), (fsp)->conn->vfs_handles, fsp, (fsctl), (ttl), (offset), (to_copy)) +#define SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp, fsctl, ttl, offset, to_copy) \ + smb_vfs_call_offload_read_send((mem_ctx), (ev), (handle)->next, (fsp), (fsctl), (ttl), (offset), (to_copy)) + +#define SMB_VFS_OFFLOAD_READ_RECV(req, conn, mem_ctx, flags, xferlen, token_blob) \ + smb_vfs_call_offload_read_recv((req), (conn)->vfs_handles, (mem_ctx), (flags), (xferlen), (token_blob)) +#define SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx, flags, xferlen, token_blob) \ + smb_vfs_call_offload_read_recv((req), (handle)->next, (mem_ctx), flags, xferlen, (token_blob)) + +#define SMB_VFS_OFFLOAD_WRITE_SEND(conn, mem_ctx, ev, fsctl, token, transfer_offset, dest_fsp, dest_off, num) \ + smb_vfs_call_offload_write_send((conn)->vfs_handles, (mem_ctx), (ev), (fsctl), (token), (transfer_offset), (dest_fsp), (dest_off), (num)) +#define SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev, fsctl, token, transfer_offset, dest_fsp, dest_off, num) \ + smb_vfs_call_offload_write_send((handle)->next, (mem_ctx), (ev), (fsctl), (token), (transfer_offset), (dest_fsp), (dest_off), (num)) + +#define SMB_VFS_OFFLOAD_WRITE_RECV(conn, req, copied) \ + smb_vfs_call_offload_write_recv((conn)->vfs_handles, (req), (copied)) +#define SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied) \ + smb_vfs_call_offload_write_recv((handle)->next, (req), (copied)) + +#define SMB_VFS_FGET_COMPRESSION(conn, mem_ctx, fsp, _compression_fmt) \ + smb_vfs_call_fget_compression((conn)->vfs_handles, (mem_ctx), (fsp), (_compression_fmt)) +#define SMB_VFS_NEXT_FGET_COMPRESSION(handle, mem_ctx, fsp, _compression_fmt) \ + smb_vfs_call_fget_compression((handle)->next, (mem_ctx), (fsp), (_compression_fmt)) + +#define SMB_VFS_SET_COMPRESSION(conn, mem_ctx, fsp, compression_fmt) \ + smb_vfs_call_set_compression((conn)->vfs_handles, (mem_ctx), (fsp), (compression_fmt)) +#define SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp, compression_fmt) \ + smb_vfs_call_set_compression((handle)->next, (mem_ctx), (fsp), (compression_fmt)) + +#define SMB_VFS_SNAP_CHECK_PATH(conn, mem_ctx, service_path, base_volume) \ + smb_vfs_call_snap_check_path((conn)->vfs_handles, (mem_ctx), (service_path), (base_volume)) +#define SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path, base_volume) \ + smb_vfs_call_snap_check_path((handle)->next, (mem_ctx), (service_path), (base_volume)) + +#define SMB_VFS_SNAP_CREATE(conn, mem_ctx, base_volume, tstamp, rw, base_path, snap_path) \ + smb_vfs_call_snap_create((conn)->vfs_handles, (mem_ctx), (base_volume), (tstamp), (rw), (base_path), (snap_path)) +#define SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp, rw, base_path, snap_path) \ + smb_vfs_call_snap_create((handle)->next, (mem_ctx), (base_volume), (tstamp), (rw), (base_path), (snap_path)) + +#define SMB_VFS_SNAP_DELETE(conn, mem_ctx, base_path, snap_path) \ + smb_vfs_call_snap_delete((conn)->vfs_handles, (mem_ctx), (base_path), (snap_path)) +#define SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path, snap_path) \ + smb_vfs_call_snap_delete((handle)->next, (mem_ctx), (base_path), (snap_path)) + +#define SMB_VFS_FGET_NT_ACL(fsp, security_info, mem_ctx, ppdesc) \ + smb_vfs_call_fget_nt_acl((fsp)->conn->vfs_handles, (fsp), (security_info), (mem_ctx), (ppdesc)) +#define SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info, mem_ctx, ppdesc) \ + smb_vfs_call_fget_nt_acl((handle)->next, (fsp), (security_info), (mem_ctx), (ppdesc)) + +#define SMB_VFS_AUDIT_FILE(conn, name, sacl, access_requested, access_denied) \ + smb_vfs_call_audit_file((conn)->vfs_handles, (name), (sacl), (access_requested), (access_denied)) +#define SMB_VFS_NEXT_AUDIT_FILE(handle, name, sacl, access_requested, access_denied) \ + smb_vfs_call_audit_file((handle)->next, (name), (sacl), (access_requested), (access_denied)) + +#define SMB_VFS_FSET_NT_ACL(fsp, security_info_sent, psd) \ + smb_vfs_call_fset_nt_acl((fsp)->conn->vfs_handles, (fsp), (security_info_sent), (psd)) +#define SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd) \ + smb_vfs_call_fset_nt_acl((handle)->next, (fsp), (security_info_sent), (psd)) + +#define SMB_VFS_SYS_ACL_GET_FD(fsp, type, mem_ctx) \ + smb_vfs_call_sys_acl_get_fd((fsp)->conn->vfs_handles, (fsp), (type), (mem_ctx)) +#define SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, type, mem_ctx) \ + smb_vfs_call_sys_acl_get_fd((handle)->next, (fsp), (type), (mem_ctx)) + +#define SMB_VFS_SYS_ACL_BLOB_GET_FD(fsp, mem_ctx, blob_description, blob) \ + smb_vfs_call_sys_acl_blob_get_fd((fsp)->conn->vfs_handles, (fsp), (mem_ctx), (blob_description), (blob)) +#define SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob) \ + smb_vfs_call_sys_acl_blob_get_fd((handle)->next, (fsp), mem_ctx, (blob_description), (blob)) + +#define SMB_VFS_SYS_ACL_SET_FD(fsp, type, theacl) \ + smb_vfs_call_sys_acl_set_fd((fsp)->conn->vfs_handles, (fsp), (type), (theacl)) +#define SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, type, theacl) \ + smb_vfs_call_sys_acl_set_fd((handle)->next, (fsp), (type), (theacl)) + +#define SMB_VFS_SYS_ACL_DELETE_DEF_FD(fsp) \ + smb_vfs_call_sys_acl_delete_def_fd((fsp)->conn->vfs_handles, (fsp)) +#define SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FD(handle, fsp) \ + smb_vfs_call_sys_acl_delete_def_fd((handle)->next, (fsp)) + +#define SMB_VFS_GETXATTRAT_SEND(mem_ctx,ev,dir_fsp,smb_fname, \ + xattr_name, alloc_hint) \ + smb_vfs_call_getxattrat_send((mem_ctx),(ev), \ + (dir_fsp)->conn->vfs_handles, \ + (dir_fsp),(smb_fname),(xattr_name), \ + (alloc_hint)) +#define SMB_VFS_GETXATTRAT_RECV(req, aio_state, mem_ctx, xattr_value) \ + smb_vfs_call_getxattrat_recv((req),(aio_state),(mem_ctx),(xattr_value)) + +#define SMB_VFS_NEXT_GETXATTRAT_SEND(mem_ctx,ev,handle,dir_fsp,smb_fname, \ + xattr_name,alloc_hint) \ + smb_vfs_call_getxattrat_send((mem_ctx),(ev), \ + (handle)->next, \ + (dir_fsp), (smb_fname),(xattr_name), \ + (alloc_hint)) +#define SMB_VFS_NEXT_GETXATTRAT_RECV(req, aio_state, mem_ctx, xattr_value) \ + smb_vfs_call_getxattrat_recv((req),(aio_state),(mem_ctx),(xattr_value)) + +#define SMB_VFS_FGETXATTR(fsp,name,value,size) \ + smb_vfs_call_fgetxattr((fsp)->conn->vfs_handles, (fsp), (name),(value),(size)) +#define SMB_VFS_NEXT_FGETXATTR(handle,fsp,name,value,size) \ + smb_vfs_call_fgetxattr((handle)->next,(fsp),(name),(value),(size)) + +#define SMB_VFS_FLISTXATTR(fsp,list,size) \ + smb_vfs_call_flistxattr((fsp)->conn->vfs_handles, (fsp), (list),(size)) +#define SMB_VFS_NEXT_FLISTXATTR(handle,fsp,list,size) \ + smb_vfs_call_flistxattr((handle)->next,(fsp),(list),(size)) + +#define SMB_VFS_FREMOVEXATTR(fsp,name) \ + smb_vfs_call_fremovexattr((fsp)->conn->vfs_handles, (fsp), (name)) +#define SMB_VFS_NEXT_FREMOVEXATTR(handle,fsp,name) \ + smb_vfs_call_fremovexattr((handle)->next,(fsp),(name)) + +#define SMB_VFS_FSETXATTR(fsp,name,value,size,flags) \ + smb_vfs_call_fsetxattr((fsp)->conn->vfs_handles, (fsp), (name),(value),(size),(flags)) +#define SMB_VFS_NEXT_FSETXATTR(handle,fsp,name,value,size,flags) \ + smb_vfs_call_fsetxattr((handle)->next,(fsp),(name),(value),(size),(flags)) + +#define SMB_VFS_AIO_FORCE(fsp) \ + smb_vfs_call_aio_force((fsp)->conn->vfs_handles, (fsp)) +#define SMB_VFS_NEXT_AIO_FORCE(handle,fsp) \ + smb_vfs_call_aio_force((handle)->next,(fsp)) + +/* durable handle operations */ + +#define SMB_VFS_DURABLE_COOKIE(fsp, mem_ctx, cookie) \ + smb_vfs_call_durable_cookie((fsp)->conn->vfs_handles, \ + (fsp), (mem_ctx), (cookie)) +#define SMB_VFS_NEXT_DURABLE_COOKIE(handle, fsp, mem_ctx, cookie) \ + smb_vfs_call_durable_cookie((handle)->next, \ + (fsp), (mem_ctx), (cookie)) + +#define SMB_VFS_DURABLE_DISCONNECT(fsp, old_cookie, mem_ctx, new_cookie) \ + smb_vfs_call_durable_disconnect((fsp)->conn->vfs_handles, \ + (fsp), (old_cookie), (mem_ctx), (new_cookie)) +#define SMB_VFS_NEXT_DURABLE_DISCONNECT(handle, fsp, old_cookie, mem_ctx, new_cookie) \ + smb_vfs_call_durable_disconnect((handle)->next, \ + (fsp), (old_cookie), (mem_ctx), (new_cookie)) + +#define SMB_VFS_DURABLE_RECONNECT(conn, smb1req, op, old_cookie, mem_ctx, fsp, new_cookie) \ + smb_vfs_call_durable_reconnect((conn)->vfs_handles, \ + (smb1req), (op), (old_cookie), \ + (mem_ctx), (fsp), (new_cookie)) +#define SMB_VFS_NEXT_DURABLE_RECONNECT(handle, smb1req, op, old_cookie, mem_ctx, fsp, new_cookie) \ + smb_vfs_call_durable_reconnect((handle)->next, \ + (smb1req), (op), (old_cookie), \ + (mem_ctx), (fsp), (new_cookie)) + +#define SMB_VFS_FREADDIR_ATTR(fsp, mem_ctx, attr_data) \ + smb_vfs_call_freaddir_attr((fsp)->conn->vfs_handles, (fsp), (mem_ctx), (attr_data)) +#define SMB_VFS_NEXT_FREADDIR_ATTR(handle, fsp, mem_ctx, attr_data) \ + smb_vfs_call_freaddir_attr((handle)->next, (fsp), (mem_ctx), (attr_data)) + +#endif /* _VFS_MACROS_H */ |