smbrdr.h revision 380acbbe9da7dc2cbab5b6db169ec6968dd927fa
/*
* 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
* 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 2011 Nexenta Systems, Inc. All rights reserved.
*/
#ifndef _SMBRDR_H_
#define _SMBRDR_H_
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <synch.h>
#include <smbsrv/libsmbrdr.h>
#include <smbsrv/wintypes.h>
#define SMBRDR_LOG_NAME "smbrdr"
#define SMBRDR_LOG_MAXCNT 1024
#define SMBRDR_REQ_BUFSZ 4096
#define MAX_ACCOUNT_NAME 32
#define MAX_SHARE_NAME 32
#define MAX_SCOPE_NAME 64
#define MAX_FILE_PATH 128
/*
* The number of shares and pipes is limited to 48 based on the note
* below. This really shouldn't cause a problem because we always
* our shares and named pipes are always opened and closed round every
* RPC transaction. This also tends to limit the number of active
* logons because we (currently) need two named pipes per logon.
*
* Q141709 Limit of 49 named pipe connections from a single workstation.
* If a named pipe server creates more than 49 distincly named pipes, a
* single client cannot connect more than 49 pipes on the named pipe
* server. Chapter 4, p113. Network Programming for Microsoft Windows
* Anthony Jones and Jim Ohlund, Microsoft Press, ISBN: 0-7356-0560-2
*/
#define N_NETUSE_TABLE 256
#define N_OFILE_TABLE 256
/*
* Logon's states
*/
#define SDB_LSTATE_START 0
#define SDB_LSTATE_INIT 1
#define SDB_LSTATE_LOGGING_OFF 2
#define SDB_LSTATE_SETUP 3
#define SDB_LOGON_NONE 0
#define SDB_LOGON_GUEST 1
#define SDB_LOGON_ANONYMOUS 2
#define SDB_LOGON_USER 3
typedef struct sdb_logon {
struct sdb_session *session;
char username[MAX_ACCOUNT_NAME];
unsigned short uid;
unsigned int type;
unsigned short state;
unsigned char ssn_key[SMBAUTH_SESSION_KEY_SZ];
} sdb_logon_t;
/*
* Session's states
*
* SDB_SSTATE_START ready to be used
* SDB_SSTATE_INIT initialized
* SDB_SSTATE_STALE lost transport connection
* SDB_SSTATE_DISCONNECTING disconnecting: logoff the user
* disconnect trees, close files
* SDB_SSTATE_CLEANING was in STALE state now just
* cleaning up
* SDB_SSTATE_CONNECTED got transport connection
* SDB_SSTATE_NEGOTIATED did SMB negotiate
*/
#define SDB_SSTATE_START 0
#define SDB_SSTATE_INIT 1
#define SDB_SSTATE_STALE 2
#define SDB_SSTATE_DISCONNECTING 3
#define SDB_SSTATE_CLEANING 4
#define SDB_SSTATE_CONNECTED 5
#define SDB_SSTATE_NEGOTIATED 6
#define SDB_SLCK_READ 1
#define SDB_SLCK_WRITE 2
struct sdb_session {
char srv_name[MAXHOSTNAMELEN];
char domain[MAXHOSTNAMELEN];
char scope[SMB_PI_MAX_SCOPE];
char native_os[SMB_PI_MAX_NATIVE_OS];
char native_lanman[SMB_PI_MAX_LANMAN];
int sock;
short port;
int remote_os;
int remote_lm;
int pdc_type;
};
/*
* Netuse's states
*/
#define SDB_NSTATE_START 0
#define SDB_NSTATE_INIT 1
#define SDB_NSTATE_DISCONNECTING 2
#define SDB_NSTATE_CONNECTED 3
struct sdb_netuse {
struct sdb_session *session;
unsigned short state;
int letter; /* local identity */
unsigned int sid;
unsigned short uid;
unsigned short tid; /* remote identity */
char share[MAX_SHARE_NAME];
};
/*
* Ofile's states
*/
#define SDB_FSTATE_START 0
#define SDB_FSTATE_INIT 1
#define SDB_FSTATE_CLOSING 2
#define SDB_FSTATE_OPEN 3
struct sdb_ofile {
struct sdb_session *session;
struct sdb_netuse *netuse;
unsigned short state;
unsigned int sid;
unsigned short uid;
unsigned short tid;
unsigned short fid; /* remote identity */
char path[MAX_FILE_PATH];
};
typedef struct smbrdr_handle {
unsigned char *srh_buf;
unsigned int srh_mbflags;
unsigned char srh_cmd;
struct sdb_session *srh_session;
struct sdb_netuse *srh_tree;
typedef struct smb_nt_negotiate_rsp {
/*
* SMB_COM_TRANSACTION
*/
typedef struct smb_transact_rsp {
/* value = 10 + SetupCount */
#if 0
#endif
/*
* SMBreadX
*/
typedef struct smb_read_andx_rsp {
#if 0
#endif
extern int smbrdr_default_timeout; /* seconds */
/*
*/
void nb_lock(void);
void nb_unlock(void);
void nb_close(int);
int nb_keep_alive(int, short);
int nb_send(int, unsigned char *, unsigned);
int nb_rcv(int, unsigned char *, unsigned, long);
int nb_exchange(int, unsigned char *, unsigned,
unsigned char *, unsigned, long);
int nb_session_request(int, char *, char *, char *, char *);
/*
*/
int smbrdr_negotiate(char *, char *);
struct sdb_session *smbrdr_session_lock(const char *, int);
void smbrdr_session_unlock(struct sdb_session *);
/*
*/
int smbrdr_logoffx(struct sdb_logon *);
/* smbrdr_netuse.c */
void smbrdr_netuse_logoff(unsigned short);
struct sdb_netuse *smbrdr_netuse_get(int);
DWORD smbrdr_tree_connect(char *, char *, char *, char *, unsigned short *);
int smbrdr_tree_disconnect(unsigned short);
void smbrdr_netuse_put(struct sdb_netuse *);
int smbrdr_tdcon(struct sdb_netuse *);
/*
*/
void smbrdr_ofile_end_of_share(unsigned short);
struct sdb_ofile *smbrdr_ofile_get(int);
void smbrdr_ofile_put(struct sdb_ofile *);
/* smbrdr_lib.c */
void smbrdr_handle_free(smbrdr_handle_t *);
void smbrdr_sign_fini(struct sdb_session *);
void smbrdr_sign_unset_key(struct sdb_session *);
void smbrdr_lock_transport(void);
void smbrdr_unlock_transport(void);
extern smb_log_hdl_t smbrdr_log_hdl;
#endif /* _SMBRDR_H_ */