5 char *factname = "factotum";
14 fprint(2, "usage: factotum [-Dd] [-a authaddr] [-m mtpt]\n");
15 fprint(2, " or factotum -g keypattern\n");
16 fprint(2, " or factotum -g 'badkeyattr\nmsg\nkeypattern'");
21 threadmain(int argc, char *argv[])
28 fmtinstall('A', attrfmt);
29 fmtinstall('H', encodefmt);
30 fmtinstall('N', attrnamefmt);
32 if(argc == 3 && strcmp(argv[1], "-g") == 0){
44 authaddr = EARGF(usage());
49 mtpt = EARGF(usage());
52 service = EARGF(usage());
59 threadpostmountsrv(&fs, service, mtpt, MBEFORE);
64 * prompt user for a key. don't care about memory leaks, runs standalone
67 promptforkey(int fd, char *params)
73 attr = _parseattr(params);
74 fprint(fd, "!adding key:");
75 for(a=attr; a; a=a->next)
76 if(a->type != AttrQuery && a->name[0] != '!')
77 fprint(fd, " %q=%q", a->name, a->val);
80 for(a=attr; a; a=a->next){
82 if(a->type != AttrQuery || v[0]=='!')
85 if(strcmp(v, "user") == 0)
87 a->val = readcons(v, def, 0);
89 sysfatal("user terminated key input");
90 a->type = AttrNameval;
92 for(a=attr; a; a=a->next){
94 if(a->type != AttrQuery || v[0]!='!')
97 if(strcmp(v+1, "user") == 0)
99 a->val = readcons(v+1, def, 1);
101 sysfatal("user terminated key input");
102 a->type = AttrNameval;
110 * send a key to the mounted factotum
118 fd = open("/mnt/factotum/ctl", ORDWR);
120 sysfatal("opening /mnt/factotum/ctl: %r");
121 rv = fprint(fd, "key %A\n", attr);
122 read(fd, buf, sizeof buf);
128 askuser(int fd, char *params)
132 attr = promptforkey(fd, params);
134 sysfatal("no key supplied");
135 if(sendkey(attr) < 0)
136 sysfatal("sending key to factotum: %r");
146 if((fd = open("/dev/cons", ORDWR)) < 0)
147 sysfatal("open /dev/cons: %r");
149 nf = getfields(s, f, nelem(f), 0, "\n");
150 if(nf == 1){ /* needkey or old badkey */
155 if(nf == 3){ /* new badkey */
157 fprint(fd, "!replace: %s\n", f[0]);
158 fprint(fd, "!because: %s\n", f[1]);