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