1 #include <u.h>
2 #include <libc.h>
3 #include <auth.h>
4 #include <fcall.h>
5 #include <thread.h>
6 #include <9p.h>
7 #include "cifs.h"
8
9
10 struct {
11 char *name;
12 int (*func)(Fmt *f);
13 char *buf;
14 int len;
15 } Infdir[] = {
16 { "Users", userinfo },
17 { "Groups", groupinfo },
18 { "Shares", shareinfo },
19 { "Connection", conninfo },
20 { "Sessions", sessioninfo },
21 { "Dfsroot", dfsrootinfo },
22 { "Dfscache", dfscacheinfo },
23 { "Domains", domaininfo },
24 { "Openfiles", openfileinfo },
25 { "Workstations", workstationinfo },
26 { "Filetable", filetableinfo },
27 };
28
29 int
walkinfo(char * name)30 walkinfo(char *name)
31 {
32 int i;
33
34 for(i = 0; i < nelem(Infdir); i++)
35 if(strcmp(Infdir[i].name, name) == 0)
36 return(i);
37 return -1;
38 }
39
40 int
numinfo(void)41 numinfo(void)
42 {
43 return nelem(Infdir);
44 }
45
46 int
dirgeninfo(int slot,Dir * d)47 dirgeninfo(int slot, Dir *d)
48 {
49 if(slot < 0 || slot > nelem(Infdir))
50 return -1;
51
52 memset(d, 0, sizeof(Dir));
53 d->type = 'N';
54 d->dev = 99;
55 d->name = estrdup9p(Infdir[slot].name);
56 d->uid = estrdup9p("other");
57 d->muid = estrdup9p("other");
58 d->gid = estrdup9p("other");
59 d->mode = 0666;
60 d->atime = time(0);
61 d->mtime = d->atime;
62 d->qid = mkqid(Infdir[slot].name, 0, 1, Pinfo, slot);
63 d->qid.vers = 1;
64 d->qid.path = slot;
65 d->qid.type = 0;
66 return 0;
67 }
68
69 int
makeinfo(int path)70 makeinfo(int path)
71 {
72 Fmt f;
73
74 if(path < 0 || path > nelem(Infdir))
75 return -1;
76 if(Infdir[path].buf != nil)
77 return 0;
78 fmtstrinit(&f);
79 if((*Infdir[path].func)(&f) == -1l)
80 return -1;
81 Infdir[path].buf = fmtstrflush(&f);
82 Infdir[path].len = strlen(Infdir[path].buf);
83 return 0;
84 }
85
86 int
readinfo(int path,char * buf,int len,int off)87 readinfo(int path, char *buf, int len, int off)
88 {
89 if(path < 0 || path > nelem(Infdir))
90 return -1;
91 if(off > Infdir[path].len)
92 return 0;
93 if(len + off > Infdir[path].len)
94 len = Infdir[path].len - off;
95 memmove(buf, Infdir[path].buf + off, len);
96 return len;
97 }
98
99 void
freeinfo(int path)100 freeinfo(int path)
101 {
102 if(path < 0 || path > nelem(Infdir))
103 return;
104 free(Infdir[path].buf);
105 Infdir[path].buf = nil;
106 }
107