pcnfsd_misc.c revision 1.1 1 1.1 jtc /* RE_SID: @(%)/usr/dosnfs/shades_SCCS/unix/pcnfsd/v2/src/SCCS/s.pcnfsd_misc.c 1.5 92/01/24 19:59:13 SMI */
2 1.1 jtc /*
3 1.1 jtc **=====================================================================
4 1.1 jtc ** Copyright (c) 1986,1987,1988,1989,1990,1991 by Sun Microsystems, Inc.
5 1.1 jtc ** @(#)pcnfsd_misc.c 1.5 1/24/92
6 1.1 jtc **=====================================================================
7 1.1 jtc */
8 1.1 jtc #include "common.h"
9 1.1 jtc /*
10 1.1 jtc **=====================================================================
11 1.1 jtc ** I N C L U D E F I L E S E C T I O N *
12 1.1 jtc ** *
13 1.1 jtc ** If your port requires different include files, add a suitable *
14 1.1 jtc ** #define in the customization section, and make the inclusion or *
15 1.1 jtc ** exclusion of the files conditional on this. *
16 1.1 jtc **=====================================================================
17 1.1 jtc */
18 1.1 jtc #include "pcnfsd.h"
19 1.1 jtc
20 1.1 jtc #include <stdio.h>
21 1.1 jtc #include <pwd.h>
22 1.1 jtc #include <sys/file.h>
23 1.1 jtc #include <signal.h>
24 1.1 jtc #include <sys/time.h>
25 1.1 jtc #include <sys/stat.h>
26 1.1 jtc #include <sys/ioctl.h>
27 1.1 jtc #include <netdb.h>
28 1.1 jtc #include <errno.h>
29 1.1 jtc #include <string.h>
30 1.1 jtc #include <ctype.h>
31 1.1 jtc
32 1.1 jtc #ifdef ISC_2_0
33 1.1 jtc #include <sys/fcntl.h>
34 1.1 jtc #endif
35 1.1 jtc
36 1.1 jtc #ifdef SHADOW_SUPPORT
37 1.1 jtc #include <shadow.h>
38 1.1 jtc #endif
39 1.1 jtc
40 1.1 jtc #ifdef WTMP
41 1.1 jtc int wtmp_enabled = 1;
42 1.1 jtc #endif
43 1.1 jtc
44 1.1 jtc #ifdef USE_GETUSERSHELL
45 1.1 jtc extern char *getusershell();
46 1.1 jtc #endif
47 1.1 jtc
48 1.1 jtc /*
49 1.1 jtc **---------------------------------------------------------------------
50 1.1 jtc ** Other #define's
51 1.1 jtc **---------------------------------------------------------------------
52 1.1 jtc */
53 1.1 jtc
54 1.1 jtc #define zchar 0x5b
55 1.1 jtc
56 1.1 jtc char tempstr[256];
57 1.1 jtc extern char sp_name[1024]; /* in pcnfsd_print.c */
58 1.1 jtc
59 1.1 jtc /*
60 1.1 jtc **=====================================================================
61 1.1 jtc ** C O D E S E C T I O N * **=====================================================================
62 1.1 jtc */
63 1.1 jtc /*
64 1.1 jtc **---------------------------------------------------------------------
65 1.1 jtc ** Support procedures
66 1.1 jtc **---------------------------------------------------------------------
67 1.1 jtc */
68 1.1 jtc
69 1.1 jtc
70 1.1 jtc void
71 1.1 jtc scramble(s1, s2)
72 1.1 jtc char *s1;
73 1.1 jtc char *s2;
74 1.1 jtc {
75 1.1 jtc while (*s1)
76 1.1 jtc {
77 1.1 jtc *s2++ = (*s1 ^ zchar) & 0x7f;
78 1.1 jtc s1++;
79 1.1 jtc }
80 1.1 jtc *s2 = 0;
81 1.1 jtc }
82 1.1 jtc
83 1.1 jtc
84 1.1 jtc
85 1.1 jtc struct passwd *
86 1.1 jtc get_password(usrnam)
87 1.1 jtc char *usrnam;
88 1.1 jtc {
89 1.1 jtc struct passwd *p;
90 1.1 jtc static struct passwd localp;
91 1.1 jtc char *pswd;
92 1.1 jtc char *ushell;
93 1.1 jtc int ok = 0;
94 1.1 jtc
95 1.1 jtc
96 1.1 jtc #ifdef SHADOW_SUPPORT
97 1.1 jtc struct spwd *sp;
98 1.1 jtc int shadowfile;
99 1.1 jtc #endif
100 1.1 jtc
101 1.1 jtc #ifdef SHADOW_SUPPORT
102 1.1 jtc /*
103 1.1 jtc **--------------------------------------------------------------
104 1.1 jtc ** Check the existence of SHADOW. If it is there, then we are
105 1.1 jtc ** running a two-password-file system.
106 1.1 jtc **--------------------------------------------------------------
107 1.1 jtc */
108 1.1 jtc if (access(SHADOW, 0))
109 1.1 jtc shadowfile = 0; /* SHADOW is not there */
110 1.1 jtc else
111 1.1 jtc shadowfile = 1;
112 1.1 jtc
113 1.1 jtc setpwent();
114 1.1 jtc if (shadowfile)
115 1.1 jtc (void) setspent(); /* Setting the shadow password
116 1.1 jtc * file */
117 1.1 jtc if ((p = getpwnam(usrnam)) == (struct passwd *)NULL ||
118 1.1 jtc (shadowfile && (sp = getspnam(usrnam)) == (struct spwd *)NULL))
119 1.1 jtc return ((struct passwd *)NULL);
120 1.1 jtc
121 1.1 jtc if (shadowfile)
122 1.1 jtc {
123 1.1 jtc pswd = sp->sp_pwdp;
124 1.1 jtc (void) endspent();
125 1.1 jtc }
126 1.1 jtc else
127 1.1 jtc pswd = p->pw_passwd;
128 1.1 jtc
129 1.1 jtc #else
130 1.1 jtc p = getpwnam(usrnam);
131 1.1 jtc if (p == (struct passwd *)NULL)
132 1.1 jtc return ((struct passwd *)NULL);
133 1.1 jtc pswd = p->pw_passwd;
134 1.1 jtc #endif
135 1.1 jtc
136 1.1 jtc #ifdef ISC_2_0
137 1.1 jtc /*
138 1.1 jtc **-----------------------------------------------------------
139 1.1 jtc ** We may have an 'x' in which case look in /etc/shadow ..
140 1.1 jtc **-----------------------------------------------------------
141 1.1 jtc */
142 1.1 jtc if (((strlen(pswd)) == 1) && pswd[0] == 'x')
143 1.1 jtc {
144 1.1 jtc struct spwd *shadow = getspnam(usrnam);
145 1.1 jtc
146 1.1 jtc if (!shadow)
147 1.1 jtc return ((struct passwd *)NULL);
148 1.1 jtc pswd = shadow->sp_pwdp;
149 1.1 jtc }
150 1.1 jtc #endif
151 1.1 jtc localp = *p;
152 1.1 jtc localp.pw_passwd = pswd;
153 1.1 jtc #ifdef USE_GETUSERSHELL
154 1.1 jtc
155 1.1 jtc setusershell();
156 1.1 jtc while(ushell = getusershell()){
157 1.1 jtc if(!strcmp(ushell, localp.pw_shell)) {
158 1.1 jtc ok = 1;
159 1.1 jtc break;
160 1.1 jtc }
161 1.1 jtc }
162 1.1 jtc endusershell();
163 1.1 jtc if(!ok)
164 1.1 jtc return ((struct passwd *)NULL);
165 1.1 jtc #else
166 1.1 jtc /*
167 1.1 jtc * the best we can do is to ensure that the shell ends in "sh"
168 1.1 jtc */
169 1.1 jtc ushell = localp.pw_shell;
170 1.1 jtc if(strlen(ushell) < 2)
171 1.1 jtc return ((struct passwd *)NULL);
172 1.1 jtc ushell += strlen(ushell) - 2;
173 1.1 jtc if(strcmp(ushell, "sh"))
174 1.1 jtc return ((struct passwd *)NULL);
175 1.1 jtc
176 1.1 jtc #endif
177 1.1 jtc return (&localp);
178 1.1 jtc }
179 1.1 jtc
180 1.1 jtc
181 1.1 jtc /*
183 1.1 jtc **---------------------------------------------------------------------
184 1.1 jtc ** Print support procedures
185 1.1 jtc **---------------------------------------------------------------------
186 1.1 jtc */
187 1.1 jtc
188 1.1 jtc char *
189 1.1 jtc mapfont(f, i, b)
190 1.1 jtc char f;
191 1.1 jtc char i;
192 1.1 jtc char b;
193 1.1 jtc {
194 1.1 jtc static char fontname[64];
195 1.1 jtc
196 1.1 jtc fontname[0] = 0; /* clear it out */
197 1.1 jtc
198 1.1 jtc switch (f) {
199 1.1 jtc case 'c':
200 1.1 jtc (void)strcpy(fontname, "Courier");
201 1.1 jtc break;
202 1.1 jtc case 'h':
203 1.1 jtc (void)strcpy(fontname, "Helvetica");
204 1.1 jtc break;
205 1.1 jtc case 't':
206 1.1 jtc (void)strcpy(fontname, "Times");
207 1.1 jtc break;
208 1.1 jtc default:
209 1.1 jtc (void)strcpy(fontname, "Times-Roman");
210 1.1 jtc goto finis ;
211 1.1 jtc }
212 1.1 jtc if (i != 'o' && b != 'b') { /* no bold or oblique */
213 1.1 jtc if (f == 't') /* special case Times */
214 1.1 jtc (void)strcat(fontname, "-Roman");
215 1.1 jtc goto finis;
216 1.1 jtc }
217 1.1 jtc (void)strcat(fontname, "-");
218 1.1 jtc if (b == 'b')
219 1.1 jtc (void)strcat(fontname, "Bold");
220 1.1 jtc if (i == 'o') /* o-blique */
221 1.1 jtc (void)strcat(fontname, f == 't' ? "Italic" : "Oblique");
222 1.1 jtc
223 1.1 jtc finis: return (&fontname[0]);
224 1.1 jtc }
225 1.1 jtc
226 1.1 jtc /*
227 1.1 jtc * run_ps630 performs the Diablo 630 emulation filtering process. ps630
228 1.1 jtc * was broken in certain Sun releases: it would not accept point size or
229 1.1 jtc * font changes. If your version is fixed, undefine the symbol
230 1.1 jtc * PS630_IS_BROKEN and rebuild pc-nfsd.
231 1.1 jtc */
232 1.1 jtc /* #define PS630_IS_BROKEN 1 */
233 1.1 jtc
234 1.1 jtc void
235 1.1 jtc run_ps630(f, opts)
236 1.1 jtc char *f;
237 1.1 jtc char *opts;
238 1.1 jtc {
239 1.1 jtc char temp_file[256];
240 1.1 jtc char commbuf[256];
241 1.1 jtc int i;
242 1.1 jtc
243 1.1 jtc (void)strcpy(temp_file, f);
244 1.1 jtc (void)strcat(temp_file, "X"); /* intermediate file name */
245 1.1 jtc
246 1.1 jtc #ifndef PS630_IS_BROKEN
247 1.1 jtc (void)sprintf(commbuf, "ps630 -s %c%c -p %s -f ",
248 1.1 jtc opts[2], opts[3], temp_file);
249 1.1 jtc (void)strcat(commbuf, mapfont(opts[4], opts[5], opts[6]));
250 1.1 jtc (void)strcat(commbuf, " -F ");
251 1.1 jtc (void)strcat(commbuf, mapfont(opts[7], opts[8], opts[9]));
252 1.1 jtc (void)strcat(commbuf, " ");
253 1.1 jtc (void)strcat(commbuf, f);
254 1.1 jtc #else /* PS630_IS_BROKEN */
255 1.1 jtc /*
256 1.1 jtc * The pitch and font features of ps630 appear to be broken at
257 1.1 jtc * this time.
258 1.1 jtc */
259 1.1 jtc (void)sprintf(commbuf, "ps630 -p %s %s", temp_file, f);
260 1.1 jtc #endif /* PS630_IS_BROKEN */
261 1.1 jtc
262 1.1 jtc
263 1.1 jtc if (i = system(commbuf)) {
264 1.1 jtc /*
265 1.1 jtc * Under (un)certain conditions, ps630 may return -1 even
266 1.1 jtc * if it worked. Hence the commenting out of this error
267 1.1 jtc * report.
268 1.1 jtc */
269 1.1 jtc /* (void)fprintf(stderr, "\n\nrun_ps630 rc = %d\n", i) */ ;
270 1.1 jtc /* exit(1); */
271 1.1 jtc }
272 1.1 jtc if (rename(temp_file, f)) {
273 1.1 jtc perror("run_ps630: rename");
274 1.1 jtc exit(1);
275 1.1 jtc }
276 1.1 jtc return;
277 1.1 jtc }
278 1.1 jtc
279 1.1 jtc
280 1.1 jtc
281 1.1 jtc
282 1.1 jtc /*
284 1.1 jtc **---------------------------------------------------------------------
285 1.1 jtc ** WTMP update support
286 1.1 jtc **---------------------------------------------------------------------
287 1.1 jtc */
288 1.1 jtc
289 1.1 jtc
290 1.1 jtc #ifdef WTMP
291 1.1 jtc
292 1.1 jtc #include <utmp.h>
293 1.1 jtc
294 1.1 jtc #ifndef _PATH_WTMP
295 1.1 jtc #define _PATH_WTMP "/usr/adm/wtmp"
296 1.1 jtc #endif
297 1.1 jtc
298 1.1 jtc void
299 1.1 jtc wlogin(name, req)
300 1.1 jtc char *name;
301 1.1 jtc struct svc_req *req;
302 1.1 jtc {
303 1.1 jtc extern char *inet_ntoa();
304 1.1 jtc struct sockaddr_in *who;
305 1.1 jtc struct hostent *hp;
306 1.1 jtc char *host;
307 1.1 jtc struct utmp ut;
308 1.1 jtc int fd;
309 1.1 jtc
310 1.1 jtc if(!wtmp_enabled)
311 1.1 jtc return;
312 1.1 jtc
313 1.1 jtc /* Get network address of client. */
314 1.1 jtc who = &req->rq_xprt->xp_raddr;
315 1.1 jtc
316 1.1 jtc /* Get name of connected client */
317 1.1 jtc hp = gethostbyaddr((char *)&who->sin_addr,
318 1.1 jtc sizeof (struct in_addr),
319 1.1 jtc who->sin_family);
320 1.1 jtc
321 1.1 jtc if (hp && (strlen(hp->h_name) <= sizeof(ut.ut_host))) {
322 1.1 jtc host = hp->h_name;
323 1.1 jtc } else {
324 1.1 jtc host = inet_ntoa(who->sin_addr);
325 1.1 jtc }
326 1.1 jtc
327 1.1 jtc (void) strcpy(ut.ut_line, "PC-NFS");
328 1.1 jtc (void) strncpy(ut.ut_name,name,sizeof ut.ut_name);
329 1.1 jtc (void) strncpy(ut.ut_host, host, sizeof ut.ut_host);
330 1.1 jtc ut.ut_time = time( (time_t *) 0);
331 1.1 jtc
332 1.1 jtc if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) >= 0) {
333 1.1 jtc (void)write(fd, (char *)&ut, sizeof(struct utmp));
334 1.1 jtc (void)close(fd);
335 1.1 jtc }
336 1.1 jtc }
337 1.1 jtc #endif WTMP
338 1.1 jtc
339 1.1 jtc /*
341 1.1 jtc **---------------------------------------------------------------------
342 1.1 jtc ** Run-process-as-user procedures
343 1.1 jtc **---------------------------------------------------------------------
344 1.1 jtc */
345 1.1 jtc
346 1.1 jtc
347 1.1 jtc #define READER_FD 0
348 1.1 jtc #define WRITER_FD 1
349 1.1 jtc
350 1.1 jtc static int child_pid;
351 1.1 jtc
352 1.1 jtc static char cached_user[64] = "";
353 1.1 jtc static uid_t cached_uid;
354 1.1 jtc static gid_t cached_gid;
355 1.1 jtc
356 1.1 jtc static struct sigaction old_action;
357 1.1 jtc static struct sigaction new_action;
358 1.1 jtc static struct itimerval timer;
359 1.1 jtc
360 1.1 jtc int interrupted = 0;
361 1.1 jtc static FILE *pipe_handle;
362 1.1 jtc
363 1.1 jtc static void myhandler()
364 1.1 jtc {
365 1.1 jtc interrupted = 1;
366 1.1 jtc fclose(pipe_handle);
367 1.1 jtc kill(child_pid, SIGKILL);
368 1.1 jtc msg_out("rpc.pcnfsd: su_popen timeout - killed child process");
369 1.1 jtc }
370 1.1 jtc
371 1.1 jtc void start_watchdog(n)
372 1.1 jtc int n;
373 1.1 jtc {
374 1.1 jtc /*
375 1.1 jtc * Setup SIGALRM handler, force interrupt of ongoing syscall
376 1.1 jtc */
377 1.1 jtc
378 1.1 jtc new_action.sa_handler = myhandler;
379 1.1 jtc sigemptyset(&(new_action.sa_mask));
380 1.1 jtc new_action.sa_flags = 0;
381 1.1 jtc #ifdef SA_INTERRUPT
382 1.1 jtc new_action.sa_flags |= SA_INTERRUPT;
383 1.1 jtc #endif
384 1.1 jtc sigaction(SIGALRM, &new_action, &old_action);
385 1.1 jtc
386 1.1 jtc /*
387 1.1 jtc * Set interval timer for n seconds
388 1.1 jtc */
389 1.1 jtc timer.it_interval.tv_sec = 0;
390 1.1 jtc timer.it_interval.tv_usec = 0;
391 1.1 jtc timer.it_value.tv_sec = n;
392 1.1 jtc timer.it_value.tv_usec = 0;
393 1.1 jtc setitimer(ITIMER_REAL, &timer, NULL);
394 1.1 jtc interrupted = 0;
395 1.1 jtc
396 1.1 jtc }
397 1.1 jtc
398 1.1 jtc void stop_watchdog()
399 1.1 jtc {
400 1.1 jtc /*
401 1.1 jtc * Cancel timer
402 1.1 jtc */
403 1.1 jtc
404 1.1 jtc timer.it_interval.tv_sec = 0;
405 1.1 jtc timer.it_interval.tv_usec = 0;
406 1.1 jtc timer.it_value.tv_sec = 0;
407 1.1 jtc timer.it_value.tv_usec = 0;
408 1.1 jtc setitimer(ITIMER_REAL, &timer, NULL);
409 1.1 jtc
410 1.1 jtc /*
411 1.1 jtc * restore old signal handling
412 1.1 jtc */
413 1.1 jtc sigaction(SIGALRM, &old_action, NULL);
414 1.1 jtc }
415 1.1 jtc
416 1.1 jtc
417 1.1 jtc
418 1.1 jtc FILE *
419 1.1 jtc su_popen(user, cmd, maxtime)
420 1.1 jtc char *user;
421 1.1 jtc char *cmd;
422 1.1 jtc int maxtime;
423 1.1 jtc {
424 1.1 jtc int p[2];
425 1.1 jtc int parent_fd, child_fd, pid;
426 1.1 jtc struct passwd *pw;
427 1.1 jtc
428 1.1 jtc if (strcmp(cached_user, user)) {
429 1.1 jtc pw = getpwnam(user);
430 1.1 jtc if (!pw)
431 1.1 jtc pw = getpwnam("nobody");
432 1.1 jtc if (pw) {
433 1.1 jtc cached_uid = pw->pw_uid;
434 1.1 jtc cached_gid = pw->pw_gid;
435 1.1 jtc strcpy(cached_user, user);
436 1.1 jtc } else {
437 1.1 jtc cached_uid = (uid_t) (-2);
438 1.1 jtc cached_gid = (gid_t) (-2);
439 1.1 jtc cached_user[0] = '\0';
440 1.1 jtc }
441 1.1 jtc }
442 1.1 jtc if (pipe(p) < 0) {
443 1.1 jtc msg_out("rpc.pcnfsd: unable to create pipe in su_popen");
444 1.1 jtc return (NULL);
445 1.1 jtc }
446 1.1 jtc parent_fd = p[READER_FD];
447 1.1 jtc child_fd = p[WRITER_FD];
448 1.1 jtc if ((pid = fork()) == 0) {
449 1.1 jtc int i;
450 1.1 jtc
451 1.1 jtc for (i = 0; i < 10; i++)
452 1.1 jtc if (i != child_fd)
453 1.1 jtc (void) close(i);
454 1.1 jtc if (child_fd != 1) {
455 1.1 jtc (void) dup2(child_fd, 1);
456 1.1 jtc (void) close(child_fd);
457 1.1 jtc }
458 1.1 jtc dup2(1, 2); /* let's get stderr as well */
459 1.1 jtc
460 1.1 jtc (void) setgid(cached_gid);
461 1.1 jtc (void) setuid(cached_uid);
462 1.1 jtc
463 1.1 jtc (void) execl("/bin/sh", "sh", "-c", cmd, (char *) NULL);
464 1.1 jtc _exit(255);
465 1.1 jtc }
466 1.1 jtc if (pid == -1) {
467 1.1 jtc msg_out("rpc.pcnfsd: fork failed");
468 1.1 jtc close(parent_fd);
469 1.1 jtc close(child_fd);
470 1.1 jtc return (NULL);
471 1.1 jtc }
472 1.1 jtc child_pid = pid;
473 1.1 jtc close(child_fd);
474 1.1 jtc start_watchdog(maxtime);
475 1.1 jtc pipe_handle = fdopen(parent_fd, "r");
476 1.1 jtc return (pipe_handle);
477 1.1 jtc }
478 1.1 jtc
479 1.1 jtc int
480 1.1 jtc su_pclose(ptr)
481 1.1 jtc FILE *ptr;
482 1.1 jtc {
483 1.1 jtc int pid, status;
484 1.1 jtc
485 1.1 jtc stop_watchdog();
486 1.1 jtc
487 1.1 jtc fclose(ptr);
488 1.1 jtc if (child_pid == -1)
489 1.1 jtc return (-1);
490 1.1 jtc while ((pid = wait(&status)) != child_pid && pid != -1);
491 1.1 jtc return (pid == -1 ? -1 : status);
492 1.1 jtc }
493 1.1 jtc
494 1.1 jtc
495 1.1 jtc /*
497 1.1 jtc ** The following routine reads a file "/etc/pcnfsd.conf" if present,
498 1.1 jtc ** and uses it to replace certain builtin elements, like the
499 1.1 jtc ** name of the print spool directory. The configuration file
500 1.1 jtc ** Is the usual kind: Comments begin with '#', blank lines are ignored,
501 1.1 jtc ** and valid lines are of the form
502 1.1 jtc **
503 1.1 jtc ** <keyword><whitespace><value>
504 1.1 jtc **
505 1.1 jtc ** The following keywords are recognized:
506 1.1 jtc **
507 1.1 jtc ** spooldir
508 1.1 jtc ** printer name alias-for command
509 1.1 jtc ** wtmp yes|no
510 1.1 jtc */
511 1.1 jtc void
512 1.1 jtc config_from_file()
513 1.1 jtc {
514 1.1 jtc FILE *fd;
515 1.1 jtc char buff[1024];
516 1.1 jtc char *cp;
517 1.1 jtc char *kw;
518 1.1 jtc char *val;
519 1.1 jtc char *arg1;
520 1.1 jtc char *arg2;
521 1.1 jtc
522 1.1 jtc if((fd = fopen("/etc/pcnfsd.conf", "r")) == NULL)
523 1.1 jtc return;
524 1.1 jtc while(fgets(buff, 1024, fd)) {
525 1.1 jtc cp = strchr(buff, '\n');
526 1.1 jtc *cp = '\0';
527 1.1 jtc cp = strchr(buff, '#');
528 1.1 jtc if(cp)
529 1.1 jtc *cp = '\0';
530 1.1 jtc kw = strtok(buff, " \t");
531 1.1 jtc if(kw == NULL)
532 1.1 jtc continue;
533 1.1 jtc val = strtok(NULL, " \t");
534 1.1 jtc if(val == NULL)
535 1.1 jtc continue;
536 1.1 jtc if(!mystrcasecmp(kw, "spooldir")) {
537 1.1 jtc strcpy(sp_name, val);
538 1.1 jtc continue;
539 1.1 jtc }
540 1.1 jtc #ifdef WTMP
541 1.1 jtc if(!mystrcasecmp(kw, "wtmp")) {
542 1.1 jtc /* assume default is YES, just look for negatives */
543 1.1 jtc if(!mystrcasecmp(val, "no") ||
544 1.1 jtc !mystrcasecmp(val, "off") ||
545 1.1 jtc !mystrcasecmp(val, "disable") ||
546 1.1 jtc !strcmp(val, "0"))
547 1.1 jtc wtmp_enabled = 0;;
548 1.1 jtc continue;
549 1.1 jtc }
550 1.1 jtc #endif
551 1.1 jtc if(!mystrcasecmp(kw, "printer")) {
552 1.1 jtc arg1 = strtok(NULL, " \t");
553 1.1 jtc arg2 = strtok(NULL, "");
554 1.1 jtc (void)add_printer_alias(val, arg1, arg2);
555 1.1 jtc continue;
556 1.1 jtc }
557 1.1 jtc /*
558 1.1 jtc ** Add new cases here
559 1.1 jtc */
560 1.1 jtc }
561 1.1 jtc fclose(fd);
562 1.1 jtc }
563 1.1 jtc
564 1.1 jtc
565 1.1 jtc /*
566 1.1 jtc ** The following are replacements for the SunOS library
567 1.1 jtc ** routines strcasecmp and strncasecmp, which SVR4 doesn't
568 1.1 jtc ** include.
569 1.1 jtc */
570 1.1 jtc
571 1.1 jtc mystrcasecmp(s1, s2)
572 1.1 jtc char *s1, *s2;
573 1.1 jtc {
574 1.1 jtc
575 1.1 jtc while (toupper(*s1) == toupper(*s2++))
576 1.1 jtc if (*s1++ == '\0')
577 1.1 jtc return(0);
578 1.1 jtc return(toupper(*s1) - toupper(*--s2));
579 1.1 jtc }
580 1.1 jtc
581 1.1 jtc mystrncasecmp(s1, s2, n)
582 1.1 jtc char *s1, *s2;
583 1.1 jtc int n;
584 1.1 jtc {
585 1.1 jtc
586 1.1 jtc while (--n >= 0 && toupper(*s1) == toupper(*s2++))
587 1.1 jtc if (*s1++ == '\0')
588 1.1 jtc return(0);
589 1.1 jtc return(n < 0 ? 0 : toupper(*s1) - toupper(*--s2));
590 1.1 jtc }
591 1.1 jtc
592 1.1 jtc
593 1.1 jtc /*
594 1.1 jtc ** strembedded - returns true if s1 is embedded (in any case) in s2
595 1.1 jtc */
596 1.1 jtc
597 1.1 jtc int strembedded(s1, s2)
598 1.1 jtc char *s1;
599 1.1 jtc char *s2;
600 1.1 jtc {
601 1.1 jtc while(*s2) {
602 1.1 jtc if(!mystrcasecmp(s1, s2))
603 1.1 jtc return 1;
604 s2++;
605 }
606 return 0;
607 }
608