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] == '!'){
104 for(pa=protos; pa; pa=pa->next){
105 if((proto = protolookup(pa->val)) == nil){
106 werrstr("unknown proto %s", pa->val);
110 if(proto->keyprompt){
111 kpa = parseattr(proto->keyprompt);
112 if(!matchattr(kpa, attr, priv)){
114 werrstr("missing attributes -- want %s", proto->keyprompt);
120 k = emalloc(sizeof(Key));
121 k->attr = mkattr(AttrNameval, "proto", proto->name, copyattr(attr));
122 k->privattr = copyattr(priv);
125 if(proto->checkkey && (*proto->checkkey)(k) < 0){
140 for(pa=attr; pa; pa=pa->next){
141 if(pa->type != AttrQuery && pa->name[0]=='!'){
142 werrstr("only !private? patterns are allowed for private fields");
147 for(i=0; i<ring.nkey; ){
148 if(matchattr(attr, ring.key[i]->attr, ring.key[i]->privattr)){
150 keyclose(ring.key[i]);
152 memmove(&ring.key[i], &ring.key[i+1], (ring.nkey-i)*sizeof(ring.key[0]));
158 werrstr("found no keys to delete");