Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/libsmb/clirap.c

    r871 r988  
    2929#include "libsmb/clirap.h"
    3030#include "trans2.h"
     31#include "../libcli/smb/smbXcli_base.h"
    3132
    3233#define PIPE_LANMAN   "\\PIPE\\LANMAN"
     
    6768         */
    6869
    69         *rparam = (char *)memdup(my_rparam, num_my_rparam);
     70        *rparam = (char *)smb_memdup(my_rparam, num_my_rparam);
    7071        if (*rparam == NULL) {
    7172                goto fail;
     
    7475        TALLOC_FREE(my_rparam);
    7576
    76         *rdata = (char *)memdup(my_rdata, num_my_rdata);
     77        *rdata = (char *)smb_memdup(my_rdata, num_my_rdata);
    7778        if (*rdata == NULL) {
    7879                goto fail;
     
    117118        p += 2;
    118119        strlcpy(p,user,sizeof(param)-PTR_DIFF(p,param));
    119         strupper_m(p);
     120        if (!strupper_m(p)) {
     121                return false;
     122        }
    120123        p += 21;
    121124        p++;
     
    123126        p++;
    124127        strlcpy(p, workstation,sizeof(param)-PTR_DIFF(p,param));
    125         strupper_m(p);
     128        if (!strupper_m(p)) {
     129                return false;
     130        }
    126131        p += 16;
    127132        SSVAL(p, 0, CLI_BUFFER_SIZE);
     
    141146                if (cli->rap_error == 0) {
    142147                        DEBUG(4,("NetWkstaUserLogon success\n"));
    143                         cli->privileges = SVAL(p, 24);
     148                        /*
     149                         * The cli->privileges = SVAL(p, 24); field was set here
     150                         * but it was not use anywhere else.
     151                         */
    144152                        /* The cli->eff_name field used to be set here
    145153                           but it wasn't used anywhere else. */
     
    158166****************************************************************************/
    159167
    160 int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32, const char *, void *), void *state)
     168int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32_t, const char *, void *), void *state)
    161169{
    162170        char *rparam = NULL;
     
    265273****************************************************************************/
    266274
    267 bool cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
    268                        void (*fn)(const char *, uint32, const char *, void *),
     275bool cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32_t stype,
     276                       void (*fn)(const char *, uint32_t, const char *, void *),
    269277                       void *state)
    270278{
     
    277285        int uLevel = 1;
    278286        size_t len;
    279         uint32 func = RAP_NetServerEnum2;
     287        uint32_t func = RAP_NetServerEnum2;
    280288        char *last_entry = NULL;
    281289        int total_cnt = 0;
     
    575583
    576584struct tevent_req *cli_qpathinfo1_send(TALLOC_CTX *mem_ctx,
    577                                        struct event_context *ev,
     585                                       struct tevent_context *ev,
    578586                                       struct cli_state *cli,
    579587                                       const char *fname)
     
    588596        state->cli = cli;
    589597        subreq = cli_qpathinfo_send(state, ev, cli, fname, SMB_INFO_STANDARD,
    590                                     22, cli->max_xmit);
     598                                    22, CLI_BUFFER_SIZE);
    591599        if (tevent_req_nomem(subreq, req)) {
    592600                return tevent_req_post(req, ev);
     
    618626                             time_t *access_time,
    619627                             time_t *write_time,
    620                              SMB_OFF_T *size,
    621                              uint16 *mode)
     628                             off_t *size,
     629                             uint16_t *mode)
    622630{
    623631        struct cli_qpathinfo1_state *state = tevent_req_data(
     
    638646
    639647        if (change_time) {
    640                 *change_time = date_fn(state->data+0, state->cli->serverzone);
     648                *change_time = date_fn(state->data+0, smb1cli_conn_server_time_zone(state->cli->conn));
    641649        }
    642650        if (access_time) {
    643                 *access_time = date_fn(state->data+4, state->cli->serverzone);
     651                *access_time = date_fn(state->data+4, smb1cli_conn_server_time_zone(state->cli->conn));
    644652        }
    645653        if (write_time) {
    646                 *write_time = date_fn(state->data+8, state->cli->serverzone);
     654                *write_time = date_fn(state->data+8, smb1cli_conn_server_time_zone(state->cli->conn));
    647655        }
    648656        if (size) {
     
    660668                        time_t *access_time,
    661669                        time_t *write_time,
    662                         SMB_OFF_T *size,
    663                         uint16 *mode)
     670                        off_t *size,
     671                        uint16_t *mode)
    664672{
    665673        TALLOC_CTX *frame = talloc_stackframe();
    666         struct event_context *ev;
     674        struct tevent_context *ev;
    667675        struct tevent_req *req;
    668676        NTSTATUS status = NT_STATUS_NO_MEMORY;
    669677
    670         if (cli_has_async_calls(cli)) {
     678        if (smbXcli_conn_has_async_calls(cli->conn)) {
    671679                /*
    672680                 * Can't use sync call while an async call is in flight
     
    675683                goto fail;
    676684        }
    677         ev = event_context_init(frame);
     685        ev = samba_tevent_context_init(frame);
    678686        if (ev == NULL) {
    679687                goto fail;
     
    702710                               time_t write_time,
    703711                               time_t change_time,
    704                                uint16 mode)
     712                               uint16_t mode)
    705713{
    706714        unsigned int data_len = 0;
     
    751759
    752760struct tevent_req *cli_qpathinfo2_send(TALLOC_CTX *mem_ctx,
    753                                        struct event_context *ev,
     761                                       struct tevent_context *ev,
    754762                                       struct cli_state *cli,
    755763                                       const char *fname)
     
    764772        subreq = cli_qpathinfo_send(state, ev, cli, fname,
    765773                                    SMB_QUERY_FILE_ALL_INFO,
    766                                     68, cli->max_xmit);
     774                                    68, CLI_BUFFER_SIZE);
    767775        if (tevent_req_nomem(subreq, req)) {
    768776                return tevent_req_post(req, ev);
     
    795803                             struct timespec *write_time,
    796804                             struct timespec *change_time,
    797                              SMB_OFF_T *size, uint16 *mode,
     805                             off_t *size, uint16_t *mode,
    798806                             SMB_INO_T *ino)
    799807{
     
    835843                        struct timespec *write_time,
    836844                        struct timespec *change_time,
    837                         SMB_OFF_T *size, uint16 *mode,
     845                        off_t *size, uint16_t *mode,
    838846                        SMB_INO_T *ino)
    839847{
    840         TALLOC_CTX *frame = talloc_stackframe();
    841         struct event_context *ev;
     848        TALLOC_CTX *frame = NULL;
     849        struct tevent_context *ev;
    842850        struct tevent_req *req;
    843851        NTSTATUS status = NT_STATUS_NO_MEMORY;
    844852
    845         if (cli_has_async_calls(cli)) {
     853        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
     854                return cli_smb2_qpathinfo2(cli,
     855                                        fname,
     856                                        create_time,
     857                                        access_time,
     858                                        write_time,
     859                                        change_time,
     860                                        size,
     861                                        mode,
     862                                        ino);
     863        }
     864
     865        frame = talloc_stackframe();
     866
     867        if (smbXcli_conn_has_async_calls(cli->conn)) {
    846868                /*
    847869                 * Can't use sync call while an async call is in flight
     
    850872                goto fail;
    851873        }
    852         ev = event_context_init(frame);
     874        ev = samba_tevent_context_init(frame);
    853875        if (ev == NULL) {
    854876                goto fail;
     
    872894****************************************************************************/
    873895
    874 static bool parse_streams_blob(TALLOC_CTX *mem_ctx, const uint8_t *data,
    875                                size_t data_len,
    876                                unsigned int *pnum_streams,
    877                                struct stream_struct **pstreams);
    878 
    879896struct cli_qpathinfo_streams_state {
    880897        uint32_t num_data;
     
    899916        subreq = cli_qpathinfo_send(state, ev, cli, fname,
    900917                                    SMB_FILE_STREAM_INFORMATION,
    901                                     0, cli->max_xmit);
     918                                    0, CLI_BUFFER_SIZE);
    902919        if (tevent_req_nomem(subreq, req)) {
    903920                return tevent_req_post(req, ev);
     
    949966                               struct stream_struct **pstreams)
    950967{
    951         TALLOC_CTX *frame = talloc_stackframe();
    952         struct event_context *ev;
     968        TALLOC_CTX *frame = NULL;
     969        struct tevent_context *ev;
    953970        struct tevent_req *req;
    954971        NTSTATUS status = NT_STATUS_NO_MEMORY;
    955972
    956         if (cli_has_async_calls(cli)) {
     973        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
     974                return cli_smb2_qpathinfo_streams(cli,
     975                                        fname,
     976                                        mem_ctx,
     977                                        pnum_streams,
     978                                        pstreams);
     979        }
     980
     981        frame = talloc_stackframe();
     982
     983        if (smbXcli_conn_has_async_calls(cli->conn)) {
    957984                /*
    958985                 * Can't use sync call while an async call is in flight
     
    961988                goto fail;
    962989        }
    963         ev = event_context_init(frame);
     990        ev = samba_tevent_context_init(frame);
    964991        if (ev == NULL) {
    965992                goto fail;
     
    9791006}
    9801007
    981 static bool parse_streams_blob(TALLOC_CTX *mem_ctx, const uint8_t *rdata,
     1008bool parse_streams_blob(TALLOC_CTX *mem_ctx, const uint8_t *rdata,
    9821009                               size_t data_len,
    9831010                               unsigned int *pnum_streams,
     
    9991026                uint8_t *tmp_buf;
    10001027
    1001                 tmp = TALLOC_REALLOC_ARRAY(mem_ctx, streams,
     1028                tmp = talloc_realloc(mem_ctx, streams,
    10021029                                           struct stream_struct,
    10031030                                           num_streams+1);
     
    10241051                 */
    10251052
    1026                 tmp_buf = TALLOC_ARRAY(streams, uint8_t, nlen+2);
     1053                tmp_buf = talloc_array(streams, uint8_t, nlen+2);
    10271054                if (tmp_buf == NULL) {
    10281055                        goto fail;
     
    10341061
    10351062                if (!convert_string_talloc(streams, CH_UTF16, CH_UNIX, tmp_buf,
    1036                                            nlen+2, &vstr, &size, false))
     1063                                           nlen+2, &vstr, &size))
    10371064                {
    10381065                        TALLOC_FREE(tmp_buf);
     
    10651092****************************************************************************/
    10661093
    1067 NTSTATUS cli_qfilename(struct cli_state *cli, uint16_t fnum, char *name,
    1068                        size_t namelen)
    1069 {
     1094NTSTATUS cli_qfilename(struct cli_state *cli, uint16_t fnum,
     1095                       TALLOC_CTX *mem_ctx, char **_name)
     1096{
     1097        uint16_t recv_flags2;
    10701098        uint8_t *rdata;
    10711099        uint32_t num_rdata;
    10721100        NTSTATUS status;
     1101        char *name = NULL;
     1102        uint32_t namelen;
    10731103
    10741104        status = cli_qfileinfo(talloc_tos(), cli, fnum,
    10751105                               SMB_QUERY_FILE_NAME_INFO,
    1076                                4, cli->max_xmit,
     1106                               4, CLI_BUFFER_SIZE, &recv_flags2,
    10771107                               &rdata, &num_rdata);
    10781108        if (!NT_STATUS_IS_OK(status)) {
     
    10801110        }
    10811111
    1082         clistr_pull(cli->inbuf, name, rdata+4, namelen, IVAL(rdata, 0),
    1083                     STR_UNICODE);
     1112        namelen = IVAL(rdata, 0);
     1113        if (namelen > (num_rdata - 4)) {
     1114                TALLOC_FREE(rdata);
     1115                return NT_STATUS_INVALID_NETWORK_RESPONSE;
     1116        }
     1117
     1118        clistr_pull_talloc(mem_ctx,
     1119                           (const char *)rdata,
     1120                           recv_flags2,
     1121                           &name,
     1122                           rdata + 4,
     1123                           namelen,
     1124                           STR_UNICODE);
     1125        if (name == NULL) {
     1126                status = map_nt_error_from_unix(errno);
     1127                TALLOC_FREE(rdata);
     1128                return status;
     1129        }
     1130
     1131        *_name = name;
    10841132        TALLOC_FREE(rdata);
    10851133        return NT_STATUS_OK;
     
    10911139
    10921140NTSTATUS cli_qfileinfo_basic(struct cli_state *cli, uint16_t fnum,
    1093                              uint16 *mode, SMB_OFF_T *size,
     1141                             uint16_t *mode, off_t *size,
    10941142                             struct timespec *create_time,
    10951143                             struct timespec *access_time,
     
    11021150        NTSTATUS status;
    11031151
     1152        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
     1153                return cli_smb2_qfileinfo_basic(cli,
     1154                                                fnum,
     1155                                                mode,
     1156                                                size,
     1157                                                create_time,
     1158                                                access_time,
     1159                                                write_time,
     1160                                                change_time,
     1161                                                ino);
     1162        }
     1163
    11041164        /* if its a win95 server then fail this - win95 totally screws it
    11051165           up */
     
    11101170        status = cli_qfileinfo(talloc_tos(), cli, fnum,
    11111171                               SMB_QUERY_FILE_ALL_INFO,
    1112                                68, MIN(cli->max_xmit, 0xffff),
     1172                               68, CLI_BUFFER_SIZE,
     1173                               NULL,
    11131174                               &rdata, &num_rdata);
    11141175        if (!NT_STATUS_IS_OK(status)) {
     
    11541215
    11551216struct tevent_req *cli_qpathinfo_basic_send(TALLOC_CTX *mem_ctx,
    1156                                             struct event_context *ev,
     1217                                            struct tevent_context *ev,
    11571218                                            struct cli_state *cli,
    11581219                                            const char *fname)
     
    11681229        subreq = cli_qpathinfo_send(state, ev, cli, fname,
    11691230                                    SMB_QUERY_FILE_BASIC_INFO,
    1170                                     36, cli->max_xmit);
     1231                                    36, CLI_BUFFER_SIZE);
    11711232        if (tevent_req_nomem(subreq, req)) {
    11721233                return tevent_req_post(req, ev);
     
    11951256
    11961257NTSTATUS cli_qpathinfo_basic_recv(struct tevent_req *req,
    1197                                   SMB_STRUCT_STAT *sbuf, uint32 *attributes)
     1258                                  SMB_STRUCT_STAT *sbuf, uint32_t *attributes)
    11981259{
    11991260        struct cli_qpathinfo_basic_state *state = tevent_req_data(
     
    12051266        }
    12061267
     1268        sbuf->st_ex_btime = interpret_long_date((char *)state->data);
    12071269        sbuf->st_ex_atime = interpret_long_date((char *)state->data+8);
    12081270        sbuf->st_ex_mtime = interpret_long_date((char *)state->data+16);
     
    12131275
    12141276NTSTATUS cli_qpathinfo_basic(struct cli_state *cli, const char *name,
    1215                              SMB_STRUCT_STAT *sbuf, uint32 *attributes)
    1216 {
    1217         TALLOC_CTX *frame = talloc_stackframe();
    1218         struct event_context *ev;
     1277                             SMB_STRUCT_STAT *sbuf, uint32_t *attributes)
     1278{
     1279        TALLOC_CTX *frame = NULL;
     1280        struct tevent_context *ev;
    12191281        struct tevent_req *req;
    12201282        NTSTATUS status = NT_STATUS_NO_MEMORY;
    12211283
    1222         if (cli_has_async_calls(cli)) {
     1284        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
     1285                return cli_smb2_qpathinfo_basic(cli,
     1286                                                name,
     1287                                                sbuf,
     1288                                                attributes);
     1289        }
     1290
     1291        frame = talloc_stackframe();
     1292
     1293        if (smbXcli_conn_has_async_calls(cli->conn)) {
    12231294                /*
    12241295                 * Can't use sync call while an async call is in flight
     
    12271298                goto fail;
    12281299        }
    1229         ev = event_context_init(frame);
     1300        ev = samba_tevent_context_init(frame);
    12301301        if (ev == NULL) {
    12311302                goto fail;
     
    12571328        NTSTATUS status;
    12581329
     1330        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
     1331                return cli_smb2_qpathinfo_alt_name(cli,
     1332                                                fname,
     1333                                                alt_name);
     1334        }
     1335
    12591336        status = cli_qpathinfo(talloc_tos(), cli, fname,
    12601337                               SMB_QUERY_FILE_ALT_NAME_INFO,
    1261                                4, cli->max_xmit, &rdata, &num_rdata);
     1338                               4, CLI_BUFFER_SIZE, &rdata, &num_rdata);
    12621339        if (!NT_STATUS_IS_OK(status)) {
    12631340                return status;
     
    12721349        /* The returned data is a pushed string, not raw data. */
    12731350        if (!convert_string_talloc(talloc_tos(),
    1274                                    cli_ucs2(cli) ? CH_UTF16LE : CH_DOS,
     1351                                   smbXcli_conn_use_unicode(cli->conn) ? CH_UTF16LE : CH_DOS,
    12751352                                   CH_UNIX,
    12761353                                   rdata + 4,
    12771354                                   len,
    12781355                                   &converted,
    1279                                    &converted_size,
    1280                                    true)) {
     1356                                   &converted_size)) {
    12811357                return NT_STATUS_NO_MEMORY;
    12821358        }
     
    12881364        return NT_STATUS_OK;
    12891365}
     1366
     1367/****************************************************************************
     1368 Send a qpathinfo SMB_QUERY_FILE_STADNDARD_INFO call.
     1369****************************************************************************/
     1370
     1371NTSTATUS cli_qpathinfo_standard(struct cli_state *cli, const char *fname,
     1372                                uint64_t *allocated, uint64_t *size,
     1373                                uint32_t *nlinks,
     1374                                bool *is_del_pending, bool *is_dir)
     1375{
     1376        uint8_t *rdata;
     1377        uint32_t num_rdata;
     1378        NTSTATUS status;
     1379
     1380        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
     1381                return NT_STATUS_NOT_IMPLEMENTED;
     1382        }
     1383
     1384        status = cli_qpathinfo(talloc_tos(), cli, fname,
     1385                               SMB_QUERY_FILE_STANDARD_INFO,
     1386                               24, CLI_BUFFER_SIZE, &rdata, &num_rdata);
     1387        if (!NT_STATUS_IS_OK(status)) {
     1388                return status;
     1389        }
     1390
     1391        if (allocated) {
     1392                *allocated = BVAL(rdata, 0);
     1393        }
     1394
     1395        if (size) {
     1396                *size = BVAL(rdata, 8);
     1397        }
     1398
     1399        if (nlinks) {
     1400                *nlinks = IVAL(rdata, 16);
     1401        }
     1402
     1403        if (is_del_pending) {
     1404                *is_del_pending = CVAL(rdata, 20);
     1405        }
     1406
     1407        if (is_dir) {
     1408                *is_dir = CVAL(rdata, 20);
     1409        }
     1410
     1411        TALLOC_FREE(rdata);
     1412
     1413        return NT_STATUS_OK;
     1414}
     1415
     1416
     1417/* like cli_qpathinfo2 but do not use SMB_QUERY_FILE_ALL_INFO with smb1 */
     1418NTSTATUS cli_qpathinfo3(struct cli_state *cli, const char *fname,
     1419                        struct timespec *create_time,
     1420                        struct timespec *access_time,
     1421                        struct timespec *write_time,
     1422                        struct timespec *change_time,
     1423                        off_t *size, uint16_t *mode,
     1424                        SMB_INO_T *ino)
     1425{
     1426        NTSTATUS status = NT_STATUS_OK;
     1427        SMB_STRUCT_STAT st = { 0 };
     1428        uint32_t attr;
     1429        uint64_t pos;
     1430
     1431        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
     1432                return cli_qpathinfo2(cli, fname,
     1433                                      create_time, access_time, write_time, change_time,
     1434                                      size, mode, ino);
     1435        }
     1436
     1437        if (create_time || access_time || write_time || change_time || mode) {
     1438                status = cli_qpathinfo_basic(cli, fname, &st, &attr);
     1439                if (!NT_STATUS_IS_OK(status)) {
     1440                        return status;
     1441                }
     1442        }
     1443
     1444        if (size) {
     1445                status = cli_qpathinfo_standard(cli, fname,
     1446                                                NULL, &pos, NULL, NULL, NULL);
     1447                if (!NT_STATUS_IS_OK(status)) {
     1448                        return status;
     1449                }
     1450
     1451                *size = pos;
     1452        }
     1453
     1454        if (create_time) {
     1455                *create_time = st.st_ex_btime;
     1456        }
     1457        if (access_time) {
     1458                *access_time = st.st_ex_atime;
     1459        }
     1460        if (write_time) {
     1461                *write_time = st.st_ex_mtime;
     1462        }
     1463        if (change_time) {
     1464                *change_time = st.st_ex_ctime;
     1465        }
     1466        if (mode) {
     1467                *mode = attr;
     1468        }
     1469        if (ino) {
     1470                *ino = 0;
     1471        }
     1472
     1473        return NT_STATUS_OK;
     1474}
Note: See TracChangeset for help on using the changeset viewer.