17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
23bdcaf822Sbasabi * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate * nlsadmin.c -- control program for the network listener service
327c478bd9Sstevel@tonic-gate *
337c478bd9Sstevel@tonic-gate * This program replaces a previous version of nlsadmin.
34*2a8bcb4eSToomas Soome *
357c478bd9Sstevel@tonic-gate * This version of nlsadmin works with the service access facility to
367c478bd9Sstevel@tonic-gate * control the network listener. The functionality of the SVR3.2 nlsadmin
377c478bd9Sstevel@tonic-gate * command is supported through calls to the more general sacadm and pmadm
387c478bd9Sstevel@tonic-gate * commands available through SAF. Users should migrate away from nlsadmin
397c478bd9Sstevel@tonic-gate * to sacadm and pmadm for these functions.
407c478bd9Sstevel@tonic-gate *
417c478bd9Sstevel@tonic-gate * The -m option of the SVR3.2 nlsadmin command is now ignored.
427c478bd9Sstevel@tonic-gate *
437c478bd9Sstevel@tonic-gate * The -t option associates an address with service code 1 (same as in SVR3.2).
447c478bd9Sstevel@tonic-gate * The -l option associates an address with service code 0.
457c478bd9Sstevel@tonic-gate *
46*2a8bcb4eSToomas Soome * nlsadmin also contains new functionality -- the ability to format a
477c478bd9Sstevel@tonic-gate * "listener-specific" string to put in the _pmtab database. This
487c478bd9Sstevel@tonic-gate * functionality is required by SAF.
497c478bd9Sstevel@tonic-gate */
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate #include <sys/types.h>
527c478bd9Sstevel@tonic-gate #include <sys/stat.h>
537c478bd9Sstevel@tonic-gate #include <stdio.h>
54bdcaf822Sbasabi #include <stdlib.h>
557c478bd9Sstevel@tonic-gate #include <ctype.h>
567c478bd9Sstevel@tonic-gate #include <errno.h>
577c478bd9Sstevel@tonic-gate #include <string.h>
587c478bd9Sstevel@tonic-gate #include <sac.h>
597c478bd9Sstevel@tonic-gate #include "nlsadmin.h"
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate #define OPTIONS "a:c:d:e:ikl:mo:p:qr:st:vw:xy:z:A:N:VDR:"
627c478bd9Sstevel@tonic-gate #ifndef FALSE
637c478bd9Sstevel@tonic-gate #define TRUE 1
647c478bd9Sstevel@tonic-gate #define FALSE 0
657c478bd9Sstevel@tonic-gate #endif
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate * defines for -q exit codes: QZERO is used for conditions that the
687c478bd9Sstevel@tonic-gate * man page documents as returning 0, QONE for those that return 1
697c478bd9Sstevel@tonic-gate */
707c478bd9Sstevel@tonic-gate #define QZERO 0
717c478bd9Sstevel@tonic-gate #define QONE 1
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate /*
747c478bd9Sstevel@tonic-gate * defines for simulated standard error format code
757c478bd9Sstevel@tonic-gate */
767c478bd9Sstevel@tonic-gate #define MM_NOSEV 0
777c478bd9Sstevel@tonic-gate #define MM_HALT 1
787c478bd9Sstevel@tonic-gate #define MM_ERROR 2
797c478bd9Sstevel@tonic-gate #define MM_WARNING 3
807c478bd9Sstevel@tonic-gate #define MM_INFO 4
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate char *Nlsname; /* set to argv[0] */
837c478bd9Sstevel@tonic-gate char Label[25]; /* label component for fmtmsg */
847c478bd9Sstevel@tonic-gate int Quietflag = FALSE; /* set to TRUE when -q used */
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate extern int errno;
877c478bd9Sstevel@tonic-gate void nlsmesg();
887c478bd9Sstevel@tonic-gate uid_t geteuid();
897c478bd9Sstevel@tonic-gate char *nexttok();
907c478bd9Sstevel@tonic-gate char *pflags();
917c478bd9Sstevel@tonic-gate char *gencmdstr();
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate struct svcfields {
947c478bd9Sstevel@tonic-gate char *pmtag;
957c478bd9Sstevel@tonic-gate char *pmtype;
967c478bd9Sstevel@tonic-gate char *svc_code;
977c478bd9Sstevel@tonic-gate char *flags;
987c478bd9Sstevel@tonic-gate char *id;
997c478bd9Sstevel@tonic-gate char *res1;
1007c478bd9Sstevel@tonic-gate char *res2;
1017c478bd9Sstevel@tonic-gate char *res3;
1027c478bd9Sstevel@tonic-gate char *addr;
1037c478bd9Sstevel@tonic-gate char *rpc;
1047c478bd9Sstevel@tonic-gate char *lflags;
1057c478bd9Sstevel@tonic-gate char *modules;
1067c478bd9Sstevel@tonic-gate char *command;
1077c478bd9Sstevel@tonic-gate char *comment;
1087c478bd9Sstevel@tonic-gate };
1097c478bd9Sstevel@tonic-gate
110bdcaf822Sbasabi void no_permission(void) __NORETURN;
111bdcaf822Sbasabi void usage(int flag);
1127c478bd9Sstevel@tonic-gate
113bdcaf822Sbasabi int
main(int argc,char ** argv)114bdcaf822Sbasabi main(int argc, char **argv)
1157c478bd9Sstevel@tonic-gate {
1167c478bd9Sstevel@tonic-gate extern char *optarg;
1177c478bd9Sstevel@tonic-gate extern int optind;
1187c478bd9Sstevel@tonic-gate int c; /* used for return from getopt */
1197c478bd9Sstevel@tonic-gate char *addrptr = NULL; /* set when -A address is used */
1207c478bd9Sstevel@tonic-gate char *rpcptr = NULL; /* set when -R rpcinfo is used */
1217c478bd9Sstevel@tonic-gate char *cmdptr = NULL; /* set with -c command */
1227c478bd9Sstevel@tonic-gate char *comptr = NULL; /* set with -y comment (old) */
1237c478bd9Sstevel@tonic-gate char *idptr = NULL; /* set with -w id (old) */
1247c478bd9Sstevel@tonic-gate char *lptr = NULL; /* set with -l addr (old) */
1257c478bd9Sstevel@tonic-gate char *moduleptr = NULL; /* set with -m modules */
1267c478bd9Sstevel@tonic-gate char *pipeptr = NULL; /* set with -o pipe */
1277c478bd9Sstevel@tonic-gate char *svcptr = NULL; /* set when service code used (old) */
1287c478bd9Sstevel@tonic-gate char *tptr = NULL; /* set when -t addr used (old) */
1297c478bd9Sstevel@tonic-gate char *netspec = NULL; /* set to the network specification */
1307c478bd9Sstevel@tonic-gate int flag = 0; /* bit flag of type of command */
1317c478bd9Sstevel@tonic-gate int exitcode = 0; /* exit status of this command */
1327c478bd9Sstevel@tonic-gate int lflags = 0; /* listener flags */
1337c478bd9Sstevel@tonic-gate char buf[BUFSIZ]; /* temp buffer #1 */
1347c478bd9Sstevel@tonic-gate char mesg[BUFSIZ]; /* temp buffer #2 */
1357c478bd9Sstevel@tonic-gate FILE *fp; /* used for checking netspec */
1367c478bd9Sstevel@tonic-gate char *ptr; /* temp pointer */
1377c478bd9Sstevel@tonic-gate char *ptr2; /* temp pointer */
1387c478bd9Sstevel@tonic-gate int sawsep = 0; /* flag for RPC separator */
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate Nlsname = argv[0];
1417c478bd9Sstevel@tonic-gate sprintf(Label, "UX:%.14s", argv[0]); /* for standard message fmt */
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, OPTIONS)) != -1) {
1447c478bd9Sstevel@tonic-gate switch (c) {
1457c478bd9Sstevel@tonic-gate case 'a':
1467c478bd9Sstevel@tonic-gate if ( (flag && (flag != CMDFLAG)) || svcptr || Quietflag
1477c478bd9Sstevel@tonic-gate || addrptr || rpcptr || lflags)
1487c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
1497c478bd9Sstevel@tonic-gate svcptr = optarg;
1507c478bd9Sstevel@tonic-gate break;
1517c478bd9Sstevel@tonic-gate case 'c':
1527c478bd9Sstevel@tonic-gate if ( (flag && (flag != CMDFLAG)) || cmdptr || Quietflag )
1537c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
1547c478bd9Sstevel@tonic-gate cmdptr = optarg;
1557c478bd9Sstevel@tonic-gate flag |= CMDFLAG;
1567c478bd9Sstevel@tonic-gate break;
1577c478bd9Sstevel@tonic-gate case 'd':
1587c478bd9Sstevel@tonic-gate if ( flag || svcptr || Quietflag || comptr || addrptr
1597c478bd9Sstevel@tonic-gate || rpcptr || cmdptr || idptr || lflags )
1607c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
1617c478bd9Sstevel@tonic-gate svcptr = optarg;
1627c478bd9Sstevel@tonic-gate flag |= DISFLAG;
1637c478bd9Sstevel@tonic-gate break;
1647c478bd9Sstevel@tonic-gate case 'e':
1657c478bd9Sstevel@tonic-gate if ( flag || svcptr || Quietflag || comptr || addrptr
1667c478bd9Sstevel@tonic-gate || rpcptr || cmdptr || idptr || lflags )
1677c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
1687c478bd9Sstevel@tonic-gate svcptr = optarg;
1697c478bd9Sstevel@tonic-gate flag |= ENAFLAG;
1707c478bd9Sstevel@tonic-gate break;
1717c478bd9Sstevel@tonic-gate case 'i':
1727c478bd9Sstevel@tonic-gate if ( flag || svcptr || Quietflag || comptr || addrptr
1737c478bd9Sstevel@tonic-gate || rpcptr || cmdptr || idptr || lflags )
1747c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
1757c478bd9Sstevel@tonic-gate flag |= INIFLAG;
1767c478bd9Sstevel@tonic-gate break;
1777c478bd9Sstevel@tonic-gate case 'k':
1787c478bd9Sstevel@tonic-gate if ( flag || svcptr || Quietflag || comptr || addrptr
1797c478bd9Sstevel@tonic-gate || rpcptr || cmdptr || idptr || lflags )
1807c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
1817c478bd9Sstevel@tonic-gate flag |= KILFLAG;
1827c478bd9Sstevel@tonic-gate break;
1837c478bd9Sstevel@tonic-gate case 'l':
1847c478bd9Sstevel@tonic-gate if ( ( flag && (flag != ADRFLAG)) || svcptr || lptr
1857c478bd9Sstevel@tonic-gate || Quietflag || comptr || addrptr || rpcptr
1867c478bd9Sstevel@tonic-gate || cmdptr || idptr || lflags )
1877c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
1887c478bd9Sstevel@tonic-gate lptr = optarg;
1897c478bd9Sstevel@tonic-gate flag |= ADRFLAG;
1907c478bd9Sstevel@tonic-gate break;
1917c478bd9Sstevel@tonic-gate case 'm':
1927c478bd9Sstevel@tonic-gate if ( (flag && (flag != CMDFLAG)) || Quietflag || rpcptr || lflags )
1937c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
1947c478bd9Sstevel@tonic-gate flag |= CMDFLAG;
1957c478bd9Sstevel@tonic-gate break;
1967c478bd9Sstevel@tonic-gate case 'o':
1977c478bd9Sstevel@tonic-gate if ( flag || svcptr || Quietflag || comptr || idptr || netspec )
1987c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
1997c478bd9Sstevel@tonic-gate pipeptr = optarg;
2007c478bd9Sstevel@tonic-gate flag |= PIPFLAG;
2017c478bd9Sstevel@tonic-gate break;
2027c478bd9Sstevel@tonic-gate case 'p':
2037c478bd9Sstevel@tonic-gate if ( (flag && (flag != CMDFLAG) && (flag != PIPFLAG)) || Quietflag )
2047c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
2057c478bd9Sstevel@tonic-gate moduleptr = optarg;
2067c478bd9Sstevel@tonic-gate break;
2077c478bd9Sstevel@tonic-gate case 'q':
208*2a8bcb4eSToomas Soome if ( (flag && (flag != ZZZFLAG)) || Quietflag || comptr
2097c478bd9Sstevel@tonic-gate || rpcptr || lflags || idptr )
2107c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
2117c478bd9Sstevel@tonic-gate Quietflag = TRUE;
2127c478bd9Sstevel@tonic-gate break;
2137c478bd9Sstevel@tonic-gate case 'r':
2147c478bd9Sstevel@tonic-gate if ( flag || svcptr || Quietflag || comptr || addrptr
2157c478bd9Sstevel@tonic-gate || rpcptr || cmdptr || idptr || lflags )
2167c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
2177c478bd9Sstevel@tonic-gate flag |= REMFLAG;
2187c478bd9Sstevel@tonic-gate svcptr = optarg;
2197c478bd9Sstevel@tonic-gate break;
2207c478bd9Sstevel@tonic-gate case 's':
2217c478bd9Sstevel@tonic-gate if ( flag || svcptr || Quietflag || comptr || addrptr
2227c478bd9Sstevel@tonic-gate || rpcptr || cmdptr || idptr || lflags )
2237c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
2247c478bd9Sstevel@tonic-gate flag |= STAFLAG;
2257c478bd9Sstevel@tonic-gate break;
2267c478bd9Sstevel@tonic-gate case 't':
2277c478bd9Sstevel@tonic-gate if ( (flag && (flag != ADRFLAG)) || svcptr || tptr
2287c478bd9Sstevel@tonic-gate || Quietflag || comptr || addrptr || rpcptr
2297c478bd9Sstevel@tonic-gate || cmdptr || idptr || lflags )
2307c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
2317c478bd9Sstevel@tonic-gate tptr = optarg;
2327c478bd9Sstevel@tonic-gate flag |= ADRFLAG;
2337c478bd9Sstevel@tonic-gate break;
2347c478bd9Sstevel@tonic-gate case 'v':
2357c478bd9Sstevel@tonic-gate if ( flag || svcptr || Quietflag || comptr || rpcptr
2367c478bd9Sstevel@tonic-gate || addrptr || idptr || lflags )
2377c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
2387c478bd9Sstevel@tonic-gate flag |= VBSFLAG;
2397c478bd9Sstevel@tonic-gate break;
2407c478bd9Sstevel@tonic-gate case 'w':
2417c478bd9Sstevel@tonic-gate if ( (flag && (flag != CMDFLAG)) || Quietflag || idptr
2427c478bd9Sstevel@tonic-gate || rpcptr || addrptr || lflags )
2437c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
2447c478bd9Sstevel@tonic-gate idptr = optarg;
2457c478bd9Sstevel@tonic-gate break;
2467c478bd9Sstevel@tonic-gate case 'x':
2477c478bd9Sstevel@tonic-gate if ( flag || svcptr || Quietflag || netspec || comptr
2487c478bd9Sstevel@tonic-gate || rpcptr || addrptr || lflags || idptr )
2497c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
2507c478bd9Sstevel@tonic-gate flag |= NETFLAG;
2517c478bd9Sstevel@tonic-gate break;
2527c478bd9Sstevel@tonic-gate case 'y':
2537c478bd9Sstevel@tonic-gate if ( (flag && (flag != CMDFLAG)) || Quietflag || comptr
2547c478bd9Sstevel@tonic-gate || rpcptr || addrptr || lflags )
2557c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
2567c478bd9Sstevel@tonic-gate comptr = optarg;
2577c478bd9Sstevel@tonic-gate break;
2587c478bd9Sstevel@tonic-gate case 'z':
2597c478bd9Sstevel@tonic-gate if ( flag || svcptr || comptr || addrptr || rpcptr
2607c478bd9Sstevel@tonic-gate || idptr || lflags )
2617c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
2627c478bd9Sstevel@tonic-gate flag |= ZZZFLAG;
2637c478bd9Sstevel@tonic-gate svcptr = optarg;
2647c478bd9Sstevel@tonic-gate break;
2657c478bd9Sstevel@tonic-gate case 'A':
2667c478bd9Sstevel@tonic-gate if ( (flag && (flag != CMDFLAG) && (flag != PIPFLAG))
2677c478bd9Sstevel@tonic-gate || netspec || svcptr || idptr || comptr )
2687c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
2697c478bd9Sstevel@tonic-gate addrptr = optarg;
2707c478bd9Sstevel@tonic-gate break;
2717c478bd9Sstevel@tonic-gate case 'D':
2727c478bd9Sstevel@tonic-gate if ( (flag && (flag != CMDFLAG) && (flag != PIPFLAG))
2737c478bd9Sstevel@tonic-gate || netspec || svcptr || idptr || comptr || addrptr
2747c478bd9Sstevel@tonic-gate || lflags )
2757c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
2767c478bd9Sstevel@tonic-gate lflags |= DFLAG;
2777c478bd9Sstevel@tonic-gate break;
2787c478bd9Sstevel@tonic-gate case 'N':
2797c478bd9Sstevel@tonic-gate if ( netspec )
2807c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
2817c478bd9Sstevel@tonic-gate netspec = optarg;
2827c478bd9Sstevel@tonic-gate break;
2837c478bd9Sstevel@tonic-gate case 'R':
2847c478bd9Sstevel@tonic-gate if ( (flag && (flag != CMDFLAG) && (flag != PIPFLAG))
2857c478bd9Sstevel@tonic-gate || netspec || svcptr || idptr || comptr )
2867c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
2877c478bd9Sstevel@tonic-gate for (ptr = optarg; *ptr; ++ptr) {
2887c478bd9Sstevel@tonic-gate if ((*ptr == ':') && !sawsep) {
2897c478bd9Sstevel@tonic-gate /*
2907c478bd9Sstevel@tonic-gate * skip separator - note that if
2917c478bd9Sstevel@tonic-gate * separator has been seen, it's not
2927c478bd9Sstevel@tonic-gate * a digit so it will generate a usage
2937c478bd9Sstevel@tonic-gate * message below like we want
2947c478bd9Sstevel@tonic-gate */
2957c478bd9Sstevel@tonic-gate sawsep++;
2967c478bd9Sstevel@tonic-gate continue;
2977c478bd9Sstevel@tonic-gate }
2987c478bd9Sstevel@tonic-gate if (!isdigit(*ptr))
2997c478bd9Sstevel@tonic-gate usage(USAGE);
3007c478bd9Sstevel@tonic-gate }
3017c478bd9Sstevel@tonic-gate ptr = strchr(optarg, ':');
3027c478bd9Sstevel@tonic-gate if (ptr)
3037c478bd9Sstevel@tonic-gate /* change the ':' to a ',' */
3047c478bd9Sstevel@tonic-gate *ptr = ',';
3057c478bd9Sstevel@tonic-gate else
3067c478bd9Sstevel@tonic-gate usage(USAGE);
3077c478bd9Sstevel@tonic-gate rpcptr = optarg;
3087c478bd9Sstevel@tonic-gate break;
3097c478bd9Sstevel@tonic-gate case 'V':
3107c478bd9Sstevel@tonic-gate if ( flag || svcptr || Quietflag || comptr || netspec
3117c478bd9Sstevel@tonic-gate || rpcptr || addrptr || idptr || lflags )
3127c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
3137c478bd9Sstevel@tonic-gate flag |= VERFLAG;
3147c478bd9Sstevel@tonic-gate break;
3157c478bd9Sstevel@tonic-gate case '?':
3167c478bd9Sstevel@tonic-gate usage(USAGE);
3177c478bd9Sstevel@tonic-gate }
318*2a8bcb4eSToomas Soome /* NOTREACHED */
3197c478bd9Sstevel@tonic-gate }
3207c478bd9Sstevel@tonic-gate
3217c478bd9Sstevel@tonic-gate if ((optind < argc) && ! netspec)
3227c478bd9Sstevel@tonic-gate netspec = argv[optind++];
3237c478bd9Sstevel@tonic-gate if (optind < argc)
3247c478bd9Sstevel@tonic-gate usage(USAGE);
3257c478bd9Sstevel@tonic-gate
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate /* determine if this command requires a netspec */
3287c478bd9Sstevel@tonic-gate if (flag != CMDFLAG) {
3297c478bd9Sstevel@tonic-gate /* if flag is CMDFLAG, more complicated checking of netspec
330*2a8bcb4eSToomas Soome * is done below in switch
3317c478bd9Sstevel@tonic-gate */
3327c478bd9Sstevel@tonic-gate if ((flag == PIPFLAG || flag == VERFLAG || flag == NETFLAG)) {
3337c478bd9Sstevel@tonic-gate if (netspec)
3347c478bd9Sstevel@tonic-gate usage(USAGE);
3357c478bd9Sstevel@tonic-gate }
3367c478bd9Sstevel@tonic-gate else if (!netspec)
3377c478bd9Sstevel@tonic-gate usage(USAGE);
3387c478bd9Sstevel@tonic-gate }
3397c478bd9Sstevel@tonic-gate
3407c478bd9Sstevel@tonic-gate if (netspec && (flag != INIFLAG)) {
3417c478bd9Sstevel@tonic-gate sprintf(buf, SAC_LSPM, netspec);
3427c478bd9Sstevel@tonic-gate
3437c478bd9Sstevel@tonic-gate if ((fp = popen(buf, "r")) == NULL) {
3447c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "System error");
3457c478bd9Sstevel@tonic-gate exit(NLS_SYSERR);
3467c478bd9Sstevel@tonic-gate }
3477c478bd9Sstevel@tonic-gate
3487c478bd9Sstevel@tonic-gate if (fgets(buf, BUFSIZ, fp) == NULL) {
3497c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "Invalid network specification");
3507c478bd9Sstevel@tonic-gate exit(NLS_BADPM);
3517c478bd9Sstevel@tonic-gate }
3527c478bd9Sstevel@tonic-gate else {
3537c478bd9Sstevel@tonic-gate ptr = strchr(buf, ':');
3547c478bd9Sstevel@tonic-gate ptr++;
3557c478bd9Sstevel@tonic-gate ptr2 = strchr(ptr, ':');
35667e41408SToomas Soome *ptr2 = '\0';
3577c478bd9Sstevel@tonic-gate if (strcmp(ptr, LISTENTYPE) != 0) {
3587c478bd9Sstevel@tonic-gate sprintf(mesg, "Network specification \"%s\" is not of type %s", netspec, LISTENTYPE);
3597c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, mesg);
3607c478bd9Sstevel@tonic-gate exit(NLS_BADPM);
3617c478bd9Sstevel@tonic-gate }
3627c478bd9Sstevel@tonic-gate }
3637c478bd9Sstevel@tonic-gate
3647c478bd9Sstevel@tonic-gate pclose(fp);
3657c478bd9Sstevel@tonic-gate }
3667c478bd9Sstevel@tonic-gate
3677c478bd9Sstevel@tonic-gate if (svcptr) {
3687c478bd9Sstevel@tonic-gate /* check to see if service code is "correct" -- right range
3697c478bd9Sstevel@tonic-gate * and format. The -m flag is ignored, so no check for
3707c478bd9Sstevel@tonic-gate * "administrative" service codes (0-100) is done.
3717c478bd9Sstevel@tonic-gate */
3727c478bd9Sstevel@tonic-gate c = strlen(svcptr);
3737c478bd9Sstevel@tonic-gate if ((c == 0) || (c >= SVC_CODE_SZ)) {
3747c478bd9Sstevel@tonic-gate sprintf(mesg, "Service code contains more than %d characters", SVC_CODE_SZ);
3757c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, mesg);
3767c478bd9Sstevel@tonic-gate exit(NLS_SERV);
3777c478bd9Sstevel@tonic-gate }
3787c478bd9Sstevel@tonic-gate }
3797c478bd9Sstevel@tonic-gate
3807c478bd9Sstevel@tonic-gate switch (flag) {
3817c478bd9Sstevel@tonic-gate default:
3827c478bd9Sstevel@tonic-gate usage(USAGE);
3837c478bd9Sstevel@tonic-gate break;
3847c478bd9Sstevel@tonic-gate case NONE:
3857c478bd9Sstevel@tonic-gate if ( svcptr || comptr || rpcptr || lflags || idptr )
3867c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
3877c478bd9Sstevel@tonic-gate exitcode = prt_nets(netspec);
3887c478bd9Sstevel@tonic-gate break;
3897c478bd9Sstevel@tonic-gate case INIFLAG:
390*2a8bcb4eSToomas Soome if (geteuid() != ROOT)
3917c478bd9Sstevel@tonic-gate no_permission();
3927c478bd9Sstevel@tonic-gate exitcode = add_pm(netspec);
3937c478bd9Sstevel@tonic-gate break;
3947c478bd9Sstevel@tonic-gate case CMDFLAG:
3957c478bd9Sstevel@tonic-gate if ( svcptr || comptr || idptr || netspec ) {
3967c478bd9Sstevel@tonic-gate if (geteuid() != ROOT)
3977c478bd9Sstevel@tonic-gate no_permission();
3987c478bd9Sstevel@tonic-gate if ((exitcode = old_addsvc(svcptr, "", cmdptr, comptr, moduleptr, idptr, NULL, netspec)) != NLS_OK)
3997c478bd9Sstevel@tonic-gate switch (exitcode) {
4007c478bd9Sstevel@tonic-gate case NLS_SERV:
4017c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "Service code already exists");
4027c478bd9Sstevel@tonic-gate break;
4037c478bd9Sstevel@tonic-gate default:
4047c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "Could not add service");
4057c478bd9Sstevel@tonic-gate break;
4067c478bd9Sstevel@tonic-gate }
4077c478bd9Sstevel@tonic-gate }
4087c478bd9Sstevel@tonic-gate else {
4097c478bd9Sstevel@tonic-gate if (netspec)
4107c478bd9Sstevel@tonic-gate usage(INCONSISTENT);
4117c478bd9Sstevel@tonic-gate exitcode = prt_cmd(cmdptr, CFLAG | lflags, moduleptr, addrptr, rpcptr);
4127c478bd9Sstevel@tonic-gate }
4137c478bd9Sstevel@tonic-gate break;
4147c478bd9Sstevel@tonic-gate case PIPFLAG:
4157c478bd9Sstevel@tonic-gate if (geteuid() != ROOT)
4167c478bd9Sstevel@tonic-gate no_permission();
4177c478bd9Sstevel@tonic-gate exitcode = prt_cmd(pipeptr, PFLAG | lflags, moduleptr, addrptr, rpcptr);
4187c478bd9Sstevel@tonic-gate break;
4197c478bd9Sstevel@tonic-gate case VERFLAG:
4207c478bd9Sstevel@tonic-gate printf("%d\n", VERSION);
4217c478bd9Sstevel@tonic-gate exit(NLS_OK);
4227c478bd9Sstevel@tonic-gate break;
4237c478bd9Sstevel@tonic-gate case DISFLAG:
4247c478bd9Sstevel@tonic-gate if (geteuid() != ROOT)
4257c478bd9Sstevel@tonic-gate no_permission();
4267c478bd9Sstevel@tonic-gate exitcode = disable_svc(svcptr, netspec);
4277c478bd9Sstevel@tonic-gate break;
4287c478bd9Sstevel@tonic-gate case ENAFLAG:
4297c478bd9Sstevel@tonic-gate if (geteuid() != ROOT)
4307c478bd9Sstevel@tonic-gate no_permission();
4317c478bd9Sstevel@tonic-gate exitcode = enable_svc(svcptr, netspec);
4327c478bd9Sstevel@tonic-gate break;
4337c478bd9Sstevel@tonic-gate case KILFLAG:
4347c478bd9Sstevel@tonic-gate if (geteuid() != ROOT)
4357c478bd9Sstevel@tonic-gate no_permission();
4367c478bd9Sstevel@tonic-gate exitcode = kill_listener(netspec);
4377c478bd9Sstevel@tonic-gate break;
4387c478bd9Sstevel@tonic-gate case ADRFLAG:
4397c478bd9Sstevel@tonic-gate /* check for root permissions in setup_addr */
4407c478bd9Sstevel@tonic-gate exitcode = setup_addr(lptr, tptr, netspec);
4417c478bd9Sstevel@tonic-gate break;
4427c478bd9Sstevel@tonic-gate case REMFLAG:
4437c478bd9Sstevel@tonic-gate if (geteuid() != ROOT)
4447c478bd9Sstevel@tonic-gate no_permission();
4457c478bd9Sstevel@tonic-gate exitcode = remove_svc(svcptr, netspec, TRUE);
4467c478bd9Sstevel@tonic-gate break;
4477c478bd9Sstevel@tonic-gate case STAFLAG:
4487c478bd9Sstevel@tonic-gate if (geteuid() != ROOT)
4497c478bd9Sstevel@tonic-gate no_permission();
4507c478bd9Sstevel@tonic-gate exitcode = start_listener(netspec);
4517c478bd9Sstevel@tonic-gate break;
4527c478bd9Sstevel@tonic-gate case VBSFLAG:
4537c478bd9Sstevel@tonic-gate exitcode = prt_svcs(NULL, netspec);
4547c478bd9Sstevel@tonic-gate break;
4557c478bd9Sstevel@tonic-gate case NETFLAG:
4567c478bd9Sstevel@tonic-gate exitcode = prt_nets(NULL);
4577c478bd9Sstevel@tonic-gate break;
4587c478bd9Sstevel@tonic-gate case ZZZFLAG:
4597c478bd9Sstevel@tonic-gate exitcode = prt_svcs(svcptr, netspec);
4607c478bd9Sstevel@tonic-gate break;
4617c478bd9Sstevel@tonic-gate }
4627c478bd9Sstevel@tonic-gate if (exitcode == NLS_SYSERR)
4637c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "System error in SAC command");
464bdcaf822Sbasabi return (exitcode);
4657c478bd9Sstevel@tonic-gate }
4667c478bd9Sstevel@tonic-gate
4677c478bd9Sstevel@tonic-gate
4687c478bd9Sstevel@tonic-gate static char umsg[] = "usage: %s -x\n\
4697c478bd9Sstevel@tonic-gate %s [ options ] netspec\n\
4707c478bd9Sstevel@tonic-gate %s [ options ] -N port_monitor_tag\n\
4717c478bd9Sstevel@tonic-gate %s -V\n\
4727c478bd9Sstevel@tonic-gate %s -c cmd | -o pipename [ -p modules ] [ -A addr | -D ] \\\n\
4737c478bd9Sstevel@tonic-gate [ -R prognum:versnum ]\n\
4747c478bd9Sstevel@tonic-gate \n\
4757c478bd9Sstevel@tonic-gate [ options ] are:\n\
4767c478bd9Sstevel@tonic-gate [ -a svc_code -c \"cmd\" -y \"cmt\" [-p modules] [-w id] ]\n\
4777c478bd9Sstevel@tonic-gate [-q] | [-v] | [-s] | [-k] | [-i] |\n\
4787c478bd9Sstevel@tonic-gate [-e svc_code] | [-d svc_code] | [-r svc_code] | [[-q] -z svc_code]\n\
4797c478bd9Sstevel@tonic-gate [[-l addr | -] [-t addr | -]] |\n\
4807c478bd9Sstevel@tonic-gate ";
4817c478bd9Sstevel@tonic-gate
482bdcaf822Sbasabi void
usage(int flag)483bdcaf822Sbasabi usage(int flag)
4847c478bd9Sstevel@tonic-gate {
4857c478bd9Sstevel@tonic-gate switch (flag) {
4867c478bd9Sstevel@tonic-gate case INCONSISTENT:
4877c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "Inconsistent options");
4887c478bd9Sstevel@tonic-gate break;
4897c478bd9Sstevel@tonic-gate case MISSINGARG:
4907c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "Missing argument");
4917c478bd9Sstevel@tonic-gate break;
4927c478bd9Sstevel@tonic-gate case USAGE:
4937c478bd9Sstevel@tonic-gate break;
4947c478bd9Sstevel@tonic-gate }
4957c478bd9Sstevel@tonic-gate fprintf(stderr, umsg, Nlsname, Nlsname, Nlsname, Nlsname, Nlsname);
4967c478bd9Sstevel@tonic-gate exit(NLS_CMD);
4977c478bd9Sstevel@tonic-gate }
4987c478bd9Sstevel@tonic-gate
4997c478bd9Sstevel@tonic-gate
5007c478bd9Sstevel@tonic-gate /*
5017c478bd9Sstevel@tonic-gate * no_permission: print out error message and exit when the user needs to
5027c478bd9Sstevel@tonic-gate * needs to be root and isn't.
5037c478bd9Sstevel@tonic-gate */
5047c478bd9Sstevel@tonic-gate
505bdcaf822Sbasabi void
no_permission(void)506bdcaf822Sbasabi no_permission(void)
5077c478bd9Sstevel@tonic-gate {
5087c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "Must be super user");
5097c478bd9Sstevel@tonic-gate exit(NLS_PERM);
5107c478bd9Sstevel@tonic-gate }
5117c478bd9Sstevel@tonic-gate
5127c478bd9Sstevel@tonic-gate /*
5137c478bd9Sstevel@tonic-gate * nlsmesg: print out either an error or a warning message. severity must
5147c478bd9Sstevel@tonic-gate * be either MM_ERROR or MM_WARNING. this routine will be converted
5157c478bd9Sstevel@tonic-gate * to use the standard message format later.
5167c478bd9Sstevel@tonic-gate */
5177c478bd9Sstevel@tonic-gate
5187c478bd9Sstevel@tonic-gate void
nlsmesg(int severity,char * text)519bdcaf822Sbasabi nlsmesg(int severity, char *text)
5207c478bd9Sstevel@tonic-gate {
5217c478bd9Sstevel@tonic-gate int class;
5227c478bd9Sstevel@tonic-gate
5237c478bd9Sstevel@tonic-gate if (severity == MM_ERROR)
5247c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: error: %s\n", Nlsname, text);
5257c478bd9Sstevel@tonic-gate else
5267c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: warning: %s\n", Nlsname, text);
5277c478bd9Sstevel@tonic-gate return;
5287c478bd9Sstevel@tonic-gate }
5297c478bd9Sstevel@tonic-gate
5307c478bd9Sstevel@tonic-gate /*
5317c478bd9Sstevel@tonic-gate * prt_cmd: print out the listener-dependent string for sacadm.
5327c478bd9Sstevel@tonic-gate */
5337c478bd9Sstevel@tonic-gate
534bdcaf822Sbasabi int
prt_cmd(char * path,long flags,char * modules,char * addr,char * rpcp)535bdcaf822Sbasabi prt_cmd(char *path, long flags, char *modules, char *addr, char *rpcp)
536bdcaf822Sbasabi /* path: full path of command or pipe */
537bdcaf822Sbasabi /* flags: listener flags */
538bdcaf822Sbasabi /* PFLAG for pipe */
539bdcaf822Sbasabi /* CFLAG for command */
540bdcaf822Sbasabi /* DFLAG for dynamic addr */
541bdcaf822Sbasabi /* modules: STREAMS modules to push */
542bdcaf822Sbasabi /* addr: private address */
543bdcaf822Sbasabi /* rpcp: RPC prog and ver # */
5447c478bd9Sstevel@tonic-gate {
5457c478bd9Sstevel@tonic-gate struct stat sbuf;
5467c478bd9Sstevel@tonic-gate char mesgbuf[BUFSIZ];
5477c478bd9Sstevel@tonic-gate char *tmp;
5487c478bd9Sstevel@tonic-gate
5497c478bd9Sstevel@tonic-gate if (*path != '/') {
5507c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "Must specify full path name");
5517c478bd9Sstevel@tonic-gate return(NLS_CMD);
5527c478bd9Sstevel@tonic-gate }
5537c478bd9Sstevel@tonic-gate
554*2a8bcb4eSToomas Soome if ((tmp = strchr(path, ' ')) != NULL)
55567e41408SToomas Soome *tmp = '\0';
5567c478bd9Sstevel@tonic-gate
5577c478bd9Sstevel@tonic-gate if (stat(path, &sbuf) < 0) {
5587c478bd9Sstevel@tonic-gate if (errno != EFAULT) {
5597c478bd9Sstevel@tonic-gate sprintf(mesgbuf, "%s does not exist", path);
5607c478bd9Sstevel@tonic-gate nlsmesg(MM_WARNING, mesgbuf);
5617c478bd9Sstevel@tonic-gate }
5627c478bd9Sstevel@tonic-gate else
5637c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
5647c478bd9Sstevel@tonic-gate }
5657c478bd9Sstevel@tonic-gate
5667c478bd9Sstevel@tonic-gate if (tmp)
5677c478bd9Sstevel@tonic-gate *tmp = ' ';
5687c478bd9Sstevel@tonic-gate
5697c478bd9Sstevel@tonic-gate printf("%s:%s:%s:%s:%s\n", (addr ? addr : ""), (rpcp ? rpcp : ""),
5707c478bd9Sstevel@tonic-gate pflags(flags), (modules ? modules : ""), path);
5717c478bd9Sstevel@tonic-gate return(NLS_OK);
5727c478bd9Sstevel@tonic-gate }
5737c478bd9Sstevel@tonic-gate
5747c478bd9Sstevel@tonic-gate /*
5757c478bd9Sstevel@tonic-gate * old_addsvc: use pmadm to add a service code to the listener. this will
5767c478bd9Sstevel@tonic-gate * not allow specification of a private address -- use pmadm!
5777c478bd9Sstevel@tonic-gate */
5787c478bd9Sstevel@tonic-gate
579bdcaf822Sbasabi int
old_addsvc(char * svc,char * addr,char * cmd,char * com,char * module,char * id,char * flags,char * netspec)580bdcaf822Sbasabi old_addsvc(char *svc, char *addr, char *cmd, char *com, char *module,
581bdcaf822Sbasabi char *id, char *flags, char *netspec)
5827c478bd9Sstevel@tonic-gate {
5837c478bd9Sstevel@tonic-gate char buf[BUFSIZ];
5847c478bd9Sstevel@tonic-gate char mesgbuf[BUFSIZ];
5857c478bd9Sstevel@tonic-gate int rtn;
5867c478bd9Sstevel@tonic-gate struct stat sbuf;
5877c478bd9Sstevel@tonic-gate char *tmp;
5887c478bd9Sstevel@tonic-gate
5897c478bd9Sstevel@tonic-gate if (!svc || !cmd || !com || !netspec)
5907c478bd9Sstevel@tonic-gate usage(MISSINGARG);
5917c478bd9Sstevel@tonic-gate
5927c478bd9Sstevel@tonic-gate /* create "port-monitor specific" info in the same way as prt_cmd */
5937c478bd9Sstevel@tonic-gate
5947c478bd9Sstevel@tonic-gate if (*cmd != '/') {
5957c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "Must specify full path name");
5967c478bd9Sstevel@tonic-gate return(NLS_CMD);
5977c478bd9Sstevel@tonic-gate }
5987c478bd9Sstevel@tonic-gate
599*2a8bcb4eSToomas Soome if ((tmp = strchr(cmd, ' ')) != NULL)
60067e41408SToomas Soome *tmp = '\0';
6017c478bd9Sstevel@tonic-gate
6027c478bd9Sstevel@tonic-gate if (stat(cmd, &sbuf) < 0) {
6037c478bd9Sstevel@tonic-gate if (errno != EFAULT) {
6047c478bd9Sstevel@tonic-gate sprintf(mesgbuf, "%s does not exist", cmd);
6057c478bd9Sstevel@tonic-gate nlsmesg(MM_WARNING, mesgbuf);
6067c478bd9Sstevel@tonic-gate }
6077c478bd9Sstevel@tonic-gate else
6087c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
6097c478bd9Sstevel@tonic-gate }
6107c478bd9Sstevel@tonic-gate
6117c478bd9Sstevel@tonic-gate if (tmp)
6127c478bd9Sstevel@tonic-gate *tmp = ' ';
6137c478bd9Sstevel@tonic-gate
6147c478bd9Sstevel@tonic-gate if (addr)
6157c478bd9Sstevel@tonic-gate sprintf(mesgbuf, "'%s::c:%s:%s'", addr, module ? module : "" , cmd);
6167c478bd9Sstevel@tonic-gate else
6177c478bd9Sstevel@tonic-gate sprintf(mesgbuf, "'::c:%s:%s'", module ? module : "" , cmd);
6187c478bd9Sstevel@tonic-gate
6197c478bd9Sstevel@tonic-gate if (flags && *flags)
6207c478bd9Sstevel@tonic-gate sprintf(buf, PM_ADDSVCF, netspec, svc, (id)?id:DEFAULTID, flags, mesgbuf, VERSION, com ? com : "");
6217c478bd9Sstevel@tonic-gate else
6227c478bd9Sstevel@tonic-gate sprintf(buf, PM_ADDSVC, netspec, svc, (id)?id:DEFAULTID, mesgbuf, VERSION, com ? com : "");
6237c478bd9Sstevel@tonic-gate
6247c478bd9Sstevel@tonic-gate if ((rtn = system(buf)) < 0) {
6257c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
6267c478bd9Sstevel@tonic-gate }
6277c478bd9Sstevel@tonic-gate rtn = (rtn>>8) & 0xff; /* get child return value out of exit word */
6287c478bd9Sstevel@tonic-gate
6297c478bd9Sstevel@tonic-gate switch (rtn) {
6307c478bd9Sstevel@tonic-gate case 0:
6317c478bd9Sstevel@tonic-gate return(NLS_OK);
6327c478bd9Sstevel@tonic-gate break;
6337c478bd9Sstevel@tonic-gate case E_BADARGS:
6347c478bd9Sstevel@tonic-gate case E_SAFERR:
6357c478bd9Sstevel@tonic-gate case E_SYSERR:
6367c478bd9Sstevel@tonic-gate case E_NOEXIST:
6377c478bd9Sstevel@tonic-gate case E_PMRUN:
6387c478bd9Sstevel@tonic-gate case E_PMNOTRUN:
6397c478bd9Sstevel@tonic-gate case E_RECOVER:
6407c478bd9Sstevel@tonic-gate case E_SACNOTRUN:
6417c478bd9Sstevel@tonic-gate default:
6427c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
6437c478bd9Sstevel@tonic-gate break;
6447c478bd9Sstevel@tonic-gate case E_DUP:
6457c478bd9Sstevel@tonic-gate return(NLS_SERV);
6467c478bd9Sstevel@tonic-gate break;
6477c478bd9Sstevel@tonic-gate case E_NOPRIV:
6487c478bd9Sstevel@tonic-gate no_permission();
6497c478bd9Sstevel@tonic-gate break;
6507c478bd9Sstevel@tonic-gate }
651bdcaf822Sbasabi /* NOTREACHED */
6527c478bd9Sstevel@tonic-gate }
6537c478bd9Sstevel@tonic-gate
6547c478bd9Sstevel@tonic-gate /*
655*2a8bcb4eSToomas Soome * prt_nets: print the status of one network, or all nets if netspec
6567c478bd9Sstevel@tonic-gate * is NULL
6577c478bd9Sstevel@tonic-gate */
658bdcaf822Sbasabi int
prt_nets(char * netspec)659bdcaf822Sbasabi prt_nets(char *netspec)
6607c478bd9Sstevel@tonic-gate {
6617c478bd9Sstevel@tonic-gate char buf[BUFSIZ];
6627c478bd9Sstevel@tonic-gate FILE *fp;
6637c478bd9Sstevel@tonic-gate char *name;
6647c478bd9Sstevel@tonic-gate char *state;
6657c478bd9Sstevel@tonic-gate char *type;
6667c478bd9Sstevel@tonic-gate int found = FALSE;
6677c478bd9Sstevel@tonic-gate int rtn = NLS_OK;
6687c478bd9Sstevel@tonic-gate
669*2a8bcb4eSToomas Soome if (netspec == NULL)
6707c478bd9Sstevel@tonic-gate sprintf(buf, SAC_LSTY, LISTENTYPE);
671*2a8bcb4eSToomas Soome else
6727c478bd9Sstevel@tonic-gate sprintf(buf, SAC_LSPM, netspec);
6737c478bd9Sstevel@tonic-gate
674*2a8bcb4eSToomas Soome if ((fp = popen(buf, "r")) == NULL)
6757c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
6767c478bd9Sstevel@tonic-gate
6777c478bd9Sstevel@tonic-gate while (fgets(buf, BUFSIZ, fp) != NULL) {
6787c478bd9Sstevel@tonic-gate if ((name = nexttok(buf, ":")) == NULL)
6797c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
6807c478bd9Sstevel@tonic-gate if ((type = nexttok(NULL, ":")) == NULL)
6817c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
6827c478bd9Sstevel@tonic-gate
6837c478bd9Sstevel@tonic-gate if (strcmp(type, LISTENTYPE) != 0)
6847c478bd9Sstevel@tonic-gate continue; /* ignore other types of port monitors */
6857c478bd9Sstevel@tonic-gate
6867c478bd9Sstevel@tonic-gate found = TRUE;
6877c478bd9Sstevel@tonic-gate if (nexttok(NULL, ":") == NULL)
6887c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
6897c478bd9Sstevel@tonic-gate if (nexttok(NULL, ":") == NULL)
6907c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
6917c478bd9Sstevel@tonic-gate if ((state = nexttok(NULL, ":")) == NULL)
6927c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
69367e41408SToomas Soome if (strcmp(state, "ENABLED") == 0 ||
69467e41408SToomas Soome strcmp(state, "STARTING") == 0) {
6957c478bd9Sstevel@tonic-gate rtn = QZERO;
6967c478bd9Sstevel@tonic-gate if (!Quietflag)
6977c478bd9Sstevel@tonic-gate printf("%s\t%s\n", name, "ACTIVE");
6987c478bd9Sstevel@tonic-gate }
6997c478bd9Sstevel@tonic-gate else {
7007c478bd9Sstevel@tonic-gate rtn = QONE;
7017c478bd9Sstevel@tonic-gate if (!Quietflag)
7027c478bd9Sstevel@tonic-gate printf("%s\t%s\n", name, "INACTIVE");
7037c478bd9Sstevel@tonic-gate }
7047c478bd9Sstevel@tonic-gate }
7057c478bd9Sstevel@tonic-gate pclose(fp);
7067c478bd9Sstevel@tonic-gate
7077c478bd9Sstevel@tonic-gate if (netspec && !found) {
7087c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "Invalid network specification");
7097c478bd9Sstevel@tonic-gate return(NLS_BADPM);
7107c478bd9Sstevel@tonic-gate }
7117c478bd9Sstevel@tonic-gate
7127c478bd9Sstevel@tonic-gate if (netspec)
7137c478bd9Sstevel@tonic-gate return(rtn);
7147c478bd9Sstevel@tonic-gate else
7157c478bd9Sstevel@tonic-gate return(NLS_OK);
7167c478bd9Sstevel@tonic-gate
7177c478bd9Sstevel@tonic-gate }
7187c478bd9Sstevel@tonic-gate
7197c478bd9Sstevel@tonic-gate
7207c478bd9Sstevel@tonic-gate /*
721*2a8bcb4eSToomas Soome * print info about service on netspec, or all services on netspec
7227c478bd9Sstevel@tonic-gate * if svc is NULL
7237c478bd9Sstevel@tonic-gate */
7247c478bd9Sstevel@tonic-gate
725bdcaf822Sbasabi int
prt_svcs(char * svc,char * netspec)726bdcaf822Sbasabi prt_svcs(char *svc, char *netspec)
7277c478bd9Sstevel@tonic-gate {
7287c478bd9Sstevel@tonic-gate char buf[BUFSIZ];
7297c478bd9Sstevel@tonic-gate char mesg[BUFSIZ];
7307c478bd9Sstevel@tonic-gate FILE *fp;
7317c478bd9Sstevel@tonic-gate struct svcfields entry;
7327c478bd9Sstevel@tonic-gate int rtn;
7337c478bd9Sstevel@tonic-gate int found = FALSE;
7347c478bd9Sstevel@tonic-gate char *p;
7357c478bd9Sstevel@tonic-gate
736*2a8bcb4eSToomas Soome if (svc == NULL)
7377c478bd9Sstevel@tonic-gate sprintf(buf, PM_LSALL, netspec);
738*2a8bcb4eSToomas Soome else
7397c478bd9Sstevel@tonic-gate sprintf(buf, PM_LSONE, netspec, svc);
7407c478bd9Sstevel@tonic-gate
741*2a8bcb4eSToomas Soome if ((fp = popen(buf, "r")) == NULL)
7427c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
7437c478bd9Sstevel@tonic-gate
7447c478bd9Sstevel@tonic-gate while (fgets(buf, BUFSIZ, fp) != NULL) {
7457c478bd9Sstevel@tonic-gate if ((rtn = svc_format(buf, &entry)) != 0) {
7467c478bd9Sstevel@tonic-gate switch (rtn) {
7477c478bd9Sstevel@tonic-gate case NOTLISTEN:
7487c478bd9Sstevel@tonic-gate continue;
7497c478bd9Sstevel@tonic-gate break;
7507c478bd9Sstevel@tonic-gate case BADPMFMT:
7517c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
7527c478bd9Sstevel@tonic-gate break;
7537c478bd9Sstevel@tonic-gate case BADLISFMT:
7547c478bd9Sstevel@tonic-gate sprintf(mesg, "Entry for code \"%s\" has incorrect format", entry.svc_code);
7557c478bd9Sstevel@tonic-gate nlsmesg(MM_WARNING, mesg);
7567c478bd9Sstevel@tonic-gate continue;
7577c478bd9Sstevel@tonic-gate break;
7587c478bd9Sstevel@tonic-gate }
7597c478bd9Sstevel@tonic-gate }
7607c478bd9Sstevel@tonic-gate found = TRUE;
7617c478bd9Sstevel@tonic-gate
7627c478bd9Sstevel@tonic-gate if (!Quietflag) {
7637c478bd9Sstevel@tonic-gate printf("%s\t", entry.svc_code);
7647c478bd9Sstevel@tonic-gate if (*entry.addr)
7657c478bd9Sstevel@tonic-gate printf("%s\t", entry.addr);
7667c478bd9Sstevel@tonic-gate else if (strchr(entry.lflags, 'd'))
7677c478bd9Sstevel@tonic-gate printf("DYNAMIC\t");
7687c478bd9Sstevel@tonic-gate else
7697c478bd9Sstevel@tonic-gate printf("NOADDR\t");
7707c478bd9Sstevel@tonic-gate
7717c478bd9Sstevel@tonic-gate if (strchr(entry.flags, 'x') == NULL)
7727c478bd9Sstevel@tonic-gate printf("ENABLED \t");
7737c478bd9Sstevel@tonic-gate else
7747c478bd9Sstevel@tonic-gate printf("DISABLED\t");
7757c478bd9Sstevel@tonic-gate
7767c478bd9Sstevel@tonic-gate
7777c478bd9Sstevel@tonic-gate printf("%s\t%s\t%s\t%s\t# %s",
7787c478bd9Sstevel@tonic-gate (*entry.rpc)?entry.rpc:"NORPC", entry.id,
7797c478bd9Sstevel@tonic-gate (*entry.modules)?entry.modules:"NOMODULES",
7807c478bd9Sstevel@tonic-gate entry.command, (*entry.comment)?entry.comment:"");
7817c478bd9Sstevel@tonic-gate }
7827c478bd9Sstevel@tonic-gate else {
7837c478bd9Sstevel@tonic-gate if (strchr(entry.flags, 'x') == NULL)
7847c478bd9Sstevel@tonic-gate return(QZERO);
7857c478bd9Sstevel@tonic-gate else
7867c478bd9Sstevel@tonic-gate return(QONE);
7877c478bd9Sstevel@tonic-gate }
7887c478bd9Sstevel@tonic-gate }
7897c478bd9Sstevel@tonic-gate
7907c478bd9Sstevel@tonic-gate pclose(fp);
7917c478bd9Sstevel@tonic-gate
7927c478bd9Sstevel@tonic-gate if (rtn == NOTLISTEN) { /* check last return to see if error */
7937c478bd9Sstevel@tonic-gate sprintf(mesg, "Network specification \"%s\" is not of type %s", netspec, LISTENTYPE);
7947c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, mesg);
7957c478bd9Sstevel@tonic-gate return(NLS_BADPM);
7967c478bd9Sstevel@tonic-gate }
7977c478bd9Sstevel@tonic-gate if (svc && !found) {
7987c478bd9Sstevel@tonic-gate if (!Quietflag) {
7997c478bd9Sstevel@tonic-gate sprintf(mesg, "Service \"%s\" unknown", svc);
8007c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, mesg);
8017c478bd9Sstevel@tonic-gate }
8027c478bd9Sstevel@tonic-gate return(NLS_SERV);
8037c478bd9Sstevel@tonic-gate }
8047c478bd9Sstevel@tonic-gate
8057c478bd9Sstevel@tonic-gate return(NLS_OK);
8067c478bd9Sstevel@tonic-gate }
8077c478bd9Sstevel@tonic-gate
8087c478bd9Sstevel@tonic-gate /*
809*2a8bcb4eSToomas Soome * disable_svc: use pmadm to disable a service
8107c478bd9Sstevel@tonic-gate */
8117c478bd9Sstevel@tonic-gate
812bdcaf822Sbasabi int
disable_svc(char * svc,char * netspec)813bdcaf822Sbasabi disable_svc(char *svc, char *netspec)
8147c478bd9Sstevel@tonic-gate {
8157c478bd9Sstevel@tonic-gate char buf[BUFSIZ];
8167c478bd9Sstevel@tonic-gate int rtn;
8177c478bd9Sstevel@tonic-gate
8187c478bd9Sstevel@tonic-gate sprintf(buf, PM_DISABLE, netspec, svc);
8197c478bd9Sstevel@tonic-gate
8207c478bd9Sstevel@tonic-gate if ((rtn = system(buf)) < 0) {
8217c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
8227c478bd9Sstevel@tonic-gate }
8237c478bd9Sstevel@tonic-gate rtn = (rtn>>8) & 0xff; /* get child return value out of exit word */
8247c478bd9Sstevel@tonic-gate
8257c478bd9Sstevel@tonic-gate switch (rtn) {
8267c478bd9Sstevel@tonic-gate case 0:
8277c478bd9Sstevel@tonic-gate return(NLS_OK);
8287c478bd9Sstevel@tonic-gate break;
8297c478bd9Sstevel@tonic-gate case E_BADARGS:
8307c478bd9Sstevel@tonic-gate case E_SAFERR:
8317c478bd9Sstevel@tonic-gate case E_SYSERR:
8327c478bd9Sstevel@tonic-gate case E_PMRUN:
8337c478bd9Sstevel@tonic-gate case E_PMNOTRUN:
8347c478bd9Sstevel@tonic-gate case E_RECOVER:
8357c478bd9Sstevel@tonic-gate case E_SACNOTRUN:
8367c478bd9Sstevel@tonic-gate default:
8377c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
8387c478bd9Sstevel@tonic-gate break;
8397c478bd9Sstevel@tonic-gate case E_NOEXIST:
8407c478bd9Sstevel@tonic-gate case E_DUP:
8417c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "Non-existent service.");
8427c478bd9Sstevel@tonic-gate return(NLS_SERV);
8437c478bd9Sstevel@tonic-gate break;
8447c478bd9Sstevel@tonic-gate case E_NOPRIV:
8457c478bd9Sstevel@tonic-gate no_permission();
8467c478bd9Sstevel@tonic-gate break;
8477c478bd9Sstevel@tonic-gate }
848bdcaf822Sbasabi /* NOTREACHED */
8497c478bd9Sstevel@tonic-gate }
8507c478bd9Sstevel@tonic-gate
8517c478bd9Sstevel@tonic-gate
852bdcaf822Sbasabi int
enable_svc(char * svc,char * netspec)853bdcaf822Sbasabi enable_svc(char *svc, char *netspec)
8547c478bd9Sstevel@tonic-gate {
8557c478bd9Sstevel@tonic-gate char buf[BUFSIZ];
8567c478bd9Sstevel@tonic-gate int rtn;
8577c478bd9Sstevel@tonic-gate
8587c478bd9Sstevel@tonic-gate sprintf(buf, PM_ENABLE, netspec, svc);
8597c478bd9Sstevel@tonic-gate
8607c478bd9Sstevel@tonic-gate if ((rtn = system(buf)) < 0) {
8617c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
8627c478bd9Sstevel@tonic-gate }
8637c478bd9Sstevel@tonic-gate rtn = (rtn>>8) & 0xff; /* get child return value out of exit word */
8647c478bd9Sstevel@tonic-gate
8657c478bd9Sstevel@tonic-gate switch (rtn) {
8667c478bd9Sstevel@tonic-gate case 0:
8677c478bd9Sstevel@tonic-gate return(NLS_OK);
8687c478bd9Sstevel@tonic-gate break;
8697c478bd9Sstevel@tonic-gate case E_BADARGS:
8707c478bd9Sstevel@tonic-gate case E_SAFERR:
8717c478bd9Sstevel@tonic-gate case E_SYSERR:
8727c478bd9Sstevel@tonic-gate case E_PMRUN:
8737c478bd9Sstevel@tonic-gate case E_PMNOTRUN:
8747c478bd9Sstevel@tonic-gate case E_RECOVER:
8757c478bd9Sstevel@tonic-gate case E_SACNOTRUN:
8767c478bd9Sstevel@tonic-gate default:
8777c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
8787c478bd9Sstevel@tonic-gate break;
8797c478bd9Sstevel@tonic-gate case E_NOEXIST:
8807c478bd9Sstevel@tonic-gate case E_DUP:
8817c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "Non-existent service.");
8827c478bd9Sstevel@tonic-gate return(NLS_SERV);
8837c478bd9Sstevel@tonic-gate break;
8847c478bd9Sstevel@tonic-gate case E_NOPRIV:
8857c478bd9Sstevel@tonic-gate no_permission();
8867c478bd9Sstevel@tonic-gate break;
8877c478bd9Sstevel@tonic-gate }
888bdcaf822Sbasabi /* NOTREACHED */
8897c478bd9Sstevel@tonic-gate }
8907c478bd9Sstevel@tonic-gate
8917c478bd9Sstevel@tonic-gate
892bdcaf822Sbasabi int
remove_svc(char * svc,char * netspec,int printerrors)893bdcaf822Sbasabi remove_svc(char *svc, char *netspec, int printerrors)
8947c478bd9Sstevel@tonic-gate {
8957c478bd9Sstevel@tonic-gate char buf[BUFSIZ];
8967c478bd9Sstevel@tonic-gate int rtn;
8977c478bd9Sstevel@tonic-gate
8987c478bd9Sstevel@tonic-gate sprintf(buf, PM_REMSVC, netspec, svc);
8997c478bd9Sstevel@tonic-gate
9007c478bd9Sstevel@tonic-gate if ((rtn = system(buf)) < 0) {
9017c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
9027c478bd9Sstevel@tonic-gate }
9037c478bd9Sstevel@tonic-gate rtn = (rtn>>8) & 0xff; /* get child return value out of exit word */
9047c478bd9Sstevel@tonic-gate
9057c478bd9Sstevel@tonic-gate switch (rtn) {
9067c478bd9Sstevel@tonic-gate case 0:
9077c478bd9Sstevel@tonic-gate return(NLS_OK);
9087c478bd9Sstevel@tonic-gate break;
9097c478bd9Sstevel@tonic-gate case E_BADARGS:
9107c478bd9Sstevel@tonic-gate case E_SAFERR:
9117c478bd9Sstevel@tonic-gate case E_SYSERR:
9127c478bd9Sstevel@tonic-gate case E_PMRUN:
9137c478bd9Sstevel@tonic-gate case E_PMNOTRUN:
9147c478bd9Sstevel@tonic-gate case E_RECOVER:
9157c478bd9Sstevel@tonic-gate case E_SACNOTRUN:
9167c478bd9Sstevel@tonic-gate default:
9177c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
9187c478bd9Sstevel@tonic-gate break;
9197c478bd9Sstevel@tonic-gate case E_NOEXIST:
9207c478bd9Sstevel@tonic-gate case E_DUP:
9217c478bd9Sstevel@tonic-gate if (printerrors)
9227c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "Non-existent service.");
9237c478bd9Sstevel@tonic-gate return(NLS_SERV);
9247c478bd9Sstevel@tonic-gate break;
9257c478bd9Sstevel@tonic-gate case E_NOPRIV:
9267c478bd9Sstevel@tonic-gate no_permission();
9277c478bd9Sstevel@tonic-gate break;
9287c478bd9Sstevel@tonic-gate }
929bdcaf822Sbasabi /* NOTREACHED */
9307c478bd9Sstevel@tonic-gate }
9317c478bd9Sstevel@tonic-gate
9327c478bd9Sstevel@tonic-gate
933bdcaf822Sbasabi int
kill_listener(char * netspec)934bdcaf822Sbasabi kill_listener(char *netspec)
9357c478bd9Sstevel@tonic-gate {
9367c478bd9Sstevel@tonic-gate char buf[BUFSIZ];
9377c478bd9Sstevel@tonic-gate char mesg[BUFSIZ];
9387c478bd9Sstevel@tonic-gate int rtn;
9397c478bd9Sstevel@tonic-gate
9407c478bd9Sstevel@tonic-gate sprintf(buf, SAC_KILLPM, netspec);
9417c478bd9Sstevel@tonic-gate
9427c478bd9Sstevel@tonic-gate if ((rtn = system(buf)) < 0) {
9437c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
9447c478bd9Sstevel@tonic-gate }
9457c478bd9Sstevel@tonic-gate rtn = (rtn>>8) & 0xff; /* get child return value out of exit word */
9467c478bd9Sstevel@tonic-gate
9477c478bd9Sstevel@tonic-gate switch (rtn) {
9487c478bd9Sstevel@tonic-gate case 0:
9497c478bd9Sstevel@tonic-gate return(NLS_OK);
9507c478bd9Sstevel@tonic-gate break;
9517c478bd9Sstevel@tonic-gate case E_BADARGS:
9527c478bd9Sstevel@tonic-gate case E_DUP:
9537c478bd9Sstevel@tonic-gate case E_SAFERR:
9547c478bd9Sstevel@tonic-gate case E_SYSERR:
9557c478bd9Sstevel@tonic-gate case E_PMRUN:
9567c478bd9Sstevel@tonic-gate case E_RECOVER:
9577c478bd9Sstevel@tonic-gate case E_SACNOTRUN:
9587c478bd9Sstevel@tonic-gate default:
9597c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
9607c478bd9Sstevel@tonic-gate break;
9617c478bd9Sstevel@tonic-gate case E_PMNOTRUN:
9627c478bd9Sstevel@tonic-gate sprintf(mesg, "No listener active on network \"%s\"", netspec);
9637c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, mesg);
9647c478bd9Sstevel@tonic-gate return(NLS_FAILED);
9657c478bd9Sstevel@tonic-gate case E_NOEXIST:
9667c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "Non-existent port monitor.");
9677c478bd9Sstevel@tonic-gate return(NLS_SERV);
9687c478bd9Sstevel@tonic-gate break;
9697c478bd9Sstevel@tonic-gate case E_NOPRIV:
9707c478bd9Sstevel@tonic-gate no_permission();
9717c478bd9Sstevel@tonic-gate break;
9727c478bd9Sstevel@tonic-gate }
973bdcaf822Sbasabi /* NOTREACHED */
9747c478bd9Sstevel@tonic-gate }
9757c478bd9Sstevel@tonic-gate
9767c478bd9Sstevel@tonic-gate
9777c478bd9Sstevel@tonic-gate /*
9787c478bd9Sstevel@tonic-gate * add_pm: add a port monitor (initialize directories) using sacadm
9797c478bd9Sstevel@tonic-gate */
9807c478bd9Sstevel@tonic-gate
981bdcaf822Sbasabi int
add_pm(char * netspec)982bdcaf822Sbasabi add_pm(char *netspec)
9837c478bd9Sstevel@tonic-gate {
9847c478bd9Sstevel@tonic-gate char buf[BUFSIZ];
9857c478bd9Sstevel@tonic-gate char mesg[BUFSIZ];
9867c478bd9Sstevel@tonic-gate int rtn;
9877c478bd9Sstevel@tonic-gate
9887c478bd9Sstevel@tonic-gate sprintf(buf, SAC_ADDPM, netspec, LISTENTYPE, gencmdstr(netspec), VERSION);
9897c478bd9Sstevel@tonic-gate
9907c478bd9Sstevel@tonic-gate if ((rtn = system(buf)) < 0) {
9917c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
9927c478bd9Sstevel@tonic-gate }
9937c478bd9Sstevel@tonic-gate rtn = (rtn>>8) & 0xff; /* get child return value out of exit word */
9947c478bd9Sstevel@tonic-gate
9957c478bd9Sstevel@tonic-gate switch (rtn) {
9967c478bd9Sstevel@tonic-gate case 0:
9977c478bd9Sstevel@tonic-gate old_addsvc(NLPSSVCCODE, NULL, NLPSSRV, "NLPS server", "", "root", NULL, netspec);
9987c478bd9Sstevel@tonic-gate return(NLS_OK);
9997c478bd9Sstevel@tonic-gate break;
10007c478bd9Sstevel@tonic-gate case E_BADARGS:
10017c478bd9Sstevel@tonic-gate case E_SAFERR:
10027c478bd9Sstevel@tonic-gate case E_SYSERR:
10037c478bd9Sstevel@tonic-gate case E_RECOVER:
10047c478bd9Sstevel@tonic-gate case E_NOEXIST:
10057c478bd9Sstevel@tonic-gate case E_PMNOTRUN:
10067c478bd9Sstevel@tonic-gate case E_SACNOTRUN:
10077c478bd9Sstevel@tonic-gate default:
10087c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
10097c478bd9Sstevel@tonic-gate break;
10107c478bd9Sstevel@tonic-gate case E_DUP:
10117c478bd9Sstevel@tonic-gate case E_PMRUN:
10127c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "Listener already initialized");
10137c478bd9Sstevel@tonic-gate return(NLS_FAILED);
10147c478bd9Sstevel@tonic-gate break;
10157c478bd9Sstevel@tonic-gate case E_NOPRIV:
10167c478bd9Sstevel@tonic-gate no_permission();
10177c478bd9Sstevel@tonic-gate break;
10187c478bd9Sstevel@tonic-gate }
1019bdcaf822Sbasabi /* NOTREACHED */
10207c478bd9Sstevel@tonic-gate }
10217c478bd9Sstevel@tonic-gate
10227c478bd9Sstevel@tonic-gate
10237c478bd9Sstevel@tonic-gate /*
10247c478bd9Sstevel@tonic-gate * gencmdstr: generate the correct string to invoke the listener (starlan
10257c478bd9Sstevel@tonic-gate * requires special handling)
10267c478bd9Sstevel@tonic-gate */
10277c478bd9Sstevel@tonic-gate
10287c478bd9Sstevel@tonic-gate char *
gencmdstr(char * netspec)1029bdcaf822Sbasabi gencmdstr(char *netspec)
10307c478bd9Sstevel@tonic-gate {
10317c478bd9Sstevel@tonic-gate static char buf[BUFSIZ];
10327c478bd9Sstevel@tonic-gate
10337c478bd9Sstevel@tonic-gate (void) strcpy(buf, LISTENCMD);
10347c478bd9Sstevel@tonic-gate if (!strcmp(netspec, "starlan"))
10357c478bd9Sstevel@tonic-gate (void) strcat(buf, " -m slan");
10367c478bd9Sstevel@tonic-gate (void) strcat(buf, " ");
10377c478bd9Sstevel@tonic-gate (void) strcat(buf, netspec);
10387c478bd9Sstevel@tonic-gate return(buf);
10397c478bd9Sstevel@tonic-gate }
10407c478bd9Sstevel@tonic-gate
10417c478bd9Sstevel@tonic-gate
10427c478bd9Sstevel@tonic-gate /*
10437c478bd9Sstevel@tonic-gate * start_listener: start the listener
10447c478bd9Sstevel@tonic-gate */
10457c478bd9Sstevel@tonic-gate
1046bdcaf822Sbasabi int
start_listener(char * netspec)1047bdcaf822Sbasabi start_listener(char *netspec)
10487c478bd9Sstevel@tonic-gate {
10497c478bd9Sstevel@tonic-gate char buf[BUFSIZ];
10507c478bd9Sstevel@tonic-gate char scratch[BUFSIZ];
10517c478bd9Sstevel@tonic-gate int rtn;
10527c478bd9Sstevel@tonic-gate
10537c478bd9Sstevel@tonic-gate sprintf(buf, SAC_STARTPM, netspec);
10547c478bd9Sstevel@tonic-gate
1055*2a8bcb4eSToomas Soome if ((rtn = system(buf)) < 0)
10567c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
1057*2a8bcb4eSToomas Soome rtn = (rtn>>8) & 0xff;
10587c478bd9Sstevel@tonic-gate switch (rtn) {
10597c478bd9Sstevel@tonic-gate case 0:
10607c478bd9Sstevel@tonic-gate break;
10617c478bd9Sstevel@tonic-gate case E_BADARGS:
10627c478bd9Sstevel@tonic-gate case E_SAFERR:
10637c478bd9Sstevel@tonic-gate case E_SYSERR:
10647c478bd9Sstevel@tonic-gate case E_RECOVER:
10657c478bd9Sstevel@tonic-gate case E_PMNOTRUN:
10667c478bd9Sstevel@tonic-gate case E_SACNOTRUN:
10677c478bd9Sstevel@tonic-gate default:
10687c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
10697c478bd9Sstevel@tonic-gate break;
10707c478bd9Sstevel@tonic-gate case E_NOEXIST:
10717c478bd9Sstevel@tonic-gate case E_DUP:
10727c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "Non-existent port monitor.");
10737c478bd9Sstevel@tonic-gate return(NLS_BADPM);
10747c478bd9Sstevel@tonic-gate break;
10757c478bd9Sstevel@tonic-gate case E_PMRUN:
10767c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "Listener already running");
10777c478bd9Sstevel@tonic-gate return(NLS_FAILED);
10787c478bd9Sstevel@tonic-gate case E_NOPRIV:
10797c478bd9Sstevel@tonic-gate no_permission();
10807c478bd9Sstevel@tonic-gate break;
10817c478bd9Sstevel@tonic-gate }
10827c478bd9Sstevel@tonic-gate
10837c478bd9Sstevel@tonic-gate sprintf(buf, SAC_ENABLPM, netspec);
10847c478bd9Sstevel@tonic-gate
10857c478bd9Sstevel@tonic-gate if ((rtn = system(buf)) < 0) {
10867c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
10877c478bd9Sstevel@tonic-gate }
1088*2a8bcb4eSToomas Soome rtn = (rtn>>8) & 0xff;
10897c478bd9Sstevel@tonic-gate switch (rtn) {
10907c478bd9Sstevel@tonic-gate case 0:
10917c478bd9Sstevel@tonic-gate return(NLS_OK);
10927c478bd9Sstevel@tonic-gate break;
10937c478bd9Sstevel@tonic-gate case E_BADARGS:
10947c478bd9Sstevel@tonic-gate case E_SAFERR:
10957c478bd9Sstevel@tonic-gate case E_SYSERR:
10967c478bd9Sstevel@tonic-gate case E_RECOVER:
10977c478bd9Sstevel@tonic-gate case E_SACNOTRUN:
10987c478bd9Sstevel@tonic-gate default:
10997c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
11007c478bd9Sstevel@tonic-gate break;
11017c478bd9Sstevel@tonic-gate case E_NOEXIST:
11027c478bd9Sstevel@tonic-gate case E_DUP:
11037c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "Non-existent port monitor.");
11047c478bd9Sstevel@tonic-gate return(NLS_BADPM);
11057c478bd9Sstevel@tonic-gate break;
11067c478bd9Sstevel@tonic-gate case E_PMRUN:
11077c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "Listener already running");
11087c478bd9Sstevel@tonic-gate return(NLS_FAILED);
11097c478bd9Sstevel@tonic-gate case E_PMNOTRUN:
11107c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "Listener start failed");
11117c478bd9Sstevel@tonic-gate return(NLS_FAILED);
11127c478bd9Sstevel@tonic-gate case E_NOPRIV:
11137c478bd9Sstevel@tonic-gate no_permission();
11147c478bd9Sstevel@tonic-gate break;
11157c478bd9Sstevel@tonic-gate }
1116bdcaf822Sbasabi /* NOTREACHED */
11177c478bd9Sstevel@tonic-gate }
11187c478bd9Sstevel@tonic-gate
11197c478bd9Sstevel@tonic-gate
11207c478bd9Sstevel@tonic-gate /*
11217c478bd9Sstevel@tonic-gate * setup_addr: setup the -l and -t addresses.
11227c478bd9Sstevel@tonic-gate */
11237c478bd9Sstevel@tonic-gate
1124bdcaf822Sbasabi int
setup_addr(char * laddr,char * taddr,char * netspec)1125bdcaf822Sbasabi setup_addr(char *laddr, char *taddr, char *netspec)
11267c478bd9Sstevel@tonic-gate {
11277c478bd9Sstevel@tonic-gate char buf[BUFSIZ];
11287c478bd9Sstevel@tonic-gate char mesg[BUFSIZ];
11297c478bd9Sstevel@tonic-gate char *p;
11307c478bd9Sstevel@tonic-gate int rtn;
11317c478bd9Sstevel@tonic-gate int qlisten = FALSE;
11327c478bd9Sstevel@tonic-gate int qtty = FALSE;
11337c478bd9Sstevel@tonic-gate FILE *fp;
11347c478bd9Sstevel@tonic-gate struct svcfields entry;
11357c478bd9Sstevel@tonic-gate
1136*2a8bcb4eSToomas Soome if (laddr && *laddr == '-')
11377c478bd9Sstevel@tonic-gate qlisten = TRUE;
11387c478bd9Sstevel@tonic-gate
11397c478bd9Sstevel@tonic-gate if (taddr && *taddr == '-')
11407c478bd9Sstevel@tonic-gate qtty = TRUE;
11417c478bd9Sstevel@tonic-gate
11427c478bd9Sstevel@tonic-gate if (laddr) {
11437c478bd9Sstevel@tonic-gate sprintf(buf, PM_LSONE, netspec, NLPSSVCCODE);
11447c478bd9Sstevel@tonic-gate
11457c478bd9Sstevel@tonic-gate if ((fp = popen(buf, "r")) == NULL) {
11467c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
11477c478bd9Sstevel@tonic-gate }
11487c478bd9Sstevel@tonic-gate
11497c478bd9Sstevel@tonic-gate if (fgets(buf, BUFSIZ, fp) != NULL) {
11507c478bd9Sstevel@tonic-gate if ((rtn = svc_format(buf, &entry)) != 0) {
11517c478bd9Sstevel@tonic-gate switch (rtn) {
1152*2a8bcb4eSToomas Soome case NOTLISTEN:
11537c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "Incorrect port monitor type. Must be of type listen");
11547c478bd9Sstevel@tonic-gate return(NLS_FAILED);
11557c478bd9Sstevel@tonic-gate break;
11567c478bd9Sstevel@tonic-gate case BADPMFMT:
11577c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
11587c478bd9Sstevel@tonic-gate break;
11597c478bd9Sstevel@tonic-gate case BADLISFMT:
11607c478bd9Sstevel@tonic-gate sprintf(mesg, "Entry for code \"%s\" has incorrect format", entry.svc_code);
11617c478bd9Sstevel@tonic-gate nlsmesg(MM_WARNING, mesg);
11627c478bd9Sstevel@tonic-gate break;
11637c478bd9Sstevel@tonic-gate }
11647c478bd9Sstevel@tonic-gate }
11657c478bd9Sstevel@tonic-gate else {
11667c478bd9Sstevel@tonic-gate if (qlisten)
11677c478bd9Sstevel@tonic-gate printf("%s\n", entry.addr);
11687c478bd9Sstevel@tonic-gate else {
11697c478bd9Sstevel@tonic-gate if (geteuid() != ROOT)
11707c478bd9Sstevel@tonic-gate no_permission();
11717c478bd9Sstevel@tonic-gate /* add address */
11727c478bd9Sstevel@tonic-gate remove_svc(NLPSSVCCODE, netspec, FALSE);
11737c478bd9Sstevel@tonic-gate p = strchr(entry.comment, '\n');
11747c478bd9Sstevel@tonic-gate if (p)
11757c478bd9Sstevel@tonic-gate *p = '\0';
11767c478bd9Sstevel@tonic-gate old_addsvc(NLPSSVCCODE, laddr, entry.command, entry.comment, entry.modules, entry.id, entry.flags, netspec);
11777c478bd9Sstevel@tonic-gate }
11787c478bd9Sstevel@tonic-gate }
11797c478bd9Sstevel@tonic-gate pclose(fp);
11807c478bd9Sstevel@tonic-gate }
11817c478bd9Sstevel@tonic-gate else if (!qlisten)
11827c478bd9Sstevel@tonic-gate nlsmesg(MM_WARNING, "NLPS service not defined");
11837c478bd9Sstevel@tonic-gate }
11847c478bd9Sstevel@tonic-gate if (taddr) {
11857c478bd9Sstevel@tonic-gate sprintf(buf, PM_LSONE, netspec, TTYSVCCODE);
11867c478bd9Sstevel@tonic-gate
11877c478bd9Sstevel@tonic-gate if ((fp = popen(buf, "r")) == NULL) {
11887c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
11897c478bd9Sstevel@tonic-gate }
11907c478bd9Sstevel@tonic-gate
11917c478bd9Sstevel@tonic-gate if (fgets(buf, BUFSIZ, fp) != NULL) {
11927c478bd9Sstevel@tonic-gate if ((rtn = svc_format(buf, &entry)) != 0) {
11937c478bd9Sstevel@tonic-gate switch (rtn) {
1194*2a8bcb4eSToomas Soome case NOTLISTEN:
11957c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "Incorrect port monitor type. Must be of type listen");
11967c478bd9Sstevel@tonic-gate return(NLS_FAILED);
11977c478bd9Sstevel@tonic-gate break;
11987c478bd9Sstevel@tonic-gate case BADPMFMT:
11997c478bd9Sstevel@tonic-gate return(NLS_SYSERR);
12007c478bd9Sstevel@tonic-gate break;
12017c478bd9Sstevel@tonic-gate case BADLISFMT:
12027c478bd9Sstevel@tonic-gate sprintf(mesg, "Entry for code \"%s\" has incorrect format", entry.svc_code);
12037c478bd9Sstevel@tonic-gate nlsmesg(MM_WARNING, mesg);
12047c478bd9Sstevel@tonic-gate break;
12057c478bd9Sstevel@tonic-gate }
12067c478bd9Sstevel@tonic-gate }
12077c478bd9Sstevel@tonic-gate else {
12087c478bd9Sstevel@tonic-gate if (qtty)
12097c478bd9Sstevel@tonic-gate printf("%s\n", entry.addr);
12107c478bd9Sstevel@tonic-gate else {
12117c478bd9Sstevel@tonic-gate if (geteuid() != ROOT)
12127c478bd9Sstevel@tonic-gate no_permission();
12137c478bd9Sstevel@tonic-gate /* add address */
12147c478bd9Sstevel@tonic-gate remove_svc(TTYSVCCODE, netspec, FALSE);
12157c478bd9Sstevel@tonic-gate p = strchr(entry.comment, '\n');
12167c478bd9Sstevel@tonic-gate if (p)
12177c478bd9Sstevel@tonic-gate *p = '\0';
12187c478bd9Sstevel@tonic-gate old_addsvc(TTYSVCCODE, taddr, entry.command, entry.comment, entry.modules, entry.id, entry.flags, netspec);
12197c478bd9Sstevel@tonic-gate }
12207c478bd9Sstevel@tonic-gate }
12217c478bd9Sstevel@tonic-gate pclose(fp);
12227c478bd9Sstevel@tonic-gate }
12237c478bd9Sstevel@tonic-gate else if (!qtty)
12247c478bd9Sstevel@tonic-gate nlsmesg(MM_WARNING, "remote login service not defined");
12257c478bd9Sstevel@tonic-gate }
12267c478bd9Sstevel@tonic-gate return(NLS_OK);
12277c478bd9Sstevel@tonic-gate }
12287c478bd9Sstevel@tonic-gate
12297c478bd9Sstevel@tonic-gate
12307c478bd9Sstevel@tonic-gate /*
12317c478bd9Sstevel@tonic-gate * svc_format: scan a line of output from pmadm to separate it into fields.
12327c478bd9Sstevel@tonic-gate * returns BADPMFMT for missing fields or incorrect syntax.
12337c478bd9Sstevel@tonic-gate * NOTLISTEN is the port monitor type is not listen.
12347c478bd9Sstevel@tonic-gate * BADLISFMT if the listener-specific data is incorrect.
12357c478bd9Sstevel@tonic-gate * NLS_OK if everything checked out and data is broken
12367c478bd9Sstevel@tonic-gate * into the structure.
12377c478bd9Sstevel@tonic-gate */
12387c478bd9Sstevel@tonic-gate
1239bdcaf822Sbasabi int
svc_format(char * buf,struct svcfields * entry)1240bdcaf822Sbasabi svc_format(char *buf, struct svcfields *entry)
12417c478bd9Sstevel@tonic-gate {
12427c478bd9Sstevel@tonic-gate char *ptr; /* temporary pointer into buffer */
12437c478bd9Sstevel@tonic-gate char *tmp; /* temporary pointer into buffer */
12447c478bd9Sstevel@tonic-gate
12457c478bd9Sstevel@tonic-gate entry->pmtag = buf;
12467c478bd9Sstevel@tonic-gate if ((ptr = strchr(buf, ':')) == NULL)
12477c478bd9Sstevel@tonic-gate return(BADPMFMT);
124867e41408SToomas Soome *ptr++ = '\0';
12497c478bd9Sstevel@tonic-gate entry->pmtype = ptr;
12507c478bd9Sstevel@tonic-gate if ((ptr = strchr(entry->pmtype, ':')) == NULL)
12517c478bd9Sstevel@tonic-gate return(BADPMFMT);
125267e41408SToomas Soome *ptr++ = '\0';
12537c478bd9Sstevel@tonic-gate entry->svc_code = ptr;
12547c478bd9Sstevel@tonic-gate
12557c478bd9Sstevel@tonic-gate if (strcmp(entry->pmtype, LISTENTYPE) != 0)
12567c478bd9Sstevel@tonic-gate return(NOTLISTEN);
12577c478bd9Sstevel@tonic-gate
12587c478bd9Sstevel@tonic-gate if ((ptr = strchr(entry->svc_code, ':')) == NULL)
12597c478bd9Sstevel@tonic-gate return(BADPMFMT);
126067e41408SToomas Soome *ptr++ = '\0';
12617c478bd9Sstevel@tonic-gate entry->flags = ptr;
12627c478bd9Sstevel@tonic-gate if ((ptr = strchr(entry->flags, ':')) == NULL)
12637c478bd9Sstevel@tonic-gate return(BADPMFMT);
126467e41408SToomas Soome *ptr++ = '\0';
12657c478bd9Sstevel@tonic-gate entry->id = ptr;
12667c478bd9Sstevel@tonic-gate if ((ptr = strchr(entry->id, ':')) == NULL)
12677c478bd9Sstevel@tonic-gate return(BADPMFMT);
126867e41408SToomas Soome *ptr++ = '\0';
12697c478bd9Sstevel@tonic-gate entry->res1 = ptr;
12707c478bd9Sstevel@tonic-gate if ((ptr = strchr(entry->res1, ':')) == NULL)
12717c478bd9Sstevel@tonic-gate return(BADPMFMT);
127267e41408SToomas Soome *ptr++ = '\0';
12737c478bd9Sstevel@tonic-gate entry->res2 = ptr;
12747c478bd9Sstevel@tonic-gate if ((ptr = strchr(entry->res2, ':')) == NULL)
12757c478bd9Sstevel@tonic-gate return(BADPMFMT);
127667e41408SToomas Soome *ptr++ = '\0';
12777c478bd9Sstevel@tonic-gate entry->res3 = ptr;
12787c478bd9Sstevel@tonic-gate if ((ptr = strchr(entry->res3, ':')) == NULL)
12797c478bd9Sstevel@tonic-gate return(BADPMFMT);
128067e41408SToomas Soome *ptr++ = '\0';
12817c478bd9Sstevel@tonic-gate entry->addr = ptr;
12827c478bd9Sstevel@tonic-gate if ((ptr = strchr(entry->addr, ':')) == NULL)
12837c478bd9Sstevel@tonic-gate return(BADLISFMT);
128467e41408SToomas Soome *ptr++ = '\0';
12857c478bd9Sstevel@tonic-gate entry->rpc = ptr;
12867c478bd9Sstevel@tonic-gate if ((ptr = strchr(entry->rpc, ':')) == NULL)
12877c478bd9Sstevel@tonic-gate return(BADLISFMT);
128867e41408SToomas Soome *ptr++ = '\0';
12897c478bd9Sstevel@tonic-gate if (*entry->rpc) {
12907c478bd9Sstevel@tonic-gate if ((tmp = strchr(entry->rpc, ',')) == NULL)
12917c478bd9Sstevel@tonic-gate return(BADLISFMT);
12927c478bd9Sstevel@tonic-gate *tmp = ':';
12937c478bd9Sstevel@tonic-gate }
12947c478bd9Sstevel@tonic-gate entry->lflags = ptr;
12957c478bd9Sstevel@tonic-gate if ((ptr = strchr(entry->lflags, ':')) == NULL)
12967c478bd9Sstevel@tonic-gate return(BADLISFMT);
129767e41408SToomas Soome *ptr++ = '\0';
12987c478bd9Sstevel@tonic-gate entry->modules = ptr;
12997c478bd9Sstevel@tonic-gate if ((ptr = strchr(entry->modules, ':')) == NULL)
13007c478bd9Sstevel@tonic-gate return(BADLISFMT);
130167e41408SToomas Soome *ptr++ = '\0';
13027c478bd9Sstevel@tonic-gate entry->command = ptr;
13037c478bd9Sstevel@tonic-gate if ((ptr = strchr(entry->command, '#')) == NULL)
13047c478bd9Sstevel@tonic-gate return(BADLISFMT);
130567e41408SToomas Soome *ptr++ = '\0';
13067c478bd9Sstevel@tonic-gate entry->comment = ptr;
13077c478bd9Sstevel@tonic-gate return(NLS_OK);
13087c478bd9Sstevel@tonic-gate }
13097c478bd9Sstevel@tonic-gate
13107c478bd9Sstevel@tonic-gate
13117c478bd9Sstevel@tonic-gate /*
13127c478bd9Sstevel@tonic-gate * nexttok - return next token, essentially a strtok, but it can
13137c478bd9Sstevel@tonic-gate * deal with null fields and strtok can not
13147c478bd9Sstevel@tonic-gate *
13157c478bd9Sstevel@tonic-gate * args: str - the string to be examined, NULL if we should
13167c478bd9Sstevel@tonic-gate * examine the remembered string
13177c478bd9Sstevel@tonic-gate * delim - the list of valid delimiters
13187c478bd9Sstevel@tonic-gate */
13197c478bd9Sstevel@tonic-gate
13207c478bd9Sstevel@tonic-gate
13217c478bd9Sstevel@tonic-gate char *
nexttok(char * str,char * delim)1322bdcaf822Sbasabi nexttok(char *str, char *delim)
13237c478bd9Sstevel@tonic-gate {
13247c478bd9Sstevel@tonic-gate static char *savep; /* the remembered string */
13257c478bd9Sstevel@tonic-gate register char *p; /* pointer to start of token */
13267c478bd9Sstevel@tonic-gate register char *ep; /* pointer to end of token */
13277c478bd9Sstevel@tonic-gate
13287c478bd9Sstevel@tonic-gate p = (str == NULL) ? savep : str ;
13297c478bd9Sstevel@tonic-gate if (p == NULL)
13307c478bd9Sstevel@tonic-gate return(NULL);
13317c478bd9Sstevel@tonic-gate ep = strpbrk(p, delim);
13327c478bd9Sstevel@tonic-gate if (ep == NULL) {
13337c478bd9Sstevel@tonic-gate savep = NULL;
13347c478bd9Sstevel@tonic-gate return(p);
13357c478bd9Sstevel@tonic-gate }
13367c478bd9Sstevel@tonic-gate savep = ep + 1;
13377c478bd9Sstevel@tonic-gate *ep = '\0';
13387c478bd9Sstevel@tonic-gate return(p);
13397c478bd9Sstevel@tonic-gate }
13407c478bd9Sstevel@tonic-gate
13417c478bd9Sstevel@tonic-gate
13427c478bd9Sstevel@tonic-gate /*
13437c478bd9Sstevel@tonic-gate * pflags - put flags into intelligible form for output
13447c478bd9Sstevel@tonic-gate *
13457c478bd9Sstevel@tonic-gate * args: flags - binary representation of flags
13467c478bd9Sstevel@tonic-gate */
13477c478bd9Sstevel@tonic-gate
13487c478bd9Sstevel@tonic-gate char *
pflags(long flags)1349bdcaf822Sbasabi pflags(long flags)
13507c478bd9Sstevel@tonic-gate {
13517c478bd9Sstevel@tonic-gate register int i; /* scratch counter */
13527c478bd9Sstevel@tonic-gate static char buf[BUFSIZ]; /* formatted flags */
13537c478bd9Sstevel@tonic-gate
13547c478bd9Sstevel@tonic-gate if (flags == 0)
13557c478bd9Sstevel@tonic-gate return("");
13567c478bd9Sstevel@tonic-gate i = 0;
13577c478bd9Sstevel@tonic-gate if (flags & CFLAG) {
13587c478bd9Sstevel@tonic-gate buf[i++] = 'c';
13597c478bd9Sstevel@tonic-gate flags &= ~CFLAG;
13607c478bd9Sstevel@tonic-gate }
13617c478bd9Sstevel@tonic-gate if (flags & DFLAG) {
13627c478bd9Sstevel@tonic-gate buf[i++] = 'd';
13637c478bd9Sstevel@tonic-gate flags &= ~DFLAG;
13647c478bd9Sstevel@tonic-gate }
13657c478bd9Sstevel@tonic-gate if (flags & PFLAG) {
13667c478bd9Sstevel@tonic-gate buf[i++] = 'p';
13677c478bd9Sstevel@tonic-gate flags &= ~PFLAG;
13687c478bd9Sstevel@tonic-gate }
13697c478bd9Sstevel@tonic-gate if (flags) {
13707c478bd9Sstevel@tonic-gate nlsmesg(MM_ERROR, "Internal error in pflags");
13717c478bd9Sstevel@tonic-gate exit(NLS_FAILED);
13727c478bd9Sstevel@tonic-gate }
13737c478bd9Sstevel@tonic-gate buf[i] = '\0';
13747c478bd9Sstevel@tonic-gate return(buf);
13757c478bd9Sstevel@tonic-gate }
1376