rap.c revision 02d09e03eb27f3a2dc299de704e45dae5173f43f
/*
* Copyright (c) 2000, Boris Popov
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Boris Popov.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: rap.c,v 1.5 2004/12/13 00:25:23 lindak Exp $
*
* This is very simple implementation of RAP protocol.
*/
#include <sys/isa_defs.h>
#include <ctype.h>
#include <stdio.h>
#include <unistd.h>
#include <strings.h>
#include <stdlib.h>
#include <libintl.h>
#include <sysexits.h>
#include "private.h"
static int
{
char *np;
int len;
switch (*s++) {
case 'L':
case 'T':
case 'W':
len = 2;
break;
case 'D':
case 'O':
len = 4;
break;
case 'b':
case 'F':
len = 1;
break;
case 'r':
case 's':
len = 0;
break;
default:
return (EINVAL);
}
if (isdigit(*s)) {
s = np;
}
*(const char **)next = s;
return (0);
}
static int
{
char *np;
int len = 0;
switch (*s++) {
case 'e':
case 'h':
len = 2;
break;
case 'i':
len = 4;
break;
case 'g':
len = 1;
break;
default:
return (EINVAL);
}
if (isdigit(*s)) {
s = np;
}
*(const char **)next = s;
return (0);
}
static int
{
char *np;
int len;
switch (*s++) {
case 'B':
len = 1;
break;
case 'W':
len = 2;
break;
case 'D':
case 'O':
case 'z':
len = 4;
break;
default:
return (EINVAL);
}
if (isdigit(*s)) {
s = np;
}
*(const char **)next = s;
return (0);
}
static int
{
return (0);
}
/*
* Marshal RAP request parameters.
* Note: value is in host order.
*/
static int
{
int len = 0;
char *p;
switch (ptype) {
case 'L':
case 'W':
/* LINTED */
break;
case 'D':
/* LINTED */
break;
case 'b':
default:
return (EINVAL);
}
return (0);
}
int
{
char *p;
return (ENOMEM);
/*
* Calculate length of request parameter block
*/
while (*p) {
if (smb_rap_parserqparam(p, &p, &plen) != 0)
break;
}
return (ENOMEM);
return (0);
}
void
{
#ifdef NOTYETDEFINED
#endif
}
int
{
char ptype = *p;
if (error)
return (error);
switch (ptype) {
case 'L':
/* FALLTHROUGH */
case 'W':
case 'D':
case 'b':
break;
default:
return (EINVAL);
}
return (0);
}
int
{
char ptype = *p;
if (error)
return (error);
switch (ptype) {
case 'r':
break;
default:
return (EINVAL);
}
return (0);
}
int
{
char ptype = *p;
if (error)
return (error);
switch (ptype) {
case 'h':
/* LINTED */
break;
default:
return (EINVAL);
}
return (0);
}
int
{
char ptype;
0, NULL, /* int tdatacnt, void *tdata */
&buffer_oflow);
if (error)
return (error);
/* LINTED */
/*
* Note: First is a "LanMan API" error code.
*/
if (rparamcnt < 2)
return (EBADRPC);
/*
* Could also return zero and let the caller
* come get r_result via smb_rap_error(),
* but in case they dont...
*/
}
if (rparamcnt < 2)
return (EBADRPC);
/* Save the returned data length */
done = 0;
while (!done && *p) {
ptype = *p;
switch (ptype) {
case 'e':
if (rparamcnt < 2)
return (EBADRPC);
/* LINTED */
rparamcnt -= 2;
p++;
break;
default:
done = 1;
}
#if 0 /* commented out in Darwin. Why? */
if (error) {
"reply parameter mismatch %s"), 0, p);
return (EBADRPC);
}
#endif
}
/*
* In general, unpacking entries we may need to relocate
* entries for proper aligning. For now use them as is.
*/
while (entries--) {
while (*p) {
ptype = *p;
if (error) {
"reply data mismatch %s"), 0, p);
return (EBADRPC);
}
return (EBADRPC);
switch (ptype) {
case 'z':
/* LINTED */
break;
}
}
}
return (error);
}
int
{
if (error)
return (error);
return (0);
}