summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/ZFlsLocs.c34
-rw-r--r--lib/ZFmtRaw.c46
-rw-r--r--lib/ZGetLocs.c42
-rw-r--r--lib/ZInit.c25
-rw-r--r--lib/ZLocateU.c85
-rw-r--r--lib/ZLocations.c33
-rw-r--r--lib/ZPeekNot.c5
-rw-r--r--lib/ZPeekPkt.c6
-rw-r--r--lib/ZRecvNot.c7
-rw-r--r--lib/ZRecvPkt.c7
-rw-r--r--lib/ZSendList.c2
-rw-r--r--lib/ZSendNot.c2
-rw-r--r--lib/ZSendPkt.c24
-rw-r--r--lib/ZSendRaw.c40
-rw-r--r--lib/ZSetDest.c27
15 files changed, 360 insertions, 25 deletions
diff --git a/lib/ZFlsLocs.c b/lib/ZFlsLocs.c
new file mode 100644
index 0000000..2f162c1
--- /dev/null
+++ b/lib/ZFlsLocs.c
@@ -0,0 +1,34 @@
+/* This file is part of the Project Athena Zephyr Notification System.
+ * It contains source for the ZFlushLocations function.
+ *
+ * Created by: Robert French
+ *
+ * $Source$
+ * $Author$
+ *
+ * Copyright (c) 1987 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, see the file
+ * "mit-copyright.h".
+ */
+/* $Header$ */
+
+#include <zephyr/mit-copyright.h>
+
+#include <zephyr/zephyr_internal.h>
+
+Code_t ZFlushLocations()
+{
+ int i;
+
+ if (!__locate_list)
+ return (ZERR_NONE);
+
+ for (i=0;i<__locate_num;i++)
+ free(__locate_list[i]);
+ free(__locate_list);
+
+ __locate_list = 0;
+ __locate_num = 0;
+
+ return (ZERR_NONE);
+}
diff --git a/lib/ZFmtRaw.c b/lib/ZFmtRaw.c
new file mode 100644
index 0000000..14b637b
--- /dev/null
+++ b/lib/ZFmtRaw.c
@@ -0,0 +1,46 @@
+/* This file is part of the Project Athena Zephyr Notification System.
+ * It contains source for the ZFormatRawNotice function.
+ *
+ * Created by: Robert French
+ *
+ * $Source$
+ * $Author$
+ *
+ * Copyright (c) 1987 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, see the file
+ * "mit-copyright.h".
+ */
+/* $Header$ */
+
+#include <zephyr/mit-copyright.h>
+
+#include <zephyr/zephyr.h>
+
+Code_t ZFormatRawNotice(notice,buffer,buffer_len,len)
+ ZNotice_t *notice;
+ ZPacket_t buffer;
+ int buffer_len;
+ int *len;
+{
+ char *ptr;
+ int hdrlen;
+ Code_t retval;
+
+ if ((retval = Z_FormatRawHeader(notice,buffer,buffer_len,&hdrlen)) !=
+ ZERR_NONE)
+ return (retval);
+
+ ptr = buffer+hdrlen;
+
+ if (notice->z_message_len+hdrlen > buffer_len)
+ return (ZERR_PKTLEN);
+
+ bcopy(notice->z_message,ptr,notice->z_message_len);
+
+ *len = hdrlen+notice->z_message_len;
+
+ if (*len > Z_MAXPKTLEN)
+ return (ZERR_PKTLEN);
+
+ return (ZERR_NONE);
+}
diff --git a/lib/ZGetLocs.c b/lib/ZGetLocs.c
new file mode 100644
index 0000000..3c2c3c9
--- /dev/null
+++ b/lib/ZGetLocs.c
@@ -0,0 +1,42 @@
+/* This file is part of the Project Athena Zephyr Notification System.
+ * It contains source for the ZGetLocations function.
+ *
+ * Created by: Robert French
+ *
+ * $Source$
+ * $Author$
+ *
+ * Copyright (c) 1987 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, see the file
+ * "mit-copyright.h".
+ */
+/* $Header$ */
+
+#include <zephyr/mit-copyright.h>
+
+#include <zephyr/zephyr_internal.h>
+
+#define min(a,b) ((a)<(b)?(a):(b))
+
+Code_t ZGetLocations(location,numlocs)
+ char *location[];
+ int *numlocs;
+{
+ int i;
+
+ if (!__locate_list)
+ return (ZERR_NOLOCATIONS);
+
+ if (__locate_next == __locate_num)
+ return (ZERR_NOMORELOCS);
+
+ for (i=0;i<min(*numlocs,__locate_num-__locate_next);i++)
+ location[i] = __locate_list[i+__locate_next];
+
+ if (__locate_num-__locate_next < *numlocs)
+ *numlocs = __locate_num-__locate_next;
+
+ __locate_next += *numlocs;
+
+ return (ZERR_NONE);
+}
diff --git a/lib/ZInit.c b/lib/ZInit.c
index 3866a5c..e0305cd 100644
--- a/lib/ZInit.c
+++ b/lib/ZInit.c
@@ -15,10 +15,35 @@
#include <zephyr/mit-copyright.h>
#include <zephyr/zephyr_internal.h>
+#include <netdb.h>
+#include <sys/socket.h>
Code_t ZInitialize()
{
+ struct servent *hmserv;
+ char addr[4];
+
init_zeph_err_tbl();
+ bzero(&__HM_addr,sizeof(__HM_addr));
+
+ __HM_addr.sin_family = AF_INET;
+
+
+ addr[0] = 127;
+ addr[1] = 0;
+ addr[2] = 0;
+ addr[3] = 1;
+
+ hmserv = (struct servent *)getservbyname("zephyr-hm","udp");
+ if (!hmserv)
+ return (ZERR_HMPORT);
+
+ __HM_addr.sin_port = hmserv->s_port;
+
+ bcopy(addr,&__HM_addr.sin_addr,4);
+
+ __HM_set = 0;
+
return (ZERR_NONE);
}
diff --git a/lib/ZLocateU.c b/lib/ZLocateU.c
new file mode 100644
index 0000000..72ccdb0
--- /dev/null
+++ b/lib/ZLocateU.c
@@ -0,0 +1,85 @@
+/* This file is part of the Project Athena Zephyr Notification System.
+ * It contains source for the ZLocateUser function.
+ *
+ * Created by: Robert French
+ *
+ * $Source$
+ * $Author$
+ *
+ * Copyright (c) 1987 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, see the file
+ * "mit-copyright.h".
+ */
+/* $Header$ */
+
+#include <zephyr/mit-copyright.h>
+
+#include <zephyr/zephyr_internal.h>
+
+Code_t ZLocateUser(user,nlocs)
+ char *user;
+ int *nlocs;
+{
+ int locate_pred();
+
+ int i,retval,auth;
+ ZNotice_t notice,retnotice;
+ ZPacket_t buffer;
+ char *ptr,*end;
+
+ retval = ZFlushLocations();
+
+ if (retval != ZERR_NONE && retval != ZERR_NOLOCATIONS)
+ return (retval);
+
+ notice.z_kind = ACKED;
+ notice.z_port = 0;
+ notice.z_class = LOCATE_CLASS;
+ notice.z_class_inst = user;
+ notice.z_opcode = LOCATE_LOCATE;
+ notice.z_sender = 0;
+ notice.z_recipient = "";
+ notice.z_message_len = 0;
+
+ if ((retval = ZSendNotice(&notice)) != ZERR_NONE)
+ return (retval);
+
+ if ((retval = ZIfNotice(buffer,sizeof buffer,&retnotice,&auth,
+ locate_pred,&notice.z_uid)) != ZERR_NONE)
+ return (retval);
+
+ if (retnotice.z_kind != SERVACK)
+ return (ZERR_INTERNAL);
+
+ end = retnotice.z_message+retnotice.z_message_len+1;
+
+ __locate_num = 0;
+
+ for (ptr=retnotice.z_message;ptr<end;ptr++)
+ if (!*ptr)
+ __locate_num++;
+
+ __locate_list = (char **)malloc(__locate_num*sizeof(char *));
+ if (!__locate_list)
+ return (ENOMEM);
+
+ for (ptr=retnotice.z_message,i=0;i<__locate_num;i++) {
+ __locate_list[i] = (char *)malloc(strlen(ptr)+1);
+ if (!__locate_list[i])
+ return (ENOMEM);
+ strcpy(__locate_list[i],ptr);
+ ptr += strlen(ptr)+1;
+ }
+
+ __locate_next = 0;
+ *nlocs = __locate_num;
+
+ return (ZERR_NONE);
+}
+
+static int locate_pred(notice,uid)
+ ZNotice_t *notice;
+ ZUnique_Id_t *uid;
+{
+ return (ZCompareUID(uid,&notice->z_uid));
+}
diff --git a/lib/ZLocations.c b/lib/ZLocations.c
new file mode 100644
index 0000000..139f793
--- /dev/null
+++ b/lib/ZLocations.c
@@ -0,0 +1,33 @@
+/* This file is part of the Project Athena Zephyr Notification System.
+ * It contains source for the ZSetLocation.c function.
+ *
+ * Created by: Robert French
+ *
+ * $Source$
+ * $Author$
+ *
+ * Copyright (c) 1987 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, see the file
+ * "mit-copyright.h".
+ */
+/* $Header$ */
+
+#include <zephyr/mit-copyright.h>
+
+#include <zephyr/zephyr_internal.h>
+
+Code_t ZSetLocation()
+{
+ ZNotice_t notice;
+
+ notice.z_kind = UNACKED;
+ notice.z_port = 0;
+ notice.z_class = LOGIN_CLASS;
+ notice.z_class_inst = (char *)Z_GetSender();
+ notice.z_opcode = LOGIN_USER_LOGIN;
+ notice.z_sender = 0;
+ notice.z_recipient = "";
+ notice.z_message_len = 0;
+
+ return (ZSendNotice(&notice));
+}
diff --git a/lib/ZPeekNot.c b/lib/ZPeekNot.c
index 9168214..cbbc610 100644
--- a/lib/ZPeekNot.c
+++ b/lib/ZPeekNot.c
@@ -16,16 +16,17 @@
#include <zephyr/zephyr_internal.h>
-Code_t ZPeekNotice(buffer,buffer_len,notice,auth)
+Code_t ZPeekNotice(buffer,buffer_len,notice,auth,from)
ZPacket_t buffer;
int buffer_len;
ZNotice_t *notice;
int *auth;
+ struct sockaddr_in *from;
{
int len;
Code_t retval;
- if ((retval = ZPeekPacket(buffer,buffer_len,&len)) !=
+ if ((retval = ZPeekPacket(buffer,buffer_len,&len,from)) !=
ZERR_NONE)
return (retval);
diff --git a/lib/ZPeekPkt.c b/lib/ZPeekPkt.c
index ff338b6..2b109fb 100644
--- a/lib/ZPeekPkt.c
+++ b/lib/ZPeekPkt.c
@@ -16,10 +16,11 @@
#include <zephyr/zephyr_internal.h>
-Code_t ZPeekPacket(buffer,buffer_len,ret_len)
+Code_t ZPeekPacket(buffer,buffer_len,ret_len,from)
ZPacket_t buffer;
int buffer_len;
int *ret_len;
+ struct sockaddr_in *from;
{
int retval;
@@ -40,6 +41,7 @@ Code_t ZPeekPacket(buffer,buffer_len,ret_len)
}
bcopy(__Q_Head->packet,buffer,*ret_len);
-
+ bcopy(&__Q_Head->from,from,sizeof(struct sockaddr_in));
+
return (retval);
}
diff --git a/lib/ZRecvNot.c b/lib/ZRecvNot.c
index 65b9514..16c5348 100644
--- a/lib/ZRecvNot.c
+++ b/lib/ZRecvNot.c
@@ -16,16 +16,17 @@
#include <zephyr/zephyr_internal.h>
-Code_t ZReceiveNotice(buffer,buffer_len,notice,auth)
+Code_t ZReceiveNotice(buffer,buffer_len,notice,auth,from)
ZPacket_t buffer;
int buffer_len;
ZNotice_t *notice;
int *auth;
+ struct sockaddr_in *from;
{
int len;
Code_t retval;
-
- if ((retval = ZReceivePacket(buffer,buffer_len,&len)) !=
+
+ if ((retval = ZReceivePacket(buffer,buffer_len,&len,from)) !=
ZERR_NONE)
return (retval);
diff --git a/lib/ZRecvPkt.c b/lib/ZRecvPkt.c
index 45caafd..42e13be 100644
--- a/lib/ZRecvPkt.c
+++ b/lib/ZRecvPkt.c
@@ -15,14 +15,14 @@
#include <zephyr/mit-copyright.h>
#include <zephyr/zephyr_internal.h>
-#include <sys/socket.h>
#define min(a,b) ((a)<(b)?(a):(b))
-Code_t ZReceivePacket(buffer,buffer_len,ret_len)
+Code_t ZReceivePacket(buffer,buffer_len,ret_len,from)
ZPacket_t buffer;
int buffer_len;
int *ret_len;
+ struct sockaddr_in *from;
{
int retval;
@@ -43,7 +43,8 @@ Code_t ZReceivePacket(buffer,buffer_len,ret_len)
}
bcopy(__Q_Head->packet,buffer,*ret_len);
-
+ bcopy(&__Q_Head->from,from,sizeof(struct sockaddr_in));
+
Z_RemQueue(__Q_Head);
return (retval);
diff --git a/lib/ZSendList.c b/lib/ZSendList.c
index 068d024..5db9105 100644
--- a/lib/ZSendList.c
+++ b/lib/ZSendList.c
@@ -27,7 +27,7 @@ Code_t ZSendList(notice,list,nitems)
buffer = (char *)malloc(Z_MAXPKTLEN);
if (!buffer)
- return (ZERR_NOMEM);
+ return (ENOMEM);
if ((retval = ZFormatNoticeList(notice,list,nitems,buffer,
Z_MAXPKTLEN,&len)) != ZERR_NONE) {
diff --git a/lib/ZSendNot.c b/lib/ZSendNot.c
index a391002..f971a9b 100644
--- a/lib/ZSendNot.c
+++ b/lib/ZSendNot.c
@@ -25,7 +25,7 @@ Code_t ZSendNotice(notice)
buffer = (char *)malloc(Z_MAXPKTLEN);
if (!buffer)
- return (ZERR_NOMEM);
+ return (ENOMEM);
if ((retval = ZFormatNotice(notice,buffer,Z_MAXPKTLEN,&len)) !=
ZERR_NONE) {
diff --git a/lib/ZSendPkt.c b/lib/ZSendPkt.c
index 7270054..60d84ae 100644
--- a/lib/ZSendPkt.c
+++ b/lib/ZSendPkt.c
@@ -24,7 +24,7 @@ Code_t ZSendPacket(packet,len)
int findack();
Code_t retval;
- struct sockaddr_in sin;
+ struct sockaddr_in dest;
struct timeval tv;
int auth,t1,t2,t3,i;
ZPacket_t ackpack;
@@ -37,22 +37,21 @@ Code_t ZSendPacket(packet,len)
if ((retval = ZOpenPort(0)) != ZERR_NONE)
return (retval);
- if ((retval = Z_GetHMPortAddr()) != ZERR_NONE)
- return (retval);
-
- sin.sin_family = AF_INET;
- sin.sin_port = htons(__HM_port);
- bcopy(__HM_addr,&sin.sin_addr,__HM_length);
-
- if (sendto(ZGetFD(),packet,len,0,&sin,sizeof(sin)) < 0)
+ dest = ZGetDestAddr();
+
+ if (sendto(ZGetFD(),packet,len,0,&dest,sizeof(dest)) < 0)
return (errno);
ZParseNotice(packet,len,&notice,&auth);
+ if (notice.z_kind == UNSAFE || notice.z_kind == HMACK ||
+ notice.z_kind == SERVACK || __HM_set)
+ return (ZERR_NONE);
+
tv.tv_sec = 0;
tv.tv_usec = 400000;
- for (i=0;i<4;i++) {
+ for (i=0;i<12;i++) {
select(0,&t1,&t2,&t3,&tv);
retval = ZCheckIfNotice(ackpack,sizeof ackpack,&notice,
&auth,findack,&notice.z_uid);
@@ -64,10 +63,9 @@ Code_t ZSendPacket(packet,len)
return (ZERR_HMDEAD);
}
-int findack(notice,uid)
+static int findack(notice,uid)
ZNotice_t *notice;
ZUnique_Id_t *uid;
{
- printf("FOO\n");
- return (!ZCompareUID(uid,&notice->z_uid));
+ return (ZCompareUID(uid,&notice->z_uid));
}
diff --git a/lib/ZSendRaw.c b/lib/ZSendRaw.c
new file mode 100644
index 0000000..0522804
--- /dev/null
+++ b/lib/ZSendRaw.c
@@ -0,0 +1,40 @@
+/* This file is part of the Project Athena Zephyr Notification System.
+ * It contains source for the ZSendRawNotice function.
+ *
+ * Created by: Robert French
+ *
+ * $Source$
+ * $Author$
+ *
+ * Copyright (c) 1987 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, see the file
+ * "mit-copyright.h".
+ */
+/* $Header$ */
+
+#include <zephyr/mit-copyright.h>
+
+#include <zephyr/zephyr_internal.h>
+
+Code_t ZSendRawNotice(notice)
+ ZNotice_t *notice;
+{
+ Code_t retval;
+ char *buffer;
+ int len;
+
+ buffer = (char *)malloc(Z_MAXPKTLEN);
+ if (!buffer)
+ return (ENOMEM);
+
+ if ((retval = ZFormatRawNotice(notice,buffer,Z_MAXPKTLEN,&len)) !=
+ ZERR_NONE) {
+ free(buffer);
+ return (retval);
+ }
+
+ retval = ZSendPacket(buffer,len);
+ free(buffer);
+
+ return (retval);
+}
diff --git a/lib/ZSetDest.c b/lib/ZSetDest.c
new file mode 100644
index 0000000..ac3dc49
--- /dev/null
+++ b/lib/ZSetDest.c
@@ -0,0 +1,27 @@
+/* This file is part of the Project Athena Zephyr Notification System.
+ * It contains source for the ZSetDestAddr function.
+ *
+ * Created by: Robert French
+ *
+ * $Source$
+ * $Author$
+ *
+ * Copyright (c) 1987 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, see the file
+ * "mit-copyright.h".
+ */
+/* $Header$ */
+
+#include <zephyr/mit-copyright.h>
+
+#include <zephyr/zephyr_internal.h>
+
+Code_t ZSetDestAddr(addr)
+ struct sockaddr_in *addr;
+{
+ __HM_addr = *addr;
+
+ __HM_set = 1;
+
+ return (ZERR_NONE);
+}