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

📄 mount.cifs.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
			if (strnlen(value, 300) < 300) {				got_unc = 1;				if (strncmp(value, "//", 2) == 0) {					if(got_unc)						printf("unc name specified twice, ignoring second\n");					else						got_unc = 1;				} else if (strncmp(value, "\\\\", 2) != 0) {	                   					printf("UNC Path does not begin with // or \\\\ \n");					return 1;				} else {					if(got_unc)						printf("unc name specified twice, ignoring second\n");					else						got_unc = 1;				}			} else {				printf("CIFS: UNC name too long\n");				return 1;			}		} else if ((strncmp(data, "domain", 3) == 0)			   || (strncmp(data, "workgroup", 5) == 0)) {			if (!value || !*value) {				printf("CIFS: invalid domain name\n");				return 1;	/* needs_arg; */			}			if (strnlen(value, 65) < 65) {				got_domain = 1;			} else {				printf("domain name too long\n");				return 1;			}		} else if (strncmp(data, "cred", 4) == 0) {			if (value && *value) {				rc = open_cred_file(value);				if(rc) {					printf("error %d opening credential file %s\n",rc, value);					return 1;				}			} else {				printf("invalid credential file name specified\n");				return 1;			}		} else if (strncmp(data, "uid", 3) == 0) {			if (value && *value) {				got_uid = 1;				if (!isdigit(*value)) {					struct passwd *pw;					static char temp[32];					if (!(pw = getpwnam(value))) {						printf("bad user name \"%s\"\n", value);						exit(1);					}					sprintf(temp, "%u", pw->pw_uid);					value = temp;					endpwent();				}			}		} else if (strncmp(data, "gid", 3) == 0) {			if (value && *value) {				got_gid = 1;				if (!isdigit(*value)) {					struct group *gr;					static char temp[32];					if (!(gr = getgrnam(value))) {						printf("bad group name \"%s\"\n", value);						exit(1);					}					sprintf(temp, "%u", gr->gr_gid);					value = temp;					endpwent();				}			}       /* fmask and dmask synonyms for people used to smbfs syntax */		} else if (strcmp(data, "file_mode") == 0 || strcmp(data, "fmask")==0) {			if (!value || !*value) {				printf ("Option '%s' requires a numerical argument\n", data);				return 1;			}			if (value[0] != '0') {				printf ("WARNING: '%s' not expressed in octal.\n", data);			}			if (strcmp (data, "fmask") == 0) {				printf ("WARNING: CIFS mount option 'fmask' is deprecated. Use 'file_mode' instead.\n");				data = "file_mode"; /* BB fix this */			}		} else if (strcmp(data, "dir_mode") == 0 || strcmp(data, "dmask")==0) {			if (!value || !*value) {				printf ("Option '%s' requires a numerical argument\n", data);				return 1;			}			if (value[0] != '0') {				printf ("WARNING: '%s' not expressed in octal.\n", data);			}			if (strcmp (data, "dmask") == 0) {				printf ("WARNING: CIFS mount option 'dmask' is deprecated. Use 'dir_mode' instead.\n");				data = "dir_mode";			}			/* the following eight mount options should be			stripped out from what is passed into the kernel			since these eight options are best passed as the			mount flags rather than redundantly to the kernel 			and could generate spurious warnings depending on the			level of the corresponding cifs vfs kernel code */		} else if (strncmp(data, "nosuid", 6) == 0) {			*filesys_flags |= MS_NOSUID;		} else if (strncmp(data, "suid", 4) == 0) {			*filesys_flags &= ~MS_NOSUID;		} else if (strncmp(data, "nodev", 5) == 0) {			*filesys_flags |= MS_NODEV;		} else if ((strncmp(data, "nobrl", 5) == 0) || 			   (strncmp(data, "nolock", 6) == 0)) {			*filesys_flags &= ~MS_MANDLOCK;		} else if (strncmp(data, "dev", 3) == 0) {			*filesys_flags &= ~MS_NODEV;		} else if (strncmp(data, "noexec", 6) == 0) {			*filesys_flags |= MS_NOEXEC;		} else if (strncmp(data, "exec", 4) == 0) {			*filesys_flags &= ~MS_NOEXEC;		} else if (strncmp(data, "guest", 5) == 0) {			got_password=1;                        /* remove the parm since it would otherwise be logged by kern */			goto nocopy;		} else if (strncmp(data, "ro", 2) == 0) {			*filesys_flags |= MS_RDONLY;		} else if (strncmp(data, "rw", 2) == 0) {			*filesys_flags &= ~MS_RDONLY;                } else if (strncmp(data, "remount", 7) == 0) {                        *filesys_flags |= MS_REMOUNT;		} /* else if (strnicmp(data, "port", 4) == 0) {			if (value && *value) {				vol->port =					simple_strtoul(value, &value, 0);			}		} else if (strnicmp(data, "rsize", 5) == 0) {			if (value && *value) {				vol->rsize =					simple_strtoul(value, &value, 0);			}		} else if (strnicmp(data, "wsize", 5) == 0) {			if (value && *value) {				vol->wsize =					simple_strtoul(value, &value, 0);			}		} else if (strnicmp(data, "version", 3) == 0) {		} else {			printf("CIFS: Unknown mount option %s\n",data);		} */ /* nothing to do on those four mount options above.			Just pass to kernel and ignore them here */		/* Copy (possibly modified) option to out */		word_len = strlen(data);		if (value)			word_len += 1 + strlen(value);		out = realloc(out, out_len + word_len + 2);		if (out == NULL) {			perror("malloc");			exit(1);		}		if (out_len)			out[out_len++] = ',';		if (value)			sprintf(out + out_len, "%s=%s", data, value);		else			sprintf(out + out_len, "%s", data);		out_len = strlen(out);nocopy:		data = next_keyword;	}	*optionsp = out;	return 0;}/* replace all (one or more) commas with double commas */static void check_for_comma(char ** ppasswrd){	char *new_pass_buf;	char *pass;	int i,j;	int number_of_commas = 0;	int len;	if(ppasswrd == NULL)		return;	else 		(pass = *ppasswrd);	len = strlen(pass);	for(i=0;i<len;i++)  {		if(pass[i] == ',')			number_of_commas++;	}	if(number_of_commas == 0)		return;	if(number_of_commas > 64) {		/* would otherwise overflow the mount options buffer */		printf("\nInvalid password. Password contains too many commas.\n");		return;	}	new_pass_buf = malloc(len+number_of_commas+1);	if(new_pass_buf == NULL)		return;	for(i=0,j=0;i<len;i++,j++) {		new_pass_buf[j] = pass[i];		if(pass[i] == ',') {			j++;			new_pass_buf[j] = pass[i];		}	}	new_pass_buf[len+number_of_commas] = 0;	free(*ppasswrd);	*ppasswrd = new_pass_buf;		return;}/* Usernames can not have backslash in them and we use   [BB check if usernames can have forward slash in them BB]    backslash as domain\user separator character*/static char * check_for_domain(char **ppuser){	char * original_string;	char * usernm;	char * domainnm;	int    original_len;	int    len;	int    i;	if(ppuser == NULL)		return NULL;	original_string = *ppuser;	if (original_string == NULL)		return NULL;		original_len = strlen(original_string);	usernm = strchr(*ppuser,'/');	if (usernm == NULL) {		usernm = strchr(*ppuser,'\\');		if (usernm == NULL)			return NULL;	}	if(got_domain) {		printf("Domain name specified twice. Username probably malformed\n");		return NULL;	}	usernm[0] = 0;	domainnm = *ppuser;	if (domainnm[0] != 0) {		got_domain = 1;	} else {		printf("null domain\n");	}	len = strlen(domainnm);	/* reset domainm to new buffer, and copy	domain name into it */	domainnm = malloc(len+1);	if(domainnm == NULL)		return NULL;	strcpy(domainnm,*ppuser);/*	move_string(*ppuser, usernm+1) */	len = strlen(usernm+1);	if(len >= original_len) {		/* should not happen */		return domainnm;	}	for(i=0;i<original_len;i++) {		if(i<len)			original_string[i] = usernm[i+1];		else /* stuff with commas to remove last parm */			original_string[i] = ',';	}	/* BB add check for more than one slash? 	  strchr(*ppuser,'/');	  strchr(*ppuser,'\\') 	*/		return domainnm;}/* Note that caller frees the returned buffer if necessary */static char * parse_server(char ** punc_name){	char * unc_name = *punc_name;	int length = strnlen(unc_name,1024);	char * share;	char * ipaddress_string = NULL;	struct hostent * host_entry = NULL;	struct in_addr server_ipaddr;	if(length > 1023) {		printf("mount error: UNC name too long");		return NULL;	}	if (strncasecmp("cifs://",unc_name,7) == 0)		return parse_cifs_url(unc_name+7);	if (strncasecmp("smb://",unc_name,6) == 0) {		return parse_cifs_url(unc_name+6);	}	if(length < 3) {		/* BB add code to find DFS root here */		printf("\nMounting the DFS root for domain not implemented yet");		return NULL;	} else {		if(strncmp(unc_name,"//",2) && strncmp(unc_name,"\\\\",2)) {			/* check for nfs syntax ie server:share */			share = strchr(unc_name,':');			if(share) {				free_share_name = 1;				*punc_name = malloc(length+3);				if(*punc_name == NULL) {					/* put the original string back  if 					   no memory left */					*punc_name = unc_name;					return NULL;				}									*share = '/';				strncpy((*punc_name)+2,unc_name,length);				unc_name = *punc_name;				unc_name[length+2] = 0;				goto continue_unc_parsing;			} else {				printf("mount error: improperly formatted UNC name.");				printf(" %s does not begin with \\\\ or //\n",unc_name);				return NULL;			}		} else {continue_unc_parsing:			unc_name[0] = '/';			unc_name[1] = '/';			unc_name += 2;			if ((share = strchr(unc_name, '/')) || 				(share = strchr(unc_name,'\\'))) {				*share = 0;  /* temporarily terminate the string */				share += 1;				if(got_ip == 0) {					host_entry = gethostbyname(unc_name);				}				*(share - 1) = '/'; /* put the slash back */				if(got_ip) {					if(verboseflag)						printf("ip address specified explicitly\n");					return NULL;				}				if(host_entry == NULL) {					printf("mount error: could not find target server. TCP name %s not found\n", unc_name);					return NULL;				} else {					/* BB should we pass an alternate version of the share name as Unicode */					/* BB what about ipv6? BB */					/* BB add retries with alternate servers in list */					memcpy(&server_ipaddr.s_addr, host_entry->h_addr, 4);					ipaddress_string = inet_ntoa(server_ipaddr);                                                                                     					if(ipaddress_string == NULL) {						printf("mount error: could not get valid ip address for target server\n");						return NULL;					}					return ipaddress_string; 				}			} else {				/* BB add code to find DFS root (send null path on get DFS Referral to specified server here */				printf("Mounting the DFS root for a particular server not implemented yet\n");				return NULL;			}		}	}}static struct option longopts[] = {	{ "all", 0, NULL, 'a' },	{ "help",0, NULL, 'h' },	{ "move",0, NULL, 'm' },	{ "bind",0, NULL, 'b' },	{ "read-only", 0, NULL, 'r' },	{ "ro", 0, NULL, 'r' },	{ "verbose", 0, NULL, 'v' },	{ "version", 0, NULL, 'V' },	{ "read-write", 0, NULL, 'w' },	{ "rw", 0, NULL, 'w' },	{ "options", 1, NULL, 'o' },	{ "type", 1, NULL, 't' },	{ "rsize",1, NULL, 'R' },	{ "wsize",1, NULL, 'W' },	{ "uid", 1, NULL, '1'},	{ "gid", 1, NULL, '2'},	{ "user",1,NULL,'u'},	{ "username",1,NULL,'u'},	{ "dom",1,NULL,'d'},	{ "domain",1,NULL,'d'},	{ "password",1,NULL,'p'},	{ "pass",1,NULL,'p'},	{ "credentials",1,NULL,'c'},	{ "port",1,NULL,'P'},

⌨️ 快捷键说明

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