#!/bin/sh # This is `snmp2.06' (part 6 of snmp2). # Do not concatenate these parts, unpack them in order with `/bin/sh'. # File `snmp2/snmplib/snmp_impl.h' is being continued... # touch -am 1231235999 $$.touch >/dev/null 2>&1 if test ! -f 1231235999 && test -f $$.touch; then shar_touch=touch else shar_touch=: echo echo 'WARNING: not restoring timestamps. Consider getting and' echo "installing GNU \`touch', distributed in GNU File Utilities..." echo fi rm -f 1231235999 $$.touch # if test ! -r _sharseq.tmp; then echo 'Please unpack part 1 first!' exit 1 fi shar_sequence=`cat _sharseq.tmp` if test "$shar_sequence" != 6; then echo "Please unpack part $shar_sequence next!" exit 1 fi if test ! -f _sharnew.tmp; then echo 'x - still skipping snmp2/snmplib/snmp_impl.h' else echo 'x - continuing file snmp2/snmplib/snmp_impl.h' sed 's/^X//' << 'SHAR_EOF' >> 'snmp2/snmplib/snmp_impl.h' && X * Definitions for SNMP (RFC 1067) implementation. X * X * X */ /*********************************************************** X Copyright 1988, 1989 by Carnegie Mellon University X X All Rights Reserved X Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of CMU not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. X CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ X X #if (defined vax) || (defined (mips)) /* X * This is a fairly bogus thing to do, but there seems to be no better way for X * compilers that don't understand void pointers. X */ #define void char #endif X /* X * Error codes: X */ /* X * These must not clash with SNMP error codes (all positive). X */ #define PARSE_ERROR -1 #define BUILD_ERROR -2 X #define COMMUNITY_MAX_LEN 64 #define MAX_NAME_LEN 128 /* number of subid's in a objid */ X #ifndef NULL #define NULL 0 #endif X #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif X struct packet_info { X int version; X u_char pdutype; X X /* community based authentication */ X u_char community[COMMUNITY_MAX_LEN + 1]; X int community_len; X int community_id; X X /* snmp security based authentication */ X oid srcParty[64]; X oid dstParty[64]; X oid context[64]; X int srcPartyLength; X int dstPartyLength; X int contextLength; X struct partyEntry *srcp, *dstp; X struct contextEntry *cxp; X X u_char *packet_end; }; X #define READ 1 #define WRITE 0 X #define RESERVE1 0 #define RESERVE2 1 #define COMMIT 2 #define ACTION 3 #define FREE 4 X /* See important comment in snmp_vars.c relating to a change X in the way the access control word is interpreted */ #define RONLY 0xAAAA /* read access for everyone */ #define RWRITE 0xAABB /* add write access for community private */ #define NOACCESS 0x0000 /* no access for anybody */ X #define INTEGER ASN_INTEGER #define STRING ASN_OCTET_STR #define OBJID ASN_OBJECT_ID #define NULLOBJ ASN_NULL #define BITSTRING ASN_BIT_STR X /* defined types (from the SMI, RFC 1157) */ #define IPADDRESS (ASN_APPLICATION | 0) #define COUNTER (ASN_APPLICATION | 1) #define GAUGE (ASN_APPLICATION | 2) #define TIMETICKS (ASN_APPLICATION | 3) #define OPAQUE (ASN_APPLICATION | 4) X /* defined types (from the SMI, RFC ????) */ #define NSAP (ASN_APPLICATION | 5) #define COUNTER64 (ASN_APPLICATION | 6) #define UINTEGER (ASN_APPLICATION | 7) X struct trapVar { X oid *varName; X int varNameLen; X u_char varType; X int varLen; X u_char *varVal; X struct trapVar *next; }; X #ifdef DEBUG #define ERROR(string) printf("%s(%d): %s\n",__FILE__, __LINE__, string); #else #define ERROR(string) #endif X /* from snmp.c*/ extern u_char sid[]; /* size SID_MAX_LEN */ X u_char *snmp_parse_var_op(); u_char *snmp_build_var_op(); X /* X * For calling secauth_build, FIRST_PASS is an indication that a new nonce X * and lastTimeStamp should be recorded. LAST_PASS is an indication that X * the packet should be checksummed and encrypted if applicable, in X * preparation for transmission. X * 0 means do neither, FIRST_PASS | LAST_PASS means do both. X * For secauth_parse, FIRST_PASS means decrypt the packet, otherwise leave it X * alone. LAST_PASS is ignored. X */ #define FIRST_PASS 1 #define LAST_PASS 2 u_char *snmp_auth_parse(); u_char *snmp_auth_build(); X u_char *snmp_secauth_parse(); u_char *snmp_secauth_build(); X X int has_access(); SHAR_EOF echo 'File snmp2/snmplib/snmp_impl.h is complete' && $shar_touch -am 1015123593 'snmp2/snmplib/snmp_impl.h' && chmod 0644 'snmp2/snmplib/snmp_impl.h' || echo 'restore of snmp2/snmplib/snmp_impl.h failed' shar_count="`wc -c < 'snmp2/snmplib/snmp_impl.h'`" test 4221 -eq "$shar_count" || echo "snmp2/snmplib/snmp_impl.h: original size 4221, current size $shar_count" rm -f _sharnew.tmp fi # ============= snmp2/snmplib/Makefile ============== if test -f 'snmp2/snmplib/Makefile' && test X"$1" != X"-c"; then echo 'x - skipping snmp2/snmplib/Makefile (file already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting snmp2/snmplib/Makefile (text)' sed 's/^X//' << 'SHAR_EOF' > 'snmp2/snmplib/Makefile' && # # Makefile for snmplib # TARG= libsnmp.a CSRCS= snmp_client.c mib.c parse.c snmp_api.c snmp.c snmp_auth.c asn1.c md5.c party.c context.c acl.c view.c party_parse.c context_parse.c acl_parse.c system.c OBJS= snmp_client.o mib.o parse.o snmp_api.o snmp.o snmp_auth.o asn1.o md5.o party.o context.o acl.o view.o party_parse.o context_parse.o acl_parse.o system.o CFLAGS=-g -DDEBUG CC = cc X all: $(TARG) X libsnmp.a: ${OBJS} X ar r libsnmp.a ${OBJS} X ranlib libsnmp.a X install: ../lib/libsnmp.a X X../lib/libsnmp.a: libsnmp.a X cp libsnmp.a ../lib X ranlib ../lib/libsnmp.a X X lint: X lint -nhx $(CSRCS) X clean: X rm -f ${OBJS} ${TARG} X rm -f ../lib/${TARG} X asn1.o: ./asn1.h mib.o: ./asn1.h mib.o: ./snmp_impl.h mib.o: ./snmp_api.h mib.o: ./parse.h parse.o: ./parse.h snmp.o: ./asn1.h snmp.o: ./snmp.h snmp.o: ./snmp_impl.h snmp.o: ./mib.h snmp_api.o: ./asn1.h snmp_api.o: ./snmp.h snmp_api.o: ./snmp_impl.h snmp_api.o: ./snmp_api.h snmp_auth.o: ./asn1.h snmp_auth.o: ./snmp.h snmp_auth.o: ./snmp_impl.h snmp_auth.o: ./party.h snmp_auth.o: ./context.h snmp_auth.o: ./md5.h snmp_client.o: ./asn1.h snmp_client.o: ./snmp.h snmp_client.o: ./snmp_impl.h snmp_client.o: ./snmp_api.h snmp_client.o: ./snmp_client.h md5.o: ./md5.h party.o: ./party.h ./asn1.h acl.o: ./acl.h ./asn1.h view.o: ./view.h ./asn1.h party_parse.o: ./asn1.h ./party.h context_parse.o: ./asn1.h ./context.h acl_parse.o: ./asn1.h ./acl.h system.o: ./system.h SHAR_EOF $shar_touch -am 1015123593 'snmp2/snmplib/Makefile' && chmod 0644 'snmp2/snmplib/Makefile' || echo 'restore of snmp2/snmplib/Makefile failed' shar_count="`wc -c < 'snmp2/snmplib/Makefile'`" test 1418 -eq "$shar_count" || echo "snmp2/snmplib/Makefile: original size 1418, current size $shar_count" rm -f _sharnew.tmp fi # ============= snmp2/snmplib/acl_parse.c ============== if test -f 'snmp2/snmplib/acl_parse.c' && test X"$1" != X"-c"; then echo 'x - skipping snmp2/snmplib/acl_parse.c (file already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting snmp2/snmplib/acl_parse.c (text)' sed 's/^X//' << 'SHAR_EOF' > 'snmp2/snmplib/acl_parse.c' && #include #include X #ifdef VXWORKS #include "VXtime.h" #else #include #include #endif X #include #include #include "asn1.h" #include "acl.h" #include "party.h" #include "context.h" X #define TRUE 1 #define FALSE 0 X static error_exit(str, linenumber, filename) X char *str; X int linenumber; X char *filename; { X fprintf(stderr, "%s on line %d of %s\n", str, linenumber, filename); X exit(1); } X int read_acl_database(filename) X char *filename; { X FILE *fp; X char buf[256], buf1[256], buf2[256], buf3[256], buf4[256]; X char *cp; X int blank; X int linenumber = 0; X oid targetParty[64], subjectParty[64], resources[64]; X int targetPartyLen, subjectPartyLen, resourcesLen; X int priveleges; X struct aclEntry *ap; X struct partyEntry *pp; X struct contextEntry *cxp; X int subject, target, res; X X fp = fopen(filename, "r"); X if (fp == NULL) X return -1; X while (fgets(buf, 256, fp)){ X linenumber++; X if (strlen(buf) > 250) X error_exit("Line longer than 250 bytes", linenumber, filename); X if (buf[0] == '#') X continue; X blank = TRUE; X for(cp = buf; *cp; cp++) X if (!isspace(*cp)){ X blank = FALSE; X break; X } X if (blank) X continue; X X if (sscanf(buf, "%s %s %s %s", buf1, buf2, buf3, buf4) != 4) X error_exit("Bad parse", linenumber, filename); X party_scanInit(); X for(pp = party_scanNext(); pp; pp = party_scanNext()){ X if (!strcasecmp(pp->partyName, buf1)){ X break; X } X } X if (!pp){ X targetPartyLen = 64; X if (!read_objid(buf1, targetParty, &targetPartyLen)) X error_exit("Bad target object identifier", linenumber, filename); X X pp = party_getEntry(targetParty, targetPartyLen); X if (!pp) X error_exit("Unknown target party identifier", X linenumber, filename); X /* why do I have subject and target mixed up here? */ X } X subject = pp->partyIndex; X X party_scanInit(); X for(pp = party_scanNext(); pp; pp = party_scanNext()){ X if (!strcasecmp(pp->partyName, buf2)){ X break; X } X } X if (!pp){ X subjectPartyLen = 64; X if (!read_objid(buf2, subjectParty, &subjectPartyLen)) X error_exit("Bad subject object identifier", linenumber, filename); X X X pp = party_getEntry(subjectParty, subjectPartyLen); X if (!pp) X error_exit("Unknown subject party identifier", X linenumber, filename); X } X target = pp->partyIndex; X X context_scanInit(); X for(cxp = context_scanNext(); cxp; cxp = context_scanNext()){ X if (!strcasecmp(cxp->contextName, buf3)){ X break; X } X } X if (!cxp){ X resourcesLen = 64; X if (!read_objid(buf3, resources, &resourcesLen)) X error_exit("Bad context object identifier", linenumber, filename); X X cxp = context_getEntry(resources, resourcesLen); X if (!cxp) X error_exit("Unknown context identifier", linenumber, filename); X } X res = cxp->contextIndex; X X priveleges = 0; X for(cp = buf4; *cp; cp++){ X switch(*cp){ X case 'g': X case 'G': X priveleges |= ACLPRIVELEGESGET; X break; X case 'n': X case 'N': X priveleges |= ACLPRIVELEGESGETNEXT; X break; X case 'r': X case 'R': X priveleges |= ACLPRIVELEGESGETRESPONSE; X break; X case 's': X case 'S': X priveleges |= ACLPRIVELEGESSET; X break; #if 0 X case 't': X case 'T': X priveleges |= ACLPRIVELEGESTRAP; X break; #endif X case 'b': X case 'B': X priveleges |= ACLPRIVELEGESBULK; X break; X case 'i': X case 'I': X priveleges |= ACLPRIVELEGESINFORM; X break; X case 'u': /* find a better letter XXXXXXXXX */ X case 'U': X priveleges |= ACLPRIVELEGESTRAP2; X break; X default: X error_exit("Bad priveleges code", linenumber, filename); X break; X } X } X X ap = acl_getEntry(target, subject, res); X if (!ap) X ap = acl_createEntry(target, subject, res); X ap->aclPriveleges = priveleges; X ap->aclStorageType = 2; /* volatile */ X ap->aclStatus = ACLACTIVE; #define ACLCOMPLETE_MASK 0x3F X /* all collumns - from acl_vars.c XXX */ X ap->aclBitMask = ACLCOMPLETE_MASK; X ap->reserved->aclBitMask = ap->aclBitMask; X } X fclose(fp); X return 0; } X SHAR_EOF $shar_touch -am 1015123593 'snmp2/snmplib/acl_parse.c' && chmod 0644 'snmp2/snmplib/acl_parse.c' || echo 'restore of snmp2/snmplib/acl_parse.c failed' shar_count="`wc -c < 'snmp2/snmplib/acl_parse.c'`" test 4150 -eq "$shar_count" || echo "snmp2/snmplib/acl_parse.c: original size 4150, current size $shar_count" rm -f _sharnew.tmp fi # ============= snmp2/snmplib/acl.h ============== if test -f 'snmp2/snmplib/acl.h' && test X"$1" != X"-c"; then echo 'x - skipping snmp2/snmplib/acl.h (file already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting snmp2/snmplib/acl.h (text)' sed 's/^X//' << 'SHAR_EOF' > 'snmp2/snmplib/acl.h' && /* X aclTarget INTEGER, X aclSubject INTEGER, X aclResources INTEGER, X aclPrivileges INTEGER, X aclStorageType StorageType, X aclStatus RowStatus X */ X #define ACLTARGET 1 #define ACLSUBJECT 2 #define ACLRESOURCES 3 #define ACLPRIVELEGES 4 #define ACLSTORAGETYPE 5 #define ACLSTATUS 6 X #define ACLNONEXISTENT 0 #define ACLACTIVE 1 #define ACLNOTINSERVICE 2 #define ACLNOTREADY 3 #define ACLCREATEANDGO 4 #define ACLCREATEANDWAIT 5 #define ACLDESTROY 6 X #define ACLPRIVELEGESGET 1 #define ACLPRIVELEGESGETNEXT 2 #define ACLPRIVELEGESGETRESPONSE 4 #define ACLPRIVELEGESSET 8 #define ACLPRIVELEGESBULK 32 #define ACLPRIVELEGESINFORM 64 #define ACLPRIVELEGESTRAP2 128 X struct aclEntry { X int aclTarget; X int aclSubject; X int aclResources; X int aclPriveleges; X int aclStorageType; X int aclStatus; X X u_long aclBitMask; X X struct aclEntry *reserved; X struct aclEntry *next; }; X u_char *var_acl(); int write_acl(); X struct aclEntry * acl_getEntry(/* int target, int subject, int resources */); /* X * Returns a pointer to the aclEntry with the X * same target and subject and resources. X * Returns NULL if that entry does not exist. X */ X int acl_scanInit(); /* X * Initialized the scan routines so that they will begin at the X * beginning of the list of aclEntries. X * X */ X X struct aclEntry * acl_scanNext(); /* X * Returns a pointer to the next aclEntry. X * These entries are returned in no particular order, X * but if N entries exist, N calls to acl_scanNext() will X * return all N entries once. X * Returns NULL if all entries have been returned. X * acl_scanInit() starts the scan over. X */ X struct aclEntry * acl_createEntry(/* int target, int subject, int resources */); /* X * Creates a aclEntry with the given index X * and returns a pointer to it. X * The status of this entry is created as invalid. X */ X SHAR_EOF $shar_touch -am 1015123593 'snmp2/snmplib/acl.h' && chmod 0644 'snmp2/snmplib/acl.h' || echo 'restore of snmp2/snmplib/acl.h failed' shar_count="`wc -c < 'snmp2/snmplib/acl.h'`" test 1926 -eq "$shar_count" || echo "snmp2/snmplib/acl.h: original size 1926, current size $shar_count" rm -f _sharnew.tmp fi # ============= snmp2/snmplib/party_parse.c ============== if test -f 'snmp2/snmplib/party_parse.c' && test X"$1" != X"-c"; then echo 'x - skipping snmp2/snmplib/party_parse.c (file already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting snmp2/snmplib/party_parse.c (text)' sed 's/^X//' << 'SHAR_EOF' > 'snmp2/snmplib/party_parse.c' && #include #include X #if 0 #include #endif X #ifdef VXWORKS #include "VXtime.h" #else #include #include #endif X #include X #include #include #include "asn1.h" #include "party.h" #include "system.h" X #define TRUE 1 #define FALSE 0 X #define IDENTITY_STATE 1 #define TRANSPORT_STATE 2 #define PROTOCOL_STATE 3 #define LIFETIME_STATE 4 #define CLOCK_STATE 5 #define AUTH_STATE 6 #define PRIV_STATE 7 X static oid noProxy[] = {1, 3, 6, 1, 2, 1, 20, 1, 3, 1}; X static error_exit(str, linenumber, filename) X char *str; X int linenumber; X char *filename; { X fprintf(stderr, "%s on line %d of %s\n", str, linenumber, filename); X exit(1); } X int read_party_database(filename) X char *filename; { X FILE *fp; X char buf[256], buf1[256], buf2[256], buf3[256]; X char *cp; X int blank, nonhex; X int linenumber = 0, chars = 0, clock_pos; X int state = IDENTITY_STATE; X u_long addr; X u_short port; X oid partyid[64]; X int partyidlen; X int priv, auth, proxy; X int lifetime, maxmessagesize; X u_long clock; X u_char privPrivate[32], authPrivate[32], privPublic[64], authPublic[64]; X u_char *ucp; X u_long byte; X int privPublicLength, authPublicLength; X char name[64]; /* friendly name */ X struct partyEntry *pp, *rp; X u_long myaddr; X int domain; X X fp = fopen(filename, "r"); X if (fp == NULL) X return -1; X while (fgets(buf, 256, fp)){ X linenumber++; X if (strlen(buf) > 250) X error_exit("Line longer than 250 bytes", linenumber, filename); X chars += strlen(buf); X if (buf[0] == '#') X continue; X blank = TRUE; X for(cp = buf; *cp; cp++) X if (!isspace(*cp)){ X blank = FALSE; X break; X } X if (blank) X continue; X switch(state){ X case IDENTITY_STATE: X if (sscanf(buf, "%s %s", name, buf1) != 2) X error_exit("Bad parse", linenumber, filename); X partyidlen = 64; X if (!read_objid(buf1, partyid, &partyidlen)) X error_exit("Bad object identifier", linenumber, filename); X state = TRANSPORT_STATE; X break; X case TRANSPORT_STATE: X if (sscanf(buf, "%s %s %s", buf1, buf2, buf3) != 3) X error_exit("Bad parse", linenumber, filename); X if (!strcasecmp(buf1, "snmpUdpDomain")) X domain = DOMAINSNMPUDP; X else X error_exit("Bad protocol type", linenumber, filename); X if ((addr = inet_addr(buf2)) == -1) X error_exit("Bad IP address", linenumber, filename); X for(cp = buf3; *cp; cp++) X if (!isdigit(*cp)) X error_exit("Not a port number", linenumber, filename); X port = atoi(buf3); X state = PROTOCOL_STATE; X break; X case PROTOCOL_STATE: X if (sscanf(buf, "%s %s", buf1, buf2) != 2) X error_exit("Bad parse", linenumber, filename); X /* maybe these should be oids */ X X if (!strcasecmp(buf1, "noAuth")) X auth = NOAUTH; X else if (!strcasecmp(buf1, "snmpv2MD5Auth")) X auth = SNMPV2MD5AUTHPROT; X else X error_exit("Bad authentication protocol type", linenumber, X filename); X X if (!strcasecmp(buf2, "noPriv")) X priv = NOPRIV; X else if (!strcasecmp(buf2, "desPriv")) X priv = DESPRIVPROT; X else X error_exit("Bad privacy protocol type", linenumber, filename); X state = LIFETIME_STATE; X break; X case LIFETIME_STATE: X if (sscanf(buf, "%s %s", buf1, buf2) != 2) X error_exit("Bad parse", linenumber, filename); X for(cp = buf1; *cp; cp++) X if (!isdigit(*cp)) X error_exit("Bad lifetime value (should be decimal integer)", X linenumber, filename); X lifetime = atoi(buf1); X for(cp = buf2; *cp; cp++) X if (!isdigit(*cp)) X error_exit("Bad Max Message Size value (should be decimal integer)", linenumber, filename); X maxmessagesize = atoi(buf2); X state = CLOCK_STATE; X break; X case CLOCK_STATE: X if (sscanf(buf, "%s", buf1) != 1) X error_exit("Bad parse", linenumber, filename); X if (strlen(buf1) != 8) X error_exit("Bad clock value (should be 8 hex digits)", X linenumber, filename); X for(cp = buf1; *cp; cp++){ X if (!isxdigit(*cp)) X error_exit("Bad clock value (should be 8 hex digits)", X linenumber, filename); X } X if (sscanf(buf1, "%x", &clock) != 1) X error_exit("Bad clock value", linenumber, filename); X clock_pos = chars - strlen(buf); X for(cp = buf; *cp && !isxdigit(*cp); cp++) X clock_pos++; X state = AUTH_STATE; X break; X case AUTH_STATE: X if (sscanf(buf, "%s %s", buf1, buf2, buf3) != 2) X error_exit("Bad parse", linenumber, filename); X if (strlen(buf1) != 32) X error_exit("Bad private key (should be 32 hex digits)", X linenumber, filename); X for(cp = buf1; *cp; cp++){ X if (!isxdigit(*cp)) X error_exit("Bad private key value (should be 32 hex digits)", X linenumber, filename); X } X ucp = authPrivate; X for(cp = buf1; *cp; cp += 2, ucp++){ X if (sscanf(cp, "%2x", &byte) != 1) X error_exit("Bad parse", linenumber, filename); X *ucp = byte; X } X X if (strlen(buf2) % 2) X error_exit("Bad private key value (should be an even number of hex digits)", linenumber, filename); X nonhex = 0; X for(cp = buf2; *cp; cp++){ X if (!isxdigit(*cp)) X nonhex = 1; X } X if (nonhex){ X if (strcasecmp(buf2, "Null")) X error_exit("Bad private key value (should be hex digits or null)", X linenumber, filename); X authPublicLength = 0; X } else { X ucp = authPublic; X for(cp = buf2; *cp; cp += 2, ucp++){ X if (sscanf(cp, "%2x", &byte) != 1) X error_exit("Bad parse", linenumber, filename); X *ucp = byte; X } X authPublicLength = ucp - authPublic; X } X state = PRIV_STATE; X break; X case PRIV_STATE: X if (sscanf(buf, "%s %s", buf1, buf2) != 2) X error_exit("Bad parse", linenumber, filename); X if (strlen(buf1) != 32) X error_exit("Bad private key (should be 32 hex digits)", X linenumber, filename); X for(cp = buf1; *cp; cp++){ X if (!isxdigit(*cp)) X error_exit("Bad private key value (should be 32 hex digits)", X linenumber, filename); X } X ucp = privPrivate; X for(cp = buf1; *cp; cp += 2, ucp++){ X if (sscanf(cp, "%2x", &byte) != 1) X error_exit("Bad parse", linenumber, filename); X *ucp = byte; X } X X if (strlen(buf2) % 2) X error_exit("Bad private key value (should be an even number of hex digits)", linenumber, filename); X nonhex = 0; X for(cp = buf2; *cp; cp++){ X if (!isxdigit(*cp)) X nonhex = 1; X } X if (nonhex){ X if (strcasecmp(buf2, "Null")) X error_exit("Bad private key value (should be hex digits or null)", X linenumber, filename); X privPublicLength = 0; X } else { X ucp = privPublic; X for(cp = buf2; *cp; cp += 2, ucp++){ X if (sscanf(cp, "%2x", &byte) != 1) X error_exit("Bad parse", linenumber, filename); X *ucp = byte; X } X privPublicLength = ucp - privPublic; X } X state = IDENTITY_STATE; X X pp = party_getEntry(partyid, partyidlen); X if (!pp) X pp = party_createEntry(partyid, partyidlen); X rp = pp->reserved; X strcpy(pp->partyName, name); X pp->partyTDomain = rp->partyTDomain = domain; X addr = htonl(addr); X port = htons(port); X bcopy((char *)&addr, pp->partyTAddress, sizeof(addr)); X bcopy((char *)&port, pp->partyTAddress + 4, sizeof(port)); X bcopy(pp->partyTAddress, rp->partyTAddress, 6); X pp->partyTAddressLen = rp->partyTAddressLen = 6; #if 0 /* nuke this??? XXX */ X if (proxy == NOPROXY){ X bcopy((char *)noProxy, (char *)pp->partyProxyFor, X sizeof(noProxy)); X bcopy((char *)noProxy, (char *)rp->partyProxyFor, X sizeof(noProxy)); X pp->partyProxyForLen = rp->partyProxyForLen = X sizeof(noProxy)/sizeof(oid); X } else { X fprintf(stderr, "Can't handle proxy\n"); X exit(1); X } #endif X pp->partyAuthProtocol = rp->partyAuthProtocol = auth; X pp->partyAuthClock = rp->partyAuthClock = clock; X pp->tv.tv_sec = pp->partyAuthClock; X if ((pp->partyAuthPublicLen = authPublicLength) != 0){ X bcopy((char *)authPublic, pp->partyAuthPublic, X authPublicLength); X bcopy((char *)authPublic, rp->partyAuthPublic, X authPublicLength); X } X pp->partyAuthLifetime = rp->partyAuthLifetime = lifetime; X pp->partyPrivProtocol = rp->partyPrivProtocol = priv; X if ((pp->partyPrivPublicLen = privPublicLength) != 0){ X bcopy((char *)privPublic, pp->partyPrivPublic, X privPublicLength); X bcopy((char *)privPublic, rp->partyPrivPublic, X privPublicLength); X } X myaddr = get_myaddr(); X if ((rp->partyTDomain == DOMAINSNMPUDP) X && !bcmp((char *)&myaddr, rp->partyTAddress, 4)){ X /* party is local */ X /* 1500 should be constant in snmp_impl.h */ X pp->partyMaxMessageSize = rp->partyMaxMessageSize = 1500; X pp->partyLocal = 1; /* TRUE */ X } else { X pp->partyMaxMessageSize = X rp->partyMaxMessageSize = maxmessagesize; X pp->partyLocal = 2; /* FALSE */ X } X bcopy(authPrivate, pp->partyAuthPrivate, 16); X bcopy(authPrivate, rp->partyAuthPrivate, 16); X pp->partyAuthPrivateLen = X rp->partyAuthPrivateLen = 16; X bcopy(privPrivate, pp->partyPrivPrivate, 16); X bcopy(privPrivate, rp->partyPrivPrivate, 16); X pp->partyPrivPrivateLen = X rp->partyPrivPrivateLen = 16; X pp->partyStorageType = 2; /* volatile */ X pp->partyStatus = rp->partyStatus = PARTYACTIVE; #define PARTYCOMPLETE_MASK 65535 X /* all collumns - from party_vars.c XXX */ X pp->partyBitMask = rp->partyBitMask = PARTYCOMPLETE_MASK; X break; X default: X error_exit("unknown state", linenumber, filename); X } X } X if (state != IDENTITY_STATE) X error_exit("Unfinished entry at EOF", linenumber, filename); X fclose(fp); X return 0; } X /* IP 127.0.0.1 2000 1.3.6.1.5.1.4.129.47.1.4.1 noProxy noAuth noPriv 30000 484 12345678 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 X X */ X int update_clock(file, pos, clock) X char *file; X int pos; X u_long clock; { X int fd; X char buf[9]; X X sprintf(buf, "%08X", clock); X #ifdef VXWORKS X /* X * UNIX man pages indicate that mode paramater is X * only needed when O_CREAT flag is specified. But, X * vxWorks header files expect the parameter to be X * there. So, it is here. X */ X fd = open(file, O_WRONLY, 0); #else X fd = open(file, O_WRONLY); #endif X X if (lseek(fd, pos, SEEK_SET) != pos){ X fprintf(stderr, "Couldn't update file\n"); X return 0; X } X if (write(fd, buf, 8) != 8){ X fprintf(stderr, "Couldn't update file\n"); X return 0; X } X if (close(fd) != 0){ X fprintf(stderr, "Couldn't update file\n"); X return 0; X } X return 1; } SHAR_EOF $shar_touch -am 1015123593 'snmp2/snmplib/party_parse.c' && chmod 0644 'snmp2/snmplib/party_parse.c' || echo 'restore of snmp2/snmplib/party_parse.c failed' shar_count="`wc -c < 'snmp2/snmplib/party_parse.c'`" test 10707 -eq "$shar_count" || echo "snmp2/snmplib/party_parse.c: original size 10707, current size $shar_count" rm -f _sharnew.tmp fi # ============= snmp2/snmplib/party.h ============== if test -f 'snmp2/snmplib/party.h' && test X"$1" != X"-c"; then echo 'x - skipping snmp2/snmplib/party.h (file already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting snmp2/snmplib/party.h (text)' sed 's/^X//' << 'SHAR_EOF' > 'snmp2/snmplib/party.h' && /* X partyIdentity Party, X partyIndex INTEGER, X partyTDomain OBJECT IDENTIFIER, X partyTAddress TAddress, X partyMaxMessageSize INTEGER, X partyLocal TruthValue, X partyAuthProtocol OBJECT IDENTIFIER, X partyAuthClock Clock, X partyAuthPrivate OCTET STRING, X partyAuthPublic OCTET STRING, X partyAuthLifetime INTEGER, X partyPrivProtocol OBJECT IDENTIFIER, X partyPrivPrivate OCTET STRING, X partyPrivPublic OCTET STRING, X partyStorageType StorageType, X partyStatus RowStatus X */ X #define PARTYIDENTITY 1 #define PARTYINDEX 2 #define PARTYTDOMAIN 3 #define PARTYTADDRESS 4 #define PARTYMAXMESSAGESIZE 5 #define PARTYLOCAL 6 #define PARTYAUTHPROTOCOL 7 #define PARTYAUTHCLOCK 8 #define PARTYAUTHPRIVATE 9 #define PARTYAUTHPUBLIC 10 #define PARTYAUTHLIFETIME 11 #define PARTYPRIVPROTOCOL 12 #define PARTYPRIVPRIVATE 13 #define PARTYPRIVPUBLIC 14 #define PARTYCLONEFROM 15 #define PARTYSTORAGETYPE 16 #define PARTYSTATUS 17 X X #define PARTYNONEXISTENT 0 #define PARTYACTIVE 1 #define PARTYNOTINSERVICE 2 #define PARTYNOTREADY 3 #define PARTYCREATEANDGO 4 #define PARTYCREATEANDWAIT 5 #define PARTYDESTROY 6 X X #define DOMAINSNMPUDP 1 /* extern oid snmpUdpDomain; */ /* no others defined yet */ X #define NOAUTH 1 /* extern oid noAuth[]; */ X #define NOPRIV 3 /* extern oid noPriv[]; */ #define DESPRIVPROT 4 /* extern oid dESPrivProt[]; */ #define SNMPV2MD5AUTHPROT 6 /* extern oid snmpv2MD5AuthProt[]; */ X struct partyEntry { X oid partyIdentity[32]; X int partyIdentityLen; X int partyIndex; X char partyName[64]; /* friendly name */ X int partyTDomain; X u_char partyTAddress[16]; X int partyTAddressLen; X int partyMaxMessageSize; X int partyLocal; X int partyAuthProtocol; X u_long partyAuthClock; X u_long partyLastTimeStamp; /* not in MIB */ X long partyAuthNonce; X u_char partyAuthPrivate[16]; X int partyAuthPrivateLen; X u_char partyAuthPublic[32]; X int partyAuthPublicLen; X u_long partyAuthLifetime; X int partyPrivProtocol; X u_char partyPrivPrivate[16]; X int partyPrivPrivateLen; X u_char partyPrivPublic[32]; X int partyPrivPublicLen; X int partyStorageType; X int partyStatus; X X u_long partyBitMask; X X struct partyEntry *reserved; X struct partyEntry *next; X struct timeval tv; }; X u_char *var_party(); int write_party(); X struct partyEntry * party_getEntry(/* oid *partyID, int partyIDLen */); /* X * Returns a pointer to the partyEntry with the X * same identity as partyID. X * Returns NULL if that entry does not exist. X */ X int party_scanInit(); /* X * Initialized the scan routines so that they will begin at the X * beginning of the list of partyEntries. X * X */ X X struct partyEntry * party_scanNext(); /* X * Returns a pointer to the next partyEntry. X * These entries are returned in no particular order, X * but if N entries exist, N calls to party_scanNext() will X * return all N entries once. X * Returns NULL if all entries have been returned. X * party_scanInit() starts the scan over. X */ X struct partyEntry * party_createEntry(/* oid *partyID, int partyIDLen */); /* X * Creates a partyEntry with the given index X * and returns a pointer to it. X * The status of this entry is created as invalid. X */ X X SHAR_EOF $shar_touch -am 1015123593 'snmp2/snmplib/party.h' && chmod 0644 'snmp2/snmplib/party.h' || echo 'restore of snmp2/snmplib/party.h failed' shar_count="`wc -c < 'snmp2/snmplib/party.h'`" test 3350 -eq "$shar_count" || echo "snmp2/snmplib/party.h: original size 3350, current size $shar_count" rm -f _sharnew.tmp fi # ============= snmp2/snmplib/party.c ============== if test -f 'snmp2/snmplib/party.c' && test X"$1" != X"-c"; then echo 'x - skipping snmp2/snmplib/party.c (file already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting snmp2/snmplib/party.c (text)' sed 's/^X//' << 'SHAR_EOF' > 'snmp2/snmplib/party.c' && #ifdef VXWORKS #include "VXtypes.h" #include "VXtime.h" #else #include #include #endif X #include X #include "asn1.h" #define NULL 0 #include "party.h" X X X static struct partyEntry *List = NULL, *ScanPtr = NULL; static struct partyEntry *cache[2]; static int cachePtr; static int NextIndex = 1; X struct partyEntry * party_getEntry(partyID, partyIDLen) X oid *partyID; X int partyIDLen; { X struct partyEntry *pp; X X pp = cache[0]; X if (pp && partyIDLen == pp->partyIdentityLen X && !bcmp((char *)pp->partyIdentity, (char *)partyID, X partyIDLen * sizeof(oid))){ X return pp; X } X pp = cache[1]; X if (pp && partyIDLen == pp->partyIdentityLen X && !bcmp((char *)pp->partyIdentity, (char *)partyID, X partyIDLen * sizeof(oid))){ X return pp; X } X for(pp = List; pp; pp = pp->next){ X if (partyIDLen == pp->partyIdentityLen X && !bcmp((char *)pp->partyIdentity, (char *)partyID, X partyIDLen * sizeof(oid))){ X cachePtr ^= 1; X cache[cachePtr] = pp; X return pp; X } X } X return NULL; } X party_scanInit() { X ScanPtr = List; } X struct partyEntry * party_scanNext() { X struct partyEntry *returnval; X X returnval = ScanPtr; X if (ScanPtr != NULL) X ScanPtr = ScanPtr->next; X return returnval; } X struct partyEntry * party_createEntry(partyID, partyIDLen) X oid *partyID; X int partyIDLen; { X struct partyEntry *pp; X X pp = (struct partyEntry *)malloc(sizeof(struct partyEntry)); X bzero((char *)pp, sizeof(struct partyEntry)); X X bcopy((char *)partyID, (char *)pp->partyIdentity, X partyIDLen * sizeof(oid)); X pp->partyIdentityLen = partyIDLen; X pp->partyIndex = NextIndex++; X pp->reserved = (struct partyEntry *)malloc(sizeof(struct partyEntry)); X bzero((char *)pp->reserved, sizeof(struct partyEntry)); X X pp->next = List; X List = pp; X return pp; } X party_destroyEntry(partyID, partyIDLen) X oid *partyID; X int partyIDLen; { X struct partyEntry *pp, *lastpp; X X if (List->partyIdentityLen == partyIDLen X && !bcmp((char *)List->partyIdentity, (char *)partyID, X partyIDLen * sizeof(oid))){ X pp = List; X List = List->next; X } else { X for(pp = List; pp; pp = pp->next){ X if (pp->partyIdentityLen == partyIDLen X && !bcmp((char *)pp->partyIdentity, (char *)partyID, X partyIDLen * sizeof(oid))) X break; X lastpp = pp; X } X if (!pp) X return; X lastpp->next = pp->next; X } X if (pp->reserved) X free((char *)pp->reserved); X free(pp); X return; } SHAR_EOF $shar_touch -am 1015123593 'snmp2/snmplib/party.c' && chmod 0644 'snmp2/snmplib/party.c' || echo 'restore of snmp2/snmplib/party.c failed' shar_count="`wc -c < 'snmp2/snmplib/party.c'`" test 2516 -eq "$shar_count" || echo "snmp2/snmplib/party.c: original size 2516, current size $shar_count" rm -f _sharnew.tmp fi # ============= snmp2/snmplib/acl.c ============== if test -f 'snmp2/snmplib/acl.c' && test X"$1" != X"-c"; then echo 'x - skipping snmp2/snmplib/acl.c (file already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting snmp2/snmplib/acl.c (text)' sed 's/^X//' << 'SHAR_EOF' > 'snmp2/snmplib/acl.c' && #ifdef VXWORKS #include "VXtypes.h" #include "VXtime.h" #else #include #include #endif X #include "asn1.h" #define NULL 0 #include "acl.h" X X X static struct aclEntry *List = NULL, *ScanPtr = NULL; X X struct aclEntry * acl_getEntry(target, subject, resources) X int target, subject, resources; { X struct aclEntry *ap; X /* cache here */ X for(ap = List; ap; ap = ap->next){ X if (target == ap->aclTarget && subject == ap->aclSubject X && resources == ap->aclResources) X return ap; X } X return NULL; } X acl_scanInit() { X ScanPtr = List; } X struct aclEntry * acl_scanNext() { X struct aclEntry *returnval; X X returnval = ScanPtr; X if (ScanPtr != NULL) X ScanPtr = ScanPtr->next; X return returnval; } X struct aclEntry * acl_createEntry(target, subject, resources) X int target, subject, resources; { X struct aclEntry *ap; X X ap = (struct aclEntry *)malloc(sizeof(struct aclEntry)); X bzero((char *)ap, sizeof(struct aclEntry)); X X ap->aclTarget = target; X ap->aclSubject = subject; X ap->aclResources = resources; X ap->reserved = (struct aclEntry *)malloc(sizeof(struct aclEntry)); X bzero((char *)ap->reserved, sizeof(struct aclEntry)); X X ap->next = List; X List = ap; X return ap; } X acl_destroyEntry(target, subject, resources) X int target, subject, resources; { X struct aclEntry *ap, *lastap; X X if (List->aclTarget == target && List->aclSubject == subject X && List->aclResources == resources){ X ap = List; X List = List->next; X } else { X for(ap = List; ap; ap = ap->next){ X if (ap->aclTarget == target X && ap->aclSubject == subject X && ap->aclResources == resources) X break; X lastap = ap; X } X if (!ap) X return; X lastap->next = ap->next; X } X if (ap->reserved) X free((char *)ap->reserved); X free(ap); X return; } SHAR_EOF $shar_touch -am 1015123593 'snmp2/snmplib/acl.c' && chmod 0644 'snmp2/snmplib/acl.c' || echo 'restore of snmp2/snmplib/acl.c failed' shar_count="`wc -c < 'snmp2/snmplib/acl.c'`" test 1841 -eq "$shar_count" || echo "snmp2/snmplib/acl.c: original size 1841, current size $shar_count" rm -f _sharnew.tmp fi # ============= snmp2/snmplib/view.c ============== if test -f 'snmp2/snmplib/view.c' && test X"$1" != X"-c"; then echo 'x - skipping snmp2/snmplib/view.c (file already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting snmp2/snmplib/view.c (text)' sed 's/^X//' << 'SHAR_EOF' > 'snmp2/snmplib/view.c' && #ifdef VXWORKS #include "VXtypes.h" #include "VXtime.h" #else #include #include #endif X #include "asn1.h" #define NULL 0 #include "view.h" X X X static struct viewEntry *List = NULL, *ScanPtr = NULL; X X struct viewEntry * view_getEntry(viewIndex, viewSubtree, viewSubtreeLen) X oid *viewSubtree; X int viewIndex, viewSubtreeLen; { X struct viewEntry *vp; X X for(vp = List; vp; vp = vp->next){ X if (viewIndex == vp->viewIndex X && viewSubtreeLen == vp->viewSubtreeLen X && !bcmp((char *)vp->viewSubtree, (char *)viewSubtree, X viewSubtreeLen * sizeof(oid))) X return vp; X } X return NULL; } X view_scanInit() { X ScanPtr = List; } X struct viewEntry * view_scanNext() { X struct viewEntry *returnval; X X returnval = ScanPtr; X if (ScanPtr != NULL) X ScanPtr = ScanPtr->next; X return returnval; } X struct viewEntry * view_createEntry(viewIndex, viewSubtree, viewSubtreeLen) X oid *viewSubtree; X int viewIndex, viewSubtreeLen; { X struct viewEntry *vp; X X vp = (struct viewEntry *)malloc(sizeof(struct viewEntry)); X bzero((char *)vp, sizeof(struct viewEntry)); X X vp->viewIndex = viewIndex; X bcopy((char *)viewSubtree, (char *)vp->viewSubtree, X viewSubtreeLen * sizeof(oid)); X vp->viewSubtreeLen = viewSubtreeLen; X vp->reserved = (struct viewEntry *)malloc(sizeof(struct viewEntry)); X bzero((char *)vp->reserved, sizeof(struct viewEntry)); X X vp->next = List; X List = vp; X return vp; } X view_destroyEntry(viewIndex, viewSubtree, viewSubtreeLen) X oid *viewSubtree; X int viewIndex, viewSubtreeLen; { X struct viewEntry *vp, *lastvp; X X if (List->viewIndex == viewIndex X && List->viewSubtreeLen == viewSubtreeLen X && !bcmp((char *)List->viewSubtree, (char *)viewSubtree, X viewSubtreeLen * sizeof(oid))){ X vp = List; X List = List->next; X } else { X for(vp = List; vp; vp = vp->next){ X if (vp->viewIndex == viewIndex X && vp->viewSubtreeLen == viewSubtreeLen X && !bcmp((char *)vp->viewSubtree, (char *)viewSubtree, X viewSubtreeLen * sizeof(oid))) X break; X lastvp = vp; X } X if (!vp) X return; X lastvp->next = vp->next; X } X if (vp->reserved) X free((char *)vp->reserved); X free(vp); X return; } X SHAR_EOF $shar_touch -am 1015123593 'snmp2/snmplib/view.c' && chmod 0644 'snmp2/snmplib/view.c' || echo 'restore of snmp2/snmplib/view.c failed' shar_count="`wc -c < 'snmp2/snmplib/view.c'`" test 2233 -eq "$shar_count" || echo "snmp2/snmplib/view.c: original size 2233, current size $shar_count" rm -f _sharnew.tmp fi # ============= snmp2/snmplib/view.h ============== if test -f 'snmp2/snmplib/view.h' && test X"$1" != X"-c"; then echo 'x - skipping snmp2/snmplib/view.h (file already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting snmp2/snmplib/view.h (text)' sed 's/^X//' << 'SHAR_EOF' > 'snmp2/snmplib/view.h' && /* X viewIndex INTEGER, -- first INDEX X viewSubtree OBJECT IDENTIFIER, -- second INDEX X viewMask OCTET STRING X viewType INTEGER, X viewStorageType StorageType, X viewStatus RowStatus, X */ X #define VIEWINDEX 1 #define VIEWSUBTREE 2 #define VIEWMASK 3 #define VIEWTYPE 4 #define VIEWSTORAGETYPE 5 #define VIEWSTATUS 6 X #define VIEWNONEXISTENT 0 #define VIEWACTIVE 1 #define VIEWNOTINSERVICE 2 #define VIEWNOTREADY 3 #define VIEWCREATEANDGO 4 #define VIEWCREATEANDWAIT 5 #define VIEWDESTROY 6 X #define VIEWINCLUDED 1 #define VIEWEXCLUDED 2 X struct viewEntry { X int viewIndex; X char viewName[64]; X int viewNameLen; X oid viewSubtree[32]; X int viewSubtreeLen; X u_char viewMask[32]; X int viewMaskLen; X int viewType; X int viewStorageType; X int viewStatus; X X u_long viewBitMask; X X struct viewEntry *reserved; X struct viewEntry *next; }; X u_char *var_view(); int write_view(); X struct viewEntry * view_getEntry(/* int viewIndex */ ); /* X * Returns a pointer to the viewEntry with the X * same viewParty and viewSubtree X * Returns NULL if that entry does not exist. X */ X int view_scanInit(); /* X * Initialized the scan routines so that they will begin at the X * beginning of the list of viewEntries. X * X */ X X struct viewEntry * view_scanNext(); /* X * Returns a pointer to the next viewEntry. X * These entries are returned in no particular order, X * but if N entries exist, N calls to view_scanNext() will X * return all N entries once. X * Returns NULL if all entries have been returned. X * view_scanInit() starts the scan over. X */ X struct viewEntry * view_createEntry(/* int viewIndex */); /* X * Creates a viewEntry with the given index X * and returns a pointer to it. X * The status of this entry is created as invalid. X */ X X X SHAR_EOF $shar_touch -am 1015123593 'snmp2/snmplib/view.h' && chmod 0644 'snmp2/snmplib/view.h' || echo 'restore of snmp2/snmplib/view.h failed' shar_count="`wc -c < 'snmp2/snmplib/view.h'`" test 1936 -eq "$shar_count" || echo "snmp2/snmplib/view.h: original size 1936, current size $shar_count" rm -f _sharnew.tmp fi # ============= snmp2/snmplib/md5.c ============== if test -f 'snmp2/snmplib/md5.c' && test X"$1" != X"-c"; then echo 'x - skipping snmp2/snmplib/md5.c (file already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting snmp2/snmplib/md5.c (text)' sed 's/^X//' << 'SHAR_EOF' > 'snmp2/snmplib/md5.c' && /* ** ************************************************************************** ** md5.c -- Implementation of MD5 Message Digest Algorithm ** ** Updated: 2/16/90 by Ronald L. Rivest ** ** (C) 1990 RSA Data Security, Inc. ** ** ************************************************************************** */ X /* ** To use MD5: ** -- Include md5.h in your program ** -- Declare an MDstruct MD to hold the state of the digest computation. ** -- Initialize MD using MDbegin(&MD) ** -- For each full block (64 bytes) X you wish to process, call ** MDupdate(&MD,X,512) ** (512 is the number of bits in a full block.) ** -- For the last block (less than 64 bytes) you wish to process, ** MDupdate(&MD,X,n) ** where n is the number of bits in the partial block. A partial ** block terminates the computation, so every MD computation should ** terminate by processing a partial block, even if it has n = 0. ** -- The message digest is available in MD.buffer[0] ... MD.buffer[3]. ** (Least-significant byte of each word should be output first.) ** -- You can print out the digest using MDprint(&MD) */ X /* Implementation notes: ** This implementation assumes that ints are 32-bit quantities. ** If the machine stores the least-significant byte of an int in the ** least-addressed byte (eg., VAX and 8086), then LOWBYTEFIRST should be ** set to TRUE. Otherwise (eg., SUNS), LOWBYTEFIRST should be set to ** FALSE. Note that on machines with LOWBYTEFIRST FALSE the routine ** MDupdate modifies has a side-effect on its input array (the order of bytes ** in each word are reversed). If this is undesired a call to MDreverse(X) can ** reverse the bytes of X back into order after each call to MDupdate. */ #define TRUE 1 #define FALSE 0 #define LOWBYTEFIRST FALSE X /* Compile-time includes */ #include #include "md5.h" X /* Compile-time declarations of MD5 ``magic constants''. */ #define I0 0x67452301 /* Initial values for MD buffer */ #define I1 0xefcdab89 #define I2 0x98badcfe #define I3 0x10325476 #define fs1 7 /* round 1 shift amounts */ #define fs2 12 #define fs3 17 #define fs4 22 #define gs1 5 /* round 2 shift amounts */ #define gs2 9 #define gs3 14 #define gs4 20 #define hs1 4 /* round 3 shift amounts */ #define hs2 11 #define hs3 16 #define hs4 23 #define is1 6 /* round 4 shift amounts */ #define is2 10 #define is3 15 #define is4 21 X X /* Compile-time macro declarations for MD5. ** Note: The ``rot'' operator uses the variable ``tmp''. ** It assumes tmp is declared as unsigned int, so that the >> ** operator will shift in zeros rather than extending the sign bit. */ #define f(X,Y,Z) ((X&Y) | ((~X)&Z)) #define g(X,Y,Z) ((X&Z) | (Y&(~Z))) #define h(X,Y,Z) (X^Y^Z) #define i_(X,Y,Z) (Y ^ ((X) | (~Z))) #define rot(X,S) (tmp=X,(tmp<>(32-S))) #define ff(A,B,C,D,i,s,lp) A = rot((A + f(B,C,D) + X[i] + lp),s) + B #define gg(A,B,C,D,i,s,lp) A = rot((A + g(B,C,D) + X[i] + lp),s) + B #define hh(A,B,C,D,i,s,lp) A = rot((A + h(B,C,D) + X[i] + lp),s) + B #define ii(A,B,C,D,i,s,lp) A = rot((A + i_(B,C,D) + X[i] + lp),s) + B X X /* MDprint(MDp) ** Print message digest buffer MDp as 32 hexadecimal digits. ** Order is from low-order byte of buffer[0] to high-order byte of buffer[3]. ** Each byte is printed with high-order hexadecimal digit first. ** This is a user-callable routine. */ void MDprint(MDp) MDptr MDp; { int i,j; X for (i=0;i<4;i++) X for (j=0;j<32;j=j+8) X printf("%02x",(MDp->buffer[i]>>j) & 0xFF); } X /* MDbegin(MDp) ** Initialize message digest buffer MDp. ** This is a user-callable routine. */ void MDbegin(MDp) MDptr MDp; { int i; X MDp->buffer[0] = I0; X MDp->buffer[1] = I1; X MDp->buffer[2] = I2; X MDp->buffer[3] = I3; X for (i=0;i<8;i++) MDp->count[i] = 0; X MDp->done = 0; } X /* MDreverse(X) ** Reverse the byte-ordering of every int in X. ** Assumes X is an array of 16 ints. ** The macro revx reverses the byte-ordering of the next word of X. */ #define revx { t = (*X << 16) | (*X >> 16); \ X *X++ = ((t & 0xFF00FF00) >> 8) | ((t & 0x00FF00FF) << 8); } MDreverse(X) unsigned int *X; { register unsigned int t; X revx; revx; revx; revx; revx; revx; revx; revx; X revx; revx; revx; revx; revx; revx; revx; revx; } X /* MDblock(MDp,X) ** Update message digest buffer MDp->buffer using 16-word data block X. ** Assumes all 16 words of X are full of data. ** Does not update MDp->count. ** This routine is not user-callable. */ static void MDblock(MDp,X) MDptr MDp; unsigned int *X; { X register unsigned int tmp, A, B, C, D; #if LOWBYTEFIRST == FALSE X MDreverse(X); #endif X A = MDp->buffer[0]; X B = MDp->buffer[1]; X C = MDp->buffer[2]; X D = MDp->buffer[3]; X X /* Update the message digest buffer */ X ff(A , B , C , D , 0 , fs1 , 3614090360); /* Round 1 */ X ff(D , A , B , C , 1 , fs2 , 3905402710); X ff(C , D , A , B , 2 , fs3 , 606105819); X ff(B , C , D , A , 3 , fs4 , 3250441966); X ff(A , B , C , D , 4 , fs1 , 4118548399); X ff(D , A , B , C , 5 , fs2 , 1200080426); X ff(C , D , A , B , 6 , fs3 , 2821735955); X ff(B , C , D , A , 7 , fs4 , 4249261313); SHAR_EOF : || echo 'restore of snmp2/snmplib/md5.c failed' fi echo 'End of snmp2 part 6' echo 'File snmp2/snmplib/md5.c is continued in part 7' echo 7 > _sharseq.tmp exit 0