2 |
- |
1 |
/* magic to get SUSV2 standard, including pread, pwrite*/
|
64 |
7u83 |
2 |
#define _XOPEN_SOURCE 600
|
2 |
- |
3 |
/* magic to get 64-bit pread/pwrite */
|
|
|
4 |
#define _LARGEFILE64_SOURCE
|
|
|
5 |
/* magic to get 64-bit stat on Linux, maybe others */
|
|
|
6 |
#define _FILE_OFFSET_BITS 64
|
|
|
7 |
|
|
|
8 |
#ifdef sgi
|
|
|
9 |
#define _BSD_TYPES 1 /* for struct timeval */
|
|
|
10 |
#include <sys/select.h>
|
|
|
11 |
#define _BSD_SOURCE 1 /* for ruserok */
|
|
|
12 |
/*
|
|
|
13 |
* SGI IRIX 5.x doesn't allow inclusion of both inttypes.h and
|
|
|
14 |
* sys/types.h. These definitions are the ones we need from
|
|
|
15 |
* inttypes.h that aren't in sys/types.h.
|
|
|
16 |
*
|
|
|
17 |
* Unlike most of our #ifdef's, IRIX5X must be set in the makefile.
|
|
|
18 |
*/
|
|
|
19 |
#ifdef IRIX5X
|
|
|
20 |
#define __inttypes_INCLUDED
|
|
|
21 |
typedef unsigned int uint32_t;
|
|
|
22 |
typedef signed long long int int64_t;
|
|
|
23 |
typedef unsigned long long int uint64_t;
|
|
|
24 |
#endif /* IRIX5X */
|
|
|
25 |
#endif /* sgi */
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
#ifdef sun /* sparc and __svr4__ are also defined on the offending machine */
|
|
|
29 |
#define __EXTENSIONS__ 1 /* for struct timeval */
|
|
|
30 |
#endif
|
|
|
31 |
|
|
|
32 |
#include <inttypes.h> /* for int64_t et al. */
|
|
|
33 |
#include <stdlib.h>
|
|
|
34 |
#include <stdarg.h> /* for va_list, vararg macros */
|
|
|
35 |
#ifndef va_copy
|
|
|
36 |
#ifdef __va_copy
|
|
|
37 |
#define va_copy __va_copy
|
|
|
38 |
#else
|
|
|
39 |
#define va_copy(d, s) memmove(&(d), &(s), sizeof(va_list))
|
|
|
40 |
#endif /* __va_copy */
|
|
|
41 |
#endif /* va_copy */
|
|
|
42 |
#include <sys/types.h>
|
|
|
43 |
#include <string.h> /* for memmove */
|
|
|
44 |
#include <unistd.h> /* for write */
|
|
|
45 |
#include <fcntl.h>
|
|
|
46 |
|
|
|
47 |
#define ulong p9ulong /* because sys/types.h has some of these sometimes */
|
|
|
48 |
#define ushort p9ushort
|
|
|
49 |
#define uchar p9uchar
|
|
|
50 |
#define uint p9uint
|
|
|
51 |
#define vlong p9vlong
|
|
|
52 |
#define uvlong p9uvlong
|
|
|
53 |
#define u32int p9u32int
|
|
|
54 |
|
|
|
55 |
typedef unsigned char uchar;
|
|
|
56 |
typedef unsigned short ushort;
|
|
|
57 |
typedef unsigned long ulong;
|
|
|
58 |
typedef unsigned int uint;
|
|
|
59 |
typedef int64_t vlong;
|
|
|
60 |
typedef uint64_t uvlong;
|
|
|
61 |
typedef uint32_t u32int;
|
|
|
62 |
typedef uint64_t u64int;
|
|
|
63 |
typedef ushort Rune;
|
|
|
64 |
|
|
|
65 |
#define nil ((void*)0)
|
|
|
66 |
#define nelem(x) (sizeof(x)/sizeof((x)[0]))
|
|
|
67 |
#ifndef offsetof
|
|
|
68 |
#define offsetof(s, m) (ulong)(&(((s*)0)->m))
|
|
|
69 |
#endif
|
|
|
70 |
#define assert(x) if(x);else _assert("x")
|
|
|
71 |
|
|
|
72 |
extern char *argv0;
|
|
|
73 |
#define ARGBEGIN for((void)(argv0||(argv0=*argv)),argv++,argc--;\
|
|
|
74 |
argv[0] && argv[0][0]=='-' && argv[0][1];\
|
|
|
75 |
argc--, argv++) {\
|
|
|
76 |
char *_args, *_argt;\
|
|
|
77 |
Rune _argc;\
|
|
|
78 |
_args = &argv[0][1];\
|
|
|
79 |
if(_args[0]=='-' && _args[1]==0){\
|
|
|
80 |
argc--; argv++; break;\
|
|
|
81 |
}\
|
|
|
82 |
_argc = 0;\
|
|
|
83 |
while(*_args && (_args += chartorune(&_argc, _args)))\
|
|
|
84 |
switch(_argc)
|
|
|
85 |
#define ARGEND SET(_argt);USED(_argt);USED(_argc);USED(_args);}\
|
|
|
86 |
USED(argv);USED(argc);
|
|
|
87 |
#define ARGF() (_argt=_args, _args="",\
|
|
|
88 |
(*_argt? _argt: argv[1]? (argc--, *++argv): 0))
|
|
|
89 |
#define EARGF(x) (_argt=_args, _args="",\
|
|
|
90 |
(*_argt? _argt: argv[1]? (argc--, *++argv): ((x), abort(), (char*)0)))
|
|
|
91 |
|
|
|
92 |
#define ARGC() _argc
|
|
|
93 |
|
|
|
94 |
#define SET(x) (x) = 0
|
|
|
95 |
#define USED(x) (void)(x)
|
|
|
96 |
|
|
|
97 |
enum
|
|
|
98 |
{
|
|
|
99 |
UTFmax = 3, /* maximum bytes per rune */
|
|
|
100 |
Runesync = 0x80, /* cannot represent part of a UTF sequence (<) */
|
|
|
101 |
Runeself = 0x80, /* rune and UTF sequences are the same (<) */
|
|
|
102 |
Runeerror = 0x80 /* decoding error in UTF */
|
|
|
103 |
};
|
|
|
104 |
|
|
|
105 |
extern int runetochar(char*, Rune*);
|
|
|
106 |
extern int chartorune(Rune*, char*);
|
|
|
107 |
extern int runelen(long);
|
|
|
108 |
extern int utflen(char*);
|
|
|
109 |
extern char* strecpy(char*, char*, char*);
|
|
|
110 |
extern int tokenize(char*, char**, int);
|
|
|
111 |
extern int getfields(char*, char**, int, int, char*);
|
|
|
112 |
|
|
|
113 |
/*
|
|
|
114 |
* print routines
|
|
|
115 |
*/
|
|
|
116 |
typedef struct Fconv Fconv;
|
|
|
117 |
struct Fconv
|
|
|
118 |
{
|
|
|
119 |
char* out; /* pointer to next output */
|
|
|
120 |
char* eout; /* pointer to end */
|
|
|
121 |
int f1;
|
|
|
122 |
int f2;
|
|
|
123 |
int f3;
|
|
|
124 |
int chr;
|
|
|
125 |
};
|
|
|
126 |
extern char* doprint(char*, char*, char*, va_list *argp);
|
|
|
127 |
extern int print(char*, ...);
|
|
|
128 |
extern char* seprint(char*, char*, char*, ...);
|
|
|
129 |
extern int snprint(char*, int, char*, ...);
|
|
|
130 |
extern int sprint(char*, char*, ...);
|
|
|
131 |
extern int fprint(int, char*, ...);
|
|
|
132 |
|
|
|
133 |
extern int fmtinstall(int, int (*)(va_list*, Fconv*));
|
|
|
134 |
extern int numbconv(va_list*, Fconv*);
|
|
|
135 |
extern void strconv(char*, Fconv*);
|
|
|
136 |
extern int fltconv(va_list*, Fconv*);
|
|
|
137 |
|
|
|
138 |
#define OREAD 0 /* open for read */
|
|
|
139 |
#define OWRITE 1 /* write */
|
|
|
140 |
#define ORDWR 2 /* read and write */
|
|
|
141 |
#define OEXEC 3 /* execute, == read but check execute permission */
|
|
|
142 |
#define OTRUNC 16 /* or'ed in (except for exec), truncate file first */
|
|
|
143 |
#define OCEXEC 32 /* or'ed in, close on exec */
|
|
|
144 |
#define ORCLOSE 64 /* or'ed in, remove on close */
|
|
|
145 |
#define OEXCL 0x1000 /* or'ed in, exclusive use */
|
|
|
146 |
|
|
|
147 |
/* bits in Qid.type */
|
|
|
148 |
#define QTDIR 0x80 /* type bit for directories */
|
|
|
149 |
#define QTAPPEND 0x40 /* type bit for append only files */
|
|
|
150 |
#define QTEXCL 0x20 /* type bit for exclusive use files */
|
|
|
151 |
#define QTMOUNT 0x10 /* type bit for mounted channel */
|
|
|
152 |
#define QTAUTH 0x08
|
|
|
153 |
#define QTFILE 0x00 /* plain file */
|
|
|
154 |
|
|
|
155 |
/* bits in Dir.mode */
|
|
|
156 |
#define DMDIR 0x80000000 /* mode bit for directories */
|
|
|
157 |
#define DMAPPEND 0x40000000 /* mode bit for append only files */
|
|
|
158 |
#define DMEXCL 0x20000000 /* mode bit for exclusive use files */
|
|
|
159 |
#define DMMOUNT 0x10000000 /* mode bit for mounted channel */
|
|
|
160 |
#define DMREAD 0x4 /* mode bit for read permission */
|
|
|
161 |
#define DMWRITE 0x2 /* mode bit for write permission */
|
|
|
162 |
#define DMEXEC 0x1 /* mode bit for execute permission */
|
|
|
163 |
|
|
|
164 |
typedef
|
|
|
165 |
struct Qid
|
|
|
166 |
{
|
|
|
167 |
vlong path;
|
|
|
168 |
ulong vers;
|
|
|
169 |
uchar type;
|
|
|
170 |
} Qid;
|
|
|
171 |
|
|
|
172 |
typedef
|
|
|
173 |
struct Dir {
|
|
|
174 |
/* system-modified data */
|
|
|
175 |
ushort type; /* server type */
|
|
|
176 |
uint dev; /* server subtype */
|
|
|
177 |
/* file data */
|
|
|
178 |
Qid qid; /* unique id from server */
|
|
|
179 |
ulong mode; /* permissions */
|
|
|
180 |
ulong atime; /* last read time */
|
|
|
181 |
ulong mtime; /* last write time */
|
|
|
182 |
vlong length; /* file length: see <u.h> */
|
|
|
183 |
char *name; /* last element of path */
|
|
|
184 |
char *uid; /* owner name */
|
|
|
185 |
char *gid; /* group name */
|
|
|
186 |
char *muid; /* last modifier name */
|
|
|
187 |
} Dir;
|
|
|
188 |
|
|
|
189 |
long readn(int, void*, long);
|
|
|
190 |
void remotehost(char*, int);
|
|
|
191 |
|
|
|
192 |
enum {
|
|
|
193 |
NAMELEN = 28,
|
|
|
194 |
ERRLEN = 64
|
|
|
195 |
};
|
|
|
196 |
|
|
|
197 |
/* DES */
|
|
|
198 |
#define DESKEYLEN 7
|
|
|
199 |
void key_setup(char key[DESKEYLEN], char expandedkey[128]);
|
|
|
200 |
void block_cipher(char expandedkey[128], char buf[8], int decrypting);
|