6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
9 * Revision 1.1 1987-08-22 18:39:29 wesommer
15 static char *rcsid_reg_stubs_c = "$Header$";
18 #include <sys/types.h>
20 #include <sys/socket.h>
21 #include <netinet/in.h>
26 #include "ureg_proto.h"
29 static int reg_sock = -1;
31 #define UNKNOWN_HOST -1
32 #define UNKNOWN_SERVICE -2
38 struct sockaddr_in sin;
43 hp = gethostbyname("sms.mit.edu");
44 if (hp == NULL) return UNKNOWN_HOST;
46 sp = getservbyname("sms_ureg", "udp");
48 if (sp == NULL) return UNKNOWN_SERVICE;
50 (void) close(reg_sock);
51 reg_sock = socket(AF_INET, SOCK_DGRAM, 0);
52 if (reg_sock < 0) return errno;
54 bzero((char *)&sin, sizeof(sin));
55 sin.sin_port = sp->s_port;
56 bcopy(hp->h_addr, (char *)&sin.sin_addr, sizeof(struct in_addr));
57 sin.sin_family = AF_INET;
59 if (connect(reg_sock, &sin, sizeof(sin)) < 0)
64 static int seq_no = 0;
67 verify_user(first, last, idnumber, hashidnumber, login)
68 char *first, *last, *idnumber, *hashidnumber, *login;
71 int version = ntohl((u_long)1);
72 int call = ntohl((u_long)UREG_VERIFY_USER);
75 register char *bp = buf;
79 bcopy((char *)&version, bp, sizeof(int));
82 bcopy((char *)&seq_no, bp, sizeof(int));
86 bcopy((char *)&call, bp, sizeof(int));
90 (void) strcpy(bp, first);
93 (void) strcpy(bp, last);
96 len = strlen(idnumber) + 1;
97 bcopy(idnumber, crypt_src, len);
99 bcopy(hashidnumber, crypt_src+len, 13);
101 string_to_key(hashidnumber, key);
103 pcbc_encrypt(crypt_src, bp, len+14, ks, key, 1);
106 return do_call(buf, len, seq_no, login);
109 grab_login(first, last, idnumber, hashidnumber, login)
110 char *first, *last, *idnumber, *hashidnumber, *login;
113 int version = ntohl((u_long)1);
114 int call = ntohl((u_long)UREG_RESERVE_LOGIN);
117 register char *bp = buf;
121 char crypt_src[1024];
124 bcopy((char *)&version, bp, sizeof(int));
127 bcopy((char *)&seq_no, bp, sizeof(int));
131 bcopy((char *)&call, bp, sizeof(int));
135 (void) strcpy(bp, first);
138 (void) strcpy(bp, last);
141 len = strlen(idnumber) + 1;
144 bcopy(idnumber, crypt_src, len);
147 bcopy(hashidnumber, cbp, 14);
150 len = strlen(login) + 1;
151 bcopy(login, cbp, len);
154 len = cbp - crypt_src;
155 string_to_key(hashidnumber, key);
157 pcbc_encrypt(crypt_src, bp, len, ks, key, 1);
159 for (i = 0; i < len; i++) {
160 printf("%02.2x ", (unsigned char)bp[i]);
164 len = ((len + 7) >> 3) << 3;
168 return do_call(buf, len, seq_no, 0);
172 set_password(first, last, idnumber, hashidnumber, password)
173 char *first, *last, *idnumber, *hashidnumber, *password;
176 int version = ntohl((u_long)1);
177 int call = ntohl((u_long)UREG_SET_PASSWORD);
180 register char *bp = buf;
184 char crypt_src[1024];
187 bcopy((char *)&version, bp, sizeof(int));
190 bcopy((char *)&seq_no, bp, sizeof(int));
194 bcopy((char *)&call, bp, sizeof(int));
198 (void) strcpy(bp, first);
201 (void) strcpy(bp, last);
204 len = strlen(idnumber) + 1;
207 bcopy(idnumber, crypt_src, len);
210 bcopy(hashidnumber, cbp, 14);
213 len = strlen(password) + 1;
214 bcopy(password, cbp, len);
217 len = cbp - crypt_src;
218 string_to_key(hashidnumber, key);
220 pcbc_encrypt(crypt_src, bp, len, ks, key, 1);
222 for (i = 0; i < len; i++) {
223 printf("%02.2x ", (unsigned char)bp[i]);
227 len = ((len + 7) >> 3) << 3;
231 return do_call(buf, len, seq_no, 0);
235 static do_call(buf, len, seq_no, login)
241 struct timeval timeout;
248 if (write(reg_sock, buf, len) != len) return errno;
251 FD_SET(reg_sock, &set);
256 struct sockaddr_in sin;
257 int addrlen = sizeof(sin);
262 rtn = select(reg_sock+1, &set, (fd_set *)0, (fd_set *)0, &timeout);
265 else if (rtn < 0) return errno;
267 len = recvfrom(reg_sock, ibuf, BUFSIZ, 0, &sin, &addrlen);
268 if (len < 0) return errno;
269 if (len < 12) return UREG_BROKEN_PACKET;
270 bcopy(ibuf, (char *)&vno, sizeof(long));
271 vno = ntohl((u_long)vno);
272 if (vno != 1) continue;
273 bcopy(ibuf + 4, (char *)&sno, sizeof(long));
275 if (sno != seq_no) continue;
277 bcopy(ibuf + 8, (char *)&stat, sizeof(long));
278 stat = ntohl((u_long)stat);
280 bcopy(ibuf+12, login, len-12);
281 login[len-12] = '\0';
285 } while (++retry < 6);
293 * c-continued-statement-offset: 4
295 * c-argdecl-indent: 4