1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
|
diff --git a/FILES b/FILES
index 40d266d..cdc5db5 100644
--- a/FILES
+++ b/FILES
@@ -50,7 +50,6 @@ pathexec_run.c
print-cc.sh
prot.c
prot.h
-readwrite.h
str.h
str_chr.c
str_len.c
diff --git a/Makefile b/Makefile
index 9a68187..be114d7 100644
--- a/Makefile
+++ b/Makefile
@@ -17,7 +17,7 @@ load auto-str.o unix.a byte.a
./load auto-str unix.a byte.a
auto-str.o: \
-compile auto-str.c buffer.h readwrite.h exit.h
+compile auto-str.c buffer.h exit.h
./compile auto-str.c
auto_home.c: \
@@ -33,7 +33,7 @@ compile buffer.c buffer.h
./compile buffer.c
buffer_2.o: \
-compile buffer_2.c readwrite.h buffer.h
+compile buffer_2.c buffer.h
./compile buffer_2.c
buffer_copy.o: \
@@ -148,7 +148,7 @@ load install.o hier.o auto_home.o unix.a byte.a
./load install hier.o auto_home.o unix.a byte.a
install.o: \
-compile install.c buffer.h strerr.h error.h open.h readwrite.h exit.h
+compile install.c buffer.h strerr.h error.h open.h exit.h
./compile install.c
instcheck: \
@@ -156,7 +156,7 @@ load instcheck.o hier.o auto_home.o unix.a byte.a
./load instcheck hier.o auto_home.o unix.a byte.a
instcheck.o: \
-compile instcheck.c strerr.h error.h readwrite.h exit.h
+compile instcheck.c strerr.h error.h exit.h
./compile instcheck.c
it: \
diff --git a/alloc.c b/alloc.c
index b94e23a..18ffc5c 100644
--- a/alloc.c
+++ b/alloc.c
@@ -1,4 +1,5 @@
#include <stdlib.h>
+
#include "alloc.h"
#include "error.h"
@@ -10,8 +11,7 @@ static aligned realspace[SPACE / ALIGNMENT];
#define space ((char *) realspace)
static unsigned int avail = SPACE; /* multiple of ALIGNMENT; 0<=avail<=SPACE */
-/*@null@*//*@out@*/char *alloc(n)
-unsigned int n;
+/*@null@*//*@out@*/void *alloc(unsigned int n)
{
char *x;
n = ALIGNMENT + n - (n & (ALIGNMENT - 1)); /* XXX: could overflow */
@@ -21,11 +21,10 @@ unsigned int n;
return x;
}
-void alloc_free(x)
-char *x;
+void alloc_free(void *x)
{
- if (x >= space)
- if (x < space + SPACE)
+ if ((char *)x >= space)
+ if ((char *)x < space + SPACE)
return; /* XXX: assuming that pointers are flat */
free(x);
}
diff --git a/alloc.h b/alloc.h
index 1b1d893..dc43a5c 100644
--- a/alloc.h
+++ b/alloc.h
@@ -1,8 +1,8 @@
#ifndef ALLOC_H
#define ALLOC_H
-extern /*@null@*//*@out@*/char *alloc();
-extern void alloc_free();
-extern int alloc_re();
+extern /* @null@*//* @out@*/void *alloc(unsigned int);
+extern void alloc_free(void *);
+extern int alloc_re(char **, unsigned int, unsigned int);
#endif
diff --git a/alloc_re.c b/alloc_re.c
index feb8b49..b2ff3cf 100644
--- a/alloc_re.c
+++ b/alloc_re.c
@@ -1,10 +1,7 @@
#include "alloc.h"
#include "byte.h"
-int alloc_re(x,m,n)
-char **x;
-unsigned int m;
-unsigned int n;
+int alloc_re(char **x, unsigned int m, unsigned int n)
{
char *y;
diff --git a/auto-str.c b/auto-str.c
index 1340591..16dc137 100644
--- a/auto-str.c
+++ b/auto-str.c
@@ -1,16 +1,17 @@
+#include <unistd.h>
+
#include "buffer.h"
-#include "readwrite.h"
#include "exit.h"
char bspace[256];
buffer b = BUFFER_INIT(write,1,bspace,sizeof bspace);
-void puts(char *s)
+void puts_str(char *s)
{
if (buffer_puts(&b,s) == -1) _exit(111);
}
-main(int argc,char **argv)
+int main(int argc,char **argv)
{
char *name;
char *value;
@@ -22,20 +23,20 @@ main(int argc,char **argv)
value = argv[2];
if (!value) _exit(100);
- puts("const char ");
- puts(name);
- puts("[] = \"\\\n");
+ puts_str("const char ");
+ puts_str(name);
+ puts_str("[] = \"\\\n");
while (ch = *value++) {
- puts("\\");
+ puts_str("\\");
octal[3] = 0;
octal[2] = '0' + (ch & 7); ch >>= 3;
octal[1] = '0' + (ch & 7); ch >>= 3;
octal[0] = '0' + (ch & 7);
- puts(octal);
+ puts_str(octal);
}
- puts("\\\n\";\n");
+ puts_str("\\\n\";\n");
if (buffer_flush(&b) == -1) _exit(111);
_exit(0);
}
diff --git a/buffer.c b/buffer.c
index f44a697..159f5c8 100644
--- a/buffer.c
+++ b/buffer.c
@@ -1,6 +1,6 @@
#include "buffer.h"
-void buffer_init(buffer *s,int (*op)(),int fd,char *buf,unsigned int len)
+void buffer_init(buffer *s,buffer_op op,int fd,char *buf,unsigned int len)
{
s->x = buf;
s->fd = fd;
diff --git a/buffer.h b/buffer.h
index 12539b3..e4e0a5c 100644
--- a/buffer.h
+++ b/buffer.h
@@ -1,19 +1,22 @@
#ifndef BUFFER_H
#define BUFFER_H
+#include <sys/types.h>
+
+typedef ssize_t (*buffer_op)(int, const void *, size_t);
typedef struct buffer {
char *x;
unsigned int p;
unsigned int n;
int fd;
- int (*op)();
+ buffer_op op;
} buffer;
#define BUFFER_INIT(op,fd,buf,len) { (buf), 0, (len), (fd), (op) }
#define BUFFER_INSIZE 8192
#define BUFFER_OUTSIZE 8192
-extern void buffer_init(buffer *,int (*)(),int,char *,unsigned int);
+extern void buffer_init(buffer *,buffer_op,int,char *,unsigned int);
extern int buffer_flush(buffer *);
extern int buffer_put(buffer *,char *,unsigned int);
diff --git a/buffer_2.c b/buffer_2.c
index 297825c..bdeb5b9 100644
--- a/buffer_2.c
+++ b/buffer_2.c
@@ -1,4 +1,5 @@
-#include "readwrite.h"
+#include <unistd.h>
+
#include "buffer.h"
char buffer_2_space[256];
diff --git a/buffer_get.c b/buffer_get.c
index 937b75e..2794afa 100644
--- a/buffer_get.c
+++ b/buffer_get.c
@@ -2,7 +2,7 @@
#include "byte.h"
#include "error.h"
-static int oneread(int (*op)(),int fd,char *buf,unsigned int len)
+static int oneread(buffer_op op,int fd,char *buf,unsigned int len)
{
int r;
diff --git a/buffer_put.c b/buffer_put.c
index a05e1f5..283a5c3 100644
--- a/buffer_put.c
+++ b/buffer_put.c
@@ -3,7 +3,7 @@
#include "byte.h"
#include "error.h"
-static int allwrite(int (*op)(),int fd,char *buf,unsigned int len)
+static int allwrite(buffer_op op,int fd,char *buf,unsigned int len)
{
int w;
diff --git a/byte.h b/byte.h
index de06c69..3a4bf50 100644
--- a/byte.h
+++ b/byte.h
@@ -3,9 +3,9 @@
extern unsigned int byte_chr();
extern unsigned int byte_rchr();
-extern void byte_copy();
-extern void byte_copyr();
-extern int byte_diff();
+extern void byte_copy(register char *, register unsigned int, register char *);
+extern void byte_copyr(register char *, register unsigned int, register char *);
+extern int byte_diff(register char *, register unsigned int, register char *);
extern void byte_zero();
#define byte_equal(s,n,t) (!byte_diff((s),(n),(t)))
diff --git a/byte_copy.c b/byte_copy.c
index eaad11b..9331064 100644
--- a/byte_copy.c
+++ b/byte_copy.c
@@ -1,9 +1,6 @@
#include "byte.h"
-void byte_copy(to,n,from)
-register char *to;
-register unsigned int n;
-register char *from;
+void byte_copy(register char *to, register unsigned int n, register char *from)
{
for (;;) {
if (!n) return; *to++ = *from++; --n;
diff --git a/byte_cr.c b/byte_cr.c
index 3e7a1d5..8e5e482 100644
--- a/byte_cr.c
+++ b/byte_cr.c
@@ -1,9 +1,6 @@
#include "byte.h"
-void byte_copyr(to,n,from)
-register char *to;
-register unsigned int n;
-register char *from;
+void byte_copyr(register char *to, register unsigned int n, register char *from)
{
to += n;
from += n;
diff --git a/byte_diff.c b/byte_diff.c
index cdbd760..408ba4c 100644
--- a/byte_diff.c
+++ b/byte_diff.c
@@ -1,9 +1,6 @@
#include "byte.h"
-int byte_diff(s,n,t)
-register char *s;
-register unsigned int n;
-register char *t;
+int byte_diff(register char *s, register unsigned int n, register char *t)
{
for (;;) {
if (!n) return 0; if (*s != *t) break; ++s; ++t; --n;
diff --git a/checkpassword.c b/checkpassword.c
index dd7233a..767820e 100644
--- a/checkpassword.c
+++ b/checkpassword.c
@@ -5,7 +5,6 @@
#include "pathexec.h"
#include "prot.h"
-extern char *crypt();
#include <pwd.h>
static struct passwd *pw;
@@ -24,8 +23,7 @@ static struct userpw *upw;
static char up[513];
static int uplen;
-int
-main(int argc,char **argv)
+int main(int argc,char **argv)
{
char *login;
char *password;
diff --git a/chkshsgr.c b/chkshsgr.c
index 57f9183..605d17f 100644
--- a/chkshsgr.c
+++ b/chkshsgr.c
@@ -2,10 +2,9 @@
#include <unistd.h>
#include "exit.h"
-int
-main()
+int main()
{
- short x[4];
+ gid_t x[4];
x[0] = x[1] = 0;
if (getgroups(1,x) == 0) if (setgroups(1,x) == -1) _exit(1);
diff --git a/error.c b/error.c
index 14adef0..b85d130 100644
--- a/error.c
+++ b/error.c
@@ -1,4 +1,3 @@
-#include <errno.h>
#include "error.h"
/* warning: as coverage improves here, should update error_{str,temp} */
diff --git a/exit.h b/exit.h
index 39011c8..614f9d1 100644
--- a/exit.h
+++ b/exit.h
@@ -1,6 +1,6 @@
#ifndef EXIT_H
#define EXIT_H
-extern void _exit();
+extern void _exit(int);
#endif
diff --git a/hier.c b/hier.c
index f11d108..97d9b1b 100644
--- a/hier.c
+++ b/hier.c
@@ -1,5 +1,7 @@
#include "auto_home.h"
+void c(const char *home,char *subdir,char *file,int uid,int gid,int mode);
+
void hier()
{
c(auto_home,"bin","checkpassword",-1,-1,0700);
diff --git a/install.c b/install.c
index f98417f..0525db8 100644
--- a/install.c
+++ b/install.c
@@ -1,11 +1,10 @@
#include <sys/stat.h>
-#include <sys/types.h>
#include <unistd.h>
+
#include "buffer.h"
#include "strerr.h"
#include "error.h"
#include "open.h"
-#include "readwrite.h"
#include "exit.h"
extern void hier();
@@ -14,11 +13,7 @@ extern void hier();
int fdsourcedir = -1;
-void h(home,uid,gid,mode)
-char *home;
-int uid;
-int gid;
-int mode;
+void h(char *home, int uid, int gid, int mode)
{
if (mkdir(home,0700) == -1)
if (errno != error_exist)
@@ -29,12 +24,7 @@ int mode;
strerr_die4sys(111,FATAL,"unable to chmod ",home,": ");
}
-void d(home,subdir,uid,gid,mode)
-char *home;
-char *subdir;
-int uid;
-int gid;
-int mode;
+void d(char *home, char *subdir, int uid, int gid, int mode)
{
if (chdir(home) == -1)
strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
@@ -52,13 +42,7 @@ char outbuf[BUFFER_OUTSIZE];
buffer ssin;
buffer ssout;
-void c(home,subdir,file,uid,gid,mode)
-char *home;
-char *subdir;
-char *file;
-int uid;
-int gid;
-int mode;
+void c(char *home, char *subdir, char *file, int uid, int gid, int mode)
{
int fdin;
int fdout;
@@ -69,7 +53,7 @@ int mode;
fdin = open_read(file);
if (fdin == -1)
strerr_die4sys(111,FATAL,"unable to read ",file,": ");
- buffer_init(&ssin,read,fdin,inbuf,sizeof inbuf);
+ buffer_init(&ssin,(buffer_op)read,fdin,inbuf,sizeof inbuf);
if (chdir(home) == -1)
strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
@@ -102,14 +86,7 @@ int mode;
strerr_die6sys(111,FATAL,"unable to chmod .../",subdir,"/",file,": ");
}
-void z(home,subdir,file,len,uid,gid,mode)
-char *home;
-char *subdir;
-char *file;
-int len;
-int uid;
-int gid;
-int mode;
+void z(char *home, char *subdir, char *file, int len, int uid, int gid, int mode)
{
int fdout;
@@ -140,8 +117,7 @@ int mode;
strerr_die6sys(111,FATAL,"unable to chmod .../",subdir,"/",file,": ");
}
-int
-main()
+int main()
{
fdsourcedir = open_read(".");
if (fdsourcedir == -1)
diff --git a/instcheck.c b/instcheck.c
index 0c0dd43..5ebaa5e 100644
--- a/instcheck.c
+++ b/instcheck.c
@@ -1,8 +1,7 @@
-#include <sys/types.h>
#include <sys/stat.h>
+#include <unistd.h>
#include "strerr.h"
#include "error.h"
-#include "readwrite.h"
#include "exit.h"
extern void hier();
@@ -10,15 +9,7 @@ extern void hier();
#define FATAL "instcheck: fatal: "
#define WARNING "instcheck: warning: "
-void perm(prefix1,prefix2,prefix3,file,type,uid,gid,mode)
-char *prefix1;
-char *prefix2;
-char *prefix3;
-char *file;
-int type;
-int uid;
-int gid;
-int mode;
+void perm(char *prefix1, char *prefix2, char *prefix3, char *file, int type, int uid, int gid, int mode)
{
struct stat st;
@@ -40,46 +31,26 @@ int mode;
strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong type",0);
}
-void h(home,uid,gid,mode)
-char *home;
-int uid;
-int gid;
-int mode;
+void h(char *home, int uid, int gid, int mode)
{
perm("","","",home,S_IFDIR,uid,gid,mode);
}
-void d(home,subdir,uid,gid,mode)
-char *home;
-char *subdir;
-int uid;
-int gid;
-int mode;
+void d(char *home, char *subdir, int uid, int gid, int mode)
{
if (chdir(home) == -1)
strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
perm("",home,"/",subdir,S_IFDIR,uid,gid,mode);
}
-void p(home,fifo,uid,gid,mode)
-char *home;
-char *fifo;
-int uid;
-int gid;
-int mode;
+void p(char *home, char *fifo, int uid, int gid, int mode)
{
if (chdir(home) == -1)
strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
perm("",home,"/",fifo,S_IFIFO,uid,gid,mode);
}
-void c(home,subdir,file,uid,gid,mode)
-char *home;
-char *subdir;
-char *file;
-int uid;
-int gid;
-int mode;
+void c(char *home, char *subdir, char *file, int uid, int gid, int mode)
{
if (chdir(home) == -1)
strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
@@ -88,21 +59,14 @@ int mode;
perm(".../",subdir,"/",file,S_IFREG,uid,gid,mode);
}
-void z(home,file,len,uid,gid,mode)
-char *home;
-char *file;
-int len;
-int uid;
-int gid;
-int mode;
+void z(char *home, char *file, int len, int uid, int gid, int mode)
{
if (chdir(home) == -1)
strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
perm("",home,"/",file,S_IFREG,uid,gid,mode);
}
-int
-main()
+int main()
{
hier();
_exit(0);
diff --git a/pathexec_run.c b/pathexec_run.c
index 256d8e5..a1f746d 100644
--- a/pathexec_run.c
+++ b/pathexec_run.c
@@ -1,4 +1,5 @@
#include <unistd.h>
+
#include "error.h"
#include "stralloc.h"
#include "str.h"
diff --git a/prot.c b/prot.c
index 1c56e9c..ff9724f 100644
--- a/prot.c
+++ b/prot.c
@@ -1,5 +1,6 @@
#include <grp.h>
#include <unistd.h>
+
#include "hasshsgr.h"
#include "prot.h"
diff --git a/readwrite.h b/readwrite.h
deleted file mode 100644
index 9423ad6..0000000
--- a/readwrite.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef READWRITE_H
-#define READWRITE_H
-
-#include <unistd.h>
-
-#endif
diff --git a/trycpp.c b/trycpp.c
index 3ab455b..690f2f3 100644
--- a/trycpp.c
+++ b/trycpp.c
@@ -1,4 +1,4 @@
-main()
+int main()
{
#ifdef NeXT
printf("nextstep\n"); exit(0);
diff --git a/trycrypt.c b/trycrypt.c
index fbce408..c32bd40 100644
--- a/trycrypt.c
+++ b/trycrypt.c
@@ -1,4 +1,4 @@
-main()
+int main()
{
;
}
diff --git a/tryshadow.c b/tryshadow.c
index fbce408..c32bd40 100644
--- a/tryshadow.c
+++ b/tryshadow.c
@@ -1,4 +1,4 @@
-main()
+int main()
{
;
}
diff --git a/tryshsgr.c b/tryshsgr.c
index f55ff60..81b395c 100644
--- a/tryshsgr.c
+++ b/tryshsgr.c
@@ -1,4 +1,4 @@
-main()
+int main()
{
short x[4];
diff --git a/tryslib.c b/tryslib.c
index fbce408..c32bd40 100644
--- a/tryslib.c
+++ b/tryslib.c
@@ -1,4 +1,4 @@
-main()
+int main()
{
;
}
diff --git a/tryspnam.c b/tryspnam.c
index 622ba8b..8b7c402 100644
--- a/tryspnam.c
+++ b/tryspnam.c
@@ -1,6 +1,7 @@
+#include <stdio.h>
#include <shadow.h>
-void main()
+int main()
{
struct spwd *spw;
diff --git a/x86cpuid.c b/x86cpuid.c
index 900d7d5..98e37db 100644
--- a/x86cpuid.c
+++ b/x86cpuid.c
@@ -5,7 +5,7 @@ void nope()
exit(1);
}
-main()
+int main()
{
unsigned long x[4];
unsigned long y[4];
|