6 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, please see the file
12 static char *rcsid_reg_stubs_c = "$Header$";
15 #include <mit-copyright.h>
17 #include <sys/types.h>
19 #include <sys/socket.h>
20 #include <netinet/in.h>
25 #include "ureg_proto.h"
28 static int reg_sock = -1;
30 #define UNKNOWN_HOST -1
31 #define UNKNOWN_SERVICE -2
37 struct sockaddr_in sin;
42 hp = gethostbyname("sms.mit.edu");
43 if (hp == NULL) return UNKNOWN_HOST;
45 sp = getservbyname("sms_ureg", "udp");
47 if (sp == NULL) return UNKNOWN_SERVICE;
49 (void) close(reg_sock);
50 reg_sock = socket(AF_INET, SOCK_DGRAM, 0);
51 if (reg_sock < 0) return errno;
53 bzero((char *)&sin, sizeof(sin));
54 sin.sin_port = sp->s_port;
55 bcopy(hp->h_addr, (char *)&sin.sin_addr, sizeof(struct in_addr));
56 sin.sin_family = AF_INET;
58 if (connect(reg_sock, &sin, sizeof(sin)) < 0)
63 static int seq_no = 0;
66 verify_user(first, last, idnumber, hashidnumber, login)
67 char *first, *last, *idnumber, *hashidnumber, *login;
70 int version = ntohl((u_long)1);
71 int call = ntohl((u_long)UREG_VERIFY_USER);
74 register char *bp = buf;
78 bcopy((char *)&version, bp, sizeof(int));
81 bcopy((char *)&seq_no, bp, sizeof(int));
85 bcopy((char *)&call, bp, sizeof(int));
89 (void) strcpy(bp, first);
92 (void) strcpy(bp, last);
95 len = strlen(idnumber) + 1;
96 bcopy(idnumber, crypt_src, len);
98 bcopy(hashidnumber, crypt_src+len, 13);
100 string_to_key(hashidnumber, key);
102 pcbc_encrypt(crypt_src, bp, len+14, ks, key, 1);
105 return do_call(buf, len, seq_no, login);
108 grab_login(first, last, idnumber, hashidnumber, login)
109 char *first, *last, *idnumber, *hashidnumber, *login;
112 int version = ntohl((u_long)1);
113 int call = ntohl((u_long)UREG_RESERVE_LOGIN);
116 register char *bp = buf;
119 char crypt_src[1024];
122 bcopy((char *)&version, bp, sizeof(int));
125 bcopy((char *)&seq_no, bp, sizeof(int));
129 bcopy((char *)&call, bp, sizeof(int));
133 (void) strcpy(bp, first);
136 (void) strcpy(bp, last);
139 len = strlen(idnumber) + 1;
142 bcopy(idnumber, crypt_src, len);
145 bcopy(hashidnumber, cbp, 14);
148 len = strlen(login) + 1;
149 bcopy(login, cbp, len);
152 len = cbp - crypt_src;
153 string_to_key(hashidnumber, key);
155 pcbc_encrypt(crypt_src, bp, len, ks, key, 1);
157 for (i = 0; i < len; i++) {
158 printf("%02.2x ", (unsigned char)bp[i]);
162 len = ((len + 7) >> 3) << 3;
166 return do_call(buf, len, seq_no, 0);
170 set_password(first, last, idnumber, hashidnumber, password)
171 char *first, *last, *idnumber, *hashidnumber, *password;
174 int version = ntohl((u_long)1);
175 int call = ntohl((u_long)UREG_SET_PASSWORD);
178 register char *bp = buf;
181 char crypt_src[1024];
184 bcopy((char *)&version, bp, sizeof(int));
187 bcopy((char *)&seq_no, bp, sizeof(int));
191 bcopy((char *)&call, bp, sizeof(int));
195 (void) strcpy(bp, first);
198 (void) strcpy(bp, last);
201 len = strlen(idnumber) + 1;
204 bcopy(idnumber, crypt_src, len);
207 bcopy(hashidnumber, cbp, 14);
210 len = strlen(password) + 1;
211 bcopy(password, cbp, len);
214 len = cbp - crypt_src;
215 string_to_key(hashidnumber, key);
217 pcbc_encrypt(crypt_src, bp, len, ks, key, 1);
219 for (i = 0; i < len; i++) {
220 printf("%02.2x ", (unsigned char)bp[i]);
224 len = ((len + 7) >> 3) << 3;
228 return do_call(buf, len, seq_no, 0);
232 static do_call(buf, len, seq_no, login)
238 struct timeval timeout;
245 if (write(reg_sock, buf, len) != len) return errno;
248 FD_SET(reg_sock, &set);
253 struct sockaddr_in sin;
254 int addrlen = sizeof(sin);
259 rtn = select(reg_sock+1, &set, (fd_set *)0, (fd_set *)0, &timeout);
262 else if (rtn < 0) return errno;
264 len = recvfrom(reg_sock, ibuf, BUFSIZ, 0, &sin, &addrlen);
265 if (len < 0) return errno;
266 if (len < 12) return UREG_BROKEN_PACKET;
267 bcopy(ibuf, (char *)&vno, sizeof(long));
268 vno = ntohl((u_long)vno);
269 if (vno != 1) continue;
270 bcopy(ibuf + 4, (char *)&sno, sizeof(long));
272 if (sno != seq_no) continue;
274 bcopy(ibuf + 8, (char *)&stat, sizeof(long));
275 stat = ntohl((u_long)stat);
276 if (login && len > 12) {
277 bcopy(ibuf+12, login, len-12);
278 login[len-12] = '\0';
283 } while (++retry < 10);
291 * c-continued-statement-offset: 4
293 * c-argdecl-indent: 4