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

Samba Server: update vendor to 3.6.0

Location:
vendor/current/source3/client
Files:
5 edited

Legend:

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

    r591 r740  
    2323
    2424#include "includes.h"
     25#include "system/filesys.h"
     26#include "popt_common.h"
     27#include "rpc_client/cli_pipe.h"
    2528#include "client/client_proto.h"
    26 #include "../librpc/gen_ndr/cli_srvsvc.h"
     29#include "../librpc/gen_ndr/ndr_srvsvc_c.h"
     30#include "../lib/util/select.h"
     31#include "system/readline.h"
     32#include "../libcli/smbreadline/smbreadline.h"
     33#include "../libcli/security/security.h"
     34#include "system/select.h"
     35#include "libsmb/libsmb.h"
     36#include "libsmb/clirap.h"
     37#include "trans2.h"
     38#include "libsmb/nmblib.h"
    2739
    2840#ifndef REGISTER
     
    3244extern int do_smb_browse(void); /* mDNS browsing */
    3345
    34 extern bool AllowDebugChange;
    3546extern bool override_logfile;
    3647extern char tar_type;
     
    164175
    165176/****************************************************************************
     177 Put up a yes/no prompt.
     178****************************************************************************/
     179
     180static bool yesno(const char *p)
     181{
     182        char ans[20];
     183        printf("%s",p);
     184
     185        if (!fgets(ans,sizeof(ans)-1,stdin))
     186                return(False);
     187
     188        if (*ans == 'y' || *ans == 'Y')
     189                return(True);
     190
     191        return(False);
     192}
     193
     194/****************************************************************************
    166195 Write to a local file with CR/LF->LF translation if appropriate. Return the
    167196 number taken from the buffer. This may not equal the number written.
     
    281310        char *targetpath = NULL;
    282311        TALLOC_CTX *ctx = talloc_tos();
     312        NTSTATUS status;
    283313
    284314        if ( !cli_resolve_path(ctx, "", auth_info, cli, client_get_cur_dir(), &targetcli, &targetpath)) {
     
    287317        }
    288318
    289         if (!NT_STATUS_IS_OK(cli_dskattr(targetcli, &bsize, &total, &avail))) {
    290                 d_printf("Error in dskattr: %s\n",cli_errstr(targetcli));
     319        status = cli_dskattr(targetcli, &bsize, &total, &avail);
     320        if (!NT_STATUS_IS_OK(status)) {
     321                d_printf("Error in dskattr: %s\n", nt_errstr(status));
    291322                return 1;
    292323        }
     
    315346static void normalize_name(char *newdir)
    316347{
    317         if (!(cli->posix_capabilities & CIFS_UNIX_POSIX_PATHNAMES_CAP)) {
     348        if (!(cli->requested_posix_capabilities & CIFS_UNIX_POSIX_PATHNAMES_CAP)) {
    318349                string_replace(newdir,'/','\\');
    319350        }
     
    391422
    392423        if (targetcli->protocol > PROTOCOL_LANMAN2 && !targetcli->win95) {
    393                 if (!cli_qpathinfo_basic( targetcli, targetpath, &sbuf, &attributes ) ) {
    394                         d_printf("cd %s: %s\n", new_cd, cli_errstr(targetcli));
     424                NTSTATUS status;
     425
     426                status = cli_qpathinfo_basic(targetcli, targetpath, &sbuf,
     427                                             &attributes);
     428                if (!NT_STATUS_IS_OK(status)) {
     429                        d_printf("cd %s: %s\n", new_cd, nt_errstr(status));
    395430                        client_set_cur_dir(saved_dir);
    396431                        goto out;
     
    403438                }
    404439        } else {
     440                NTSTATUS status;
     441
    405442                targetpath = talloc_asprintf(ctx,
    406443                                "%s%s",
     
    417454                }
    418455
    419                 if (!NT_STATUS_IS_OK(cli_chkpath(targetcli, targetpath))) {
    420                         d_printf("cd %s: %s\n", new_cd, cli_errstr(targetcli));
     456                status = cli_chkpath(targetcli, targetpath);
     457                if (!NT_STATUS_IS_OK(status)) {
     458                        d_printf("cd %s: %s\n", new_cd, nt_errstr(status));
    421459                        client_set_cur_dir(saved_dir);
    422460                        goto out;
     
    463501********************************************************************/
    464502
    465 static bool do_this_one(file_info *finfo)
     503static bool do_this_one(struct file_info *finfo)
    466504{
    467505        if (!finfo->name) {
     
    469507        }
    470508
    471         if (finfo->mode & aDIR) {
     509        if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
    472510                return true;
    473511        }
     
    484522        }
    485523
    486         if ((archive_level==1 || archive_level==2) && !(finfo->mode & aARCH)) {
     524        if ((archive_level==1 || archive_level==2) && !(finfo->mode & FILE_ATTRIBUTE_ARCHIVE)) {
    487525                DEBUG(3,("archive %s failed\n", finfo->name));
    488526                return false;
     
    496534****************************************************************************/
    497535
    498 static void display_finfo(file_info *finfo, const char *dir)
     536static NTSTATUS display_finfo(struct cli_state *cli_state, struct file_info *finfo,
     537                          const char *dir)
    499538{
    500539        time_t t;
    501540        TALLOC_CTX *ctx = talloc_tos();
     541        NTSTATUS status = NT_STATUS_OK;
    502542
    503543        if (!do_this_one(finfo)) {
    504                 return;
     544                return NT_STATUS_OK;
    505545        }
    506546
     
    519559                /* skip if this is . or .. */
    520560                if ( strequal(finfo->name,"..") || strequal(finfo->name,".") )
    521                         return;
     561                        return NT_STATUS_OK;
    522562                /* create absolute filename for cli_ntcreate() FIXME */
    523563                afname = talloc_asprintf(ctx,
     
    527567                                        finfo->name);
    528568                if (!afname) {
    529                         return;
     569                        return NT_STATUS_NO_MEMORY;
    530570                }
    531571                /* print file meta date header */
     
    534574                d_printf( "SIZE:%.0f\n", (double)finfo->size);
    535575                d_printf( "MTIME:%s", time_to_asc(t));
    536                 if (!NT_STATUS_IS_OK(cli_ntcreate(finfo->cli, afname, 0,
    537                                 CREATE_ACCESS_READ, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
    538                                 FILE_OPEN, 0x0, 0x0, &fnum))) {
     576                status = cli_ntcreate(cli_state, afname, 0,
     577                                      CREATE_ACCESS_READ, 0,
     578                                      FILE_SHARE_READ|FILE_SHARE_WRITE,
     579                                      FILE_OPEN, 0x0, 0x0, &fnum);
     580                if (!NT_STATUS_IS_OK(status)) {
    539581                        DEBUG( 0, ("display_finfo() Failed to open %s: %s\n",
    540                                 afname,
    541                                 cli_errstr( finfo->cli)));
     582                                   afname, nt_errstr(status)));
    542583                } else {
    543                         SEC_DESC *sd = NULL;
    544                         sd = cli_query_secdesc(finfo->cli, fnum, ctx);
     584                        struct security_descriptor *sd = NULL;
     585                        sd = cli_query_secdesc(cli_state, fnum, ctx);
    545586                        if (!sd) {
    546587                                DEBUG( 0, ("display_finfo() failed to "
    547588                                        "get security descriptor: %s",
    548                                         cli_errstr( finfo->cli)));
     589                                        cli_errstr(cli_state)));
     590                                status = cli_nt_error(cli_state);
    549591                        } else {
    550592                                display_sec_desc(sd);
     
    554596                TALLOC_FREE(afname);
    555597        }
     598        return status;
    556599}
    557600
     
    560603****************************************************************************/
    561604
    562 static void do_du(file_info *finfo, const char *dir)
     605static NTSTATUS do_du(struct cli_state *cli_state, struct file_info *finfo,
     606                  const char *dir)
    563607{
    564608        if (do_this_one(finfo)) {
    565609                dir_total += finfo->size;
    566610        }
     611        return NT_STATUS_OK;
    567612}
    568613
     
    573618static long do_list_queue_start = 0;
    574619static long do_list_queue_end = 0;
    575 static void (*do_list_fn)(file_info *, const char *dir);
     620static NTSTATUS (*do_list_fn)(struct cli_state *cli_state, struct file_info *,
     621                          const char *dir);
    576622
    577623/****************************************************************************
     
    690736****************************************************************************/
    691737
    692 static void do_list_helper(const char *mntpoint, file_info *f, const char *mask, void *state)
    693 {
     738static NTSTATUS do_list_helper(const char *mntpoint, struct file_info *f,
     739                           const char *mask, void *state)
     740{
     741        struct cli_state *cli_state = (struct cli_state *)state;
    694742        TALLOC_CTX *ctx = talloc_tos();
    695743        char *dir = NULL;
    696744        char *dir_end = NULL;
     745        NTSTATUS status = NT_STATUS_OK;
    697746
    698747        /* Work out the directory. */
    699748        dir = talloc_strdup(ctx, mask);
    700749        if (!dir) {
    701                 return;
     750                return NT_STATUS_NO_MEMORY;
    702751        }
    703752        if ((dir_end = strrchr(dir, CLI_DIRSEP_CHAR)) != NULL) {
     
    705754        }
    706755
    707         if (f->mode & aDIR) {
     756        if (f->mode & FILE_ATTRIBUTE_DIRECTORY) {
    708757                if (do_list_dirs && do_this_one(f)) {
    709                         do_list_fn(f, dir);
     758                        status = do_list_fn(cli_state, f, dir);
     759                        if (!NT_STATUS_IS_OK(status)) {
     760                                return status;
     761                        }
    710762                }
    711763                if (do_list_recurse &&
     
    719771                                d_printf("Empty dir name returned. Possible server misconfiguration.\n");
    720772                                TALLOC_FREE(dir);
    721                                 return;
     773                                return NT_STATUS_UNSUCCESSFUL;
    722774                        }
    723775
     
    728780                        if (!mask2) {
    729781                                TALLOC_FREE(dir);
    730                                 return;
     782                                return NT_STATUS_NO_MEMORY;
    731783                        }
    732784                        p = strrchr_m(mask2,CLI_DIRSEP_CHAR);
     
    742794                        if (!mask2) {
    743795                                TALLOC_FREE(dir);
    744                                 return;
     796                                return NT_STATUS_NO_MEMORY;
    745797                        }
    746798                        add_to_do_list_queue(mask2);
     
    748800                }
    749801                TALLOC_FREE(dir);
    750                 return;
     802                return NT_STATUS_OK;
    751803        }
    752804
    753805        if (do_this_one(f)) {
    754                 do_list_fn(f,dir);
     806                status = do_list_fn(cli_state, f, dir);
    755807        }
    756808        TALLOC_FREE(dir);
     809        return status;
    757810}
    758811
     
    761814****************************************************************************/
    762815
    763 void do_list(const char *mask,
     816NTSTATUS do_list(const char *mask,
    764817                        uint16 attribute,
    765                         void (*fn)(file_info *, const char *dir),
     818                        NTSTATUS (*fn)(struct cli_state *cli_state, struct file_info *,
     819                                   const char *dir),
    766820                        bool rec,
    767821                        bool dirs)
     
    771825        struct cli_state *targetcli = NULL;
    772826        char *targetpath = NULL;
     827        NTSTATUS ret_status = NT_STATUS_OK;
     828        NTSTATUS status = NT_STATUS_OK;
    773829
    774830        if (in_do_list && rec) {
     
    798854
    799855                        if (!head) {
    800                                 return;
     856                                return NT_STATUS_NO_MEMORY;
    801857                        }
    802858
     
    809865                        }
    810866
    811                         cli_list(targetcli, targetpath, attribute, do_list_helper, NULL);
     867                        status = cli_list(targetcli, targetpath, attribute,
     868                                 do_list_helper, targetcli);
     869                        if (!NT_STATUS_IS_OK(status)) {
     870                                d_printf("%s listing %s\n",
     871                                         nt_errstr(status), targetpath);
     872                                ret_status = status;
     873                        }
    812874                        remove_do_list_queue_head();
    813875                        if ((! do_list_queue_empty()) && (fn == display_finfo)) {
     
    837899                /* check for dfs */
    838900                if (cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetpath)) {
    839                         if (cli_list(targetcli, targetpath, attribute, do_list_helper, NULL) == -1) {
     901
     902                        status = cli_list(targetcli, targetpath, attribute,
     903                                          do_list_helper, targetcli);
     904                        if (!NT_STATUS_IS_OK(status)) {
    840905                                d_printf("%s listing %s\n",
    841                                         cli_errstr(targetcli), targetpath);
     906                                         nt_errstr(status), targetpath);
     907                                ret_status = status;
    842908                        }
    843909                        TALLOC_FREE(targetpath);
    844910                } else {
    845911                        d_printf("do_list: [%s] %s\n", mask, cli_errstr(cli));
     912                        ret_status = cli_nt_error(cli);
    846913                }
    847914        }
     
    849916        in_do_list = 0;
    850917        reset_do_list_queue();
     918        return ret_status;
    851919}
    852920
     
    858926{
    859927        TALLOC_CTX *ctx = talloc_tos();
    860         uint16 attribute = aDIR | aSYSTEM | aHIDDEN;
     928        uint16 attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
    861929        char *mask = NULL;
    862930        char *buf = NULL;
    863931        int rc = 1;
     932        NTSTATUS status;
    864933
    865934        dir_total = 0;
     
    888957        }
    889958
    890         do_list(mask, attribute, display_finfo, recurse, true);
     959        status = do_list(mask, attribute, display_finfo, recurse, true);
     960        if (!NT_STATUS_IS_OK(status)) {
     961                return 1;
     962        }
    891963
    892964        rc = do_dskattr();
     
    904976{
    905977        TALLOC_CTX *ctx = talloc_tos();
    906         uint16 attribute = aDIR | aSYSTEM | aHIDDEN;
     978        uint16 attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
    907979        char *mask = NULL;
    908980        char *buf = NULL;
     981        NTSTATUS status;
    909982        int rc = 1;
    910983
     
    9321005        }
    9331006
    934         do_list(mask, attribute, do_du, recurse, true);
     1007        status = do_list(mask, attribute, do_du, recurse, true);
     1008        if (!NT_STATUS_IS_OK(status)) {
     1009                return 1;
     1010        }
    9351011
    9361012        rc = do_dskattr();
     
    9831059        uint16_t fnum;
    9841060        bool newhandle = false;
    985         struct timeval tp_start;
     1061        struct timespec tp_start;
    9861062        uint16 attr;
    9871063        SMB_OFF_T size;
     
    10081084        }
    10091085
    1010         GetTimeOfDay(&tp_start);
    1011 
    1012         if (!NT_STATUS_IS_OK(cli_open(targetcli, targetname, O_RDONLY, DENY_NONE, &fnum))) {
    1013                 d_printf("%s opening remote file %s\n",cli_errstr(cli),rname);
     1086        clock_gettime_mono(&tp_start);
     1087
     1088        status = cli_open(targetcli, targetname, O_RDONLY, DENY_NONE, &fnum);
     1089        if (!NT_STATUS_IS_OK(status)) {
     1090                d_printf("%s opening remote file %s\n", nt_errstr(status),
     1091                         rname);
    10141092                return 1;
    10151093        }
     
    10381116
    10391117
    1040         if (!cli_qfileinfo(targetcli, fnum,
    1041                            &attr, &size, NULL, NULL, NULL, NULL, NULL) &&
    1042             !NT_STATUS_IS_OK(cli_getattrE(targetcli, fnum,
    1043                           &attr, &size, NULL, NULL, NULL))) {
    1044                 d_printf("getattrib: %s\n",cli_errstr(targetcli));
    1045                 return 1;
     1118        status = cli_qfileinfo_basic(targetcli, fnum, &attr, &size, NULL, NULL,
     1119                                     NULL, NULL, NULL);
     1120        if (!NT_STATUS_IS_OK(status)) {
     1121                status = cli_getattrE(targetcli, fnum, &attr, &size, NULL, NULL,
     1122                                      NULL);
     1123                if(!NT_STATUS_IS_OK(status)) {
     1124                        d_printf("getattrib: %s\n", nt_errstr(status));
     1125                        return 1;
     1126                }
    10461127        }
    10471128
     
    10581139        }
    10591140
    1060         if (!NT_STATUS_IS_OK(cli_close(targetcli, fnum))) {
    1061                 d_printf("Error %s closing remote file\n",cli_errstr(cli));
     1141        status = cli_close(targetcli, fnum);
     1142        if (!NT_STATUS_IS_OK(status)) {
     1143                d_printf("Error %s closing remote file\n", nt_errstr(status));
    10621144                rc = 1;
    10631145        }
     
    10671149        }
    10681150
    1069         if (archive_level >= 2 && (attr & aARCH)) {
    1070                 cli_setatr(cli, rname, attr & ~(uint16)aARCH, 0);
     1151        if (archive_level >= 2 && (attr & FILE_ATTRIBUTE_ARCHIVE)) {
     1152                cli_setatr(cli, rname, attr & ~(uint16)FILE_ATTRIBUTE_ARCHIVE, 0);
    10711153        }
    10721154
    10731155        {
    1074                 struct timeval tp_end;
     1156                struct timespec tp_end;
    10751157                int this_time;
    10761158
    1077                 GetTimeOfDay(&tp_end);
    1078                 this_time =
    1079                         (tp_end.tv_sec - tp_start.tv_sec)*1000 +
    1080                         (tp_end.tv_usec - tp_start.tv_usec)/1000;
     1159                clock_gettime_mono(&tp_end);
     1160                this_time = nsec_time_diff(&tp_end,&tp_start)/1000000;
    10811161                get_total_time_ms += this_time;
    10821162                get_total_size += nread;
     
    11321212****************************************************************************/
    11331213
    1134 static void do_mget(file_info *finfo, const char *dir)
    1135 {
    1136         TALLOC_CTX *ctx = talloc_tos();
     1214static NTSTATUS do_mget(struct cli_state *cli_state, struct file_info *finfo,
     1215                    const char *dir)
     1216{
     1217        TALLOC_CTX *ctx = talloc_tos();
     1218        NTSTATUS status = NT_STATUS_OK;
    11371219        char *rname = NULL;
    11381220        char *quest = NULL;
     
    11421224
    11431225        if (!finfo->name) {
    1144                 return;
     1226                return NT_STATUS_OK;
    11451227        }
    11461228
    11471229        if (strequal(finfo->name,".") || strequal(finfo->name,".."))
    1148                 return;
     1230                return NT_STATUS_OK;
    11491231
    11501232        if (abort_mget) {
    11511233                d_printf("mget aborted\n");
    1152                 return;
    1153         }
    1154 
    1155         if (finfo->mode & aDIR) {
     1234                return NT_STATUS_UNSUCCESSFUL;
     1235        }
     1236
     1237        if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
    11561238                if (asprintf(&quest,
    11571239                         "Get directory %s? ",finfo->name) < 0) {
    1158                         return;
     1240                        return NT_STATUS_NO_MEMORY;
    11591241                }
    11601242        } else {
    11611243                if (asprintf(&quest,
    11621244                         "Get file %s? ",finfo->name) < 0) {
    1163                         return;
     1245                        return NT_STATUS_NO_MEMORY;
    11641246                }
    11651247        }
     
    11671249        if (prompt && !yesno(quest)) {
    11681250                SAFE_FREE(quest);
    1169                 return;
     1251                return NT_STATUS_OK;
    11701252        }
    11711253        SAFE_FREE(quest);
    11721254
    1173         if (!(finfo->mode & aDIR)) {
     1255        if (!(finfo->mode & FILE_ATTRIBUTE_DIRECTORY)) {
    11741256                rname = talloc_asprintf(ctx,
    11751257                                "%s%s",
     
    11771259                                finfo->name);
    11781260                if (!rname) {
    1179                         return;
     1261                        return NT_STATUS_NO_MEMORY;
    11801262                }
    11811263                do_get(rname, finfo->name, false);
    11821264                TALLOC_FREE(rname);
    1183                 return;
     1265                return NT_STATUS_OK;
    11841266        }
    11851267
     
    11871269        saved_curdir = talloc_strdup(ctx, client_get_cur_dir());
    11881270        if (!saved_curdir) {
    1189                 return;
     1271                return NT_STATUS_NO_MEMORY;
    11901272        }
    11911273
     
    11961278                                CLI_DIRSEP_STR);
    11971279        if (!new_cd) {
    1198                 return;
     1280                return NT_STATUS_NO_MEMORY;
    11991281        }
    12001282        client_set_cur_dir(new_cd);
     
    12091291                d_printf("failed to create directory %s\n",finfo->name);
    12101292                client_set_cur_dir(saved_curdir);
    1211                 return;
     1293                return map_nt_error_from_unix(errno);
    12121294        }
    12131295
     
    12151297                d_printf("failed to chdir to directory %s\n",finfo->name);
    12161298                client_set_cur_dir(saved_curdir);
    1217                 return;
     1299                return map_nt_error_from_unix(errno);
    12181300        }
    12191301
     
    12231305
    12241306        if (!mget_mask) {
    1225                 return;
    1226         }
    1227 
    1228         do_list(mget_mask, aSYSTEM | aHIDDEN | aDIR,do_mget,false, true);
     1307                return NT_STATUS_NO_MEMORY;
     1308        }
     1309
     1310        status = do_list(mget_mask, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY,do_mget,false, true);
     1311        if (!NT_STATUS_IS_OK(status)) {
     1312                return status;
     1313        }
     1314
    12291315        if (chdir("..") == -1) {
    12301316                d_printf("do_mget: failed to chdir to .. (error %s)\n",
    12311317                        strerror(errno) );
     1318                return map_nt_error_from_unix(errno);
    12321319        }
    12331320        client_set_cur_dir(saved_curdir);
     
    12351322        TALLOC_FREE(saved_curdir);
    12361323        TALLOC_FREE(new_cd);
     1324        return NT_STATUS_OK;
    12371325}
    12381326
     
    13091397{
    13101398        TALLOC_CTX *ctx = talloc_tos();
    1311         uint16 attribute = aSYSTEM | aHIDDEN;
     1399        uint16 attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
    13121400        char *mget_mask = NULL;
    13131401        char *buf = NULL;
     1402        NTSTATUS status = NT_STATUS_OK;
    13141403
    13151404        if (recurse) {
    1316                 attribute |= aDIR;
     1405                attribute |= FILE_ATTRIBUTE_DIRECTORY;
    13171406        }
    13181407
     
    13201409
    13211410        while (next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
     1411
    13221412                mget_mask = talloc_strdup(ctx, client_get_cur_dir());
    13231413                if (!mget_mask) {
     
    13331423                        return 1;
    13341424                }
    1335                 do_list(mget_mask, attribute, do_mget, false, true);
     1425                status = do_list(mget_mask, attribute, do_mget, false, true);
     1426                if (!NT_STATUS_IS_OK(status)) {
     1427                        return 1;
     1428                }
    13361429        }
    13371430
     
    13481441                        return 1;
    13491442                }
    1350                 do_list(mget_mask, attribute, do_mget, false, true);
     1443                status = do_list(mget_mask, attribute, do_mget, false, true);
     1444                if (!NT_STATUS_IS_OK(status)) {
     1445                        return 1;
     1446                }
    13511447        }
    13521448
     
    13631459        struct cli_state *targetcli;
    13641460        char *targetname = NULL;
     1461        NTSTATUS status;
    13651462
    13661463        if (!cli_resolve_path(ctx, "", auth_info, cli, name, &targetcli, &targetname)) {
     
    13691466        }
    13701467
    1371         if (!NT_STATUS_IS_OK(cli_mkdir(targetcli, targetname))) {
     1468        status = cli_mkdir(targetcli, targetname);
     1469        if (!NT_STATUS_IS_OK(status)) {
    13721470                d_printf("%s making remote directory %s\n",
    1373                          cli_errstr(targetcli),name);
     1471                         nt_errstr(status),name);
    13741472                return false;
    13751473        }
     
    13851483{
    13861484        fstring altname;
    1387 
    1388         if (!NT_STATUS_IS_OK(cli_qpathinfo_alt_name(cli, name, altname))) {
     1485        NTSTATUS status;
     1486
     1487        status = cli_qpathinfo_alt_name(cli, name, altname);
     1488        if (!NT_STATUS_IS_OK(status)) {
    13891489                d_printf("%s getting alt name for %s\n",
    1390                          cli_errstr(cli),name);
     1490                         nt_errstr(status),name);
    13911491                return false;
    13921492        }
     
    15051605}
    15061606
     1607static char *attr_str(TALLOC_CTX *mem_ctx, uint16_t mode)
     1608{
     1609        char *attrs = TALLOC_ZERO_ARRAY(mem_ctx, char, 17);
     1610        int i = 0;
     1611
     1612        if (!(mode & FILE_ATTRIBUTE_NORMAL)) {
     1613                if (mode & FILE_ATTRIBUTE_ENCRYPTED) {
     1614                        attrs[i++] = 'E';
     1615                }
     1616                if (mode & FILE_ATTRIBUTE_NONINDEXED) {
     1617                        attrs[i++] = 'N';
     1618                }
     1619                if (mode & FILE_ATTRIBUTE_OFFLINE) {
     1620                        attrs[i++] = 'O';
     1621                }
     1622                if (mode & FILE_ATTRIBUTE_COMPRESSED) {
     1623                        attrs[i++] = 'C';
     1624                }
     1625                if (mode & FILE_ATTRIBUTE_REPARSE_POINT) {
     1626                        attrs[i++] = 'r';
     1627                }
     1628                if (mode & FILE_ATTRIBUTE_SPARSE) {
     1629                        attrs[i++] = 's';
     1630                }
     1631                if (mode & FILE_ATTRIBUTE_TEMPORARY) {
     1632                        attrs[i++] = 'T';
     1633                }
     1634                if (mode & FILE_ATTRIBUTE_NORMAL) {
     1635                        attrs[i++] = 'N';
     1636                }
     1637                if (mode & FILE_ATTRIBUTE_READONLY) {
     1638                        attrs[i++] = 'R';
     1639                }
     1640                if (mode & FILE_ATTRIBUTE_HIDDEN) {
     1641                        attrs[i++] = 'H';
     1642                }
     1643                if (mode & FILE_ATTRIBUTE_SYSTEM) {
     1644                        attrs[i++] = 'S';
     1645                }
     1646                if (mode & FILE_ATTRIBUTE_DIRECTORY) {
     1647                        attrs[i++] = 'D';
     1648                }
     1649                if (mode & FILE_ATTRIBUTE_ARCHIVE) {
     1650                        attrs[i++] = 'A';
     1651                }
     1652        }
     1653        return attrs;
     1654}
     1655
    15071656/****************************************************************************
    15081657 Show all info we can get
     
    15171666        SMB_INO_T ino;
    15181667        NTTIME tmp;
     1668        uint16_t fnum;
    15191669        unsigned int num_streams;
    15201670        struct stream_struct *streams;
     1671        int num_snapshots;
     1672        char **snapshots;
    15211673        unsigned int i;
    1522 
    1523         if (!NT_STATUS_IS_OK(cli_qpathinfo_alt_name(cli, name, altname))) {
    1524                 d_printf("%s getting alt name for %s\n",
    1525                          cli_errstr(cli),name);
     1674        NTSTATUS status;
     1675
     1676        status = cli_qpathinfo_alt_name(cli, name, altname);
     1677        if (!NT_STATUS_IS_OK(status)) {
     1678                d_printf("%s getting alt name for %s\n", nt_errstr(status),
     1679                         name);
    15261680                return false;
    15271681        }
    15281682        d_printf("altname: %s\n", altname);
    15291683
    1530         if (!cli_qpathinfo2(cli, name, &b_time, &a_time, &m_time, &c_time,
    1531                             &size, &mode, &ino)) {
    1532                 d_printf("%s getting pathinfo for %s\n",
    1533                          cli_errstr(cli),name);
     1684        status = cli_qpathinfo2(cli, name, &b_time, &a_time, &m_time, &c_time,
     1685                                &size, &mode, &ino);
     1686        if (!NT_STATUS_IS_OK(status)) {
     1687                d_printf("%s getting pathinfo for %s\n", nt_errstr(status),
     1688                         name);
    15341689                return false;
    15351690        }
     
    15471702        d_printf("change_time:    %s\n", nt_time_string(talloc_tos(), tmp));
    15481703
    1549         if (!cli_qpathinfo_streams(cli, name, talloc_tos(), &num_streams,
    1550                                    &streams)) {
    1551                 d_printf("%s getting streams for %s\n",
    1552                          cli_errstr(cli),name);
     1704        d_printf("attributes: %s (%x)\n", attr_str(talloc_tos(), mode), mode);
     1705
     1706        status = cli_qpathinfo_streams(cli, name, talloc_tos(), &num_streams,
     1707                                       &streams);
     1708        if (!NT_STATUS_IS_OK(status)) {
     1709                d_printf("%s getting streams for %s\n", nt_errstr(status),
     1710                         name);
    15531711                return false;
    15541712        }
     
    15581716                         (unsigned long long)streams[i].size);
    15591717        }
     1718
     1719        status = cli_ntcreate(cli, name, 0,
     1720                              CREATE_ACCESS_READ, 0,
     1721                              FILE_SHARE_READ|FILE_SHARE_WRITE
     1722                              |FILE_SHARE_DELETE,
     1723                              FILE_OPEN, 0x0, 0x0, &fnum);
     1724        if (!NT_STATUS_IS_OK(status)) {
     1725                /*
     1726                 * Ignore failure, it does not hurt if we can't list
     1727                 * snapshots
     1728                 */
     1729                return 0;
     1730        }
     1731        status = cli_shadow_copy_data(talloc_tos(), cli, fnum,
     1732                                      true, &snapshots, &num_snapshots);
     1733        if (!NT_STATUS_IS_OK(status)) {
     1734                cli_close(cli, fnum);
     1735                return 0;
     1736        }
     1737
     1738        for (i=0; i<num_snapshots; i++) {
     1739                char *snap_name;
     1740
     1741                d_printf("%s\n", snapshots[i]);
     1742                snap_name = talloc_asprintf(talloc_tos(), "%s%s",
     1743                                            snapshots[i], name);
     1744                status = cli_qpathinfo2(cli, snap_name, &b_time, &a_time,
     1745                                        &m_time, &c_time, &size,
     1746                                        NULL, NULL);
     1747                if (!NT_STATUS_IS_OK(status)) {
     1748                        d_fprintf(stderr, "pathinfo(%s) failed: %s\n",
     1749                                  snap_name, nt_errstr(status));
     1750                        TALLOC_FREE(snap_name);
     1751                        continue;
     1752                }
     1753                unix_timespec_to_nt_time(&tmp, b_time);
     1754                d_printf("create_time:    %s\n", nt_time_string(talloc_tos(), tmp));
     1755                unix_timespec_to_nt_time(&tmp, a_time);
     1756                d_printf("access_time:    %s\n", nt_time_string(talloc_tos(), tmp));
     1757                unix_timespec_to_nt_time(&tmp, m_time);
     1758                d_printf("write_time:     %s\n", nt_time_string(talloc_tos(), tmp));
     1759                unix_timespec_to_nt_time(&tmp, c_time);
     1760                d_printf("change_time:    %s\n", nt_time_string(talloc_tos(), tmp));
     1761                d_printf("size: %d\n", (int)size);
     1762        }
     1763
     1764        TALLOC_FREE(snapshots);
    15601765
    15611766        return 0;
     
    16021807        SMB_OFF_T start = 0;
    16031808        int rc = 0;
    1604         struct timeval tp_start;
     1809        struct timespec tp_start;
    16051810        struct cli_state *targetcli;
    16061811        char *targetname = NULL;
     
    16131818        }
    16141819
    1615         GetTimeOfDay(&tp_start);
     1820        clock_gettime_mono(&tp_start);
    16161821
    16171822        if (reput) {
    16181823                status = cli_open(targetcli, targetname, O_RDWR|O_CREAT, DENY_NONE, &fnum);
    16191824                if (NT_STATUS_IS_OK(status)) {
    1620                         if (!cli_qfileinfo(targetcli, fnum, NULL, &start, NULL, NULL, NULL, NULL, NULL) &&
    1621                             !NT_STATUS_IS_OK(cli_getattrE(targetcli, fnum, NULL, &start, NULL, NULL, NULL))) {
    1622                                 d_printf("getattrib: %s\n",cli_errstr(cli));
     1825                        if (!NT_STATUS_IS_OK(status = cli_qfileinfo_basic(
     1826                                                     targetcli, fnum, NULL,
     1827                                                     &start, NULL, NULL,
     1828                                                     NULL, NULL, NULL)) &&
     1829                            !NT_STATUS_IS_OK(status = cli_getattrE(
     1830                                                     targetcli, fnum, NULL,
     1831                                                     &start, NULL, NULL,
     1832                                                     NULL))) {
     1833                                d_printf("getattrib: %s\n", nt_errstr(status));
    16231834                                return 1;
    16241835                        }
     
    16291840
    16301841        if (!NT_STATUS_IS_OK(status)) {
    1631                 d_printf("%s opening remote file %s\n",cli_errstr(targetcli),rname);
     1842                d_printf("%s opening remote file %s\n", nt_errstr(status),
     1843                         rname);
    16321844                return 1;
    16331845        }
     
    16691881        if (!NT_STATUS_IS_OK(status)) {
    16701882                d_fprintf(stderr, "cli_push returned %s\n", nt_errstr(status));
    1671         }
    1672 
    1673         if (!NT_STATUS_IS_OK(cli_close(targetcli, fnum))) {
    1674                 d_printf("%s closing remote file %s\n",cli_errstr(cli),rname);
     1883                rc = 1;
     1884        }
     1885
     1886        status = cli_close(targetcli, fnum);
     1887        if (!NT_STATUS_IS_OK(status)) {
     1888                d_printf("%s closing remote file %s\n", nt_errstr(status),
     1889                         rname);
    16751890                if (f != x_stdin) {
    16761891                        x_fclose(f);
     
    16841899
    16851900        {
    1686                 struct timeval tp_end;
     1901                struct timespec tp_end;
    16871902                int this_time;
    16881903
    1689                 GetTimeOfDay(&tp_end);
    1690                 this_time =
    1691                         (tp_end.tv_sec - tp_start.tv_sec)*1000 +
    1692                         (tp_end.tv_usec - tp_start.tv_usec)/1000;
     1904                clock_gettime_mono(&tp_end);
     1905                this_time = nsec_time_diff(&tp_end,&tp_start)/1000000;
    16931906                put_total_time_ms += this_time;
    16941907                put_total_size += state.nread;
     
    20792292****************************************************************************/
    20802293
    2081 static void do_del(file_info *finfo, const char *dir)
     2294static NTSTATUS do_del(struct cli_state *cli_state, struct file_info *finfo,
     2295                   const char *dir)
    20822296{
    20832297        TALLOC_CTX *ctx = talloc_tos();
    20842298        char *mask = NULL;
     2299        NTSTATUS status;
    20852300
    20862301        mask = talloc_asprintf(ctx,
     
    20902305                                finfo->name);
    20912306        if (!mask) {
    2092                 return;
    2093         }
    2094 
    2095         if (finfo->mode & aDIR) {
     2307                return NT_STATUS_NO_MEMORY;
     2308        }
     2309
     2310        if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
    20962311                TALLOC_FREE(mask);
    2097                 return;
    2098         }
    2099 
    2100         if (!NT_STATUS_IS_OK(cli_unlink(finfo->cli, mask, aSYSTEM | aHIDDEN))) {
     2312                return NT_STATUS_OK;
     2313        }
     2314
     2315        status = cli_unlink(cli_state, mask, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     2316        if (!NT_STATUS_IS_OK(status)) {
    21012317                d_printf("%s deleting remote file %s\n",
    2102                                 cli_errstr(finfo->cli),mask);
     2318                         nt_errstr(status), mask);
    21032319        }
    21042320        TALLOC_FREE(mask);
     2321        return status;
    21052322}
    21062323
     
    21142331        char *mask = NULL;
    21152332        char *buf = NULL;
    2116         uint16 attribute = aSYSTEM | aHIDDEN;
     2333        NTSTATUS status = NT_STATUS_OK;
     2334        uint16 attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
    21172335
    21182336        if (recurse) {
    2119                 attribute |= aDIR;
     2337                attribute |= FILE_ATTRIBUTE_DIRECTORY;
    21202338        }
    21212339
     
    21332351        }
    21342352
    2135         do_list(mask,attribute,do_del,false,false);
     2353        status = do_list(mask,attribute,do_del,false,false);
     2354        if (!NT_STATUS_IS_OK(status)) {
     2355                return 1;
     2356        }
    21362357        return 0;
    21372358}
     
    21492370        struct cli_state *targetcli;
    21502371        char *targetname = NULL;
     2372        NTSTATUS status;
    21512373
    21522374        if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
     
    21742396        }
    21752397
    2176         if (!NT_STATUS_IS_OK(cli_unlink(targetcli, targetname, attribute))) {
    2177                 d_printf("%s deleting remote files %s\n",cli_errstr(targetcli),targetname);
     2398        status = cli_unlink(targetcli, targetname, attribute);
     2399        if (!NT_STATUS_IS_OK(status)) {
     2400                d_printf("%s deleting remote files %s\n", nt_errstr(status),
     2401                         targetname);
    21782402        }
    21792403        return 0;
     
    25332757        d_printf("Server supports CIFS capabilities %s\n", caps);
    25342758
    2535         if (!cli_set_unix_extensions_capabilities(cli, major, minor, caplow, caphigh)) {
    2536                 d_printf("Can't set UNIX CIFS extensions capabilities. %s.\n", cli_errstr(cli));
     2759        status = cli_set_unix_extensions_capabilities(cli, major, minor,
     2760                                                      caplow, caphigh);
     2761        if (!NT_STATUS_IS_OK(status)) {
     2762                d_printf("Can't set UNIX CIFS extensions capabilities. %s.\n",
     2763                         nt_errstr(status));
    25372764                return 1;
    25382765        }
     
    27783005        char *buf = NULL;
    27793006        char *buf2 = NULL;
    2780         char *targetname = NULL;
    2781         struct cli_state *targetcli;
     3007        struct cli_state *newcli;
    27823008
    27833009        if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
     
    27863012                return 1;
    27873013        }
    2788         oldname = talloc_asprintf(ctx,
    2789                         "%s%s",
    2790                         client_get_cur_dir(),
    2791                         buf);
    2792         if (!oldname) {
    2793                 return 1;
    2794         }
     3014        /* Oldname (link target) must be an untouched blob. */
     3015        oldname = buf;
     3016
    27953017        newname = talloc_asprintf(ctx,
    27963018                        "%s%s",
     
    28013023        }
    28023024
    2803         if (!cli_resolve_path(ctx, "", auth_info, cli, oldname, &targetcli, &targetname)) {
     3025        /* New name must be present in share namespace. */
     3026        if (!cli_resolve_path(ctx, "", auth_info, cli, newname, &newcli, &newname)) {
    28043027                d_printf("link %s: %s\n", oldname, cli_errstr(cli));
    28053028                return 1;
    28063029        }
    28073030
    2808         if (!SERVER_HAS_UNIX_CIFS(targetcli)) {
     3031        if (!SERVER_HAS_UNIX_CIFS(newcli)) {
    28093032                d_printf("Server doesn't support UNIX CIFS calls.\n");
    28103033                return 1;
    28113034        }
    28123035
    2813         if (!NT_STATUS_IS_OK(cli_posix_symlink(targetcli, targetname, newname))) {
     3036        if (!NT_STATUS_IS_OK(cli_posix_symlink(newcli, oldname, newname))) {
    28143037                d_printf("%s symlinking files (%s -> %s)\n",
    2815                         cli_errstr(targetcli), newname, targetname);
     3038                        cli_errstr(newcli), newname, newname);
    28163039                return 1;
    28173040        }
     
    31403363}
    31413364
     3365static void printf_cb(const char *buf, void *private_data)
     3366{
     3367        printf("%s", buf);
     3368}
     3369
     3370/****************************************************************************
     3371 Get the EA list of a file
     3372****************************************************************************/
     3373
     3374static int cmd_geteas(void)
     3375{
     3376        TALLOC_CTX *ctx = talloc_tos();
     3377        char *src = NULL;
     3378        char *name = NULL;
     3379        char *targetname = NULL;
     3380        struct cli_state *targetcli;
     3381        NTSTATUS status;
     3382        size_t i, num_eas;
     3383        struct ea_struct *eas;
     3384
     3385        if (!next_token_talloc(ctx, &cmd_ptr,&name,NULL)) {
     3386                d_printf("geteas filename\n");
     3387                return 1;
     3388        }
     3389        src = talloc_asprintf(ctx,
     3390                        "%s%s",
     3391                        client_get_cur_dir(),
     3392                        name);
     3393        if (!src) {
     3394                return 1;
     3395        }
     3396
     3397        if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli,
     3398                              &targetname)) {
     3399                d_printf("stat %s: %s\n", src, cli_errstr(cli));
     3400                return 1;
     3401        }
     3402
     3403        status = cli_get_ea_list_path(targetcli, targetname, talloc_tos(),
     3404                                      &num_eas, &eas);
     3405        if (!NT_STATUS_IS_OK(status)) {
     3406                d_printf("cli_get_ea_list_path: %s\n", nt_errstr(status));
     3407                return 1;
     3408        }
     3409
     3410        for (i=0; i<num_eas; i++) {
     3411                d_printf("%s (%d) =\n", eas[i].name, (int)eas[i].flags);
     3412                dump_data_cb(eas[i].value.data, eas[i].value.length, false,
     3413                             printf_cb, NULL);
     3414                d_printf("\n");
     3415        }
     3416
     3417        TALLOC_FREE(eas);
     3418
     3419        return 0;
     3420}
     3421
     3422/****************************************************************************
     3423 Set an EA of a file
     3424****************************************************************************/
     3425
     3426static int cmd_setea(void)
     3427{
     3428        TALLOC_CTX *ctx = talloc_tos();
     3429        char *src = NULL;
     3430        char *name = NULL;
     3431        char *eaname = NULL;
     3432        char *eavalue = NULL;
     3433        char *targetname = NULL;
     3434        struct cli_state *targetcli;
     3435        NTSTATUS status;
     3436
     3437        if (!next_token_talloc(ctx, &cmd_ptr, &name, NULL)
     3438            || !next_token_talloc(ctx, &cmd_ptr, &eaname, NULL)) {
     3439                d_printf("setea filename eaname value\n");
     3440                return 1;
     3441        }
     3442        if (!next_token_talloc(ctx, &cmd_ptr, &eavalue, NULL)) {
     3443                eavalue = talloc_strdup(ctx, "");
     3444        }
     3445        src = talloc_asprintf(ctx,
     3446                        "%s%s",
     3447                        client_get_cur_dir(),
     3448                        name);
     3449        if (!src) {
     3450                return 1;
     3451        }
     3452
     3453        if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli,
     3454                              &targetname)) {
     3455                d_printf("stat %s: %s\n", src, cli_errstr(cli));
     3456                return 1;
     3457        }
     3458
     3459        status =  cli_set_ea_path(targetcli, targetname, eaname, eavalue,
     3460                                  strlen(eavalue));
     3461        if (!NT_STATUS_IS_OK(status)) {
     3462                d_printf("set_ea %s: %s\n", src, nt_errstr(status));
     3463                return 1;
     3464        }
     3465
     3466        return 0;
     3467}
     3468
    31423469/****************************************************************************
    31433470 UNIX stat.
     
    33563683        uint32 serial_num;
    33573684        time_t create_date;
    3358 
    3359         if (!cli_get_fs_volume_info(cli, volname, &serial_num, &create_date)) {
    3360                 d_printf("Errr %s getting volume info\n",cli_errstr(cli));
     3685        NTSTATUS status;
     3686
     3687        status = cli_get_fs_volume_info(cli, volname, &serial_num,
     3688                                        &create_date);
     3689        if (!NT_STATUS_IS_OK(status)) {
     3690                d_printf("Error %s getting volume info\n", nt_errstr(status));
    33613691                return 1;
    33623692        }
     
    36854015        uint32_t total_entries = 0;
    36864016        int i;
     4017        struct dcerpc_binding_handle *b;
    36874018
    36884019        status = cli_rpc_pipe_open_noauth(cli, &ndr_table_srvsvc.syntax_id,
     
    36964027        }
    36974028
     4029        b = pipe_hnd->binding_handle;
     4030
    36984031        ZERO_STRUCT(info_ctr);
    36994032        ZERO_STRUCT(ctr1);
     
    37024035        info_ctr.ctr.ctr1 = &ctr1;
    37034036
    3704         status = rpccli_srvsvc_NetShareEnumAll(pipe_hnd, frame,
     4037        status = dcerpc_srvsvc_NetShareEnumAll(b, frame,
    37054038                                              pipe_hnd->desthost,
    37064039                                              &info_ctr,
     
    38194152        TALLOC_CTX *ctx = talloc_tos();
    38204153        char *l_username, *l_password;
     4154        NTSTATUS nt_status;
    38214155
    38224156        if (!next_token_talloc(ctx, &cmd_ptr,&l_username,NULL)) {
     
    38354169        }
    38364170
    3837         if (!NT_STATUS_IS_OK(cli_session_setup(cli, l_username,
    3838                                                l_password, strlen(l_password),
    3839                                                l_password, strlen(l_password),
    3840                                                lp_workgroup()))) {
    3841                 d_printf("session setup failed: %s\n", cli_errstr(cli));
     4171        nt_status = cli_session_setup(cli, l_username,
     4172                                      l_password, strlen(l_password),
     4173                                      l_password, strlen(l_password),
     4174                                      lp_workgroup());
     4175        if (!NT_STATUS_IS_OK(nt_status)) {
     4176                d_printf("session setup failed: %s\n", nt_errstr(nt_status));
    38424177                return -1;
    38434178        }
     
    39194254}
    39204255
     4256/****************************************************************************
     4257history
     4258****************************************************************************/
     4259static int cmd_history(void)
     4260{
     4261#if defined(HAVE_LIBREADLINE) && defined(HAVE_HISTORY_LIST)
     4262        HIST_ENTRY **hlist;
     4263        int i;
     4264
     4265        hlist = history_list();
     4266
     4267        for (i = 0; hlist && hlist[i]; i++) {
     4268                DEBUG(0, ("%d: %s\n", i, hlist[i]->line));
     4269        }
     4270#else
     4271        DEBUG(0,("no history without readline support\n"));
     4272#endif
     4273
     4274        return 0;
     4275}
    39214276
    39224277/* Some constants for completing filename arguments */
     
    39564311  {"get",cmd_get,"<remote name> [local name] get a file",{COMPL_REMOTE,COMPL_LOCAL}},
    39574312  {"getfacl",cmd_getfacl,"<file name> get the POSIX ACL on a file (UNIX extensions only)",{COMPL_REMOTE,COMPL_LOCAL}},
     4313  {"geteas", cmd_geteas, "<file name> get the EA list of a file",
     4314   {COMPL_REMOTE, COMPL_LOCAL}},
    39584315  {"hardlink",cmd_hardlink,"<src> <dest> create a Windows hard link",{COMPL_REMOTE,COMPL_REMOTE}},
    39594316  {"help",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}},
     
    39964353  {"rmdir",cmd_rmdir,"<directory> remove a directory",{COMPL_NONE,COMPL_NONE}},
    39974354  {"showacls",cmd_showacls,"toggle if ACLs are shown or not",{COMPL_NONE,COMPL_NONE}}, 
     4355  {"setea", cmd_setea, "<file name> <eaname> <eaval> Set an EA of a file",
     4356   {COMPL_REMOTE, COMPL_LOCAL}},
    39984357  {"setmode",cmd_setmode,"filename <setmode string> change modes of file",{COMPL_REMOTE,COMPL_NONE}},
    39994358  {"stat",cmd_stat,"filename Do a UNIX extensions stat call on a file",{COMPL_REMOTE,COMPL_REMOTE}},
     
    41344493#define MAX_COMPLETIONS 100
    41354494
    4136 typedef struct {
     4495struct completion_remote {
    41374496        char *dirmask;
    41384497        char **matches;
     
    41404499        const char *text;
    41414500        int len;
    4142 } completion_remote_t;
    4143 
    4144 static void completion_remote_filter(const char *mnt,
    4145                                 file_info *f,
     4501};
     4502
     4503static NTSTATUS completion_remote_filter(const char *mnt,
     4504                                struct file_info *f,
    41464505                                const char *mask,
    41474506                                void *state)
    41484507{
    4149         completion_remote_t *info = (completion_remote_t *)state;
    4150 
    4151         if ((info->count < MAX_COMPLETIONS - 1) &&
    4152                         (strncmp(info->text, f->name, info->len) == 0) &&
    4153                         (strcmp(f->name, ".") != 0) &&
    4154                         (strcmp(f->name, "..") != 0)) {
    4155                 if ((info->dirmask[0] == 0) && !(f->mode & aDIR))
    4156                         info->matches[info->count] = SMB_STRDUP(f->name);
    4157                 else {
    4158                         TALLOC_CTX *ctx = talloc_stackframe();
    4159                         char *tmp;
    4160 
    4161                         tmp = talloc_strdup(ctx,info->dirmask);
    4162                         if (!tmp) {
    4163                                 TALLOC_FREE(ctx);
    4164                                 return;
    4165                         }
    4166                         tmp = talloc_asprintf_append(tmp, "%s", f->name);
    4167                         if (!tmp) {
    4168                                 TALLOC_FREE(ctx);
    4169                                 return;
    4170                         }
    4171                         if (f->mode & aDIR) {
    4172                                 tmp = talloc_asprintf_append(tmp, "%s", CLI_DIRSEP_STR);
    4173                         }
    4174                         if (!tmp) {
    4175                                 TALLOC_FREE(ctx);
    4176                                 return;
    4177                         }
    4178                         info->matches[info->count] = SMB_STRDUP(tmp);
     4508        struct completion_remote *info = (struct completion_remote *)state;
     4509
     4510        if (info->count >= MAX_COMPLETIONS - 1) {
     4511                return NT_STATUS_OK;
     4512        }
     4513        if (strncmp(info->text, f->name, info->len) != 0) {
     4514                return NT_STATUS_OK;
     4515        }
     4516        if (ISDOT(f->name) || ISDOTDOT(f->name)) {
     4517                return NT_STATUS_OK;
     4518        }
     4519
     4520        if ((info->dirmask[0] == 0) && !(f->mode & FILE_ATTRIBUTE_DIRECTORY))
     4521                info->matches[info->count] = SMB_STRDUP(f->name);
     4522        else {
     4523                TALLOC_CTX *ctx = talloc_stackframe();
     4524                char *tmp;
     4525
     4526                tmp = talloc_strdup(ctx,info->dirmask);
     4527                if (!tmp) {
    41794528                        TALLOC_FREE(ctx);
    4180                 }
    4181                 if (info->matches[info->count] == NULL) {
    4182                         return;
    4183                 }
    4184                 if (f->mode & aDIR) {
    4185                         smb_readline_ca_char(0);
    4186                 }
    4187                 if (info->count == 1) {
    4188                         info->samelen = strlen(info->matches[info->count]);
    4189                 } else {
    4190                         while (strncmp(info->matches[info->count],
    4191                                                 info->matches[info->count-1],
    4192                                                 info->samelen) != 0) {
    4193                                 info->samelen--;
    4194                         }
    4195                 }
    4196                 info->count++;
    4197         }
     4529                        return NT_STATUS_NO_MEMORY;
     4530                }
     4531                tmp = talloc_asprintf_append(tmp, "%s", f->name);
     4532                if (!tmp) {
     4533                        TALLOC_FREE(ctx);
     4534                        return NT_STATUS_NO_MEMORY;
     4535                }
     4536                if (f->mode & FILE_ATTRIBUTE_DIRECTORY) {
     4537                        tmp = talloc_asprintf_append(tmp, "%s",
     4538                                                     CLI_DIRSEP_STR);
     4539                }
     4540                if (!tmp) {
     4541                        TALLOC_FREE(ctx);
     4542                        return NT_STATUS_NO_MEMORY;
     4543                }
     4544                info->matches[info->count] = SMB_STRDUP(tmp);
     4545                TALLOC_FREE(ctx);
     4546        }
     4547        if (info->matches[info->count] == NULL) {
     4548                return NT_STATUS_OK;
     4549        }
     4550        if (f->mode & FILE_ATTRIBUTE_DIRECTORY) {
     4551                smb_readline_ca_char(0);
     4552        }
     4553        if (info->count == 1) {
     4554                info->samelen = strlen(info->matches[info->count]);
     4555        } else {
     4556                while (strncmp(info->matches[info->count],
     4557                               info->matches[info->count-1],
     4558                               info->samelen) != 0) {
     4559                        info->samelen--;
     4560                }
     4561        }
     4562        info->count++;
     4563        return NT_STATUS_OK;
    41984564}
    41994565
     
    42054571        struct cli_state *targetcli = NULL;
    42064572        int i;
    4207         completion_remote_t info = { NULL, NULL, 1, 0, NULL, 0 };
    4208 
    4209         /* can't have non-static intialisation on Sun CC, so do it
     4573        struct completion_remote info = { NULL, NULL, 1, 0, NULL, 0 };
     4574        NTSTATUS status;
     4575
     4576        /* can't have non-static initialisation on Sun CC, so do it
    42104577           at run time here */
    42114578        info.samelen = len;
     
    42644631                goto cleanup;
    42654632        }
    4266         if (cli_list(targetcli, targetpath, aDIR | aSYSTEM | aHIDDEN,
    4267                                 completion_remote_filter, (void *)&info) < 0) {
     4633        status = cli_list(targetcli, targetpath, FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN,
     4634                          completion_remote_filter, (void *)&info);
     4635        if (!NT_STATUS_IS_OK(status)) {
    42684636                goto cleanup;
    42694637        }
     
    44074775static void readline_callback(void)
    44084776{
    4409         fd_set fds;
    4410         struct timeval timeout;
    44114777        static time_t last_t;
     4778        struct timespec now;
    44124779        time_t t;
    4413 
    4414         t = time(NULL);
     4780        int ret, revents;
     4781
     4782        clock_gettime_mono(&now);
     4783        t = now.tv_sec;
    44154784
    44164785        if (t - last_t < 5)
     
    44214790 again:
    44224791
    4423         if (cli->fd < 0 || cli->fd >= FD_SETSIZE) {
    4424                 errno = EBADF;
     4792        if (cli->fd == -1)
    44254793                return;
    4426         }
    4427 
    4428         FD_ZERO(&fds);
    4429         FD_SET(cli->fd,&fds);
    4430 
    4431         timeout.tv_sec = 0;
    4432         timeout.tv_usec = 0;
    4433         sys_select_intr(cli->fd+1,&fds,NULL,NULL,&timeout);
    44344794
    44354795        /* We deliberately use receive_smb_raw instead of
     
    44374797           session keepalives and then drop them here.
    44384798        */
    4439         if (FD_ISSET(cli->fd,&fds)) {
     4799
     4800        ret = poll_intr_one_fd(cli->fd, POLLIN|POLLHUP, 0, &revents);
     4801
     4802        if ((ret > 0) && (revents & (POLLIN|POLLHUP|POLLERR))) {
    44404803                NTSTATUS status;
    44414804                size_t len;
     
    45914954{
    45924955        cli = cli_cm_open(talloc_tos(), NULL,
    4593                         query_host, "IPC$", auth_info, true, smb_encrypt,
     4956                        have_ip ? dest_ss_str : query_host, "IPC$", auth_info, true, smb_encrypt,
    45944957                        max_protocol, port, name_type);
    45954958        if (!cli)
     
    46174980                cli_shutdown(cli);
    46184981                cli = cli_cm_open(talloc_tos(), NULL,
    4619                                 query_host, "IPC$", auth_info, true, smb_encrypt,
     4982                                have_ip ? dest_ss_str : query_host, "IPC$",
     4983                                auth_info, true, smb_encrypt,
    46204984                                max_protocol, 139, name_type);
    46214985        }
     
    47715135
    47725136        /* set default debug level to 1 regardless of what smb.conf sets */
    4773         setup_logging( "smbclient", true );
    4774         DEBUGLEVEL_CLASS[DBGC_ALL] = 1;
    4775         if ((dbf = x_fdup(x_stderr))) {
    4776                 x_setbuf( dbf, NULL );
    4777         }
    4778 
     5137        setup_logging( "smbclient", DEBUG_DEFAULT_STDERR );
    47795138        load_case_tables();
     5139
     5140        lp_set_cmdline("log level", "1");
    47805141
    47815142        auth_info = user_auth_info_init(frame);
     
    48445205                        break;
    48455206                case 'E':
    4846                         if (dbf) {
    4847                                 x_fclose(dbf);
    4848                         }
    4849                         dbf = x_stderr;
     5207                        setup_logging("smbclient", DEBUG_STDERR );
    48505208                        display_set_stderr();
    48515209                        break;
     
    49215279        }
    49225280
    4923         /*
    4924          * Don't load debug level from smb.conf. It should be
    4925          * set by cmdline arg or remain default (0)
    4926          */
    4927         AllowDebugChange = false;
    4928 
    49295281        /* save the workgroup...
    49305282
     
    49405292
    49415293        if ( override_logfile )
    4942                 setup_logging( lp_logfile(), false );
     5294                setup_logging( lp_logfile(), DEBUG_FILE );
    49435295
    49445296        if (!lp_load(get_dyn_CONFIGFILE(),true,false,false,true)) {
  • vendor/current/source3/client/client_proto.h

    r414 r740  
    2424#define _CLIENT_PROTO_H_
    2525
     26struct cli_state;
     27struct file_info;
    2628
    2729/* The following definitions come from client/client.c  */
     
    2931const char *client_get_cur_dir(void);
    3032const char *client_set_cur_dir(const char *newdir);
    31 void do_list(const char *mask,
     33NTSTATUS do_list(const char *mask,
    3234                        uint16 attribute,
    33                         void (*fn)(file_info *, const char *dir),
     35                        NTSTATUS (*fn)(struct cli_state *cli_state, struct file_info *,
     36                                   const char *dir),
    3437                        bool rec,
    3538                        bool dirs);
  • 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]) {
  • vendor/current/source3/client/dnsbrowse.c

    r591 r740  
    2424
    2525#include <dns_sd.h>
     26#include "system/select.h"
    2627
    2728/* Holds service instances found during DNS browse */
     
    6162        int fdsetsz;
    6263        int ret;
    63         fd_set *fdset = NULL;
    6464        struct timeval tv;
    6565        DNSServiceErrorType err;
     
    7878        mdnsfd = DNSServiceRefSockFD(mdns_conn_sdref);
    7979        for (;;)  {
    80                 if (fdset != NULL) {
    81                         TALLOC_FREE(fdset);
    82                 }
    83 
    84                 if (mdnsfd < 0 || mdnsfd >= FD_SETSIZE) {
    85                         errno = EBADF;
    86                         break;
    87                 }
    88 
    89                 fdsetsz = howmany(mdnsfd + 1, NFDBITS) * sizeof(fd_mask);
    90                 fdset = TALLOC_ZERO(ctx, fdsetsz);
    91                 FD_SET(mdnsfd, fdset);
    92 
    93                 tv.tv_sec = 1;
    94                 tv.tv_usec = 0;
    95 
    96                 /* Wait until response received from mDNS daemon */
    97                 ret = sys_select(mdnsfd + 1, fdset, NULL, NULL, &tv);
     80                int revents;
     81
     82                ret = poll_one_fd(mdnsfd, POLLIN|POLLHUP, 1000, &revents);
    9883                if (ret <= 0 && errno != EINTR) {
    9984                        break;
    10085                }
    10186
    102                 if (FD_ISSET(mdnsfd, fdset)) {
     87                if (revents & (POLLIN|POLLHUP|POLLERR)) {
    10388                        /* Invoke callback function */
    10489                        DNSServiceProcessResult(mdns_conn_sdref);
     
    161146        int fdsetsz;
    162147        int ret;
    163         fd_set *fdset = NULL;
    164148        struct mdns_browse_state bstate;
    165149        struct mdns_smbsrv_result *resptr;
     
    183167        mdnsfd = DNSServiceRefSockFD(mdns_conn_sdref);
    184168        for (;;)  {
    185                 if (fdset != NULL) {
    186                         TALLOC_FREE(fdset);
    187                 }
    188 
    189                 if (mdnsfd < 0 || mdnsfd >= FD_SETSIZE) {
    190                         errno = EBADF;
    191                         TALLOC_FREE(ctx);
    192                         return 1;
    193                 }
    194 
    195                 fdsetsz = howmany(mdnsfd + 1, NFDBITS) * sizeof(fd_mask);
    196                 fdset = TALLOC_ZERO(ctx, fdsetsz);
    197                 FD_SET(mdnsfd, fdset);
    198 
    199                 tv.tv_sec = 1;
    200                 tv.tv_usec = 0;
    201 
    202                 /* Wait until response received from mDNS daemon */
    203                 ret = sys_select(mdnsfd + 1, fdset, NULL, NULL, &tv);
     169                int revents;
     170
     171                ret = poll_one_fd(mdnsfd, POLLIN|POLLHUP, &revents, 1000);
    204172                if (ret <= 0 && errno != EINTR) {
    205173                        break;
    206174                }
    207175
    208                 if (FD_ISSET(mdnsfd, fdset)) {
     176                if (revents & (POLLIN|POLLHUP|POLLERR)) {
    209177                        /* Invoke callback function */
    210178                        if (DNSServiceProcessResult(mdns_conn_sdref)) {
  • vendor/current/source3/client/smbspool.c

    r414 r740  
    2424
    2525#include "includes.h"
     26#include "system/filesys.h"
     27#include "system/passwd.h"
     28#include "libsmb/libsmb.h"
    2629
    2730/*
     
    241244         */
    242245
    243         setup_logging("smbspool", True);
     246        setup_logging("smbspool", DEBUG_STDOUT);
    244247
    245248        lp_set_in_client(True); /* Make sure that we tell lp_load we are */
     
    402405        *need_auth = false;
    403406        nt_status = cli_start_connection(&cli, myname, server, NULL, port,
    404                                          Undefined, flags, NULL);
     407                                         Undefined, flags);
    405408        if (!NT_STATUS_IS_OK(nt_status)) {
    406409                fprintf(stderr, "ERROR: Connection failed: %s\n", nt_errstr(nt_status));
     
    559562        char            buffer[8192],   /* Buffer for copy */
    560563                       *ptr;    /* Pointer into title */
     564        NTSTATUS nt_status;
    561565
    562566
     
    575579         */
    576580
    577         if (!NT_STATUS_IS_OK(cli_open(cli, title, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum))) {
     581        nt_status = cli_open(cli, title, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE,
     582                          &fnum);
     583        if (!NT_STATUS_IS_OK(nt_status)) {
    578584                fprintf(stderr, "ERROR: %s opening remote spool %s\n",
    579                         cli_errstr(cli), title);
    580                 return (get_exit_code(cli, cli_nt_error(cli)));
     585                        nt_errstr(nt_status), title);
     586                return get_exit_code(cli, nt_status);
    581587        }
    582588
     
    591597
    592598        while ((nbytes = fread(buffer, 1, sizeof(buffer), fp)) > 0) {
    593                 if (cli_write(cli, fnum, 0, buffer, tbytes, nbytes) != nbytes) {
    594                         int status = get_exit_code(cli, cli_nt_error(cli));
    595 
    596                         fprintf(stderr, "ERROR: Error writing spool: %s\n", cli_errstr(cli));
    597                         fprintf(stderr, "DEBUG: Returning status %d...\n", status);
     599                NTSTATUS status;
     600
     601                status = cli_writeall(cli, fnum, 0, (uint8_t *)buffer,
     602                                      tbytes, nbytes, NULL);
     603                if (!NT_STATUS_IS_OK(status)) {
     604                        int ret = get_exit_code(cli, status);
     605                        fprintf(stderr, "ERROR: Error writing spool: %s\n",
     606                                nt_errstr(status));
     607                        fprintf(stderr, "DEBUG: Returning status %d...\n",
     608                                ret);
    598609                        cli_close(cli, fnum);
    599610
    600                         return (status);
     611                        return (ret);
    601612                }
    602613                tbytes += nbytes;
    603614        }
    604615
    605         if (!NT_STATUS_IS_OK(cli_close(cli, fnum))) {
     616        nt_status = cli_close(cli, fnum);
     617        if (!NT_STATUS_IS_OK(nt_status)) {
    606618                fprintf(stderr, "ERROR: %s closing remote spool %s\n",
    607                         cli_errstr(cli), title);
    608                 return (get_exit_code(cli, cli_nt_error(cli)));
     619                        nt_errstr(nt_status), title);
     620                return get_exit_code(cli, nt_status);
    609621        } else {
    610622                return (0);
Note: See TracChangeset for help on using the changeset viewer.