ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/Spectre/Maker.cpp
(Generate patch)

Comparing trunk/Spectre/Maker.cpp (file contents):
Revision 148 by douglas, 2003-06-08T16:55:49-07:00 vs.
Revision 165 by douglas, 2003-06-14T00:52:30-07:00

# Line 2 | Line 2
2   //
3   // Douglas Thrift
4   //
5 < // Spectre.cpp
5 > // Maker.cpp
6  
7 #include "Spectre.h"
7   #include "Maker.h"
9 #include "Mounter.h"
8  
9 < int main(int argc, char* argv[])
9 > void Maker::make()
10   {
11 +        samba();
12 +
13 +        struct stat dir;
14 +
15 +        if (stat(config.root.c_str(), &dir) != 0)
16 +        {
17 +                if (mkdir(config.root.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH
18 +                        | S_IXOTH) != 0)
19 +                {
20 +                        string prefix = program + ": " + config.root;
21 +                        perror(prefix.c_str());
22 +                }
23 +        }
24 +
25 +        string path = config.root + "/" + host;
26 +
27 +        if (stat(path.c_str(), &dir) != 0)
28 +        {
29 +                if (mkdir(path.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH
30 +                        | S_IXOTH) != 0)
31 +                {
32 +                        string prefix = program + ": " + path;
33 +                        perror(prefix.c_str());
34 +                }
35 +        }
36 +
37 +        for (map<string, Folder>::iterator itor = folders.begin(); itor
38 +                != folders.end(); itor++)
39 +        {
40 +                make(itor->first, itor->second.local);
41 +        }
42 + }
43 +
44 + void Maker::samba()
45 + {
46 +        vector<string> args;
47 +
48 +        args.push_back("-N");
49 +        args.push_back("-L");
50 +        args.push_back(host);
51 +        args.push_back("-U");
52 +        args.push_back(regular.remote + "%" + password(regular.remote));
53 +
54 +        ipstream smbclient(config.smbclient, args);
55 +
56          //
57 + }
58 +
59 + void Maker::make(const string& folder, const string& user)
60 + {
61 +        struct stat dir;
62 +        string path = config.root + "/" + host + "/" + folder;
63 +
64 +        if (stat(path.c_str(), &dir) != 0)
65 +        {
66 +                if (mkdir(path.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH
67 +                        | S_IXOTH) != 0)
68 +                {
69 +                        string prefix = program + ": " + path;
70 +                        perror(prefix.c_str());
71 +                }
72 +        }
73 +
74 +        struct passwd* item = getpwnam(user.c_str());
75 +
76 +        if (item == NULL)
77 +        {
78 +                cerr << program << ": " << user << ": Unknown user\n";
79 +                return;
80 +        }
81 +
82 +        if (dir.st_uid == item->pw_uid && dir.st_gid == item->pw_gid) return;
83  
84 <        return 0;
84 >        if (chown(path.c_str(), item->pw_uid, item->pw_gid) != 0)
85 >        {
86 >                string prefix = program + ": " + path;
87 >                perror(prefix.c_str());
88 >        }
89   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines