2N/A/*
2N/A * Copyright (c) 2000-2001 Boris Popov
2N/A * All rights reserved.
2N/A *
2N/A * Redistribution and use in source and binary forms, with or without
2N/A * modification, are permitted provided that the following conditions
2N/A * are met:
2N/A * 1. Redistributions of source code must retain the above copyright
2N/A * notice, this list of conditions and the following disclaimer.
2N/A * 2. Redistributions in binary form must reproduce the above copyright
2N/A * notice, this list of conditions and the following disclaimer in the
2N/A * documentation and/or other materials provided with the distribution.
2N/A * 3. All advertising materials mentioning features or use of this software
2N/A * must display the following acknowledgement:
2N/A * This product includes software developed by Boris Popov.
2N/A * 4. Neither the name of the author nor the names of any co-contributors
2N/A * may be used to endorse or promote products derived from this software
2N/A * without specific prior written permission.
2N/A *
2N/A * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2N/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2N/A * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2N/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2N/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2N/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2N/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2N/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2N/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2N/A * SUCH DAMAGE.
2N/A *
2N/A * $Id: smb_lib.h,v 1.21.82.2 2005/06/02 00:55:39 lindak Exp $
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#ifndef _NETSMB_SMB_LIB_H_
2N/A#define _NETSMB_SMB_LIB_H_
2N/A
2N/A/*
2N/A * Internal interface exported to our commands in:
2N/A * usr/src/cmd/fs.d/smbclnt/
2N/A */
2N/A
2N/A#include <sys/types.h>
2N/A#include <sys/socket.h>
2N/A#include <netinet/in.h>
2N/A#include <arpa/inet.h>
2N/A#include <sys/byteorder.h>
2N/A#include <paths.h>
2N/A#include <libnvpair.h>
2N/A
2N/A#include <netsmb/libsmbfs.h>
2N/A#include <netsmb/smb_dev.h>
2N/A
2N/A/*
2N/A * bits to indicate the source of error
2N/A */
2N/A#define SMB_ERRTYPE_MASK 0xf0000
2N/A#define SMB_SYS_ERROR 0x00000
2N/A#define SMB_RAP_ERROR 0x10000
2N/A#define SMB_NB_ERROR 0x20000
2N/A
2N/A/*
2N/A * Size of all LM/NTLM hashes (16 bytes).
2N/A * The driver needs to know this, so it's
2N/A * defined by smb_dev.h
2N/A */
2N/A#define NTLM_HASH_SZ SMBIOC_HASH_SZ
2N/A#define NTLM_CHAL_SZ 8 /* challenge size */
2N/A
2N/A/*
2N/A * This is what goes across the door call to the IOD
2N/A * when asking for a new connection.
2N/A *
2N/A * iod_ntstatus can be set to either NT_STATUS_UNSUCCESSFUL (for
2N/A * internal errors) or NT status returned by remote server upon
2N/A * SmbSessionSetup failure.
2N/A * Other fields are used for encoding the SmbSessionSetup request.
2N/A */
2N/Astruct smb_iod_ssn {
2N/A struct smbioc_ossn iod_ossn;
2N/A int iod_authflags; /* SMB_AT_x */
2N/A uchar_t iod_nthash[NTLM_HASH_SZ];
2N/A uchar_t iod_lmhash[NTLM_HASH_SZ];
2N/A uint32_t iod_ntstatus;
2N/A uint32_t iod_flags;
2N/A char iod_realm[SMBIOC_MAX_NAME];
2N/A /* Kerberos cred. cache res. name? */
2N/A};
2N/Atypedef struct smb_iod_ssn smb_iod_ssn_t;
2N/A
2N/A/*
2N/A * This is the return values of the door call to the IOD
2N/A * when asking for a new connection.
2N/A */
2N/Atypedef struct smb_iod_ssn_retval
2N/A{
2N/A int r_err; /* errno or user-defined error */
2N/A uint32_t r_ntstatus; /* NT status in SmbSessionSetup reply */
2N/A} smb_iod_ssn_retval_t;
2N/A
2N/A/*
2N/A * SMB work context. Used to store all values which are necessary
2N/A * to establish connection to an SMB server.
2N/A */
2N/Astruct smb_ctx {
2N/A int ct_flags; /* SMBCF_ */
2N/A int ct_dev_fd; /* device handle */
2N/A int ct_door_fd; /* to smbiod */
2N/A int ct_parsedlevel;
2N/A int ct_minlevel;
2N/A int ct_maxlevel;
2N/A char *ct_fullserver; /* orig. server name from cmd line */
2N/A char *ct_srvaddr_s; /* hostname or IP address of server */
2N/A struct addrinfo *ct_addrinfo; /* IP addresses of the server */
2N/A struct nb_ctx *ct_nb; /* NetBIOS info. */
2N/A char *ct_locname; /* local (machine) name */
2N/A smb_iod_ssn_t ct_iod_ssn;
2N/A /* smbioc_oshare_t ct_sh; XXX */
2N/A int ct_shtype_req; /* share type wanted */
2N/A char *ct_origshare;
2N/A char *ct_rpath; /* remote file name */
2N/A
2N/A /* Connection setup SMB stuff. */
2N/A /* Strings from the SMB negotiate response. */
2N/A char *ct_srv_OS;
2N/A char *ct_srv_LM;
2N/A
2N/A /* NTLM auth. stuff */
2N/A uchar_t ct_clnonce[NTLM_CHAL_SZ];
2N/A uchar_t ct_ntlm_chal[NTLM_CHAL_SZ];
2N/A char ct_password[SMBIOC_MAX_NAME];
2N/A
2N/A /* See ssp.c */
2N/A void *ct_ssp_ctx;
2N/A smbioc_ssn_work_t ct_work;
2N/A};
2N/A
2N/A
2N/A/*
2N/A * Short-hand for some of the substruct fields above
2N/A */
2N/A#define ct_ssn ct_iod_ssn.iod_ossn
2N/A#define ct_vopt ct_iod_ssn.iod_ossn.ssn_vopt
2N/A#define ct_owner ct_iod_ssn.iod_ossn.ssn_owner
2N/A#define ct_srvaddr ct_iod_ssn.iod_ossn.ssn_srvaddr
2N/A#define ct_domain ct_iod_ssn.iod_ossn.ssn_domain
2N/A#define ct_user ct_iod_ssn.iod_ossn.ssn_user
2N/A#define ct_srvname ct_iod_ssn.iod_ossn.ssn_srvname
2N/A#define ct_authflags ct_iod_ssn.iod_authflags
2N/A#define ct_nthash ct_iod_ssn.iod_nthash
2N/A#define ct_lmhash ct_iod_ssn.iod_lmhash
2N/A#define ct_ntstatus ct_iod_ssn.iod_ntstatus
2N/A#define ct_rflags ct_iod_ssn.iod_flags
2N/A#define ct_realm ct_iod_ssn.iod_realm
2N/A
2N/A#define ct_sopt ct_work.wk_sopt
2N/A#define ct_iods ct_work.wk_iods
2N/A#define ct_tran_fd ct_work.wk_iods.is_tran_fd
2N/A#define ct_hflags ct_work.wk_iods.is_hflags
2N/A#define ct_hflags2 ct_work.wk_iods.is_hflags2
2N/A#define ct_vcflags ct_work.wk_iods.is_vcflags
2N/A#define ct_ssn_key ct_work.wk_iods.is_ssn_key
2N/A#define ct_mac_seqno ct_work.wk_iods.is_next_seq
2N/A#define ct_mackeylen ct_work.wk_iods.is_u_maclen
2N/A#define ct_mackey ct_work.wk_iods.is_u_mackey.lp_ptr
2N/A
2N/A
2N/A/*
2N/A * Bits in smb_ctx_t.ct_flags
2N/A */
2N/A#define SMBCF_NOPWD 0x0001 /* don't ask for a password */
2N/A#define SMBCF_SRIGHTS 0x0002 /* share access rights supplied */
2N/A#define SMBCF_LOCALE 0x0004 /* use current locale */
2N/A#define SMBCF_CMD_DOM 0x0010 /* CMD specified domain */
2N/A#define SMBCF_CMD_USR 0x0020 /* CMD specified user */
2N/A#define SMBCF_CMD_PW 0x0040 /* CMD specified password */
2N/A#define SMBCF_RESOLVED 0x8000 /* structure has been verified */
2N/A#define SMBCF_KCBAD 0x00080000 /* keychain password failed */
2N/A#define SMBCF_KCFOUND 0x00100000 /* password is from keychain */
2N/A#define SMBCF_BROWSEOK 0x00200000 /* browser dialogue may be used */
2N/A#define SMBCF_AUTHREQ 0x00400000 /* auth. dialog requested */
2N/A#define SMBCF_KCSAVE 0x00800000 /* add to keychain requested */
2N/A#define SMBCF_XXX 0x01000000 /* mount-all, a very bad thing */
2N/A#define SMBCF_SSNACTIVE 0x02000000 /* session setup succeeded */
2N/A#define SMBCF_KCDOMAIN 0x04000000 /* use domain in KC lookup */
2N/A
2N/Atypedef struct smbfs_passwd {
2N/A uid_t pw_uid; /* UID */
2N/A char pw_dom[SMBIOC_MAX_NAME]; /* CIFS domain name */
2N/A char pw_usr[SMBIOC_MAX_NAME]; /* CIFS user name */
2N/A uchar_t pw_lmhash[NTLM_HASH_SZ]; /* LanMan p/w hash */
2N/A uchar_t pw_nthash[NTLM_HASH_SZ]; /* NTLM p/w hash */
2N/A} smbfs_passwd_t;
2N/A
2N/A/*
2N/A * Context management
2N/A */
2N/A
2N/Aint smbfs_ctx_init(struct smb_ctx *);
2N/Avoid smbfs_ctx_done(struct smb_ctx *);
2N/Aint smbfs_open_driver(void);
2N/A
2N/Aint smbfs_ctx_gethandle(struct smb_ctx *);
2N/Aint smbfs_ctx_findvc(struct smb_ctx *);
2N/Aint smbfs_ctx_newvc(struct smb_ctx *);
2N/A
2N/A/*
2N/A * I/O daemon stuff
2N/A */
2N/A
2N/A#define SMBIOD_RUNDIR _PATH_SYSVOL "/smbiod"
2N/A#define SMBIOD_SVC_DOOR SMBIOD_RUNDIR "/.svc"
2N/A#define SMBIOD_USR_DOOR SMBIOD_RUNDIR "/%d"
2N/A#define SMBIOD_PWDFILE "/var/smb/smbfspasswd"
2N/A#define SMBIOD_START 1
2N/A#define SMBIOD_PWDFILE_ADD 2
2N/A#define SMBIOD_PWDFILE_DEL 3
2N/A#define SMBIOD_PWDFILE_DELALL 4
2N/A
2N/Aint smbfs_iod_cl_newvc(smb_ctx_t *ctx);
2N/Achar *smbfs_iod_door_path(void);
2N/Aint smbfs_iod_open_door(int *);
2N/Aint smbfs_iod_connect(struct smb_ctx *);
2N/Aint smbfs_iod_work(struct smb_ctx *);
2N/A
2N/Aint smbfs_iod_start(void);
2N/Aint smbfs_iod_pwdadd(smbfs_passwd_t *);
2N/Aint smbfs_iod_pwddel(smbfs_passwd_t *);
2N/Aint smbfs_door_decode(char *, size_t, int *, smbfs_passwd_t *);
2N/A
2N/Aint smbfs_pwd_add(smbfs_passwd_t *);
2N/Aint smbfs_pwd_del(smbfs_passwd_t *, boolean_t);
2N/Aint smbfs_pwd_loadkeychain(void);
2N/A
2N/A/* SMBFS client credential cache functions */
2N/A#define SMBFS_CCACHE_DIR _PATH_SYSVOL "/smbiod/ccache"
2N/A#define SMBFS_CCACHE_PREFIX "ccache"
2N/A#define SMBFS_CCACHE_PATH_PREFIX SMBFS_CCACHE_DIR "/" SMBFS_CCACHE_PREFIX
2N/Atypedef enum {
2N/A SMBFS_CCACHE_CLNT_DEFAULT = 0, /* /tmp/krbrcc_<uid> */
2N/A SMBFS_CCACHE_CLNT_SMBFS, /* /var/run/smbiod/ccache */
2N/A SMBFS_CCACHE_CLNT_MAX
2N/A} smbfs_ccache_clnt_type_t;
2N/Aint smbfs_ccache_clnt_set(struct smb_ctx *, smbfs_ccache_clnt_type_t);
2N/A
2N/Atypedef enum {
2N/A SMBFS_CCACHE_SRV_SYS = 3, /* /var/run/smb/computer_ccache */
2N/A SMBFS_CCACHE_SRV_USER, /* /var/run/smb/user_ccache */
2N/A SMBFS_CCACHE_SRV_MAX
2N/A} smbfs_ccache_srv_type_t;
2N/Aint smbfs_ccache_srv_set(struct smb_ctx *, smbfs_ccache_srv_type_t);
2N/A
2N/A/*
2N/A * Other stuff
2N/A */
2N/Avoid smbfs_simplecrypt(char *dst, const char *src);
2N/Aint smbfs_simpledecrypt(char *dst, const char *src);
2N/A
2N/Achar *smbfs_nls_str_upper(char *, const char *);
2N/A
2N/A#endif /* _NETSMB_SMB_LIB_H_ */