// Spectre Samba Mounter // // Douglas Thrift // // Maker.cpp #include "Maker.h" void Maker::make() { samba(); struct stat dir; if (stat(config.root.c_str(), &dir) != 0) { if (mkdir(config.root.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) != 0) { string prefix = program + ": " + config.root; perror(prefix.c_str()); } } string path = config.root + "/" + host; if (stat(path.c_str(), &dir) != 0) { if (mkdir(path.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) != 0) { string prefix = program + ": " + path; perror(prefix.c_str()); } } for (map::iterator itor = folders.begin(); itor != folders.end(); itor++) { make(itor->first, itor->second.local); } } void Maker::samba() { vector args; args.push_back("-N"); args.push_back("-L"); args.push_back(host); args.push_back("-U"); args.push_back(regular.remote + "%" + password(regular.remote)); ipstream smbclient(config.smbclient, args); // } void Maker::make(const string& folder, const string& user) { struct stat dir; string path = config.root + "/" + host + "/" + folder; if (stat(path.c_str(), &dir) != 0) { if (mkdir(path.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) != 0) { string prefix = program + ": " + path; perror(prefix.c_str()); } } struct passwd* item = getpwnam(user.c_str()); if (item == NULL) { cerr << program << ": " << user << ": Unknown user\n"; return; } if (dir.st_uid == item->pw_uid && dir.st_gid == item->pw_gid) return; if (chown(path.c_str(), item->pw_uid, item->pw_gid) != 0) { string prefix = program + ": " + path; perror(prefix.c_str()); } }