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

📄 substitute.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
			string_sub(p,"%M", client_name(),l);			break;		case 'R' :			string_sub(p,"%R", remote_proto,l);			break;		case 'T' :			string_sub(p,"%T", timestring(False),l);			break;		case 'a' :			string_sub(p,"%a", remote_arch,l);			break;		case 'd' :			slprintf(pidstr,sizeof(pidstr)-1, "%d",(int)sys_getpid());			string_sub(p,"%d", pidstr,l);			break;		case 'h' :			string_sub(p,"%h", myhostname(),l);			break;		case 'm' :			string_sub(p,"%m", get_remote_machine_name(),l);			break;		case 'v' :			string_sub(p,"%v", SAMBA_VERSION_STRING,l);			break;		case 'w' :			string_sub(p,"%w", lp_winbind_separator(),l);			break;		case '$' :			p += expand_env_var(p,l);			break; /* Expand environment variables */		case '\0': 			p++; 			break; /* don't run off the end of the string */					default: p+=2; 			break;		}	}}static void standard_sub_advanced(int snum, const char *user, 				  const char *connectpath, gid_t gid, 				  const char *smb_name, char *str, size_t len){	char *p, *s, *home;	for (s=str; (p=strchr_m(s, '%'));s=p) {		int l = (int)len - (int)(p-str);			if (l < 0)			l = 0;			switch (*(p+1)) {		case 'N' :			string_sub(p,"%N", automount_server(user),l);			break;		case 'H':			if ((home = get_user_home_dir(user)))				string_sub(p,"%H",home, l);			else				p += 2;			break;		case 'P': 			string_sub(p,"%P", connectpath, l); 			break;		case 'S': 			if ( snum != -1 )				string_sub(p,"%S", lp_servicename(snum), l); 			break;		case 'g': 			string_sub(p,"%g", gidtoname(gid), l); 			break;		case 'u': 			string_sub(p,"%u", user, l); 			break;						/* Patch from jkf@soton.ac.uk Left the %N (NIS			 * server name) in standard_sub_basic as it is			 * a feature for logon servers, hence uses the			 * username.  The %p (NIS server path) code is			 * here as it is used instead of the default			 * "path =" string in [homes] and so needs the			 * service name, not the username.  */		case 'p': 			if ( snum != -1 )				string_sub(p,"%p", automount_path(lp_servicename(snum)), l); 			break;		case '\0': 			p++; 			break; /* don't run off the end of the string */					default: p+=2; 			break;		}	}	standard_sub_basic(smb_name, str, len);}/**************************************************************************** Do some standard substitutions in a string. This function will return an allocated string that have to be freed.****************************************************************************/char *talloc_sub_basic(TALLOC_CTX *mem_ctx, const char *smb_name, const char *str){	char *a, *t;       	a = alloc_sub_basic(smb_name, str);	if (!a) return NULL;	t = talloc_strdup(mem_ctx, a);	SAFE_FREE(a);	return t;}char *alloc_sub_basic(const char *smb_name, const char *str){	char *b, *p, *s, *t, *r, *a_string;	fstring pidstr;	struct passwd *pass;	const char *local_machine_name = get_local_machine_name();	/* workaround to prevent a crash while lookinf at bug #687 */		if ( !str ) {		DEBUG(0,("alloc_sub_basic: NULL source string!  This should not happen\n"));		return NULL;	}		a_string = SMB_STRDUP(str);	if (a_string == NULL) {		DEBUG(0, ("alloc_sub_specified: Out of memory!\n"));		return NULL;	}		for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {		r = NULL;		b = t = a_string;				switch (*(p+1)) {		case 'U' : 			r = strdup_lower(smb_name);			if (r == NULL) goto error;			t = realloc_string_sub(t, "%U", r);			break;		case 'G' :			r = SMB_STRDUP(smb_name);			if (r == NULL) goto error;			if ((pass = Get_Pwnam(r))!=NULL) {				t = realloc_string_sub(t, "%G", gidtoname(pass->pw_gid));			} 			break;		case 'D' :			r = strdup_upper(current_user_info.domain);			if (r == NULL) goto error;			t = realloc_string_sub(t, "%D", r);			break;		case 'I' :			t = realloc_string_sub(t, "%I", client_addr());			break;		case 'L' : 			if (local_machine_name && *local_machine_name)				t = realloc_string_sub(t, "%L", local_machine_name); 			else				t = realloc_string_sub(t, "%L", global_myname()); 			break;		case 'N':			t = realloc_string_sub(t, "%N", automount_server(smb_name));			break;		case 'M' :			t = realloc_string_sub(t, "%M", client_name());			break;		case 'R' :			t = realloc_string_sub(t, "%R", remote_proto);			break;		case 'T' :			t = realloc_string_sub(t, "%T", timestring(False));			break;		case 'a' :			t = realloc_string_sub(t, "%a", remote_arch);			break;		case 'd' :			slprintf(pidstr,sizeof(pidstr)-1, "%d",(int)sys_getpid());			t = realloc_string_sub(t, "%d", pidstr);			break;		case 'h' :			t = realloc_string_sub(t, "%h", myhostname());			break;		case 'm' :			t = realloc_string_sub(t, "%m", remote_machine);			break;		case 'v' :			t = realloc_string_sub(t, "%v", SAMBA_VERSION_STRING);			break;		case 'w' :			t = realloc_string_sub(t, "%w", lp_winbind_separator());			break;		case '$' :			t = realloc_expand_env_var(t, p); /* Expand environment variables */			break;					default: 			break;		}		p++;		SAFE_FREE(r);		if (t == NULL) goto error;		a_string = t;	}	return a_string;error:	SAFE_FREE(a_string);	return NULL;}/**************************************************************************** Do some specific substitutions in a string. This function will return an allocated string that have to be freed.****************************************************************************/char *talloc_sub_specified(TALLOC_CTX *mem_ctx,			const char *input_string,			const char *username,			const char *domain,			uid_t uid,			gid_t gid){	char *a, *t;       	a = alloc_sub_specified(input_string, username, domain, uid, gid);	if (!a) return NULL;	t = talloc_strdup(mem_ctx, a);	SAFE_FREE(a);	return t;}char *alloc_sub_specified(const char *input_string,			const char *username,			const char *domain,			uid_t uid,			gid_t gid){	char *a_string, *ret_string;	char *b, *p, *s, *t;	a_string = SMB_STRDUP(input_string);	if (a_string == NULL) {		DEBUG(0, ("alloc_sub_specified: Out of memory!\n"));		return NULL;	}		for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {				b = t = a_string;				switch (*(p+1)) {		case 'U' : 			t = realloc_string_sub(t, "%U", username);			break;		case 'u' : 			t = realloc_string_sub(t, "%u", username);			break;		case 'G' :			if (gid != -1) {				t = realloc_string_sub(t, "%G", gidtoname(gid));			} else {				t = realloc_string_sub(t, "%G", "NO_GROUP");			}			break;		case 'g' :			if (gid != -1) {				t = realloc_string_sub(t, "%g", gidtoname(gid));			} else {				t = realloc_string_sub(t, "%g", "NO_GROUP");			}			break;		case 'D' :			t = realloc_string_sub(t, "%D", domain);			break;		case 'N' : 			t = realloc_string_sub(t, "%N", automount_server(username)); 			break;		default: 			break;		}		p++;		if (t == NULL) {			SAFE_FREE(a_string);			return NULL;		}		a_string = t;	}	ret_string = alloc_sub_basic(username, a_string);	SAFE_FREE(a_string);	return ret_string;}char *talloc_sub_advanced(TALLOC_CTX *mem_ctx,			int snum,			const char *user,			const char *connectpath,			gid_t gid,			const char *smb_name,			const char *str){	char *a, *t;       	a = alloc_sub_advanced(snum, user, connectpath, gid, smb_name, str);	if (!a) return NULL;	t = talloc_strdup(mem_ctx, a);	SAFE_FREE(a);	return t;}char *alloc_sub_advanced(int snum, const char *user, 				  const char *connectpath, gid_t gid, 				  const char *smb_name, const char *str){	char *a_string, *ret_string;	char *b, *p, *s, *t, *h;	a_string = SMB_STRDUP(str);	if (a_string == NULL) {		DEBUG(0, ("alloc_sub_specified: Out of memory!\n"));		return NULL;	}		for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {				b = t = a_string;				switch (*(p+1)) {		case 'N' :			t = realloc_string_sub(t, "%N", automount_server(user));			break;		case 'H':			if ((h = get_user_home_dir(user)))				t = realloc_string_sub(t, "%H", h);			break;		case 'P': 			t = realloc_string_sub(t, "%P", connectpath); 			break;		case 'S': 			t = realloc_string_sub(t, "%S", lp_servicename(snum)); 			break;		case 'g': 			t = realloc_string_sub(t, "%g", gidtoname(gid)); 			break;		case 'u': 			t = realloc_string_sub(t, "%u", user); 			break;						/* Patch from jkf@soton.ac.uk Left the %N (NIS			 * server name) in standard_sub_basic as it is			 * a feature for logon servers, hence uses the			 * username.  The %p (NIS server path) code is			 * here as it is used instead of the default			 * "path =" string in [homes] and so needs the			 * service name, not the username.  */		case 'p': 			t = realloc_string_sub(t, "%p", automount_path(lp_servicename(snum))); 			break;					default: 			break;		}		p++;		if (t == NULL) {			SAFE_FREE(a_string);			return NULL;		}		a_string = t;	}	ret_string = alloc_sub_basic(smb_name, a_string);	SAFE_FREE(a_string);	return ret_string;}/**************************************************************************** Do some standard substitutions in a string.****************************************************************************/void standard_sub_conn(connection_struct *conn, char *str, size_t len){	standard_sub_advanced(SNUM(conn), conn->user, conn->connectpath,			conn->gid, smb_user_name, str, len);}char *talloc_sub_conn(TALLOC_CTX *mem_ctx, connection_struct *conn, const char *str){	return talloc_sub_advanced(mem_ctx, SNUM(conn), conn->user,			conn->connectpath, conn->gid,			smb_user_name, str);}char *alloc_sub_conn(connection_struct *conn, const char *str){	return alloc_sub_advanced(SNUM(conn), conn->user, conn->connectpath,			conn->gid, smb_user_name, str);}/**************************************************************************** Like standard_sub but by snum.****************************************************************************/void standard_sub_snum(int snum, char *str, size_t len){	static uid_t cached_uid = -1;	static fstring cached_user;	/* calling uidtoname() on every substitute would be too expensive, so	   we cache the result here as nearly every call is for the same uid */	if (cached_uid != current_user.uid) {		fstrcpy(cached_user, uidtoname(current_user.uid));		cached_uid = current_user.uid;	}	standard_sub_advanced(snum, cached_user, "", current_user.gid,			      smb_user_name, str, len);}

⌨️ 快捷键说明

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