⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientgen.c

📁 MC Linux/Unix 终端下文件管理器
💻 C
📖 第 1 页 / 共 5 页
字号:
				finfo->mode = CVAL(p,0); p += 4;				namelen = IVAL(p,0); p += 4;				p += 4; /* EA size */				p += 2; /* short name len? */				p += 24; /* short name? */	  				StrnCpy(finfo->name,p,namelen);				return(ret);			}			return(SVAL(p,0));		}		DEBUG(1,("Unknown long filename format %d\n",level));	return(SVAL(p,0));}/****************************************************************************  do a directory listing, calling fn on each file found  ****************************************************************************/int cli_list(struct cli_state *cli,const char *Mask,uint16 attribute, 	     void (*fn)(file_info *, const char *, void *), void *state){	int max_matches = 512;	/* NT uses 260, OS/2 uses 2. Both accept 1. */	int info_level = cli->protocol<PROTOCOL_NT1?1:260; 	char *p, *p2;	pstring mask;	file_info finfo;	int i;	char *dirlist = NULL;	int dirlist_len = 0;	int total_received = -1;	BOOL First = True;	int ff_resume_key = 0;	int ff_searchcount=0;	int ff_eos=0;	int ff_lastname=0;	int ff_dir_handle=0;	int loop_count = 0;	char *rparam=NULL, *rdata=NULL;	int param_len, data_len;		uint16 setup;	pstring param;		pstrcpy(mask,Mask);		while (ff_eos == 0) {		loop_count++;		if (loop_count > 200) {			DEBUG(0,("Error: Looping in FIND_NEXT??\n"));			break;		}		param_len = 12+strlen(mask)+1;		if (First) {			setup = TRANSACT2_FINDFIRST;			SSVAL(param,0,attribute); /* attribute */			SSVAL(param,2,max_matches); /* max count */			SSVAL(param,4,8+4+2);	/* resume required + close on end + continue */			SSVAL(param,6,info_level); 			SIVAL(param,8,0);			pstrcpy(param+12,mask);		} else {			setup = TRANSACT2_FINDNEXT;			SSVAL(param,0,ff_dir_handle);			SSVAL(param,2,max_matches); /* max count */			SSVAL(param,4,info_level); 			SIVAL(param,6,ff_resume_key); /* ff_resume_key */			SSVAL(param,10,8+4+2);	/* resume required + close on end + continue */			pstrcpy(param+12,mask);			DEBUG(5,("hand=0x%X resume=%d ff_lastname=%d mask=%s\n",				 ff_dir_handle,ff_resume_key,ff_lastname,mask));		}		if (!cli_send_trans(cli, SMBtrans2, 				    NULL, 0,                /* Name, length */				    -1, 0,                  /* fid, flags */				    &setup, 1, 0,           /* setup, length, max */				    param, param_len, 10,   /* param, length, max */				    NULL, 0, 				    cli->max_xmit /* data, length, max */				    )) {			break;		}		if (!cli_receive_trans(cli, SMBtrans2, 				       &rparam, &param_len,				       &rdata, &data_len)) {			/* we need to work around a Win95 bug - sometimes			   it gives ERRSRV/ERRerror temprarily */			uint8 eclass;			uint32 ecode;			cli_error(cli, &eclass, &ecode, NULL);			if (eclass != ERRSRV || ecode != ERRerror) break;			msleep(100);			continue;		}		if (total_received == -1) total_received = 0;		/* parse out some important return info */		p = rparam;		if (First) {			ff_dir_handle = SVAL(p,0);			ff_searchcount = SVAL(p,2);			ff_eos = SVAL(p,4);			ff_lastname = SVAL(p,8);		} else {			ff_searchcount = SVAL(p,0);			ff_eos = SVAL(p,2);			ff_lastname = SVAL(p,6);		}		if (ff_searchcount == 0) 			break;		/* point to the data bytes */		p = rdata;		/* we might need the lastname for continuations */		if (ff_lastname > 0) {			switch(info_level)				{				case 260:					ff_resume_key =0;					StrnCpy(mask,p+ff_lastname,						data_len-ff_lastname);					break;				case 1:					pstrcpy(mask,p + ff_lastname + 1);					ff_resume_key = 0;					break;				}		} else {			pstrcpy(mask,"");		}  		/* and add them to the dirlist pool */		dirlist = Realloc(dirlist,dirlist_len + data_len);		if (!dirlist) {			DEBUG(0,("Failed to expand dirlist\n"));			break;		}		/* put in a length for the last entry, to ensure we can chain entries 		   into the next packet */		for (p2=p,i=0;i<(ff_searchcount-1);i++)			p2 += interpret_long_filename(info_level,p2,NULL);		SSVAL(p2,0,data_len - PTR_DIFF(p2,p));		/* grab the data for later use */		memcpy(dirlist+dirlist_len,p,data_len);		dirlist_len += data_len;		total_received += ff_searchcount;		if (rdata) free(rdata); rdata = NULL;		if (rparam) free(rparam); rparam = NULL;				DEBUG(3,("received %d entries (eos=%d resume=%d)\n",			 ff_searchcount,ff_eos,ff_resume_key));		First = False;	}	for (p=dirlist,i=0;i<total_received;i++) {		p += interpret_long_filename(info_level,p,&finfo);		fn(&finfo, Mask, state);	}	/* free up the dirlist buffer */	if (dirlist) free(dirlist);	return(total_received);}/****************************************************************************Send a SamOEMChangePassword command****************************************************************************/BOOL cli_oem_change_password(struct cli_state *cli, const char *user, const char *new_password,                             const char *old_password){  char param[16+sizeof(fstring)];  char data[532];  char *p = param;  fstring upper_case_old_pw;  fstring upper_case_new_pw;  unsigned char old_pw_hash[16];  unsigned char new_pw_hash[16];  int data_len;  int param_len = 0;  char *rparam = NULL;  char *rdata = NULL;  int rprcnt, rdrcnt;  if (strlen(user) >= sizeof(fstring)-1) {    DEBUG(0,("cli_oem_change_password: user name %s is too long.\n", user));    return False;  }  SSVAL(p,0,214); /* SamOEMChangePassword command. */  p += 2;  pstrcpy(p, "zsT");  p = skip_string(p,1);  pstrcpy(p, "B516B16");  p = skip_string(p,1);  pstrcpy(p,user);  p = skip_string(p,1);  SSVAL(p,0,532);  p += 2;  param_len = PTR_DIFF(p,param);  /*   * Get the Lanman hash of the old password, we   * use this as the key to make_oem_passwd_hash().   */  memset(upper_case_old_pw, '\0', sizeof(upper_case_old_pw));  fstrcpy(upper_case_old_pw, old_password);  strupper(upper_case_old_pw);  E_P16((uchar *)upper_case_old_pw, old_pw_hash);	if (!make_oem_passwd_hash( data, new_password, old_pw_hash, False))	{		return False;	}  /*    * Now place the old password hash in the data.   */  memset(upper_case_new_pw, '\0', sizeof(upper_case_new_pw));  fstrcpy(upper_case_new_pw, new_password);  strupper(upper_case_new_pw);  E_P16((uchar *)upper_case_new_pw, new_pw_hash);  E_old_pw_hash( new_pw_hash, old_pw_hash, (uchar *)&data[516]);  data_len = 532;      if (cli_send_trans(cli,SMBtrans,                    PIPE_LANMAN,strlen(PIPE_LANMAN),      /* name, length */                    0,0,                                  /* fid, flags */                    NULL,0,0,                             /* setup, length, max */                    param,param_len,2,                    /* param, length, max */                    data,data_len,0                       /* data, length, max */                   ) == False) {    DEBUG(0,("cli_oem_change_password: Failed to send password change for user %s\n",              user ));    return False;  }  if (cli_receive_trans(cli,SMBtrans,                       &rparam, &rprcnt,                       &rdata, &rdrcnt)) {    if (rparam)      cli->rap_error = SVAL(rparam,0);  }  if (rparam)    free(rparam);  if (rdata)    free(rdata);  return (cli->rap_error == 0);}/****************************************************************************send a negprot command****************************************************************************/BOOL cli_negprot(struct cli_state *cli){	char *p;	int numprots;	int plength;	memset(cli->outbuf,'\0',smb_size);	/* setup the protocol strings */	for (plength=0,numprots=0;	     prots[numprots].name && prots[numprots].prot<=cli->protocol;	     numprots++)		plength += strlen(prots[numprots].name)+2;    	set_message(cli->outbuf,0,plength,True);	p = smb_buf(cli->outbuf);	for (numprots=0;	     prots[numprots].name && prots[numprots].prot<=cli->protocol;	     numprots++) {		*p++ = 2;		pstrcpy(p,prots[numprots].name);		p += strlen(p) + 1;	}	CVAL(cli->outbuf,smb_com) = SMBnegprot;	cli_setup_packet(cli);	CVAL(smb_buf(cli->outbuf),0) = 2;	cli_send_smb(cli);	if (!cli_receive_smb(cli))		return False;	show_msg(cli->inbuf);	if (CVAL(cli->inbuf,smb_rcls) != 0 || 	    ((int)SVAL(cli->inbuf,smb_vwv0) >= numprots)) {		return(False);	}	cli->protocol = prots[SVAL(cli->inbuf,smb_vwv0)].prot;	if (cli->protocol >= PROTOCOL_NT1) {    		/* NT protocol */		cli->sec_mode = CVAL(cli->inbuf,smb_vwv1);		cli->max_mux = SVAL(cli->inbuf, smb_vwv1+1);		cli->max_xmit = IVAL(cli->inbuf,smb_vwv3+1);		cli->sesskey = IVAL(cli->inbuf,smb_vwv7+1);		cli->serverzone = SVALS(cli->inbuf,smb_vwv15+1)*60;		/* this time arrives in real GMT */		cli->servertime = interpret_long_date(cli->inbuf+smb_vwv11+1);		memcpy(cli->cryptkey,smb_buf(cli->inbuf),8);		cli->capabilities = IVAL(cli->inbuf,smb_vwv9+1);		if (cli->capabilities & 1) {			cli->readbraw_supported = True;			cli->writebraw_supported = True;      		}	} else if (cli->protocol >= PROTOCOL_LANMAN1) {		cli->sec_mode = SVAL(cli->inbuf,smb_vwv1);		cli->max_xmit = SVAL(cli->inbuf,smb_vwv2);		cli->sesskey = IVAL(cli->inbuf,smb_vwv6);		cli->serverzone = SVALS(cli->inbuf,smb_vwv10)*60;		/* this time is converted to GMT by make_unix_date */		cli->servertime = make_unix_date(cli->inbuf+smb_vwv8);		cli->readbraw_supported = ((SVAL(cli->inbuf,smb_vwv5) & 0x1) != 0);		cli->writebraw_supported = ((SVAL(cli->inbuf,smb_vwv5) & 0x2) != 0);		memcpy(cli->cryptkey,smb_buf(cli->inbuf),8);	} else {		/* the old core protocol */		cli->sec_mode = 0;		cli->serverzone = TimeDiff(time(NULL));	}	cli->max_xmit = MIN(cli->max_xmit, CLI_BUFFER_SIZE);	return True;}/****************************************************************************  send a session request.  see rfc1002.txt 4.3 and 4.3.2****************************************************************************/BOOL cli_session_request(struct cli_state *cli,			 struct nmb_name *calling, struct nmb_name *called){	char *p;	int len = 4;	/* send a session request (RFC 1002) */	memcpy(&(cli->calling), calling, sizeof(*calling));	memcpy(&(cli->called ), called , sizeof(*called ));  	/* put in the destination name */	p = cli->outbuf+len;	name_mangle(cli->called .name, p, cli->called .name_type);	len += name_len(p);	/* and my name */	p = cli->outbuf+len;	name_mangle(cli->calling.name, p, cli->calling.name_type);	len += name_len(p);	/* setup the packet length */	_smb_setlen(cli->outbuf,len);	CVAL(cli->outbuf,0) = 0x81;#ifdef WITH_SSLretry:#endif /* WITH_SSL */	cli_send_smb(cli);	DEBUG(5,("Sent session request\n"));	if (!cli_receive_smb(cli))		return False;	if (CVAL(cli->inbuf,0) == 0x84) {		/* C. Hoch  9/14/95 Start */		/* For information, here is the response structure.		 * We do the byte-twiddling to for portability.		struct RetargetResponse{		unsigned char type;		unsigned char flags;		int16 length;		int32 ip_addr;		int16 port;		};		*/		int port = (CVAL(cli->inbuf,8)<<8)+CVAL(cli->inbuf,9);		/* SESSION RETARGET */		putip((char *)&cli->dest_ip,cli->inbuf+4);		close_sockets();		cli->fd = open_socket_out(SOCK_STREAM, &cli->dest_ip, port, LONG_CONNECT_TIMEOUT);		if (cli->fd == -1)			return False;		DEBUG(3,("Retargeted\n"));		set_socket_options(cli->fd,user_socket_options);		/* Try again */		return cli_session_request(cli, calling, called);	} /* C. Hoch 9/14/95 End */#ifdef WITH_SSL    if (CVAL(cli->inbuf,0) == 0x83 && CVAL(cli->inbuf,4) == 0x8e){ /* use ssl */        if (!sslutil_fd_is_ssl(cli->fd)){            if (sslutil_connect(cli->fd) == 0)                goto retry;        }    }#endif /* WITH_SSL */	if (CVAL(cli->inbuf,0) != 0x82) {                /* This is the wrong place to put the error... JRA. */		cli->rap_error = CVAL(cli->inbuf,0);		return False;	}	return(True);}/****************************************************************************open the client sockets****************************************************************************/BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip){	extern struct in_addr ipzero;	fstrcpy(cli->desthost, host);		if (!ip || ip_equal(*ip, ipzero)) {                if (!resolve_name( cli->desthost, &cli->dest_ip, 0x20)) {                        return False;                }		if (ip) *ip = cli->dest_ip;	} else {		cli->dest_ip = *ip;	}        if (cli -> port == 0) cli -> port = 139;  /* Set to default */	cli->fd = open_socket_out(SOCK_STREAM, &cli->dest_ip, 				  cli -> port, cli->timeout);	if (cli->fd == -1)		return False;	return True;}/****************************************************************************initialise a client structure****************************************************************************/struct cli_state *cli_initialise(struct cli_state *cli){	if (!cli) {		cli = (struct cli_state *)malloc(sizeof(*cli));		if (!cli)			return NULL;		ZERO_STRUCTP(cli);	}	if (cli->initialised) {		cli_shutdown(cli);	}	ZERO_STRUCTP(cli);	cli->port = 0;	cli->fd = -1;	cli->cnum = -1;	cli->pid = (uint16)getpid();	cli->mid = 1;	cli->vuid 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -