/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
*/
#ifndef _LIBSMBFS_H
#define _LIBSMBFS_H
/*
* Defines the API exported to smbfs commands and to the
* MS-style RPC-over-named-pipes library (libndr).
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h>
#include <sys/acl.h>
/*
* Some errno values we need to expose in this API.
* NB: These two defines are duplicated from the
* driver smb_dev.h to avoid exposing that here.
*
* EBADRPC is used for message decoding errors.
* EAUTH is used for CIFS authentication errors.
*/
#ifndef EBADRPC
#define EBADRPC 113
#endif
#ifndef EAUTH
#define EAUTH 114
#endif
/*
* Share type values for smb_ctx_new, _init
* Based on NetUseAdd() USE_INFO_[12] _asg_type values
* They also happen to match: STYPE_DISKTREE, etc.
*/
typedef enum {
USE_DISKDEV = 0, /* also STYPE_DISKTREE */
USE_SPOOLDEV, /* also STYPE_PRINTQ */
USE_CHARDEV, /* also STYPE_DEVICE */
USE_IPC, /* also STYPE_IPC */
USE_WILDCARD /* also STYPE_UNKNOWN */
} smb_use_shtype_t;
/*
* Parse "level" spec. for smb_ctx_parseunc()
* i.e. whether we require a share name, etc.
*/
typedef enum {
SMBL_NONE = 0, /* have nothing */
SMBL_SERVER, /* have server */
SMBL_VC = 1, /* alias for _SERVER */
SMBL_SHARE, /* have server share */
SMBL_PATH /* have server share path */
} smb_parse_level_t;
/*
* Authentication type flags
* See: smb_ctx_setauthflags()
*/
#define SMB_AT_ANON 1 /* anonymous (NULL session) */
#define SMB_AT_LM1 2 /* LM1 (with NTLM) */
#define SMB_AT_NTLM1 4 /* NTLM (v1) */
#define SMB_AT_NTLM2 8 /* NTLMv2 */
#define SMB_AT_KRB5 0x10 /* Kerberos5 (AD) */
#define SMB_AT_DEFAULT (SMB_AT_KRB5 | SMB_AT_NTLM2 | SMB_AT_NTLM1)
/*
* Value of the ct_rflags, used to determine the context of request.
*/
#define SMBFS_STANDALONE 0x00000000 /* Client standalone request */
#define SMBFS_OUTBOUNDDC 0x00000001 /* SMB server request */
struct smb_ctx; /* anonymous here; real one in smb_lib.h */
typedef struct smb_ctx smb_ctx_t;
extern int smbfs_debug;
int smbfs_lib_init(void);
void smbfs_error(const char *, int, ...);
/*
* Context management
*/
int smbfs_ctx_alloc(struct smb_ctx **);
void smbfs_ctx_free(struct smb_ctx *);
int smbfs_ctx_kill(struct smb_ctx *);
int smbfs_ctx_parseunc(struct smb_ctx *, const char *, int, int, int,
const char **);
int smbfs_ctx_parsedomuser(char *, char **, char **);
int smbfs_get_authentication(struct smb_ctx *);
int smbfs_ctx_flags2(struct smb_ctx *);
int smbfs_ctx_resolve(struct smb_ctx *);
int smbfs_ctx_get_ssn(struct smb_ctx *);
int smbfs_ctx_get_tree(struct smb_ctx *);
int smbfs_ctx_setauthflags(struct smb_ctx *, int);
int smbfs_ctx_setcharset(struct smb_ctx *, const char *);
int smbfs_ctx_setfullserver(struct smb_ctx *, const char *);
int smbfs_ctx_setsigning(struct smb_ctx *, boolean_t required);
int smbfs_ctx_setnbflags(struct smb_ctx *, int ena, int bcast);
int smbfs_ctx_setscope(struct smb_ctx *, const char *);
int smbfs_ctx_setwins(struct smb_ctx *, const char *, const char *);
int smbfs_ctx_setserver(struct smb_ctx *, const char *);
int smbfs_ctx_setshare(struct smb_ctx *, const char *, int);
int smbfs_ctx_setrealm(struct smb_ctx *, const char *);
int smbfs_ctx_setdomain(struct smb_ctx *, const char *, int);
int smbfs_ctx_setuser(struct smb_ctx *, const char *, int);
int smbfs_ctx_setpassword(struct smb_ctx *, const char *, int);
int smbfs_ctx_setpwhash(struct smb_ctx *, const uchar_t *, const uchar_t *);
typedef void (*smb_ctx_close_hook_t)(struct smb_ctx *);
/*
* Additional client context passed from consumers of smbfs_fh_open calls.
* These context values are set by consumers of smbfs_fh_open calls to
* facilitate authentication.
*/
typedef struct smbfs_fh_ctx {
char *sf_realm;
uint32_t sf_cflag;
} smbfs_fh_ctx_t;
void smbfs_fh_ctx_create(smbfs_fh_ctx_t *, uint32_t, char *);
void smbfs_fh_ctx_destroy(smbfs_fh_ctx_t *);
int smbfs_fh_open(const char *, int, const smbfs_fh_ctx_t *);
int smbfs_fh_close(int);
int smbfs_fh_read(int, void *, size_t, off_t);
int smbfs_fh_write(int, const void *, size_t, off_t);
int smbfs_fh_xactnp(int, int, const char *,
int *, char *, int *);
int smbfs_fh_getssnkey(int, uchar_t *, size_t);
int smbfs_print(const char *, const char *, const char *);
void smbfs_set_default_domain(const char *);
void smbfs_set_default_user(const char *);
char *smbfs_strerror(int);
/*
* Get/set ACL APIs.
* The ACL is in the form used by libsec (type=ACE_T)
* but we need to carry the uid/gid info here too.
*/
/*
* Get a ZFS-style acl from an FD opened in smbfs.
* Intentionally similar to: facl_get(3SEC)
*
* Allocates an acl_t via libsec. Free with: acl_free(3SEC)
* Get owner/group IDs too if ID pointers != NULL
*/
int smbfs_acl_get(int fd, acl_t **, uid_t *, gid_t *);
/*
* Set a ZFS-style acl onto an FD opened in smbfs.
* Intentionally similar to: facl_set(3SEC)
*
* The acl_t must be of type ACE_T (from libsec).
* Set owner/group IDs too if ID values != -1
*/
int smbfs_acl_set(int fd, acl_t *, uid_t, gid_t);
/*
* Slightly lower-level functions, allowing access to
* the raw Windows Security Descriptor (SD)
*
* The struct i_ntsid is opaque in this I/F.
* Real decl. in: common/smbclnt/smbfs_ntacl.h
*/
struct i_ntsd;
/*
* Get an "internal form" SD from the FD (opened in smbfs).
* Allocates a hierarchy in isdp. Caller must free it via
* smbfs_acl_free_isd()
*/
int smbfs_acl_getsd(int fd, uint32_t, struct i_ntsd **);
/*
* Set an "internal form" SD onto the FD (opened in smbfs).
*/
int smbfs_acl_setsd(int fd, uint32_t, struct i_ntsd *);
struct __FILE;
void smbfs_acl_print_sd(struct __FILE *, struct i_ntsd *);
/*
* These are duplicated from common/smbclnt/smbfs_ntacl.h
* rather than exporting that header for this library.
* Any mismatch would be detected in smb/acl_api.c
*/
int smbfs_acl_sd2zfs(struct i_ntsd *, acl_t *, uid_t *, gid_t *);
int smbfs_acl_zfs2sd(acl_t *, uid_t, gid_t, uint32_t, struct i_ntsd **);
void smbfs_acl_free_sd(struct i_ntsd *);
/*
* External interface to the libsmbfs/netsmb keychain
* storage mechanism. This interface is consumed by
* the smbfs commands like login, logout etc. and by the SMBFS PAM module.
*/
#define SMB_KEYCHAIN_SUCCESS 0
#define SMB_KEYCHAIN_BADPASSWD 300
#define SMB_KEYCHAIN_BADDOMAIN 301
#define SMB_KEYCHAIN_BADUSER 302
#define SMB_KEYCHAIN_NODRIVER 303
#define SMB_KEYCHAIN_UNKNOWN 304
/* Add a password to the keychain. */
int smbfs_keychain_add(uid_t uid, const char *domain, const char *user,
const char *password, boolean_t updatefile);
/* Add LM-hash and NT-hash (16-bytes) to the keychain. */
int smbfs_keychain_addhash(uid_t uid, const char *domain, const char *user,
const uchar_t *lmhash, const uchar_t *nthash);
/* Delete a password from the keychain. */
int smbfs_keychain_del(uid_t uid, const char *domain, const char *user,
boolean_t updatefile);
/*
* Check for existence of a keychain entry.
* Returns 0 if it exists, else ENOENT.
*/
int smbfs_keychain_chk(const char *domain, const char *user);
/*
* Delete all keychain entries owned by the caller.
*/
int smbfs_keychain_del_owner(boolean_t updatefile);
/*
* Delete all keychain entries (regardless of owner).
* Requires super-user privliege.
*/
int smbfs_keychain_del_everyone(void);
/*
* This is not really part of the keychain library,
* but is typically needed in code that wants to
* provide (editable) defaults for domain/user
*
* Get default domain and user names
* Server name is optional.
*/
int smbfs_default_dom_usr(char *dom, int maxdom, char *usr, int maxusr);
#ifdef __cplusplus
}
#endif
#endif /* _LIBSMBFS_H */