~ubuntu-branches/ubuntu/lucid/mc/lucid

« back to all changes in this revision

Viewing changes to vfs/smbfs.c

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Winnertz
  • Date: 2008-09-16 10:38:59 UTC
  • mfrom: (3.1.6 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080916103859-2uwn8w61xk5mbxxq
Tags: 2:4.6.2~git20080311-4
Corrected fix for odt2txt issue (Closes: #492019) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Virtual File System: Midnight Commander file system.
2
2
 
3
 
   Copyright (C) 1995, 1996, 1997 The Free Software Foundation
 
3
   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007
 
4
   Free Software Foundation, Inc.
4
5
 
5
6
   Written by Wayne Roberts <wroberts1@home.com>, 1997
6
7
              Andrew V. Samoilov <sav@bcs.zp.ua> 2002, 2003
25
26
#include <sys/types.h>
26
27
 
27
28
#undef  USE_NCURSES     /* Don't include *curses.h */
 
29
#include "../src/global.h"
 
30
#include "../src/tty.h"         /* enable/disable interrupt key */
 
31
#include "../src/wtools.h"      /* message() */
 
32
#include "../src/main.h"        /* print_vfs_message */
28
33
#include "utilvfs.h"
29
34
 
30
35
#undef  PACKAGE_BUGREPORT
59
64
/* stuff that is same with each connection */
60
65
extern int DEBUGLEVEL;
61
66
extern pstring myhostname;
 
67
extern struct in_addr ipzero;
62
68
static mode_t myumask = 0755;
63
69
extern pstring global_myname;
64
70
static int smbfs_open_connections = 0;
99
105
 
100
106
static GSList *auth_list;
101
107
 
102
 
static inline BOOL dbghdr_wrapper (int level, const char *file, const char *func, int line)
 
108
/* this function allows you to write:
 
109
 * char *s = g_strdup("hello, world");
 
110
 * s = free_after(g_strconcat(s, s, (char *)0), s);
 
111
 */
 
112
static inline char *
 
113
free_after (char *result, char *string_to_free)
103
114
{
104
 
        return dbghdr (level, const_cast(char *, file), const_cast(char *, func), line);
 
115
        g_free(string_to_free);
 
116
        return result;
105
117
}
106
 
#define dbghdr dbghdr_wrapper
 
118
 
107
119
 
108
120
static void 
109
121
smbfs_auth_free (struct smb_authinfo const *a)
271
283
    if (DEBUGLEVEL > 0) {
272
284
        FILE *outfile = fopen (filename, "w");
273
285
        if (outfile) {
274
 
            setup_logging (const_cast(char *, ""), True);       /* No needs for timestamp for each message */
 
286
            setup_logging ("", True);   /* No needs for timestamp for each message */
275
287
            dbf = outfile;
276
288
            setbuf (dbf, NULL);
277
289
            pstrcpy (debugf, filename);
295
307
    if (!get_myname (myhostname, NULL))
296
308
        DEBUG (0, ("Failed to get my hostname.\n"));
297
309
 
298
 
    if (!lp_load (const_cast(char *, servicesf), True, False, False))
 
310
    if (!lp_load (servicesf, True, False, False))
299
311
        DEBUG (0, ("Cannot load %s - run testparm to debug it\n", servicesf));
300
312
 
301
313
    codepage_initialise (lp_client_code_page ());
334
346
{
335
347
    int i;
336
348
    char *path;
 
349
 
 
350
    (void) me;
 
351
 
337
352
    for (i = 0; i < SMBFS_MAX_CONNECTIONS; i++) {
338
353
        if (smbfs_connections [i].cli) {
339
354
            path = g_strconcat (URL_HEADER,
373
388
 
374
389
        DEBUG(3, ("smbfs_write(fnum:%d, nread:%d, nbyte:%d)\n",
375
390
                info->fnum, (int)info->nread, nbyte));
376
 
        n = cli_write(info->cli, info->fnum, 0, const_cast(char *, buf), info->nread, nbyte);
 
391
        n = cli_write(info->cli, info->fnum, 0, buf, info->nread, nbyte);
377
392
        if (n > 0)
378
393
                info->nread += n;
379
394
    return n;
404
419
static int
405
420
smbfs_errno (struct vfs_class *me)
406
421
{
407
 
        DEBUG(3, ("smbfs_errno: %s\n", g_strerror(my_errno)));
 
422
    (void) me;
 
423
 
 
424
    DEBUG(3, ("smbfs_errno: %s\n", g_strerror(my_errno)));
408
425
    return my_errno;
409
426
}
410
427
 
457
474
smbfs_browsing_helper (const char *name, uint32 type, const char *comment, void *state)
458
475
{
459
476
    const char *typestr = "";
460
 
 
461
477
    dir_entry *new_entry = smbfs_new_dir_entry (name);
462
478
 
 
479
    (void) state;
 
480
 
463
481
    switch (type) {
464
482
    case STYPE_DISKTREE:
465
483
        typestr = "Disk";
486
504
{
487
505
    dir_entry *new_entry = (dir_entry *) entry;
488
506
    time_t t = finfo->mtime;    /* the time is assumed to be passed as GMT */
 
507
 
 
508
    (void) mask;
 
509
 
489
510
#if 0                           /* I want to see dot files */
490
511
    if (finfo->mode & aHIDDEN)
491
512
        return;                 /* don't bother with hidden files, "~$" screws up mc */
546
567
    if (p)
547
568
        my_remote = p;   /* strip off share/service name */
548
569
    /* create remote filename as understood by smb clientgen */
549
 
    result = g_strconcat (my_remote, trailing_asterik ? "/*" : "", 0);
 
570
    result = g_strconcat (my_remote, trailing_asterik ? "/*" : "", (char *) NULL);
550
571
    unix_to_dos (result, /* inplace = */ 1); /* code page conversion */
551
572
    str_replace(result, '/', '\\');
552
573
    return result;
558
579
{
559
580
    dir_entry *new_entry = smbfs_new_dir_entry (name);
560
581
 
 
582
    (void) m;
 
583
    (void) state;
 
584
 
561
585
    /* show this as dir */
562
586
    new_entry->my_stat.st_mode =
563
587
        (S_IFDIR | S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP |
835
859
static int
836
860
smbfs_chmod (struct vfs_class *me, const char *path, int mode)
837
861
{
 
862
        (void) me;
 
863
 
838
864
        DEBUG(3, ("smbfs_chmod(path:%s, mode:%d)\n", path, mode));
839
865
/*      my_errno = EOPNOTSUPP;
840
866
        return -1;      */      /* cannot chmod on smb filesystem */
844
870
static int
845
871
smbfs_chown (struct vfs_class *me, const char *path, int owner, int group)
846
872
{
 
873
        (void) me;
 
874
 
847
875
        DEBUG(3, ("smbfs_chown(path:%s, owner:%d, group:%d)\n", path, owner, group));
848
876
        my_errno = EOPNOTSUPP;  /* ready for your labotomy? */
849
877
        return -1;
852
880
static int
853
881
smbfs_utime (struct vfs_class *me, const char *path, struct utimbuf *times)
854
882
{
 
883
        (void) me;
 
884
        (void) times;
 
885
 
855
886
        DEBUG(3, ("smbfs_utime(path:%s)\n", path));
856
887
        my_errno = EOPNOTSUPP;
857
 
    return -1;
 
888
        return -1;
858
889
}
859
890
 
860
891
static int
861
892
smbfs_readlink (struct vfs_class *me, const char *path, char *buf, size_t size)
862
893
{
 
894
        (void) me;
 
895
 
863
896
        DEBUG (3,
864
897
            ("smbfs_readlink(path:%s, buf:%s, size:%d)\n", path, buf,
865
898
            (int) size));
866
899
        my_errno = EOPNOTSUPP;
867
 
    return -1;                 /* no symlinks on smb filesystem? */
 
900
        return -1;              /* no symlinks on smb filesystem? */
868
901
}
869
902
 
870
903
static int
871
904
smbfs_symlink (struct vfs_class *me, const char *n1, const char *n2)
872
905
{
 
906
        (void) me;
 
907
 
873
908
        DEBUG(3, ("smbfs_symlink(n1:%s, n2:%s)\n", n1, n2));
874
909
        my_errno = EOPNOTSUPP;
875
 
    return -1;  /* no symlinks on smb filesystem? */
 
910
        return -1;              /* no symlinks on smb filesystem? */
876
911
}
877
912
 
878
913
/* Extract the hostname and username from the path */
890
925
        struct cli_state *c;
891
926
        struct nmb_name called, calling;
892
927
        struct in_addr ip;
893
 
        extern struct in_addr ipzero;
894
928
 
895
929
        DEBUG(3, ("smbfs_do_connect(%s, %s)\n", server, share));
896
930
        if (*share == '\\') {
956
990
        
957
991
        DEBUG(3, (" session setup ok\n"));
958
992
 
959
 
        if (!cli_send_tconX(c, share, const_cast(char *, "?????"),
 
993
        if (!cli_send_tconX(c, share, "?????",
960
994
                            current_bucket->password, strlen(current_bucket->password)+1)) {
961
995
                DEBUG(1,("%s: tree connect failed: %s\n", share, cli_errstr(c)));
962
996
                break;
977
1011
static int
978
1012
smbfs_get_master_browser(char **host)
979
1013
{
 
1014
        static char so_broadcast[] = "SO_BROADCAST";
980
1015
        int count;
981
1016
        struct in_addr *ip_list, bcast_addr;
982
 
        extern struct in_addr  ipzero;
983
1017
 
984
1018
        /* does port = 137 for win95 master browser? */
985
1019
        int fd= open_socket_in( SOCK_DGRAM, 0, 3,
986
1020
                             interpret_addr(lp_socket_address()), True ); 
987
1021
        if (fd == -1)
988
1022
                return 0;
989
 
        set_socket_options(fd, const_cast(char *, "SO_BROADCAST"));
 
1023
        set_socket_options(fd, so_broadcast);
990
1024
        ip_list = iface_bcast(ipzero);
991
1025
        bcast_addr = *ip_list;
992
1026
        if ((ip_list = name_query(fd, "\01\02__MSBROWSE__\02", 1, True, 
1204
1238
        smbfs_connection *sc;
1205
1239
        char *remote_dir;
1206
1240
 
1207
 
        DEBUG(3, ("smbfs_opendir(dirname:%s)\n", dirname));
 
1241
    (void) me;
 
1242
 
 
1243
    DEBUG(3, ("smbfs_opendir(dirname:%s)\n", dirname));
1208
1244
 
1209
1245
    if (!(remote_dir = smbfs_get_path (&sc, dirname)))
1210
 
                return NULL;
 
1246
        return NULL;
1211
1247
 
1212
 
        /* FIXME: where freed? */
 
1248
    /* FIXME: where freed? */
1213
1249
    smbfs_info = g_new (opendir_info, 1);
1214
1250
        smbfs_info->server_list = FALSE;
1215
1251
    smbfs_info->path = g_strdup(dirname);               /* keep original */
1227
1263
    dir_entry *dentry;
1228
1264
    const char *p;
1229
1265
 
 
1266
    (void) server_url;
 
1267
 
1230
1268
    if ((p = strrchr (path, '/')))
1231
1269
        path = p + 1;           /* advance until last '/' */
1232
1270
 
1452
1490
    char *remote_dir;
1453
1491
    smbfs_connection *sc;
1454
1492
 
 
1493
    (void) me;
 
1494
 
1455
1495
    DEBUG (3, ("smbfs_chdir(path:%s)\n", path));
1456
1496
    if (!(remote_dir = smbfs_get_path (&sc, path)))
1457
1497
        return -1;
1621
1661
static int
1622
1662
smbfs_mknod (struct vfs_class *me, const char *path, int mode, int dev)
1623
1663
{
 
1664
    (void) me;
 
1665
 
1624
1666
        DEBUG(3, ("smbfs_mknod(path:%s, mode:%d, dev:%d)\n", path, mode, dev));
1625
1667
        my_errno = EOPNOTSUPP;
1626
1668
    return -1;
1633
1675
    char *remote_file;
1634
1676
    char *cpath;
1635
1677
 
 
1678
    (void) me;
 
1679
 
1636
1680
    DEBUG (3, ("smbfs_mkdir(path:%s, mode:%d)\n", path, (int) mode));
1637
1681
    if ((remote_file = smbfs_get_path (&sc, path)) == 0)
1638
1682
        return -1;
1657
1701
        char *remote_file;
1658
1702
        char *cpath;
1659
1703
 
 
1704
        (void) me;
 
1705
 
1660
1706
        DEBUG(3, ("smbfs_rmdir(path:%s)\n", path));
1661
1707
        if ((remote_file = smbfs_get_path (&sc, path)) == 0)
1662
1708
                return -1;
1678
1724
static int
1679
1725
smbfs_link (struct vfs_class *me, const char *p1, const char *p2)
1680
1726
{
 
1727
    (void) me;
 
1728
 
1681
1729
    DEBUG (3, ("smbfs_link(p1:%s, p2:%s)\n", p1, p2));
1682
1730
    my_errno = EOPNOTSUPP;
1683
1731
    return -1;
1732
1780
static int
1733
1781
smbfs_setctl (struct vfs_class *me, const char *path, int ctlop, void *arg)
1734
1782
{
 
1783
    (void) me;
 
1784
    (void) arg;
 
1785
 
1735
1786
    DEBUG (3, ("smbfs_setctl(path:%s, ctlop:%d)\n", path, ctlop));
1736
1787
    switch (ctlop) {
1737
1788
    case VFS_SETCTL_FORGET:
1747
1798
{
1748
1799
    size_t size;
1749
1800
 
 
1801
    (void) mode;
 
1802
 
1750
1803
    if (flags & O_TRUNC)        /* if it exists truncate to zero */
1751
1804
        DEBUG (3, ("smbfs_open: O_TRUNC\n"));
1752
1805
 
1803
1856
    smbfs_connection    *sc;
1804
1857
    smbfs_handle        *remote_handle;
1805
1858
 
 
1859
    (void) me;
 
1860
 
1806
1861
    DEBUG(3, ("smbfs_open(file:%s, flags:%d, mode:%o)\n", file, flags, mode));
1807
1862
 
1808
1863
    if (!(remote_file = smbfs_get_path (&sc, file)))
1829
1884
    smbfs_connection *sc;
1830
1885
    char *remote_file;
1831
1886
 
 
1887
    (void) me;
 
1888
 
1832
1889
    if ((remote_file = smbfs_get_path (&sc, path)) == 0)
1833
1890
        return -1;
1834
1891
 
1851
1908
    char *ra, *rb;
1852
1909
    int retval;
1853
1910
 
 
1911
    (void) me;
 
1912
 
1854
1913
    if ((ra = smbfs_get_path (&sc, a)) == 0)
1855
1914
        return -1;
1856
1915