Browse Source

Plan 9 from Bell Labs 2012-04-04

David du Colombier 12 years ago
parent
commit
98f0fb3742

+ 2 - 1
sys/man/2/dsa

@@ -136,4 +136,5 @@ are provided to manage signature storage.
 .IR rsa (2),
 .IR sechash (2),
 .IR prime (2),
-.IR rand (2)
+.IR rand (2),
+.IR dsa (8)

+ 171 - 0
sys/man/8/dsa

@@ -0,0 +1,171 @@
+.EQ
+delim $$
+.EN
+.TH DSA 8
+.SH NAME
+dsagen, asn12dsa, dsa2pub, dsa2ssh \- generate and format dsa keys
+.SH SYNOPSIS
+.B auth/dsagen
+.\" [
+.\" .B -b
+.\" .I nbits
+.\" ]
+[
+.B -t
+.I tag
+]
+.PP
+.B auth/asn12dsa
+[
+.B -t
+.I tag
+]
+[
+.I file
+]
+.PP
+.B auth/dsa2pub
+[
+.I file
+]
+.PP
+.B auth/dsa2ssh
+[
+.B -c
+.I comment
+] [
+.I file
+]
+.SH DESCRIPTION
+Plan 9 represents a DSA (Digital Signature Algorithm)
+key as an attribute-value pair list
+prefixed with the string
+.BR key ;
+this is the generic key format used by
+.IR factotum (4).
+A full DSA private key has the following attributes:
+.TF secret
+.TP
+.B proto
+must be
+.B dsa
+.TP
+.B !secret
+decryption key
+.TP
+.B p
+modulus, a large prime
+.TP
+.B q
+group order, another large prime that divides
+.I p
+- 1.
+.TP
+.B alpha
+group generator
+.TP
+.B key
+$"alpha" sup secret ~ mod ~ p$
+.PD
+.LP
+All the numbers are in hexadecimal.
+A DSA public key omits the attributes beginning with
+.LR ! .
+A key may have other attributes as well (for example, a
+.B service
+attribute identifying how this key is typically used),
+but to these utilities such attributes are merely comments.
+.PP
+For example, a private key and corresponding public key might look like this
+(with [⋯] indicating elisions and \e marking line breaks for readability):
+.IP
+.EX
+key proto=dsa p=D5[⋯]DB q=C2[⋯]E7 alpha=44[⋯]9B key=C1[⋯]3F \e
+	!secret=9E[⋯]3B
+key proto=dsa p=D5[⋯]DB q=C2[⋯]E7 alpha=44[⋯]9B key=C1[⋯]3F
+.EE
+.LP
+Note that the order of the attributes does not matter.
+.PP
+.I Dsagen
+prints a randomly generated DSA private key
+whose
+.B n
+has exactly
+.I nbits
+(default 1024)
+significant bits.
+If
+.I tag
+is specified, it is printed between
+.B key
+and
+.BR proto=dsa ;
+typically,
+.I tag
+is a sequence of attribute-value comments describing the key.
+.PP
+.I Asn12dsa
+reads an DSA private key stored as ASN.1
+encoded in the binary Distinguished Encoding Rules (DER)
+and prints a Plan 9 DSA key,
+inserting
+.I tag
+exactly as
+.I dsagen
+does.
+ASN.1/DER is a popular key format on Unix and Windows;
+it is often encoded in text form using the Privacy Enhanced Mail (PEM) format
+in a section labeled as an
+.RB `` DSA
+.B PRIVATE
+.BR KEY .''
+The command:
+.IP
+.EX
+auth/pemdecode 'DSA PRIVATE KEY' | auth/asn12dsa
+.EE
+.LP
+extracts the key section from a textual ASN.1/DER/PEM key
+into binary ASN.1/DER format and then
+converts it to a Plan 9 DSA key.
+.PP
+.I Dsa2pub
+reads a Plan 9 DSA public or private key,
+removes the private attributes, and prints the resulting public key.
+Comment attributes are preserved.
+.PP
+.I Dsa2ssh
+reads a Plan 9 DSA public or private key and prints the public portion 
+in the format used by SSH:
+.L ssh-dss
+and a long base-64 encoded number.
+.EQ
+delim @@
+.EN
+For compatibility with external SSH implementations, the public keys in
+.B /sys/lib/ssh/keyring
+and
+.B $home/lib/keyring
+are stored in this format.
+.br
+.ne 4
+.SH EXAMPLES
+Generate a fresh key and configure a remote Unix system to
+allow use of that key for logins:
+.IP
+.EX
+auth/dsagen -t 'service=ssh' >key
+auth/dsa2ssh key | ssh unix 'cat >>.ssh/authorized_keys'
+cat key >/mnt/factotum/ctl
+ssh unix
+.EE
+.SH SOURCE
+.B /sys/src/cmd/auth
+.SH "SEE ALSO
+.IR ssh (1),
+.IR factotum (4),
+.IR pem (8),
+.IR rsa (8)
+.SH BUGS
+There are too many key formats.

+ 0 - 10
sys/man/8/fossilcons

@@ -1205,13 +1205,3 @@ To save an old (but not yet discarded) snapshot into the archive tree:
 .EX
 snap -a -s /snapshot/2003/1220/0700 -d /archive/2003/1220
 .EE
-.SH BUGS
-It is prudent to avoid taking a snapshot at the same time as an
-archival dump.
-.I Fossil
-has been seen to sometimes hang when they collide.
-Snapshots are taken when
-.BI time(0)/60% interval
-is zero, so
-an interval of 60 will take snapshots on the hour.
-It's easiest to schedule the archival dumps to happen not exactly on the hour.

+ 11 - 10
sys/man/8/rsa

@@ -2,7 +2,7 @@
 .SH NAME
 rsagen, rsafill, asn12rsa, rsa2pub, rsa2ssh, rsa2x509 \- generate and format rsa keys
 .SH SYNOPSIS
-.B rsagen
+.B auth/rsagen
 [
 .B -b
 .I nbits
@@ -12,12 +12,12 @@ rsagen, rsafill, asn12rsa, rsa2pub, rsa2ssh, rsa2x509 \- generate and format rsa
 .I tag
 ]
 .PP
-.B rsafill
+.B auth/rsafill
 [
 .I file
 ]
 .PP
-.B asn12rsa
+.B auth/asn12rsa
 [
 .B -t
 .I tag
@@ -26,17 +26,17 @@ rsagen, rsafill, asn12rsa, rsa2pub, rsa2ssh, rsa2x509 \- generate and format rsa
 .I file
 ]
 .PP
-.B rsa2pub
+.B auth/rsa2pub
 [
 .I file
 ]
 .PP
-.B rsa2ssh
+.B auth/rsa2ssh
 [
 .I file
 ]
 .PP
-.B rsa2x509
+.B auth/rsa2x509
 [
 .B -e
 .I expiretime
@@ -86,10 +86,10 @@ parameters derived from the other attributes, cached to speed decryption
 .PD
 .LP
 All the numbers are in hexadecimal except
-.I size ,
+.IR size ,
 which is decimal.
 An RSA public key omits the attributes beginning with
-.L ! .
+.LR ! .
 A key may have other attributes as well (for example, a
 .B service
 attribute identifying how this key is typically used),
@@ -235,8 +235,9 @@ ssh unix
 .SH SOURCE
 .B /sys/src/cmd/auth
 .SH "SEE ALSO
+.IR ssh (1),
 .IR factotum (4),
-.IR pem (8),
-.IR ssh (1)
+.IR dsa (8),
+.IR pem (8)
 .SH BUGS
 There are too many key formats.

+ 2 - 2
sys/src/cmd/fossil/9excl.c

@@ -9,14 +9,14 @@ static struct {
 	Excl*	tail;
 } ebox;
 
-typedef struct Excl {
+struct Excl {
 	Fsys*	fsys;
 	uvlong	path;
 	ulong	time;
 
 	Excl*	next;
 	Excl*	prev;
-} Excl;
+};
 
 enum {
 	LifeTime	= (5*60),

+ 3 - 5
sys/src/cmd/fossil/9fsys.c

@@ -4,8 +4,6 @@
 #include "fns.h"
 #include "9.h"
 
-typedef struct Fsys Fsys;
-
 struct Fsys {
 	VtLock* lock;
 
@@ -662,7 +660,7 @@ fsysLabel(Fsys* fsys, int argc, char* argv[])
 			goto Out1;
 		n = 0;
 		for(;;){
-			if(blockWrite(bb)){
+			if(blockWrite(bb, Waitlock)){
 				while(bb->iostate != BioClean){
 					assert(bb->iostate == BioWriting);
 					vtSleep(bb->ioready);
@@ -844,9 +842,9 @@ fsysDf(Fsys *fsys, int argc, char* argv[])
 
 	fs = fsys->fs;
 	cacheCountUsed(fs->cache, fs->elo, &used, &tot, &bsize);
-	consPrint("\t%s: %,llud used + %,llud free = %,llud (%llud%% used)\n",
+	consPrint("\t%s: %,llud used + %,llud free = %,llud (%.1f%% used)\n",
 		fsys->name, used*(vlong)bsize, (tot-used)*(vlong)bsize,
-		tot*(vlong)bsize, used*100LL/tot);
+		tot*(vlong)bsize, used*100.0/tot);
 	return 1;
 }
 

+ 2 - 2
sys/src/cmd/fossil/9lstn.c

@@ -3,7 +3,7 @@
 #include "9.h"
 
 typedef struct Lstn Lstn;
-typedef struct Lstn {
+struct Lstn {
 	int	afd;
 	int	flags;
 	char*	address;
@@ -11,7 +11,7 @@ typedef struct Lstn {
 
 	Lstn*	next;
 	Lstn*	prev;
-} Lstn;
+};
 
 static struct {
 	VtLock*	lock;

+ 1 - 1
sys/src/cmd/fossil/9p.c

@@ -1133,7 +1133,7 @@ rTversion(Msg* m)
 		/*
 		 * Currently, the only defined version
 		 * is "9P2000"; ignore any later versions.
-          	 */
+		 */
 		v = strtol(&t->version[2], 0, 10);
 		if(v >= 2000){
 			r->version = VERSION9P;

+ 2 - 2
sys/src/cmd/fossil/9srv.c

@@ -3,7 +3,7 @@
 #include "9.h"
 
 typedef struct Srv Srv;
-typedef struct Srv {
+struct Srv {
 	int	fd;
 	int	srvfd;
 	char*	service;
@@ -11,7 +11,7 @@ typedef struct Srv {
 
 	Srv*	next;
 	Srv*	prev;
-} Srv;
+};
 
 static struct {
 	VtLock*	lock;

+ 4 - 4
sys/src/cmd/fossil/9user.c

@@ -9,7 +9,7 @@ enum {
 typedef struct Ubox Ubox;
 typedef struct User User;
 
-typedef struct User {
+struct User {
 	char*	uid;
 	char*	uname;
 	char*	leader;
@@ -19,11 +19,11 @@ typedef struct User {
 	User*	next;			/* */
 	User*	ihash;			/* lookup by .uid */
 	User*	nhash;			/* lookup by .uname */
-} User;
+};
 
 #pragma varargck type "U"   User*
 
-typedef struct Ubox {
+struct Ubox {
 	User*	head;
 	User*	tail;
 	int	nuser;
@@ -31,7 +31,7 @@ typedef struct Ubox {
 
 	User*	ihash[NUserHash];	/* lookup by .uid */
 	User*	nhash[NUserHash];	/* lookup by .uname */
-} Ubox;
+};
 
 static struct {
 	VtLock*	lock;

+ 16 - 24
sys/src/cmd/fossil/cache.c

@@ -9,9 +9,6 @@ typedef struct FreeList FreeList;
 typedef struct BAddr BAddr;
 
 enum {
-	Nowaitlock,
-	Waitlock,
-
 	BadHeap = ~0,
 };
 
@@ -25,7 +22,6 @@ enum {
 struct Cache
 {
 	VtLock	*lk;
-	VtLock	*dirtylk;
 	int 	ref;
 	int	mode;
 
@@ -163,7 +159,6 @@ cacheAlloc(Disk *disk, VtSession *z, ulong nblocks, int mode)
 	nbl = nblocks * 4;
 
 	c->lk = vtLockAlloc();
-	c->dirtylk = vtLockAlloc();	/* allowed to dirty blocks */
 	c->ref = 1;
 	c->disk = disk;
 	c->z = z;
@@ -561,12 +556,15 @@ fprint(2, "%s: _cacheLocal want epoch %ud got %ud\n", argv0, epoch, b->l.epoch);
 		switch(b->iostate){
 		default:
 			abort();
-		case BioEmpty:
 		case BioLabel:
-			if(mode == OOverWrite){
-				blockSetIOState(b, BioClean);
+			if(mode == OOverWrite)
+				/*
+				 * leave iostate as BioLabel because data
+				 * hasn't been read.
+				 */
 				return b;
-			}
+			/* fall through */
+		case BioEmpty:
 			diskRead(c->disk, b);
 			vtSleep(b->ioready);
 			break;
@@ -1098,16 +1096,14 @@ blockDirty(Block *b)
 
 	if(b->iostate == BioDirty)
 		return 1;
-	assert(b->iostate == BioClean);
+	assert(b->iostate == BioClean || b->iostate == BioLabel);
 
-	vtLock(c->dirtylk);
 	vtLock(c->lk);
 	b->iostate = BioDirty;
 	c->ndirty++;
 	if(c->ndirty > (c->maxdirty>>1))
 		vtWakeup(c->flush);
 	vtUnlock(c->lk);
-	vtUnlock(c->dirtylk);
 
 	return 1;
 }
@@ -1171,7 +1167,7 @@ blockRollback(Block *b, uchar *buf)
  *	Otherwise, bail.
  */
 int
-blockWrite(Block *b)
+blockWrite(Block *b, int waitlock)
 {
 	uchar *dmap;
 	Cache *c;
@@ -1195,7 +1191,7 @@ blockWrite(Block *b)
 		}
 
 		lockfail = 0;
-		bb = _cacheLocalLookup(c, p->part, p->addr, p->vers, Nowaitlock,
+		bb = _cacheLocalLookup(c, p->part, p->addr, p->vers, waitlock,
 			&lockfail);
 		if(bb == nil){
 			if(lockfail)
@@ -1476,10 +1472,13 @@ blockRemoveLink(Block *b, u32int addr, int type, u32int tag, int recurse)
 	bl.next = nil;
 	bl.recurse = recurse;
 
-	p = blistAlloc(b);
+	if(b->part == PartSuper && b->iostate == BioClean)
+		p = nil;
+	else
+		p = blistAlloc(b);
 	if(p == nil){
 		/*
-		 * We were out of blists so blistAlloc wrote b to disk.
+		 * b has already been written to disk.
 		 */
 		doRemoveLink(b->c, &bl);
 		return;
@@ -2008,7 +2007,7 @@ cacheFlushBlock(Cache *c)
 		b = _cacheLocalLookup(c, p->part, p->addr, p->vers, Nowaitlock,
 			&lockfail);
 
-		if(b && blockWrite(b)){
+		if(b && blockWrite(b, Nowaitlock)){
 			c->nflush++;
 			blockPut(b);
 			return 1;
@@ -2088,12 +2087,6 @@ flushThread(void *a)
 void
 cacheFlush(Cache *c, int wait)
 {
-	/*
-	 * Lock c->dirtylk so that more blocks aren't being dirtied
-	 * while we try to write out what's already here.
-	 * Otherwise we might not ever finish!
-	 */
-	vtLock(c->dirtylk);
 	vtLock(c->lk);
 	if(wait){
 		while(c->ndirty){
@@ -2106,7 +2099,6 @@ cacheFlush(Cache *c, int wait)
 	}else if(c->ndirty)
 		vtWakeup(c->flush);
 	vtUnlock(c->lk);
-	vtUnlock(c->dirtylk);
 }
 
 /*

+ 3 - 0
sys/src/cmd/fossil/dat.h

@@ -34,6 +34,9 @@ enum {
 };
 
 enum {
+	Nowaitlock,
+	Waitlock,
+
 	NilBlock	= (~0UL),
 	MaxBlock	= (1UL<<31),
 };

+ 1 - 1
sys/src/cmd/fossil/fns.h

@@ -39,7 +39,7 @@ uchar*	blockRollback(Block*, uchar*);
 void	blockSetIOState(Block*, int);
 Block*	_blockSetLabel(Block*, Label*);
 int	blockSetLabel(Block*, Label*, int);
-int	blockWrite(Block*);
+int	blockWrite(Block*, int);
 
 Disk*	diskAlloc(int);
 int	diskBlockSize(Disk*);

+ 2 - 2
sys/src/cmd/fossil/fs.c

@@ -204,8 +204,8 @@ superWrite(Block* b, Super* super, int forceWrite)
 	superPack(super, b->data);
 	blockDirty(b);
 	if(forceWrite){
-		while(!blockWrite(b)){
-			/* BUG: what should really happen here? */
+		while(!blockWrite(b, Waitlock)){
+			/* this should no longer happen */
 			fprint(2, "%s: could not write super block; "
 				"waiting 10 seconds\n", argv0);
 			sleep(10*1000);