diff options
author | Robert S. French <rfrench@mit.edu> | 1987-07-05 22:09:03 +0000 |
---|---|---|
committer | Robert S. French <rfrench@mit.edu> | 1987-07-05 22:09:03 +0000 |
commit | 6d052aeba968f16100de9e59add743abcfb06094 (patch) | |
tree | 368c868683b79102cca00e89abbe29987573e639 | |
parent | 63e063c0681783c90e604aa788dc4e9e52f0719b (diff) |
safety
-rw-r--r-- | lib/ZFmtList.c | 9 | ||||
-rw-r--r-- | lib/ZFmtNotice.c | 8 | ||||
-rw-r--r-- | lib/ZLocateU.c | 6 | ||||
-rw-r--r-- | lib/ZLocations.c | 87 | ||||
-rw-r--r-- | lib/ZMkAuth.c | 49 | ||||
-rw-r--r-- | lib/ZParseNot.c | 110 | ||||
-rw-r--r-- | lib/ZReadAscii.c | 2 | ||||
-rw-r--r-- | lib/ZSendList.c | 6 | ||||
-rw-r--r-- | lib/ZSendNot.c | 8 | ||||
-rw-r--r-- | lib/ZSendPkt.c | 13 | ||||
-rw-r--r-- | lib/ZSubs.c | 92 |
11 files changed, 257 insertions, 133 deletions
diff --git a/lib/ZFmtList.c b/lib/ZFmtList.c index 779511a..8db8cbb 100644 --- a/lib/ZFmtList.c +++ b/lib/ZFmtList.c @@ -16,22 +16,23 @@ #include <zephyr/zephyr_internal.h> -Code_t ZFormatNoticeList(notice,list,nitems,buffer,buffer_len,ret_len,cert) +Code_t ZFormatNoticeList(notice,list,nitems,buffer,buffer_len,ret_len, + cert_routine) ZNotice_t *notice; char *list[]; int nitems; ZPacket_t buffer; int buffer_len; int *ret_len; - int cert; + int (*cert_routine)(); { char *ptr,*end; Code_t retval; end = buffer+buffer_len; - if ((retval = Z_FormatHeader(notice,buffer,buffer_len,ret_len,cert)) != - ZERR_NONE) + if ((retval = Z_FormatHeader(notice,buffer,buffer_len,ret_len, + cert_routine)) != ZERR_NONE) return (retval); ptr = buffer+*ret_len; diff --git a/lib/ZFmtNotice.c b/lib/ZFmtNotice.c index 54d9933..9e90e12 100644 --- a/lib/ZFmtNotice.c +++ b/lib/ZFmtNotice.c @@ -16,19 +16,19 @@ #include <zephyr/zephyr.h> -Code_t ZFormatNotice(notice,buffer,buffer_len,len,cert) +Code_t ZFormatNotice(notice,buffer,buffer_len,len,cert_routine) ZNotice_t *notice; ZPacket_t buffer; int buffer_len; int *len; - int cert; + int (*cert_routine)(); { char *ptr; int hdrlen; Code_t retval; - if ((retval = Z_FormatHeader(notice,buffer,buffer_len,&hdrlen,cert)) != - ZERR_NONE) + if ((retval = Z_FormatHeader(notice,buffer,buffer_len,&hdrlen, + cert_routine)) != ZERR_NONE) return (retval); ptr = buffer+hdrlen; diff --git a/lib/ZLocateU.c b/lib/ZLocateU.c index abe537e..5514358 100644 --- a/lib/ZLocateU.c +++ b/lib/ZLocateU.c @@ -22,7 +22,7 @@ Code_t ZLocateUser(user,nlocs) { int locate_pred(); - int i,retval,auth; + int i,retval; ZNotice_t notice,retnotice; ZPacket_t buffer; char *ptr,*end; @@ -41,10 +41,10 @@ Code_t ZLocateUser(user,nlocs) notice.z_recipient = ""; notice.z_message_len = 0; - if ((retval = ZSendNotice(¬ice,0)) != ZERR_NONE) + if ((retval = ZSendNotice(¬ice,ZNOAUTH)) != ZERR_NONE) return (retval); - if ((retval = ZIfNotice(buffer,sizeof buffer,&retnotice,&auth, + if ((retval = Z_NoAuthIfNotice(buffer,sizeof buffer,&retnotice, ZCompareUIDPred,(char *)¬ice.z_uid)) != ZERR_NONE) return (retval); diff --git a/lib/ZLocations.c b/lib/ZLocations.c index 76c80e5..e831eaf 100644 --- a/lib/ZLocations.c +++ b/lib/ZLocations.c @@ -1,5 +1,6 @@ /* This file is part of the Project Athena Zephyr Notification System. - * It contains source for the ZSetLocation function. + * It contains source for the ZSetLocation, ZUnsetLocation, ZHideLocation, + * and ZUnhideLocation functions. * * Created by: Robert French * @@ -18,6 +19,8 @@ #include <pwd.h> #include <sys/file.h> +#include <sys/param.h> +#include <netdb.h> uid_t getuid(); @@ -37,3 +40,85 @@ Code_t ZSetLocation() return (Z_SendLocation(LOGIN_CLASS,quiet?LOGIN_QUIET_LOGIN: LOGIN_USER_LOGIN)); } + +Code_t ZUnsetLocation() +{ + return (Z_SendLocation(LOGIN_CLASS,LOGIN_USER_LOGOUT)); +} + +Code_t ZHideLocation() +{ + return (Z_SendLocation(LOCATE_CLASS,LOCATE_HIDE)); +} + +Code_t ZUnhideLocation() +{ + return (Z_SendLocation(LOCATE_CLASS,LOCATE_UNHIDE)); +} + +Z_SendLocation(class,opcode) + char *class; + char *opcode; +{ + char *ttyname(),*ctime(); + + int retval; + long ourtime; + ZNotice_t notice,retnotice; + ZPacket_t buffer; + char *bptr[2],host[MAXHOSTNAMELEN]; + struct hostent *hent; + + notice.z_kind = ACKED; + notice.z_port = 0; + notice.z_class = class; + notice.z_class_inst = ZGetSender(); + notice.z_opcode = opcode; + notice.z_sender = 0; + notice.z_recipient = ""; + + if (gethostname(host,MAXHOSTNAMELEN) < 0) + return (errno); + + hent = gethostbyname(host); + if (!hent) + bptr[0] = "unknown"; + else { + (void) strcpy(host,hent->h_name); + bptr[0] = host; + } + + ourtime = time((long *)0); + bptr[1] = ctime(&ourtime); + bptr[1][strlen(bptr[1])-1] = '\0'; + + if ((retval = ZSendList(¬ice,bptr,2,ZAUTH)) != ZERR_NONE) + return (retval); + + if ((retval = ZIfNotice(buffer,sizeof buffer,&retnotice,(int *)0, + ZCompareUIDPred,(char *)¬ice.z_uid)) != + ZERR_NONE) + return (retval); + + if (retnotice.z_kind == SERVNAK) { + if (!retnotice.z_message_len) + return (ZERR_SERVNAK); + if (!strcmp(retnotice.z_message,ZSRVACK_NOTSENT)) + return (ZERR_AUTHFAIL); + if (!strcmp(retnotice.z_message,ZSRVACK_FAIL)) + return (ZERR_LOGINFAIL); + return (ZERR_SERVNAK); + } + + if (retnotice.z_kind != SERVACK) + return (ZERR_INTERNAL); + + if (!retnotice.z_message_len) + return (ZERR_INTERNAL); + + if (strcmp(retnotice.z_message,ZSRVACK_SENT) && + strcmp(retnotice.z_message,ZSRVACK_NOTSENT)) + return (ZERR_INTERNAL); + + return (ZERR_NONE); +} diff --git a/lib/ZMkAuth.c b/lib/ZMkAuth.c new file mode 100644 index 0000000..23b54da --- /dev/null +++ b/lib/ZMkAuth.c @@ -0,0 +1,49 @@ +/* This file is part of the Project Athena Zephyr Notification System. + * It contains source for the internal Zephyr routines. + * + * 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 ZMakeAuthentication(notice,buffer,buffer_len,len) + ZNotice_t *notice; + ZPacket_t buffer; + int buffer_len; + int *len; +{ + int retval,result; + KTEXT_ST authent; + + notice->z_auth = 1; + if ((result = mk_ap_req(&authent,SERVER_SERVICE, + SERVER_INSTANCE,__Zephyr_realm,0)) + != MK_AP_OK) + return (result+krb_err_base); + notice->z_authent_len = authent.length; + notice->z_ascii_authent = (char *)malloc((unsigned)authent.length*3); + if (!notice->z_ascii_authent) + return (ENOMEM); + if ((retval = ZMakeAscii(notice->z_ascii_authent, + authent.length*3, + authent.dat, + authent.length)) != ZERR_NONE) { + free(notice->z_ascii_authent); + return (retval); + } + retval = Z_FormatRawHeader(notice,buffer,buffer_len,len); + free(notice->z_ascii_authent); + notice->z_authent_len = 0; + + return (retval); +} diff --git a/lib/ZParseNot.c b/lib/ZParseNot.c index d0c84b3..af13a34 100644 --- a/lib/ZParseNot.c +++ b/lib/ZParseNot.c @@ -23,112 +23,8 @@ Code_t ZParseNotice(buffer,len,notice,auth,from) int *auth; struct sockaddr_in *from; { - char *ptr,*end,*cksum,srcprincipal[ANAME_SZ+INST_SZ+REALM_SZ+4]; - int result; - unsigned int temp[3]; - AUTH_DAT dat; - KTEXT_ST authent; - ZChecksum_t our_checksum; - CREDENTIALS cred; - - ptr = buffer; - end = buffer+len; - - if (ZReadAscii(ptr,end-ptr,(char *)temp,sizeof(int)) == ZERR_BADFIELD) - return (ZERR_BADPKT); - ptr += strlen(ptr)+1; - - if (*temp != ZVERSION) - return (ZERR_VERS); + extern int ZCheckAuthentication(); - if (ZReadAscii(ptr,end-ptr,(char *)temp,sizeof(int)) == ZERR_BADFIELD) - return (ZERR_BADPKT); - notice->z_kind = (ZNotice_Kind_t)*temp; - ptr += strlen(ptr)+1; - - if (ZReadAscii(ptr,end-ptr,(char *)temp,sizeof(ZUnique_Id_t)) == - ZERR_BADFIELD) - return (ZERR_BADPKT); - bcopy((char *)temp,(char *)¬ice->z_uid,sizeof(ZUnique_Id_t)); - ptr += strlen(ptr)+1; - - if (ZReadAscii(ptr,end-ptr,(char *)temp,sizeof(u_short)) == - ZERR_BADFIELD) - return (ZERR_BADPKT); - notice->z_port = (u_short)*temp; - ptr += strlen(ptr)+1; - - if (ZReadAscii(ptr,end-ptr,(char *)temp,sizeof(int)) == ZERR_BADFIELD) - return (ZERR_BADPKT); - notice->z_auth = *temp; - ptr += strlen(ptr)+1; - - if (ZReadAscii(ptr,end-ptr,(char *)temp,sizeof(int)) == ZERR_BADFIELD) - return (ZERR_BADPKT); - notice->z_authent_len = *temp; - ptr += strlen(ptr)+1; - - notice->z_ascii_authent = ptr; - ptr += strlen(ptr)+1; - notice->z_class = ptr; - ptr += strlen(ptr)+1; - notice->z_class_inst = ptr; - ptr += strlen(ptr)+1; - notice->z_opcode = ptr; - ptr += strlen(ptr)+1; - notice->z_sender = ptr; - ptr += strlen(ptr)+1; - notice->z_recipient = ptr; - ptr += strlen(ptr)+1; - - cksum = ptr; - - if (ZReadAscii(ptr,end-ptr,(char *)¬ice->z_checksum, - sizeof(ZChecksum_t)) - == ZERR_BADFIELD) - return (ZERR_BADPKT); - ptr += strlen(ptr)+1; - - notice->z_message = (caddr_t) ptr; - notice->z_message_len = len-(ptr-buffer); - - if (!auth) - return (ZERR_NONE); - if (!notice->z_auth) { - *auth = 0; - return (ZERR_NONE); - } - - if (__Zephyr_server) { - if (ZReadAscii(notice->z_ascii_authent, - strlen(notice->z_ascii_authent)+1, - (char *)authent.dat, - notice->z_authent_len) == ZERR_BADFIELD) { - *auth = 0; - return (ZERR_NONE); - } - authent.length = notice->z_authent_len; - result = rd_ap_req(&authent,SERVER_SERVICE, - SERVER_INSTANCE,from->sin_addr.s_addr, - &dat,SERVER_SRVTAB); - bcopy((char *)dat.session,(char *)__Zephyr_session, - sizeof(C_Block)); - *auth = (result == RD_AP_OK); - (void) sprintf(srcprincipal,"%s%s%s@%s",dat.pname, - dat.pinst[0]?".":"",dat.pinst,dat.prealm); - if (strcmp(srcprincipal,notice->z_sender)) - *auth = 0; - return (ZERR_NONE); - } - - if (result = get_credentials(SERVER_SERVICE,SERVER_INSTANCE, - __Zephyr_realm,&cred)) - return (result+krb_err_base); - - our_checksum = (ZChecksum_t)quad_cksum(buffer,NULL,cksum-buffer,0, - cred.session); - - *auth = (our_checksum == notice->z_checksum); - - return (ZERR_NONE); + return (Z_InternalParseNotice(buffer,len,notice,auth,from, + ZCheckAuthentication)); } diff --git a/lib/ZReadAscii.c b/lib/ZReadAscii.c index fdcd2f7..ea84650 100644 --- a/lib/ZReadAscii.c +++ b/lib/ZReadAscii.c @@ -1,5 +1,5 @@ /* This file is part of the Project Athena Zephyr Notification System. - * It contains source for the ZParseNotice function. + * It contains source for the ZReadAscii function. * * Created by: Robert French * diff --git a/lib/ZSendList.c b/lib/ZSendList.c index 3df8cca..3e4520c 100644 --- a/lib/ZSendList.c +++ b/lib/ZSendList.c @@ -16,11 +16,11 @@ #include <zephyr/zephyr_internal.h> -Code_t ZSendList(notice,list,nitems,cert) +Code_t ZSendList(notice,list,nitems,cert_routine) ZNotice_t *notice; char *list[]; int nitems; - int cert; + int (*cert_routine)(); { Code_t retval; char *buffer; @@ -31,7 +31,7 @@ Code_t ZSendList(notice,list,nitems,cert) return (ENOMEM); if ((retval = ZFormatNoticeList(notice,list,nitems,buffer, - Z_MAXPKTLEN,&len,cert)) + Z_MAXPKTLEN,&len,cert_routine)) != ZERR_NONE) { free(buffer); return (retval); diff --git a/lib/ZSendNot.c b/lib/ZSendNot.c index 12f67c0..51b62a2 100644 --- a/lib/ZSendNot.c +++ b/lib/ZSendNot.c @@ -16,9 +16,9 @@ #include <zephyr/zephyr_internal.h> -Code_t ZSendNotice(notice,cert) +Code_t ZSendNotice(notice,cert_routine) ZNotice_t *notice; - int cert; + int (*cert_routine)(); { Code_t retval; char *buffer; @@ -28,8 +28,8 @@ Code_t ZSendNotice(notice,cert) if (!buffer) return (ENOMEM); - if ((retval = ZFormatNotice(notice,buffer,Z_MAXPKTLEN,&len,cert)) != - ZERR_NONE) { + if ((retval = ZFormatNotice(notice,buffer,Z_MAXPKTLEN,&len, + cert_routine)) != ZERR_NONE) { free(buffer); return (retval); } diff --git a/lib/ZSendPkt.c b/lib/ZSendPkt.c index eca41de..f1d95a1 100644 --- a/lib/ZSendPkt.c +++ b/lib/ZSendPkt.c @@ -24,7 +24,7 @@ Code_t ZSendPacket(packet,len) Code_t retval; struct sockaddr_in dest; struct timeval tv; - int auth,i; + int i; fd_set t1,t2,t3; ZPacket_t ackpack; ZNotice_t notice; @@ -36,8 +36,9 @@ Code_t ZSendPacket(packet,len) if ((retval = ZOpenPort((u_short *)0)) != ZERR_NONE) return (retval); - if ((retval = ZParseNotice(packet,len,¬ice,(int *)0, - (struct sockaddr_in *)0)) != ZERR_NONE) + if ((retval = Z_InternalParseNotice(packet,len,¬ice,(int *)0, + (struct sockaddr_in *)0),(int (*)())0) + != ZERR_NONE) return (retval); dest = ZGetDestAddr(); @@ -56,9 +57,9 @@ Code_t ZSendPacket(packet,len) for (i=0;i<HM_TIMEOUT*2;i++) { if (select(0,&t1,&t2,&t3,&tv) < 0) return (errno); - retval = ZCheckIfNotice(ackpack,sizeof ackpack,¬ice, - &auth,ZCompareUIDPred, - (char *)¬ice.z_uid); + retval = Z_NoAuthCheckIfNotice(ackpack,sizeof ackpack,¬ice, + ZCompareUIDPred, + (char *)¬ice.z_uid); if (retval == ZERR_NONE) return (ZERR_NONE); if (retval != ZERR_NONOTICE) diff --git a/lib/ZSubs.c b/lib/ZSubs.c new file mode 100644 index 0000000..7587f3a --- /dev/null +++ b/lib/ZSubs.c @@ -0,0 +1,92 @@ +/* This file is part of the Project Athena Zephyr Notification System. + * It contains source for the ZSubscribeTo, ZUnsubscribeTo, and + * ZCancelSubscriptions functions. + * + * 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 ZSubscribeTo(sublist,nitems,port) + ZSubscription_t *sublist; + int nitems; + u_short port; +{ + return (Z_Subscriptions(sublist,nitems,port,CLIENT_SUBSCRIBE)); +} + +Code_t ZUnsubscribeTo(sublist,nitems,port) + ZSubscription_t *sublist; + int nitems; + u_short port; +{ + return (Z_Subscriptions(sublist,nitems,port,CLIENT_UNSUBSCRIBE)); +} + +Code_t ZCancelSubscriptions(port) + u_short port; +{ + return (Z_Subscriptions((ZSubscription_t *)0,0,port, + CLIENT_CANCELSUB)); +} + +Z_Subscriptions(sublist,nitems,port,opcode) + ZSubscription_t *sublist; + int nitems; + u_short port; + char *opcode; +{ + int i,retval; + ZNotice_t notice,retnotice; + ZPacket_t buffer; + char **list; + + list = (char **)malloc((unsigned)nitems*3*sizeof(char *)); + if (!list) + return (ENOMEM); + + notice.z_kind = ACKED; + notice.z_port = port; + notice.z_class = ZEPHYR_CTL_CLASS; + notice.z_class_inst = ZEPHYR_CTL_CLIENT; + notice.z_opcode = opcode; + notice.z_sender = 0; + notice.z_recipient = ""; + notice.z_message_len = 0; + + for (i=0;i<nitems;i++) { + list[i*3] = sublist[i].class; + list[i*3+1] = sublist[i].classinst; + list[i*3+2] = sublist[i].recipient; + } + + retval = ZSendList(¬ice,list,nitems*3,ZAUTH); + + free((char *)list); + + if (retval != ZERR_NONE) + return (retval); + + if ((retval = ZIfNotice(buffer,sizeof buffer,&retnotice,(int *)0, + ZCompareUIDPred,(char *)¬ice.z_uid)) != + ZERR_NONE) + return (retval); + + if (retnotice.z_kind == SERVNAK) + return (ZERR_SERVNAK); + + if (retnotice.z_kind != SERVACK) + return (ZERR_INTERNAL); + + return (ZERR_NONE); +} |