lpc.c (68400) | lpc.c (78146) |
---|---|
1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 29 unchanged lines hidden (view full) --- 38 The Regents of the University of California. All rights reserved.\n"; 39#endif /* not lint */ 40 41#ifndef lint 42#if 0 43static char sccsid[] = "@(#)lpc.c 8.3 (Berkeley) 4/28/95"; 44#endif 45static const char rcsid[] = | 1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 29 unchanged lines hidden (view full) --- 38 The Regents of the University of California. All rights reserved.\n"; 39#endif /* not lint */ 40 41#ifndef lint 42#if 0 43static char sccsid[] = "@(#)lpc.c 8.3 (Berkeley) 4/28/95"; 44#endif 45static const char rcsid[] = |
46 "$FreeBSD: head/usr.sbin/lpr/lpc/lpc.c 68400 2000-11-06 19:19:49Z gad $"; | 46 "$FreeBSD: head/usr.sbin/lpr/lpc/lpc.c 78146 2001-06-12 16:38:20Z gad $"; |
47#endif /* not lint */ 48 49#include <sys/param.h> 50 51#include <ctype.h> 52#include <dirent.h> 53#include <err.h> 54#include <grp.h> --- 22 unchanged lines hidden (view full) --- 77#define MAX_MARGV 20 78static int fromatty; 79 80static char cmdline[MAX_CMDLINE]; 81static int margc; 82static char *margv[MAX_MARGV]; 83uid_t uid, euid; 84 | 47#endif /* not lint */ 48 49#include <sys/param.h> 50 51#include <ctype.h> 52#include <dirent.h> 53#include <err.h> 54#include <grp.h> --- 22 unchanged lines hidden (view full) --- 77#define MAX_MARGV 20 78static int fromatty; 79 80static char cmdline[MAX_CMDLINE]; 81static int margc; 82static char *margv[MAX_MARGV]; 83uid_t uid, euid; 84 |
85int main __P((int, char *[])); 86static void cmdscanner __P((void)); 87static struct cmd *getcmd __P((char *)); 88static void intr __P((int)); 89static void makeargv __P((void)); 90static int ingroup __P((char *)); | 85int main(int _argc, char *_argv[]); 86static void cmdscanner(void); 87static struct cmd *getcmd(const char *_name); 88static void intr(int _signo); 89static void makeargv(void); 90static int ingroup(const char *_grname); |
91 92int | 91 92int |
93main(argc, argv) 94 int argc; 95 char *argv[]; | 93main(int argc, char *argv[]) |
96{ 97 register struct cmd *c; 98 99 euid = geteuid(); 100 uid = getuid(); 101 seteuid(uid); 102 name = argv[0]; 103 openlog("lpd", 0, LOG_LPR); --- 22 unchanged lines hidden (view full) --- 126 if (!fromatty) 127 signal(SIGINT, intr); 128 for (;;) { 129 cmdscanner(); 130 } 131} 132 133static void | 94{ 95 register struct cmd *c; 96 97 euid = geteuid(); 98 uid = getuid(); 99 seteuid(uid); 100 name = argv[0]; 101 openlog("lpd", 0, LOG_LPR); --- 22 unchanged lines hidden (view full) --- 124 if (!fromatty) 125 signal(SIGINT, intr); 126 for (;;) { 127 cmdscanner(); 128 } 129} 130 131static void |
134intr(signo) 135 int signo; | 132intr(int signo __unused) |
136{ | 133{ |
134 /* (the '__unused' is just to avoid a compile-time warning) */ |
|
137 exit(0); 138} 139 | 135 exit(0); 136} 137 |
140static char * | 138static const char * |
141lpc_prompt(void) 142{ 143 return ("lpc> "); 144} 145 146/* 147 * Command parser. 148 */ 149static void | 139lpc_prompt(void) 140{ 141 return ("lpc> "); 142} 143 144/* 145 * Command parser. 146 */ 147static void |
150cmdscanner() | 148cmdscanner(void) |
151{ 152 register struct cmd *c; 153 static EditLine *el = NULL; 154 static History *hist = NULL; 155 int num = 0; 156 int len; 157 const char *bp = NULL; 158 --- 46 unchanged lines hidden (view full) --- 205 if (c->c_generic != 0) 206 generic(c->c_generic, margc, margv); 207 else 208 (*c->c_handler)(margc, margv); 209 } 210} 211 212static struct cmd * | 149{ 150 register struct cmd *c; 151 static EditLine *el = NULL; 152 static History *hist = NULL; 153 int num = 0; 154 int len; 155 const char *bp = NULL; 156 --- 46 unchanged lines hidden (view full) --- 203 if (c->c_generic != 0) 204 generic(c->c_generic, margc, margv); 205 else 206 (*c->c_handler)(margc, margv); 207 } 208} 209 210static struct cmd * |
213getcmd(name) 214 register char *name; | 211getcmd(const char *name) |
215{ | 212{ |
216 register char *p, *q; | 213 register const char *p, *q; |
217 register struct cmd *c, *found; 218 register int nmatches, longest; 219 220 longest = 0; 221 nmatches = 0; 222 found = 0; 223 for (c = cmdtab; (p = c->c_name); c++) { 224 for (q = name; *q == *p++; q++) --- 12 unchanged lines hidden (view full) --- 237 return((struct cmd *)-1); 238 return(found); 239} 240 241/* 242 * Slice a string up into argc/argv. 243 */ 244static void | 214 register struct cmd *c, *found; 215 register int nmatches, longest; 216 217 longest = 0; 218 nmatches = 0; 219 found = 0; 220 for (c = cmdtab; (p = c->c_name); c++) { 221 for (q = name; *q == *p++; q++) --- 12 unchanged lines hidden (view full) --- 234 return((struct cmd *)-1); 235 return(found); 236} 237 238/* 239 * Slice a string up into argc/argv. 240 */ 241static void |
245makeargv() | 242makeargv(void) |
246{ 247 register char *cp; 248 register char **argp = margv; 249 register int n = 0; 250 251 margc = 0; 252 for (cp = cmdline; *cp && (cp - cmdline) < sizeof(cmdline) && 253 n < MAX_MARGV; n++) { --- 13 unchanged lines hidden (view full) --- 267} 268 269#define HELPINDENT (sizeof ("directory")) 270 271/* 272 * Help command. 273 */ 274void | 243{ 244 register char *cp; 245 register char **argp = margv; 246 register int n = 0; 247 248 margc = 0; 249 for (cp = cmdline; *cp && (cp - cmdline) < sizeof(cmdline) && 250 n < MAX_MARGV; n++) { --- 13 unchanged lines hidden (view full) --- 264} 265 266#define HELPINDENT (sizeof ("directory")) 267 268/* 269 * Help command. 270 */ 271void |
275help(argc, argv) 276 int argc; 277 char *argv[]; | 272help(int argc, char *argv[]) |
278{ 279 register struct cmd *c; 280 281 if (argc == 1) { 282 register int i, j, w; 283 int columns, width = 0, lines; 284 285 printf("Commands may be abbreviated. Commands are:\n\n"); --- 39 unchanged lines hidden (view full) --- 325 c->c_name, c->c_help); 326 } 327} 328 329/* 330 * return non-zero if the user is a member of the given group 331 */ 332static int | 273{ 274 register struct cmd *c; 275 276 if (argc == 1) { 277 register int i, j, w; 278 int columns, width = 0, lines; 279 280 printf("Commands may be abbreviated. Commands are:\n\n"); --- 39 unchanged lines hidden (view full) --- 320 c->c_name, c->c_help); 321 } 322} 323 324/* 325 * return non-zero if the user is a member of the given group 326 */ 327static int |
333ingroup(grname) 334 char *grname; | 328ingroup(const char *grname) |
335{ 336 static struct group *gptr=NULL; 337 static int ngroups = 0; 338 static gid_t groups[NGROUPS]; 339 register gid_t gid; 340 register int i; 341 342 if (gptr == NULL) { --- 14 unchanged lines hidden --- | 329{ 330 static struct group *gptr=NULL; 331 static int ngroups = 0; 332 static gid_t groups[NGROUPS]; 333 register gid_t gid; 334 register int i; 335 336 if (gptr == NULL) { --- 14 unchanged lines hidden --- |