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

📄 net_rpc_printer.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/*    Samba Unix/Linux SMB client library    Distributed SMB/CIFS Server Management Utility    Copyright (C) 2004 Guenther Deschner (gd@samba.org)   This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2 of the License, or   (at your option) any later version.      This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.      You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */ #include "includes.h"#include "utils/net.h"struct table_node {	const char *long_archi;	const char *short_archi;	int version;};/* support itanium as well */static const struct table_node archi_table[]= {	{"Windows 4.0",          "WIN40",	0 },	{"Windows NT x86",       "W32X86",	2 },	{"Windows NT x86",       "W32X86",	3 },	{"Windows NT R4000",     "W32MIPS",	2 },	{"Windows NT Alpha_AXP", "W32ALPHA",	2 },	{"Windows NT PowerPC",   "W32PPC",	2 },	{"Windows IA64",         "IA64",	3 },	{"Windows x64",          "x64",		3 },	{NULL,                   "",		-1 }};/** * The display-functions for Security-Descriptors were taken from rpcclient *  * They reside here for debugging purpose and should  * possibly be removed later on * **//**************************************************************************** Convert a security permissions into a string.****************************************************************************/char *get_sec_mask_str(uint32 type){	static fstring typestr="";	typestr[0] = 0;	if (type & GENERIC_ALL_ACCESS)		fstrcat(typestr, "Generic all access ");	if (type & GENERIC_EXECUTE_ACCESS)		fstrcat(typestr, "Generic execute access ");	if (type & GENERIC_WRITE_ACCESS)		fstrcat(typestr, "Generic write access ");	if (type & GENERIC_READ_ACCESS)		fstrcat(typestr, "Generic read access ");	if (type & MAXIMUM_ALLOWED_ACCESS)		fstrcat(typestr, "MAXIMUM_ALLOWED_ACCESS ");	if (type & SYSTEM_SECURITY_ACCESS)		fstrcat(typestr, "SYSTEM_SECURITY_ACCESS ");	if (type & SYNCHRONIZE_ACCESS)		fstrcat(typestr, "SYNCHRONIZE_ACCESS ");	if (type & WRITE_OWNER_ACCESS)		fstrcat(typestr, "WRITE_OWNER_ACCESS ");	if (type & WRITE_DAC_ACCESS)		fstrcat(typestr, "WRITE_DAC_ACCESS ");	if (type & READ_CONTROL_ACCESS)		fstrcat(typestr, "READ_CONTROL_ACCESS ");	if (type & DELETE_ACCESS)		fstrcat(typestr, "DELETE_ACCESS ");	printf("\t\tSpecific bits: 0x%lx\n", (unsigned long)type&SPECIFIC_RIGHTS_MASK);	return typestr;}/**************************************************************************** Display sec_ace structure. ****************************************************************************/void display_sec_ace(SEC_ACE *ace){	fstring sid_str;	printf("\tACE\n\t\ttype: ");	switch (ace->type) {		case SEC_ACE_TYPE_ACCESS_ALLOWED:			printf("ACCESS ALLOWED");			break;		case SEC_ACE_TYPE_ACCESS_DENIED:			printf("ACCESS DENIED");			break;		case SEC_ACE_TYPE_SYSTEM_AUDIT:			printf("SYSTEM AUDIT");			break;		case SEC_ACE_TYPE_SYSTEM_ALARM:			printf("SYSTEM ALARM");			break;		default:			printf("????");			break;	}	printf(" (%d) flags: %d\n", ace->type, ace->flags);	printf("\t\tPermissions: 0x%x: %s\n", ace->info.mask, get_sec_mask_str(ace->info.mask));	sid_to_string(sid_str, &ace->trustee);	printf("\t\tSID: %s\n\n", sid_str);}/**************************************************************************** Display sec_acl structure. ****************************************************************************/void display_sec_acl(SEC_ACL *sec_acl){	int i;	printf("\tACL\tNum ACEs:\t%d\trevision:\t%x\n",			 sec_acl->num_aces, sec_acl->revision); 	printf("\t---\n");	if (sec_acl->size != 0 && sec_acl->num_aces != 0)		for (i = 0; i < sec_acl->num_aces; i++)			display_sec_ace(&sec_acl->ace[i]);				}/**************************************************************************** Display sec_desc structure. ****************************************************************************/void display_sec_desc(SEC_DESC *sec){	fstring sid_str;	if (sec == NULL)		return;	if (sec->sacl) {		printf("SACL\n");		display_sec_acl(sec->sacl);	}	if (sec->dacl) {		printf("DACL\n");		display_sec_acl(sec->dacl);	}	if (sec->owner_sid) {		sid_to_string(sid_str, sec->owner_sid);		printf("\tOwner SID:\t%s\n", sid_str);	}	if (sec->grp_sid) {		sid_to_string(sid_str, sec->grp_sid);		printf("\tParent SID:\t%s\n", sid_str);	}}/** * This display-printdriver-functions was borrowed from rpcclient/cmd_spoolss.c. * It is here for debugging purpose and should be removed later on. **//**************************************************************************** Printer info level 3 display function.****************************************************************************/static void display_print_driver_3(DRIVER_INFO_3 *i1){	fstring name = "";	fstring architecture = "";	fstring driverpath = "";	fstring datafile = "";	fstring configfile = "";	fstring helpfile = "";	fstring dependentfiles = "";	fstring monitorname = "";	fstring defaultdatatype = "";		int length=0;	BOOL valid = True;		if (i1 == NULL)		return;	rpcstr_pull(name, i1->name.buffer, sizeof(name), -1, STR_TERMINATE);	rpcstr_pull(architecture, i1->architecture.buffer, sizeof(architecture), -1, STR_TERMINATE);	rpcstr_pull(driverpath, i1->driverpath.buffer, sizeof(driverpath), -1, STR_TERMINATE);	rpcstr_pull(datafile, i1->datafile.buffer, sizeof(datafile), -1, STR_TERMINATE);	rpcstr_pull(configfile, i1->configfile.buffer, sizeof(configfile), -1, STR_TERMINATE);	rpcstr_pull(helpfile, i1->helpfile.buffer, sizeof(helpfile), -1, STR_TERMINATE);	rpcstr_pull(monitorname, i1->monitorname.buffer, sizeof(monitorname), -1, STR_TERMINATE);	rpcstr_pull(defaultdatatype, i1->defaultdatatype.buffer, sizeof(defaultdatatype), -1, STR_TERMINATE);	d_printf ("Printer Driver Info 3:\n");	d_printf ("\tVersion: [%x]\n", i1->version);	d_printf ("\tDriver Name: [%s]\n",name);	d_printf ("\tArchitecture: [%s]\n", architecture);	d_printf ("\tDriver Path: [%s]\n", driverpath);	d_printf ("\tDatafile: [%s]\n", datafile);	d_printf ("\tConfigfile: [%s]\n", configfile);	d_printf ("\tHelpfile: [%s]\n\n", helpfile);	while (valid) {		rpcstr_pull(dependentfiles, i1->dependentfiles+length, sizeof(dependentfiles), -1, STR_TERMINATE);				length+=strlen(dependentfiles)+1;				if (strlen(dependentfiles) > 0) {			d_printf ("\tDependentfiles: [%s]\n", dependentfiles);		} else {			valid = False;		}	}		printf ("\n");	d_printf ("\tMonitorname: [%s]\n", monitorname);	d_printf ("\tDefaultdatatype: [%s]\n\n", defaultdatatype);	return;	}static void display_reg_value(const char *subkey, REGISTRY_VALUE value){	pstring text;	switch(value.type) {	case REG_DWORD:		d_printf("\t[%s:%s]: REG_DWORD: 0x%08x\n", subkey, value.valuename, 		       *((uint32 *) value.data_p));		break;	case REG_SZ:		rpcstr_pull(text, value.data_p, sizeof(text), value.size,			    STR_TERMINATE);		d_printf("\t[%s:%s]: REG_SZ: %s\n", subkey, value.valuename, text);		break;	case REG_BINARY: 		d_printf("\t[%s:%s]: REG_BINARY: unknown length value not displayed\n", 			 subkey, value.valuename);		break;	case REG_MULTI_SZ: {		uint16 *curstr = (uint16 *) value.data_p;		uint8 *start = value.data_p;		d_printf("\t[%s:%s]: REG_MULTI_SZ:\n", subkey, value.valuename);		while ((*curstr != 0) && 		       ((uint8 *) curstr < start + value.size)) {			rpcstr_pull(text, curstr, sizeof(text), -1, 				    STR_TERMINATE);			d_printf("%s\n", text);			curstr += strlen(text) + 1;		}	}	break;	default:		d_printf("\t%s: unknown type %d\n", value.valuename, value.type);	}	}/** * Copies ACLs, DOS-attributes and timestamps from one  * file or directory from one connected share to another connected share  * * @param mem_ctx		A talloc-context * @param cli_share_src		A connected cli_state  * @param cli_share_dst		A connected cli_state  * @param src_file		The source file-name * @param dst_file		The destination file-name * @param copy_acls		Whether to copy acls * @param copy_attrs		Whether to copy DOS attributes * @param copy_timestamps	Whether to preserve timestamps * @param is_file		Whether this file is a file or a dir * * @return Normal NTSTATUS return. **/ NTSTATUS net_copy_fileattr(TALLOC_CTX *mem_ctx,		  struct cli_state *cli_share_src,		  struct cli_state *cli_share_dst, 		  const char *src_name, const char *dst_name,		  BOOL copy_acls, BOOL copy_attrs,		  BOOL copy_timestamps, BOOL is_file){	NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;	int fnum_src = 0;	int fnum_dst = 0;	SEC_DESC *sd = NULL;	uint16 attr;	time_t f_atime, f_ctime, f_mtime;	if (!copy_timestamps && !copy_acls && !copy_attrs)		return NT_STATUS_OK;	/* open file/dir on the originating server */	DEBUGADD(3,("opening %s %s on originating server\n", 		is_file?"file":"dir", src_name));	fnum_src = cli_nt_create(cli_share_src, src_name, READ_CONTROL_ACCESS);	if (fnum_src == -1) {		DEBUGADD(0,("cannot open %s %s on originating server %s\n", 			is_file?"file":"dir", src_name, cli_errstr(cli_share_src)));		nt_status = cli_nt_error(cli_share_src);		goto out;	}	if (copy_acls) {		/* get the security descriptor */		sd = cli_query_secdesc(cli_share_src, fnum_src, mem_ctx);		if (!sd) {			DEBUG(0,("failed to get security descriptor: %s\n",				cli_errstr(cli_share_src)));			nt_status = cli_nt_error(cli_share_src);			goto out;		}		if (opt_verbose && DEBUGLEVEL >= 3)			display_sec_desc(sd);	}	if (copy_attrs || copy_timestamps) {		/* get file attributes */		if (!cli_getattrE(cli_share_src, fnum_src, &attr, NULL, 				 &f_ctime, &f_atime, &f_mtime)) {			DEBUG(0,("failed to get file-attrs: %s\n", 				cli_errstr(cli_share_src)));			nt_status = cli_nt_error(cli_share_src);			goto out;		}	}	/* open the file/dir on the destination server */ 	fnum_dst = cli_nt_create(cli_share_dst, dst_name, WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS);	if (fnum_dst == -1) {		DEBUG(0,("failed to open %s on the destination server: %s: %s\n",			is_file?"file":"dir", dst_name, cli_errstr(cli_share_dst)));		nt_status = cli_nt_error(cli_share_dst);		goto out;	}	if (copy_timestamps) {		/* set timestamps */		if (!cli_setattrE(cli_share_dst, fnum_dst, f_ctime, f_atime, f_mtime)) {			DEBUG(0,("failed to set file-attrs (timestamps): %s\n",				cli_errstr(cli_share_dst)));			nt_status = cli_nt_error(cli_share_dst);			goto out;		}	}	if (copy_acls) {		/* set acls */		if (!cli_set_secdesc(cli_share_dst, fnum_dst, sd)) {			DEBUG(0,("could not set secdesc on %s: %s\n",				dst_name, cli_errstr(cli_share_dst)));			nt_status = cli_nt_error(cli_share_dst);			goto out;		}	}	if (copy_attrs) {		/* set attrs */		if (!cli_setatr(cli_share_dst, dst_name, attr, 0)) {			DEBUG(0,("failed to set file-attrs: %s\n",				cli_errstr(cli_share_dst)));			nt_status = cli_nt_error(cli_share_dst);			goto out;		}	}	/* closing files */	if (!cli_close(cli_share_src, fnum_src)) {		d_fprintf(stderr, "could not close %s on originating server: %s\n", 			is_file?"file":"dir", cli_errstr(cli_share_src));		nt_status = cli_nt_error(cli_share_src);		goto out;	}	if (!cli_close(cli_share_dst, fnum_dst)) {		d_fprintf(stderr, "could not close %s on destination server: %s\n", 			is_file?"file":"dir", cli_errstr(cli_share_dst));		nt_status = cli_nt_error(cli_share_dst);		goto out;	}	nt_status = NT_STATUS_OK;out:	/* cleaning up */	if (fnum_src)		cli_close(cli_share_src, fnum_src);	if (fnum_dst)		cli_close(cli_share_dst, fnum_dst);	return nt_status;}/** * Copy a file or directory from a connected share to another connected share  * * @param mem_ctx		A talloc-context * @param cli_share_src		A connected cli_state  * @param cli_share_dst		A connected cli_state  * @param src_file		The source file-name * @param dst_file		The destination file-name * @param copy_acls		Whether to copy acls * @param copy_attrs		Whether to copy DOS attributes * @param copy_timestamps	Whether to preserve timestamps * @param is_file		Whether this file is a file or a dir * * @return Normal NTSTATUS return. **/ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx,		       struct cli_state *cli_share_src,		       struct cli_state *cli_share_dst, 		       const char *src_name, const char *dst_name,		       BOOL copy_acls, BOOL copy_attrs,		       BOOL copy_timestamps, BOOL is_file){	NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;	int fnum_src = 0;	int fnum_dst = 0;	static int io_bufsize = 64512;	int read_size = io_bufsize;	char *data = NULL;	off_t start = 0;	off_t nread = 0;	if (!src_name || !dst_name)		goto out;	if (cli_share_src == NULL || cli_share_dst == NULL)		goto out; 			/* open on the originating server */	DEBUGADD(3,("opening %s %s on originating server\n", 		is_file ? "file":"dir", src_name));	if (is_file)		fnum_src = cli_open(cli_share_src, src_name, O_RDONLY, DENY_NONE);	else		fnum_src = cli_nt_create(cli_share_src, src_name, READ_CONTROL_ACCESS);	if (fnum_src == -1) {		DEBUGADD(0,("cannot open %s %s on originating server %s\n",			is_file ? "file":"dir",			src_name, cli_errstr(cli_share_src)));		nt_status = cli_nt_error(cli_share_src);

⌨️ 快捷键说明

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