Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/utils/smbget.c

    r599 r745  
    88   the Free Software Foundation; either version 3 of the License, or
    99   (at your option) any later version.
    10    
     10
    1111   This program is distributed in the hope that it will be useful,
    1212   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1313   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1414   GNU General Public License for more details.
    15    
     15
    1616   You should have received a copy of the GNU General Public License
    1717   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
    1818
    1919#include "includes.h"
     20#include "system/filesys.h"
     21#include "popt_common.h"
    2022#include "libsmbclient.h"
    2123
     
    5052static int blocksize = SMB_DEFAULT_BLOCKSIZE;
    5153
    52 static int smb_download_file(const char *base, const char *name, int recursive, int resume, char *outfile);
     54static int smb_download_file(const char *base, const char *name, int recursive,
     55                             int resume, int toplevel, char *outfile);
    5356
    5457static int get_num_cols(void)
     
    7578static void human_readable(off_t s, char *buffer, int l)
    7679{
    77         if(s > 1024 * 1024 * 1024) snprintf(buffer, l, "%.2fGB",
    78                                             1.0 * s / (1024 * 1024 * 1024));
    79         else if(s > 1024 * 1024) snprintf(buffer, l, "%.2fMB",
    80                                           1.0 * s / (1024 * 1024));
    81         else if(s > 1024) snprintf(buffer, l, "%.2fkB", 1.0 * s / 1024);
    82         else snprintf(buffer, l, OFF_T_FORMAT"b", (OFF_T_FORMAT_CAST)s);
     80        if (s > 1024 * 1024 * 1024) {
     81                snprintf(buffer, l, "%.2fGB", 1.0 * s / (1024 * 1024 * 1024));
     82        } else if (s > 1024 * 1024) {
     83                snprintf(buffer, l, "%.2fMB", 1.0 * s / (1024 * 1024));
     84        } else if (s > 1024) {
     85                snprintf(buffer, l, "%.2fkB", 1.0 * s / 1024);
     86        } else {
     87                snprintf(buffer, l, OFF_T_FORMAT"b", (OFF_T_FORMAT_CAST)s);
     88        }
    8389}
    8490
     
    138144        dirhandle = smbc_opendir(path);
    139145        if(dirhandle < 1) {
    140                 if(errno == ENOTDIR) return smb_download_file(base, name, 1, resume, NULL);
     146                if (errno == ENOTDIR) {
     147                        return smb_download_file(base, name, 1, resume,
     148                                                 0, NULL);
     149                }
    141150                fprintf(stderr, "Can't open directory %s: %s\n", path, strerror(errno));
    142151                return 1;
     
    145154        while(*relname == '/')relname++;
    146155        mkdir(relname, 0755);
    147        
     156
    148157        tmpname = SMB_STRDUP(name);
    149158
     
    168177
    169178                case SMBC_FILE:
    170                         ret = smb_download_file(base, newname, 1, resume, NULL);
     179                        ret = smb_download_file(base, newname, 1, resume, 0,
     180                                                NULL);
    171181                        break;
    172182
     
    182192                        if(!quiet)printf("Ignoring comms share %s\n", dirent->name);
    183193                        break;
    184                        
     194
    185195                case SMBC_IPC_SHARE:
    186196                        if(!quiet)printf("Ignoring ipc$ share %s\n", dirent->name);
     
    201211                        return 1;
    202212                }
    203                
     213
    204214                if(chmod(relname, remotestat.st_mode) < 0) {
    205215                        fprintf(stderr, "Unable to change mode of local dir %s to %o\n", relname,
     
    250260                return;
    251261        }
    252        
     262
    253263        if(columns) {
    254264                int required = strlen(name), available = columns - len - strlen("[] ");
     
    269279/* Return 1 on error, 0 on success. */
    270280
    271 static int smb_download_file(const char *base, const char *name, int recursive, int resume, char *outfile) {
     281static int smb_download_file(const char *base, const char *name, int recursive,
     282                             int resume, int toplevel, char *outfile)
     283{
    272284        int remotehandle, localhandle;
    273         time_t start_time = time(NULL);
     285        time_t start_time = time_mono(NULL);
    274286        const char *newpath;
    275287        char path[SMB_MAXPATHLEN];
     
    280292
    281293        snprintf(path, SMB_MAXPATHLEN-1, "%s%s%s", base, (*base && *name && name[0] != '/' && base[strlen(base)-1] != '/')?"/":"", name);
    282        
     294
    283295        remotehandle = smbc_open(path, O_RDONLY, 0755);
    284296
     
    325337        } else newpath = name;
    326338
    327         if(newpath[0] == '/')newpath++;
    328        
     339        if (!toplevel && (newpath[0] == '/')) {
     340                newpath++;
     341        }
     342
    329343        /* Open local file according to the mode */
    330344        if(update) {
     
    353367                        return 1;
    354368                }
    355        
     369
    356370                if (fstat(localhandle, &localstat) != 0) {
    357371                        fprintf(stderr, "Can't fstat %s: %s\n", newpath, strerror(errno));
     
    404418                                        (OFF_T_FORMAT_CAST)off1,
    405419                                        (OFF_T_FORMAT_CAST)off2);
     420                                smbc_close(remotehandle); close(localhandle);
    406421                                return 1;
    407422                        }
     
    435450
    436451        readbuf = (char *)SMB_MALLOC(blocksize);
     452        if (!readbuf) {
     453                return 1;
     454        }
    437455
    438456        /* Now, download all bytes from offset_download to the end */
     
    459477                if(dots)fputc('.', stderr);
    460478                else if(!quiet) {
    461                         print_progress(newpath, start_time, time(NULL), start_offset, curpos, remotestat.st_size);
     479                        print_progress(newpath, start_time, time_mono(NULL),
     480                                        start_offset, curpos, remotestat.st_size);
    462481                }
    463482        }
     
    499518        human_readable(total_bytes, bs, sizeof(bs));
    500519        if(!quiet)fprintf(stderr, "Downloaded %s in %lu seconds\n", bs,
    501                 (unsigned long)(time(NULL) - total_start_time));
     520                (unsigned long)(time_mono(NULL) - total_start_time));
    502521        exit(0);
    503522}
     
    655674                        "require");
    656675        }
    657        
     676
    658677        columns = get_num_cols();
    659678
    660         total_start_time = time(NULL);
     679        total_start_time = time_mono(NULL);
    661680
    662681        while ( (file = poptGetArg(pc)) ) {
    663682                if (!recursive)
    664                         ret = smb_download_file(file, "", recursive, resume, outputfile);
     683                        ret = smb_download_file(file, "", recursive, resume,
     684                                                1, outputfile);
    665685                else
    666686                        ret = smb_download_dir(file, "", resume);
Note: See TracChangeset for help on using the changeset viewer.