/*
* 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 2013 Nexenta Systems, Inc. All rights reserved.
*/
/*
* Test program for the smbfs named pipe API.
*/
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <libintl.h>
#include <netsmb/smbfs_api.h>
/*
* This is a quick hack for testing client-side named pipes.
* Its purpose is to test the ability to connect to a server,
* open a pipe, send and receive data. The "hack" aspect is
* the use of hand-crafted RPC messages, which allows testing
* of the named pipe API separately from the RPC libraries.
*
* I captured the two small name pipe messages sent when
* dropped them into the arrays below (bind and info).
* This program sends the two messages (with adjustments)
* and just dumps whatever comes back over the pipe.
* Use wireshark if you want to see decoded messages.
*/
extern char *optarg;
static const uchar_t
srvsvc_bind[] = {
0x05, 0x00, 0x0b, 0x03, 0x10, 0x00, 0x00, 0x00,
0x48, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
0xc8, 0x4f, 0x32, 0x4b, 0x70, 0x16, 0xd3, 0x01,
0x12, 0x78, 0x5a, 0x47, 0xbf, 0x6e, 0xe1, 0x88,
0x03, 0x00, 0x00, 0x00, 0x04, 0x5d, 0x88, 0x8a,
0xeb, 0x1c, 0xc9, 0x11, 0x9f, 0xe8, 0x08, 0x00,
0x2b, 0x10, 0x48, 0x60, 0x02, 0x00, 0x00, 0x00 };
/* This is a srvsvc "get server info" call, in two parts */
static const uchar_t
srvsvc_info[] = {
0x05, 0x00, 0x00, 0x03, 0x10, 0x00, 0x00, 0x00,
/* V - RPC frag length */
0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* ... and the operation number is: VVVV */
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x15, 0x00,
/* server name, length 14 vv ... */
0x01, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00 };
/* UNC server here, i.e.: "\\192.168.1.6" */
static char *server;
static void
srvinfo_usage(void)
{
printf("usage: srvinfo [-d domain][-u user][-p passwd] server\n");
exit(1);
}
int
{
int c, error;
switch (c) {
case 'v':
smb_verbose = 1;
break;
case 'd':
break;
case 'u':
break;
case 'p':
break;
case '?':
break;
}
}
argv[0]);
}
/*
* This section is intended to demonstrate how an
* RPC client library might use this interface.
*/
if (error) {
goto out;
}
/*
* Set server, share, domain, user
* (in the ctx handle).
*/
if (dom)
if (usr)
if (pw)
/*
* If this code were in smbutil or mount_smbfs, it would
* get system and $HOME/.nsmbrc settings here, like this:
*/
#if 0
if (error) {
goto out;
}
#endif
/*
* Resolve the server address,
* setup derived defaults.
*/
if (error) {
goto out;
}
/*
* Get the session and tree.
*/
if (error) {
goto out;
}
if (error) {
goto out;
}
/*
* Do some named pipe I/O.
*/
if (error) {
goto out;
}
out:
return ((error) ? 1 : 0);
}
static void
int ofs = 0;
while (len--) {
if (ofs % 16 == 0)
ofs++;
}
printf("\n");
}
/*
* Put a unicode UNC server name, including the null.
* Quick-n-dirty, just for this test...
*/
static int
{
char c;
*p++ = '\\'; *p++ = '\0';
*p++ = '\\'; *p++ = '\0';
do {
c = *s++;
if (c == '/')
c = '\\';
*p++ = c;
*p++ = '\0';
} while (c != 0);
return (p - buf);
}
/* Get a little-endian int. Just for testing. */
static int
{
return (p[0] + (p[1]<<8) + (p[2]<<16) + (p[3]<<24));
}
/*
* Send the bind and read the ack.
* This tests smb_fh_xactnp.
*/
static int
{
more = 0;
sizeof (srvsvc_bind), (char *)srvsvc_bind,
if (err) {
return (err);
}
if (smb_verbose) {
}
if (more > 0) {
}
if (len == -1) {
return (err);
}
if (smb_verbose) {
}
}
return (0);
}
static int
{
uchar_t *p;
/*
* Build the info request - two parts.
* See above: srvsvc_info
*
* First part: RPC header, etc.
*/
p = sendbuf;
p += len;
/* Second part: UNC server name */
p += len;
/* Third part: level, etc. (align4) */
*p++ = '\0';
*p++ = 101; /* the "level" */
*p++ = 0; *p++ = 0; *p++ = 0;
/*
* Compute total length, and fixup RPC header.
*/
/*
* Send the info request, read the response.
* This tests smb_fh_write, smb_fh_read.
*/
if (wlen == -1) {
return (err);
}
return (EIO);
}
if (rlen == -1) {
return (err);
}
if (smb_verbose) {
}
if (x != 0x10) {
printf("Data representation 0x%x not supported\n", x);
return (ENOTSUP);
}
return (0);
}
static int
{
if (fd < 0) {
return (errno);
}
/* Test this too. */
if (err) {
goto out;
}
if (err) {
goto out;
}
if (err)
out:
return (err);
}