/*
* 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 2014 Nexenta Systems, Inc. All rights reserved.
*/
#include <smbsrv/smb_kproto.h>
#include <smbsrv/smb_fsops.h>
#include <smbsrv/smb_share.h>
#include <smbsrv/mailslot.h>
#include <smbsrv/winioctl.h>
/*
* count of bytes in server response packet
* except parameters and data. Note that setup
* word count is zero.
*/
/*
* We started by using common functions for transaction/transaction2
* and transaction_secondary/transaction2_secondary because they
* are respectively so similar. However, it turned out to be a bad
* idea because of quirky differences. Be sure if you modify one
* of these four functions to check and see if the modification should
* be applied to its peer.
*/
static int smb_trans_ready(smb_xa_t *);
{
return (SDRC_SUCCESS);
}
void
{
}
{
int rc;
char *stn;
int ready;
return (SDRC_ERROR);
}
if (rc != 0)
return (SDRC_ERROR);
return (SDRC_ERROR);
}
/* Should be some alignment stuff here in SMB? */
} else {
}
if (rc != 0) {
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
if (smb_xa_open(xa)) {
return (SDRC_ERROR);
}
if (!ready) {
}
if (!smb_xa_complete(xa)) {
return (SDRC_ERROR);
}
}
{
return (SDRC_SUCCESS);
}
void
{
}
{
int rc;
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
}
return (SDRC_DROP_VC);
}
if (rc != 0)
return (SDRC_ERROR);
/*
* The words psdisp, dsdisp, tell us what displacement
* into the entire trans parameter and data buffers
* where we should put the params & data that are
* delivered by this request. [MS-CIFS] says all the
* parameters and data SHOULD be sent sequentially, so
* so we can normally reassemble by simply appending.
* However, the components MAY come out of order, so
* check and set the current offset. This is rare,
* and we might like to know when this happens, so
* fire some static dtrace probes when it does.
*/
}
}
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
if (!smb_trans_ready(xa))
return (SDRC_NO_REPLY);
if (!smb_xa_complete(xa))
return (SDRC_NO_REPLY);
}
{
return (SDRC_SUCCESS);
}
void
{
}
{
int rc;
if (rc != 0)
return (SDRC_ERROR);
return (SDRC_NOT_IMPLEMENTED);
}
{
return (SDRC_SUCCESS);
}
void
{
}
{
int ready;
int rc;
if (rc != 0)
return (SDRC_ERROR);
if (xa == 0) {
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
if (smb_xa_open(xa)) {
return (SDRC_ERROR);
}
if (!ready) {
}
if (!smb_xa_complete(xa)) {
return (SDRC_ERROR);
}
}
{
return (SDRC_SUCCESS);
}
void
{
}
{
int rc;
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
}
return (SDRC_DROP_VC);
}
if (rc != 0)
return (SDRC_ERROR);
if (fid != 0xFFFF)
/*
* See comment in smb_com_transaction_secondary
*/
}
}
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
if (!smb_trans_ready(xa))
return (SDRC_NO_REPLY);
if (!smb_xa_complete(xa))
return (SDRC_NO_REPLY);
}
static smb_sdrc_t
{
int rc;
case NT_TRANSACT_CREATE:
break;
break;
break;
break;
case NT_TRANSACT_IOCTL:
break;
case NT_TRANSACT_QUERY_QUOTA:
break;
case NT_TRANSACT_SET_QUOTA:
break;
case NT_TRANSACT_RENAME:
break;
default:
return (SDRC_ERROR);
}
switch (rc) {
case SDRC_SUCCESS:
break;
case SDRC_DROP_VC:
case SDRC_NO_REPLY:
case SDRC_ERROR:
case SDRC_SR_KEPT:
return (rc);
case SDRC_NOT_IMPLEMENTED:
return (SDRC_ERROR);
default:
break;
}
return (SDRC_ERROR);
}
/* neato, blast it over there */
"b3.llllllllbCw#.C#.C",
n_param, /* Total Parameter Bytes */
n_data, /* Total Data Bytes */
n_param, /* Total Parameter Bytes this buffer */
param_off, /* Param offset from header start */
0, /* Param displacement */
n_data, /* Total Data Bytes this buffer */
data_off, /* Data offset from header start */
0, /* Data displacement */
n_setup, /* suwcnt */
total_bytes, /* Total data bytes */
&xa->rep_param_mb,
&xa->rep_data_mb);
}
{
return (SDRC_SUCCESS);
}
void
{
}
{
int ready;
int rc;
if (rc != 0)
return (SDRC_ERROR);
if (xa == 0) {
return (SDRC_ERROR);
}
xa->smb_timeout = 0;
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
if (smb_xa_open(xa)) {
return (SDRC_ERROR);
}
if (!ready) {
}
if (!smb_xa_complete(xa)) {
return (SDRC_ERROR);
}
}
{
return (SDRC_SUCCESS);
}
void
{
}
{
int rc;
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
}
return (SDRC_DROP_VC);
}
if (rc != 0)
return (SDRC_ERROR);
if (fid != 0xFFFF)
/*
* See comment in smb_com_transaction_secondary
*/
}
}
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
if (!smb_trans_ready(xa))
return (SDRC_NO_REPLY);
if (!smb_xa_complete(xa))
return (SDRC_NO_REPLY);
}
static int
{
int rc;
return (rc);
}
static void
{
}
static void
{
pword);
}
int
{
/*
* Number of data bytes that will
* be sent in the current response
*/
/*
* Total number of data bytes that
* are sent till now. This is only
* used for calculating current data
* displacement
*/
/*
* Number of parameter bytes should
* be sent for the current response.
* It is 8 for the 1st response and
* 0 for others
*/
/* number of setup and parameter bytes */
/* data and parameter displacement */
/* parameter and data offset and pad */
/*
* total bytes of parameters and data
* in the packet, plus the pad bytes.
*/
int tot_packet_bytes;
char *sent_buf;
&esi.es_bufsize) != 0)
return (SDRC_NOT_IMPLEMENTED);
if (level != 1) {
/*
* Only level 1 is valid for NetShareEnum
* None of the error codes in the spec are meaningful
* here. This error code is returned by Windows.
*/
ERROR_INVALID_LEVEL, 0, 0, 0);
return (SDRC_SUCCESS);
}
/* client buffer size is not big enough to hold any shares */
return (SDRC_SUCCESS);
}
/*
* Initialize the reply mbuf chain. Note that we re-initialize
* this on each pass through the loop below.
*/
/*
* The rep_setup_mb is already initialized in smb_trans_dispatch().
* Calling MBC_INIT() will initialized the structure and so the
* pointer to the mbuf chains will be lost. Therefore, we need
* to free the resources before calling MBC_INIT() again.
*/
n_setup = 0; /* Setup count for NetShareEnum SMB is 0 */
n_param = 8;
tot_data_scnt = 0;
first_resp = B_TRUE;
if (data_scnt > pkt_bufsize)
/* Only the 1st response packet contains parameters */
if (first_resp) {
? ERROR_MORE_DATA : 0,
}
/* data off from hdr start */
(void) smb_mbc_encodef(&reply,
"bww2.wwwwwwb.Cw#.C#.C",
n_param, /* Total Parameter Bytes */
param_scnt, /* Total Parameter Bytes this buffer */
param_off, /* Param offset from header start */
param_disp, /* Param displacement */
data_scnt, /* Total Data Bytes this buffer */
data_off, /* Data offset from header start */
data_disp, /* Data displacement */
n_setup, /* suwcnt */
tot_packet_bytes, /* Total data bytes */
&xa->rep_param_mb,
&xa->rep_data_mb);
}
return (SDRC_NO_REPLY);
}
int
{
char *share;
char *password;
return (SDRC_NOT_IMPLEMENTED);
NERR_NetNameNotFound, 0, 0);
if (si)
return (SDRC_SUCCESS);
}
password = "";
switch (level) {
case 0 :
si->shr_oemname);
break;
case 1 :
break;
case 2 :
break;
default:
ERROR_INVALID_LEVEL, 0, 0);
return (SDRC_NOT_IMPLEMENTED);
}
return (SDRC_SUCCESS);
}
int
{
char *domain;
char *hostname;
(level != 10)) {
NERR_BadTransactConfig, 0, 0, 0);
return (SDRC_SUCCESS);
}
MBC_LENGTH(&str_mb));
return (SDRC_SUCCESS);
}
int
{
unsigned char *user;
int rc;
&user,
&level,
&max_bytes);
if (rc != 0)
return (SDRC_NOT_IMPLEMENTED);
NERR_UserNotFound, 0, 0);
return (SDRC_SUCCESS);
}
{
return (SDRC_ERROR);
sizeof (server_name));
/* valid levels are 0 and 1 */
switch (level) {
case 0:
break;
case 1:
break;
default:
ERROR_INVALID_LEVEL, 0, 0);
return (SDRC_SUCCESS);
}
return (SDRC_SUCCESS);
}
/*
* 6.4 The NetServerEnum2 RAP Service
*
* The NetServerEnum2 RAP service lists all computers of the specified type
* or types that are visible in the specified domains. It may also
* enumerate domains.
*
* The following definition uses the notation and terminology defined in
* the CIFS Remote Administration Protocol specification, which is required
* in order to make it well-defined. The definition is:
*
* uint16_t NetServerEnum2 (
* uint16_t sLevel,
* RCVBUF pbBuffer,
* RCVBUFLEN cbBuffer,
* ENTCOUNT pcEntriesRead,
* uint16_t *pcTotalAvail,
* uint32_t fServerType,
* char *pszDomain,
* );
*
* where:
*
* sLevel specifies the level of detail (0 or 1) requested.
*
* pbBuffer points to the buffer to receive the returned data. If the
* function is successful, the buffer contains a sequence of
* server_info_x structures, where x is 0 or 1, depending on the
* level of detail requested.
*
* cbBuffer specifies the size, in bytes, of the buffer pointed to by
* the pbBuffer parameter.
*
* pcEntriesRead points to a 16 bit variable that receives a count of
* the number of servers enumerated in the buffer. This count is
* valid only if NetServerEnum2 returns the NERR_Success or
* ERROR_MORE_DATA values.
*
* pcTotal Avail points to a 16 bit variable that receives a count of
* the total number of available entries. This count is valid only if
* NetServerEnum2 returns the NERR_Success or ERROR_MORE_DATA values.
*
* fServerType specifies the type or types of computers to enumerate.
* Computers that match at least one of the specified types are
* returned in the buffer. Possible values are defined in the request
* parameters section.
*
* pszDomain points to a null-terminated string that contains the
* name of the workgroup in which to enumerate computers of the
* specified type or types. If the pszDomain parameter is a null
* string or a null pointer, servers are enumerated for the current
* domain of the computer.
*
* 6.4.1 Transaction Request Parameters section
*
* The Transaction request parameters section in this instance contains:
* . The 16 bit function number for NetServerEnum2 which is 104.
* . The parameter descriptor string which is "WrLehDz".
* . The data descriptor string for the (returned) data which is "B16" for
* level detail 0 or "B16BBDz" for level detail 1.
* . The actual parameters as described by the parameter descriptor
* string.
*
* The parameters are:
* . A 16 bit integer with a value of 0 or 1 (corresponding to the "W" in
* the parameter descriptor string. This represents the level of detail
* the server is expected to return
* . A 16 bit integer that contains the size of the receive buffer.
* . A 32 bit integer that represents the type of servers the function
* should enumerate. The possible values may be any of the following or
* a combination of the following:
*
* SV_TYPE_WORKSTATION 0x00000001 All workstations
* SV_TYPE_SERVER 0x00000002 All servers
* SV_TYPE_SQLSERVER 0x00000004 Any server running with SQL
* server
* SV_TYPE_DOMAIN_CTRL 0x00000008 Primary domain controller
* SV_TYPE_DOMAIN_BAKCTRL 0x00000010 Backup domain controller
* SV_TYPE_TIME_SOURCE 0x00000020 Server running the timesource
* service
* SV_TYPE_AFP 0x00000040 Apple File Protocol servers
* SV_TYPE_NOVELL 0x00000080 Novell servers
* SV_TYPE_DOMAIN_MEMBER 0x00000100 Domain Member
* SV_TYPE_PRINTQ_SERVER 0x00000200 Server sharing print queue
* SV_TYPE_DIALIN_SERVER 0x00000400 Server running dialin service.
* SV_TYPE_XENIX_SERVER 0x00000800 Xenix server
* SV_TYPE_NT 0x00001000 NT server
* SV_TYPE_WFW 0x00002000 Server running Windows for
* Workgroups
* SV_TYPE_SERVER_NT 0x00008000 Windows NT non DC server
* SV_TYPE_POTENTIAL_BROWSER 0x00010000 Server that can run the browser
* service
* SV_TYPE_BACKUP_BROWSER 0x00020000 Backup browser server
* SV_TYPE_MASTER_BROWSER 0x00040000 Master browser server
* SV_TYPE_DOMAIN_MASTER 0x00080000 Domain Master Browser server
* SV_TYPE_LOCAL_LIST_ONLY 0x40000000 Enumerate only entries marked
* "local"
* SV_TYPE_DOMAIN_ENUM 0x80000000 Enumerate Domains. The pszDomain
* parameter must be NULL.
*
* . A null terminated ASCII string representing the pszDomain parameter
* described above
*
* 6.4.2 Transaction Request Data section
*
* There is no data or auxiliary data to send as part of the request.
*
* 6.4.3 Transaction Response Parameters section
*
* The transaction response parameters section consists of:
* . A 16 bit word indicating the return status. The possible values are:
*
* Code Value Description
* NERR_Success 0 No errors encountered
* ERROR_MORE_DATA 234 Additional data is available
* NERR_ServerNotStarted 2114 The RAP service on the remote computer
* is not running
* NERR_BadTransactConfig 2141 The server is not configured for
* transactions, IPC$ is not shared
*
* . A 16 bit "converter" word.
* . A 16 bit number representing the number of entries returned.
* . A 16 bit number representing the total number of available entries.
* If the supplied buffer is large enough, this will equal the number of
* entries returned.
*
* 6.4.4 Transaction Response Data section
*
* The return data section consists of a number of SERVER_INFO_1 structures.
* The number of such structures present is determined by the third entry
* (described above) in the return parameters section.
*
* At level detail 0, the Transaction response data section contains a
* number of SERVER_INFO_0 data structure. The number of such structures is
* equal to the 16 bit number returned by the server in the third parameter
* in the Transaction response parameter section. The SERVER_INFO_0 data
* structure is defined as:
*
* struct SERVER_INFO_0 {
* char sv0_name[16];
* };
*
* where:
*
* sv0_name is a null-terminated string that specifies the name of a
* computer or domain .
*
* At level detail 1, the Transaction response data section contains a
* number of SERVER_INFO_1 data structure. The number of such structures is
* equal to the 16 bit number returned by the server in the third parameter
* in the Transaction response parameter section. The SERVER_INFO_1 data
* structure is defined as:
*
* struct SERVER_INFO_1 {
* char sv1_name[16];
* char sv1_version_major;
* char sv1_version_minor;
* uint32_t sv1_type;
* char *sv1_comment_or_master_browser;
* };
*
* sv1_name contains a null-terminated string that specifies the name
* of a computer, or a domain name if SV_TYPE_DOMAIN_ENUM is set in
* sv1_type.
*
* sv1_version_major whatever was specified in the HostAnnouncement
* or DomainAnnouncement frame with which the entry was registered.
*
* sv1_version_minor whatever was specified in the HostAnnouncement
* or DomainAnnouncement frame with which the entry was registered.
*
* sv1_type specifies the type of software the computer is running.
* The member can be one or a combination of the values defined above
* in the Transaction request parameters section for fServerType.
*
*
* sv1_comment_or_master_browser points to a null-terminated string. If
* the sv1_type indicates that the entry is for a domain, this
* specifies the name of server running the domain master browser;
* otherwise, it specifies a comment describing the server. The comment
* can be a null string or the pointer may be a null pointer.
*
* In case there are multiple SERVER_INFO_1 data structures to
* return, the server may put all these fixed length structures in
* the return buffer, leave some space and then put all the variable
* length data (the actual value of the sv1_comment strings) at the
* end of the buffer.
*
* There is no auxiliary data to receive.
*/
int
{
unsigned char *domain;
char *hostname, *s;
return (SDRC_NOT_IMPLEMENTED);
return (SDRC_SUCCESS);
}
if ((server_type & MY_SERVER_TYPE) == 0) {
return (SDRC_SUCCESS);
}
if (level == 1) {
}
return (SDRC_SUCCESS);
}
static boolean_t
{
static char *mailslots[] = {
};
int i;
return (B_TRUE);
return (B_FALSE);
}
/*
* smb_trans_nmpipe
*
* This is used for RPC bind and request transactions.
*
* If the data available from the pipe is larger than the maximum
* data size requested by the client, return as much as requested.
* The residual data remains in the pipe until the client comes back
* with a read request or closes the pipe.
*
* When we read less than what's available, we MUST return the
* status NT_STATUS_BUFFER_OVERFLOW (or ERRDOS/ERROR_MORE_DATA)
*/
static smb_sdrc_t
{
return (SDRC_ERROR);
}
/*
* A little confusing perhaps, but the fsctl "input" is what we
* write to the pipe (from the transaction "send" data), and the
* fsctl "output" is what we read from the pipe (and becomes the
* transaction receive data).
*/
if (status) {
return (SDRC_ERROR);
/* Warnings like NT_STATUS_BUFFER_OVERFLOW are OK */
}
return (SDRC_SUCCESS);
}
static smb_sdrc_t
{
char *req_fmt;
char *rep_fmt;
if (xa->smb_suwcnt > 0) {
if (rc != 0)
goto trans_err_not_supported;
switch (opcode) {
case TRANS_SET_NMPIPE_STATE:
&devstate)) != 0)
goto trans_err_not_supported;
rc = SDRC_SUCCESS;
break;
case TRANS_TRANSACT_NMPIPE:
break;
case TRANS_WAIT_NMPIPE:
rc = SDRC_SUCCESS;
break;
default:
goto trans_err_not_supported;
}
} else {
goto trans_err_not_supported;
goto trans_err_not_supported;
switch (opcode) {
case API_WshareEnum:
break;
case API_WshareGetInfo:
break;
case API_WserverGetInfo:
break;
case API_WUserGetInfo:
break;
case API_WWkstaGetInfo:
break;
case API_NetServerEnum2:
break;
default:
goto trans_err_not_supported;
}
}
switch (rc) {
case SDRC_SUCCESS:
break;
case SDRC_DROP_VC:
case SDRC_NO_REPLY:
case SDRC_ERROR:
return (rc);
case SDRC_NOT_IMPLEMENTED:
goto trans_err_not_supported;
default:
break;
}
goto trans_err_too_small;
}
/* neato, blast it over there */
/* Param off from hdr start */
"bww2.wwwwwwb.Cw#.C#.C",
n_param, /* Total Parameter Bytes */
n_data, /* Total Data Bytes */
n_param, /* Total Parameter Bytes this buffer */
param_off, /* Param offset from header start */
0, /* Param displacement */
n_data, /* Total Data Bytes this buffer */
data_off, /* Data offset from header start */
0, /* Data displacement */
n_setup, /* suwcnt */
total_bytes, /* Total data bytes */
&xa->rep_param_mb,
&xa->rep_data_mb);
goto trans_err;
goto trans_err;
10, /* wct */
4, 0, /* tpscnt tdscnt */
0, 0, 0, /* dscnt dsoff dsdisp */
0, /* suwcnt */
4, /* bcc */
rc,
0); /* converter word? */
}
static smb_sdrc_t
{
char *fmt;
goto trans_err_not_supported;
/*
* Save this for /proc to read later.
*/
/* for now, only respond to the */
switch (opcode) {
case TRANS2_OPEN2:
break;
case TRANS2_CREATE_DIRECTORY:
break;
case TRANS2_FIND_FIRST2:
/*
* Should have enough room to send the response
* data back to client.
*/
if (n_data == 0) {
return (SDRC_ERROR);
}
break;
case TRANS2_FIND_NEXT2:
/*
* Should have enough room to send the response
* data back to client.
*/
if (n_data == 0) {
return (SDRC_ERROR);
}
break;
/*
* Should have enough room to send the response
* data back to client.
*/
if (n_data == 0) {
return (SDRC_ERROR);
}
break;
break;
/*
* Should have enough room to send the response
* data back to client.
*/
if (n_data == 0) {
return (SDRC_ERROR);
}
break;
/*
* Should have enough room to send the response
* data back to client.
*/
if (n_data == 0) {
return (SDRC_ERROR);
}
break;
break;
break;
case TRANS2_GET_DFS_REFERRAL:
break;
default:
goto trans_err_not_supported;
}
switch (rc) {
case SDRC_SUCCESS:
break;
case SDRC_DROP_VC:
case SDRC_NO_REPLY:
case SDRC_ERROR:
return (rc);
case SDRC_NOT_IMPLEMENTED:
goto trans_err_not_supported;
default:
break;
}
goto trans_err_too_small;
}
/* neato, blast it over there */
/*
* Including the nt_unknown_secret value persuades netmon to
* display the correct data format for QueryPathInfo and
* QueryFileInfo.
*/
if (opcode == TRANS2_QUERY_FILE_INFORMATION ||
fmt = "bww2.wwwwwwb.Cw#.CwC";
nt_unknown_secret = 0x0100;
}
else
{
/* Param off from hdr start */
fmt = "bww2.wwwwwwb.Cw#.C#.C";
}
fmt,
n_param, /* Total Parameter Bytes */
n_param, /* Total Parameter Bytes this buffer */
param_off, /* Param offset from header start */
0, /* Param displacement */
data_off, /* Data offset from header start */
0, /* Data displacement */
n_setup, /* suwcnt */
total_bytes, /* Total data bytes */
&xa->rep_param_mb,
&xa->rep_data_mb);
goto trans_err;
goto trans_err;
10, /* wct */
4, 0, /* tpscnt tdscnt */
0, 0, 0, /* dscnt dsoff dsdisp */
0, /* suwcnt */
4, /* bcc */
rc,
0); /* converter word? */
}
smb_xa_t *
{
/*
* Sanity check what the client says it will send.
* Caller handles NULL return as ERRnoroom.
*/
return (NULL);
return (NULL);
return (NULL);
/*
* Limit what the client asks us to allocate for
* returned setup, params, data.
*/
/* request parts */
/* reply parts */
/*
* The new xa structure is checked against the current list to see
* if it exists already.
*/
while (nxa) {
!SMB_XA_CLOSED(nxa) &&
return (NULL);
}
}
return (xa);
}
void
{
if (xa->xa_pipe_name)
/* request parts */
/* reply parts */
}
smb_xa_t *
{
return (xa);
}
void
{
return;
}
}
int
{
int rc;
rc = 0;
} else {
}
return (rc);
}
void
{
return;
}
}
int
{
int rc;
rc = 0; /* error ("not complete") */
} else {
/*
* During trans & trans-secondary processing,
* we copied the request data into these.
* Now we want to parse them, so we need to
* move the "finger" back to the beginning.
*/
}
return (rc);
}
smb_xa_t *
{
while (xa) {
!SMB_XA_CLOSED(xa) &&
break;
}
}
return (xa);
}