⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 freebsd-3.2.il-kernel.patch

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 PATCH
📖 第 1 页 / 共 5 页
字号:
diff -N -c -r /usr/src/sys/9fs/9auth.c ./9fs/9auth.c*** /usr/src/sys/9fs/9auth.c	Wed Dec 31 19:00:00 1969--- ./9fs/9auth.c	Mon May 22 17:11:29 2000****************** 0 ****--- 1,238 ----+ #include <sys/param.h>+ #include <sys/systm.h>+ #include <sys/socket.h>+ #include <sys/socketvar.h>+ #include <sys/protosw.h>+ #include <sys/malloc.h>+ #include <sys/mbuf.h>+ #include <sys/uio.h>+ + #include <9fs/9p.h>+ #include <9fs/9auth.h>+ + #define	N2HCHAR(x)		x = *p+++ #define	N2HSHORT(x)	x = (p[0] | (p[1]<<8)); p += 2+ #define	N2HLONG(x)		x = (p[0] | (p[1]<<8) |\+ 				(p[2]<<16) | (p[3]<<24)); p += 4+ #define	N2HQUAD(x)	x = (u_int64_t)(p[0] | (p[1]<<8) |\+ 					(p[2]<<16) | (p[3]<<24)) |\+ 				((u_int64_t)(p[4] | (p[5]<<8) |\+ 					(p[6]<<16) | (p[7]<<24)) << 32); p += 8+ #define	N2HSTRING(x,n)	bcopy(p, x, n); p += n+ + #define	H2NCHAR(x)	*p++ = x+ #define	H2NSHORT(x)	p[0]=x; p[1]=x>>8; p += 2+ #define	H2NLONG(x)		p[0]=x; p[1]=x>>8; p[2]=x>>16; p[3]=x>>24; p += 4+ #define	H2NQUAD(x)	p[0]=x;	p[1]=x>>8;\+ 			p[2]=x>>16;	p[3]=x>>24;\+ 			p[4]=x>>32;	p[5]=x>>40;\+ 			p[6]=x>>48;	p[7]=x>>56;\+ 			p += 8+ #define	H2NSTRING(x,n)	bcopy(x, p, n); p += n+ + static int u9auth_send __P((struct socket *so, struct mbuf *top, struct proc *p));+ static int u9auth_recv __P((struct socket *so, struct mbuf **mp, struct proc *p));+ + static int u9auth_count = 0;+ + static int u9auth_tr2m(struct u9auth_ticketreq *f, char *ap)+ {+ 	int n;+ 	u_char *p;+ + 	p = (u_char*)ap;+         H2NCHAR(f->type);+ 	H2NSTRING(f->authid, U9FS_NAMELEN);+ 	H2NSTRING(f->authdom, U9FS_DOMLEN);+ 	H2NSTRING(f->chal, U9FS_CHALLEN);+ 	H2NSTRING(f->hostid, U9FS_NAMELEN);+ 	H2NSTRING(f->uid, U9FS_NAMELEN);+ 	n = p - (u_char*)ap;+ 	return n;+ }+ + static struct mbuf * u9auth_m_tr2m(struct u9auth_ticketreq * tktq)+ {+   register struct mbuf *m;+   char * ap;+   int sz = 141;+ +   MGETHDR(m, M_WAIT, MT_DATA);+   if( sz > MHLEN )+     MCLGET(m, M_WAIT);+   m->m_len = 0;+ +   if ( M_TRAILINGSPACE(m) < sz )+     panic("u9auth_m_tr2m");+   +   ap = mtod(m, char *);+   m->m_len = u9auth_tr2m(tktq, ap);+   m->m_pkthdr.len = m->m_len;+ +   return (m);+ }+ + static int+ u9auth_send(so, top, p)+ 	register struct socket *so;+ 	register struct mbuf *top;+ 	register struct proc *p;+ 	+ {+   int error, soflags, flags;+   +   soflags = so->so_proto->pr_flags;+   if (so->so_type == SOCK_SEQPACKET)+     flags = MSG_EOR;+   else+     flags = 0;+   +   error = so->so_proto->pr_usrreqs->pru_sosend(so, 0, 0, top, 0, flags, p);+ +   return (error);+ }+ + static int+ u9auth_recv(so, mp, p)	+      register struct socket * so;+      register struct mbuf **mp;+      struct proc *p;+ {+   struct uio auio;+   u_int32_t len;+   int error = 0, sotype, rcvflg;+ +   *mp = 0;+   sotype = so->so_type;+   +   /*+    * For reliable protocols, lock against other senders/receivers+    * in case a reconnect is necessary.+    * For SOCK_STREAM, first get the Record Mark to find out how much+    * more there is to get.+    * We must lock the socket against other receivers+    * until we have an entire rpc request/reply.+    */+   if (sotype == SOCK_SEQPACKET ) {+     if( (so->so_state & SS_ISCONNECTED) == 0 )+       return (EACCES);+ 		auio.uio_resid = len = 1000000;+ 		auio.uio_procp = p;+ 		do {+ 			rcvflg = 0;+ 			error =  so->so_proto->pr_usrreqs->pru_soreceive+ 				(so, 0, &auio, mp,+ 				(struct mbuf **)0, &rcvflg);+ 		} while (error == EWOULDBLOCK);+ 		len -= auio.uio_resid;    +   }+   if (error) {+     m_freem(*mp);+     *mp = 0;+   }+   return (error);  + }+ + static void+ u9auth_m2t(char *ap, struct u9auth_ticket *f, char *key)+ {+ 	u_char *p;+ + 	if(key)+ 		decrypt9(key, ap, U9AUTH_TICKETLEN);+ 	p = (u_char*)ap;+ 	N2HCHAR(f->num);+ 	N2HSTRING(f->chal, U9FS_CHALLEN);+ 	N2HSTRING(f->cuid, U9FS_NAMELEN);+ 	f->cuid[U9FS_NAMELEN-1] = 0;+ 	N2HSTRING(f->suid, U9FS_NAMELEN);+ 	f->suid[U9FS_NAMELEN-1] = 0;+ 	N2HSTRING(f->key, U9AUTH_DESKEYLEN);+ };+ + static int + u9auth_a2m(struct u9auth_authenticator *f, char *ap, char *key)+ {+ 	int n;+ 	u_char *p;+ + 	p = (u_char*)ap;+ 	H2NCHAR(f->num);+ 	H2NSTRING(f->chal, U9FS_CHALLEN);+ 	H2NLONG(f->id);+ 	n = p - (u_char*)ap;+ 	if(key)+ 		encrypt9(key, ap, n);+ 	return n;+ }+ + void u9auth_genchal (char * chal)+ {+   u_long * lp = (u_long *)chal;+ +   *lp++ = random();+   *lp = random();+ }+ + int u9auth_gettickets (struct socket * so, struct u9fsreq * rep,+ 			   char * user, char * ckey, char * ts, char * authc,+ 		       struct proc *p)+ {+   char * cp;+   struct u9auth_ticketreq tktq;+   struct u9auth_ticket tc;+   struct u9auth_authenticator auth;+   struct mbuf * m;+   int error, len;+   +   bzero(&tktq, sizeof(tktq));+   tktq.type = AuthTreq;+   bcopy(rep->r_authid, tktq.authid, U9FS_NAMELEN);+   bcopy(rep->r_authdom, tktq.authdom, U9FS_DOMLEN);+   bcopy(rep->r_chal, tktq.chal, U9FS_CHALLEN);+   strncpy(tktq.hostid, user, U9FS_NAMELEN);+   strncpy(tktq.uid, user, U9FS_NAMELEN);+ +   m = u9auth_m_tr2m(&tktq);+   error = u9auth_send(so, m, p);+   if( error ) +     goto bad;+   error = u9auth_recv(so, &m, p);+   if( error )+     goto bad;+ +   len = U9AUTH_TICKETLEN+1;+   if( m->m_len < len && (m = m_pullup(m, len)) == 0 )+     goto bad;+ +   cp = mtod(m, char *);+   switch( cp[0] ) {+   case AuthOK:+     u9auth_m2t(&cp[1], & tc, ckey);+     bzero(&auth, sizeof(auth));+     auth.num = AuthAc;+     bcopy(tc.chal, auth.chal, sizeof(auth.chal));+     auth.id = u9auth_count++;+ +     m->m_len -= len;+     m->m_data += len;+ +     len = U9AUTH_TICKETLEN;+     if( m->m_len < len && (m = m_pullup(m, len)) == 0 )+       goto bad;+     cp = mtod(m, char *);+     bcopy(cp, ts, len);+     break;+   case AuthErr:+   case AuthOKvar:+     m_freem(m);+     goto bad;+     break;+   }+ +   u9auth_a2m(&auth, authc, tc.key);+   return 0;+  bad:+   return error;+ }+ diff -N -c -r /usr/src/sys/9fs/9auth.h ./9fs/9auth.h*** /usr/src/sys/9fs/9auth.h	Wed Dec 31 19:00:00 1969--- ./9fs/9auth.h	Thu Nov 11 15:00:29 1999****************** 0 ****--- 1,129 ----+ #ifndef P9AUTH_H+ #define P9AUTH_H+ + #define U9AUTH_DOMLEN		48		/* length of an authentication domain name */+ #define U9AUTH_DESKEYLEN	7		/* length of a des key for encrypt/decrypt */+ #define U9AUTH_CHALLEN	8		/* length of a challenge */+ #define U9AUTH_NETCHLEN	16		/* max network challenge length	*/+ #define U9AUTH_CONFIGLEN	14+ #define U9AUTH_SECRETLEN	32		/* max length of a secret */+ #define U9AUTH_APOPCHLEN	256+ #define U9AUTH_MD5LEN		16+ #define U9AUTH_KEYDBOFF	8		/* length of random data at the start of key file */+ #define U9AUTH_OKEYDBLEN	U9FSNAMELEN+U9AUTH_DESKEYLEN+4+2,	/* length of an entry in old key file */+ #define U9AUTH_KEYDBLEN	OKEYDBLENSECRETLEN,	/* length of an entry in key file */+ + /* encryption numberings (anti-replay) */+ enum+ {+ 	AuthTreq=1,	/* ticket request */+ 	AuthChal=2,	/* challenge box request */+ 	AuthPass=3,	/* change password */+ 	AuthOK=4,	/* fixed length reply follows */+ 	AuthErr=5,	/* error follows */+ 	AuthMod=6,	/* modify user */+ 	AuthApop=7,	/* apop authentication for pop3 */+ 	AuthOKvar=9,	/* variable length reply follows */+ 	AuthChap=10,	/* chap authentication for ppp */+ 	AuthMSchap=11,	/* MS chap authentication for ppp */+ + + 	AuthTs=64,	/* ticket encrypted with server's key */+ 	AuthTc,		/* ticket encrypted with client's key */+ 	AuthAs,		/* server generated authenticator */+ 	AuthAc,		/* client generated authenticator */+ 	AuthTp,		/* ticket encrypted with clien's key for password change */+ };+ + struct u9auth_ticketreq+ {+ 	char	type;+ 	char	authid[U9FS_NAMELEN];	/* server's encryption id */+ 	char	authdom[U9AUTH_DOMLEN];	/* server's authentication domain */+ 	char	chal[U9AUTH_CHALLEN];		/* challenge from server */+ 	char	hostid[U9FS_NAMELEN];	/* host's encryption id */+ 	char	uid[U9FS_NAMELEN];		/* uid of requesting user on host */+ };+ #define	U9AUTH_TICKREQLEN	(3*U9FS_NAMELEN+U9AUTH_CHALLEN+U9AUTH_DOMLEN+1)+ + struct u9auth_ticket+ {+ 	char	num;			/* replay protection */+ 	char	chal[U9AUTH_CHALLEN];		/* server challenge */+ 	char	cuid[U9FS_NAMELEN];		/* uid on client */+ 	char	suid[U9FS_NAMELEN];		/* uid on server */+ 	char	key[U9AUTH_DESKEYLEN];		/* nonce DES key */+ };+ #define	U9AUTH_TICKETLEN	(U9AUTH_CHALLEN+2*U9FS_NAMELEN+U9AUTH_DESKEYLEN+1)+ + struct u9auth_authenticator+ {+ 	char	num;			/* replay protection */+ 	char	chal[U9AUTH_CHALLEN];+ 	u_long	id;			/* authenticator id, ++'d with each auth */+ };+ #define	U9AUTH_AUTHENTLEN	(U9AUTH_CHALLEN+4+1)+ + struct u9auth_passwordreq+ {+ 	char	num;+ 	char	old[U9FS_NAMELEN];+ 	char	new[U9FS_NAMELEN];+ 	char	changesecret;+ 	char	secret[U9AUTH_SECRETLEN];	/* new secret */+ };+ #define	U9AUTH_PASSREQLEN	(2*U9FS_NAMELEN+1+1+U9AUTH_SECRETLEN)+ + struct u9auth_nvrsafe+ {+ 	char	machkey[U9AUTH_DESKEYLEN];+ 	u_char	machsum;+ 	char	authkey[U9AUTH_DESKEYLEN];+ 	u_char	authsum;+ 	char	config[U9AUTH_CONFIGLEN];+ 	u_char	configsum;+ 	char	authid[U9FS_NAMELEN];+ 	u_char	authidsum;+ 	char	authdom[U9AUTH_DOMLEN];+ 	u_char	authdomsum;+ };+ + struct u9auth_chalstate+ {+ 	int	afd;			/* /dev/authenticate */+ 	int	asfd;			/* authdial() */+ 	char	chal[U9AUTH_NETCHLEN];		/* challenge/response */+ };+ + struct u9auth_apopchalstate+ {+ 	int	afd;			/* /dev/authenticate */+ 	int	asfd;			/* authdial() */+ 	char	chal[U9AUTH_APOPCHLEN];	/* challenge/response */+ };+ + struct	u9auth_chapreply+ {+ 	u_char	id;+ 	char	uid[U9FS_NAMELEN];+ 	char	resp[U9AUTH_MD5LEN];+ };+ + struct	u9auth_mSchapreply+ {+ 	char	uid[U9FS_NAMELEN];+ 	char	LMresp[24];		/* Lan Manager response */+ 	char	NTresp[24];		/* NT response */+ };+ + #ifdef KERNEL+ void u9auth_genchal __P((char *));+ int  u9auth_gettickets __P((struct socket * so, struct u9fsreq * rep,+ 			   char * user, char * ckey, char * ts, char * authc,+ 			    struct proc * p));+ int encrypt9 __P((void *key, void * vbuf, int n));+ int decrypt9 __P((void *key, void * vbuf, int n));+ + #endif+ + #endifdiff -N -c -r /usr/src/sys/9fs/9crypt.c ./9fs/9crypt.c*** /usr/src/sys/9fs/9crypt.c	Wed Dec 31 19:00:00 1969--- ./9fs/9crypt.c	Thu Nov 11 12:23:02 1999****************** 0 ****--- 1,416 ----+ /*+  *	Data Encryption Standard+  *	D.P.Mitchell  83/06/08.+  *+  *	block_cipher(key, block, decrypting)+  */+ #include <sys/param.h>+ #include <sys/systm.h>+ #include <sys/socket.h>+ #include <sys/socketvar.h>+ + typedef unsigned char uchar;+ typedef unsigned long ulong;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -