5 * key attr=val... - add a key
6 * the attr=val pairs are protocol-specific.
7 * for example, both of these are valid:
8 * key p9sk1 gre cs.bell-labs.com mysecret
9 * key p9sk1 gre cs.bell-labs.com 11223344556677 fmt=des7hex
10 * delkey ... - delete a key
11 * if given, the attr=val pairs are used to narrow the search
12 * [maybe should require a password?]
14 * debug - toggle debugging
17 static char *msg[] = {
28 for(i=0; i<nelem(msg); i++)
29 if(strcmp(msg[i], s) == 0)
39 Attr *attr, *kpa, **l, **lpriv, **lprotos, *pa, *priv, *protos;
43 while(*a == ' ' || *a == '\t' || *a == '\n')
46 if(a[0] == '#' || a[0] == '\0')
50 * it would be nice to emit a warning of some sort here.
51 * we ignore all but the first line of the write. this helps
52 * both with things like "echo delkey >/mnt/factotum/ctl"
53 * and writes that (incorrectly) contain multiple key lines.
55 if(p = strchr(a, '\n')){
57 werrstr("multiline write not allowed");
63 if((p = strchr(a, ' ')) == nil)
69 werrstr("unknown verb %s", a);
73 /* separate out proto= attributes */
76 if(strcmp((*l)->name, "proto") == 0){
78 lprotos = &(*l)->next;
85 werrstr("key without protos");
90 /* separate out private attributes */
93 if((*l)->name[0] == '!'){
101 flog("addkey %A %A %N", protos, attr, priv);
105 for(pa=protos; pa; pa=pa->next){
106 if((proto = protolookup(pa->val)) == nil){
107 werrstr("unknown proto %s", pa->val);
112 if(proto->keyprompt){
113 kpa = parseattr(proto->keyprompt);
114 if(!matchattr(kpa, attr, priv)){
116 werrstr("missing attributes -- want %s", proto->keyprompt);
117 flog("addkey %s: %r", proto->name);
123 k = emalloc(sizeof(Key));
124 k->attr = mkattr(AttrNameval, "proto", proto->name, copyattr(attr));
125 k->privattr = copyattr(priv);
128 if(proto->checkkey && (*proto->checkkey)(k) < 0){
129 flog("addkey %s: %r", proto->name);
134 flog("adding key: %A %N", k->attr, k->privattr);
145 flog("delkey %A", attr);
146 for(pa=attr; pa; pa=pa->next){
147 if(pa->type != AttrQuery && pa->name[0]=='!'){
148 werrstr("only !private? patterns are allowed for private fields");
153 for(i=0; i<ring.nkey; ){
154 if(matchattr(attr, ring.key[i]->attr, ring.key[i]->privattr)){
156 flog("deleting %A %N", ring.key[i]->attr, ring.key[i]->privattr);
157 keyclose(ring.key[i]);
159 memmove(&ring.key[i], &ring.key[i+1], (ring.nkey-i)*sizeof(ring.key[0]));
165 werrstr("found no keys to delete");
171 flog("debug = %d", debug);