Changeset 988 for vendor/current/source3/libsmb/clirap.c
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/libsmb/clirap.c
r871 r988 29 29 #include "libsmb/clirap.h" 30 30 #include "trans2.h" 31 #include "../libcli/smb/smbXcli_base.h" 31 32 32 33 #define PIPE_LANMAN "\\PIPE\\LANMAN" … … 67 68 */ 68 69 69 *rparam = (char *) memdup(my_rparam, num_my_rparam);70 *rparam = (char *)smb_memdup(my_rparam, num_my_rparam); 70 71 if (*rparam == NULL) { 71 72 goto fail; … … 74 75 TALLOC_FREE(my_rparam); 75 76 76 *rdata = (char *) memdup(my_rdata, num_my_rdata);77 *rdata = (char *)smb_memdup(my_rdata, num_my_rdata); 77 78 if (*rdata == NULL) { 78 79 goto fail; … … 117 118 p += 2; 118 119 strlcpy(p,user,sizeof(param)-PTR_DIFF(p,param)); 119 strupper_m(p); 120 if (!strupper_m(p)) { 121 return false; 122 } 120 123 p += 21; 121 124 p++; … … 123 126 p++; 124 127 strlcpy(p, workstation,sizeof(param)-PTR_DIFF(p,param)); 125 strupper_m(p); 128 if (!strupper_m(p)) { 129 return false; 130 } 126 131 p += 16; 127 132 SSVAL(p, 0, CLI_BUFFER_SIZE); … … 141 146 if (cli->rap_error == 0) { 142 147 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 */ 144 152 /* The cli->eff_name field used to be set here 145 153 but it wasn't used anywhere else. */ … … 158 166 ****************************************************************************/ 159 167 160 int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32 , const char *, void *), void *state)168 int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32_t, const char *, void *), void *state) 161 169 { 162 170 char *rparam = NULL; … … 265 273 ****************************************************************************/ 266 274 267 bool cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,268 void (*fn)(const char *, uint32 , const char *, void *),275 bool cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32_t stype, 276 void (*fn)(const char *, uint32_t, const char *, void *), 269 277 void *state) 270 278 { … … 277 285 int uLevel = 1; 278 286 size_t len; 279 uint32 func = RAP_NetServerEnum2;287 uint32_t func = RAP_NetServerEnum2; 280 288 char *last_entry = NULL; 281 289 int total_cnt = 0; … … 575 583 576 584 struct tevent_req *cli_qpathinfo1_send(TALLOC_CTX *mem_ctx, 577 struct event_context *ev,585 struct tevent_context *ev, 578 586 struct cli_state *cli, 579 587 const char *fname) … … 588 596 state->cli = cli; 589 597 subreq = cli_qpathinfo_send(state, ev, cli, fname, SMB_INFO_STANDARD, 590 22, cli->max_xmit);598 22, CLI_BUFFER_SIZE); 591 599 if (tevent_req_nomem(subreq, req)) { 592 600 return tevent_req_post(req, ev); … … 618 626 time_t *access_time, 619 627 time_t *write_time, 620 SMB_OFF_T*size,621 uint16 *mode)628 off_t *size, 629 uint16_t *mode) 622 630 { 623 631 struct cli_qpathinfo1_state *state = tevent_req_data( … … 638 646 639 647 if (change_time) { 640 *change_time = date_fn(state->data+0, s tate->cli->serverzone);648 *change_time = date_fn(state->data+0, smb1cli_conn_server_time_zone(state->cli->conn)); 641 649 } 642 650 if (access_time) { 643 *access_time = date_fn(state->data+4, s tate->cli->serverzone);651 *access_time = date_fn(state->data+4, smb1cli_conn_server_time_zone(state->cli->conn)); 644 652 } 645 653 if (write_time) { 646 *write_time = date_fn(state->data+8, s tate->cli->serverzone);654 *write_time = date_fn(state->data+8, smb1cli_conn_server_time_zone(state->cli->conn)); 647 655 } 648 656 if (size) { … … 660 668 time_t *access_time, 661 669 time_t *write_time, 662 SMB_OFF_T*size,663 uint16 *mode)670 off_t *size, 671 uint16_t *mode) 664 672 { 665 673 TALLOC_CTX *frame = talloc_stackframe(); 666 struct event_context *ev;674 struct tevent_context *ev; 667 675 struct tevent_req *req; 668 676 NTSTATUS status = NT_STATUS_NO_MEMORY; 669 677 670 if ( cli_has_async_calls(cli)) {678 if (smbXcli_conn_has_async_calls(cli->conn)) { 671 679 /* 672 680 * Can't use sync call while an async call is in flight … … 675 683 goto fail; 676 684 } 677 ev = event_context_init(frame);685 ev = samba_tevent_context_init(frame); 678 686 if (ev == NULL) { 679 687 goto fail; … … 702 710 time_t write_time, 703 711 time_t change_time, 704 uint16 mode)712 uint16_t mode) 705 713 { 706 714 unsigned int data_len = 0; … … 751 759 752 760 struct tevent_req *cli_qpathinfo2_send(TALLOC_CTX *mem_ctx, 753 struct event_context *ev,761 struct tevent_context *ev, 754 762 struct cli_state *cli, 755 763 const char *fname) … … 764 772 subreq = cli_qpathinfo_send(state, ev, cli, fname, 765 773 SMB_QUERY_FILE_ALL_INFO, 766 68, cli->max_xmit);774 68, CLI_BUFFER_SIZE); 767 775 if (tevent_req_nomem(subreq, req)) { 768 776 return tevent_req_post(req, ev); … … 795 803 struct timespec *write_time, 796 804 struct timespec *change_time, 797 SMB_OFF_T *size, uint16*mode,805 off_t *size, uint16_t *mode, 798 806 SMB_INO_T *ino) 799 807 { … … 835 843 struct timespec *write_time, 836 844 struct timespec *change_time, 837 SMB_OFF_T *size, uint16*mode,845 off_t *size, uint16_t *mode, 838 846 SMB_INO_T *ino) 839 847 { 840 TALLOC_CTX *frame = talloc_stackframe();841 struct event_context *ev;848 TALLOC_CTX *frame = NULL; 849 struct tevent_context *ev; 842 850 struct tevent_req *req; 843 851 NTSTATUS status = NT_STATUS_NO_MEMORY; 844 852 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)) { 846 868 /* 847 869 * Can't use sync call while an async call is in flight … … 850 872 goto fail; 851 873 } 852 ev = event_context_init(frame);874 ev = samba_tevent_context_init(frame); 853 875 if (ev == NULL) { 854 876 goto fail; … … 872 894 ****************************************************************************/ 873 895 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 879 896 struct cli_qpathinfo_streams_state { 880 897 uint32_t num_data; … … 899 916 subreq = cli_qpathinfo_send(state, ev, cli, fname, 900 917 SMB_FILE_STREAM_INFORMATION, 901 0, cli->max_xmit);918 0, CLI_BUFFER_SIZE); 902 919 if (tevent_req_nomem(subreq, req)) { 903 920 return tevent_req_post(req, ev); … … 949 966 struct stream_struct **pstreams) 950 967 { 951 TALLOC_CTX *frame = talloc_stackframe();952 struct event_context *ev;968 TALLOC_CTX *frame = NULL; 969 struct tevent_context *ev; 953 970 struct tevent_req *req; 954 971 NTSTATUS status = NT_STATUS_NO_MEMORY; 955 972 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)) { 957 984 /* 958 985 * Can't use sync call while an async call is in flight … … 961 988 goto fail; 962 989 } 963 ev = event_context_init(frame);990 ev = samba_tevent_context_init(frame); 964 991 if (ev == NULL) { 965 992 goto fail; … … 979 1006 } 980 1007 981 staticbool parse_streams_blob(TALLOC_CTX *mem_ctx, const uint8_t *rdata,1008 bool parse_streams_blob(TALLOC_CTX *mem_ctx, const uint8_t *rdata, 982 1009 size_t data_len, 983 1010 unsigned int *pnum_streams, … … 999 1026 uint8_t *tmp_buf; 1000 1027 1001 tmp = TALLOC_REALLOC_ARRAY(mem_ctx, streams,1028 tmp = talloc_realloc(mem_ctx, streams, 1002 1029 struct stream_struct, 1003 1030 num_streams+1); … … 1024 1051 */ 1025 1052 1026 tmp_buf = TALLOC_ARRAY(streams, uint8_t, nlen+2);1053 tmp_buf = talloc_array(streams, uint8_t, nlen+2); 1027 1054 if (tmp_buf == NULL) { 1028 1055 goto fail; … … 1034 1061 1035 1062 if (!convert_string_talloc(streams, CH_UTF16, CH_UNIX, tmp_buf, 1036 nlen+2, &vstr, &size , false))1063 nlen+2, &vstr, &size)) 1037 1064 { 1038 1065 TALLOC_FREE(tmp_buf); … … 1065 1092 ****************************************************************************/ 1066 1093 1067 NTSTATUS cli_qfilename(struct cli_state *cli, uint16_t fnum, char *name, 1068 size_t namelen) 1069 { 1094 NTSTATUS cli_qfilename(struct cli_state *cli, uint16_t fnum, 1095 TALLOC_CTX *mem_ctx, char **_name) 1096 { 1097 uint16_t recv_flags2; 1070 1098 uint8_t *rdata; 1071 1099 uint32_t num_rdata; 1072 1100 NTSTATUS status; 1101 char *name = NULL; 1102 uint32_t namelen; 1073 1103 1074 1104 status = cli_qfileinfo(talloc_tos(), cli, fnum, 1075 1105 SMB_QUERY_FILE_NAME_INFO, 1076 4, cli->max_xmit,1106 4, CLI_BUFFER_SIZE, &recv_flags2, 1077 1107 &rdata, &num_rdata); 1078 1108 if (!NT_STATUS_IS_OK(status)) { … … 1080 1110 } 1081 1111 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; 1084 1132 TALLOC_FREE(rdata); 1085 1133 return NT_STATUS_OK; … … 1091 1139 1092 1140 NTSTATUS cli_qfileinfo_basic(struct cli_state *cli, uint16_t fnum, 1093 uint16 *mode, SMB_OFF_T*size,1141 uint16_t *mode, off_t *size, 1094 1142 struct timespec *create_time, 1095 1143 struct timespec *access_time, … … 1102 1150 NTSTATUS status; 1103 1151 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 1104 1164 /* if its a win95 server then fail this - win95 totally screws it 1105 1165 up */ … … 1110 1170 status = cli_qfileinfo(talloc_tos(), cli, fnum, 1111 1171 SMB_QUERY_FILE_ALL_INFO, 1112 68, MIN(cli->max_xmit, 0xffff), 1172 68, CLI_BUFFER_SIZE, 1173 NULL, 1113 1174 &rdata, &num_rdata); 1114 1175 if (!NT_STATUS_IS_OK(status)) { … … 1154 1215 1155 1216 struct tevent_req *cli_qpathinfo_basic_send(TALLOC_CTX *mem_ctx, 1156 struct event_context *ev,1217 struct tevent_context *ev, 1157 1218 struct cli_state *cli, 1158 1219 const char *fname) … … 1168 1229 subreq = cli_qpathinfo_send(state, ev, cli, fname, 1169 1230 SMB_QUERY_FILE_BASIC_INFO, 1170 36, cli->max_xmit);1231 36, CLI_BUFFER_SIZE); 1171 1232 if (tevent_req_nomem(subreq, req)) { 1172 1233 return tevent_req_post(req, ev); … … 1195 1256 1196 1257 NTSTATUS cli_qpathinfo_basic_recv(struct tevent_req *req, 1197 SMB_STRUCT_STAT *sbuf, uint32 *attributes)1258 SMB_STRUCT_STAT *sbuf, uint32_t *attributes) 1198 1259 { 1199 1260 struct cli_qpathinfo_basic_state *state = tevent_req_data( … … 1205 1266 } 1206 1267 1268 sbuf->st_ex_btime = interpret_long_date((char *)state->data); 1207 1269 sbuf->st_ex_atime = interpret_long_date((char *)state->data+8); 1208 1270 sbuf->st_ex_mtime = interpret_long_date((char *)state->data+16); … … 1213 1275 1214 1276 NTSTATUS 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; 1219 1281 struct tevent_req *req; 1220 1282 NTSTATUS status = NT_STATUS_NO_MEMORY; 1221 1283 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)) { 1223 1294 /* 1224 1295 * Can't use sync call while an async call is in flight … … 1227 1298 goto fail; 1228 1299 } 1229 ev = event_context_init(frame);1300 ev = samba_tevent_context_init(frame); 1230 1301 if (ev == NULL) { 1231 1302 goto fail; … … 1257 1328 NTSTATUS status; 1258 1329 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 1259 1336 status = cli_qpathinfo(talloc_tos(), cli, fname, 1260 1337 SMB_QUERY_FILE_ALT_NAME_INFO, 1261 4, cli->max_xmit, &rdata, &num_rdata);1338 4, CLI_BUFFER_SIZE, &rdata, &num_rdata); 1262 1339 if (!NT_STATUS_IS_OK(status)) { 1263 1340 return status; … … 1272 1349 /* The returned data is a pushed string, not raw data. */ 1273 1350 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, 1275 1352 CH_UNIX, 1276 1353 rdata + 4, 1277 1354 len, 1278 1355 &converted, 1279 &converted_size, 1280 true)) { 1356 &converted_size)) { 1281 1357 return NT_STATUS_NO_MEMORY; 1282 1358 } … … 1288 1364 return NT_STATUS_OK; 1289 1365 } 1366 1367 /**************************************************************************** 1368 Send a qpathinfo SMB_QUERY_FILE_STADNDARD_INFO call. 1369 ****************************************************************************/ 1370 1371 NTSTATUS 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 */ 1418 NTSTATUS 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.