// Samba Test // // Douglas Thrift // // $Id$ #include #include #include #include extern "C" { #include #include #include } #include struct Exception { int code; Exception(int code) : code(code) {} }; std::ostream& operator<<(std::ostream& out, const Exception& exception) { return out << "Exception(" << exception.code << ")[" << ::strerror(exception.code) << ']'; } inline int check(int code) { if (code < 0) throw Exception(errno); return code; } extern "C" { void authenticate(const char* srv, const char* shr, char* wg, int wglen, char* un, int unlen, char* pw, int pwlen) { std::cout << "srv = " << srv << std::endl << "shr = " << shr << std::endl << "wg = " << wg << std::endl << "un = " << un << std::endl << "un = "; std::string line; std::getline(std::cin, line); if (!line.empty()) std::snprintf(un, unlen, line.c_str()); std::snprintf(pw, pwlen, "%s", ::getpass("pw = ")); } } int main(int argc, char* argv[]) { std::string uri("smb://"); for (int index(1); index < argc; ++index) { uri += argv[index]; uri += '/'; } try { check(::smbc_init(authenticate, 2)); int dir(check(::smbc_opendir(uri.c_str()))); ::smbc_dirent* ent; while ((ent = ::smbc_readdir(dir)) != NULL) { std::cout << "ent.smbc_type = "; switch (ent->smbc_type) { case SMBC_WORKGROUP: std::cout << "workgroup"; break; case SMBC_SERVER: std::cout << "server"; break; case SMBC_FILE_SHARE: std::cout << "file share"; break; case SMBC_PRINTER_SHARE: std::cout << "printer share"; break; case SMBC_COMMS_SHARE: std::cout << "comms share"; break; case SMBC_IPC_SHARE: std::cout << "ipc share"; break; case SMBC_DIR: std::cout << "dir"; break; case SMBC_FILE: std::cout << "file"; break; case SMBC_LINK: std::cout << "link"; } std::cout << std::endl << "ent.comment = " << ent->comment << std::endl << "ent.name = " << ent->name << std::endl; } check(::smbc_closedir(dir)); } catch (Exception exception) { std::cerr << exception << std::endl; } return 0; }