~ubuntu-branches/ubuntu/vivid/samba/vivid

« back to all changes in this revision

Viewing changes to source3/libsmb/libsmb_path.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
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/>.
23
23
*/
60
60
        int err_count = 0;
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) {
78
78
                                /* Replace valid %xx sequence with %dd */
87
87
                }
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) {
106
106
                                /* Replace valid %xx sequence with %dd */
115
115
                }
116
116
                *p++ = character;
117
117
        }
118
 
        
 
118
 
119
119
        *p = '\0';
120
120
        *pp_dest = dest;
121
121
        return err_count;
129
129
        TALLOC_CTX *frame = talloc_stackframe();
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);
135
135
        }
151
151
               int 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 != '-' &&
159
159
                     *src != '.') ||
172
172
                        max_dest_len--;
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
}
181
181
 
235
235
        char *q, *r;
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, "");
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, "");
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
253
253
         * to the workgroup in the provided context.
256
256
                *pp_workgroup =
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);
267
267
        if (strncmp(s,SMBC_PREFIX,len) || (s[len] != '/' && s[len] != 0)) {
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) {
291
291
                        TALLOC_FREE(*pp_options);
292
292
                        *pp_options = talloc_strdup(ctx, q);
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) {
309
309
                        return -1;
311
311
                (*pp_server)[wl] = '\0';
312
312
                return 0;
313
313
        }
314
 
        
 
314
 
315
315
        /*
316
316
         * ok, its for us. Now parse out the server, share etc.
317
317
         *
318
318
         * However, we want to parse out [[domain;]user[:password]@] if it
319
319
         * exists ...
320
320
         */
321
 
        
 
321
 
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;
327
327
                const char *u;
328
 
                
 
328
 
329
329
                next_token_no_ltrim_talloc(ctx, &p, &userinfo, "@");
330
330
                if (!userinfo) {
331
331
                        return -1;
332
332
                }
333
333
                u = userinfo;
334
 
                
 
334
 
335
335
                if (strchr_m(u, ';')) {
336
336
                        next_token_no_ltrim_talloc(ctx, &u, &workgroup, ";");
337
337
                        if (!workgroup) {
341
341
                                *pp_workgroup = workgroup;
342
342
                        }
343
343
                }
344
 
                
 
344
 
345
345
                if (strchr_m(u, ':')) {
346
346
                        next_token_no_ltrim_talloc(ctx, &u, pp_user, ":");
347
347
                        if (!*pp_user) {
358
358
                        }
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
376
376
         * NetApp filers.
386
386
                return -1;
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);
394
393
        (void) urldecode_talloc(ctx, pp_share, *pp_share);
407
406
                                           workgroup,
408
407
                                           *pp_user,
409
408
                                           *pp_password);
410
 
        
411
409
        return 0;
412
410
}
413
411