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

📄 cmd_spoolss.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
	PRINTER_DRIVER_CTR 	ctr;	fstring 	printername, 			servername, 			user;	uint32		i;	BOOL		success = False;	if ((argc == 1) || (argc > 3)) 	{		printf("Usage: %s <printername> [level]\n", argv[0]);		return WERR_OK;	}	/* get the arguments need to open the printer handle */	slprintf(servername, sizeof(servername)-1, "\\\\%s", cli->cli->desthost);	strupper_m(servername);	fstrcpy(user, cli->user_name);	slprintf(printername, sizeof(servername)-1, "%s\\%s", servername, argv[1]);	if (argc == 3)		info_level = atoi(argv[2]);	/* Open a printer handle */	werror = rpccli_spoolss_open_printer_ex(cli, mem_ctx, printername, "", 					     PRINTER_ACCESS_USE,					     servername, user, &pol);	if (!W_ERROR_IS_OK(werror)) {		printf("Error opening printer handle for %s!\n", printername);		return werror;	}	opened_hnd = True;	/* loop through and print driver info level for each architecture */	for (i=0; archi_table[i].long_archi!=NULL; i++) {		werror = rpccli_spoolss_getprinterdriver( cli, mem_ctx, &pol, info_level, 			archi_table[i].long_archi, archi_table[i].version,			&ctr);		if (!W_ERROR_IS_OK(werror))			continue;				/* need at least one success */				success = True;					printf ("\n[%s]\n", archi_table[i].long_archi);		switch (info_level) {		case 1:			display_print_driver_1 (ctr.info1);			break;		case 2:			display_print_driver_2 (ctr.info2);			break;		case 3:			display_print_driver_3 (ctr.info3);			break;		default:			printf("unknown info level %d\n", info_level);			break;		}	}		/* Cleanup */	if (opened_hnd)		rpccli_spoolss_close_printer (cli, mem_ctx, &pol);		if ( success )		werror = WERR_OK;			return werror;}/********************************************************************************************************************************************************/static WERROR cmd_spoolss_enum_drivers(struct rpc_pipe_client *cli,                                          TALLOC_CTX *mem_ctx,                                         int argc, const char **argv){	WERROR werror = WERR_OK;	uint32          info_level = 1;	PRINTER_DRIVER_CTR 	ctr;	uint32		i, j,			returned;	if (argc > 2) {		printf("Usage: enumdrivers [level]\n");		return WERR_OK;	}	if (argc == 2)		info_level = atoi(argv[1]);	/* loop through and print driver info level for each architecture */	for (i=0; archi_table[i].long_archi!=NULL; i++) {		/* check to see if we already asked for this architecture string */		if ( i>0 && strequal(archi_table[i].long_archi, archi_table[i-1].long_archi) )			continue;		werror = rpccli_spoolss_enumprinterdrivers(			cli, mem_ctx, info_level, 			archi_table[i].long_archi, &returned, &ctr);		if (W_ERROR_V(werror) == W_ERROR_V(WERR_INVALID_ENVIRONMENT)) {			printf ("Server does not support environment [%s]\n", 				archi_table[i].long_archi);			werror = WERR_OK;			continue;		}		if (returned == 0)			continue;					if (!W_ERROR_IS_OK(werror)) {			printf ("Error getting driver for environment [%s] - %d\n",				archi_table[i].long_archi, W_ERROR_V(werror));			continue;		}				printf ("\n[%s]\n", archi_table[i].long_archi);		switch (info_level) 		{					case 1:			for (j=0; j < returned; j++) {				display_print_driver_1 (&ctr.info1[j]);			}			break;		case 2:			for (j=0; j < returned; j++) {				display_print_driver_2 (&ctr.info2[j]);			}			break;		case 3:			for (j=0; j < returned; j++) {				display_print_driver_3 (&ctr.info3[j]);			}			break;		default:			printf("unknown info level %d\n", info_level);			return WERR_UNKNOWN_LEVEL;		}	}		return werror;}/********************************************************************************************************************************************************/static void display_printdriverdir_1(DRIVER_DIRECTORY_1 *i1){        fstring name;        if (i1 == NULL)                return; 	rpcstr_pull(name, i1->name.buffer, sizeof(name), -1, STR_TERMINATE); 	printf ("\tDirectory Name:[%s]\n", name);}/********************************************************************************************************************************************************/static WERROR cmd_spoolss_getdriverdir(struct rpc_pipe_client *cli,                                          TALLOC_CTX *mem_ctx,                                         int argc, const char **argv){	WERROR result;	fstring			env;	DRIVER_DIRECTORY_CTR	ctr;	if (argc > 2) {		printf("Usage: %s [environment]\n", argv[0]);		return WERR_OK;	}	/* Get the arguments need to open the printer handle */	if (argc == 2)		fstrcpy (env, argv[1]);	else		fstrcpy (env, "Windows NT x86");	/* Get the directory.  Only use Info level 1 */	result = rpccli_spoolss_getprinterdriverdir(cli, mem_ctx, 1, env, &ctr);	if (W_ERROR_IS_OK(result))		display_printdriverdir_1(ctr.info1);	return result;}/********************************************************************************************************************************************************/void set_drv_info_3_env (DRIVER_INFO_3 *info, const char *arch){	int i;		for (i=0; archi_table[i].long_archi != NULL; i++) 	{		if (strcmp(arch, archi_table[i].short_archi) == 0)		{			info->version = archi_table[i].version;			init_unistr (&info->architecture, archi_table[i].long_archi);			break;		}	}		if (archi_table[i].long_archi == NULL)	{		DEBUG(0, ("set_drv_info_3_env: Unknown arch [%s]\n", arch));	}		return;}/************************************************************************** wrapper for strtok to get the next parameter from a delimited list. Needed to handle the empty parameter string denoted by "NULL" *************************************************************************/ static char* get_driver_3_param (char* str, const char* delim, UNISTR* dest){	char	*ptr;	/* get the next token */	ptr = strtok(str, delim);	/* a string of 'NULL' is used to represent an empty	   parameter because two consecutive delimiters	   will not return an empty string.  See man strtok(3)	   for details */	if (ptr && (StrCaseCmp(ptr, "NULL") == 0))		ptr = NULL;	if (dest != NULL)		init_unistr(dest, ptr);		return ptr;}/******************************************************************************** fill in the members of a DRIVER_INFO_3 struct using a character  string in the form of 	 <Long Printer Name>:<Driver File Name>:<Data File Name>:\	     <Config File Name>:<Help File Name>:<Language Monitor Name>:\	     <Default Data Type>:<Comma Separated list of Files>  *******************************************************************************/static BOOL init_drv_info_3_members ( TALLOC_CTX *mem_ctx, DRIVER_INFO_3 *info,                                       char *args ){	char	*str, *str2;	uint32	len, i;		/* fill in the UNISTR fields */	str = get_driver_3_param (args, ":", &info->name);	str = get_driver_3_param (NULL, ":", &info->driverpath);	str = get_driver_3_param (NULL, ":", &info->datafile);	str = get_driver_3_param (NULL, ":", &info->configfile);	str = get_driver_3_param (NULL, ":", &info->helpfile);	str = get_driver_3_param (NULL, ":", &info->monitorname);	str = get_driver_3_param (NULL, ":", &info->defaultdatatype);	/* <Comma Separated List of Dependent Files> */	str2 = get_driver_3_param (NULL, ":", NULL); /* save the beginning of the string */	str = str2;				/* begin to strip out each filename */	str = strtok(str, ",");			len = 0;	while (str != NULL)	{		/* keep a cumlative count of the str lengths */		len += strlen(str)+1;		str = strtok(NULL, ",");	}	/* allocate the space; add one extra slot for a terminating NULL.	   Each filename is NULL terminated and the end contains a double	   NULL */	if ((info->dependentfiles=TALLOC_ARRAY(mem_ctx, uint16, len+1)) == NULL)	{		DEBUG(0,("init_drv_info_3_members: Unable to malloc memory for dependenfiles\n"));		return False;	}	for (i=0; i<len; i++)	{		SSVAL(&info->dependentfiles[i], 0, str2[i]);	}	info->dependentfiles[len] = '\0';	return True;}/********************************************************************************************************************************************************/static WERROR cmd_spoolss_addprinterdriver(struct rpc_pipe_client *cli,                                              TALLOC_CTX *mem_ctx,                                             int argc, const char **argv){	WERROR result;	uint32                  level = 3;	PRINTER_DRIVER_CTR	ctr;	DRIVER_INFO_3		info3;	const char		*arch;	fstring			driver_name;	char 			*driver_args;	/* parse the command arguements */	if (argc != 3 && argc != 4)	{		printf ("Usage: %s <Environment> \\\n", argv[0]);		printf ("\t<Long Printer Name>:<Driver File Name>:<Data File Name>:\\\n");    		printf ("\t<Config File Name>:<Help File Name>:<Language Monitor Name>:\\\n");	    	printf ("\t<Default Data Type>:<Comma Separated list of Files> \\\n");		printf ("\t[version]\n");            return WERR_OK;        }			/* Fill in the DRIVER_INFO_3 struct */	ZERO_STRUCT(info3);	if (!(arch = cmd_spoolss_get_short_archi(argv[1])))	{		printf ("Error Unknown architechture [%s]\n", argv[1]);		return WERR_INVALID_PARAM;	}	else		set_drv_info_3_env(&info3, arch);	driver_args = talloc_strdup( mem_ctx, argv[2] );	if (!init_drv_info_3_members(mem_ctx, &info3, driver_args ))	{		printf ("Error Invalid parameter list - %s.\n", argv[2]);		return WERR_INVALID_PARAM;	}	/* if printer driver version specified, override the default version	 * used by the architecture.  This allows installation of Windows	 * 2000 (version 3) printer drivers. */	if (argc == 4)	{		info3.version = atoi(argv[3]);	}	ctr.info3 = &info3;	result = rpccli_spoolss_addprinterdriver (cli, mem_ctx, level, &ctr);	if (W_ERROR_IS_OK(result)) {		rpcstr_pull(driver_name, info3.name.buffer, 			    sizeof(driver_name), -1, STR_TERMINATE);		printf ("Printer Driver %s successfully installed.\n",			driver_name);	}	return result;}/********************************************************************************************************************************************************/static WERROR cmd_spoolss_addprinterex(struct rpc_pipe_client *cli,                                          TALLOC_CTX *mem_ctx,                                         int argc, const char **argv){	WERROR result;	uint32			level = 2;	PRINTER_INFO_CTR	ctr;	PRINTER_INFO_2		info2;	fstring			servername;		/* parse the command arguements */	if (argc != 5)	{		printf ("Usage: %s <name> <shared name> <driver> <port>\n", argv[0]);		return WERR_OK;        }	        slprintf(servername, sizeof(servername)-1, "\\\\%s", cli->cli->desthost);        strupper_m(servername);	/* Fill in the DRIVER_INFO_2 struct */	ZERO_STRUCT(info2);		init_unistr( &info2.printername,	argv[1]);	init_unistr( &info2.sharename, 		argv[2]);	init_unistr( &info2.drivername,		argv[3]);	init_unistr( &info2.portname,		argv[4]);	init_unistr( &info2.comment,		"Created by rpcclient");	init_unistr( &info2.printprocessor, 	"winprint");	init_unistr( &info2.datatype,		"RAW");	info2.devmode = 	NULL;	info2.secdesc = 	NULL;	info2.attributes 	= PRINTER_ATTRIBUTE_SHARED;	info2.priority 		= 0;	info2.defaultpriority	= 0;	info2.starttime		= 0;	info2.untiltime		= 0;		/* These three fields must not be used by AddPrinter() 	   as defined in the MS Platform SDK documentation..  	   --jerry	info2.status		= 0;	info2.cjobs		= 0;	info2.averageppm	= 0;	*/	ctr.printers_2 = &info2;	result = rpccli_spoolss_addprinterex (cli, mem_ctx, level, &ctr);	if (W_ERROR_IS_OK(result))		printf ("Printer %s successfully installed.\n", argv[1]);	return result;}/********************************************************************************************************************************************************/static WERROR cmd_spoolss_setdriver(struct rpc_pipe_client *cli,                                       TALLOC_CTX *mem_ctx,                                      int argc, const char **argv){	POLICY_HND		pol;	WERROR                  result;	uint32			level = 2;	BOOL			opened_hnd = False;	PRINTER_INFO_CTR	ctr;	PRINTER_INFO_2		info2;	fstring			servername,				printername,				user;		/* parse the command arguements */	if (argc != 3)	{		printf ("Usage: %s <printer> <driver>\n", argv[0]);		return WERR_OK;        }	slprintf(servername, sizeof(servername)-1, "\\\\%s", cli->cli->desthost);	strupper_m(servername);	slprintf(printername, sizeof(printername)-1, "%s\\%s", servername, argv[1]);	fstrcpy(user, cli->user_name);	/* Get a printer handle */	result = rpccli_spoolss_open_printer_ex(cli, mem_ctx, printername, "", 					     PRINTER_ALL_ACCESS,					     servername, user, &pol);	if (!W_ERROR_IS_OK(result))		goto done;	opened_hnd = True;	/* Get printer info */	ZERO_STRUCT (info2);	ctr.printers_2 = &info2;	result = rpccli_spoolss_getprinter(cli, mem_ctx, &pol, level, &ctr);	if (!W_ERROR_IS_OK(result)) {		printf ("Unable to retrieve printer information!\n");		goto done;	}	/* Set the printer driver */	init_unistr(&ctr.printers_2->drivername, argv[2]);	result = rpccli_spoolss_setprinter(cli, mem_ctx, &pol, level, &ctr, 0);

⌨️ 快捷键说明

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