~ubuntu-branches/ubuntu/gutsy/samba/gutsy-updates

« back to all changes in this revision

Viewing changes to source/libsmb/libsmbclient.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2006-11-28 20:14:37 UTC
  • mfrom: (0.10.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061128201437-a6x4lzlhempazocp
Tags: 3.0.23d-1ubuntu1
* Merge from debian unstable.
* Drop python2.4-samba, replace with python-samba. Added Conflicts/Replaces
  on python2.4-samba
* Drop track-connection-dos.patch, ubuntu-winbind-panic.patch, 
  ubuntu-fix-ldap.patch, ubuntu-setlocale.patch, ubuntu-setlocale-fixes.patch
* Remaining Ubuntu changes:
  - Revert Debian's installation of mount.cifs and umount.cifs as suid
  - Comment out the default [homes] shares and add more verbose comments to
    explain what they do and how they work (closes: launchpad.net/27608)
  - Add a "valid users = %S" stanza to the commented-out [homes] section, to
    show users how to restrict access to \\server\username to only username.
  - Change the (commented-out) "printer admin" example to use "@lpadmin"
    instead of "@ntadmin", since the lpadmin group is used for spool admin.
  - Alter the panic-action script to encourage users to report their
    bugs in Ubuntu packages to Ubuntu, rather than reporting to Debian.
    Modify text to more closely match the Debian script
  - Munge our init script to deal with the fact that our implementation
    (or lack thereof) of log_daemon_msg and log_progress_msg differs
    from Debian's implementation of the same (Ubuntu #19691)
  - Kept ubuntu-auxsrc.patch: some auxilliary sources (undocumented in 
    previous changelogs)
  - Set default workgroup to MSHOME

Show diffs side-by-side

added added

removed removed

Lines of Context:
181
181
 
182
182
        *p = '\0';
183
183
 
184
 
        strncpy(dest, temp, max_dest_len);
 
184
        strncpy(dest, temp, max_dest_len - 1);
 
185
        dest[max_dest_len - 1] = '\0';
185
186
 
186
187
        return err_count;
187
188
}
268
269
static int
269
270
smbc_parse_path(SMBCCTX *context,
270
271
                const char *fname,
 
272
                char *workgroup, int workgroup_len,
271
273
                char *server, int server_len,
272
274
                char *share, int share_len,
273
275
                char *path, int path_len,
282
284
        int len;
283
285
 
284
286
        server[0] = share[0] = path[0] = user[0] = password[0] = (char)0;
 
287
 
 
288
        /*
 
289
         * Assume we wont find an authentication domain to parse, so default
 
290
         * to the workgroup in the provided context.
 
291
         */
 
292
        if (workgroup != NULL) {
 
293
                strncpy(workgroup, context->workgroup, workgroup_len - 1);
 
294
                workgroup[workgroup_len - 1] = '\0';
 
295
        }
 
296
 
285
297
        if (options != NULL && options_len > 0) {
286
298
                options[0] = (char)0;
287
299
        }
328
340
                        ((strlen(context->workgroup) < 16)
329
341
                         ? strlen(context->workgroup)
330
342
                         : 16));
 
343
                server[server_len - 1] = '\0';
331
344
                return 0;
332
345
                
333
346
        }
369
382
 
370
383
                }
371
384
 
372
 
                if (username[0])
373
 
                        strncpy(user, username, user_len);  /* FIXME, domain */
374
 
 
375
 
                if (passwd[0])
376
 
                        strncpy(password, passwd, password_len);
 
385
                if (domain[0] && workgroup) {
 
386
                        strncpy(workgroup, domain, workgroup_len - 1);
 
387
                        workgroup[workgroup_len - 1] = '\0';
 
388
                }
 
389
 
 
390
                if (username[0]) {
 
391
                        strncpy(user, username, user_len - 1);
 
392
                        user[user_len - 1] = '\0';
 
393
                }
 
394
 
 
395
                if (passwd[0]) {
 
396
                        strncpy(password, passwd, password_len - 1);
 
397
                        password[password_len - 1] = '\0';
 
398
                }
377
399
 
378
400
        }
379
401
 
391
413
 
392
414
        }
393
415
 
394
 
        safe_strcpy(path, p, path_len - 1);
 
416
        /*
 
417
         * Prepend a leading slash if there's a file path, as required by
 
418
         * NetApp filers.
 
419
         */
 
420
        *path = '\0';
 
421
        if (*p != '\0') {
 
422
                *path = '/';
 
423
                safe_strcpy(path + 1, p, path_len - 2);
 
424
        }
395
425
 
396
426
        all_string_sub(path, "/", "\\", 0);
397
427
 
530
560
                                                   workgroup, username);
531
561
 
532
562
        if (!auth_called && !srv && (!username[0] || !password[0])) {
533
 
                context->callbacks.auth_fn(server, share,
534
 
                                           workgroup, sizeof(fstring),
535
 
                                           username, sizeof(fstring),
536
 
                                           password, sizeof(fstring));
 
563
                if (context->internal->_auth_fn_with_context != NULL) {
 
564
                         context->internal->_auth_fn_with_context(
 
565
                                context,
 
566
                                server, share,
 
567
                                workgroup, sizeof(fstring),
 
568
                                username, sizeof(fstring),
 
569
                                password, sizeof(fstring));
 
570
                } else {
 
571
                        context->callbacks.auth_fn(
 
572
                                server, share,
 
573
                                workgroup, sizeof(fstring),
 
574
                                username, sizeof(fstring),
 
575
                                password, sizeof(fstring));
 
576
                }
 
577
 
537
578
                /*
538
579
                 * However, smbc_auth_fn may have picked up info relating to
539
580
                 * an existing connection, so try for an existing connection
635
676
                 */
636
677
                if (srv->cli.cnum == (uint16) -1) {
637
678
                        /* Ensure we have accurate auth info */
638
 
                        context->callbacks.auth_fn(server, share,
639
 
                                                   workgroup, sizeof(fstring),
640
 
                                                   username, sizeof(fstring),
641
 
                                                   password, sizeof(fstring));
 
679
                        if (context->internal->_auth_fn_with_context != NULL) {
 
680
                                context->internal->_auth_fn_with_context(
 
681
                                        context,
 
682
                                        server, share,
 
683
                                        workgroup, sizeof(fstring),
 
684
                                        username, sizeof(fstring),
 
685
                                        password, sizeof(fstring));
 
686
                        } else {
 
687
                                context->callbacks.auth_fn(
 
688
                                        server, share,
 
689
                                        workgroup, sizeof(fstring),
 
690
                                        username, sizeof(fstring),
 
691
                                        password, sizeof(fstring));
 
692
                        }
642
693
 
643
694
                        if (! cli_send_tconX(&srv->cli, share, "?????",
644
695
                                             password, strlen(password)+1)) {
879
930
                /* We didn't find a cached connection.  Get the password */
880
931
                if (*password == '\0') {
881
932
                        /* ... then retrieve it now. */
882
 
                        context->callbacks.auth_fn(server, share,
883
 
                                                   workgroup, sizeof(fstring),
884
 
                                                   username, sizeof(fstring),
885
 
                                                   password, sizeof(fstring));
 
933
                        if (context->internal->_auth_fn_with_context != NULL) {
 
934
                                context->internal->_auth_fn_with_context(
 
935
                                        context,
 
936
                                        server, share,
 
937
                                        workgroup, sizeof(fstring),
 
938
                                        username, sizeof(fstring),
 
939
                                        password, sizeof(fstring));
 
940
                        } else {
 
941
                                context->callbacks.auth_fn(
 
942
                                        server, share,
 
943
                                        workgroup, sizeof(fstring),
 
944
                                        username, sizeof(fstring),
 
945
                                        password, sizeof(fstring));
 
946
                        }
886
947
                }
887
948
        
888
949
                zero_ip(&ip);
1001
1062
        }
1002
1063
 
1003
1064
        if (smbc_parse_path(context, fname,
 
1065
                            workgroup, sizeof(workgroup),
1004
1066
                            server, sizeof(server),
1005
1067
                            share, sizeof(share),
1006
1068
                            path, sizeof(path),
1013
1075
 
1014
1076
        if (user[0] == (char)0) fstrcpy(user, context->user);
1015
1077
 
1016
 
        fstrcpy(workgroup, context->workgroup);
1017
 
 
1018
1078
        srv = smbc_server(context, True,
1019
1079
                          server, share, workgroup, user, password);
1020
1080
 
1049
1109
                if (!cli_resolve_path( "", &srv->cli, path, &targetcli, targetpath))
1050
1110
                {
1051
1111
                        d_printf("Could not resolve %s\n", path);
 
1112
                        SAFE_FREE(file);
1052
1113
                        return NULL;
1053
1114
                }
1054
1115
                /*d_printf(">>>open: resolved %s as %s\n", path, targetpath);*/
1178
1239
         * the call to cli_read() instead of file->offset fixes a problem
1179
1240
         * retrieving data at an offset greater than 4GB.
1180
1241
         */
1181
 
        off_t offset = file->offset;
 
1242
        off_t offset;
1182
1243
 
1183
1244
        if (!context || !context->internal ||
1184
1245
            !context->internal->_initialized) {
1197
1258
 
1198
1259
        }
1199
1260
 
 
1261
        offset = file->offset;
 
1262
 
1200
1263
        /* Check that the buffer exists ... */
1201
1264
 
1202
1265
        if (buf == NULL) {
1208
1271
 
1209
1272
        /*d_printf(">>>read: parsing %s\n", file->fname);*/
1210
1273
        if (smbc_parse_path(context, file->fname,
 
1274
                            NULL, 0,
1211
1275
                            server, sizeof(server),
1212
1276
                            share, sizeof(share),
1213
1277
                            path, sizeof(path),
1260
1324
        pstring path, targetpath;
1261
1325
        struct cli_state *targetcli;
1262
1326
 
 
1327
        /* First check all pointers before dereferencing them */
 
1328
        
 
1329
        if (!context || !context->internal ||
 
1330
            !context->internal->_initialized) {
 
1331
 
 
1332
                errno = EINVAL;
 
1333
                return -1;
 
1334
 
 
1335
        }
 
1336
 
 
1337
        if (!file || !DLIST_CONTAINS(context->internal->_files, file)) {
 
1338
 
 
1339
                errno = EBADF;
 
1340
                return -1;
 
1341
    
 
1342
        }
 
1343
 
 
1344
        /* Check that the buffer exists ... */
 
1345
 
 
1346
        if (buf == NULL) {
 
1347
 
 
1348
                errno = EINVAL;
 
1349
                return -1;
 
1350
 
 
1351
        }
 
1352
 
1263
1353
        offset = file->offset; /* See "offset" comment in smbc_read_ctx() */
1264
1354
 
1265
 
        if (!context || !context->internal ||
1266
 
            !context->internal->_initialized) {
1267
 
 
1268
 
                errno = EINVAL;
1269
 
                return -1;
1270
 
 
1271
 
        }
1272
 
 
1273
 
        if (!file || !DLIST_CONTAINS(context->internal->_files, file)) {
1274
 
 
1275
 
                errno = EBADF;
1276
 
                return -1;
1277
 
    
1278
 
        }
1279
 
 
1280
 
        /* Check that the buffer exists ... */
1281
 
 
1282
 
        if (buf == NULL) {
1283
 
 
1284
 
                errno = EINVAL;
1285
 
                return -1;
1286
 
 
1287
 
        }
1288
 
 
1289
1355
        /*d_printf(">>>write: parsing %s\n", file->fname);*/
1290
1356
        if (smbc_parse_path(context, file->fname,
 
1357
                            NULL, 0,
1291
1358
                            server, sizeof(server),
1292
1359
                            share, sizeof(share),
1293
1360
                            path, sizeof(path),
1359
1426
 
1360
1427
        /*d_printf(">>>close: parsing %s\n", file->fname);*/
1361
1428
        if (smbc_parse_path(context, file->fname,
 
1429
                            NULL, 0,
1362
1430
                            server, sizeof(server),
1363
1431
                            share, sizeof(share),
1364
1432
                            path, sizeof(path),
1456
1524
  
1457
1525
        if (!srv->no_pathinfo2 &&
1458
1526
            cli_qpathinfo2(targetcli, targetpath,
1459
 
                           c_time, a_time, m_time, NULL, size, mode, ino)) {
 
1527
                           NULL, a_time, m_time, c_time, size, mode, ino)) {
1460
1528
            return True;
1461
1529
        }
1462
1530
 
1499
1567
        int ret;
1500
1568
 
1501
1569
        /*
1502
 
         * Get the create time of the file (if not provided); we'll need it in
1503
 
         * the set call.
1504
 
         */
1505
 
        if (! srv->no_pathinfo && c_time == 0) {
1506
 
                if (! cli_qpathinfo(&srv->cli, path,
1507
 
                                    &c_time, NULL, NULL, NULL, NULL)) {
1508
 
                        /* qpathinfo not available */
1509
 
                        srv->no_pathinfo = True;
1510
 
                } else {
1511
 
                        /*
1512
 
                         * We got a creation time.  Some OS versions don't
1513
 
                         * return a valid create time, though.  If we got an
1514
 
                         * invalid time, start with the current time instead.
1515
 
                         */
1516
 
                        if (c_time == 0 || c_time == (time_t) -1) {
1517
 
                                c_time = time(NULL);
1518
 
                        }
1519
 
 
1520
 
                        /*
1521
 
                         * We got a creation time.  For sanity sake, since
1522
 
                         * there is no POSIX function to set the create time
1523
 
                         * of a file, if the existing create time is greater
1524
 
                         * than either of access time or modification time,
1525
 
                         * set create time to the smallest of those.  This
1526
 
                         * ensure that the create time of a file is never
1527
 
                         * greater than its last access or modification time.
1528
 
                         */
1529
 
                        if (c_time > a_time) c_time = a_time;
1530
 
                        if (c_time > m_time) c_time = m_time;
1531
 
                }
1532
 
        }
1533
 
 
1534
 
        /*
1535
1570
         * First, try setpathinfo (if qpathinfo succeeded), for it is the
1536
1571
         * modern function for "new code" to be using, and it works given a
1537
1572
         * filename rather than requiring that the file be opened to have its
1645
1680
        }
1646
1681
 
1647
1682
        if (smbc_parse_path(context, fname,
 
1683
                            workgroup, sizeof(workgroup),
1648
1684
                            server, sizeof(server),
1649
1685
                            share, sizeof(share),
1650
1686
                            path, sizeof(path),
1657
1693
 
1658
1694
        if (user[0] == (char)0) fstrcpy(user, context->user);
1659
1695
 
1660
 
        fstrcpy(workgroup, context->workgroup);
1661
 
 
1662
1696
        srv = smbc_server(context, True,
1663
1697
                          server, share, workgroup, user, password);
1664
1698
 
1762
1796
        DEBUG(4, ("smbc_rename(%s,%s)\n", oname, nname));
1763
1797
 
1764
1798
        smbc_parse_path(ocontext, oname,
 
1799
                        workgroup, sizeof(workgroup),
1765
1800
                        server1, sizeof(server1),
1766
1801
                        share1, sizeof(share1),
1767
1802
                        path1, sizeof(path1),
1772
1807
        if (user1[0] == (char)0) fstrcpy(user1, ocontext->user);
1773
1808
 
1774
1809
        smbc_parse_path(ncontext, nname,
 
1810
                        NULL, 0,
1775
1811
                        server2, sizeof(server2),
1776
1812
                        share2, sizeof(share2),
1777
1813
                        path2, sizeof(path2),
1791
1827
 
1792
1828
        }
1793
1829
 
1794
 
        fstrcpy(workgroup, ocontext->workgroup);
1795
 
 
1796
1830
        srv = smbc_server(ocontext, True,
1797
1831
                          server1, share1, workgroup, user1, password1);
1798
1832
        if (!srv) {
1891
1925
        case SEEK_END:
1892
1926
                /*d_printf(">>>lseek: parsing %s\n", file->fname);*/
1893
1927
                if (smbc_parse_path(context, file->fname,
 
1928
                                    NULL, 0,
1894
1929
                                    server, sizeof(server),
1895
1930
                                    share, sizeof(share),
1896
1931
                                    path, sizeof(path),
2049
2084
        DEBUG(4, ("smbc_stat(%s)\n", fname));
2050
2085
 
2051
2086
        if (smbc_parse_path(context, fname,
 
2087
                            workgroup, sizeof(workgroup),
2052
2088
                            server, sizeof(server),
2053
2089
                            share, sizeof(share),
2054
2090
                            path, sizeof(path),
2061
2097
 
2062
2098
        if (user[0] == (char)0) fstrcpy(user, context->user);
2063
2099
 
2064
 
        fstrcpy(workgroup, context->workgroup);
2065
 
 
2066
2100
        srv = smbc_server(context, True,
2067
2101
                          server, share, workgroup, user, password);
2068
2102
 
2137
2171
 
2138
2172
        /*d_printf(">>>fstat: parsing %s\n", file->fname);*/
2139
2173
        if (smbc_parse_path(context, file->fname,
 
2174
                            NULL, 0,
2140
2175
                            server, sizeof(server),
2141
2176
                            share, sizeof(share),
2142
2177
                            path, sizeof(path),
2157
2192
        /*d_printf(">>>fstat: resolved path as %s\n", targetpath);*/
2158
2193
 
2159
2194
        if (!cli_qfileinfo(targetcli, file->cli_fd, &mode, &size,
2160
 
                           &c_time, &a_time, &m_time, NULL, &ino)) {
 
2195
                           NULL, &a_time, &m_time, &c_time, &ino)) {
2161
2196
            if (!cli_getattrE(targetcli, file->cli_fd, &mode, &size,
2162
2197
                              &c_time, &a_time, &m_time)) {
2163
2198
 
2270
2305
        dirent->commentlen = comment_len;
2271
2306
        dirent->dirlen = size;
2272
2307
  
 
2308
        /*
 
2309
         * dirent->namelen + 1 includes the null (no null termination needed)
 
2310
         * Ditto for dirent->commentlen.
 
2311
         * The space for the two null bytes was allocated.
 
2312
         */
2273
2313
        strncpy(dirent->name, (name?name:""), dirent->namelen + 1);
2274
 
 
2275
2314
        dirent->comment = (char *)(&dirent->name + dirent->namelen + 1);
2276
2315
        strncpy(dirent->comment, (comment?comment:""), dirent->commentlen + 1);
2277
2316
        
2474
2513
        cli_rpc_pipe_close(pipe_hnd);
2475
2514
 
2476
2515
        /* Free all memory which was allocated for this request */
2477
 
        talloc_free(mem_ctx);
 
2516
        TALLOC_FREE(mem_ctx);
2478
2517
 
2479
2518
        /* Tell 'em if it worked */
2480
2519
        return W_ERROR_IS_OK(result) ? 0 : -1;
2510
2549
        }
2511
2550
 
2512
2551
        if (smbc_parse_path(context, fname,
 
2552
                            workgroup, sizeof(workgroup),
2513
2553
                            server, sizeof(server),
2514
2554
                            share, sizeof(share),
2515
2555
                            path, sizeof(path),
2534
2574
 
2535
2575
        if (user[0] == (char)0) fstrcpy(user, context->user);
2536
2576
 
2537
 
        pstrcpy(workgroup, context->workgroup);
2538
 
 
2539
2577
        dir = SMB_MALLOC_P(SMBCFILE);
2540
2578
 
2541
2579
        if (!dir) {
2598
2636
 
2599
2637
                        if (!find_master_ip(workgroup, &server_addr.ip)) {
2600
2638
 
 
2639
                                if (dir) {
 
2640
                                        SAFE_FREE(dir->fname);
 
2641
                                        SAFE_FREE(dir);
 
2642
                                }
2601
2643
                                errno = ENOENT;
2602
2644
                                return NULL;
2603
2645
                        }
2709
2751
                                        DEBUG(0, ("Could not get name of "
2710
2752
                                                  "local/domain master browser "
2711
2753
                                                  "for server %s\n", server));
 
2754
                                        if (dir) {
 
2755
                                                SAFE_FREE(dir->fname);
 
2756
                                                SAFE_FREE(dir);
 
2757
                                        }
2712
2758
                                        errno = EPERM;
2713
2759
                                        return NULL;
2714
2760
 
2832
2878
                                              &targetcli, targetpath))
2833
2879
                        {
2834
2880
                                d_printf("Could not resolve %s\n", path);
 
2881
                                if (dir) {
 
2882
                                        SAFE_FREE(dir->fname);
 
2883
                                        SAFE_FREE(dir);
 
2884
                                }
2835
2885
                                return NULL;
2836
2886
                        }
2837
2887
                        
2934
2984
                dest->comment = dest->name + dest->namelen + 1;
2935
2985
 
2936
2986
                /* Copy the comment */
2937
 
                strncpy(dest->comment, src->comment, max_namebuf_len);
2938
 
 
2939
 
                /* Ensure the comment is null terminated */
2940
 
                if (max_namebuf_len > src->commentlen) {
2941
 
                        dest->comment[src->commentlen] = '\0';
2942
 
                } else {
2943
 
                        dest->comment[max_namebuf_len - 1] = '\0';
2944
 
                }
 
2987
                strncpy(dest->comment, src->comment, max_namebuf_len - 1);
 
2988
                dest->comment[max_namebuf_len - 1] = '\0';
2945
2989
 
2946
2990
                /* Save other fields */
2947
2991
                dest->smbc_type = src->smbc_type;
3156
3200
        DEBUG(4, ("smbc_mkdir(%s)\n", fname));
3157
3201
 
3158
3202
        if (smbc_parse_path(context, fname,
 
3203
                            workgroup, sizeof(workgroup),
3159
3204
                            server, sizeof(server),
3160
3205
                            share, sizeof(share),
3161
3206
                            path, sizeof(path),
3168
3213
 
3169
3214
        if (user[0] == (char)0) fstrcpy(user, context->user);
3170
3215
 
3171
 
        fstrcpy(workgroup, context->workgroup);
3172
 
 
3173
3216
        srv = smbc_server(context, True,
3174
3217
                          server, share, workgroup, user, password);
3175
3218
 
3253
3296
        DEBUG(4, ("smbc_rmdir(%s)\n", fname));
3254
3297
 
3255
3298
        if (smbc_parse_path(context, fname,
 
3299
                            workgroup, sizeof(workgroup),
3256
3300
                            server, sizeof(server),
3257
3301
                            share, sizeof(share),
3258
3302
                            path, sizeof(path),
3266
3310
 
3267
3311
        if (user[0] == (char)0) fstrcpy(user, context->user);
3268
3312
 
3269
 
        fstrcpy(workgroup, context->workgroup);
3270
 
 
3271
3313
        srv = smbc_server(context, True,
3272
3314
                          server, share, workgroup, user, password);
3273
3315
 
3507
3549
        DEBUG(4, ("smbc_chmod(%s, 0%3o)\n", fname, newmode));
3508
3550
 
3509
3551
        if (smbc_parse_path(context, fname,
 
3552
                            workgroup, sizeof(workgroup),
3510
3553
                            server, sizeof(server),
3511
3554
                            share, sizeof(share),
3512
3555
                            path, sizeof(path),
3519
3562
 
3520
3563
        if (user[0] == (char)0) fstrcpy(user, context->user);
3521
3564
 
3522
 
        fstrcpy(workgroup, context->workgroup);
3523
 
 
3524
3565
        srv = smbc_server(context, True,
3525
3566
                          server, share, workgroup, user, password);
3526
3567
 
3586
3627
                char atimebuf[32];
3587
3628
                char mtimebuf[32];
3588
3629
 
3589
 
                strncpy(atimebuf, ctime(&a_time), sizeof(atimebuf));
 
3630
                strncpy(atimebuf, ctime(&a_time), sizeof(atimebuf) - 1);
3590
3631
                atimebuf[sizeof(atimebuf) - 1] = '\0';
3591
3632
                if ((p = strchr(atimebuf, '\n')) != NULL) {
3592
3633
                        *p = '\0';
3593
3634
                }
3594
3635
 
3595
 
                strncpy(mtimebuf, ctime(&m_time), sizeof(mtimebuf));
 
3636
                strncpy(mtimebuf, ctime(&m_time), sizeof(mtimebuf) - 1);
3596
3637
                mtimebuf[sizeof(mtimebuf) - 1] = '\0';
3597
3638
                if ((p = strchr(mtimebuf, '\n')) != NULL) {
3598
3639
                        *p = '\0';
3603
3644
        }
3604
3645
 
3605
3646
        if (smbc_parse_path(context, fname,
 
3647
                            workgroup, sizeof(workgroup),
3606
3648
                            server, sizeof(server),
3607
3649
                            share, sizeof(share),
3608
3650
                            path, sizeof(path),
3615
3657
 
3616
3658
        if (user[0] == (char)0) fstrcpy(user, context->user);
3617
3659
 
3618
 
        fstrcpy(workgroup, context->workgroup);
3619
 
 
3620
3660
        srv = smbc_server(context, True,
3621
3661
                          server, share, workgroup, user, password);
3622
3662
 
3750
3790
        }
3751
3791
 
3752
3792
        if (!NT_STATUS_IS_OK(rpccli_lsa_lookup_names(pipe_hnd, ipc_cli->mem_ctx, 
3753
 
                                                  pol, 1, &str, &sids, 
 
3793
                                                  pol, 1, &str, NULL, &sids, 
3754
3794
                                                  &types))) {
3755
3795
                result = False;
3756
3796
                goto done;
3900
3940
                return True;
3901
3941
        }
3902
3942
 
3903
 
        aces = SMB_CALLOC_ARRAY(SEC_ACE, 1+(*the_acl)->num_aces);
 
3943
        if ((aces = SMB_CALLOC_ARRAY(SEC_ACE, 1+(*the_acl)->num_aces)) == NULL) {
 
3944
                return False;
 
3945
        }
3904
3946
        memcpy(aces, (*the_acl)->ace, (*the_acl)->num_aces * sizeof(SEC_ACE));
3905
3947
        memcpy(aces+(*the_acl)->num_aces, ace, sizeof(SEC_ACE));
3906
3948
        newacl = make_sec_acl(ctx, (*the_acl)->revision,
3921
3963
{
3922
3964
        const char *p = str;
3923
3965
        fstring tok;
3924
 
        SEC_DESC *ret;
 
3966
        SEC_DESC *ret = NULL;
3925
3967
        size_t sd_size;
3926
3968
        DOM_SID *grp_sid=NULL;
3927
3969
        DOM_SID *owner_sid=NULL;
3936
3978
                }
3937
3979
 
3938
3980
                if (StrnCaseCmp(tok,"OWNER:", 6) == 0) {
 
3981
                        if (owner_sid) {
 
3982
                                DEBUG(5, ("OWNER specified more than once!\n"));
 
3983
                                goto done;
 
3984
                        }
3939
3985
                        owner_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
3940
3986
                        if (!owner_sid ||
3941
3987
                            !convert_string_to_sid(ipc_cli, pol,
3942
3988
                                                   numeric,
3943
3989
                                                   owner_sid, tok+6)) {
3944
3990
                                DEBUG(5, ("Failed to parse owner sid\n"));
3945
 
                                return NULL;
 
3991
                                goto done;
3946
3992
                        }
3947
3993
                        continue;
3948
3994
                }
3949
3995
 
3950
3996
                if (StrnCaseCmp(tok,"OWNER+:", 7) == 0) {
 
3997
                        if (owner_sid) {
 
3998
                                DEBUG(5, ("OWNER specified more than once!\n"));
 
3999
                                goto done;
 
4000
                        }
3951
4001
                        owner_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
3952
4002
                        if (!owner_sid ||
3953
4003
                            !convert_string_to_sid(ipc_cli, pol,
3954
4004
                                                   False,
3955
4005
                                                   owner_sid, tok+7)) {
3956
4006
                                DEBUG(5, ("Failed to parse owner sid\n"));
3957
 
                                return NULL;
 
4007
                                goto done;
3958
4008
                        }
3959
4009
                        continue;
3960
4010
                }
3961
4011
 
3962
4012
                if (StrnCaseCmp(tok,"GROUP:", 6) == 0) {
 
4013
                        if (grp_sid) {
 
4014
                                DEBUG(5, ("GROUP specified more than once!\n"));
 
4015
                                goto done;
 
4016
                        }
3963
4017
                        grp_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
3964
4018
                        if (!grp_sid ||
3965
4019
                            !convert_string_to_sid(ipc_cli, pol,
3966
4020
                                                   numeric,
3967
4021
                                                   grp_sid, tok+6)) {
3968
4022
                                DEBUG(5, ("Failed to parse group sid\n"));
3969
 
                                return NULL;
 
4023
                                goto done;
3970
4024
                        }
3971
4025
                        continue;
3972
4026
                }
3973
4027
 
3974
4028
                if (StrnCaseCmp(tok,"GROUP+:", 7) == 0) {
 
4029
                        if (grp_sid) {
 
4030
                                DEBUG(5, ("GROUP specified more than once!\n"));
 
4031
                                goto done;
 
4032
                        }
3975
4033
                        grp_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
3976
4034
                        if (!grp_sid ||
3977
4035
                            !convert_string_to_sid(ipc_cli, pol,
3978
4036
                                                   False,
3979
4037
                                                   grp_sid, tok+6)) {
3980
4038
                                DEBUG(5, ("Failed to parse group sid\n"));
3981
 
                                return NULL;
 
4039
                                goto done;
3982
4040
                        }
3983
4041
                        continue;
3984
4042
                }
3987
4045
                        SEC_ACE ace;
3988
4046
                        if (!parse_ace(ipc_cli, pol, &ace, numeric, tok+4)) {
3989
4047
                                DEBUG(5, ("Failed to parse ACL %s\n", tok));
3990
 
                                return NULL;
 
4048
                                goto done;
3991
4049
                        }
3992
4050
                        if(!add_ace(&dacl, &ace, ctx)) {
3993
4051
                                DEBUG(5, ("Failed to add ACL %s\n", tok));
3994
 
                                return NULL;
 
4052
                                goto done;
3995
4053
                        }
3996
4054
                        continue;
3997
4055
                }
4000
4058
                        SEC_ACE ace;
4001
4059
                        if (!parse_ace(ipc_cli, pol, &ace, False, tok+5)) {
4002
4060
                                DEBUG(5, ("Failed to parse ACL %s\n", tok));
4003
 
                                return NULL;
 
4061
                                goto done;
4004
4062
                        }
4005
4063
                        if(!add_ace(&dacl, &ace, ctx)) {
4006
4064
                                DEBUG(5, ("Failed to add ACL %s\n", tok));
4007
 
                                return NULL;
 
4065
                                goto done;
4008
4066
                        }
4009
4067
                        continue;
4010
4068
                }
4011
4069
 
4012
4070
                DEBUG(5, ("Failed to parse security descriptor\n"));
4013
 
                return NULL;
 
4071
                goto done;
4014
4072
        }
4015
4073
 
4016
4074
        ret = make_sec_desc(ctx, revision, SEC_DESC_SELF_RELATIVE, 
4017
4075
                            owner_sid, grp_sid, NULL, dacl, &sd_size);
4018
4076
 
 
4077
  done:
4019
4078
        SAFE_FREE(grp_sid);
4020
4079
        SAFE_FREE(owner_sid);
4021
4080
 
4808
4867
                                    CONST_DISCARD(char *, the_acl));
4809
4868
 
4810
4869
                if (!sd) {
4811
 
                        errno = EINVAL;
4812
 
                        return -1;
 
4870
                        errno = EINVAL;
 
4871
                        return -1;
4813
4872
                }
4814
4873
        }
4815
4874
 
 
4875
        /* SMBC_XATTR_MODE_REMOVE_ALL is the only caller
 
4876
           that doesn't deref sd */
 
4877
 
 
4878
        if (!sd && (mode != SMBC_XATTR_MODE_REMOVE_ALL)) {
 
4879
                errno = EINVAL;
 
4880
                return -1;
 
4881
        }
 
4882
 
4816
4883
        /* The desired access below is the only one I could find that works
4817
4884
           with NT4, W2KP and Samba */
4818
4885
 
4999
5066
                  fname, name, (int) size, (const char*)value));
5000
5067
 
5001
5068
        if (smbc_parse_path(context, fname,
 
5069
                            workgroup, sizeof(workgroup),
5002
5070
                            server, sizeof(server),
5003
5071
                            share, sizeof(share),
5004
5072
                            path, sizeof(path),
5011
5079
 
5012
5080
        if (user[0] == (char)0) fstrcpy(user, context->user);
5013
5081
 
5014
 
        fstrcpy(workgroup, context->workgroup);
5015
 
 
5016
5082
        srv = smbc_server(context, True,
5017
5083
                          server, share, workgroup, user, password);
5018
5084
        if (!srv) {
5267
5333
        DEBUG(4, ("smbc_getxattr(%s, %s)\n", fname, name));
5268
5334
 
5269
5335
        if (smbc_parse_path(context, fname,
 
5336
                            workgroup, sizeof(workgroup),
5270
5337
                            server, sizeof(server),
5271
5338
                            share, sizeof(share),
5272
5339
                            path, sizeof(path),
5279
5346
 
5280
5347
        if (user[0] == (char)0) fstrcpy(user, context->user);
5281
5348
 
5282
 
        fstrcpy(workgroup, context->workgroup);
5283
 
 
5284
5349
        srv = smbc_server(context, True,
5285
5350
                          server, share, workgroup, user, password);
5286
5351
        if (!srv) {
5384
5449
        DEBUG(4, ("smbc_removexattr(%s, %s)\n", fname, name));
5385
5450
 
5386
5451
        if (smbc_parse_path(context, fname,
 
5452
                            workgroup, sizeof(workgroup),
5387
5453
                            server, sizeof(server),
5388
5454
                            share, sizeof(share),
5389
5455
                            path, sizeof(path),
5396
5462
 
5397
5463
        if (user[0] == (char)0) fstrcpy(user, context->user);
5398
5464
 
5399
 
        fstrcpy(workgroup, context->workgroup);
5400
 
 
5401
5465
        srv = smbc_server(context, True,
5402
5466
                          server, share, workgroup, user, password);
5403
5467
        if (!srv) {
5539
5603
        DEBUG(4, ("smbc_open_print_job_ctx(%s)\n", fname));
5540
5604
 
5541
5605
        if (smbc_parse_path(context, fname,
 
5606
                            NULL, 0,
5542
5607
                            server, sizeof(server),
5543
5608
                            share, sizeof(share),
5544
5609
                            path, sizeof(path),
5676
5741
        DEBUG(4, ("smbc_list_print_jobs(%s)\n", fname));
5677
5742
 
5678
5743
        if (smbc_parse_path(context, fname,
 
5744
                            workgroup, sizeof(workgroup),
5679
5745
                            server, sizeof(server),
5680
5746
                            share, sizeof(share),
5681
5747
                            path, sizeof(path),
5688
5754
 
5689
5755
        if (user[0] == (char)0) fstrcpy(user, context->user);
5690
5756
        
5691
 
        fstrcpy(workgroup, context->workgroup);
5692
 
 
5693
5757
        srv = smbc_server(context, True,
5694
5758
                          server, share, workgroup, user, password);
5695
5759
 
5747
5811
        DEBUG(4, ("smbc_unlink_print_job(%s)\n", fname));
5748
5812
 
5749
5813
        if (smbc_parse_path(context, fname,
 
5814
                            workgroup, sizeof(workgroup),
5750
5815
                            server, sizeof(server),
5751
5816
                            share, sizeof(share),
5752
5817
                            path, sizeof(path),
5759
5824
 
5760
5825
        if (user[0] == (char)0) fstrcpy(user, context->user);
5761
5826
 
5762
 
        fstrcpy(workgroup, context->workgroup);
5763
 
 
5764
5827
        srv = smbc_server(context, True,
5765
5828
                          server, share, workgroup, user, password);
5766
5829
 
5802
5865
 
5803
5866
        context->internal = SMB_MALLOC_P(struct smbc_internal_data);
5804
5867
        if (!context->internal) {
 
5868
                SAFE_FREE(context);
5805
5869
                errno = ENOMEM;
5806
5870
                return NULL;
5807
5871
        }
5947
6011
void
5948
6012
smbc_option_set(SMBCCTX *context,
5949
6013
                char *option_name,
5950
 
                ...)
5951
 
{
5952
 
        va_list args;
5953
 
 
5954
 
        va_start(args, option_name);
5955
 
 
5956
 
        if (strcmp(option_name, "debug_stderr") == 0) {
5957
 
                /*
5958
 
                 * Log to standard error instead of standard output.
5959
 
                 *
5960
 
                 *  optional parameters: none (it can't be turned off once on)
5961
 
                 */
5962
 
                context->internal->_debug_stderr = True;
5963
 
        }
5964
 
 
5965
 
        va_end(args);
 
6014
                void *option_value)
 
6015
{
 
6016
        if (strcmp(option_name, "debug_stderr") == 0) {
 
6017
                /*
 
6018
                 * Log to standard error instead of standard output.
 
6019
                 */
 
6020
                context->internal->_debug_stderr =
 
6021
                        (option_value == NULL ? False : True);
 
6022
        } else if (strcmp(option_name, "auth_function") == 0) {
 
6023
                /*
 
6024
                 * Use the new-style authentication function which includes
 
6025
                 * the context.
 
6026
                 */
 
6027
                context->internal->_auth_fn_with_context = option_value;
 
6028
        } else if (strcmp(option_name, "user_data") == 0) {
 
6029
                /*
 
6030
                 * Save a user data handle which may be retrieved by the user
 
6031
                 * with smbc_option_get()
 
6032
                 */
 
6033
                context->internal->_user_data = option_value;
 
6034
        }
 
6035
}
 
6036
 
 
6037
 
 
6038
/*
 
6039
 * Retrieve the current value of an option
 
6040
 */
 
6041
void *
 
6042
smbc_option_get(SMBCCTX *context,
 
6043
                char *option_name)
 
6044
{
 
6045
        if (strcmp(option_name, "debug_stderr") == 0) {
 
6046
                /*
 
6047
                 * Log to standard error instead of standard output.
 
6048
                 */
 
6049
#if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T)
 
6050
                return (void *) (intptr_t) context->internal->_debug_stderr;
 
6051
#else
 
6052
                return (void *) context->internal->_debug_stderr;
 
6053
#endif
 
6054
        } else if (strcmp(option_name, "auth_function") == 0) {
 
6055
                /*
 
6056
                 * Use the new-style authentication function which includes
 
6057
                 * the context.
 
6058
                 */
 
6059
                return (void *) context->internal->_auth_fn_with_context;
 
6060
        } else if (strcmp(option_name, "user_data") == 0) {
 
6061
                /*
 
6062
                 * Save a user data handle which may be retrieved by the user
 
6063
                 * with smbc_option_get()
 
6064
                 */
 
6065
                return context->internal->_user_data;
 
6066
        }
 
6067
 
 
6068
        return NULL;
5966
6069
}
5967
6070
 
5968
6071
 
5991
6094
                return 0;
5992
6095
        }
5993
6096
 
5994
 
        if (!context->callbacks.auth_fn ||
 
6097
        if ((!context->callbacks.auth_fn &&
 
6098
             !context->internal->_auth_fn_with_context) ||
5995
6099
            context->debug < 0 ||
5996
6100
            context->debug > 100) {
5997
6101
 
6025
6129
                home = getenv("HOME");
6026
6130
                if (home) {
6027
6131
                        slprintf(conf, sizeof(conf), "%s/.smb/smb.conf", home);
6028
 
                        if (lp_load(conf, True, False, False)) {
 
6132
                        if (lp_load(conf, True, False, False, True)) {
6029
6133
                                conf_loaded = True;
6030
6134
                        } else {
6031
6135
                                DEBUG(5, ("Could not load config file: %s\n",
6041
6145
                         * defaults ...
6042
6146
                         */
6043
6147
 
6044
 
                        if (!lp_load(dyn_CONFIGFILE, True, False, False)) {
 
6148
                        if (!lp_load(dyn_CONFIGFILE, True, False, False, False)) {
6045
6149
                                DEBUG(5, ("Could not load config file: %s\n",
6046
6150
                                          dyn_CONFIGFILE));
6047
6151
                        } else if (home) {
6052
6156
                                 */
6053
6157
                                slprintf(conf, sizeof(conf),
6054
6158
                                         "%s/.smb/smb.conf.append", home);
6055
 
                                if (!lp_load(conf, True, False, False)) {
 
6159
                                if (!lp_load(conf, True, False, False, False)) {
6056
6160
                                        DEBUG(10,
6057
6161
                                              ("Could not append config file: "
6058
6162
                                               "%s\n",