Changeset 808
- Timestamp:
- Sep 16, 2013, 7:03:21 PM (12 years ago)
- Location:
- trunk/client/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/client/src/smbwrp.c ¶
r645 r808 39 39 static int 40 40 net_share_enum_rpc(struct cli_state *cli, 41 42 43 44 45 46 { 47 41 void (*fn)(const char *name, 42 uint32 type, 43 const char *comment, 44 void *state), 45 void *state) 46 { 47 int i; 48 48 NTSTATUS status; 49 49 WERROR werr; 50 50 uint32_t resume_handle = 0; 51 52 53 51 uint32_t total_entries = 0; 52 struct srvsvc_NetShareInfoCtr info_ctr; 53 struct srvsvc_NetShareCtr1 ctr1; 54 54 fstring name = ""; 55 56 55 fstring comment = ""; 56 void *mem_ctx; 57 57 struct rpc_pipe_client *pipe_hnd; 58 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 59 /* Open the server service pipe */ 60 status = cli_rpc_pipe_open_noauth(cli, &ndr_table_srvsvc.syntax_id, &pipe_hnd); 61 if (!NT_STATUS_IS_OK(status)) { 62 DEBUG(1, ("net_share_enum_rpc pipe open fail!\n")); 63 return -1; 64 } 65 66 /* Allocate a context for parsing and for the entries in "ctr" */ 67 mem_ctx = talloc_init("libsmbclient: net_share_enum_rpc"); 68 if (mem_ctx == NULL) { 69 DEBUG(0, ("out of memory for net_share_enum_rpc!\n")); 70 TALLOC_FREE(pipe_hnd); 71 return -1; 72 } 73 74 /* Issue the NetShareEnum RPC call and retrieve the response */ 75 75 ZERO_STRUCT(info_ctr); 76 77 78 76 ZERO_STRUCT(ctr1); 77 info_ctr.level = 1; 78 info_ctr.ctr.ctr1 = &ctr1; 79 79 status = rpccli_srvsvc_NetShareEnumAll(pipe_hnd, mem_ctx, 80 81 82 83 84 85 86 87 80 pipe_hnd->desthost, 81 &info_ctr, 82 0xffffffff, 83 &total_entries, 84 &resume_handle, 85 &werr); 86 87 /* Was it successful? */ 88 88 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr) || info_ctr.ctr.ctr1->count == 0) { 89 89 /* Nope. Go clean up. */ 90 90 goto done; 91 92 93 94 95 96 97 98 99 91 } 92 93 /* For each returned entry... */ 94 for (i = 0; i < info_ctr.ctr.ctr1->count; i++) { 95 struct srvsvc_NetShareInfo1 info = info_ctr.ctr.ctr1->array[i]; 96 97 /* Add this share to the list */ 98 (*fn)(info.name, info.type, info.comment, state); 99 } 100 100 101 101 done: 102 103 104 105 106 107 108 109 102 /* Close the server service pipe */ 103 TALLOC_FREE(pipe_hnd); 104 105 /* Free all memory which was allocated for this request */ 106 TALLOC_FREE(mem_ctx); 107 108 /* Tell 'em if it worked */ 109 return W_ERROR_IS_OK(status) ? 0 : -1; 110 110 } 111 111 … … 125 125 void smbwrp_Logging() 126 126 { 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 127 char slogfile[_MAX_PATH +1] = {0}; 128 char slogfilename[] = "log.smbc"; 129 char *env = getenv("LOGFILES"); 130 if (env != NULL) 131 { 132 strncpy(slogfile, env, sizeof(slogfile) -1); 133 strncat(slogfile, "\\", sizeof(slogfile) - strlen(slogfile) -1); 134 strncat(slogfile, slogfilename, sizeof(slogfile) - strlen(slogfile) -1); 135 } 136 else 137 { 138 strncpy(slogfile, slogfilename, sizeof(slogfile) -1); 139 } 140 141 // init samba for debug messages 142 setup_logging(slogfile, false); 143 lp_set_logfile(slogfile); 144 debug_parse_levels("10"); 145 145 146 146 } 147 147 const char * smbwrp_getVersion() 148 148 { 149 149 return samba_version_string(); 150 150 } 151 151 … … 169 169 initialised = 1; 170 170 171 171 lp_set_in_client(true); /* Make sure that we tell lp_load we are client */ 172 172 173 173 load_case_tables(); … … 184 184 } 185 185 186 187 188 189 186 if (writeLog()) 187 { 188 smbwrp_Logging(); 189 } 190 190 191 191 /* … … 200 200 void smbwrp_initthread(void) 201 201 { 202 203 204 205 206 202 /* 203 * Block SIGPIPE (from lib/util_sock.c: write()) 204 * It is not needed and should not stop execution 205 */ 206 BlockSignals(True, SIGPIPE); 207 207 } 208 208 … … 313 313 uint16 setup = TRANSACT2_QPATHINFO; 314 314 char *param; 315 315 size_t nlen = 2*(strlen(fname)+1); 316 316 char *rparam=NULL, *rdata=NULL; 317 317 char *p; 318 319 320 318 319 param = SMB_MALLOC_ARRAY(char, 6+nlen+2); 320 if (!param) { 321 321 return false; 322 322 } … … 331 331 332 332 if (!cli_send_trans(cli, SMBtrans2, 333 NULL,/* name */334 -1, 0,/* fid, flags */335 &setup, 1, 0,/* setup, length, max */336 param, param_len, 10,/* param, length, max */337 338 333 NULL, /* name */ 334 -1, 0, /* fid, flags */ 335 &setup, 1, 0, /* setup, length, max */ 336 param, param_len, 10, /* param, length, max */ 337 NULL, data_len, cli->max_xmit /* data, length, max */ 338 )) { 339 339 return False; 340 340 } 341 341 342 342 SAFE_FREE(param); 343 343 if (!cli_receive_trans(cli, SMBtrans2, 344 345 344 &rparam, ¶m_len, 345 &rdata, &data_len)) { 346 346 return False; 347 347 } … … 402 402 403 403 if (!cli_send_trans(cli, SMBtrans2, 404 NULL,/* name */405 -1, 0,/* fid, flags */406 &setup, 1, 0,/* setup, length, max */407 param, param_len, 2,/* param, length, max */408 409 404 NULL, /* name */ 405 -1, 0, /* fid, flags */ 406 &setup, 1, 0, /* setup, length, max */ 407 param, param_len, 2, /* param, length, max */ 408 NULL, data_len, cli->max_xmit /* data, length, max */ 409 )) { 410 410 return False; 411 411 } 412 412 413 413 if (!cli_receive_trans(cli, SMBtrans2, 414 415 414 &rparam, ¶m_len, 415 &rdata, &data_len)) { 416 416 return False; 417 417 } … … 465 465 char* dev_type; 466 466 int loginerror = 0; 467 467 NTSTATUS status; 468 468 469 469 zero_sockaddr(&ss); … … 504 504 505 505 again: 506 506 zero_sockaddr(&ss); 507 507 508 508 /* have to open a new connection */ … … 556 556 return 6; 557 557 } 558 558 debuglocal(4,"Anonymous login successful\n"); 559 559 status = cli_init_creds(c, "", lp_workgroup(), ""); 560 560 } else { … … 634 634 return os2cli_errno(cli); 635 635 } 636 file->fd = fd; 637 if (file->openmode & (O_WRONLY | O_RDWR | O_TRUNC | O_CREAT)) 638 { 639 time_t t; 640 file->mtime = time(NULL); 641 #if 0 // as time() delivers elapsed time in epoch we already have UTC 642 t = get_time_zone(file->mtime); 643 debuglocal(4,"cli_open mtime %lu %lu\n", file->mtime, t); 644 file->mtime -= t; 645 #endif 646 debuglocal(4,"cli_open new mtime %lu\n", file->mtime); 647 } 636 file->fd = fd; 637 file->newmtime = 0; 648 638 file->offset = 0; 649 639 return 0; … … 696 686 } 697 687 688 file->newmtime = 1; 698 689 file->offset += ret; 699 690 *result = ret; … … 717 708 return os2cli_errno(cli); 718 709 } 710 if (file->newmtime) 711 { 712 file->newmtime = 0; 713 file->mtime = time(NULL); 714 debuglocal(4,"cli_close new mtime %lu\n", file->mtime); 715 } 719 716 file->fd = -1; 720 717 file->offset = 0; … … 726 723 debuglocal(4,"Set attr on close failed %d\n", os2cli_errno(cli)); 727 724 //rc = os2cli_errno(cli); 728 } 725 } 726 729 727 file->openattr = 0; 730 728 file->mtime = 0; … … 743 741 uint16 setup = TRANSACT2_SETFILEINFO; 744 742 char param[6]; 745 743 unsigned char data[8]; 746 744 char *rparam=NULL, *rdata=NULL; 747 745 748 746 SSVAL(param,0,fnum); 749 747 SSVAL(param,2,SMB_SET_FILE_END_OF_FILE_INFO); 750 751 752 748 SSVAL(param,4,0); 749 750 SBVAL(data, 0, newsize); 753 751 754 752 if (!cli_send_trans(cli, SMBtrans2, 755 NULL, 756 -1, 0, 757 &setup, 1, 0, 758 param, param_len, 2, 759 (char *)&data, data_len, 760 753 NULL, /* name */ 754 -1, 0, /* fid, flags */ 755 &setup, 1, 0, /* setup, length, max */ 756 param, param_len, 2, /* param, length, max */ 757 (char *)&data, data_len, /* data, length */ 758 cli->max_xmit /* max */ 761 759 )) { 762 760 return False; … … 795 793 return os2cli_errno(cli); 796 794 } 797 795 uint16_t fd = 0; 798 796 file->fd = -1; 799 797 file->offset = 0; … … 805 803 return os2cli_errno(cli); 806 804 } 807 805 file->fd = fd; 808 806 } 809 807 return 0; … … 842 840 843 841 debuglocal(4,"Setting on <%s> attr %04x, time %lu (timezone /%lu\n", finfo->fname, finfo->attr, finfo->mtime, finfo->mtime + get_time_zone(finfo->mtime)); 844 842 // we already have gmt time, so no need to add timezone 845 843 // if (!cli_setatr(cli, finfo->fname, finfo->attr, finfo->mtime + (finfo->mtime == 0 ? 0 : get_time_zone(finfo->mtime))) 846 844 if (!NT_STATUS_IS_OK(cli_setatr(cli, finfo->fname, finfo->attr, finfo->mtime)) … … 952 950 //debuglocal(2,("getattr rc1 %d\n", os2cli_errno(cli))); 953 951 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 952 if (cli->fd == -1) 953 { 954 /* fd == -1 means the connection is broken */ 955 return maperror(ENOTCONN); 956 } 957 958 /* If the path is not on a share (it is a workgroup or a server), 959 * then cli_qpathinfo3 obviously fails. Return some fake information 960 * about the directory. 961 */ 962 if ( *srv->server_name == 0 963 || (strcmp(cli->dev,"IPC") == 0) 964 || *srv->share_name == 0 965 || (stricmp(srv->share_name,"IPC$") == 0) 966 || (strncmp(cli->dev,"LPT",3) == 0) 969 967 ) 970 968 { 971 972 973 974 975 976 977 978 979 969 debuglocal(4,"getattr not a share.\n"); 970 *(time_t *)&finfo->ctime = time (NULL); 971 *(time_t *)&finfo->atime = time (NULL); 972 *(time_t *)&finfo->mtime = time (NULL); 973 finfo->size = 0; 974 finfo->easize = 0; 975 finfo->attr = aDIR; 976 return 0; 977 } 980 978 981 979 /* if this is NT then don't bother with the getatr */ … … 1045 1043 1046 1044 // =============================DIRECTORY ROUTINES============================ 1047 1045 1048 1046 /***************************************************** 1049 1047 add a entry to a directory listing … … 1129 1127 const char *base = p; 1130 1128 size_t ret; 1131 1129 char *fname; 1132 1130 1133 1131 data_blob_free(p_last_name_raw); … … 1138 1136 1139 1137 /* ZERO_STRUCTP(finfo); */ 1140 1141 1142 1143 1138 finfo->atime = 0; 1139 finfo->ctime = 0; 1140 finfo->mtime = 0; 1141 *finfo->fname = '\0'; 1144 1142 1145 1143 switch (level) { 1146 1144 case SMB_FIND_INFO_STANDARD: /* OS/2 understands this */ 1147 1145 /* these dates are converted to GMT by 1148 1146 make_unix_date */ 1149 1147 if (pdata_end - base < 27) { 1150 1148 return pdata_end - base; … … 1185 1183 p += ret; 1186 1184 finfo->easize = -1; 1187 1185 strncat(finfo->fname, fname, sizeof(finfo->fname) -1); 1188 1186 return PTR_DIFF(p, base); 1189 1187 1190 1188 case SMB_FIND_EA_SIZE: /* this is what OS/2 uses mostly */ 1191 1189 /* these dates are converted to GMT by 1192 1190 make_unix_date */ 1193 1191 if (pdata_end - base < 31) { 1194 1192 return pdata_end - base; … … 1213 1211 } 1214 1212 p += ret; 1215 1213 strncat(finfo->fname, fname, sizeof(finfo->fname) -1); 1216 1214 return PTR_DIFF(p, base) + 1; 1217 1215 … … 1274 1272 return pdata_end - base; 1275 1273 } 1276 1274 strncat(finfo->fname, fname, sizeof(finfo->fname) -1); 1277 1275 1278 1276 /* To be robust in the face of unicode conversion failures … … 1330 1328 1331 1329 /* NT uses SMB_FIND_FILE_BOTH_DIRECTORY_INFO, 1332 1330 OS/2 uses SMB_FIND_EA_SIZE. Both accept SMB_FIND_INFO_STANDARD. */ 1333 1331 info_level = (cli->capabilities&CAP_NT_SMBS)? 1334 1332 SMB_FIND_FILE_BOTH_DIRECTORY_INFO : SMB_FIND_EA_SIZE; 1335 1333 1336 1334 debuglocal(4,"list_files level %d. mask <%s>\n", info_level, Mask); 1337 1335 1338 1336 mask = SMB_STRDUP(Mask); 1339 1340 1341 1342 1337 if (!mask) { 1338 TALLOC_FREE(frame); 1339 return -1; 1340 } 1343 1341 1344 1342 /* Try to get the listing from cache. */ … … 1350 1348 1351 1349 while (ff_eos == 0) { 1352 1350 size_t nlen = 2*(strlen(mask)+1); 1353 1351 1354 1352 loop_count++; … … 1358 1356 } 1359 1357 1360 1358 param = SMB_MALLOC_ARRAY(char, 12+nlen+last_name_raw.length+2); 1361 1359 if (!param) { 1362 1360 break; … … 1390 1388 } else { 1391 1389 p += clistr_push(cli, param+12, mask, 1392 1390 nlen, STR_TERMINATE); 1393 1391 } 1394 1392 } … … 1397 1395 1398 1396 if (!cli_send_trans(cli, SMBtrans2, 1399 NULL, 1400 -1, 0, 1401 &setup, 1, 0, 1397 NULL, /* Name */ 1398 -1, 0, /* fid, flags */ 1399 &setup, 1, 0, /* setup, length, max */ 1402 1400 param, param_len, 10, /* param, length, max */ 1403 1401 NULL, 0, … … 1409 1407 #endif 1410 1408 )) { 1411 1412 1409 SAFE_FREE(param); 1410 TALLOC_FREE(frame); 1413 1411 break; 1414 1412 } 1415 1413 1416 1414 SAFE_FREE(param); 1417 1415 1418 1416 if (!cli_receive_trans(cli, SMBtrans2, 1419 1417 &rparam, ¶m_len, 1420 1418 &rdata, &data_len) && 1421 1419 cli_is_dos_error(cli)) { 1422 1420 /* we need to work around a Win95 bug - sometimes 1423 1421 it gives ERRSRV/ERRerror temprarily */ … … 1449 1447 } 1450 1448 1451 1449 if (cli_is_error(cli) || !rdata || !rparam) 1452 1450 { 1453 1451 if (First && info_level == SMB_FIND_EA_SIZE) … … 1486 1484 /* point to the data bytes */ 1487 1485 p = rdata; 1488 1486 rdata_end = rdata + data_len; 1489 1487 1490 1488 memset(&finfo, 0, sizeof(finfo)); … … 1493 1491 for (p2=p,i=0;i<ff_searchcount && p2 < rdata_end;i++) { 1494 1492 if ((info_level == SMB_FIND_FILE_BOTH_DIRECTORY_INFO) && 1495 1493 (i == ff_searchcount-1)) { 1496 1494 /* Last entry - fixup the last offset length. */ 1497 1495 SIVAL(p2,0,PTR_DIFF((rdata + data_len),p2)); … … 1500 1498 &resume_key, &last_name_raw); 1501 1499 1502 1500 if (!finfo.fname) { 1503 1501 debuglocal(0,"Error: unable to parse name from info level %d\n", 1504 1502 info_level); 1505 1503 ff_eos = 1; 1506 1504 break; 1507 1505 } 1508 1506 1509 1507 if (!First && *mask && strcsequal(finfo.fname, mask)) { … … 1515 1513 } 1516 1514 1517 1515 SAFE_FREE(mask); 1518 1516 if (ff_searchcount > 0 && ff_eos == 0 && finfo.fname) { 1519 1517 mask = SMB_STRDUP(finfo.fname); … … 1521 1519 mask = SMB_STRDUP(""); 1522 1520 } 1523 1521 if (!mask) { 1524 1522 SAFE_FREE(rdata); 1525 1523 SAFE_FREE(rparam); … … 1555 1553 } 1556 1554 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1555 /* see if the server disconnected or the connection otherwise failed */ 1556 if (cli_is_error(cli)) { 1557 total_received = -1; 1558 } else { 1559 void *dircachectx = dircache_write_begin(state, total_received); 1560 1561 /* no connection problem. let user function add each entry */ 1562 rdata_end = dirlist + dirlist_len; 1563 for (p=dirlist,i=0;i<total_received;i++) { 1564 p += _os2_interpret_long_filename(frame, cli, info_level, p, rdata_end, 1565 &finfo,NULL,NULL); 1568 1566 1569 1567 if (!finfo.fname) { … … 1571 1569 info_level); 1572 1570 break; 1573 1574 1575 1576 1577 1578 1571 } 1572 fn(cli->dfs_mountpoint,&finfo, Mask, state ); 1573 1574 /* Also add the entry to the cache. */ 1575 dircache_write_entry(dircachectx, &finfo); 1576 } 1579 1577 1580 1578 dircache_write_end(dircachectx); 1581 1579 1582 1580 } 1583 1581 1584 1582 /* free up the dirlist buffer and last name raw blob */ 1585 1583 SAFE_FREE(dirlist); 1586 1587 1588 1584 data_blob_free(&last_name_raw); 1585 SAFE_FREE(mask); 1586 TALLOC_FREE(frame); 1589 1587 return(total_received); 1590 1588 } … … 1621 1619 smbwrp_special_add("..", state); 1622 1620 1623 1624 1621 if (net_share_enum_rpc(cli, smbwrp_share_add, state) < 0 && 1622 cli_RNetShareEnum(cli,smbwrp_share_add, state) < 0) 1625 1623 { 1626 1624 return os2cli_errno(cli); … … 1651 1649 smbwrp_dir_add, state) < 0) 1652 1650 #endif 1653 { 1651 { 1654 1652 return os2cli_errno(cli); 1655 1653 } 1656 } 1654 } 1657 1655 1658 1656 return 0; … … 1753 1751 1754 1752 #pragma pack(1) 1755 typedef struct _FEA 1756 { 1757 unsigned char fEA; /* flags*/1758 unsigned char cbName;/* name length not including NULL */1759 1753 typedef struct _FEA /* fea */ 1754 { 1755 unsigned char fEA; /* flags */ 1756 unsigned char cbName; /* name length not including NULL */ 1757 unsigned short cbValue; /* value length */ 1760 1758 } FEA; 1761 1759 … … 1763 1761 { 1764 1762 unsigned long cbList; /* total bytes of structure including full list */ 1765 FEA list[1]; 1763 FEA list[1]; /* variable length FEA structures */ 1766 1764 } FEALIST; 1767 1765 #pragma pack() -
TabularUnified trunk/client/src/smbwrp.h ¶
r521 r808 91 91 int denymode; 92 92 unsigned long mtime; 93 int newmtime; 93 94 char fullname[261]; 94 95 char fname[261];
Note:
See TracChangeset
for help on using the changeset viewer.