1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 *
26 * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
27 */
28
29#ifndef _NETSMB_SMBFS_API_H
30#define	_NETSMB_SMBFS_API_H
31
32/*
33 * Define the API exported to our commands and to
34 * libraries doing DCE-RPC over SMB named pipes.
35 */
36
37#include <sys/types.h>
38
39#ifdef	__cplusplus
40extern "C" {
41#endif
42
43/*
44 * Some errno values we need to expose in this API.
45 * NB: These two defines are duplicated from the
46 * driver smb_dev.h to avoid exposing that here.
47 *
48 * EBADRPC is used for message decoding errors.
49 * EAUTH is used for CIFS authentication errors.
50 */
51#ifndef EBADRPC
52#define	EBADRPC		113
53#endif
54#ifndef EAUTH
55#define	EAUTH		114
56#endif
57
58
59/*
60 * Share type values for smb_ctx_new, _init
61 * Based on NetUseAdd() USE_INFO_[12] _asg_type values
62 * They also happen to match: STYPE_DISKTREE, etc.
63 * Note: these values appear on the wire.
64 */
65typedef enum {
66	USE_DISKDEV = 0,	/* also STYPE_DISKTREE */
67	USE_SPOOLDEV,		/* also STYPE_PRINTQ */
68	USE_CHARDEV,		/* also STYPE_DEVICE */
69	USE_IPC,		/* also STYPE_IPC */
70	USE_WILDCARD		/* also STYPE_UNKNOWN */
71} smb_use_shtype_t;
72
73/*
74 * Parse "level" spec. for smb_ctx_parseunc()
75 * i.e. whether we require a share name, etc.
76 */
77typedef enum {
78	SMBL_NONE = 0,	/* have nothing */
79	SMBL_SERVER,	/* have server */
80	SMBL_VC = 1,	/* alias for _SERVER */
81	SMBL_SHARE,	/* have server share */
82	SMBL_PATH	/* have server share path */
83} smb_parse_level_t;
84
85/*
86 * Authentication type flags
87 * See: smb_ctx_setauthflags()
88 */
89#define	SMB_AT_ANON	1	/* anonymous (NULL session) */
90#define	SMB_AT_LM1	2	/* LM1 (with NTLM) */
91#define	SMB_AT_NTLM1	4	/* NTLM (v1) */
92#define	SMB_AT_NTLM2	8	/* NTLMv2 */
93#define	SMB_AT_KRB5	0x10	/* Kerberos5 (AD) */
94
95struct smb_ctx;	/* anonymous here; real one in smb_lib.h */
96typedef struct smb_ctx smb_ctx_t;
97
98extern int smb_debug, smb_verbose;
99
100int  smb_lib_init(void);
101void smb_error(const char *, int, ...);
102
103/*
104 * Context management
105 */
106int  smb_ctx_alloc(struct smb_ctx **);
107void smb_ctx_free(struct smb_ctx *);
108int  smb_ctx_kill(struct smb_ctx *);
109
110int  smb_ctx_scan_argv(struct smb_ctx *, int, char **, int, int, int);
111int  smb_ctx_parseunc(struct smb_ctx *, const char *, int, int, int,
112	const char **);
113int  smb_ctx_readrc(struct smb_ctx *);
114int  smb_ctx_opt(struct smb_ctx *, int, const char *);
115int  smb_get_authentication(struct smb_ctx *);
116
117int  smb_ctx_flags2(struct smb_ctx *);
118int  smb_ctx_resolve(struct smb_ctx *);
119int  smb_ctx_get_ssn(struct smb_ctx *);
120int  smb_ctx_get_tree(struct smb_ctx *);
121
122int  smb_ctx_setauthflags(struct smb_ctx *, int);
123int  smb_ctx_setcharset(struct smb_ctx *, const char *);
124int  smb_ctx_setfullserver(struct smb_ctx *, const char *);
125int  smb_ctx_setsigning(struct smb_ctx *, int ena, int req);
126int  smb_ctx_setminver(struct smb_ctx *, int ver);
127int  smb_ctx_setmaxver(struct smb_ctx *, int ver);
128
129int  smb_ctx_setnbflags(struct smb_ctx *, int ena, int bcast);
130int  smb_ctx_setscope(struct smb_ctx *, const char *);
131int  smb_ctx_setwins(struct smb_ctx *, const char *, const char *);
132
133int  smb_ctx_setsrvaddr(struct smb_ctx *, const char *);
134int  smb_ctx_setserver(struct smb_ctx *, const char *);
135int  smb_ctx_setshare(struct smb_ctx *, const char *, int);
136
137int  smb_ctx_setdomain(struct smb_ctx *, const char *, int);
138int  smb_ctx_setuser(struct smb_ctx *, const char *, int);
139int  smb_ctx_setpassword(struct smb_ctx *, const char *, int);
140int  smb_ctx_setpwhash(struct smb_ctx *, const uchar_t *, const uchar_t *);
141
142typedef void (*smb_ctx_close_hook_t)(struct smb_ctx *);
143void smb_ctx_set_close_hook(smb_ctx_close_hook_t);
144int  smb_fh_close(int);
145int  smb_fh_open(struct smb_ctx *ctx, const char *, int);
146int  smb_fh_read(int, off64_t, size_t, char *);
147int  smb_fh_write(int, off64_t, size_t, const char *);
148int  smb_fh_xactnp(int, int, const char *,
149	int *, char *, int *);
150int  smb_fh_getssnkey(int, uchar_t *, size_t);
151
152int  smb_open_printer(struct smb_ctx *, const char *, int, int);
153
154void smbfs_set_default_domain(const char *);
155void smbfs_set_default_user(const char *);
156
157char *smb_strerror(int);
158
159#ifdef	__cplusplus
160}
161#endif
162
163#endif /* _NETSMB_SMBFS_API_H */
164