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

📄 net_rpc_printer.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
		goto out;	}	if (is_file) {		/* open file on the destination server */		DEBUGADD(3,("opening file %s on destination server\n", dst_name));		fnum_dst = cli_open(cli_share_dst, dst_name, 				O_RDWR|O_CREAT|O_TRUNC, DENY_NONE);		if (fnum_dst == -1) {			DEBUGADD(1,("cannot create file %s on destination server: %s\n", 				dst_name, cli_errstr(cli_share_dst)));			nt_status = cli_nt_error(cli_share_dst);			goto out;		}		/* allocate memory */		if (!(data = (char *)SMB_MALLOC(read_size))) {			d_fprintf(stderr, "malloc fail for size %d\n", read_size);			nt_status = NT_STATUS_NO_MEMORY;			goto out;		}	}	if (opt_verbose) {		d_printf("copying [\\\\%s\\%s%s] => [\\\\%s\\%s%s] "			 "%s ACLs and %s DOS Attributes %s\n", 			cli_share_src->desthost, cli_share_src->share, src_name,			cli_share_dst->desthost, cli_share_dst->share, dst_name,			copy_acls ?  "with" : "without", 			copy_attrs ? "with" : "without",			copy_timestamps ? "(preserving timestamps)" : "" );	}	while (is_file) {		/* copying file */		int n, ret;		n = cli_read(cli_share_src, fnum_src, data, nread + start, 				read_size);		if (n <= 0)			break;		ret = cli_write(cli_share_dst, fnum_dst, 0, data, 			nread + start, n);		if (n != ret) {			d_fprintf(stderr, "Error writing file: %s\n", 				cli_errstr(cli_share_dst));			nt_status = cli_nt_error(cli_share_dst);			goto out;		}		nread += n;	}	if (!is_file && !cli_chkpath(cli_share_dst, dst_name)) {		/* creating dir */		DEBUGADD(3,("creating dir %s on the destination server\n", 			dst_name));		if (!cli_mkdir(cli_share_dst, dst_name)) {			DEBUG(0,("cannot create directory %s: %s\n",				dst_name, cli_errstr(cli_share_dst)));			nt_status = NT_STATUS_NO_SUCH_FILE;		}		if (!cli_chkpath(cli_share_dst, dst_name)) {			d_fprintf(stderr, "cannot check for directory %s: %s\n",				dst_name, cli_errstr(cli_share_dst));			goto out;		}	}	/* closing files */	if (!cli_close(cli_share_src, fnum_src)) {		d_fprintf(stderr, "could not close file on originating server: %s\n", 			cli_errstr(cli_share_src));		nt_status = cli_nt_error(cli_share_src);		goto out;	}	if (is_file && !cli_close(cli_share_dst, fnum_dst)) {		d_fprintf(stderr, "could not close file on destination server: %s\n", 			cli_errstr(cli_share_dst));		nt_status = cli_nt_error(cli_share_dst);		goto out;	}	/* possibly we have to copy some file-attributes / acls / sd */	nt_status = net_copy_fileattr(mem_ctx, cli_share_src, cli_share_dst, 				      src_name, dst_name, copy_acls, 				      copy_attrs, copy_timestamps, is_file);	if (!NT_STATUS_IS_OK(nt_status))		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);	SAFE_FREE(data);	return nt_status;}/** * Copy a driverfile from on connected share to another connected share  * This silently assumes that a driver-file is picked up from  * *	\\src_server\print$\{arch}\{version}\file  * * and copied to * * 	\\dst_server\print$\{arch}\file  *  * to be added via setdriver-calls later. * @param mem_ctx		A talloc-context * @param cli_share_src		A cli_state connected to source print$-share * @param cli_share_dst		A cli_state connected to destination print$-share * @param file			The file-name to be copied  * @param short_archi		The name of the driver-architecture (short form) * * @return Normal NTSTATUS return. **/ static NTSTATUS net_copy_driverfile(TALLOC_CTX *mem_ctx,				    struct cli_state *cli_share_src,				    struct cli_state *cli_share_dst, 				    char *file, const char *short_archi) {	NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;	const char *p;	char *src_name;	char *dst_name;	fstring version;	fstring filename;	fstring tok;	/* scroll through the file until we have the part 	   beyond archi_table.short_archi */	p = file;	while (next_token(&p, tok, "\\", sizeof(tok))) {		if (strequal(tok, short_archi)) {			next_token(&p, version, "\\", sizeof(version));			next_token(&p, filename, "\\", sizeof(filename));		}	}	/* build source file name */	if (asprintf(&src_name, "\\%s\\%s\\%s", short_archi, version, filename) < 0 ) 		return NT_STATUS_NO_MEMORY;	/* create destination file name */	if (asprintf(&dst_name, "\\%s\\%s", short_archi, filename) < 0 )                return NT_STATUS_NO_MEMORY;	/* finally copy the file */	nt_status = net_copy_file(mem_ctx, cli_share_src, cli_share_dst, 				  src_name, dst_name, False, False, False, True);	if (!NT_STATUS_IS_OK(nt_status))		goto out;	nt_status = NT_STATUS_OK;out:	SAFE_FREE(src_name);	SAFE_FREE(dst_name);	return nt_status;}/** * Check for existing Architecture directory on a given server * * @param cli_share		A cli_state connected to a print$-share * @param short_archi		The Architecture for the print-driver * * @return Normal NTSTATUS return. **/static NTSTATUS check_arch_dir(struct cli_state *cli_share, const char *short_archi){	NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;	char *dir;	if (asprintf(&dir, "\\%s", short_archi) < 0) {		return NT_STATUS_NO_MEMORY;	}	DEBUG(10,("creating print-driver dir for architecture: %s\n", 		short_archi));	if (!cli_mkdir(cli_share, dir)) {                DEBUG(1,("cannot create directory %s: %s\n",                         dir, cli_errstr(cli_share)));                nt_status = NT_STATUS_NO_SUCH_FILE;        }	if (!cli_chkpath(cli_share, dir)) {		d_fprintf(stderr, "cannot check %s: %s\n", 			dir, cli_errstr(cli_share));		goto out;	}	nt_status = NT_STATUS_OK;out:	SAFE_FREE(dir);	return nt_status;}/** * Copy a print-driver (level 3) from one connected print$-share to another  * connected print$-share * * @param mem_ctx		A talloc-context * @param cli_share_src		A cli_state connected to a print$-share * @param cli_share_dst		A cli_state connected to a print$-share * @param short_archi		The Architecture for the print-driver * @param i1			The DRIVER_INFO_3-struct * * @return Normal NTSTATUS return. **/static NTSTATUS copy_print_driver_3(TALLOC_CTX *mem_ctx,		    struct cli_state *cli_share_src, 		    struct cli_state *cli_share_dst, 		    const char *short_archi, DRIVER_INFO_3 *i1){	NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;	int length = 0;	BOOL valid = True;		fstring name = "";	fstring driverpath = "";	fstring datafile = "";	fstring configfile = "";	fstring helpfile = "";	fstring dependentfiles = "";		if (i1 == NULL)		return nt_status;	rpcstr_pull(name, i1->name.buffer, sizeof(name), -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);	if (opt_verbose)		d_printf("copying driver: [%s], for architecture: [%s], version: [%d]\n", 			  name, short_archi, i1->version);		nt_status = net_copy_driverfile(mem_ctx, cli_share_src, cli_share_dst, 		driverpath, short_archi);	if (!NT_STATUS_IS_OK(nt_status))		return nt_status;			nt_status = net_copy_driverfile(mem_ctx, cli_share_src, cli_share_dst, 		datafile, short_archi);	if (!NT_STATUS_IS_OK(nt_status))		return nt_status;			nt_status = net_copy_driverfile(mem_ctx, cli_share_src, cli_share_dst, 		configfile, short_archi);	if (!NT_STATUS_IS_OK(nt_status))		return nt_status;			nt_status = net_copy_driverfile(mem_ctx, cli_share_src, cli_share_dst, 		helpfile, short_archi);	if (!NT_STATUS_IS_OK(nt_status))		return nt_status;	while (valid) {				rpcstr_pull(dependentfiles, i1->dependentfiles+length, sizeof(dependentfiles), -1, STR_TERMINATE);		length += strlen(dependentfiles)+1;				if (strlen(dependentfiles) > 0) {			nt_status = net_copy_driverfile(mem_ctx, 					cli_share_src, cli_share_dst, 					dependentfiles, short_archi);			if (!NT_STATUS_IS_OK(nt_status))				return nt_status;		} else {			valid = False;		}	}	return NT_STATUS_OK;}/** * net_spoolss-functions * ===================== * * the net_spoolss-functions aim to simplify spoolss-client-functions * required during the migration-process wrt buffer-sizes, returned * error-codes, etc.  * * this greatly reduces the complexitiy of the migrate-functions. * **/static BOOL net_spoolss_enum_printers(struct rpc_pipe_client *pipe_hnd,					TALLOC_CTX *mem_ctx, 					char *name,					uint32 flags,					uint32 level, 					uint32 *num_printers,					PRINTER_INFO_CTR *ctr){	WERROR result;	/* enum printers */	result = rpccli_spoolss_enum_printers(pipe_hnd, mem_ctx, name, flags,		level, num_printers, ctr);	if (!W_ERROR_IS_OK(result)) {		printf("cannot enum printers: %s\n", dos_errstr(result));		return False;	}	return True;}static BOOL net_spoolss_open_printer_ex(struct rpc_pipe_client *pipe_hnd,					TALLOC_CTX *mem_ctx,					const char *printername,					uint32 access_required, 					const char *username,					POLICY_HND *hnd){	WERROR result;	fstring servername, printername2;	slprintf(servername, sizeof(servername)-1, "\\\\%s", pipe_hnd->cli->desthost);	fstrcpy(printername2, servername);	fstrcat(printername2, "\\");	fstrcat(printername2, printername);	DEBUG(10,("connecting to: %s as %s for %s and access: %x\n", 		servername, username, printername2, access_required));	/* open printer */	result = rpccli_spoolss_open_printer_ex(pipe_hnd, mem_ctx, printername2,			"", access_required,			servername, username, hnd);	/* be more verbose */	if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) {		d_fprintf(stderr, "no access to printer [%s] on [%s] for user [%s] granted\n", 			printername2, servername, username);		return False;	}	if (!W_ERROR_IS_OK(result)) {		d_fprintf(stderr, "cannot open printer %s on server %s: %s\n", 			printername2, servername, dos_errstr(result));		return False;	}	DEBUG(2,("got printer handle for printer: %s, server: %s\n", 		printername2, servername));	return True;}static BOOL net_spoolss_getprinter(struct rpc_pipe_client *pipe_hnd,				TALLOC_CTX *mem_ctx,				POLICY_HND *hnd,				uint32 level, 				PRINTER_INFO_CTR *ctr){	WERROR result;	/* getprinter call */	result = rpccli_spoolss_getprinter(pipe_hnd, mem_ctx, hnd, level, ctr);	if (!W_ERROR_IS_OK(result)) {		printf("cannot get printer-info: %s\n", dos_errstr(result));		return False;	}	return True;}static BOOL net_spoolss_setprinter(struct rpc_pipe_client *pipe_hnd,				TALLOC_CTX *mem_ctx,				POLICY_HND *hnd,				uint32 level, 				PRINTER_INFO_CTR *ctr){	WERROR result;	/* setprinter call */	result = rpccli_spoolss_setprinter(pipe_hnd, mem_ctx, hnd, level, ctr, 0);	if (!W_ERROR_IS_OK(result)) {		printf("cannot set printer-info: %s\n", dos_errstr(result));		return False;	}	return True;}static BOOL net_spoolss_setprinterdata(struct rpc_pipe_client *pipe_hnd,					TALLOC_CTX *mem_ctx,					POLICY_HND *hnd,					REGISTRY_VALUE *value){	WERROR result;		/* setprinterdata call */	result = rpccli_spoolss_setprinterdata(pipe_hnd, mem_ctx, hnd, value);	if (!W_ERROR_IS_OK(result)) {		printf ("unable to set printerdata: %s\n", dos_errstr(result));		return False;	}	return True;}static BOOL net_spoolss_enumprinterkey(struct rpc_pipe_client *pipe_hnd,					TALLOC_CTX *mem_ctx,					POLICY_HND *hnd,					const char *keyname,					uint16 **keylist){	WERROR result;	/* enumprinterkey call */	result = rpccli_spoolss_enumprinterkey(pipe_hnd, mem_ctx, hnd, keyname, keylist, NULL);			if (!W_ERROR_IS_OK(result)) {		printf("enumprinterkey failed: %s\n", dos_errstr(result));		return False;	}		return True;}static BOOL net_spoolss_enumprinterdataex(struct rpc_pipe_client *pipe_hnd,					TALLOC_CTX *mem_ctx,					uint32 offered, 					POLICY_HND *hnd,					const char *keyname, 					REGVAL_CTR *ctr) {	WERROR result;	/* enumprinterdataex call */	result = rpccli_spoolss_enumprinterdataex(pipe_hnd, mem_ctx, hnd, keyname, ctr);				if (!W_ERROR_IS_OK(result)) {		printf("enumprinterdataex failed: %s\n", dos_errstr(result));		return False;	}	

⌨️ 快捷键说明

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