1 #include "u.h"
2 #include "lib.h"
3 #include "kern/dat.h"
4 #include "kern/fns.h"
5 #include "user.h"
6
7 #include "drawterm.h"
8
9 char *argv0;
10 char *user;
11
12 extern int errfmt(Fmt*);
13 void
sizebug(void)14 sizebug(void)
15 {
16 /*
17 * Needed by various parts of the code.
18 * This is a huge bug.
19 */
20 assert(sizeof(char)==1);
21 assert(sizeof(short)==2);
22 assert(sizeof(ushort)==2);
23 assert(sizeof(int)==4);
24 assert(sizeof(uint)==4);
25 assert(sizeof(long)==4);
26 assert(sizeof(ulong)==4);
27 assert(sizeof(vlong)==8);
28 assert(sizeof(uvlong)==8);
29 }
30
31 int
main(int argc,char ** argv)32 main(int argc, char **argv)
33 {
34 eve = getuser();
35 if(eve == nil)
36 eve = "drawterm";
37
38 sizebug();
39
40 osinit();
41 procinit0();
42 printinit();
43 screeninit();
44
45 chandevreset();
46 chandevinit();
47 quotefmtinstall();
48
49 if(bind("#c", "/dev", MBEFORE) < 0)
50 panic("bind #c: %r");
51 if(bind("#m", "/dev", MBEFORE) < 0)
52 panic("bind #m: %r");
53 if(bind("#i", "/dev", MBEFORE) < 0)
54 panic("bind #i: %r");
55 if(bind("#I", "/net", MBEFORE) < 0)
56 panic("bind #I: %r");
57 if(bind("#U", "/", MAFTER) < 0)
58 panic("bind #U: %r");
59 bind("#A", "/dev", MAFTER);
60
61 if(open("/dev/cons", OREAD) != 0)
62 panic("open0: %r");
63 if(open("/dev/cons", OWRITE) != 1)
64 panic("open1: %r");
65 if(open("/dev/cons", OWRITE) != 2)
66 panic("open2: %r");
67
68 cpumain(argc, argv);
69 return 0;
70 }
71
72 char*
getkey(char * user,char * dom)73 getkey(char *user, char *dom)
74 {
75 char buf[1024];
76
77 snprint(buf, sizeof buf, "%s@%s password", user, dom);
78 return readcons(buf, nil, 1);
79 }
80
81 char*
findkey(char ** puser,char * dom)82 findkey(char **puser, char *dom)
83 {
84 char buf[1024], *f[50], *p, *ep, *nextp, *pass, *user;
85 int nf, haveproto, havedom, i;
86
87 for(p=secstorebuf; *p; p=nextp){
88 nextp = strchr(p, '\n');
89 if(nextp == nil){
90 ep = p+strlen(p);
91 nextp = "";
92 }else{
93 ep = nextp++;
94 }
95 if(ep-p >= sizeof buf){
96 print("warning: skipping long line in secstore factotum file\n");
97 continue;
98 }
99 memmove(buf, p, ep-p);
100 buf[ep-p] = 0;
101 nf = tokenize(buf, f, nelem(f));
102 if(nf == 0 || strcmp(f[0], "key") != 0)
103 continue;
104 pass = nil;
105 haveproto = havedom = 0;
106 user = nil;
107 for(i=1; i<nf; i++){
108 if(strncmp(f[i], "user=", 5) == 0)
109 user = f[i]+5;
110 if(strncmp(f[i], "!password=", 10) == 0)
111 pass = f[i]+10;
112 if(strncmp(f[i], "dom=", 4) == 0 && strcmp(f[i]+4, dom) == 0)
113 havedom = 1;
114 if(strcmp(f[i], "proto=p9sk1") == 0)
115 haveproto = 1;
116 }
117 if(!haveproto || !havedom || !pass || !user)
118 continue;
119 *puser = strdup(user);
120 pass = strdup(pass);
121 memset(buf, 0, sizeof buf);
122 return pass;
123 }
124 return nil;
125 }
126
127