--- /dev/null
+/*
+ * $Source$
+ * $Header$
+ */
+
+#ifndef lint
+static char *rcsid_test_c = "$Header$";
+#endif lint
+
+/*
+ * $Source$
+ * $Author$
+ * $Header$
+ *
+ * Copyright (C) 1987 by the Massachusetts Institute of Technology
+ *
+ * $Log$
+ * Revision 1.1 1987-08-22 18:31:59 wesommer
+ * Initial revision
+ *
+ */
+
+#ifndef lint
+static char *rcsid_test_c = "$Header$";
+#endif lint
+
+#include <stdio.h>
+#include <sms.h>
+#include <ss.h>
+
+int ss;
+extern ss_request_table sms_test;
+
+#ifndef __SABER__
+main(argc, argv)
+ int argc;
+ char **argv;
+#else __SABER__
+sms()
+#endif __SABER__
+{
+ int status;
+ char *whoami;
+
+#ifndef __SABER__
+ whoami = argv[0];
+#else
+ whoami = "sms";
+#endif __SABER__
+
+ init_ss_err_tbl();
+ init_sms_err_tbl();
+ init_krb_err_tbl();
+
+ ss = ss_create_invocation("sms", "0.1", (char *)NULL,
+ &sms_test, &status);
+ if (status != 0) {
+ com_err(whoami, status, "Unable to create invocation");
+ exit(1);
+ }
+ ss_listen(ss, &status);
+ if (status != 0) {
+ com_err(whoami, status, 0);
+ exit(1);
+ }
+}
+
+test_noop()
+{
+ int status = sms_noop();
+ if (status) ss_perror(ss, status, 0);
+}
+
+test_connect()
+{
+ int status = sms_connect();
+ if (status) ss_perror(ss, status, 0);
+}
+
+test_disconnect()
+{
+ int status = sms_disconnect();
+ if (status) ss_perror(ss, status, 0);
+}
+
+test_auth()
+{
+ int status = sms_auth();
+ if (status) ss_perror(ss, status, 0);
+}
+
+char *concat(str1, str2)
+ char *str1, *str2;
+{
+ char *rtn;
+ extern char *malloc();
+
+ if (!str1) {
+ int len = strlen(str2) + 1 ;
+ rtn = malloc(len);
+ bcopy(str2, rtn, len);
+ } else {
+ int len1 = strlen(str1);
+ int len2 = strlen(str2) + 1;
+ rtn = malloc(len1+len2);
+ bcopy(str1, rtn, len1);
+ bcopy(str2, rtn+len1, len2);
+ }
+ return rtn;
+}
+
+test_shutdown(argc, argv)
+ int argc;
+ char **argv;
+{
+ char *reason = NULL;
+ int status, i;
+
+ if (argc < 2) {
+ ss_perror(ss, 0, "Usage: shutdown reason ...");
+ return;
+ }
+
+ for (i = 1 ; i < argc; i++) {
+ if (i != 1) reason = concat(reason, " ");
+ reason = concat(reason, argv[i]);
+ }
+ status = sms_shutdown(reason);
+ if (status) ss_perror(ss, status, 0);
+}
+static int count;
+
+
+print_reply(argc, argv)
+ int argc;
+ char **argv;
+{
+ int i;
+ for (i = 0; i < argc; i++) {
+ if (i != 0) printf(", ");
+ printf("%s", argv[i]);
+ }
+ printf("\n");
+ count++;
+}
+
+test_query(argc, argv)
+ int argc;
+ char **argv;
+{
+ int status;
+ if (argc < 2) {
+ ss_perror(ss, 0, "Usage: query handle [ args ... ]");
+ return;
+ }
+ count = 0;
+ status = sms_query(argv[1], argc-2, argv+2, print_reply, (char *)NULL);
+ printf("%d tuples\n", count);
+ if (status) ss_perror(ss, status, 0);
+}
+
+test_access(argc, argv)
+ int argc;
+ char **argv;
+{
+ int status;
+ if (argc < 2) {
+ ss_perror(ss, 0, "Usage: access handle [ args ... ]");
+ return;
+ }
+ status = sms_access(argv[1], argc-2, argv+2);
+ if (status) ss_perror(ss, status, 0);
+}
+
--- /dev/null
+/*
+ * $Source$
+ * $Author$
+ * $Header$
+ *
+ * Copyright (C) 1987 by the Massachusetts Institute of Technology
+ *
+ * $Log$
+ * Revision 1.1 1987-08-22 18:39:29 wesommer
+ * Initial revision
+ *
+ */
+
+#ifndef lint
+static char *rcsid_reg_stubs_c = "$Header$";
+#endif lint
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <des.h>
+#include <errno.h>
+#include "ureg_err.h"
+#include "ureg_proto.h"
+#include <strings.h>
+
+static int reg_sock = -1;
+extern errno;
+#define UNKNOWN_HOST -1
+#define UNKNOWN_SERVICE -2
+
+ureg_init()
+{
+ struct servent *sp;
+ struct hostent *hp;
+ struct sockaddr_in sin;
+
+ init_ureg_err_tbl();
+ init_sms_err_tbl();
+
+ hp = gethostbyname("sms.mit.edu");
+ if (hp == NULL) return UNKNOWN_HOST;
+
+ sp = getservbyname("sms_ureg", "udp");
+
+ if (sp == NULL) return UNKNOWN_SERVICE;
+
+ (void) close(reg_sock);
+ reg_sock = socket(AF_INET, SOCK_DGRAM, 0);
+ if (reg_sock < 0) return errno;
+
+ bzero((char *)&sin, sizeof(sin));
+ sin.sin_port = sp->s_port;
+ bcopy(hp->h_addr, (char *)&sin.sin_addr, sizeof(struct in_addr));
+ sin.sin_family = AF_INET;
+
+ if (connect(reg_sock, &sin, sizeof(sin)) < 0)
+ return errno;
+ return 0;
+}
+
+static int seq_no = 0;
+
+int
+verify_user(first, last, idnumber, hashidnumber, login)
+ char *first, *last, *idnumber, *hashidnumber, *login;
+{
+ char buf[1024];
+ int version = ntohl((u_long)1);
+ int call = ntohl((u_long)UREG_VERIFY_USER);
+ C_Block key;
+ Key_schedule ks;
+ register char *bp = buf;
+ register int len;
+ char crypt_src[1024];
+
+ bcopy((char *)&version, bp, sizeof(int));
+ bp += sizeof(int);
+ seq_no++;
+ bcopy((char *)&seq_no, bp, sizeof(int));
+
+ bp += sizeof(int);
+
+ bcopy((char *)&call, bp, sizeof(int));
+
+ bp += sizeof(int);
+
+ (void) strcpy(bp, first);
+ bp += strlen(bp)+1;
+
+ (void) strcpy(bp, last);
+ bp += strlen(bp)+1;
+
+ len = strlen(idnumber) + 1;
+ bcopy(idnumber, crypt_src, len);
+
+ bcopy(hashidnumber, crypt_src+len, 13);
+
+ string_to_key(hashidnumber, key);
+ key_sched(key, ks);
+ pcbc_encrypt(crypt_src, bp, len+14, ks, key, 1);
+ bp += len+14+8;
+ len = bp - buf;
+ return do_call(buf, len, seq_no, login);
+}
+
+grab_login(first, last, idnumber, hashidnumber, login)
+ char *first, *last, *idnumber, *hashidnumber, *login;
+{
+ char buf[1024];
+ int version = ntohl((u_long)1);
+ int call = ntohl((u_long)UREG_RESERVE_LOGIN);
+ C_Block key;
+ Key_schedule ks;
+ register char *bp = buf;
+ register int len;
+ int i;
+
+ char crypt_src[1024];
+ char *cbp;
+
+ bcopy((char *)&version, bp, sizeof(int));
+ bp += sizeof(int);
+ seq_no++;
+ bcopy((char *)&seq_no, bp, sizeof(int));
+
+ bp += sizeof(int);
+
+ bcopy((char *)&call, bp, sizeof(int));
+
+ bp += sizeof(int);
+
+ (void) strcpy(bp, first);
+ bp += strlen(bp)+1;
+
+ (void) strcpy(bp, last);
+ bp += strlen(bp)+1;
+
+ len = strlen(idnumber) + 1;
+ cbp = crypt_src;
+
+ bcopy(idnumber, crypt_src, len);
+ cbp += len;
+
+ bcopy(hashidnumber, cbp, 14);
+ cbp += 14;
+
+ len = strlen(login) + 1;
+ bcopy(login, cbp, len);
+ cbp += len;
+
+ len = cbp - crypt_src;
+ string_to_key(hashidnumber, key);
+ key_sched(key, ks);
+ pcbc_encrypt(crypt_src, bp, len, ks, key, 1);
+#ifdef notdef
+ for (i = 0; i < len; i++) {
+ printf("%02.2x ", (unsigned char)bp[i]);
+ }
+ printf("\n");
+#endif notdef
+ len = ((len + 7) >> 3) << 3;
+ bp += len;
+
+ len = bp - buf;
+ return do_call(buf, len, seq_no, 0);
+
+}
+
+set_password(first, last, idnumber, hashidnumber, password)
+ char *first, *last, *idnumber, *hashidnumber, *password;
+{
+ char buf[1024];
+ int version = ntohl((u_long)1);
+ int call = ntohl((u_long)UREG_SET_PASSWORD);
+ C_Block key;
+ Key_schedule ks;
+ register char *bp = buf;
+ register int len;
+ int i;
+
+ char crypt_src[1024];
+ char *cbp;
+
+ bcopy((char *)&version, bp, sizeof(int));
+ bp += sizeof(int);
+ seq_no++;
+ bcopy((char *)&seq_no, bp, sizeof(int));
+
+ bp += sizeof(int);
+
+ bcopy((char *)&call, bp, sizeof(int));
+
+ bp += sizeof(int);
+
+ (void) strcpy(bp, first);
+ bp += strlen(bp)+1;
+
+ (void) strcpy(bp, last);
+ bp += strlen(bp)+1;
+
+ len = strlen(idnumber) + 1;
+ cbp = crypt_src;
+
+ bcopy(idnumber, crypt_src, len);
+ cbp += len;
+
+ bcopy(hashidnumber, cbp, 14);
+ cbp += 14;
+
+ len = strlen(password) + 1;
+ bcopy(password, cbp, len);
+ cbp += len;
+
+ len = cbp - crypt_src;
+ string_to_key(hashidnumber, key);
+ key_sched(key, ks);
+ pcbc_encrypt(crypt_src, bp, len, ks, key, 1);
+#ifdef notdef
+ for (i = 0; i < len; i++) {
+ printf("%02.2x ", (unsigned char)bp[i]);
+ }
+ printf("\n");
+#endif notdef
+ len = ((len + 7) >> 3) << 3;
+ bp += len;
+
+ len = bp - buf;
+ return do_call(buf, len, seq_no, 0);
+
+}
+
+static do_call(buf, len, seq_no, login)
+ char *buf;
+ char *login;
+ int seq_no;
+ int len;
+{
+ struct timeval timeout;
+ char ibuf[1024];
+ fd_set set;
+
+ int retry = 0;
+
+ do {
+ if (write(reg_sock, buf, len) != len) return errno;
+
+ FD_ZERO(&set);
+ FD_SET(reg_sock, &set);
+ timeout.tv_sec = 10;
+ timeout.tv_usec = 0;
+ do {
+ int rtn;
+ struct sockaddr_in sin;
+ int addrlen = sizeof(sin);
+ int vno;
+ int sno;
+ int stat;
+
+ rtn = select(reg_sock+1, &set, (fd_set *)0, (fd_set *)0, &timeout);
+ if (rtn == 0)
+ break;
+ else if (rtn < 0) return errno;
+
+ len = recvfrom(reg_sock, ibuf, BUFSIZ, 0, &sin, &addrlen);
+ if (len < 0) return errno;
+ if (len < 12) return UREG_BROKEN_PACKET;
+ bcopy(ibuf, (char *)&vno, sizeof(long));
+ vno = ntohl((u_long)vno);
+ if (vno != 1) continue;
+ bcopy(ibuf + 4, (char *)&sno, sizeof(long));
+
+ if (sno != seq_no) continue;
+
+ bcopy(ibuf + 8, (char *)&stat, sizeof(long));
+ stat = ntohl((u_long)stat);
+ if (login) {
+ bcopy(ibuf+12, login, len-12);
+ login[len-12] = '\0';
+ }
+ return stat;
+ } while (1);
+ } while (++retry < 6);
+ return ETIMEDOUT;
+}
+
+/*
+ * Local Variables:
+ * mode: c
+ * c-indent-level: 4
+ * c-continued-statement-offset: 4
+ * c-brace-offset: -4
+ * c-argdecl-indent: 4
+ * c-label-offset: -4
+ * End:
+ */