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

📄 client.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
 Make a directory.****************************************************************************/static int cmd_mkdir(void){	pstring mask;	pstring buf;	char *p=buf;  	pstrcpy(mask,cur_dir);	if (!next_token_nr(NULL,p,NULL,sizeof(buf))) {		if (!recurse)			d_printf("mkdir <dirname>\n");		return 1;	}	pstrcat(mask,p);	if (recurse) {		pstring ddir;		pstring ddir2;		*ddir2 = 0;				pstrcpy(ddir,mask);		trim_char(ddir,'.','\0');		p = strtok(ddir,"/\\");		while (p) {			pstrcat(ddir2,p);			if (!cli_chkpath(cli, ddir2)) { 				do_mkdir(ddir2);			}			pstrcat(ddir2,"\\");			p = strtok(NULL,"/\\");		}	 	} else {		do_mkdir(mask);	}		return 0;}/**************************************************************************** Show alt name.****************************************************************************/static int cmd_altname(void){	pstring name;	pstring buf;	char *p=buf;  	pstrcpy(name,cur_dir);	if (!next_token_nr(NULL,p,NULL,sizeof(buf))) {		d_printf("altname <file>\n");		return 1;	}	pstrcat(name,p);	do_altname(name);	return 0;}/**************************************************************************** Put a single file.****************************************************************************/static int do_put(char *rname, char *lname, BOOL reput){	int fnum;	XFILE *f;	SMB_OFF_T start = 0;	off_t nread = 0;	char *buf = NULL;	int maxwrite = io_bufsize;	int rc = 0;	struct timeval tp_start;	struct cli_state *targetcli;	pstring targetname;		if ( !cli_resolve_path( "", cli, rname, &targetcli, targetname ) ) {		d_printf("Failed to open %s: %s\n", rname, cli_errstr(cli));		return 1;	}		GetTimeOfDay(&tp_start);	if (reput) {		fnum = cli_open(targetcli, targetname, O_RDWR|O_CREAT, DENY_NONE);		if (fnum >= 0) {			if (!cli_qfileinfo(targetcli, fnum, NULL, &start, NULL, NULL, NULL, NULL, NULL) &&			    !cli_getattrE(targetcli, fnum, NULL, &start, NULL, NULL, NULL)) {				d_printf("getattrib: %s\n",cli_errstr(cli));				return 1;			}		}	} else {		fnum = cli_open(targetcli, targetname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE);	}  	if (fnum == -1) {		d_printf("%s opening remote file %s\n",cli_errstr(targetcli),rname);		return 1;	}	/* allow files to be piped into smbclient	   jdblair 24.jun.98	   Note that in this case this function will exit(0) rather	   than returning. */	if (!strcmp(lname, "-")) {		f = x_stdin;		/* size of file is not known */	} else {		f = x_fopen(lname,O_RDONLY, 0);		if (f && reput) {			if (x_tseek(f, start, SEEK_SET) == -1) {				d_printf("Error seeking local file\n");				return 1;			}		}	}	if (!f) {		d_printf("Error opening local file %s\n",lname);		return 1;	}  	DEBUG(1,("putting file %s as %s ",lname,		 rname));  	buf = (char *)SMB_MALLOC(maxwrite);	if (!buf) {		d_printf("ERROR: Not enough memory!\n");		return 1;	}	while (!x_feof(f)) {		int n = maxwrite;		int ret;		if ((n = readfile(buf,n,f)) < 1) {			if((n == 0) && x_feof(f))				break; /* Empty local file. */			d_printf("Error reading local file: %s\n", strerror(errno));			rc = 1;			break;		}		ret = cli_write(targetcli, fnum, 0, buf, nread + start, n);		if (n != ret) {			d_printf("Error writing file: %s\n", cli_errstr(cli));			rc = 1;			break;		} 		nread += n;	}	if (!cli_close(targetcli, fnum)) {		d_printf("%s closing remote file %s\n",cli_errstr(cli),rname);		x_fclose(f);		SAFE_FREE(buf);		return 1;	}		if (f != x_stdin) {		x_fclose(f);	}	SAFE_FREE(buf);	{		struct timeval tp_end;		int this_time;				GetTimeOfDay(&tp_end);		this_time = 			(tp_end.tv_sec - tp_start.tv_sec)*1000 +			(tp_end.tv_usec - tp_start.tv_usec)/1000;		put_total_time_ms += this_time;		put_total_size += nread;				DEBUG(1,("(%3.1f kb/s) (average %3.1f kb/s)\n",			 nread / (1.024*this_time + 1.0e-4),			 put_total_size / (1.024*put_total_time_ms)));	}	if (f == x_stdin) {		cli_cm_shutdown();		exit(0);	}		return rc;}/**************************************************************************** Put a file.****************************************************************************/static int cmd_put(void){	pstring lname;	pstring rname;	pstring buf;	char *p=buf;		pstrcpy(rname,cur_dir);	pstrcat(rname,"\\");  	if (!next_token_nr(NULL,p,NULL,sizeof(buf))) {		d_printf("put <filename>\n");		return 1;	}	pstrcpy(lname,p);  	if (next_token_nr(NULL,p,NULL,sizeof(buf)))		pstrcat(rname,p);      	else		pstrcat(rname,lname);		dos_clean_name(rname);	{		SMB_STRUCT_STAT st;		/* allow '-' to represent stdin		   jdblair, 24.jun.98 */		if (!file_exist(lname,&st) &&		    (strcmp(lname,"-"))) {			d_printf("%s does not exist\n",lname);			return 1;		}	}	return do_put(rname, lname, False);}/************************************* File list structure.*************************************/static struct file_list {	struct file_list *prev, *next;	char *file_path;	BOOL isdir;} *file_list;/**************************************************************************** Free a file_list structure.****************************************************************************/static void free_file_list (struct file_list * list){	struct file_list *tmp;		while (list) {		tmp = list;		DLIST_REMOVE(list, list);		SAFE_FREE(tmp->file_path);		SAFE_FREE(tmp);	}}/**************************************************************************** Seek in a directory/file list until you get something that doesn't start with the specified name.****************************************************************************/static BOOL seek_list(struct file_list *list, char *name){	while (list) {		trim_string(list->file_path,"./","\n");		if (strncmp(list->file_path, name, strlen(name)) != 0) {			return(True);		}		list = list->next;	}      	return(False);}/**************************************************************************** Set the file selection mask.****************************************************************************/static int cmd_select(void){	pstrcpy(fileselection,"");	next_token_nr(NULL,fileselection,NULL,sizeof(fileselection));	return 0;}/****************************************************************************  Recursive file matching function act as find  match must be always set to True when calling this function****************************************************************************/static int file_find(struct file_list **list, const char *directory, 		      const char *expression, BOOL match){	SMB_STRUCT_DIR *dir;	struct file_list *entry;        struct stat statbuf;        int ret;        char *path;	BOOL isdir;	const char *dname;        dir = sys_opendir(directory);	if (!dir)		return -1;	        while ((dname = readdirname(dir))) {		if (!strcmp("..", dname))			continue;		if (!strcmp(".", dname))			continue;				if (asprintf(&path, "%s/%s", directory, dname) <= 0) {			continue;		}		isdir = False;		if (!match || !gen_fnmatch(expression, dname)) {			if (recurse) {				ret = stat(path, &statbuf);				if (ret == 0) {					if (S_ISDIR(statbuf.st_mode)) {						isdir = True;						ret = file_find(list, path, expression, False);					}				} else {					d_printf("file_find: cannot stat file %s\n", path);				}								if (ret == -1) {					SAFE_FREE(path);					sys_closedir(dir);					return -1;				}			}			entry = SMB_MALLOC_P(struct file_list);			if (!entry) {				d_printf("Out of memory in file_find\n");				sys_closedir(dir);				return -1;			}			entry->file_path = path;			entry->isdir = isdir;                        DLIST_ADD(*list, entry);		} else {			SAFE_FREE(path);		}        }	sys_closedir(dir);	return 0;}/**************************************************************************** mput some files.****************************************************************************/static int cmd_mput(void){	pstring buf;	char *p=buf;		while (next_token_nr(NULL,p,NULL,sizeof(buf))) {		int ret;		struct file_list *temp_list;		char *quest, *lname, *rname;			file_list = NULL;		ret = file_find(&file_list, ".", p, True);		if (ret) {			free_file_list(file_list);			continue;		}				quest = NULL;		lname = NULL;		rname = NULL;						for (temp_list = file_list; temp_list; 		     temp_list = temp_list->next) {			SAFE_FREE(lname);			if (asprintf(&lname, "%s/", temp_list->file_path) <= 0)				continue;			trim_string(lname, "./", "/");						/* check if it's a directory */			if (temp_list->isdir) {				/* if (!recurse) continue; */								SAFE_FREE(quest);				if (asprintf(&quest, "Put directory %s? ", lname) < 0) break;				if (prompt && !yesno(quest)) { /* No */					/* Skip the directory */					lname[strlen(lname)-1] = '/';					if (!seek_list(temp_list, lname))						break;		    				} else { /* Yes */	      				SAFE_FREE(rname);					if(asprintf(&rname, "%s%s", cur_dir, lname) < 0) break;					dos_format(rname);					if (!cli_chkpath(cli, rname) && 					    !do_mkdir(rname)) {						DEBUG (0, ("Unable to make dir, skipping..."));						/* Skip the directory */						lname[strlen(lname)-1] = '/';						if (!seek_list(temp_list, lname))							break;					}				}				continue;			} else {				SAFE_FREE(quest);				if (asprintf(&quest,"Put file %s? ", lname) < 0) break;				if (prompt && !yesno(quest)) /* No */					continue;								/* Yes */				SAFE_FREE(rname);				if (asprintf(&rname, "%s%s", cur_dir, lname) < 0) break;			}			dos_format(rname);			do_put(rname, lname, False);		}		free_file_list(file_list);		SAFE_FREE(quest);		SAFE_FREE(lname);		SAFE_FREE(rname);	}	return 0;}/**************************************************************************** Cancel a print job.****************************************************************************/static int do_cancel(int job){	if (cli_printjob_del(cli, job)) {		d_printf("Job %d cancelled\n",job);		return 0;	} else {		d_printf("Error cancelling job %d : %s\n",job,cli_errstr(cli));		return 1;	}}/**************************************************************************** Cancel a print job.****************************************************************************/static int cmd_cancel(void){	pstring buf;	int job; 	if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {		d_printf("cancel <jobid> ...\n");		return 1;	}	do {		job = atoi(buf);		do_cancel(job);	} while (next_token_nr(NULL,buf,NULL,sizeof(buf)));		return 0;}/**************************************************************************** Print a file.****************************************************************************/static int cmd_print(void){	pstring lname;	pstring rname;	char *p;	if (!next_token_nr(NULL,lname,NULL, sizeof(lname))) {		d_printf("print <filename>\n");		return 1;	}	pstrcpy(rname,lname);	p = strrchr_m(rname,'/');	if (p) {		slprintf(rname, sizeof(rname)-1, "%s-%d", p+1, (int)sys_getpid());	}	if (strequal(lname,"-")) {		slprintf(rname, sizeof(rname)-1, "stdin-%d", (int)sys_getpid());	}	return do_put(rname, lname, False);}/**************************************************************************** Show a print queue entry.****************************************************************************/static void queue_fn(struct print_job_info *p){	d_printf("%-6d   %-9d    %s\n", (int)p->id, (int)p->size, p->name);}/**************************************************************************** Show a print queue.****************************************************************************/static int cmd_queue(void){	cli_print_queue(cli, queue_fn);		return 0;}/**************************************************************************** Delete some files.****************************************************************************/static void do_del(file_info *finfo){	pstring mask;	pstr_sprintf( mask, "%s\\%s", finfo->dir, finfo->name );	if (finfo->mode & aDIR) 		return;

⌨️ 快捷键说明

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