7
7
Copyright (C) Tom Jansen (Ninja ISD) 2002
8
8
Copyright (C) Derrell Lipman 2003-2008
9
9
Copyright (C) Jeremy Allison 2007, 2008
11
11
This program is free software; you can redistribute it and/or modify
12
12
it under the terms of the GNU General Public License as published by
13
13
the Free Software Foundation; either version 3 of the License, or
14
14
(at your option) any later version.
16
16
This program is distributed in the hope that it will be useful,
17
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
19
GNU General Public License for more details.
21
21
You should have received a copy of the GNU General Public License
22
22
along with this program. If not, see <http://www.gnu.org/licenses/>.
64
64
if (old_length == 0) {
69
69
for (i = 0; i < old_length; ) {
70
70
unsigned char character = src[i++];
72
72
if (character == '%') {
73
73
int a = i+1 < old_length ? hex2int(src[i]) : -1;
74
74
int b = i+1 < old_length ? hex2int(src[i+1]) : -1;
76
76
/* Replace valid sequence */
77
77
if (a != -1 && b != -1) {
78
78
/* Replace valid %xx sequence with %dd */
91
91
dest = TALLOC_ARRAY(ctx, char, newlen);
97
97
for (p = dest, i = 0; i < old_length; ) {
98
98
unsigned char character = src[i++];
100
100
if (character == '%') {
101
101
int a = i+1 < old_length ? hex2int(src[i]) : -1;
102
102
int b = i+1 < old_length ? hex2int(src[i+1]) : -1;
104
104
/* Replace valid sequence */
105
105
if (a != -1 && b != -1) {
106
106
/* Replace valid %xx sequence with %dd */
129
129
TALLOC_CTX *frame = talloc_stackframe();
131
131
int ret = urldecode_talloc(frame, &pdest, src);
134
134
strlcpy(dest, pdest, max_dest_len);
236
236
char *workgroup = NULL;
239
239
/* Ensure these returns are at least valid pointers. */
240
240
*pp_server = talloc_strdup(ctx, "");
241
241
*pp_share = talloc_strdup(ctx, "");
242
242
*pp_path = talloc_strdup(ctx, "");
243
243
*pp_user = talloc_strdup(ctx, "");
244
244
*pp_password = talloc_strdup(ctx, "");
246
246
if (!*pp_server || !*pp_share || !*pp_path ||
247
247
!*pp_user || !*pp_password) {
252
252
* Assume we wont find an authentication domain to parse, so default
253
253
* to the workgroup in the provided context.
257
257
talloc_strdup(ctx, smbc_getWorkgroup(context));
260
260
if (pp_options) {
261
261
*pp_options = talloc_strdup(ctx, "");
263
263
s = talloc_strdup(ctx, fname);
265
265
/* see if it has the right prefix */
266
266
len = strlen(SMBC_PREFIX);
267
267
if (strncmp(s,SMBC_PREFIX,len) || (s[len] != '/' && s[len] != 0)) {
268
268
return -1; /* What about no smb: ? */
273
273
/* Watch the test below, we are testing to see if we should exit */
275
275
if (strncmp(p, "//", 2) && strncmp(p, "\\\\", 2)) {
276
276
DEBUG(1, ("Invalid path (does not begin with smb://"));
280
280
p += 2; /* Skip the double slash */
282
282
/* See if any options were specified */
283
283
if ((q = strrchr(p, '?')) != NULL ) {
284
284
/* There are options. Null terminate here and point to them */
287
287
DEBUG(4, ("Found options '%s'", q));
289
289
/* Copy the options */
290
290
if (pp_options && *pp_options != NULL) {
291
291
TALLOC_FREE(*pp_options);
292
292
*pp_options = talloc_strdup(ctx, q);
296
296
if (*p == '\0') {
301
301
int wl = strlen(smbc_getWorkgroup(context));
307
307
*pp_server = talloc_strdup(ctx, smbc_getWorkgroup(context));
308
308
if (!*pp_server) {
311
311
(*pp_server)[wl] = '\0';
316
316
* ok, its for us. Now parse out the server, share etc.
318
318
* However, we want to parse out [[domain;]user[:password]@] if it
322
322
/* check that '@' occurs before '/', if '/' exists at all */
323
323
q = strchr_m(p, '@');
324
324
r = strchr_m(p, '/');
325
325
if (q && (!r || q < r)) {
326
326
char *userinfo = NULL;
329
329
next_token_no_ltrim_talloc(ctx, &p, &userinfo, "@");
335
335
if (strchr_m(u, ';')) {
336
336
next_token_no_ltrim_talloc(ctx, &u, &workgroup, ";");
337
337
if (!workgroup) {
362
362
if (!next_token_talloc(ctx, &p, pp_server, "/")) {
366
366
if (*p == (char)0) {
367
367
goto decoding; /* That's it ... */
370
370
if (!next_token_talloc(ctx, &p, pp_share, "/")) {
375
375
* Prepend a leading slash if there's a file path, as required by
388
388
string_replace(*pp_path, '/', '\\');
392
391
(void) urldecode_talloc(ctx, pp_path, *pp_path);
393
392
(void) urldecode_talloc(ctx, pp_server, *pp_server);
394
393
(void) urldecode_talloc(ctx, pp_share, *pp_share);