/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
/*
stoa - convert string to address
If a string begins in \o or \O, the following address is octal
" " " " " \x or \X, the following address is hex
Otherwise, a string is considered text. Text may be quoted
with double quotes and the C-like escapes \n, \b, \t, \v, \r, and \nnn
(nnn = octal char) are recognized.
A \ followed by a newline causes the newline
to vanish. A \ followed by any other char causes any "magic" of
any other char to disappear.
Other escape sequences recognized are:
\!cmd args [ \! || EOL ]
which is replaced by the raw output of the execution of cmd.
This may only be used in a string.
\$cmd args [ \$ || EOL ]
which is replaced by the output of the execution of cmd and
is then reprocessed.
A NULL is returned on any error(s).
*/
#include <stdio.h>
#include <memory.h>
#include <ctype.h>
#include "nsaddr.h"
#define FALSE 0;
int sbp = 0;
extern void free();
struct netbuf *
char *str;
{
if (!str)
return NULL;
++str;
if (!addr) {
return NULL;
}
/* Now process the address */
quote = 0;
if (*str == '\\') {
++str;
switch (*str) {
case 'X': /* hex */
case 'x':
break;
case 'o': /* octal */
case 'O':
break;
case '\0': /* No address given!, length is 0 */
break;
default: /* \ is handled by dostring */
break;
}
}
else {
quote = 1;
++str;
}
}
if (myadr)
return NULL;
}
return NULL;
else
return addr;
}
/*
dostring: Copy string at s to buf translating
escaped characters and shell escapes.
return length of string.
*/
int
char *s, *buf;
int quote;
{
char *xcmd();
int l = 0;
char *rout;
while (*s) {
break;
}
else if (*s == '\\')
switch(*++s) {
case '!': /* raw shell escape */
len += l;
}
break;
case '\n': /* ignore newline */
++s;
break;
case 'b': /* backspace */
break;
case 'n': /* newline */
break;
case 'r': /* return */
break;
case 't': /* horiz. tab */
break;
case 'v': /* vert. tab */
case '0':
case '1':
case '2':
case '3':
break;
case 0: /* end of string -- terminate */
break;
default: /* take the character blindly */
break;
}
break;
else
}
}
/*
dobase : converts a hex or octal ASCII string
to a binary address. Only HEX or OCT may be used
for type.
return length of binary string (in bytes), 0 if error.
The binary result is placed at buf.
*/
int
char *s, *buf; /* source ASCII, result binary string */
int type;
{
void memcp();
int shift = 0;
char *end;
/* any non-white, non-digits cause address to be rejected,
other fields are ignored */
buf[0] = '\0';
return 0;
}
--end;
if (shift > 5) {
}
}
else /* hex */
--end;
}
if (bp == 0) {
return 0;
}
/* need to catch end case to avoid extra 0's in front */
if (!shift)
bp++;
}
#ifdef NOTUSED
/*
atos(str, addr, type)
convert address to ASCII form with address in hex, octal,
or character form.
return pointer to buffer (NULL on failure).
*/
char *
char *str;
int type;
{
char *xfer();
void memcp();
char *base;
return NULL;
return NULL;
else
mystr = 1;
switch (type) {
case OCT:
/* first add \o */
sbuf[0] = '\\';
case HEX:
/* first add \x */
sbuf[0] = '\\';
case RAW:
if (base)
return base;
default:
return NULL;
}
}
/*
x_atos, o_atos
return the number of bytes occupied by string + NULL*/
/*
x_atos : convert an address string a, length s
to hex ASCII in s */
unsigned
x_atos(s, a, l)
char *s, *a;
unsigned l;
{
char *b;
b = s;
while (l--) {
++a;
}
*s = '\0';
return (s - b + 1);
}
/*
o_atos : convert an address a, length l
to octal ASCII in s */
unsigned
o_atos(s, a, l)
char *s, *a;
unsigned l;
{
int i, shift;
char *b;
b = s;
if (l == 0) {
*s = '\0';
return 0;
}
/* take care of partial bits and set shift factor for next 3 */
i = l % 3;
shift = 2 + i;
while (l)
if (shift <= 5) {
if (shift == 0) {
++a;
--l;
}
}
else {
*s++ = itoac(i);
shift -= 3;
--l;
}
*s++ = '\0';
return (s - b + 1);
}
#endif /* NOTUSED */
void
char *d, *s;
int n;
{
while (n--)
*d++ = *s++;
}
/* transfer block to a given destination or allocate one of the
right size
if max = 0 : ignore max
*/
char *
{
return NULL;
}
if (!dest)
return NULL;
}
return dest;
}
/*
prescan: scan through string s, expanding all \$...\$
as shell escapes.
Return pointer to string of expanded text.
*/
char *
prescan(s)
char *s;
{
int scan();
if (!s || !*s || !scan(s))
return NULL;
return scanbuf;
}
/*
scan: scan through string s, expanding all \$...\$.
(Part II of prescan)
Return 0 if anything failed, else 1.
*/
int
scan(s)
char *s;
{
char *xcmd();
char *cmd;
int len;
while (*s) {
level past %d on shell escape\n", rec);
return 0;
}
if (*cmd != '\0')
}
else
return 0;
}
return 0;
}
}
return 1;
}
/*
xcmd : extract command line for shell escape and execute it
return pointer to output of command
*/
char *
char *s; /* input string */
char ec; /* escape char ( $ or ! ) */
char **ps; /* address of input string pointer */
int *len; /* Number of bytes of output from command */
{
int pclose();
*len = 0;
return NULL;
}
return NULL;
}
while (*s) {
s += 2;
break;
}
else
}
*cmdp = '\0';
*ps = s;
break;
}
return ocmd;
}