2 * lib/krb5/os/k5dfspag.c
4 * New Kerberos module to issue the DFS PAG syscalls.
5 * It also contains the routine to fork and exec the
6 * k5dcecon routine to do most of the work.
8 * This file is designed to be as independent of DCE
9 * and DFS as possible. The only dependencies are on
10 * the syscall numbers. If DFS not running or not installed,
11 * the sig handlers will catch and the signal and
14 * krb5_dfs_newpag and krb5_dfs_getpag should not be real
15 * Kerberos routines, since they should be setpag and getpag
16 * in the DCE library, but without the DCE baggage.
17 * Thus they don't have context, and don't return a krb5 error.
38 #include <sys/param.h>
40 /* Only run this DFS PAG code on systems with POSIX
41 * All that we are interested in dor:, AIX 4.x,
42 * Solaris 2.5.x, HPUX 10.x Even SunOS 4.1.4, AIX 3.2.5
43 * and SGI 5.3 are OK. This simplifies
44 * the build/configure which I don't want to change now.
45 * All of them also have waitpid as well.
58 #define sigjmp_buf jmp_buf
59 #define sigsetjmp(j,s) setjmp(j)
60 #define siglongjmp longjmp
64 typedef struct sigaction handler
;
65 #define handler_init(H,F) (sigemptyset(&(H).sa_mask), \
68 #define handler_swap(S,NEW,OLD) sigaction(S, &NEW, &OLD)
69 #define handler_set(S,OLD) sigaction(S, &OLD, NULL)
71 typedef sigtype (*handler
)();
72 #define handler_init(H,F) ((H) = (F))
73 #define handler_swap(S,NEW,OLD) ((OLD) = signal ((S), (NEW)))
74 #define handler_set(S,OLD) (signal ((S), (OLD)))
77 #define krb5_sigtype void
79 typedef krb5_sigtype sigtype
;
83 * Need some syscall numbers based on different systems.
85 * HPUX 10.10 /opt/dce/include/dcedfs/syscall.h
86 * Solaris 2.5 /opt/dcelocal/share/include/dcedfs/syscall.h
87 * AIX 4.2 - needs some funny games with load and kafs_syscall
88 * to get the kernel extentions. There should be a better way!
95 #define AFSCALL_SETPAG 2
96 #define AFSCALL_GETPAG 11
99 #define AFS_SYSCALL 72
102 /* assume HPUX 10 + or is it 50 */
103 #define AFS_SYSCALL 326
107 #define DPAGAIX LIBEXECDIR "/dpagaix"
110 static int (*dpagaix
)(int, int, int, int, int, int) = 0;
112 #elif defined(sgi) || defined(_sgi)
113 #define AFS_SYSCALL 206+1000
116 #define AFS_SYSCALL (Unknown_DFS_AFS_SYSCALL)
122 #else /* WAIT_USES_INT */
123 union wait wait_status
;
124 #endif /* WAIT_USES_INT */
127 #define K5DCECON LIBEXECDIR "/k5dcecon"
133 * signal handler if DFS not running
137 static sigjmp_buf setpag_buf
;
139 static sigtype
mysig()
141 siglongjmp(setpag_buf
, 1);
145 * krb5_dfs_pag_syscall()
147 * wrapper for the syscall with signal handlers
151 static int krb5_dfs_pag_syscall(opt1
,opt2
)
159 handler_init (sa1
, mysig
);
160 handler_init (sa2
, mysig
);
161 handler_swap (SIGSYS
, sa1
, osa1
);
162 handler_swap (SIGSEGV
, sa2
, osa2
);
164 if (sigsetjmp(setpag_buf
, 1) == 0) {
168 dpagaix
= load(DPAGAIX
, 0, 0);
170 pag
= (*dpagaix
)(opt1
, opt2
, 0, 0, 0, 0);
172 pag
= syscall(AFS_SYSCALL
, opt1
, opt2
, 0, 0, 0, 0);
175 handler_set (SIGSYS
, osa1
);
176 handler_set (SIGSEGV
, osa2
);
180 /* syscall failed! return 0 */
181 handler_set (SIGSYS
, osa1
);
182 handler_set (SIGSEGV
, osa2
);
189 * issue a DCE/DFS setpag system call to set the newpag
190 * for this process. This takes advantage of a currently
191 * undocumented feature of the Transarc port of DFS.
192 * Even in DCE 1.2.2 for which the source is available,
193 * (but no vendors have released), this feature is not
194 * there, but it should be, or could be added.
195 * If new_pag is zero, then the syscall will get a new pag
196 * and return its value.
199 int krb5_dfs_newpag(new_pag
)
202 return(krb5_dfs_pag_syscall(AFSCALL_SETPAG
, new_pag
));
208 * get the current PAG. Used mostly as a test.
211 int krb5_dfs_getpag()
213 return(krb5_dfs_pag_syscall(AFSCALL_GETPAG
, 0));
219 * Given a principal and local username,
220 * fork and exec the k5dcecon module to create
221 * refresh or join a new DCE/DFS
222 * Process Authentication Group (PAG)
224 * This routine should be called after krb5_kuserok has
225 * determined that this combination of local user and
226 * principal are acceptable for the local host.
228 * It should also be called after a forwarded ticket has
229 * been received, and the KRB5CCNAME environment variable
230 * has been set to point at it. k5dcecon will convert this
231 * to a new DCE context and a new pag and replace KRB5CCNAME
232 * in the environment.
234 * If there is no forwarded ticket, k5dcecon will attempt
235 * to join an existing PAG for the same principal and local
238 * And it should be called before access to the home directory
239 * as this may be in DFS, not accessible by root, and require
240 * the PAG to have been setup.
242 * The krb5_afs_pag can be called after this routine to
243 * use the the cache obtained by k5dcecon to get an AFS token.
247 int krb5_dfs_pag(context
, flag
, principal
, luser
)
248 krb5_context context
;
249 int flag
; /* 1 if a forwarded TGT is to be used */
250 krb5_principal principal
;
261 char newccname
[MAXPATHLEN
] = "";
264 struct sigaction newsig
, oldsig
;
268 #else /* WAIT_USES_INT */
269 union wait wait_status
;
270 #endif /* WAIT_USES_INT */
272 if (krb5_unparse_name(context
, principal
, &princ
))
275 /* test if DFS is running or installed */
276 if (krb5_dfs_getpag() == -2)
277 return(0); /* DFS not running, dont try */
282 /* Make sure that telnetd.c's SIGCHLD action don't happen right now... */
283 memset((char *)&newsig
, 0, sizeof(newsig
));
284 newsig
.sa_handler
= SIG_DFL
;
285 sigaction(SIGCHLD
, &newsig
, &oldsig
);
291 if (pid
== 0) { /* child process */
293 close(1); /* close stdout */
294 dup(fd
[1]); /* point stdout at pipe here */
295 close(fd
[0]); /* don't use end of pipe here */
296 close(fd
[1]); /* pipe now as stdout */
298 execl(K5DCECON
, "k5dcecon",
299 (flag
) ? "-f" : "-s" ,
301 "-p", princ
, (char *)0);
303 exit(127); /* incase execl fails */
306 /* parent, wait for child to finish */
308 close(fd
[1]); /* dont need this end of pipe */
310 /* #if defined(sgi) || defined(_sgi) */
311 /* wait_status.w_status = 0; */
312 /* waitpid((pid_t) pid, &wait_status.w_status, 0); */
318 err
= waitpid((pid_t
) pid
, &wait_status
, 0);
319 #else /* HAVE_WAITPID */
320 err
= wait4(pid
, &wait_status
, 0, (struct rusage
*) NULL
);
321 #endif /* HAVE_WAITPID */
324 sigaction(SIGCHLD
, &oldsig
, 0);
325 if (WIFEXITED(wait_status
)){
326 if (WEXITSTATUS(wait_status
) == 0) {
330 i
= read(fd
[0], &newccname
[j
], sizeof(newccname
)-1-j
);
333 if (j
>= sizeof(newccname
)-1)
339 esetenv("KRB5CCNAME",newccname
,1);
340 sscanf(&newccname
[j
-8],"%8x",&new_pag
);
341 if (new_pag
&& strncmp("FILE:/opt/dcelocal/var/security/creds/dcecred_", newccname
, 46) == 0) {
342 if((pag
= krb5_dfs_newpag(new_pag
)) != -2) {
349 return(0); /* something not right */
355 * krb5_dfs_pag - dummy version for the lib for systems
356 * which don't have DFS, or the needed setpag kernel code.
360 krb5_dfs_pag(context
, principal
, luser
)
361 krb5_context context
;
362 krb5_principal principal
;