xref: /freebsd/crypto/krb5/src/util/ss/list_rqs.c (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1*7f2fe78bSCy Schubert /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2*7f2fe78bSCy Schubert /*
3*7f2fe78bSCy Schubert  * Copyright 1987, 1988 by MIT Student Information Processing Board
4*7f2fe78bSCy Schubert  *
5*7f2fe78bSCy Schubert  * For copyright information, see copyright.h.
6*7f2fe78bSCy Schubert  */
7*7f2fe78bSCy Schubert #include "copyright.h"
8*7f2fe78bSCy Schubert #include "ss_internal.h"
9*7f2fe78bSCy Schubert #include <signal.h>
10*7f2fe78bSCy Schubert #include <setjmp.h>
11*7f2fe78bSCy Schubert #include <sys/wait.h>
12*7f2fe78bSCy Schubert 
13*7f2fe78bSCy Schubert #ifdef lint     /* "lint returns a value which is sometimes ignored" */
14*7f2fe78bSCy Schubert #define DONT_USE(x)     x=x;
15*7f2fe78bSCy Schubert #else /* !lint */
16*7f2fe78bSCy Schubert #define DONT_USE(x)     ;
17*7f2fe78bSCy Schubert #endif /* lint */
18*7f2fe78bSCy Schubert 
19*7f2fe78bSCy Schubert static char const twentyfive_spaces[26] =
20*7f2fe78bSCy Schubert     "                         ";
21*7f2fe78bSCy Schubert static char const NL[2] = "\n";
22*7f2fe78bSCy Schubert 
23*7f2fe78bSCy Schubert void
ss_list_requests(argc,argv,sci_idx,info_ptr)24*7f2fe78bSCy Schubert ss_list_requests(argc, argv, sci_idx, info_ptr)
25*7f2fe78bSCy Schubert     int argc;
26*7f2fe78bSCy Schubert     const char * const *argv;
27*7f2fe78bSCy Schubert     int sci_idx;
28*7f2fe78bSCy Schubert #ifdef __STDC__
29*7f2fe78bSCy Schubert     void *info_ptr;
30*7f2fe78bSCy Schubert #else
31*7f2fe78bSCy Schubert     char *info_ptr;
32*7f2fe78bSCy Schubert #endif
33*7f2fe78bSCy Schubert {
34*7f2fe78bSCy Schubert     ss_request_entry *entry;
35*7f2fe78bSCy Schubert     char const *const *name;
36*7f2fe78bSCy Schubert     int spacing;
37*7f2fe78bSCy Schubert     ss_request_table **table;
38*7f2fe78bSCy Schubert 
39*7f2fe78bSCy Schubert     char buffer[BUFSIZ];
40*7f2fe78bSCy Schubert     FILE *output;
41*7f2fe78bSCy Schubert     int fd;
42*7f2fe78bSCy Schubert #ifdef POSIX_SIGNALS
43*7f2fe78bSCy Schubert     struct sigaction nsig, osig;
44*7f2fe78bSCy Schubert     sigset_t nmask, omask;
45*7f2fe78bSCy Schubert #else
46*7f2fe78bSCy Schubert     int mask;
47*7f2fe78bSCy Schubert     void (*func)();
48*7f2fe78bSCy Schubert #endif
49*7f2fe78bSCy Schubert #ifndef WAIT_USES_INT
50*7f2fe78bSCy Schubert     union wait waitb;
51*7f2fe78bSCy Schubert #else
52*7f2fe78bSCy Schubert     int waitb;
53*7f2fe78bSCy Schubert #endif
54*7f2fe78bSCy Schubert 
55*7f2fe78bSCy Schubert     DONT_USE(argc);
56*7f2fe78bSCy Schubert     DONT_USE(argv);
57*7f2fe78bSCy Schubert 
58*7f2fe78bSCy Schubert #ifdef POSIX_SIGNALS
59*7f2fe78bSCy Schubert     sigemptyset(&nmask);
60*7f2fe78bSCy Schubert     sigaddset(&nmask, SIGINT);
61*7f2fe78bSCy Schubert     sigprocmask(SIG_BLOCK, &nmask, &omask);
62*7f2fe78bSCy Schubert 
63*7f2fe78bSCy Schubert     nsig.sa_handler = SIG_IGN;
64*7f2fe78bSCy Schubert     sigemptyset(&nsig.sa_mask);
65*7f2fe78bSCy Schubert     nsig.sa_flags = 0;
66*7f2fe78bSCy Schubert     sigaction(SIGINT, &nsig, &osig);
67*7f2fe78bSCy Schubert #else
68*7f2fe78bSCy Schubert     mask = sigblock(sigmask(SIGINT));
69*7f2fe78bSCy Schubert     func = signal(SIGINT, SIG_IGN);
70*7f2fe78bSCy Schubert #endif
71*7f2fe78bSCy Schubert 
72*7f2fe78bSCy Schubert     fd = ss_pager_create();     /* FD_CLOEXEC set */
73*7f2fe78bSCy Schubert     output = fdopen(fd, "w");
74*7f2fe78bSCy Schubert 
75*7f2fe78bSCy Schubert #ifdef POSIX_SIGNALS
76*7f2fe78bSCy Schubert     sigprocmask(SIG_SETMASK, &omask, (sigset_t *)0);
77*7f2fe78bSCy Schubert #else
78*7f2fe78bSCy Schubert     sigsetmask(mask);
79*7f2fe78bSCy Schubert #endif
80*7f2fe78bSCy Schubert 
81*7f2fe78bSCy Schubert     fprintf (output, "Available %s requests:\n\n",
82*7f2fe78bSCy Schubert              ss_info (sci_idx) -> subsystem_name);
83*7f2fe78bSCy Schubert 
84*7f2fe78bSCy Schubert     for (table = ss_info(sci_idx)->rqt_tables; *table; table++) {
85*7f2fe78bSCy Schubert         entry = (*table)->requests;
86*7f2fe78bSCy Schubert         for (; entry->command_names; entry++) {
87*7f2fe78bSCy Schubert             spacing = -2;
88*7f2fe78bSCy Schubert             buffer[0] = '\0';
89*7f2fe78bSCy Schubert             if (entry->flags & SS_OPT_DONT_LIST)
90*7f2fe78bSCy Schubert                 continue;
91*7f2fe78bSCy Schubert             buffer[sizeof(buffer) - 1] = '\0';
92*7f2fe78bSCy Schubert             for (name = entry->command_names; *name; name++) {
93*7f2fe78bSCy Schubert                 int len = strlen(*name);
94*7f2fe78bSCy Schubert                 strncat(buffer, *name, sizeof(buffer) - 1 - strlen(buffer));
95*7f2fe78bSCy Schubert                 spacing += len + 2;
96*7f2fe78bSCy Schubert                 if (name[1]) {
97*7f2fe78bSCy Schubert                     strncat(buffer, ", ", sizeof(buffer) - 1 - strlen(buffer));
98*7f2fe78bSCy Schubert                 }
99*7f2fe78bSCy Schubert             }
100*7f2fe78bSCy Schubert             if (spacing > 23) {
101*7f2fe78bSCy Schubert                 strncat(buffer, NL, sizeof(buffer) - 1 - strlen(buffer));
102*7f2fe78bSCy Schubert                 fputs(buffer, output);
103*7f2fe78bSCy Schubert                 spacing = 0;
104*7f2fe78bSCy Schubert                 buffer[0] = '\0';
105*7f2fe78bSCy Schubert             }
106*7f2fe78bSCy Schubert             strncat(buffer, twentyfive_spaces, sizeof(buffer) - 1 - (25-spacing));
107*7f2fe78bSCy Schubert             strncpy(buffer + 25, entry->info_string, sizeof(buffer) - 1 - 25);
108*7f2fe78bSCy Schubert             strncat(buffer, NL, sizeof(buffer) - 1 - strlen(buffer));
109*7f2fe78bSCy Schubert             fputs(buffer, output);
110*7f2fe78bSCy Schubert         }
111*7f2fe78bSCy Schubert     }
112*7f2fe78bSCy Schubert     fclose(output);
113*7f2fe78bSCy Schubert #ifndef NO_FORK
114*7f2fe78bSCy Schubert     wait(&waitb);
115*7f2fe78bSCy Schubert #endif
116*7f2fe78bSCy Schubert #ifdef POSIX_SIGNALS
117*7f2fe78bSCy Schubert     sigaction(SIGINT, &osig, (struct sigaction *)0);
118*7f2fe78bSCy Schubert #else
119*7f2fe78bSCy Schubert     (void) signal(SIGINT, func);
120*7f2fe78bSCy Schubert #endif
121*7f2fe78bSCy Schubert }
122