Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/client/clitar.c

    r414 r740  
    3636
    3737#include "includes.h"
     38#include "system/filesys.h"
    3839#include "clitar.h"
    3940#include "client/client_proto.h"
     41#include "libsmb/libsmb.h"
    4042
    4143static int clipfind(char **aret, int ret, char *tok);
     
    7072#define ATTRRESET 0
    7173
    72 static uint16 attribute = aDIR | aSYSTEM | aHIDDEN;
     74static uint16 attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
    7375
    7476#ifndef CLIENT_TIMEOUT
     
    115117static void writetarheader(int f,  const char *aname, uint64_t size, time_t mtime,
    116118                           const char *amode, unsigned char ftype);
    117 static void do_atar(const char *rname_in,char *lname,file_info *finfo1);
    118 static void do_tar(file_info *finfo, const char *dir);
     119static NTSTATUS do_atar(const char *rname_in, char *lname,
     120                    struct file_info *finfo1);
     121static NTSTATUS do_tar(struct cli_state *cli_state, struct file_info *finfo,
     122                   const char *dir);
    119123static void oct_it(uint64_t value, int ndgs, char *p);
    120124static void fixtarname(char *tptr, const char *fp, size_t l);
     
    292296        if ((unoct(hb->dbuf.mode, sizeof(hb->dbuf.mode)) & S_IFDIR) ||
    293297                                (*(finfo->name+strlen(finfo->name)-1) == '\\')) {
    294                 finfo->mode=aDIR;
     298                finfo->mode=FILE_ATTRIBUTE_DIRECTORY;
    295299        } else {
    296300                finfo->mode=0; /* we don't care about mode at the moment, we'll
     
    487491        char *s1_0=s1;
    488492
    489         while(*s1 && *s2 && (*s1 == *s2 || tolower_ascii(*s1) == tolower_ascii(*s2) ||
     493        while(*s1 && *s2 && (*s1 == *s2 || tolower_m(*s1) == tolower_m(*s2) ||
    490494                                (*s1 == '\\' && *s2=='/') || (*s1 == '/' && *s2=='\\'))) {
    491495                s1++; s2++;
     
    614618***************************************************************************/
    615619
    616 static void do_atar(const char *rname_in,char *lname,file_info *finfo1)
     620static NTSTATUS do_atar(const char *rname_in, char *lname,
     621                    struct file_info *finfo1)
    617622{
    618623        uint16_t fnum = (uint16_t)-1;
     
    626631        char *rname = NULL;
    627632        TALLOC_CTX *ctx = talloc_stackframe();
    628 
    629         struct timeval tp_start;
    630 
    631         GetTimeOfDay(&tp_start);
     633        NTSTATUS status = NT_STATUS_OK;
     634        struct timespec tp_start;
     635
     636        clock_gettime_mono(&tp_start);
    632637
    633638        data = SMB_MALLOC_ARRAY(char, read_size);
    634639        if (!data) {
    635640                DEBUG(0,("do_atar: out of memory.\n"));
     641                status = NT_STATUS_NO_MEMORY;
    636642                goto cleanup;
    637643        }
     
    660666        rname = clean_name(ctx, rname_in);
    661667        if (!rname) {
     668                status = NT_STATUS_NO_MEMORY;
    662669                goto cleanup;
    663670        }
    664671
    665         if (!NT_STATUS_IS_OK(cli_open(cli, rname, O_RDONLY, DENY_NONE, &fnum))) {
     672        status = cli_open(cli, rname, O_RDONLY, DENY_NONE, &fnum);
     673        if (!NT_STATUS_IS_OK(status)) {
    666674                DEBUG(0,("%s opening remote file %s (%s)\n",
    667675                                cli_errstr(cli),rname, client_get_cur_dir()));
     
    672680        if (finfo.name == NULL) {
    673681                DEBUG(0, ("Unable to allocate space for finfo.name in do_atar\n"));
     682                status = NT_STATUS_NO_MEMORY;
    674683                goto cleanup;
    675684        }
     
    679688        DEBUG(3,("file %s attrib 0x%X\n",finfo.name,finfo.mode));
    680689
    681         if (tar_inc && !(finfo.mode & aARCH)) {
     690        if (tar_inc && !(finfo.mode & FILE_ATTRIBUTE_ARCHIVE)) {
    682691                DEBUG(4, ("skipping %s - archive bit not set\n", finfo.name));
    683692                shallitime=0;
    684         } else if (!tar_system && (finfo.mode & aSYSTEM)) {
     693        } else if (!tar_system && (finfo.mode & FILE_ATTRIBUTE_SYSTEM)) {
    685694                DEBUG(4, ("skipping %s - system bit is set\n", finfo.name));
    686695                shallitime=0;
    687         } else if (!tar_hidden && (finfo.mode & aHIDDEN)) {
     696        } else if (!tar_hidden && (finfo.mode & FILE_ATTRIBUTE_HIDDEN)) {
    688697                DEBUG(4, ("skipping %s - hidden bit is set\n", finfo.name));
    689698                shallitime=0;
     
    702711                        if (datalen == -1) {
    703712                                DEBUG(0,("Error reading file %s : %s\n", rname, cli_errstr(cli)));
     713                                status = cli_nt_error(cli);
    704714                                break;
    705715                        }
     
    730740                        if (dotarbuf(tarhandle,data,datalen) != datalen) {
    731741                                DEBUG(0,("Error writing to tar file - %s\n", strerror(errno)));
     742                                status = map_nt_error_from_unix(errno);
    732743                                break;
    733744                        }
    734745
    735746                        if ( (datalen == 0) && (finfo.size != 0) ) {
     747                                status = NT_STATUS_UNSUCCESSFUL;
    736748                                DEBUG(0,("Error reading file %s. Got 0 bytes\n", rname));
    737749                                break;
     
    746758                                DEBUG(0, ("Didn't get entire file. size=%.0f, nread=%d\n",
    747759                                                        (double)finfo.size, (int)nread));
    748                                 if (padit(data, (uint64_t)sizeof(data), finfo.size - nread))
     760                                if (padit(data, (uint64_t)sizeof(data), finfo.size - nread)) {
     761                                        status = map_nt_error_from_unix(errno);
    749762                                        DEBUG(0,("Error writing tar file - %s\n", strerror(errno)));
     763                                }
    750764                        }
    751765
     
    759773                        DEBUG(4, ("skipping %s - initial read failed (file was locked ?)\n", finfo.name));
    760774                        shallitime=0;
     775                        status = NT_STATUS_UNSUCCESSFUL;
    761776                }
    762777        }
     
    766781
    767782        if (shallitime) {
    768                 struct timeval tp_end;
     783                struct timespec tp_end;
    769784                int this_time;
    770785
    771786                /* if shallitime is true then we didn't skip */
    772787                if (tar_reset && !dry_run)
    773                         (void) do_setrattr(finfo.name, aARCH, ATTRRESET);
    774 
    775                 GetTimeOfDay(&tp_end);
    776                 this_time = (tp_end.tv_sec - tp_start.tv_sec)*1000 + (tp_end.tv_usec - tp_start.tv_usec)/1000;
     788                        (void) do_setrattr(finfo.name, FILE_ATTRIBUTE_ARCHIVE, ATTRRESET);
     789
     790                clock_gettime_mono(&tp_end);
     791                this_time = (tp_end.tv_sec - tp_start.tv_sec)*1000 + (tp_end.tv_nsec - tp_start.tv_nsec)/1000000;
    777792                get_total_time_ms += this_time;
    778793                get_total_size += finfo.size;
     
    798813        TALLOC_FREE(ctx);
    799814        SAFE_FREE(data);
     815        return status;
    800816}
    801817
     
    804820***************************************************************************/
    805821
    806 static void do_tar(file_info *finfo, const char *dir)
     822static NTSTATUS do_tar(struct cli_state *cli_state, struct file_info *finfo,
     823                   const char *dir)
    807824{
    808825        TALLOC_CTX *ctx = talloc_stackframe();
     826        NTSTATUS status = NT_STATUS_OK;
    809827
    810828        if (strequal(finfo->name,"..") || strequal(finfo->name,"."))
    811                 return;
     829                return NT_STATUS_OK;
    812830
    813831        /* Is it on the exclude list ? */
     
    822840                                finfo->name);
    823841                if (!exclaim) {
    824                         return;
     842                        return NT_STATUS_NO_MEMORY;
    825843                }
    826844
     
    831849                        DEBUG(3,("Skipping file %s\n", exclaim));
    832850                        TALLOC_FREE(exclaim);
    833                         return;
     851                        return NT_STATUS_OK;
    834852                }
    835853                TALLOC_FREE(exclaim);
    836854        }
    837855
    838         if (finfo->mode & aDIR) {
     856        if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
    839857                char *saved_curdir = NULL;
    840858                char *new_cd = NULL;
     
    843861                saved_curdir = talloc_strdup(ctx, client_get_cur_dir());
    844862                if (!saved_curdir) {
    845                         return;
     863                        return NT_STATUS_NO_MEMORY;
    846864                }
    847865
     
    856874                                finfo->name);
    857875                if (!new_cd) {
    858                         return;
     876                        return NT_STATUS_NO_MEMORY;
    859877                }
    860878                client_set_cur_dir(new_cd);
     
    875893                                client_get_cur_dir());
    876894                if (!mtar_mask) {
    877                         return;
     895                        return NT_STATUS_NO_MEMORY;
    878896                }
    879897                DEBUG(5, ("Doing list with mtar_mask: %s\n", mtar_mask));
    880                 do_list(mtar_mask, attribute, do_tar, False, True);
     898                status = do_list(mtar_mask, attribute, do_tar, False, True);
    881899                client_set_cur_dir(saved_curdir);
    882900                TALLOC_FREE(saved_curdir);
     
    889907                                        finfo->name);
    890908                if (!rname) {
    891                         return;
    892                 }
    893                 do_atar(rname,finfo->name,finfo);
     909                        return NT_STATUS_NO_MEMORY;
     910                }
     911                status = do_atar(rname,finfo->name,finfo);
    894912                TALLOC_FREE(rname);
    895913        }
     914        return status;
    896915}
    897916
     
    9991018static int get_file(file_info2 finfo)
    10001019{
    1001         uint16_t fnum;
     1020        uint16_t fnum = (uint16_t) -1;
    10021021        int pos = 0, dsize = 0, bpos = 0;
    10031022        uint64_t rsize = 0;
     1023        NTSTATUS status;
    10041024
    10051025        DEBUG(5, ("get_file: file: %s, size %.0f\n", finfo.name, (double)finfo.size));
    10061026
    1007         if (ensurepath(finfo.name) &&
    1008                         (!NT_STATUS_IS_OK(cli_open(cli, finfo.name, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE,&fnum)))) {
     1027        if (!ensurepath(finfo.name)) {
    10091028                DEBUG(0, ("abandoning restore\n"));
    1010                 return(False);
     1029                return False;
     1030        }
     1031
     1032        status = cli_open(cli, finfo.name, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE, &fnum);
     1033        if (!NT_STATUS_IS_OK(status)) {
     1034                DEBUG(0, ("abandoning restore\n"));
     1035                return False;
    10111036        }
    10121037
     
    10221047                DEBUG(5, ("writing %i bytes, bpos = %i ...\n", dsize, bpos));
    10231048
    1024                 if (cli_write(cli, fnum, 0, buffer_p + bpos, pos, dsize) != dsize) {
    1025                         DEBUG(0, ("Error writing remote file\n"));
     1049                status = cli_writeall(cli, fnum, 0,
     1050                                      (uint8_t *)(buffer_p + bpos), pos,
     1051                                      dsize, NULL);
     1052                if (!NT_STATUS_IS_OK(status)) {
     1053                        DEBUG(0, ("Error writing remote file: %s\n",
     1054                                  nt_errstr(status)));
    10261055                        return 0;
    10271056                }
     
    11561185{
    11571186        file_info2 finfo;
    1158         struct timeval tp_start;
     1187        struct timespec tp_start;
    11591188        char *longfilename = NULL, linkflag;
    11601189        int skip = False;
     
    11621191        ZERO_STRUCT(finfo);
    11631192
    1164         GetTimeOfDay(&tp_start);
     1193        clock_gettime_mono(&tp_start);
    11651194        DEBUG(5, ("RJS do_tarput called ...\n"));
    11661195
     
    11841213                                if ((next_block(tarbuf, &buffer_p, tbufsiz) <= 0) && !skip_file(finfo.size)) {
    11851214                                        DEBUG(0, ("Short file, bailing out...\n"));
     1215                                        SAFE_FREE(longfilename);
    11861216                                        return;
    11871217                                }
     
    11901220                        case -1:
    11911221                                DEBUG(0, ("abandoning restore, -1 from read tar header\n"));
     1222                                SAFE_FREE(longfilename);
    11921223                                return;
    11931224
    11941225                        case 0: /* chksum is zero - looks like an EOF */
    11951226                                DEBUG(0, ("tar: restored %d files and directories\n", ntarf));
     1227                                SAFE_FREE(longfilename);
    11961228                                return;        /* Hmmm, bad here ... */
    11971229
     
    13751407                                        break;
    13761408                                case 'r':
    1377                                         attra[direct]|=aRONLY;
     1409                                        attra[direct]|=FILE_ATTRIBUTE_READONLY;
    13781410                                        break;
    13791411                                case 'h':
    1380                                         attra[direct]|=aHIDDEN;
     1412                                        attra[direct]|=FILE_ATTRIBUTE_HIDDEN;
    13811413                                        break;
    13821414                                case 's':
    1383                                         attra[direct]|=aSYSTEM;
     1415                                        attra[direct]|=FILE_ATTRIBUTE_SYSTEM;
    13841416                                        break;
    13851417                                case 'a':
    1386                                         attra[direct]|=aARCH;
     1418                                        attra[direct]|=FILE_ATTRIBUTE_ARCHIVE;
    13871419                                        break;
    13881420                                default:
     
    19241956                 */
    19251957                if (tarhandle == 1)  {
    1926                         dbf = x_stderr;
     1958                        setup_logging("smbclient", DEBUG_STDERR);
    19271959                }
    19281960                if (!argv[Optind]) {
Note: See TracChangeset for help on using the changeset viewer.