use unix sockets too
[heimdal.git] / appl / dceutils / testpag.c
blob8c9bf4a653b5ed6c04ded80fa03ae8b97d0c381a
1 /* Test the k5dcepag routine by setting a pag, and
2 * and execing a shell under this pag.
4 * This allows you to join a PAG which was created
5 * earlier by some other means.
6 * for example k5dcecon
8 * Must be run as root for testing only.
12 #include <stdio.h>
13 #include <sys/stat.h>
14 #include <sys/wait.h>
15 #include <fcntl.h>
16 #include <signal.h>
17 #include <setjmp.h>
18 #include <errno.h>
20 #define POSIX_SETJMP
21 #define POSIX_SIGNALS
23 #ifdef POSIX_SIGNALS
24 typedef struct sigaction handler;
25 #define handler_init(H,F) (sigemptyset(&(H).sa_mask), \
26 (H).sa_flags=0, \
27 (H).sa_handler=(F))
28 #define handler_swap(S,NEW,OLD) sigaction(S, &NEW, &OLD)
29 #define handler_set(S,OLD) sigaction(S, &OLD, NULL)
30 #else
31 typedef sigtype (*handler)();
32 #define handler_init(H,F) ((H) = (F))
33 #define handler_swap(S,NEW,OLD) ((OLD) = signal ((S), (NEW)))
35 #define handler_set(S,OLD) (signal ((S), (OLD)))
36 #endif
38 typedef void sigtype;
41 * We could include the dcedfs/syscall.h which should have these
42 * numbers, but it has extra baggage. So for
43 * simplicity sake now, we define these here.
47 #define AFSCALL_SETPAG 2
48 #define AFSCALL_GETPAG 11
50 #if defined(sun)
51 #define AFS_SYSCALL 72
53 #elif defined(hpux)
54 /* assume HPUX 10 + or is it 50 */
55 #define AFS_SYSCALL 326
57 #elif defined(_AIX)
58 #define DPAGAIX "dpagaix"
59 /* #define DPAGAIX "/krb5/sbin/dpagaix" */
61 #elif defined(sgi) || defined(_sgi)
62 #define AFS_SYSCALL 206+1000
64 #else
65 #define AFS_SYSCALL (Unknown_DFS_AFS_SYSCALL)
66 #endif
68 static sigjmp_buf setpag_buf;
70 static sigtype mysig()
72 siglongjmp(setpag_buf, 1);
76 int krb5_dfs_newpag(new_pag)
77 int new_pag;
79 handler sa1, osa1;
80 handler sa2, osa2;
81 int pag = -1;
83 handler_init (sa1, mysig);
84 handler_init (sa2, mysig);
85 handler_swap (SIGSYS, sa1, osa1);
86 handler_swap (SIGSEGV, sa2, osa2);
88 if (sigsetjmp(setpag_buf, 1) == 0) {
89 #if defined(_AIX)
90 int (*dpagaix)(int, int, int, int, int, int);
92 if (dpagaix = load(DPAGAIX, 0, 0))
93 pag = (*dpagaix)(AFSCALL_SETPAG, new_pag, 0, 0, 0, 0);
94 #else
95 pag = syscall(AFS_SYSCALL,AFSCALL_SETPAG, new_pag, 0, 0, 0, 0);
96 #endif
97 handler_set (SIGSYS, osa1);
98 handler_set (SIGSEGV, osa2);
99 return(pag);
102 fprintf(stderr,"Setpag failed with a system error\n");
103 /* syscall failed! return 0 */
104 handler_set (SIGSYS, osa1);
105 handler_set (SIGSEGV, osa2);
106 return(-1);
109 main(argc, argv)
110 int argc;
111 char *argv[];
113 extern int optind;
114 extern char *optarg;
115 int rv;
116 int rc;
117 unsigned int pag;
118 unsigned int newpag = 0;
119 char ccname[256];
120 int nflag = 0;
122 while((rv = getopt(argc,argv,"n:")) != -1) {
123 switch(rv) {
124 case 'n':
125 nflag++;
126 sscanf(optarg,"%8x",&newpag);
127 break;
128 default:
129 printf("Usage: k5dcepagt -n pag \n");
130 exit(1);
134 if (nflag) {
135 fprintf (stderr,"calling k5dcepag newpag=%8.8x\n",newpag);
136 pag = krb5_dfs_newpag(newpag);
138 fprintf (stderr,"PAG returned = %8.8x\n",pag);
139 if ((pag != 0) && (pag != -1)) {
140 sprintf (ccname,
141 "FILE:/opt/dcelocal/var/security/creds/dcecred_%8.8x",
142 pag);
143 esetenv("KRB5CCNAME",ccname,1);
144 execl("/bin/csh", "csh", NULL);
146 else {
147 fprintf(stderr," Not a good pag value\n");