Mercurial > pidgin.yaz
annotate src/protocols/zephyr/ZInit.c @ 2501:227cc42ffa6e
[gaim-migrate @ 2514]
i should have hidden something ultra-secret in this.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Sun, 14 Oct 2001 11:36:36 +0000 |
parents | 7ba69b8e0de5 |
children | 43d6c08d7e96 |
rev | line source |
---|---|
2086 | 1 /* This file is part of the Project Athena Zephyr Notification System. |
2 * It contains source for the ZInitialize function. | |
3 * | |
4 * Created by: Robert French | |
5 * | |
6 * $Source$ | |
7 * $Author: warmenhoven $ | |
8 * | |
9 * Copyright (c) 1987, 1991 by the Massachusetts Institute of Technology. | |
10 * For copying and distribution information, see the file | |
11 * "mit-copyright.h". | |
12 */ | |
13 /* $Header$ */ | |
14 | |
15 #ifndef lint | |
16 static char rcsid_ZInitialize_c[] = | |
17 "$Zephyr: /afs/athena.mit.edu/astaff/project/zephyr/src/lib/RCS/ZInitialize.c,v 1.17 89/05/30 18:11:25 jtkohl Exp $"; | |
18 #endif | |
19 | |
20 #include <internal.h> | |
21 | |
22 #include <sys/socket.h> | |
23 #ifdef ZEPHYR_USES_KERBEROS | |
24 #include <krb_err.h> | |
25 #endif | |
26 | |
2419
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
27 #ifndef INADDR_NONE |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
28 #define INADDR_NONE 0xffffffff |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
29 #endif |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
30 |
2086 | 31 Code_t ZInitialize() |
32 { | |
33 struct servent *hmserv; | |
2419
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
34 struct hostent *hostent; |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
35 char addr[4], hostname[MAXHOSTNAMELEN]; |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
36 struct in_addr servaddr; |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
37 struct sockaddr_in sin; |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
38 int s, sinsize = sizeof(sin); |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
39 Code_t code; |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
40 ZNotice_t notice; |
2086 | 41 #ifdef ZEPHYR_USES_KERBEROS |
2419
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
42 char *krealm = NULL; |
2086 | 43 int krbval; |
2419
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
44 char d1[ANAME_SZ], d2[INST_SZ]; |
2086 | 45 |
46 initialize_krb_error_table(); | |
47 #endif | |
48 | |
49 initialize_zeph_error_table(); | |
50 | |
51 (void) memset((char *)&__HM_addr, 0, sizeof(__HM_addr)); | |
52 | |
53 __HM_addr.sin_family = AF_INET; | |
54 | |
55 /* Set up local loopback address for HostManager */ | |
56 addr[0] = 127; | |
57 addr[1] = 0; | |
58 addr[2] = 0; | |
59 addr[3] = 1; | |
60 | |
61 hmserv = (struct servent *)getservbyname(HM_SVCNAME, "udp"); | |
62 __HM_addr.sin_port = (hmserv) ? hmserv->s_port : HM_SVC_FALLBACK; | |
63 | |
64 (void) memcpy((char *)&__HM_addr.sin_addr, addr, 4); | |
65 | |
66 __HM_set = 0; | |
67 | |
2419
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
68 /* Initialize the input queue */ |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
69 __Q_Tail = NULL; |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
70 __Q_Head = NULL; |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
71 |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
72 /* if the application is a server, there might not be a zhm. The |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
73 code will fall back to something which might not be "right", |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
74 but this is is ok, since none of the servers call krb_rd_req. */ |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
75 |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
76 servaddr.s_addr = INADDR_NONE; |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
77 if (! __Zephyr_server) { |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
78 if ((code = ZOpenPort(NULL)) != ZERR_NONE) |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
79 return(code); |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
80 |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
81 if ((code = ZhmStat(NULL, ¬ice)) != ZERR_NONE) |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
82 return(code); |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
83 |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
84 ZClosePort(); |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
85 |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
86 /* the first field, which is NUL-terminated, is the server name. |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
87 If this code ever support a multiplexing zhm, this will have to |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
88 be made smarter, and probably per-message */ |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
89 |
2086 | 90 #ifdef ZEPHYR_USES_KERBEROS |
2419
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
91 krealm = krb_realmofhost(notice.z_message); |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
92 #endif |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
93 hostent = gethostbyname(notice.z_message); |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
94 if (hostent && hostent->h_addrtype == AF_INET) |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
95 memcpy(&servaddr, hostent->h_addr, sizeof(servaddr)); |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
96 |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
97 ZFreeNotice(¬ice); |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
98 } |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
99 |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
100 #ifdef ZEPHYR_USES_KERBEROS |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
101 if (krealm) { |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
102 strcpy(__Zephyr_realm, krealm); |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
103 } else if ((krb_get_tf_fullname(TKT_FILE, d1, d2, __Zephyr_realm) |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
104 != KSUCCESS) && |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
105 ((krbval = krb_get_lrealm(__Zephyr_realm, 1)) != KSUCCESS)) { |
2086 | 106 return (krbval); |
2419
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
107 } |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
108 #else |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
109 strcpy(__Zephyr_realm, "local-realm"); |
2086 | 110 #endif |
111 | |
2419
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
112 __My_addr.s_addr = INADDR_NONE; |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
113 if (servaddr.s_addr != INADDR_NONE) { |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
114 /* Try to get the local interface address by connecting a UDP |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
115 * socket to the server address and getting the local address. |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
116 * Some broken operating systems (e.g. Solaris 2.0-2.5) yield |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
117 * INADDR_ANY (zero), so we have to check for that. */ |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
118 s = socket(AF_INET, SOCK_DGRAM, 0); |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
119 if (s != -1) { |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
120 memset(&sin, 0, sizeof(sin)); |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
121 sin.sin_family = AF_INET; |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
122 memcpy(&sin.sin_addr, &servaddr, sizeof(servaddr)); |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
123 sin.sin_port = HM_SRV_SVC_FALLBACK; |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
124 if (connect(s, (struct sockaddr *) &sin, sizeof(sin)) == 0 |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
125 && getsockname(s, (struct sockaddr *) &sin, &sinsize) == 0 |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
126 && sin.sin_addr.s_addr != 0) |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
127 memcpy(&__My_addr, &sin.sin_addr, sizeof(__My_addr)); |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
128 close(s); |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
129 } |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
130 } |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
131 if (__My_addr.s_addr == INADDR_NONE) { |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
132 /* We couldn't figure out the local interface address by the |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
133 * above method. Try by resolving the local hostname. (This |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
134 * is a pretty broken thing to do, and unfortunately what we |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
135 * always do on server machines.) */ |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
136 if (gethostname(hostname, sizeof(hostname)) == 0) { |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
137 hostent = gethostbyname(hostname); |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
138 if (hostent && hostent->h_addrtype == AF_INET) |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
139 memcpy(&__My_addr, hostent->h_addr, sizeof(__My_addr)); |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
140 } |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
141 } |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
142 /* If the above methods failed, zero out __My_addr so things will |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
143 * sort of kind of work. */ |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
144 if (__My_addr.s_addr == INADDR_NONE) |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
145 __My_addr.s_addr = 0; |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
146 |
2086 | 147 /* Get the sender so we can cache it */ |
148 (void) ZGetSender(); | |
149 | |
150 return (ZERR_NONE); | |
151 } | |
2419
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
152 |