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, **l, **lpriv, **lprotos, *pa, *priv, *protos;
43 if(a[0] == '#' || a[0] == '\0')
47 * it would be nice to emit a warning of some sort here.
48 * we ignore all but the first line of the write. this helps
49 * both with things like "echo delkey >/mnt/factotum/ctl"
50 * and writes that (incorrectly) contain multiple key lines.
52 if(p = strchr(a, '\n')){
54 werrstr("multiline write not allowed");
60 if((p = strchr(a, ' ')) == nil)
66 werrstr("unknown verb");
70 /* separate out proto= attributes */
73 if(strcmp((*l)->name, "proto") == 0){
75 lprotos = &(*l)->next;
82 werrstr("key without protos");
87 /* separate out private attributes */
90 if((*l)->name[0] == '!'){
101 for(pa=protos; pa; pa=pa->next){
102 if((proto = protolookup(pa->val)) == nil){
103 werrstr("unknown proto %s", pa->val);
107 if(proto->checkkey == nil){
108 werrstr("proto %s does not accept keys", proto->name);
112 k = emalloc(sizeof(Key));
113 k->attr = mkattr(AttrNameval, "proto", proto->name, copyattr(attr));
114 k->privattr = copyattr(priv);
117 if((*proto->checkkey)(k) < 0){
132 for(pa=attr; pa; pa=pa->next){
133 if(pa->type != AttrQuery && pa->name[0]=='!'){
134 werrstr("only !private? patterns are allowed for private fields");
139 for(i=0; i<ring.nkey; ){
140 if(matchattr(attr, ring.key[i]->attr, ring.key[i]->privattr)){
142 keyclose(ring.key[i]);
144 memmove(&ring.key[i], &ring.key[i+1], (ring.nkey-i)*sizeof(ring.key[0]));
150 werrstr("found no keys to delete");