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

📄 srv_srvsvc_nt.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
	}	for (snum = 0; snum < num_sessions; snum++) {		if ((strequal(session_list[snum].username, username) || username[0] == '\0' ) &&		    strequal(session_list[snum].remote_machine, machine)) {					if (user.uid != sec_initial_uid()) {				not_root = True;				become_root();			}			if (message_send_pid(pid_to_procid(session_list[snum].pid), MSG_SHUTDOWN, NULL, 0, False))				r_u->status = WERR_OK;			if (not_root) 				unbecome_root();		}	}	DEBUG(5,("_srv_net_sess_del: %d\n", __LINE__));done:	SAFE_FREE(session_list);	return r_u->status;}/******************************************************************* Net share enum all.********************************************************************/WERROR _srv_net_share_enum_all(pipes_struct *p, SRV_Q_NET_SHARE_ENUM *q_u, SRV_R_NET_SHARE_ENUM *r_u){	DEBUG(5,("_srv_net_share_enum: %d\n", __LINE__));	if (!pipe_access_check(p)) {		DEBUG(3, ("access denied to srv_net_share_enum_all\n"));		return WERR_ACCESS_DENIED;	}	/* Create the list of shares for the response. */	init_srv_r_net_share_enum(p, r_u,				q_u->ctr.info_level,				get_enum_hnd(&q_u->enum_hnd), True);	DEBUG(5,("_srv_net_share_enum: %d\n", __LINE__));	return r_u->status;}/******************************************************************* Net share enum.********************************************************************/WERROR _srv_net_share_enum(pipes_struct *p, SRV_Q_NET_SHARE_ENUM *q_u, SRV_R_NET_SHARE_ENUM *r_u){	DEBUG(5,("_srv_net_share_enum: %d\n", __LINE__));	if (!pipe_access_check(p)) {		DEBUG(3, ("access denied to srv_net_share_enum\n"));		return WERR_ACCESS_DENIED;	}	/* Create the list of shares for the response. */	init_srv_r_net_share_enum(p, r_u,				  q_u->ctr.info_level,				  get_enum_hnd(&q_u->enum_hnd), False);	DEBUG(5,("_srv_net_share_enum: %d\n", __LINE__));	return r_u->status;}/******************************************************************* Net share get info.********************************************************************/WERROR _srv_net_share_get_info(pipes_struct *p, SRV_Q_NET_SHARE_GET_INFO *q_u, SRV_R_NET_SHARE_GET_INFO *r_u){	fstring share_name;	DEBUG(5,("_srv_net_share_get_info: %d\n", __LINE__));	/* Create the list of shares for the response. */	unistr2_to_ascii(share_name, &q_u->uni_share_name, sizeof(share_name));	init_srv_r_net_share_get_info(p, r_u, share_name, q_u->info_level);	DEBUG(5,("_srv_net_share_get_info: %d\n", __LINE__));	return r_u->status;}/******************************************************************* Check a given DOS pathname is valid for a share.********************************************************************/char *valid_share_pathname(char *dos_pathname){	char *ptr;	/* Convert any '\' paths to '/' */	unix_format(dos_pathname);	unix_clean_name(dos_pathname);	/* NT is braindead - it wants a C: prefix to a pathname ! So strip it. */	ptr = dos_pathname;	if (strlen(dos_pathname) > 2 && ptr[1] == ':' && ptr[0] != '/')		ptr += 2;	/* Only absolute paths allowed. */	if (*ptr != '/')		return NULL;	return ptr;}/******************************************************************* Net share set info. Modify share details.********************************************************************/WERROR _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u, SRV_R_NET_SHARE_SET_INFO *r_u){	struct current_user user;	pstring command;	fstring share_name;	fstring comment;	pstring pathname;	int type;	int snum;	int ret;	char *path;	SEC_DESC *psd = NULL;	SE_PRIV se_diskop = SE_DISK_OPERATOR;	BOOL is_disk_op = False;	int max_connections = 0;	DEBUG(5,("_srv_net_share_set_info: %d\n", __LINE__));	unistr2_to_ascii(share_name, &q_u->uni_share_name, sizeof(share_name));	r_u->parm_error = 0;	if ( strequal(share_name,"IPC$") 		|| ( lp_enable_asu_support() && strequal(share_name,"ADMIN$") )		|| strequal(share_name,"global") )	{		return WERR_ACCESS_DENIED;	}	snum = find_service(share_name);	/* Does this share exist ? */	if (snum < 0)		return WERR_NET_NAME_NOT_FOUND;	/* No change to printer shares. */	if (lp_print_ok(snum))		return WERR_ACCESS_DENIED;	get_current_user(&user,p);	is_disk_op = user_has_privileges( p->pipe_user.nt_user_token, &se_diskop );		/* fail out now if you are not root and not a disk op */		if ( user.uid != sec_initial_uid() && !is_disk_op )		return WERR_ACCESS_DENIED;	switch (q_u->info_level) {	case 1:		pstrcpy(pathname, lp_pathname(snum));		unistr2_to_ascii(comment, &q_u->info.share.info2.info_2_str.uni_remark, sizeof(comment));		type = q_u->info.share.info2.info_2.type;		psd = NULL;		break;	case 2:		unistr2_to_ascii(comment, &q_u->info.share.info2.info_2_str.uni_remark, sizeof(comment));		unistr2_to_ascii(pathname, &q_u->info.share.info2.info_2_str.uni_path, sizeof(pathname));		type = q_u->info.share.info2.info_2.type;		max_connections = (q_u->info.share.info2.info_2.max_uses == 0xffffffff) ? 0 : q_u->info.share.info2.info_2.max_uses;		psd = NULL;		break;#if 0		/* not supported on set but here for completeness */	case 501:		unistr2_to_ascii(comment, &q_u->info.share.info501.info_501_str.uni_remark, sizeof(comment));		type = q_u->info.share.info501.info_501.type;		psd = NULL;		break;#endif	case 502:		unistr2_to_ascii(comment, &q_u->info.share.info502.info_502_str.uni_remark, sizeof(comment));		unistr2_to_ascii(pathname, &q_u->info.share.info502.info_502_str.uni_path, sizeof(pathname));		type = q_u->info.share.info502.info_502.type;		psd = q_u->info.share.info502.info_502_str.sd;		map_generic_share_sd_bits(psd);		break;	case 1004:		pstrcpy(pathname, lp_pathname(snum));		unistr2_to_ascii(comment, &q_u->info.share.info1004.info_1004_str.uni_remark, sizeof(comment));		type = STYPE_DISKTREE;		break;	case 1005:                /* XP re-sets the csc policy even if it wasn't changed by the		   user, so we must compare it to see if it's what is set in		   smb.conf, so that we can contine other ops like setting		   ACLs on a share */		if (((q_u->info.share.info1005.share_info_flags &		      SHARE_1005_CSC_POLICY_MASK) >>		     SHARE_1005_CSC_POLICY_SHIFT) == lp_csc_policy(snum))			return WERR_OK;		else {			DEBUG(3, ("_srv_net_share_set_info: client is trying to change csc policy from the network; must be done with smb.conf\n"));			return WERR_ACCESS_DENIED;		}	case 1006:	case 1007:		return WERR_ACCESS_DENIED;	case 1501:		pstrcpy(pathname, lp_pathname(snum));		fstrcpy(comment, lp_comment(snum));		psd = q_u->info.share.info1501.sdb->sec;		map_generic_share_sd_bits(psd);		type = STYPE_DISKTREE;		break;	default:		DEBUG(5,("_srv_net_share_set_info: unsupported switch value %d\n", q_u->info_level));		return WERR_UNKNOWN_LEVEL;	}	/* We can only modify disk shares. */	if (type != STYPE_DISKTREE)		return WERR_ACCESS_DENIED;			/* Check if the pathname is valid. */	if (!(path = valid_share_pathname( pathname )))		return WERR_OBJECT_PATH_INVALID;	/* Ensure share name, pathname and comment don't contain '"' characters. */	string_replace(share_name, '"', ' ');	string_replace(path, '"', ' ');	string_replace(comment, '"', ' ');	DEBUG(10,("_srv_net_share_set_info: change share command = %s\n",		lp_change_share_cmd() ? lp_change_share_cmd() : "NULL" ));	/* Only call modify function if something changed. */		if (strcmp(path, lp_pathname(snum)) || strcmp(comment, lp_comment(snum)) 		|| (lp_max_connections(snum) != max_connections) ) 	{		if (!lp_change_share_cmd() || !*lp_change_share_cmd()) {			DEBUG(10,("_srv_net_share_set_info: No change share command\n"));			return WERR_ACCESS_DENIED;		}		slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\" %d",				lp_change_share_cmd(), dyn_CONFIGFILE, share_name, path, comment, max_connections ); 		DEBUG(10,("_srv_net_share_set_info: Running [%s]\n", command ));						/********* BEGIN SeDiskOperatorPrivilege BLOCK *********/			if ( is_disk_op )			become_root();					if ( (ret = smbrun(command, NULL)) == 0 ) {			/* Tell everyone we updated smb.conf. */			message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL);		}				if ( is_disk_op )			unbecome_root();					/********* END SeDiskOperatorPrivilege BLOCK *********/		DEBUG(3,("_srv_net_share_set_info: Running [%s] returned (%d)\n", command, ret ));					if ( ret != 0 )			return WERR_ACCESS_DENIED;	} else {		DEBUG(10,("_srv_net_share_set_info: No change to share name (%s)\n", share_name ));	}	/* Replace SD if changed. */	if (psd) {		SEC_DESC *old_sd;		size_t sd_size;		old_sd = get_share_security(p->mem_ctx, snum, &sd_size);		if (old_sd && !sec_desc_equal(old_sd, psd)) {			if (!set_share_security(p->mem_ctx, share_name, psd))				DEBUG(0,("_srv_net_share_set_info: Failed to change security info in share %s.\n",					share_name ));		}	}				DEBUG(5,("_srv_net_share_set_info: %d\n", __LINE__));	return WERR_OK;}/******************************************************************* Net share add. Call 'add_share_command "sharename" "pathname"  "comment" "max connections = "********************************************************************/WERROR _srv_net_share_add(pipes_struct *p, SRV_Q_NET_SHARE_ADD *q_u, SRV_R_NET_SHARE_ADD *r_u){	struct current_user user;	pstring command;	fstring share_name;	fstring comment;	pstring pathname;	int type;	int snum;	int ret;	char *path;	SEC_DESC *psd = NULL;	SE_PRIV se_diskop = SE_DISK_OPERATOR;	BOOL is_disk_op;	int max_connections = 0;	DEBUG(5,("_srv_net_share_add: %d\n", __LINE__));	r_u->parm_error = 0;	get_current_user(&user,p);	is_disk_op = user_has_privileges( p->pipe_user.nt_user_token, &se_diskop );	if (user.uid != sec_initial_uid()  && !is_disk_op ) 		return WERR_ACCESS_DENIED;	if (!lp_add_share_cmd() || !*lp_add_share_cmd()) {		DEBUG(10,("_srv_net_share_add: No add share command\n"));		return WERR_ACCESS_DENIED;	}		switch (q_u->info_level) {	case 0:		/* No path. Not enough info in a level 0 to do anything. */		return WERR_ACCESS_DENIED;	case 1:		/* Not enough info in a level 1 to do anything. */		return WERR_ACCESS_DENIED;	case 2:		unistr2_to_ascii(share_name, &q_u->info.share.info2.info_2_str.uni_netname, sizeof(share_name));		unistr2_to_ascii(comment, &q_u->info.share.info2.info_2_str.uni_remark, sizeof(share_name));		unistr2_to_ascii(pathname, &q_u->info.share.info2.info_2_str.uni_path, sizeof(share_name));		max_connections = (q_u->info.share.info2.info_2.max_uses == 0xffffffff) ? 0 : q_u->info.share.info2.info_2.max_uses;		type = q_u->info.share.info2.info_2.type;		break;	case 501:		/* No path. Not enough info in a level 501 to do anything. */		return WERR_ACCESS_DENIED;	case 502:		unistr2_to_ascii(share_name, &q_u->info.share.info502.info_502_str.uni_netname, sizeof(share_name));		unistr2_to_ascii(comment, &q_u->info.share.info502.info_502_str.uni_remark, sizeof(share_name));		unistr2_to_ascii(pathname, &q_u->info.share.info502.info_502_str.uni_path, sizeof(share_name));		type = q_u->info.share.info502.info_502.type;		psd = q_u->info.share.info502.info_502_str.sd;		map_generic_share_sd_bits(psd);		break;		/* none of the following contain share names.  NetShareAdd does not have a separate parameter for the share name */ 	case 1004:	case 1005:	case 1006:	case 1007:		return WERR_ACCESS_DENIED;	case 1501:		/* DFS only level. */		return WERR_ACCESS_DENIED;	default:		DEBUG(5,("_srv_net_share_add: unsupported switch value %d\n", q_u->info_level));		return WERR_UNKNOWN_LEVEL;	}	/* check for invalid share names */	if ( !validate_net_name( share_name, INVALID_SHARENAME_CHARS, sizeof(share_name) ) ) {		DEBUG(5,("_srv_net_name_validate: Bad sharename \"%s\"\n", share_name));		return WERR_INVALID_NAME;	}	if ( strequal(share_name,"IPC$") || strequal(share_name,"global")		|| ( lp_enable_asu_support() && strequal(share_name,"ADMIN$") ) )	{		return WERR_ACCESS_DENIED;	}	snum = find_service(share_name);	/* Share already exists. */	if (snum >= 0)		return WERR_ALREADY_EXISTS;	/* We can only add disk shares. */	if (type != STYPE_DISKTREE)		return WERR_ACCESS_DENIED;			/* Check if the pathname is valid. */	if (!(path = valid_share_pathname( pathname )))		return WERR_OBJECT_PATH_INVALID;	/* Ensure share name, pathname and comment don't contain '"' characters. */	string_replace(share_name, '"', ' ');	string_replace(path, '"', ' ');	string_replace(comment, '"', ' ');	slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\" %d",			lp_add_share_cmd(), 			dyn_CONFIGFILE, 			share_name, 			path, 			comment, 			max_connections);				DEBUG(10,("_srv_net_share_add: Running [%s]\n", command ));		/********* BEGIN SeDiskOperatorPrivilege BLOCK *********/		if ( is_disk_op )		become_root();	if ( (ret = smbrun(command, NULL)) == 0 ) {		/* Tell everyone we updated smb.conf. */		message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL);	}	if ( is_disk_op )		unbecome_root();			/********* END SeDiskOperatorPrivilege BLOCK *********/	DEBUG(3,("_srv_net_share_add: Running [%s] returned (%d)\n", command, ret ));	if ( ret != 0 )		return WERR_ACCESS_DENIED;	if (psd) {		if (!set_share_security(p->mem_ctx, share_name, psd)) {			DEBUG(0,("_srv_net_share_add: Failed to add security info to share %s.\n", share_name ));		}	}	/*	 * We don't call reload_services() here, the message will	 * cause this to be done before the next packet is read	 * from the client. JRA.	 */	DEBUG(5,("_srv_net_share_add: %d\n", __LINE__));	return WERR_OK;}/******************************************************************* Net share delete. Call "delete share command" with the share name as a parameter.********************************************************************/WERROR _srv_net_share_del(pipes_struct *p, SRV_Q_NET_SHARE_DEL *q_u, SRV_R_NET_SHARE_DEL *r_u){

⌨️ 快捷键说明

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