Changeset 745 for trunk/server/source3/libsmb/libsmb_path.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source3/libsmb/libsmb_path.c
r414 r745 8 8 Copyright (C) Derrell Lipman 2003-2008 9 9 Copyright (C) Jeremy Allison 2007, 2008 10 10 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. 15 15 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. 20 20 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/>. … … 61 61 size_t newlen = 1; 62 62 char *p, *dest; 63 63 64 64 if (old_length == 0) { 65 65 return 0; 66 66 } 67 67 68 68 *pp_dest = NULL; 69 69 for (i = 0; i < old_length; ) { 70 70 unsigned char character = src[i++]; 71 71 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; 75 75 76 76 /* Replace valid sequence */ 77 77 if (a != -1 && b != -1) { … … 88 88 newlen++; 89 89 } 90 90 91 91 dest = TALLOC_ARRAY(ctx, char, newlen); 92 92 if (!dest) { 93 93 return err_count; 94 94 } 95 95 96 96 err_count = 0; 97 97 for (p = dest, i = 0; i < old_length; ) { 98 98 unsigned char character = src[i++]; 99 99 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; 103 103 104 104 /* Replace valid sequence */ 105 105 if (a != -1 && b != -1) { … … 116 116 *p++ = character; 117 117 } 118 118 119 119 *p = '\0'; 120 120 *pp_dest = dest; … … 130 130 char *pdest; 131 131 int ret = urldecode_talloc(frame, &pdest, src); 132 132 133 133 if (pdest) { 134 134 strlcpy(dest, pdest, max_dest_len); … … 152 152 { 153 153 char hex[] = "0123456789ABCDEF"; 154 154 155 155 for (; *src != '\0' && max_dest_len >= 3; src++) { 156 156 157 157 if ((*src < '0' && 158 158 *src != '-' && … … 173 173 } 174 174 } 175 175 176 176 *dest++ = '\0'; 177 177 max_dest_len--; 178 178 179 179 return max_dest_len; 180 180 } … … 236 236 char *workgroup = NULL; 237 237 int len; 238 238 239 239 /* Ensure these returns are at least valid pointers. */ 240 240 *pp_server = talloc_strdup(ctx, ""); … … 243 243 *pp_user = talloc_strdup(ctx, ""); 244 244 *pp_password = talloc_strdup(ctx, ""); 245 245 246 246 if (!*pp_server || !*pp_share || !*pp_path || 247 247 !*pp_user || !*pp_password) { 248 248 return -1; 249 249 } 250 250 251 251 /* 252 252 * Assume we wont find an authentication domain to parse, so default … … 257 257 talloc_strdup(ctx, smbc_getWorkgroup(context)); 258 258 } 259 259 260 260 if (pp_options) { 261 261 *pp_options = talloc_strdup(ctx, ""); 262 262 } 263 263 s = talloc_strdup(ctx, fname); 264 264 265 265 /* see if it has the right prefix */ 266 266 len = strlen(SMBC_PREFIX); … … 268 268 return -1; /* What about no smb: ? */ 269 269 } 270 270 271 271 p = s + len; 272 272 273 273 /* Watch the test below, we are testing to see if we should exit */ 274 274 275 275 if (strncmp(p, "//", 2) && strncmp(p, "\\\\", 2)) { 276 276 DEBUG(1, ("Invalid path (does not begin with smb://")); 277 277 return -1; 278 278 } 279 279 280 280 p += 2; /* Skip the double slash */ 281 281 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 */ 285 285 *q++ = '\0'; 286 286 287 287 DEBUG(4, ("Found options '%s'", q)); 288 288 289 289 /* Copy the options */ 290 290 if (pp_options && *pp_options != NULL) { … … 293 293 } 294 294 } 295 295 296 296 if (*p == '\0') { 297 297 goto decoding; 298 298 } 299 299 300 300 if (*p == '/') { 301 301 int wl = strlen(smbc_getWorkgroup(context)); 302 302 303 303 if (wl > 16) { 304 304 wl = 16; 305 305 } 306 306 307 307 *pp_server = talloc_strdup(ctx, smbc_getWorkgroup(context)); 308 308 if (!*pp_server) { … … 312 312 return 0; 313 313 } 314 314 315 315 /* 316 316 * ok, its for us. Now parse out the server, share etc. … … 319 319 * exists ... 320 320 */ 321 321 322 322 /* check that '@' occurs before '/', if '/' exists at all */ 323 323 q = strchr_m(p, '@'); … … 326 326 char *userinfo = NULL; 327 327 const char *u; 328 328 329 329 next_token_no_ltrim_talloc(ctx, &p, &userinfo, "@"); 330 330 if (!userinfo) { … … 332 332 } 333 333 u = userinfo; 334 334 335 335 if (strchr_m(u, ';')) { 336 336 next_token_no_ltrim_talloc(ctx, &u, &workgroup, ";"); … … 342 342 } 343 343 } 344 344 345 345 if (strchr_m(u, ':')) { 346 346 next_token_no_ltrim_talloc(ctx, &u, pp_user, ":"); … … 359 359 } 360 360 } 361 361 362 362 if (!next_token_talloc(ctx, &p, pp_server, "/")) { 363 363 return -1; 364 364 } 365 365 366 366 if (*p == (char)0) { 367 367 goto decoding; /* That's it ... */ 368 368 } 369 369 370 370 if (!next_token_talloc(ctx, &p, pp_share, "/")) { 371 371 return -1; 372 372 } 373 373 374 374 /* 375 375 * Prepend a leading slash if there's a file path, as required by … … 387 387 } 388 388 string_replace(*pp_path, '/', '\\'); 389 389 390 390 decoding: 391 392 391 (void) urldecode_talloc(ctx, pp_path, *pp_path); 393 392 (void) urldecode_talloc(ctx, pp_server, *pp_server); … … 408 407 *pp_user, 409 408 *pp_password); 410 411 409 return 0; 412 410 }
Note:
See TracChangeset
for help on using the changeset viewer.