plunder 2.0.0a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/agent +48 -0
- data/bin/plunder +158 -0
- data/ext/fsdb/extconf.rb +13 -0
- data/ext/fsdb/fsdb-c.c +134 -0
- data/ext/fsdb/fsdb-c.h +49 -0
- data/ext/fsdb/fsdb.c +267 -0
- data/ext/fsdb/hash.c +140 -0
- data/ext/fsdb/hash.h +52 -0
- data/ext/fsdb/test.c +90 -0
- data/ext/fsdb/utilities.c +125 -0
- data/ext/fsdb/utilities.h +32 -0
- data/ext/fsdb/vault.c +78 -0
- data/ext/fsdb/vault.h +44 -0
- data/ext/smbclient/extconf.rb +32 -0
- data/ext/smbclient/smb.c +234 -0
- data/ext/smbclient/smb.h +61 -0
- data/ext/smbclient/smbclient.c +116 -0
- data/lib/core/agent.rb +67 -0
- data/lib/core/analyzer.rb +84 -0
- data/lib/core/client.rb +163 -0
- data/lib/core/commands.rb +53 -0
- data/lib/core/config.rb +103 -0
- data/lib/core/io.rb +84 -0
- data/lib/core/plunder.rb +208 -0
- data/lib/core/report.rb +78 -0
- data/lib/core/target.rb +33 -0
- data/lib/core/tree.rb +59 -0
- metadata +74 -0
data/ext/fsdb/vault.h
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Plunder - SMB scanning and auditing tool
|
|
3
|
+
// Copyright (C) 2017 Joshua Stone
|
|
4
|
+
//
|
|
5
|
+
// This program is free software; you can redistribute it and/or
|
|
6
|
+
// modify it under the terms of the GNU General Public License
|
|
7
|
+
// as published by the Free Software Foundation; either version 2
|
|
8
|
+
// of the License, or (at your option) any later version.
|
|
9
|
+
//
|
|
10
|
+
// This program is distributed in the hope that it will be useful,
|
|
11
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
// GNU General Public License for more details.
|
|
14
|
+
//
|
|
15
|
+
// You should have received a copy of the GNU General Public License
|
|
16
|
+
// along with this program; if not, write to the Free Software
|
|
17
|
+
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
18
|
+
//
|
|
19
|
+
|
|
20
|
+
#ifndef VAULT_H
|
|
21
|
+
#define VAULT_H
|
|
22
|
+
|
|
23
|
+
#include <stdint.h>
|
|
24
|
+
#include <stdlib.h>
|
|
25
|
+
#include <string.h>
|
|
26
|
+
#include <stdio.h>
|
|
27
|
+
|
|
28
|
+
#include "utilities.h"
|
|
29
|
+
|
|
30
|
+
typedef struct {
|
|
31
|
+
uint8_t *base;
|
|
32
|
+
uint32_t top;
|
|
33
|
+
uint32_t count;
|
|
34
|
+
uint32_t size;
|
|
35
|
+
} vault;
|
|
36
|
+
|
|
37
|
+
vault vault_init(uint32_t size);
|
|
38
|
+
uint8_t *vault_get(vault v, uint32_t offset);
|
|
39
|
+
uint32_t vault_insert_string(vault *v, char *s);
|
|
40
|
+
uint32_t vault_insert_bytes(vault *v, void *p, uint32_t bytes);
|
|
41
|
+
void vault_info(vault v, char *name);
|
|
42
|
+
void vault_free(vault v);
|
|
43
|
+
|
|
44
|
+
#endif
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Loads mkmf which is used to make makefiles for Ruby extensions
|
|
2
|
+
require 'mkmf'
|
|
3
|
+
|
|
4
|
+
extension_name = 'smbclient'
|
|
5
|
+
|
|
6
|
+
success = true
|
|
7
|
+
|
|
8
|
+
unless have_header("samba-4.0/libsmbclient.h")
|
|
9
|
+
puts "\x1b[31;1m"
|
|
10
|
+
puts "-------- missing dependency --------"
|
|
11
|
+
puts "must have 'samba-4.0/libsmbclient.h' to compile smbclient extension"
|
|
12
|
+
puts "perhaps you need to install 'libsmbclient-devel' or 'libsmbclient-dev'?"
|
|
13
|
+
puts ""
|
|
14
|
+
puts "Note: if libsmbclient is installed, but not the *-dev[el] package,"
|
|
15
|
+
puts " then I can't find the headers to compile."
|
|
16
|
+
puts "\x1b[0m"
|
|
17
|
+
success = false
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
unless have_library("smbclient")
|
|
21
|
+
puts "\x1b[31;1m"
|
|
22
|
+
puts "-------- missing dependency --------"
|
|
23
|
+
puts "must have smbclient library to compile smbclient extension"
|
|
24
|
+
puts "perhaps you need to install 'libsmbclient' package?"
|
|
25
|
+
puts "\x1b[0m"
|
|
26
|
+
success = false
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
exit 1 unless success
|
|
30
|
+
|
|
31
|
+
dir_config(extension_name)
|
|
32
|
+
create_makefile(extension_name)
|
data/ext/smbclient/smb.c
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Plunder - SMB scanning and auditing tool
|
|
3
|
+
// Copyright (C) 2017 Joshua Stone
|
|
4
|
+
//
|
|
5
|
+
// This program is free software; you can redistribute it and/or
|
|
6
|
+
// modify it under the terms of the GNU General Public License
|
|
7
|
+
// as published by the Free Software Foundation; either version 2
|
|
8
|
+
// of the License, or (at your option) any later version.
|
|
9
|
+
//
|
|
10
|
+
// This program is distributed in the hope that it will be useful,
|
|
11
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
// GNU General Public License for more details.
|
|
14
|
+
//
|
|
15
|
+
// You should have received a copy of the GNU General Public License
|
|
16
|
+
// along with this program; if not, write to the Free Software
|
|
17
|
+
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
18
|
+
//
|
|
19
|
+
|
|
20
|
+
#include "smb.h"
|
|
21
|
+
|
|
22
|
+
// We want to dynamically grow the buffer sizes to make sure they
|
|
23
|
+
// are always big enough for the values they need to store. This
|
|
24
|
+
// is an ugly conditional to splatter all over, so we can clean
|
|
25
|
+
// it up a big with a macro.
|
|
26
|
+
|
|
27
|
+
#define CHECK_SIZE(ptr, len) if(ptr == NULL) {\
|
|
28
|
+
ptr = (char *) malloc(len);\
|
|
29
|
+
} else if(strlen(ptr) < len) {\
|
|
30
|
+
ptr = (char *) realloc(ptr, len);\
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
void smb_init() {
|
|
34
|
+
SMBC_DOMAIN = NULL;
|
|
35
|
+
SMBC_USERNAME = NULL;
|
|
36
|
+
SMBC_PASSWORD = NULL;
|
|
37
|
+
cred_root = NULL;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
SMBCCTX *get_context() {
|
|
41
|
+
SMBCCTX *context = smbc_new_context();
|
|
42
|
+
|
|
43
|
+
smbc_setFunctionAuthDataWithContext(context, smb_auth_fn);
|
|
44
|
+
smbc_setOptionNoAutoAnonymousLogin(context, 1);
|
|
45
|
+
smbc_setOptionUrlEncodeReaddirEntries(context, 1);
|
|
46
|
+
smbc_setTimeout(context, 5000);
|
|
47
|
+
smbc_init_context(context);
|
|
48
|
+
smbc_set_context(context);
|
|
49
|
+
|
|
50
|
+
return context;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
void free_node(cred_node *node) {
|
|
54
|
+
free(node->domain);
|
|
55
|
+
free(node->username);
|
|
56
|
+
free(node->password);
|
|
57
|
+
free(node);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
void free_context(SMBCCTX *context) {
|
|
61
|
+
cred_node *prev = NULL;
|
|
62
|
+
cred_node *node = NULL;
|
|
63
|
+
|
|
64
|
+
if(cred_root) {
|
|
65
|
+
if(cred_root->context == context) {
|
|
66
|
+
node = cred_root;
|
|
67
|
+
cred_root = (cred_node *)cred_root->next;
|
|
68
|
+
free_node(node);
|
|
69
|
+
} else if(cred_root->next) {
|
|
70
|
+
prev = cred_root;
|
|
71
|
+
node = (cred_node *)cred_root->next;
|
|
72
|
+
while(node) {
|
|
73
|
+
if(node->context == context) {
|
|
74
|
+
prev->next = node->next;
|
|
75
|
+
free_node(node);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
prev = node;
|
|
79
|
+
node = (cred_node *)node->next;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
smbc_free_context(context, 1);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
void smb_set_creds(SMBCCTX *context, char *domain, char *user, char *password) {
|
|
88
|
+
int d_len = strlen(domain) + 1;
|
|
89
|
+
int u_len = strlen(user) + 1;
|
|
90
|
+
int p_len = strlen(password) + 1;
|
|
91
|
+
cred_node *node;
|
|
92
|
+
|
|
93
|
+
node = cred_root;
|
|
94
|
+
|
|
95
|
+
while(node) {
|
|
96
|
+
if(node->context == context) {
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
node = (cred_node *)node->next;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if(node) {
|
|
103
|
+
free(node->domain);
|
|
104
|
+
free(node->username);
|
|
105
|
+
free(node->password);
|
|
106
|
+
} else {
|
|
107
|
+
node = (cred_node *) malloc(sizeof(cred_node));
|
|
108
|
+
node->context = context;
|
|
109
|
+
node->next = (struct cred_node *)cred_root;
|
|
110
|
+
cred_root = node;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
node->domain = (char *)malloc(d_len);
|
|
114
|
+
node->username = (char *)malloc(u_len);
|
|
115
|
+
node->password = (char *)malloc(p_len);
|
|
116
|
+
|
|
117
|
+
strncpy(node->domain, domain, d_len);
|
|
118
|
+
strncpy(node->username, user, u_len);
|
|
119
|
+
strncpy(node->password, password, p_len);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
int smb_test_creds(SMBCCTX *context, char *url, int type) {
|
|
123
|
+
int dir;
|
|
124
|
+
int result;
|
|
125
|
+
|
|
126
|
+
smbc_set_context(context);
|
|
127
|
+
if(type == 0) {
|
|
128
|
+
dir = smbc_opendir(url);
|
|
129
|
+
} else {
|
|
130
|
+
dir = smbc_open(url, O_RDONLY, 'r');
|
|
131
|
+
}
|
|
132
|
+
result = dir < 0 ? 0 : 1;
|
|
133
|
+
smbc_close(dir);
|
|
134
|
+
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
int smb_is_container(struct smbc_dirent *dirent) {
|
|
139
|
+
int len = strlen(dirent->name);
|
|
140
|
+
return (dirent->smbc_type == SMBC_WORKGROUP ||
|
|
141
|
+
dirent->smbc_type == SMBC_SERVER ||
|
|
142
|
+
dirent->smbc_type == SMBC_FILE_SHARE ||
|
|
143
|
+
dirent->smbc_type == SMBC_DIR) &&
|
|
144
|
+
strncmp(".", dirent->name, len) &&
|
|
145
|
+
strncmp("..", dirent->name, len);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
int smb_list_contents(SMBCCTX *context, char *url, VALUE dirs, VALUE files) {
|
|
149
|
+
int dir = 0;
|
|
150
|
+
int len;
|
|
151
|
+
struct smbc_dirent *dirent;
|
|
152
|
+
|
|
153
|
+
smbc_set_context(context);
|
|
154
|
+
|
|
155
|
+
if((dir = smbc_opendir(url)) >= 0) {
|
|
156
|
+
while(dir >= 0 && (dirent = smbc_readdir(dir))) {
|
|
157
|
+
len = strlen(dirent->name);
|
|
158
|
+
if(smb_is_container(dirent)) {
|
|
159
|
+
rb_ary_push(dirs, rb_str_new2(dirent->name));
|
|
160
|
+
} else if(strncmp(".", dirent->name, len) &&
|
|
161
|
+
strncmp("..", dirent->name, len)) {
|
|
162
|
+
rb_ary_push(files, rb_str_new2(dirent->name));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
FILE *f;
|
|
167
|
+
if(dir == -1 && errno == 1) {
|
|
168
|
+
f = fopen("agent.log", "a");
|
|
169
|
+
fprintf(f, "EACCES at %s\n", url);
|
|
170
|
+
fclose(f);
|
|
171
|
+
return 0;
|
|
172
|
+
} else if(errno == 13) {
|
|
173
|
+
// permission error
|
|
174
|
+
} else {
|
|
175
|
+
f = fopen("agent.log", "a");
|
|
176
|
+
fprintf(f, "SMB operation failed with handle %d, errno: %d at %s\n", dir, errno, url);
|
|
177
|
+
fclose(f);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
smbc_closedir(dir);
|
|
182
|
+
return 1;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
void smb_auth_fn(SMBCCTX * context,
|
|
186
|
+
const char * pServer,
|
|
187
|
+
const char * pShare,
|
|
188
|
+
char * pWorkgroup,
|
|
189
|
+
int maxLenWorkgroup,
|
|
190
|
+
char * pUsername,
|
|
191
|
+
int maxLenUsername,
|
|
192
|
+
char * pPassword,
|
|
193
|
+
int maxLenPassword) {
|
|
194
|
+
|
|
195
|
+
cred_node *node = cred_root;
|
|
196
|
+
|
|
197
|
+
while(node) {
|
|
198
|
+
if(node->context == context) {
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
node = (cred_node *)node->next;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if(node) {
|
|
205
|
+
strncpy(pWorkgroup, node->domain, maxLenWorkgroup - 1);
|
|
206
|
+
strncpy(pUsername, node->username, maxLenUsername - 1);
|
|
207
|
+
strncpy(pPassword, node->password, maxLenPassword - 1);
|
|
208
|
+
} else {
|
|
209
|
+
fprintf(stderr, "Error: cannot set credentials for uninitialized context!\n");
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
char *slurp_file(SMBCCTX *context, char *url, int *size) {
|
|
214
|
+
int fd;
|
|
215
|
+
char *buffer;
|
|
216
|
+
struct stat st;
|
|
217
|
+
|
|
218
|
+
*size = 0;
|
|
219
|
+
smbc_set_context(context);
|
|
220
|
+
if((fd = smbc_open(url, O_RDONLY, 0)) >= 0) {
|
|
221
|
+
if(smbc_fstat(fd, &st) >= 0) {
|
|
222
|
+
buffer = (char *)malloc(st.st_size);
|
|
223
|
+
smbc_read(fd, buffer, st.st_size);
|
|
224
|
+
*size = st.st_size;
|
|
225
|
+
return buffer;
|
|
226
|
+
} else {
|
|
227
|
+
fprintf(stderr, "ERROR: Cannot stat file %s\n", url);
|
|
228
|
+
return NULL;
|
|
229
|
+
}
|
|
230
|
+
} else {
|
|
231
|
+
fprintf(stderr, "ERROR: Cannot open file %s\n", url);
|
|
232
|
+
return NULL;
|
|
233
|
+
}
|
|
234
|
+
}
|
data/ext/smbclient/smb.h
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Plunder - SMB scanning and auditing tool
|
|
3
|
+
// Copyright (C) 2017 Joshua Stone
|
|
4
|
+
//
|
|
5
|
+
// This program is free software; you can redistribute it and/or
|
|
6
|
+
// modify it under the terms of the GNU General Public License
|
|
7
|
+
// as published by the Free Software Foundation; either version 2
|
|
8
|
+
// of the License, or (at your option) any later version.
|
|
9
|
+
//
|
|
10
|
+
// This program is distributed in the hope that it will be useful,
|
|
11
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
// GNU General Public License for more details.
|
|
14
|
+
//
|
|
15
|
+
// You should have received a copy of the GNU General Public License
|
|
16
|
+
// along with this program; if not, write to the Free Software
|
|
17
|
+
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
18
|
+
//
|
|
19
|
+
|
|
20
|
+
#ifndef SMB_H
|
|
21
|
+
#define SMB_H
|
|
22
|
+
|
|
23
|
+
#include <sys/types.h>
|
|
24
|
+
#include <unistd.h>
|
|
25
|
+
#include <dirent.h>
|
|
26
|
+
#include <errno.h>
|
|
27
|
+
#include <stdio.h>
|
|
28
|
+
#include <string.h>
|
|
29
|
+
#include <stdlib.h>
|
|
30
|
+
#include <ruby.h>
|
|
31
|
+
|
|
32
|
+
#include <samba-4.0/libsmbclient.h>
|
|
33
|
+
|
|
34
|
+
char *SMBC_DOMAIN;
|
|
35
|
+
char *SMBC_USERNAME;
|
|
36
|
+
char *SMBC_PASSWORD;
|
|
37
|
+
|
|
38
|
+
typedef struct {
|
|
39
|
+
SMBCCTX *context;
|
|
40
|
+
char *domain;
|
|
41
|
+
char *username;
|
|
42
|
+
char *password;
|
|
43
|
+
struct cred_node *next;
|
|
44
|
+
} cred_node;
|
|
45
|
+
|
|
46
|
+
cred_node *cred_root;
|
|
47
|
+
|
|
48
|
+
SMBCCTX *get_context();
|
|
49
|
+
|
|
50
|
+
void smb_init();
|
|
51
|
+
void smb_set_creds(SMBCCTX *context, char *domain, char *user, char *password);
|
|
52
|
+
int smb_test_creds(SMBCCTX *context, char *url, int type);
|
|
53
|
+
void free_context(SMBCCTX *context);
|
|
54
|
+
int smb_is_container(struct smbc_dirent *dirent);
|
|
55
|
+
int smb_list_contents(SMBCCTX *context, char *url, VALUE dirs, VALUE files);
|
|
56
|
+
char *slurp_file(SMBCCTX *context, char *url, int *size);
|
|
57
|
+
|
|
58
|
+
void smb_auth_fn(SMBCCTX *, const char *, const char *, char *,
|
|
59
|
+
int, char *, int, char *, int);
|
|
60
|
+
|
|
61
|
+
#endif
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Plunder - SMB scanning and auditing tool
|
|
3
|
+
// Copyright (C) 2017 Joshua Stone
|
|
4
|
+
//
|
|
5
|
+
// This program is free software; you can redistribute it and/or
|
|
6
|
+
// modify it under the terms of the GNU General Public License
|
|
7
|
+
// as published by the Free Software Foundation; either version 2
|
|
8
|
+
// of the License, or (at your option) any later version.
|
|
9
|
+
//
|
|
10
|
+
// This program is distributed in the hope that it will be useful,
|
|
11
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
// GNU General Public License for more details.
|
|
14
|
+
//
|
|
15
|
+
// You should have received a copy of the GNU General Public License
|
|
16
|
+
// along with this program; if not, write to the Free Software
|
|
17
|
+
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
18
|
+
//
|
|
19
|
+
|
|
20
|
+
#include <ruby.h>
|
|
21
|
+
#include <ctype.h>
|
|
22
|
+
|
|
23
|
+
#include "smb.h"
|
|
24
|
+
|
|
25
|
+
VALUE module = Qnil;
|
|
26
|
+
VALUE smb_klass = Qnil;
|
|
27
|
+
|
|
28
|
+
void Init_smbclient();
|
|
29
|
+
VALUE smb_method_new(VALUE self, VALUE dom, VALUE user, VALUE pass);
|
|
30
|
+
VALUE smb_method_set_creds(VALUE self, VALUE dom, VALUE user, VALUE pass);
|
|
31
|
+
VALUE smb_method_login(VALUE self, VALUE url);
|
|
32
|
+
VALUE smb_method_list_contents(VALUE self, VALUE url);
|
|
33
|
+
VALUE smb_method_slurp(VALUE self, VALUE url);
|
|
34
|
+
|
|
35
|
+
void Init_smbclient() {
|
|
36
|
+
smb_init();
|
|
37
|
+
|
|
38
|
+
smb_klass = rb_define_class("SMBClient", rb_cObject);
|
|
39
|
+
|
|
40
|
+
rb_define_singleton_method(smb_klass, "new", smb_method_new, 3);
|
|
41
|
+
|
|
42
|
+
rb_define_method(smb_klass, "set_creds", smb_method_set_creds, 3);
|
|
43
|
+
rb_define_method(smb_klass, "login", smb_method_login, 1);
|
|
44
|
+
rb_define_method(smb_klass, "list", smb_method_list_contents, 1);
|
|
45
|
+
rb_define_method(smb_klass, "slurp", smb_method_slurp, 1);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
VALUE smb_method_new(VALUE self, VALUE dom, VALUE user, VALUE pass) {
|
|
49
|
+
SMBCCTX *context;
|
|
50
|
+
|
|
51
|
+
context = get_context();
|
|
52
|
+
smb_set_creds(context,
|
|
53
|
+
StringValueCStr(dom),
|
|
54
|
+
StringValueCStr(user),
|
|
55
|
+
StringValueCStr(pass));
|
|
56
|
+
|
|
57
|
+
return Data_Wrap_Struct(smb_klass, NULL, free_context, context);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
VALUE smb_method_set_creds(VALUE self, VALUE dom, VALUE user, VALUE pass) {
|
|
61
|
+
SMBCCTX *context;
|
|
62
|
+
char *d = StringValueCStr(dom);
|
|
63
|
+
char *u = StringValueCStr(user);
|
|
64
|
+
char *p = StringValueCStr(pass);
|
|
65
|
+
|
|
66
|
+
Data_Get_Struct(self, SMBCCTX, context);
|
|
67
|
+
smb_set_creds(context, d, u, p);
|
|
68
|
+
|
|
69
|
+
return Qtrue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
VALUE smb_method_login(VALUE self, VALUE url) {
|
|
73
|
+
SMBCCTX *context;
|
|
74
|
+
char *u = StringValueCStr(url);
|
|
75
|
+
int len = strlen(u);
|
|
76
|
+
int type = u[len-1] != '/';
|
|
77
|
+
|
|
78
|
+
Data_Get_Struct(self, SMBCCTX, context);
|
|
79
|
+
int value = smb_test_creds(context, u, type);
|
|
80
|
+
return (value == 1) ? Qtrue : Qfalse;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
VALUE smb_method_list_contents(VALUE self, VALUE url) {
|
|
84
|
+
SMBCCTX *context;
|
|
85
|
+
VALUE dirs;
|
|
86
|
+
VALUE files;
|
|
87
|
+
VALUE ret;
|
|
88
|
+
|
|
89
|
+
char *u = StringValueCStr(url);
|
|
90
|
+
dirs = rb_ary_new();
|
|
91
|
+
files = rb_ary_new();
|
|
92
|
+
ret = rb_ary_new();
|
|
93
|
+
|
|
94
|
+
Data_Get_Struct(self, SMBCCTX, context);
|
|
95
|
+
if(!smb_list_contents(context, u, dirs, files)) {
|
|
96
|
+
return Qnil;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
rb_ary_push(ret, dirs);
|
|
100
|
+
rb_ary_push(ret, files);
|
|
101
|
+
|
|
102
|
+
return ret;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
VALUE smb_method_slurp(VALUE self, VALUE url) {
|
|
106
|
+
SMBCCTX *context;
|
|
107
|
+
int size;
|
|
108
|
+
char *u = StringValueCStr(url);
|
|
109
|
+
Data_Get_Struct(self, SMBCCTX, context);
|
|
110
|
+
char *b = slurp_file(context, u, &size);
|
|
111
|
+
VALUE v = rb_str_new(b, size);
|
|
112
|
+
free(b);
|
|
113
|
+
|
|
114
|
+
return v;
|
|
115
|
+
}
|
|
116
|
+
|