Copyright (C) Tom Jansen (Ninja ISD) 2002
Copyright (C) Derrell Lipman 2003-2008
Copyright (C) Jeremy Allison 2007, 2008
Copyright (C) Tom Jansen (Ninja ISD) 2002
Copyright (C) Derrell Lipman 2003-2008
Copyright (C) Jeremy Allison 2007, 2008
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* Replace valid sequence */
if (a != -1 && b != -1) {
/* Replace valid %xx sequence with %dd */
/* Replace valid sequence */
if (a != -1 && b != -1) {
/* Replace valid %xx sequence with %dd */
err_count = 0;
for (p = dest, i = 0; i < old_length; ) {
unsigned char character = src[i++];
err_count = 0;
for (p = dest, i = 0; i < old_length; ) {
unsigned char character = src[i++];
/* Replace valid sequence */
if (a != -1 && b != -1) {
/* Replace valid %xx sequence with %dd */
/* Replace valid sequence */
if (a != -1 && b != -1) {
/* Replace valid %xx sequence with %dd */
TALLOC_CTX *frame = talloc_stackframe();
char *pdest;
int ret = urldecode_talloc(frame, &pdest, src);
TALLOC_CTX *frame = talloc_stackframe();
char *pdest;
int ret = urldecode_talloc(frame, &pdest, src);
/* Ensure these returns are at least valid pointers. */
*pp_server = talloc_strdup(ctx, "");
*pp_share = talloc_strdup(ctx, "");
*pp_path = talloc_strdup(ctx, "");
*pp_user = talloc_strdup(ctx, "");
*pp_password = talloc_strdup(ctx, "");
/* Ensure these returns are at least valid pointers. */
*pp_server = talloc_strdup(ctx, "");
*pp_share = talloc_strdup(ctx, "");
*pp_path = talloc_strdup(ctx, "");
*pp_user = talloc_strdup(ctx, "");
*pp_password = talloc_strdup(ctx, "");
/*
* Assume we wont find an authentication domain to parse, so default
* to the workgroup in the provided context.
/*
* Assume we wont find an authentication domain to parse, so default
* to the workgroup in the provided context.
if (pp_options) {
*pp_options = talloc_strdup(ctx, "");
}
s = talloc_strdup(ctx, fname);
if (pp_options) {
*pp_options = talloc_strdup(ctx, "");
}
s = talloc_strdup(ctx, fname);
/* see if it has the right prefix */
len = strlen(SMBC_PREFIX);
if (strncmp(s,SMBC_PREFIX,len) || (s[len] != '/' && s[len] != 0)) {
return -1; /* What about no smb: ? */
}
/* see if it has the right prefix */
len = strlen(SMBC_PREFIX);
if (strncmp(s,SMBC_PREFIX,len) || (s[len] != '/' && s[len] != 0)) {
return -1; /* What about no smb: ? */
}
if (strncmp(p, "//", 2) && strncmp(p, "\\\\", 2)) {
DEBUG(1, ("Invalid path (does not begin with smb://"));
return -1;
}
if (strncmp(p, "//", 2) && strncmp(p, "\\\\", 2)) {
DEBUG(1, ("Invalid path (does not begin with smb://"));
return -1;
}
/* See if any options were specified */
if ((q = strrchr(p, '?')) != NULL ) {
/* There are options. Null terminate here and point to them */
*q++ = '\0';
/* See if any options were specified */
if ((q = strrchr(p, '?')) != NULL ) {
/* There are options. Null terminate here and point to them */
*q++ = '\0';
/* Copy the options */
if (pp_options && *pp_options != NULL) {
TALLOC_FREE(*pp_options);
*pp_options = talloc_strdup(ctx, q);
}
}
/* Copy the options */
if (pp_options && *pp_options != NULL) {
TALLOC_FREE(*pp_options);
*pp_options = talloc_strdup(ctx, q);
}
}
/*
* ok, its for us. Now parse out the server, share etc.
*
* However, we want to parse out [[domain;]user[:password]@] if it
* exists ...
*/
/*
* ok, its for us. Now parse out the server, share etc.
*
* However, we want to parse out [[domain;]user[:password]@] if it
* exists ...
*/
/* check that '@' occurs before '/', if '/' exists at all */
q = strchr_m(p, '@');
r = strchr_m(p, '/');
if (q && (!r || q < r)) {
char *userinfo = NULL;
const char *u;
/* check that '@' occurs before '/', if '/' exists at all */
q = strchr_m(p, '@');
r = strchr_m(p, '/');
if (q && (!r || q < r)) {
char *userinfo = NULL;
const char *u;
next_token_no_ltrim_talloc(ctx, &p, &userinfo, "@");
if (!userinfo) {
return -1;
}
u = userinfo;
next_token_no_ltrim_talloc(ctx, &p, &userinfo, "@");
if (!userinfo) {
return -1;
}
u = userinfo;
if (strchr_m(u, ';')) {
next_token_no_ltrim_talloc(ctx, &u, &workgroup, ";");
if (!workgroup) {
if (strchr_m(u, ';')) {
next_token_no_ltrim_talloc(ctx, &u, &workgroup, ";");
if (!workgroup) {
if (strchr_m(u, ':')) {
next_token_no_ltrim_talloc(ctx, &u, pp_user, ":");
if (!*pp_user) {
if (strchr_m(u, ':')) {
next_token_no_ltrim_talloc(ctx, &u, pp_user, ":");
if (!*pp_user) {
if (!next_token_talloc(ctx, &p, pp_server, "/")) {
return -1;
}
if (!next_token_talloc(ctx, &p, pp_server, "/")) {
return -1;
}
if (!next_token_talloc(ctx, &p, pp_share, "/")) {
return -1;
}
if (!next_token_talloc(ctx, &p, pp_share, "/")) {
return -1;
}
(void) urldecode_talloc(ctx, pp_path, *pp_path);
(void) urldecode_talloc(ctx, pp_server, *pp_server);
(void) urldecode_talloc(ctx, pp_share, *pp_share);
(void) urldecode_talloc(ctx, pp_path, *pp_path);
(void) urldecode_talloc(ctx, pp_server, *pp_server);
(void) urldecode_talloc(ctx, pp_share, *pp_share);