Changeset 929 for branches/client-3.0/src/smbwrp.c
- Timestamp:
- Jul 25, 2016, 11:19:09 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/client-3.0/src/smbwrp.c
r887 r929 24 24 #include "libsmb/libsmb.h" 25 25 #include "libsmb/clirap.h" 26 #include "param.h" 27 #include "smb/smbXcli_base.h" 26 28 #include "trans2.h" 27 29 #include "smbwrp.h" 30 #include "util.h" 28 31 29 32 /* … … 33 36 int os2cli_errno(cli_state * cli) 34 37 { 38 #if 0 // cli->fd not available in Samba 4.x 35 39 if (cli->fd == -1) 36 40 { 37 41 return maperror( ENOTCONN); 38 42 } 43 #endif 39 44 return maperror(cli_errno(cli)); 40 45 } … … 57 62 58 63 // init samba for debug messages 59 setup_logging(slogfile, false);64 setup_logging(slogfile, DEBUG_FILE); 60 65 lp_set_logfile(slogfile); 61 debug_parse_levels("10");62 63 } 66 reopen_logs(); 67 } 68 64 69 const char * smbwrp_getVersion() 65 70 { … … 80 85 char *p; 81 86 87 struct loadparm_context *lp_ctx; 88 TALLOC_CTX *frame = talloc_stackframe(); 89 82 90 if (initialised) 83 91 { … … 86 94 initialised = 1; 87 95 88 lp_set_in_client(true); /* Make sure that we tell lp_load we are client */ 89 90 load_case_tables(); 91 92 if (!lp_load(get_dyn_CONFIGFILE(),true,false,false,true)) { 93 debuglocal(0,("The initial smb.conf is missing, defaults are used!\n")); 94 } 95 96 smb_init_locale(); 97 98 if (!lp_load_client(get_dyn_CONFIGFILE())) { 99 debuglocal(0,("Can't load %s, defaults are used!\n",get_dyn_CONFIGFILE())); 100 } 96 101 load_interfaces(); 97 102 … … 219 224 /***************************************************** 220 225 return a connection to a server 226 loosely based on do_connect() from libsmb/clidfs.c 221 227 *******************************************************/ 222 228 int _System smbwrp_connect( Resource* pRes, cli_state ** cli) … … 228 234 struct nmb_name called, calling; 229 235 char *p, *server_n = server; 230 fstring group;231 struct sockaddr_storage ss;232 236 struct cli_state * c; 233 237 char* dev_type; 234 238 int loginerror = 0; 235 239 NTSTATUS status; 236 237 zero_sockaddr(&ss); 240 int max_protocol = lp__client_max_protocol(); 241 int port = 0; //NBT_SMB_PORT; 242 int name_type= 0x20; 243 int flags = 0; 244 enum protocol_types protocol; 245 const char *name = NULL; 238 246 239 247 debuglocal(1,"Connecting to \\\\%s:*********@%s:%s\\%s. Master %s:%d\n", srv->username, workgroup, server, share, srv->master, srv->ifmastergroup); 240 241 if (!*server) {242 struct sockaddr_storage sip;243 244 if (*workgroup)245 {246 if (!find_master_ip(workgroup, &sip)) {247 return 1;248 }249 fstrcpy(group, inet_ntoa(sip.sin_addr));250 server_n = group;251 } else252 if (*srv->master)253 {254 if (srv->ifmastergroup)255 {256 if (!find_master_ip(srv->master, &sip)) {257 return 11;258 }259 strncpy(srv->master, inet_ntoa(sip.sin_addr), sizeof(srv->master) - 1);260 srv->ifmastergroup = 0;261 }262 server_n = srv->master;263 } else264 {265 return 10;266 }267 }268 269 make_nmb_name(&calling, global_myname(), 0x0);270 // make_nmb_name(&calling, "WORK", 0x0); // this machine name271 make_nmb_name(&called , server_n, 0x20);272 273 again:274 zero_sockaddr(&ss);275 276 /* have to open a new connection */277 if (!(c=cli_initialise()))278 {279 return 2;280 }281 248 282 249 cli_set_timeout(c, 10000); /* 10 seconds. */ … … 288 255 } 289 256 290 if (!NT_STATUS_IS_OK(cli_connect(c, server_n, &ss))) 291 { 257 status = cli_connect_nb( 258 server, NULL, port, name_type, NULL, 259 SMB_SIGNING_DEFAULT, flags, &c); 260 261 if (!NT_STATUS_IS_OK(status)) { 262 debuglocal(4,"Connection to %s failed (Error %s)\n", 263 server, 264 nt_errstr(status)); 292 265 return 3; 293 266 } 294 267 295 if (!cli_session_request(c, &calling, &called)) { 268 if (max_protocol == PROTOCOL_DEFAULT) { 269 max_protocol = PROTOCOL_LATEST; 270 } 271 DEBUG(4,(" session request ok, c->timeout = %d\n",c->timeout)); 272 273 status = smbXcli_negprot(c->conn, c->timeout, 274 lp_client_min_protocol(), 275 max_protocol); 276 277 if (!NT_STATUS_IS_OK(status)) { 278 debuglocal(4,"protocol negotiation failed: %s\n", 279 nt_errstr(status)); 296 280 cli_shutdown(c); 297 if (strcmp(called.name, "*SMBSERVER")) { 298 make_nmb_name(&called , "*SMBSERVER", 0x20); 299 goto again; 300 } 301 return 4; 302 } 303 304 debuglocal(4," session request ok\n"); 305 306 if (!NT_STATUS_IS_OK(cli_negprot(c))) { 307 cli_shutdown(c); 308 return 5; 309 } 310 311 debuglocal(4," session setuping for <%s>/<********> in <%s> %08x %08x %08x\n", srv->username, workgroup, c->protocol, c->sec_mode, c->capabilities); 281 return status; 282 } 312 283 313 284 if (!NT_STATUS_IS_OK(cli_session_setup(c, srv->username, … … 325 296 } 326 297 debuglocal(4,"Anonymous login successful\n"); 327 status = cli_init_creds(c, "", lp_workgroup(), "");328 } else {329 status = cli_init_creds(c, srv->username, workgroup, srv->password);330 298 } 331 299 … … 359 327 } 360 328 361 debuglocal(4," tconx ok. cli caps %08x\n", c->capabilities);329 debuglocal(4," tconx ok.\n"); 362 330 363 331 // save cli_state pointer … … 419 387 return maperror(EINVAL); 420 388 } 421 389 size_t nread; 422 390 *result = 0; 423 ret = cli_read(cli, file->fd, buf, file->offset, count );391 ret = cli_read(cli, file->fd, buf, file->offset, count, &nread); 424 392 if (ret == -1) 425 393 { 394 debuglocal(4," smbwrp_read - cli_read ret = %d\n",ret); 426 395 return os2cli_errno(cli); 427 396 } 428 397 429 file->offset += ret; 430 *result = ret; 398 file->offset += nread; 399 *result = nread; 400 debuglocal(4," smbwrp_read successful, nread = %d, ret = %d\n",nread,ret); 431 401 return 0; 432 402 } … … 669 639 return maperror(EINVAL); 670 640 } 671 debuglocal(4,"getattr %d %d <%s>\n", cli->capabilities & CAP_NOPATHINFO2, cli->capabilities& CAP_NT_SMBS, finfo->fname);672 if (!(cli->capabilities & CAP_NOPATHINFO2) && 673 641 debuglocal(4,"getattr %d %d <%s>\n", smb1cli_conn_capabilities(cli->conn) & CAP_NOPATHINFO2, smb1cli_conn_capabilities(cli->conn) & CAP_NT_SMBS, finfo->fname); 642 643 if (NT_STATUS_IS_OK(cli_qpathinfo2(cli, finfo->fname, &ctime, &atime, &mtime, NULL, 674 644 (off_t *)&finfo->size, (unsigned short *)&finfo->attr, &ino))) 675 645 { … … 681 651 } 682 652 653 #if 0 // cli->fd not available in Samba 4.x 683 654 if (cli->fd == -1) 684 655 { 685 656 /* fd == -1 means the connection is broken */ 686 657 return maperror(ENOTCONN); 658 } 659 #endif 660 661 debuglocal(4, "smbwrp_getattr, calling cli_qpathinfo3\n"); 662 if (NT_STATUS_IS_OK(cli_qpathinfo3(cli, finfo->fname, &ctime, &atime, &mtime, NULL, 663 (off_t *)&finfo->size, (unsigned short *)&finfo->attr, &ino))) 664 { 665 finfo->attr &= 0x7F; 666 finfo->ctime = convert_timespec_to_time_t(ctime); 667 finfo->atime = convert_timespec_to_time_t(atime); 668 finfo->mtime = convert_timespec_to_time_t(mtime); 669 return 0; 687 670 } 688 671 … … 709 692 710 693 /* if this is NT then don't bother with the getatr */ 711 if ( cli->capabilities & CAP_NT_SMBS && !(cli->capabilities & CAP_NOPATHINFO2))694 if (smb1cli_conn_capabilities(cli->conn) & CAP_NT_SMBS/* && !(smb1cli_conn_capabilities(cli->conn) & CAP_NOPATHINFO2)*/) 712 695 { 713 696 int ret = cli_errno(cli); … … 728 711 finfo->atime = finfo->atime; //was mtime 729 712 finfo->ctime = finfo->ctime; //was mtime 730 cli->capabilities &= CAP_NOPATHINFO2;731 713 return 0; 732 714 } … … 782 764 add a entry to a directory listing 783 765 *******************************************************/ 784 static voidsmbwrp_dir_add(const char* mnt, smbwrp_fileinfo *finfo, const char *mask, void *state)766 static NTSTATUS smbwrp_dir_add(const char* mnt, smbwrp_fileinfo *finfo, const char *mask, void *state) 785 767 { 786 768 if (state && finfo) … … 814 796 } 815 797 816 static voidsmbwrp_printjob_add(struct print_job_info *job, void * state)798 static NTSTATUS smbwrp_printjob_add(struct print_job_info *job, void * state) 817 799 { 818 800 smbwrp_fileinfo finfo = {0}; … … 832 814 } 833 815 834 static void smbwrp_share_add(const char *share, uint32 type,816 static void smbwrp_share_add(const char *share, uint32_t type, 835 817 const char *comment, void *state) 836 818 { … … 852 834 Modified from cli_list 853 835 ****************************************************************************/ 854 static int list_files(struct cli_state *cli, const char *mask, uint16 attribute,836 static int list_files(struct cli_state *cli, const char *mask, uint16_t attribute, 855 837 void (*fn)(const char *, smbwrp_fileinfo *, const char *, 856 838 void *), void *state) … … 873 855 } 874 856 875 if ( cli_has_async_calls(cli)) {857 if (smbXcli_conn_has_async_calls(cli->conn)) { 876 858 /* 877 859 * Can't use sync call while an async call is in flight … … 880 862 goto fail; 881 863 } 882 ev = event_context_init(frame);864 ev = samba_tevent_context_init(frame); 883 865 if (ev == NULL) { 884 866 goto fail; 885 867 } 886 868 887 info_level = ( cli->capabilities& CAP_NT_SMBS)869 info_level = (smb1cli_conn_capabilities(cli->conn) & CAP_NT_SMBS) 888 870 ? SMB_FIND_FILE_BOTH_DIRECTORY_INFO : SMB_FIND_EA_SIZE; 889 871
Note:
See TracChangeset
for help on using the changeset viewer.