ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/Spectre/Maker.cpp
Revision: 165
Committed: 2003-06-14T00:52:30-07:00 (22 years ago) by douglas
File size: 1692 byte(s)
Log Message:
Maker just needs more Samba stuff!

File Contents

# User Rev Content
1 douglas 161 // Spectre Samba Mounter
2     //
3     // Douglas Thrift
4     //
5     // Maker.cpp
6 douglas 148
7 douglas 161 #include "Maker.h"
8    
9     void Maker::make()
10     {
11 douglas 165 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 douglas 161 }
43 douglas 165
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     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     }