1 | /* |
---|
2 | * $Id: rk_lib.c,v 1.4 1996-09-20 03:15:05 ghudson Exp $ |
---|
3 | * $Source: /afs/dev.mit.edu/source/repository/athena/bin/rkinit/lib/rk_lib.c,v $ |
---|
4 | * $Author: ghudson $ |
---|
5 | * |
---|
6 | * This file contains the non-rpc top-level rkinit library routines. |
---|
7 | * The routines in the rkinit library that should be called from clients |
---|
8 | * are exactly those defined in this file. |
---|
9 | * |
---|
10 | * The naming convetions used within the rkinit library are as follows: |
---|
11 | * Functions intended for general client use start with rkinit_ |
---|
12 | * Functions intended for use only inside the library or server start with |
---|
13 | * rki_ |
---|
14 | * Functions that do network communcation start with rki_rpc_ |
---|
15 | * Static functions can be named in any fashion. |
---|
16 | */ |
---|
17 | |
---|
18 | #if !defined(lint) && !defined(SABER) && !defined(LOCORE) && defined(RCS_HDRS) |
---|
19 | static char *rcsid = "$Id: rk_lib.c,v 1.4 1996-09-20 03:15:05 ghudson Exp $"; |
---|
20 | #endif /* lint || SABER || LOCORE || RCS_HDRS */ |
---|
21 | |
---|
22 | #include <stdio.h> |
---|
23 | #include <string.h> |
---|
24 | #include <setjmp.h> |
---|
25 | #include <krb.h> |
---|
26 | |
---|
27 | #ifdef SYSV |
---|
28 | #include <netdb.h> |
---|
29 | #endif |
---|
30 | #include <rkinit.h> |
---|
31 | #include <rkinit_private.h> |
---|
32 | #include <rkinit_err.h> |
---|
33 | |
---|
34 | #ifdef __STDC__ |
---|
35 | char *rkinit_errmsg(char *string) |
---|
36 | #else |
---|
37 | char *rkinit_errmsg(string) |
---|
38 | char *string; |
---|
39 | #endif /* __STDC__ */ |
---|
40 | { |
---|
41 | static char errmsg[BUFSIZ]; |
---|
42 | |
---|
43 | if (string) { |
---|
44 | BCLEAR(errmsg); |
---|
45 | strncpy(errmsg, string, sizeof(errmsg) - 1); |
---|
46 | } |
---|
47 | |
---|
48 | return(errmsg); |
---|
49 | } |
---|
50 | |
---|
51 | #ifdef __STDC__ |
---|
52 | int rkinit(char *host, char *r_krealm, rkinit_info *info, int timeout) |
---|
53 | #else |
---|
54 | int rkinit(host, r_krealm, info, timeout) |
---|
55 | char *host; |
---|
56 | char *r_krealm; |
---|
57 | rkinit_info *info; |
---|
58 | int timeout; |
---|
59 | #endif /* __STDC__ */ |
---|
60 | { |
---|
61 | int status = RKINIT_SUCCESS; |
---|
62 | int version = 0; |
---|
63 | char phost[MAXHOSTNAMELEN]; |
---|
64 | jmp_buf timeout_env; |
---|
65 | int (*old_alrm)(); |
---|
66 | char origtktfilename[MAXPATHLEN]; /* original ticket file name */ |
---|
67 | char tktfilename[MAXPATHLEN]; /* temporary client ticket file */ |
---|
68 | |
---|
69 | extern int (*rki_setup_timer())(); |
---|
70 | extern void rki_restore_timer(); |
---|
71 | extern void rki_cleanup_rpc(); |
---|
72 | |
---|
73 | BCLEAR(phost); |
---|
74 | BCLEAR(origtktfilename); |
---|
75 | BCLEAR(tktfilename); |
---|
76 | BCLEAR(timeout_env); |
---|
77 | |
---|
78 | initialize_rkin_error_table(); |
---|
79 | |
---|
80 | if (status = rki_setup_rpc(host)) |
---|
81 | return(status); |
---|
82 | |
---|
83 | /* The alarm handler longjmps us to here. */ |
---|
84 | if ((status = setjmp(timeout_env)) == 0) { |
---|
85 | |
---|
86 | strcpy(origtktfilename, tkt_string()); |
---|
87 | sprintf(tktfilename, "/tmp/tkt_rkinit.%d", getpid()); |
---|
88 | krb_set_tkt_string(tktfilename); |
---|
89 | |
---|
90 | if (timeout) |
---|
91 | old_alrm = rki_setup_timer(timeout_env); |
---|
92 | |
---|
93 | if ((status = rki_choose_version(&version)) == RKINIT_SUCCESS) |
---|
94 | status = rki_get_tickets(version, host, r_krealm, info); |
---|
95 | } |
---|
96 | |
---|
97 | if (timeout) |
---|
98 | rki_restore_timer(old_alrm); |
---|
99 | |
---|
100 | dest_tkt(); |
---|
101 | krb_set_tkt_string(origtktfilename); |
---|
102 | |
---|
103 | rki_cleanup_rpc(); |
---|
104 | |
---|
105 | return(status); |
---|
106 | } |
---|