Deleted Added
full compact
uudecode.c (90720) uudecode.c (91661)
1/*-
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 28 unchanged lines hidden (view full) ---

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41#if 0
42static char sccsid[] = "@(#)uudecode.c 8.2 (Berkeley) 4/2/94";
43#endif
44static const char rcsid[] =
1/*-
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 28 unchanged lines hidden (view full) ---

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41#if 0
42static char sccsid[] = "@(#)uudecode.c 8.2 (Berkeley) 4/2/94";
43#endif
44static const char rcsid[] =
45 "$FreeBSD: head/usr.bin/uudecode/uudecode.c 90720 2002-02-16 09:18:33Z mike $";
45 "$FreeBSD: head/usr.bin/uudecode/uudecode.c 91661 2002-03-05 03:27:47Z jmallett $";
46#endif /* not lint */
47
48/*
49 * uudecode [file ...]
50 *
51 * create the specified file, decoding as you go.
52 * used with uuencode.
53 */
54#include <sys/param.h>
46#endif /* not lint */
47
48/*
49 * uudecode [file ...]
50 *
51 * create the specified file, decoding as you go.
52 * used with uuencode.
53 */
54#include <sys/param.h>
55#include <sys/socket.h>
55#include <sys/stat.h>
56
56#include <sys/stat.h>
57
58#include <netinet/in.h>
59
57#include <err.h>
60#include <err.h>
58#include <fnmatch.h>
59#include <pwd.h>
61#include <pwd.h>
62#include <resolv.h>
60#include <stdio.h>
61#include <stdlib.h>
62#include <string.h>
63#include <unistd.h>
64
65const char *filename;
66char *outfile;
67int cflag, iflag, oflag, pflag, sflag;
68
69static void usage __P((void));
70int decode __P((void));
71int decode2 __P((int));
63#include <stdio.h>
64#include <stdlib.h>
65#include <string.h>
66#include <unistd.h>
67
68const char *filename;
69char *outfile;
70int cflag, iflag, oflag, pflag, sflag;
71
72static void usage __P((void));
73int decode __P((void));
74int decode2 __P((int));
75void base64_decode __P((const char *));
72
73int
74main(argc, argv)
75 int argc;
76 char *argv[];
77{
78 int rval, ch;
79

--- 70 unchanged lines hidden (view full) ---

150
151int
152decode2(flag)
153 int flag;
154{
155 struct passwd *pw;
156 register int n;
157 register char ch, *p;
76
77int
78main(argc, argv)
79 int argc;
80 char *argv[];
81{
82 int rval, ch;
83

--- 70 unchanged lines hidden (view full) ---

154
155int
156decode2(flag)
157 int flag;
158{
159 struct passwd *pw;
160 register int n;
161 register char ch, *p;
158 int ignore, mode, n1;
162 int base64, ignore, mode, n1;
159 char buf[MAXPATHLEN];
160 char buffn[MAXPATHLEN]; /* file name buffer */
161
163 char buf[MAXPATHLEN];
164 char buffn[MAXPATHLEN]; /* file name buffer */
165
162 ignore = 0;
166 base64 = ignore = 0;
163 /* search for header line */
164 do {
165 if (!fgets(buf, sizeof(buf), stdin)) {
166 if (flag) /* no error */
167 return(0);
168
169 warnx("%s: no \"begin\" line", filename);
170 return(1);
171 }
167 /* search for header line */
168 do {
169 if (!fgets(buf, sizeof(buf), stdin)) {
170 if (flag) /* no error */
171 return(0);
172
173 warnx("%s: no \"begin\" line", filename);
174 return(1);
175 }
172 } while (strncmp(buf, "begin ", 6) ||
173 fnmatch("begin [0-7]* *", buf, 0));
176 } while (strncmp(buf, "begin", 5) != 0);
174
177
178 if (strncmp(buf, "begin-base64", 12) == 0)
179 base64 = 1;
180
175 if (oflag) {
181 if (oflag) {
176 (void)sscanf(buf, "begin %o ", &mode);
182 if (base64)
183 (void)sscanf(buf, "begin-base64 %o ", &mode);
184 else
185 (void)sscanf(buf, "begin %o ", &mode);
177 if (strlcpy(buf, outfile, sizeof(buf)) >= sizeof(buf)) {
178 warnx("%s: filename too long", outfile);
179 return (1);
180 }
186 if (strlcpy(buf, outfile, sizeof(buf)) >= sizeof(buf)) {
187 warnx("%s: filename too long", outfile);
188 return (1);
189 }
181 } else
182 (void)sscanf(buf, "begin %o %[^\n\r]", &mode, buf);
190 } else {
191 if (base64)
192 (void)sscanf(buf, "begin-base64 %o %[^\n\r]", &mode, buf);
193 else
194 (void)sscanf(buf, "begin %o %[^\n\r]", &mode, buf);
195 }
183
184 if (!sflag && !pflag) {
185 strncpy(buffn, buf, sizeof(buffn));
186 if (strrchr(buffn, '/') != NULL)
187 strncpy(buf, strrchr(buffn, '/') + 1, sizeof(buf));
188 if (buf[0] == '\0') {
189 warnx("%s: illegal filename", buffn);
190 return(1);

--- 34 unchanged lines hidden (view full) ---

225 fchmod(fileno(stdout), mode&0666)) {
226 warn("%s: %s", buf, filename);
227 return(1);
228 }
229 }
230 strcpy(buffn, buf); /* store file name from header line */
231
232 /* for each input line */
196
197 if (!sflag && !pflag) {
198 strncpy(buffn, buf, sizeof(buffn));
199 if (strrchr(buffn, '/') != NULL)
200 strncpy(buf, strrchr(buffn, '/') + 1, sizeof(buf));
201 if (buf[0] == '\0') {
202 warnx("%s: illegal filename", buffn);
203 return(1);

--- 34 unchanged lines hidden (view full) ---

238 fchmod(fileno(stdout), mode&0666)) {
239 warn("%s: %s", buf, filename);
240 return(1);
241 }
242 }
243 strcpy(buffn, buf); /* store file name from header line */
244
245 /* for each input line */
246next:
233 for (;;) {
234 if (!fgets(p = buf, sizeof(buf), stdin)) {
235 warnx("%s: short file", filename);
236 return(1);
237 }
247 for (;;) {
248 if (!fgets(p = buf, sizeof(buf), stdin)) {
249 warnx("%s: short file", filename);
250 return(1);
251 }
252 if (base64) {
253 if (strncmp(buf, "====", 4) == 0)
254 return (0);
255 base64_decode(buf);
256 goto next;
257 }
238#define DEC(c) (((c) - ' ') & 077) /* single character decode */
239#define IS_DEC(c) ( (((c) - ' ') >= 0) && (((c) - ' ') <= 077 + 1) )
240/* #define IS_DEC(c) (1) */
241
242#define OUT_OF_RANGE \
243{ \
244 warnx( \
245"\n\tinput file: %s\n\tencoded file: %s\n\tcharacter out of range: [%d-%d]", \

--- 53 unchanged lines hidden (view full) ---

299 (strcmp(buf, "end") && strcmp(buf, "end\n") &&
300 strcmp(buf, "end\r\n"))) {
301 warnx("%s: no \"end\" line", filename);
302 return(1);
303 }
304 return(0);
305}
306
258#define DEC(c) (((c) - ' ') & 077) /* single character decode */
259#define IS_DEC(c) ( (((c) - ' ') >= 0) && (((c) - ' ') <= 077 + 1) )
260/* #define IS_DEC(c) (1) */
261
262#define OUT_OF_RANGE \
263{ \
264 warnx( \
265"\n\tinput file: %s\n\tencoded file: %s\n\tcharacter out of range: [%d-%d]", \

--- 53 unchanged lines hidden (view full) ---

319 (strcmp(buf, "end") && strcmp(buf, "end\n") &&
320 strcmp(buf, "end\r\n"))) {
321 warnx("%s: no \"end\" line", filename);
322 return(1);
323 }
324 return(0);
325}
326
327void
328base64_decode(stream)
329 const char *stream;
330{
331 unsigned char out[MAXPATHLEN * 4];
332 int rv;
333
334 rv = b64_pton(stream, out, (sizeof(out) / sizeof(out[0])));
335 if (rv == -1)
336 errx(1, "b64_pton: error decoding base64 input stream");
337 printf("%s", out);
338}
339
307static void
308usage()
309{
310 (void)fprintf(stderr, "usage: uudecode [-cips] [file ...]\n");
311 (void)fprintf(stderr, "usage: uudecode [-i] -o output_file [file]\n");
312 exit(1);
313}
340static void
341usage()
342{
343 (void)fprintf(stderr, "usage: uudecode [-cips] [file ...]\n");
344 (void)fprintf(stderr, "usage: uudecode [-i] -o output_file [file]\n");
345 exit(1);
346}