From fbc611f431db443c23486f768ca5e2bc4db95c24 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Tue, 29 Mar 2005 00:42:51 +0000 Subject: r6108: Added smbsh/smbwrapper for Linux to example/libsmbclient tree; provided more complete libsmbclient testbrowse utility (This used to be commit 15736b97c837a16d9c009b8bff18b31429ccbe83) --- examples/libsmbclient/smbwrapper/smbw_stat.c | 146 +++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 examples/libsmbclient/smbwrapper/smbw_stat.c (limited to 'examples/libsmbclient/smbwrapper/smbw_stat.c') diff --git a/examples/libsmbclient/smbwrapper/smbw_stat.c b/examples/libsmbclient/smbwrapper/smbw_stat.c new file mode 100644 index 0000000000..70b3064d22 --- /dev/null +++ b/examples/libsmbclient/smbwrapper/smbw_stat.c @@ -0,0 +1,146 @@ +/* + Unix SMB/Netbios implementation. + Version 2.0 + SMB wrapper stat functions + Copyright (C) Andrew Tridgell 1998 + Copyright (C) Derrell Lipman 2003-2005 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "smbw.h" + +static int timezone_diff = -1; + +#define TM_YEAR_BASE 1900 + +/******************************************************************* +yield the difference between *A and *B, in seconds, ignoring leap seconds +********************************************************************/ +static int tm_diff(struct tm *a, struct tm *b) +{ + int ay = a->tm_year + (TM_YEAR_BASE - 1); + int by = b->tm_year + (TM_YEAR_BASE - 1); + int intervening_leap_days = + (ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400); + int years = ay - by; + int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday); + int hours = 24*days + (a->tm_hour - b->tm_hour); + int minutes = 60*hours + (a->tm_min - b->tm_min); + int seconds = 60*minutes + (a->tm_sec - b->tm_sec); + + return seconds; +} + +/******************************************************************* + return the UTC offset in seconds west of UTC, or 0 if it cannot be determined + ******************************************************************/ +static int TimeZone(time_t t) +{ + struct tm *tm = gmtime(&t); + struct tm tm_utc; + if (!tm) + return 0; + tm_utc = *tm; + tm = localtime(&t); + if (!tm) + return 0; + return tm_diff(&tm_utc,tm); + +} + + +static void copy_stat(struct SMBW_stat *external, struct stat *internal) +{ + if (timezone_diff < 0) + { + timezone_diff = TimeZone(time(NULL)); + } + + external->s_dev = internal->st_dev; + external->s_ino = internal->st_ino; + external->s_mode = internal->st_mode; + external->s_nlink = internal->st_nlink; + external->s_uid = internal->st_uid; + external->s_gid = internal->st_gid; + external->s_rdev = internal->st_rdev; + external->s_size = internal->st_size; + external->s_blksize = internal->st_blksize; + external->s_blocks = internal->st_blocks; + external->s_atime = internal->st_atime + timezone_diff; + external->s_mtime = internal->st_mtime + timezone_diff; + external->s_ctime = internal->st_ctime + timezone_diff; +} + + +/***************************************************** +a wrapper for fstat() +*******************************************************/ +int smbw_fstat(int fd_smbw, struct SMBW_stat *st) +{ + int fd_client = smbw_fd_map[fd_smbw]; + struct stat statbuf; + + if (smbc_fstat(fd_client, &statbuf) < 0) { + return -1; + } + + copy_stat(st, &statbuf); + + return 0; +} + + +/***************************************************** +a wrapper for stat() +*******************************************************/ +int smbw_stat(const char *fname, struct SMBW_stat *st) +{ + int simulate; + char *p; + char path[PATH_MAX]; + struct stat statbuf; + + SMBW_INIT(); + + smbw_fix_path(fname, path); + + p = path + 6; /* look just past smb:// */ + simulate = (strchr(p, '/') == NULL); + + /* special case for full-network scan, workgroups, and servers */ + if (simulate) { + statbuf.st_dev = 0; + statbuf.st_ino = 0; + statbuf.st_mode = 0040777; + statbuf.st_nlink = 1; + statbuf.st_uid = 0; + statbuf.st_gid = 0; + statbuf.st_rdev = 0; + statbuf.st_size = 0; + statbuf.st_blksize = 1024; + statbuf.st_blocks = 1; + statbuf.st_atime = 0; /* beginning of epoch */ + statbuf.st_mtime = 0; /* beginning of epoch */ + statbuf.st_ctime = 0; /* beginning of epoch */ + + } else if (smbc_stat(path, &statbuf) < 0) { + return -1; + } + + copy_stat(st, &statbuf); + + return 0; +} -- cgit From e317034997bbeab447298070afdb1b78c60e0e69 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Wed, 1 Jun 2005 17:40:40 +0000 Subject: r7168: Updating file times from libsmbclient was not working for win98. Although the function that was being used to set attributes is a core protocol function (SMBsetatr = 0x09), it does not appear to work on win98. As a temporary measure, when file times are to be set, this version opens the file and uses SMBsetattrE = 0x22 instead. (The other advantage of this function over the original one is that it supports setting access time as well as modification time.) The next step, the proper solution if it can be made to work, is to write functions that use TRANS2_SET_PATH_INFO instead. (This used to be commit bab0bf7f4f9d2a4b6fcee4429094349302bbeb33) --- examples/libsmbclient/smbwrapper/smbw_stat.c | 51 ++-------------------------- 1 file changed, 3 insertions(+), 48 deletions(-) (limited to 'examples/libsmbclient/smbwrapper/smbw_stat.c') diff --git a/examples/libsmbclient/smbwrapper/smbw_stat.c b/examples/libsmbclient/smbwrapper/smbw_stat.c index 70b3064d22..a386c09209 100644 --- a/examples/libsmbclient/smbwrapper/smbw_stat.c +++ b/examples/libsmbclient/smbwrapper/smbw_stat.c @@ -22,53 +22,8 @@ #include "smbw.h" -static int timezone_diff = -1; - -#define TM_YEAR_BASE 1900 - -/******************************************************************* -yield the difference between *A and *B, in seconds, ignoring leap seconds -********************************************************************/ -static int tm_diff(struct tm *a, struct tm *b) -{ - int ay = a->tm_year + (TM_YEAR_BASE - 1); - int by = b->tm_year + (TM_YEAR_BASE - 1); - int intervening_leap_days = - (ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400); - int years = ay - by; - int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday); - int hours = 24*days + (a->tm_hour - b->tm_hour); - int minutes = 60*hours + (a->tm_min - b->tm_min); - int seconds = 60*minutes + (a->tm_sec - b->tm_sec); - - return seconds; -} - -/******************************************************************* - return the UTC offset in seconds west of UTC, or 0 if it cannot be determined - ******************************************************************/ -static int TimeZone(time_t t) -{ - struct tm *tm = gmtime(&t); - struct tm tm_utc; - if (!tm) - return 0; - tm_utc = *tm; - tm = localtime(&t); - if (!tm) - return 0; - return tm_diff(&tm_utc,tm); - -} - - static void copy_stat(struct SMBW_stat *external, struct stat *internal) { - if (timezone_diff < 0) - { - timezone_diff = TimeZone(time(NULL)); - } - external->s_dev = internal->st_dev; external->s_ino = internal->st_ino; external->s_mode = internal->st_mode; @@ -79,9 +34,9 @@ static void copy_stat(struct SMBW_stat *external, struct stat *internal) external->s_size = internal->st_size; external->s_blksize = internal->st_blksize; external->s_blocks = internal->st_blocks; - external->s_atime = internal->st_atime + timezone_diff; - external->s_mtime = internal->st_mtime + timezone_diff; - external->s_ctime = internal->st_ctime + timezone_diff; + external->s_atime = internal->st_atime; + external->s_mtime = internal->st_mtime; + external->s_ctime = internal->st_ctime; } -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- examples/libsmbclient/smbwrapper/smbw_stat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/libsmbclient/smbwrapper/smbw_stat.c') diff --git a/examples/libsmbclient/smbwrapper/smbw_stat.c b/examples/libsmbclient/smbwrapper/smbw_stat.c index a386c09209..c70496903f 100644 --- a/examples/libsmbclient/smbwrapper/smbw_stat.c +++ b/examples/libsmbclient/smbwrapper/smbw_stat.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 58e9534300430fa4f2bcb50fb2d1d2990bdbe636 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:57:11 +0000 Subject: r23785: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit d0e89d246d8e5e64196d6c1d16d39a70579ca42f) --- examples/libsmbclient/smbwrapper/smbw_stat.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'examples/libsmbclient/smbwrapper/smbw_stat.c') diff --git a/examples/libsmbclient/smbwrapper/smbw_stat.c b/examples/libsmbclient/smbwrapper/smbw_stat.c index c70496903f..7b2b011282 100644 --- a/examples/libsmbclient/smbwrapper/smbw_stat.c +++ b/examples/libsmbclient/smbwrapper/smbw_stat.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "smbw.h" -- cgit