~zulcss/samba/server-dailies-3.4

« back to all changes in this revision

Viewing changes to examples/libsmbclient/smbwrapper/smbw_stat.c

  • Committer: Chuck Short
  • Date: 2010-09-28 20:38:39 UTC
  • Revision ID: zulcss@ubuntu.com-20100928203839-pgjulytsi9ue63x1
Initial version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
   Unix SMB/Netbios implementation.
 
3
   Version 2.0
 
4
   SMB wrapper stat functions
 
5
   Copyright (C) Andrew Tridgell 1998
 
6
   Copyright (C) Derrell Lipman 2003-2005
 
7
   
 
8
   This program is free software; you can redistribute it and/or modify
 
9
   it under the terms of the GNU General Public License as published by
 
10
   the Free Software Foundation; either version 3 of the License, or
 
11
   (at your option) any later version.
 
12
   
 
13
   This program is distributed in the hope that it will be useful,
 
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
   GNU General Public License for more details.
 
17
   
 
18
   You should have received a copy of the GNU General Public License
 
19
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
*/
 
21
 
 
22
#include "smbw.h"
 
23
 
 
24
static void copy_stat(struct SMBW_stat *external, struct stat *internal)
 
25
{
 
26
        external->s_dev = internal->st_dev;
 
27
        external->s_ino = internal->st_ino;
 
28
        external->s_mode = internal->st_mode;
 
29
        external->s_nlink = internal->st_nlink;
 
30
        external->s_uid = internal->st_uid;
 
31
        external->s_gid = internal->st_gid;
 
32
        external->s_rdev = internal->st_rdev;
 
33
        external->s_size = internal->st_size;
 
34
        external->s_blksize = internal->st_blksize;
 
35
        external->s_blocks = internal->st_blocks;
 
36
        external->s_atime = internal->st_atime;
 
37
        external->s_mtime = internal->st_mtime;
 
38
        external->s_ctime = internal->st_ctime;
 
39
}
 
40
 
 
41
 
 
42
/***************************************************** 
 
43
a wrapper for fstat()
 
44
*******************************************************/
 
45
int smbw_fstat(int fd_smbw, struct SMBW_stat *st)
 
46
{
 
47
        int fd_client = smbw_fd_map[fd_smbw];
 
48
        struct stat statbuf;
 
49
 
 
50
        if (smbc_fstat(fd_client, &statbuf) < 0) {
 
51
                return -1;
 
52
        }
 
53
        
 
54
        copy_stat(st, &statbuf);
 
55
 
 
56
        return 0;
 
57
}
 
58
 
 
59
 
 
60
/***************************************************** 
 
61
a wrapper for stat()
 
62
*******************************************************/
 
63
int smbw_stat(const char *fname, struct SMBW_stat *st)
 
64
{
 
65
        int simulate;
 
66
        char *p;
 
67
        char path[PATH_MAX];
 
68
        struct stat statbuf;
 
69
 
 
70
        SMBW_INIT();
 
71
 
 
72
        smbw_fix_path(fname, path);
 
73
 
 
74
        p = path + 6;           /* look just past smb:// */
 
75
        simulate = (strchr(p, '/') == NULL);
 
76
 
 
77
        /* special case for full-network scan, workgroups, and servers */
 
78
        if (simulate) {
 
79
            statbuf.st_dev = 0;
 
80
            statbuf.st_ino = 0;
 
81
            statbuf.st_mode = 0040777;
 
82
            statbuf.st_nlink = 1;
 
83
            statbuf.st_uid = 0;
 
84
            statbuf.st_gid = 0;
 
85
            statbuf.st_rdev = 0;
 
86
            statbuf.st_size = 0;
 
87
            statbuf.st_blksize = 1024;
 
88
            statbuf.st_blocks = 1;
 
89
            statbuf.st_atime = 0; /* beginning of epoch */
 
90
            statbuf.st_mtime = 0; /* beginning of epoch */
 
91
            statbuf.st_ctime = 0; /* beginning of epoch */
 
92
 
 
93
        } else if (smbc_stat(path, &statbuf) < 0) {
 
94
                return -1;
 
95
        }
 
96
        
 
97
        copy_stat(st, &statbuf);
 
98
 
 
99
        return 0;
 
100
}