xref: /illumos-gate/usr/src/lib/krb5/ss/list_rqs.c (revision 1da57d55)
17c478bd9Sstevel@tonic-gate /*
256a424ccSmp  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
356a424ccSmp  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
57c478bd9Sstevel@tonic-gate 
67c478bd9Sstevel@tonic-gate /*
77c478bd9Sstevel@tonic-gate  * Copyright 1987, 1988 by MIT Student Information Processing Board
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * For copyright information, see copyright.h.
107c478bd9Sstevel@tonic-gate  */
117c478bd9Sstevel@tonic-gate #include "copyright.h"
127c478bd9Sstevel@tonic-gate #include "ss_internal.h"
137c478bd9Sstevel@tonic-gate #include <libintl.h>
147c478bd9Sstevel@tonic-gate #include <signal.h>
157c478bd9Sstevel@tonic-gate #include <setjmp.h>
167c478bd9Sstevel@tonic-gate #include <sys/wait.h>
177c478bd9Sstevel@tonic-gate 
187c478bd9Sstevel@tonic-gate #ifdef lint     /* "lint returns a value which is sometimes ignored" */
197c478bd9Sstevel@tonic-gate #define DONT_USE(x)     x=x;
207c478bd9Sstevel@tonic-gate #else /* !lint */
217c478bd9Sstevel@tonic-gate #define DONT_USE(x)     ;
227c478bd9Sstevel@tonic-gate #endif /* lint */
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate extern int ss_pager_create();
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate static char const twentyfive_spaces[26] =
277c478bd9Sstevel@tonic-gate     "                         ";
287c478bd9Sstevel@tonic-gate static char const NL[2] = "\n";
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate void
ss_list_requests(argc,argv,sci_idx,info_ptr)317c478bd9Sstevel@tonic-gate ss_list_requests(argc, argv, sci_idx, info_ptr)
327c478bd9Sstevel@tonic-gate     int argc;
3356a424ccSmp     const char * const *argv;
347c478bd9Sstevel@tonic-gate     int sci_idx;
3556a424ccSmp #ifdef __STDC__
3656a424ccSmp     void *info_ptr;
3756a424ccSmp #else
3856a424ccSmp     char *info_ptr;
3956a424ccSmp #endif
407c478bd9Sstevel@tonic-gate {
417c478bd9Sstevel@tonic-gate     register ss_request_entry *entry;
427c478bd9Sstevel@tonic-gate     register char const * const *name;
437c478bd9Sstevel@tonic-gate     register int spacing;
447c478bd9Sstevel@tonic-gate     register ss_request_table **table;
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate     char buffer[BUFSIZ];
477c478bd9Sstevel@tonic-gate     FILE *output;
487c478bd9Sstevel@tonic-gate     int fd;
497c478bd9Sstevel@tonic-gate #ifdef POSIX_SIGNALS
507c478bd9Sstevel@tonic-gate     struct sigaction nsig, osig;
517c478bd9Sstevel@tonic-gate     sigset_t nmask, omask;
527c478bd9Sstevel@tonic-gate #else
537c478bd9Sstevel@tonic-gate     int mask;
547c478bd9Sstevel@tonic-gate     RETSIGTYPE (*func)();
557c478bd9Sstevel@tonic-gate #endif
567c478bd9Sstevel@tonic-gate #ifndef WAIT_USES_INT
577c478bd9Sstevel@tonic-gate     union wait waitb;
587c478bd9Sstevel@tonic-gate #else
597c478bd9Sstevel@tonic-gate     int waitb;
607c478bd9Sstevel@tonic-gate #endif
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate     DONT_USE(argc);
637c478bd9Sstevel@tonic-gate     DONT_USE(argv);
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate #ifdef POSIX_SIGNALS
667c478bd9Sstevel@tonic-gate     sigemptyset(&nmask);
677c478bd9Sstevel@tonic-gate     sigaddset(&nmask, SIGINT);
687c478bd9Sstevel@tonic-gate     sigprocmask(SIG_BLOCK, &nmask, &omask);
69*1da57d55SToomas Soome 
707c478bd9Sstevel@tonic-gate     nsig.sa_handler = SIG_IGN;
717c478bd9Sstevel@tonic-gate     sigemptyset(&nsig.sa_mask);
727c478bd9Sstevel@tonic-gate     nsig.sa_flags = 0;
737c478bd9Sstevel@tonic-gate     sigaction(SIGINT, &nsig, &osig);
747c478bd9Sstevel@tonic-gate #else
757c478bd9Sstevel@tonic-gate     mask = sigblock(sigmask(SIGINT));
767c478bd9Sstevel@tonic-gate     func = signal(SIGINT, SIG_IGN);
777c478bd9Sstevel@tonic-gate #endif
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate     fd = ss_pager_create();
807c478bd9Sstevel@tonic-gate     output = fdopen(fd, "w");
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate #ifdef POSIX_SIGNALS
837c478bd9Sstevel@tonic-gate     sigprocmask(SIG_SETMASK, &omask, (sigset_t *)0);
847c478bd9Sstevel@tonic-gate #else
857c478bd9Sstevel@tonic-gate     sigsetmask(mask);
867c478bd9Sstevel@tonic-gate #endif
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate     fprintf (output, dgettext(TEXT_DOMAIN, "Available %s requests:\n\n"),
897c478bd9Sstevel@tonic-gate 	     ss_info (sci_idx) -> subsystem_name);
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate     for (table = ss_info(sci_idx)->rqt_tables; *table; table++) {
927c478bd9Sstevel@tonic-gate         entry = (*table)->requests;
937c478bd9Sstevel@tonic-gate         for (; entry->command_names; entry++) {
947c478bd9Sstevel@tonic-gate             spacing = -2;
957c478bd9Sstevel@tonic-gate             buffer[0] = '\0';
967c478bd9Sstevel@tonic-gate             if (entry->flags & SS_OPT_DONT_LIST)
977c478bd9Sstevel@tonic-gate                 continue;
9856a424ccSmp             buffer[sizeof(buffer) - 1] = '\0';
997c478bd9Sstevel@tonic-gate             for (name = entry->command_names; *name; name++) {
1007c478bd9Sstevel@tonic-gate                 register int len = strlen(*name);
10156a424ccSmp                 strncat(buffer, *name, sizeof(buffer) - 1 - strlen(buffer));
1027c478bd9Sstevel@tonic-gate                 spacing += len + 2;
1037c478bd9Sstevel@tonic-gate                 if (name[1]) {
10456a424ccSmp                     strncat(buffer, ", ", sizeof(buffer) - 1 - strlen(buffer));
1057c478bd9Sstevel@tonic-gate                 }
1067c478bd9Sstevel@tonic-gate             }
1077c478bd9Sstevel@tonic-gate             if (spacing > 23) {
10856a424ccSmp                 strncat(buffer, NL, sizeof(buffer) - 1 - strlen(buffer));
1097c478bd9Sstevel@tonic-gate                 fputs(buffer, output);
1107c478bd9Sstevel@tonic-gate                 spacing = 0;
1117c478bd9Sstevel@tonic-gate                 buffer[0] = '\0';
1127c478bd9Sstevel@tonic-gate             }
11356a424ccSmp             strncat(buffer, twentyfive_spaces, strlen(twentyfive_spaces) - spacing);
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate             /*
1167c478bd9Sstevel@tonic-gate              * Due to libss not knowing what TEXT_DOMAIN
1177c478bd9Sstevel@tonic-gate              * the calling application is using for its info_string
1187c478bd9Sstevel@tonic-gate              * messages, we know require the callers (ktutil,kadmin)
1197c478bd9Sstevel@tonic-gate              * to L10N the messages before calling libss.
1207c478bd9Sstevel@tonic-gate              */
12156a424ccSmp             strncat(buffer, entry->info_string, sizeof(buffer) -1 - strlen(buffer));
12256a424ccSmp             strncat(buffer, NL,  sizeof(buffer) - 1 - strlen(buffer));
1237c478bd9Sstevel@tonic-gate             fputs(buffer, output);
1247c478bd9Sstevel@tonic-gate         }
1257c478bd9Sstevel@tonic-gate     }
1267c478bd9Sstevel@tonic-gate     fclose(output);
1277c478bd9Sstevel@tonic-gate #ifndef NO_FORK
1287c478bd9Sstevel@tonic-gate     wait(&waitb);
1297c478bd9Sstevel@tonic-gate #endif
1307c478bd9Sstevel@tonic-gate #ifdef POSIX_SIGNALS
1317c478bd9Sstevel@tonic-gate     sigaction(SIGINT, &osig, (struct sigaction *)0);
1327c478bd9Sstevel@tonic-gate #else
1337c478bd9Sstevel@tonic-gate     (void) signal(SIGINT, func);
1347c478bd9Sstevel@tonic-gate #endif
1357c478bd9Sstevel@tonic-gate }
136