ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/SambaTest/SambaTest.cpp
Revision: 427
Committed: 2005-03-22T22:57:52-08:00 (20 years, 3 months ago) by douglas
File size: 2324 byte(s)
Log Message:
Hrm, we might want to know this stuff.

File Contents

# Content
1 // Samba Test
2 //
3 // Douglas Thrift
4 //
5 // $Id$
6
7 #include <iostream>
8 #include <string>
9 #include <cstdio>
10 #include <cstring>
11
12 #include <errno.h>
13 #include <pwd.h>
14 #include <unistd.h>
15 #include <libsmbclient.h>
16
17 struct Exception
18 {
19 int code;
20 Exception(int code) : code(code) {}
21 };
22
23 std::ostream& operator<<(std::ostream& out, const Exception& exception)
24 {
25 return out << "Exception(" << exception.code << ")[" << ::strerror(exception.code) << ']';
26 }
27
28 inline int check(int code)
29 {
30 if (code < 0) throw Exception(errno);
31
32 return code;
33 }
34
35 extern "C"
36 {
37 void authenticate(const char* srv, const char* shr, char* wg, int wglen, char* un, int unlen, char* pw, int pwlen)
38 {
39 std::cout << "srv = " << srv << std::endl << "shr = " << shr << std::endl << "wg = " << wg << std::endl << "wglen = " << wglen << std::endl << "un = " << un << std::endl << "unlen = " << unlen << std::endl << "un = ";
40
41 std::string line;
42
43 std::getline(std::cin, line);
44
45 if (!line.empty()) ::snprintf(un, unlen, line.c_str());
46
47 std::cout << "pw = " << pw << std::endl << "pwlen = " << pwlen << std::endl;
48
49 ::snprintf(pw, pwlen, "%s", ::getpass("pw = "));
50 }
51 }
52
53 int main(int argc, char* argv[])
54 {
55 std::string uri("smb://");
56
57 for (int index(1); index < argc; ++index)
58 {
59 uri += argv[index];
60 uri += '/';
61 }
62
63 try
64 {
65 check(::smbc_init(authenticate, 2));
66
67 int dir(check(::smbc_opendir(uri.c_str())));
68 ::smbc_dirent* ent;
69
70 while ((ent = ::smbc_readdir(dir)) != NULL)
71 {
72 std::cout << "ent.smbc_type = ";
73
74 switch (ent->smbc_type)
75 {
76 case SMBC_WORKGROUP:
77 std::cout << "workgroup";
78 break;
79 case SMBC_SERVER:
80 std::cout << "server";
81 break;
82 case SMBC_FILE_SHARE:
83 std::cout << "file share";
84 break;
85 case SMBC_PRINTER_SHARE:
86 std::cout << "printer share";
87 break;
88 case SMBC_COMMS_SHARE:
89 std::cout << "comms share";
90 break;
91 case SMBC_IPC_SHARE:
92 std::cout << "ipc share";
93 break;
94 case SMBC_DIR:
95 std::cout << "dir";
96 break;
97 case SMBC_FILE:
98 std::cout << "file";
99 break;
100 case SMBC_LINK:
101 std::cout << "link";
102 }
103
104 std::cout << std::endl << "ent.comment = " << ent->comment << std::endl << "ent.name = " << ent->name << std::endl;
105 }
106
107 check(::smbc_closedir(dir));
108 }
109 catch (Exception exception)
110 {
111 std::cerr << exception << std::endl;
112 }
113
114 return 0;
115 }

Properties

Name Value
svn:keywords Id