xref: /onnv-gate/usr/src/lib/krb5/ss/list_rqs.c (revision 2881:ea6360e7e1c5)
10Sstevel@tonic-gate /*
2*2881Smp153739  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
3*2881Smp153739  * Use is subject to license terms.
40Sstevel@tonic-gate  */
50Sstevel@tonic-gate 
60Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
70Sstevel@tonic-gate 
80Sstevel@tonic-gate /*
90Sstevel@tonic-gate  * Copyright 1987, 1988 by MIT Student Information Processing Board
100Sstevel@tonic-gate  *
110Sstevel@tonic-gate  * For copyright information, see copyright.h.
120Sstevel@tonic-gate  */
130Sstevel@tonic-gate #include "copyright.h"
140Sstevel@tonic-gate #include "ss_internal.h"
150Sstevel@tonic-gate #include <libintl.h>
160Sstevel@tonic-gate #include <signal.h>
170Sstevel@tonic-gate #include <setjmp.h>
180Sstevel@tonic-gate #include <sys/wait.h>
190Sstevel@tonic-gate 
200Sstevel@tonic-gate #ifdef lint     /* "lint returns a value which is sometimes ignored" */
210Sstevel@tonic-gate #define DONT_USE(x)     x=x;
220Sstevel@tonic-gate #else /* !lint */
230Sstevel@tonic-gate #define DONT_USE(x)     ;
240Sstevel@tonic-gate #endif /* lint */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate extern int ss_pager_create();
270Sstevel@tonic-gate 
280Sstevel@tonic-gate static char const twentyfive_spaces[26] =
290Sstevel@tonic-gate     "                         ";
300Sstevel@tonic-gate static char const NL[2] = "\n";
310Sstevel@tonic-gate 
320Sstevel@tonic-gate void
ss_list_requests(argc,argv,sci_idx,info_ptr)330Sstevel@tonic-gate ss_list_requests(argc, argv, sci_idx, info_ptr)
340Sstevel@tonic-gate     int argc;
35*2881Smp153739     const char * const *argv;
360Sstevel@tonic-gate     int sci_idx;
37*2881Smp153739 #ifdef __STDC__
38*2881Smp153739     void *info_ptr;
39*2881Smp153739 #else
40*2881Smp153739     char *info_ptr;
41*2881Smp153739 #endif
420Sstevel@tonic-gate {
430Sstevel@tonic-gate     register ss_request_entry *entry;
440Sstevel@tonic-gate     register char const * const *name;
450Sstevel@tonic-gate     register int spacing;
460Sstevel@tonic-gate     register ss_request_table **table;
470Sstevel@tonic-gate 
480Sstevel@tonic-gate     char buffer[BUFSIZ];
490Sstevel@tonic-gate     FILE *output;
500Sstevel@tonic-gate     int fd;
510Sstevel@tonic-gate #ifdef POSIX_SIGNALS
520Sstevel@tonic-gate     struct sigaction nsig, osig;
530Sstevel@tonic-gate     sigset_t nmask, omask;
540Sstevel@tonic-gate #else
550Sstevel@tonic-gate     int mask;
560Sstevel@tonic-gate     RETSIGTYPE (*func)();
570Sstevel@tonic-gate #endif
580Sstevel@tonic-gate #ifndef WAIT_USES_INT
590Sstevel@tonic-gate     union wait waitb;
600Sstevel@tonic-gate #else
610Sstevel@tonic-gate     int waitb;
620Sstevel@tonic-gate #endif
630Sstevel@tonic-gate 
640Sstevel@tonic-gate     DONT_USE(argc);
650Sstevel@tonic-gate     DONT_USE(argv);
660Sstevel@tonic-gate 
670Sstevel@tonic-gate #ifdef POSIX_SIGNALS
680Sstevel@tonic-gate     sigemptyset(&nmask);
690Sstevel@tonic-gate     sigaddset(&nmask, SIGINT);
700Sstevel@tonic-gate     sigprocmask(SIG_BLOCK, &nmask, &omask);
710Sstevel@tonic-gate 
720Sstevel@tonic-gate     nsig.sa_handler = SIG_IGN;
730Sstevel@tonic-gate     sigemptyset(&nsig.sa_mask);
740Sstevel@tonic-gate     nsig.sa_flags = 0;
750Sstevel@tonic-gate     sigaction(SIGINT, &nsig, &osig);
760Sstevel@tonic-gate #else
770Sstevel@tonic-gate     mask = sigblock(sigmask(SIGINT));
780Sstevel@tonic-gate     func = signal(SIGINT, SIG_IGN);
790Sstevel@tonic-gate #endif
800Sstevel@tonic-gate 
810Sstevel@tonic-gate     fd = ss_pager_create();
820Sstevel@tonic-gate     output = fdopen(fd, "w");
830Sstevel@tonic-gate 
840Sstevel@tonic-gate #ifdef POSIX_SIGNALS
850Sstevel@tonic-gate     sigprocmask(SIG_SETMASK, &omask, (sigset_t *)0);
860Sstevel@tonic-gate #else
870Sstevel@tonic-gate     sigsetmask(mask);
880Sstevel@tonic-gate #endif
890Sstevel@tonic-gate 
900Sstevel@tonic-gate     fprintf (output, dgettext(TEXT_DOMAIN, "Available %s requests:\n\n"),
910Sstevel@tonic-gate 	     ss_info (sci_idx) -> subsystem_name);
920Sstevel@tonic-gate 
930Sstevel@tonic-gate     for (table = ss_info(sci_idx)->rqt_tables; *table; table++) {
940Sstevel@tonic-gate         entry = (*table)->requests;
950Sstevel@tonic-gate         for (; entry->command_names; entry++) {
960Sstevel@tonic-gate             spacing = -2;
970Sstevel@tonic-gate             buffer[0] = '\0';
980Sstevel@tonic-gate             if (entry->flags & SS_OPT_DONT_LIST)
990Sstevel@tonic-gate                 continue;
100*2881Smp153739             buffer[sizeof(buffer) - 1] = '\0';
1010Sstevel@tonic-gate             for (name = entry->command_names; *name; name++) {
1020Sstevel@tonic-gate                 register int len = strlen(*name);
103*2881Smp153739                 strncat(buffer, *name, sizeof(buffer) - 1 - strlen(buffer));
1040Sstevel@tonic-gate                 spacing += len + 2;
1050Sstevel@tonic-gate                 if (name[1]) {
106*2881Smp153739                     strncat(buffer, ", ", sizeof(buffer) - 1 - strlen(buffer));
1070Sstevel@tonic-gate                 }
1080Sstevel@tonic-gate             }
1090Sstevel@tonic-gate             if (spacing > 23) {
110*2881Smp153739                 strncat(buffer, NL, sizeof(buffer) - 1 - strlen(buffer));
1110Sstevel@tonic-gate                 fputs(buffer, output);
1120Sstevel@tonic-gate                 spacing = 0;
1130Sstevel@tonic-gate                 buffer[0] = '\0';
1140Sstevel@tonic-gate             }
115*2881Smp153739             strncat(buffer, twentyfive_spaces, strlen(twentyfive_spaces) - spacing);
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate             /*
1180Sstevel@tonic-gate              * Due to libss not knowing what TEXT_DOMAIN
1190Sstevel@tonic-gate              * the calling application is using for its info_string
1200Sstevel@tonic-gate              * messages, we know require the callers (ktutil,kadmin)
1210Sstevel@tonic-gate              * to L10N the messages before calling libss.
1220Sstevel@tonic-gate              */
123*2881Smp153739             strncat(buffer, entry->info_string, sizeof(buffer) -1 - strlen(buffer));
124*2881Smp153739             strncat(buffer, NL,  sizeof(buffer) - 1 - strlen(buffer));
1250Sstevel@tonic-gate             fputs(buffer, output);
1260Sstevel@tonic-gate         }
1270Sstevel@tonic-gate     }
1280Sstevel@tonic-gate     fclose(output);
1290Sstevel@tonic-gate #ifndef NO_FORK
1300Sstevel@tonic-gate     wait(&waitb);
1310Sstevel@tonic-gate #endif
1320Sstevel@tonic-gate #ifdef POSIX_SIGNALS
1330Sstevel@tonic-gate     sigaction(SIGINT, &osig, (struct sigaction *)0);
1340Sstevel@tonic-gate #else
1350Sstevel@tonic-gate     (void) signal(SIGINT, func);
1360Sstevel@tonic-gate #endif
1370Sstevel@tonic-gate }
138