1 /* $NetBSD: k5dfspag.c,v 1.1.1.2 2014/04/24 12:45:49 pettai Exp $ */
4 * lib/krb5/os/k5dfspag.c
6 * New Kerberos module to issue the DFS PAG syscalls.
7 * It also contains the routine to fork and exec the
8 * k5dcecon routine to do most of the work.
10 * This file is designed to be as independent of DCE
11 * and DFS as possible. The only dependencies are on
12 * the syscall numbers. If DFS not running or not installed,
13 * the sig handlers will catch and the signal and
16 * krb5_dfs_newpag and krb5_dfs_getpag should not be real
17 * Kerberos routines, since they should be setpag and getpag
18 * in the DCE library, but without the DCE baggage.
19 * Thus they don't have context, and don't return a krb5 error.
32 #include <krb5/krb5.h>
40 #include <sys/param.h>
42 /* Only run this DFS PAG code on systems with POSIX
43 * All that we are interested in dor:, AIX 4.x,
44 * Solaris 2.5.x, HPUX 10.x Even SunOS 4.1.4, AIX 3.2.5
45 * and SGI 5.3 are OK. This simplifies
46 * the build/configure which I don't want to change now.
47 * All of them also have waitpid as well.
60 #define sigjmp_buf jmp_buf
61 #define sigsetjmp(j,s) setjmp(j)
62 #define siglongjmp longjmp
66 typedef struct sigaction handler
;
67 #define handler_init(H,F) (sigemptyset(&(H).sa_mask), \
70 #define handler_swap(S,NEW,OLD) sigaction(S, &NEW, &OLD)
71 #define handler_set(S,OLD) sigaction(S, &OLD, NULL)
73 typedef sigtype (*handler
)();
74 #define handler_init(H,F) ((H) = (F))
75 #define handler_swap(S,NEW,OLD) ((OLD) = signal ((S), (NEW)))
76 #define handler_set(S,OLD) (signal ((S), (OLD)))
79 #define krb5_sigtype void
81 typedef krb5_sigtype sigtype
;
85 * Need some syscall numbers based on different systems.
87 * HPUX 10.10 /opt/dce/include/dcedfs/syscall.h
88 * Solaris 2.5 /opt/dcelocal/share/include/dcedfs/syscall.h
89 * AIX 4.2 - needs some funny games with load and kafs_syscall
90 * to get the kernel extentions. There should be a better way!
97 #define AFSCALL_SETPAG 2
98 #define AFSCALL_GETPAG 11
101 #define AFS_SYSCALL 72
104 /* assume HPUX 10 + or is it 50 */
105 #define AFS_SYSCALL 326
109 #define DPAGAIX LIBEXECDIR "/dpagaix"
112 static int (*dpagaix
)(int, int, int, int, int, int) = 0;
114 #elif defined(sgi) || defined(_sgi)
115 #define AFS_SYSCALL 206+1000
118 #define AFS_SYSCALL (Unknown_DFS_AFS_SYSCALL)
124 #else /* WAIT_USES_INT */
125 union wait wait_status
;
126 #endif /* WAIT_USES_INT */
129 #define K5DCECON LIBEXECDIR "/k5dcecon"
135 * signal handler if DFS not running
139 static sigjmp_buf setpag_buf
;
141 static sigtype
mysig()
143 siglongjmp(setpag_buf
, 1);
147 * krb5_dfs_pag_syscall()
149 * wrapper for the syscall with signal handlers
153 static int krb5_dfs_pag_syscall(opt1
,opt2
)
161 handler_init (sa1
, mysig
);
162 handler_init (sa2
, mysig
);
163 handler_swap (SIGSYS
, sa1
, osa1
);
164 handler_swap (SIGSEGV
, sa2
, osa2
);
166 if (sigsetjmp(setpag_buf
, 1) == 0) {
170 dpagaix
= load(DPAGAIX
, 0, 0);
172 pag
= (*dpagaix
)(opt1
, opt2
, 0, 0, 0, 0);
174 pag
= syscall(AFS_SYSCALL
, opt1
, opt2
, 0, 0, 0, 0);
177 handler_set (SIGSYS
, osa1
);
178 handler_set (SIGSEGV
, osa2
);
182 /* syscall failed! return 0 */
183 handler_set (SIGSYS
, osa1
);
184 handler_set (SIGSEGV
, osa2
);
191 * issue a DCE/DFS setpag system call to set the newpag
192 * for this process. This takes advantage of a currently
193 * undocumented feature of the Transarc port of DFS.
194 * Even in DCE 1.2.2 for which the source is available,
195 * (but no vendors have released), this feature is not
196 * there, but it should be, or could be added.
197 * If new_pag is zero, then the syscall will get a new pag
198 * and return its value.
201 int krb5_dfs_newpag(new_pag
)
204 return(krb5_dfs_pag_syscall(AFSCALL_SETPAG
, new_pag
));
210 * get the current PAG. Used mostly as a test.
213 int krb5_dfs_getpag()
215 return(krb5_dfs_pag_syscall(AFSCALL_GETPAG
, 0));
221 * Given a principal and local username,
222 * fork and exec the k5dcecon module to create
223 * refresh or join a new DCE/DFS
224 * Process Authentication Group (PAG)
226 * This routine should be called after krb5_kuserok has
227 * determined that this combination of local user and
228 * principal are acceptable for the local host.
230 * It should also be called after a forwarded ticket has
231 * been received, and the KRB5CCNAME environment variable
232 * has been set to point at it. k5dcecon will convert this
233 * to a new DCE context and a new pag and replace KRB5CCNAME
234 * in the environment.
236 * If there is no forwarded ticket, k5dcecon will attempt
237 * to join an existing PAG for the same principal and local
240 * And it should be called before access to the home directory
241 * as this may be in DFS, not accessable by root, and require
242 * the PAG to have been setup.
244 * The krb5_afs_pag can be called after this routine to
245 * use the the cache obtained by k5dcecon to get an AFS token.
249 int krb5_dfs_pag(context
, flag
, principal
, luser
)
250 krb5_context context
;
251 int flag
; /* 1 if a forwarded TGT is to be used */
252 krb5_principal principal
;
263 char newccname
[MAXPATHLEN
] = "";
266 struct sigaction newsig
, oldsig
;
270 #else /* WAIT_USES_INT */
271 union wait wait_status
;
272 #endif /* WAIT_USES_INT */
274 if (krb5_unparse_name(context
, principal
, &princ
))
277 /* test if DFS is running or installed */
278 if (krb5_dfs_getpag() == -2)
279 return(0); /* DFS not running, dont try */
284 /* Make sure that telnetd.c's SIGCHLD action don't happen right now... */
285 memset((char *)&newsig
, 0, sizeof(newsig
));
286 newsig
.sa_handler
= SIG_DFL
;
287 sigaction(SIGCHLD
, &newsig
, &oldsig
);
293 if (pid
== 0) { /* child process */
295 close(1); /* close stdout */
296 dup(fd
[1]); /* point stdout at pipe here */
297 close(fd
[0]); /* don't use end of pipe here */
298 close(fd
[1]); /* pipe now as stdout */
300 execl(K5DCECON
, "k5dcecon",
301 (flag
) ? "-f" : "-s" ,
303 "-p", princ
, (char *)0);
305 exit(127); /* incase execl fails */
308 /* parent, wait for child to finish */
310 close(fd
[1]); /* dont need this end of pipe */
312 /* #if defined(sgi) || defined(_sgi) */
313 /* wait_status.w_status = 0; */
314 /* waitpid((pid_t) pid, &wait_status.w_status, 0); */
320 err
= waitpid((pid_t
) pid
, &wait_status
, 0);
321 #else /* HAVE_WAITPID */
322 err
= wait4(pid
, &wait_status
, 0, (struct rusage
*) NULL
);
323 #endif /* HAVE_WAITPID */
326 sigaction(SIGCHLD
, &oldsig
, 0);
327 if (WIFEXITED(wait_status
)){
328 if (WEXITSTATUS(wait_status
) == 0) {
332 i
= read(fd
[0], &newccname
[j
], sizeof(newccname
)-1-j
);
335 if (j
>= sizeof(newccname
)-1)
341 esetenv("KRB5CCNAME",newccname
,1);
342 sscanf(&newccname
[j
-8],"%8x",&new_pag
);
343 if (new_pag
&& strncmp("FILE:/opt/dcelocal/var/security/creds/dcecred_", newccname
, 46) == 0) {
344 if((pag
= krb5_dfs_newpag(new_pag
)) != -2) {
351 return(0); /* something not right */
357 * krb5_dfs_pag - dummy version for the lib for systems
358 * which don't have DFS, or the needed setpag kernel code.
362 krb5_dfs_pag(context
, principal
, luser
)
363 krb5_context context
;
364 krb5_principal principal
;