Exemple #1
0
static ipp_handler_t *
ipp_operation_handler(papi_attribute_t **request, papi_attribute_t ***response)
{
	int id = 0;
	int index;
	papi_attribute_t **ops = NULL;
	papi_status_t status;
	char configured = PAPI_FALSE;

	/* get the operation from the request */
	status = papiAttributeListGetInteger(request, NULL,
				"operation-id", &id);
	if (status != PAPI_OK) {
		ipp_set_status(response, PAPI_BAD_ARGUMENT,
			"no operation specified in request");
		return (default_handler);
	}

	/* find the operation in the handler table */
	index = ipp_operation_id_to_index(id);
#ifdef DEBUG
	if (index == -1)
		fprintf(stderr, "Operation: 0x%4.4x\n", id);
	else
		fprintf(stderr, "Operation: 0x%4.4x(%s)\n", id,
			handlers[index].name);
	fflush(stderr);
#endif

	if ((index == -1) || (handlers[index].function == NULL)) {
		ipp_set_status(response, PAPI_OPERATION_NOT_SUPPORTED,
			"operation (0x%4.4x) not implemented by server",
			id);
		return (default_handler);
	}

	/* find the configured operations */
	status = papiAttributeListGetCollection(request, NULL,
				"operations", &ops);
	if (status != PAPI_OK) {	/* this should not be possible */
		ipp_set_status(response, PAPI_INTERNAL_ERROR,
			"sofware error, no operations configured");
		return (default_handler);
	}

	/* check if the requested operation is configured */
	status = papiAttributeListGetBoolean(ops, NULL,
				handlers[index].name, &configured);
	if ((status != PAPI_OK) || (configured != PAPI_TRUE)) {
		ipp_set_status(response, PAPI_OPERATION_NOT_SUPPORTED,
			"operation (%s 0x%4.4x) not enabled on server",
			handlers[index].name, id);
		return (default_handler);
	}

	return (handlers[index].function);
}
Exemple #2
0
/* ARGSUSED2 */
static int
report_accepting(papi_service_t svc, char *name, papi_printer_t printer,
		int verbose, int description)
{
	papi_status_t status;
	papi_attribute_t **attrs = papiPrinterGetAttributeList(printer);
	time_t curr;
	char boolean = PAPI_FALSE;

	if (name == NULL) {
		status = papiAttributeListGetString(attrs, NULL,
					"printer-name", &name);
		if (status != PAPI_OK)
			status = papiAttributeListGetString(attrs, NULL,
					"printer-uri-supported", &name);
	}
	if (name == NULL)
		return (-1);

	(void) papiAttributeListGetBoolean(attrs, NULL,
				"printer-is-accepting-jobs", &boolean);
	(void) time(&curr);
	(void) papiAttributeListGetDatetime(attrs, NULL,
					"printer-up-time", &curr);
	(void) papiAttributeListGetDatetime(attrs, NULL,
					"printer-state-time", &curr);
	(void) papiAttributeListGetDatetime(attrs, NULL,
					"lpsched-reject-date", &curr);

	if (boolean == PAPI_TRUE) {
		printf(gettext("%s accepting requests since %s\n"),
			name, nctime(&curr));
	} else {
		char *reason = "unknown reason";

		(void) papiAttributeListGetString(attrs, NULL,
					"lpsched-reject-reason", &reason);

		printf(gettext("%s not accepting requests since %s\n\t%s\n"),
			name, nctime(&curr), reason);
	}

	return (0);
}
Exemple #3
0
void
ipp_operations_supported(papi_attribute_t ***list, papi_attribute_t **request)
{
	papi_attribute_t **group = NULL;

	(void) papiAttributeListGetCollection(request, NULL,
				"operations", &group);
	if (group != NULL) {
		int i;

		for (i = 0; handlers[i].name != NULL; i++) {
			char boolean = PAPI_FALSE;
			(void) papiAttributeListGetBoolean(group, NULL,
					handlers[i].name, &boolean);

			if (boolean == PAPI_TRUE)
				(void) papiAttributeListAddInteger(list,
					PAPI_ATTR_APPEND,
					"operations-supported",
					handlers[i].id);
		}
	}
}
Exemple #4
0
/*
 * When the PAPI supports papiJobCreate(), papiJobStreamAdd() and
 * papiJobClose(), this will be much cleaner and more efficient, but in the
 * meantime, we are using a private, non-standard interface to do this.
 */
papi_status_t
ipp_send_document(papi_service_t svc, papi_attribute_t **request,
		papi_attribute_t ***response, ipp_reader_t iread, void *fd)
{
	papi_status_t status;
	papi_stream_t s = NULL;
	papi_job_t j = NULL;
	papi_attribute_t **operational = NULL;
	papi_attribute_t **job_attributes = NULL;
	char *queue = NULL;
	ssize_t rc;
	int id = -1;
	char buf[BUFSIZ];
	char last = PAPI_FALSE;
	char *keys[] = { "attributes-natural-language", "attributes-charset",
			"printer-uri", "job-id", "job-uri", "last-document",
			NULL };

	/* Get operational attributes from the request */
	(void) papiAttributeListGetCollection(request, NULL,
				"operational-attributes-group", &operational);

	/*
	 * the operational-attributes-group must contain:
	 *	job-uri (or printer-uri/job-id)
	 *	last-document
	 */
	get_printer_id(operational, &queue, &id);
	if (id < 0) {
		ipp_set_status(response, PAPI_BAD_REQUEST,
				"missing job-uri or job-id");
		return (PAPI_BAD_REQUEST);
	} else if (queue == NULL) {
		ipp_set_status(response, PAPI_BAD_REQUEST,
				"missing printer-uri or job-uri");
		return (PAPI_BAD_REQUEST);
	}

	status = papiAttributeListGetBoolean(operational, NULL,
			"last-document", &last);
	if (status != PAPI_OK) {
		ipp_set_status(response, status, "last-document: %s",
				papiStatusString(status));
		return (PAPI_BAD_REQUEST);
	}

	/*
	 * the operational-attributes-group may contain:
	 *	document-name
	 *	compression
	 *	document-format
	 *	document-natural-language
	 * Simply copy the entire contents of the operational-attributes-group
	 * for the PAPI call's possible use.
	 */
	split_and_copy_attributes(keys, operational, NULL, &job_attributes);

	/* copy any job-attributes-group attributes for the PAPI call */
	if (papiAttributeListGetCollection(request, NULL,
			"job-attributes-group", &operational) == PAPI_OK)
		copy_attributes(&job_attributes, operational);

	/* create a stream to write the document data on */
	status = papiJobStreamAdd(svc, queue, id, &s);
	papiAttributeListFree(job_attributes);
	if (status != PAPI_OK) {
		ipp_set_status(response, status, "job submission: %s",
				ipp_svc_status_mesg(svc, status));
		return (status);
	}

	/* copy the document data from the IPP connection to the stream */
	while ((status == PAPI_OK) && ((rc = iread(fd, buf, sizeof (buf))) > 0))
		status = papiJobStreamWrite(svc, s, buf, rc);
	if (status != PAPI_OK) {
		ipp_set_status(response, status, "write job data: %s",
				ipp_svc_status_mesg(svc, status));
		return (status);
	}

	/* close the stream */
	status = papiJobStreamClose(svc, s, &j);
	if (status != PAPI_OK) {
		ipp_set_status(response, status, "close job stream: %s",
				ipp_svc_status_mesg(svc, status));
		papiJobFree(j); /* we shouldn't have a job, but just in case */
		return (status);
	}

	/* if it's the last document, commit the job */
	if (last == PAPI_TRUE) {
		status = papiJobCommit(svc, queue, id);
	}

	/* add the job attributes to the response in a job-attributes-group */
	if (j != NULL) {
		papi_to_ipp_job_group(response, request, PAPI_ATTR_REPLACE, j);
		papiJobFree(j);
	}

	return (status);
}
Exemple #5
0
int
main(int ac, char *av[])
{
	papi_status_t status;
	papi_service_t svc = NULL;
	papi_attribute_t **list = NULL;
	papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
	papi_job_t job = NULL;
	char prefetch[3];
	int prefetch_len = sizeof (prefetch);
	char *printer = NULL;
	char b = PAPI_TRUE;
	int copy = 0;
	int silent = 0;
	int dump = 0;
	int validate = 0;
	int modify = -1;
	int c;
	uid_t ruid;
	struct passwd *pw;

	(void) setlocale(LC_ALL, "");
	(void) textdomain("SUNW_OST_OSCMD");

	ruid = getuid();
	if ((pw = getpwuid(ruid)) != NULL)
		(void) initgroups(pw->pw_name, pw->pw_gid);
	(void) setuid(ruid);


	while ((c = getopt(ac, av, "DEH:P:S:T:cd:f:i:mn:o:pq:rst:Vwy:")) != EOF)
		switch (c) {
		case 'H':	/* handling */
			if (strcasecmp(optarg, "hold") == 0)
				papiAttributeListAddString(&list,
				    PAPI_ATTR_EXCL,
				    "job-hold-until", "indefinite");
			else if (strcasecmp(optarg, "immediate") == 0)
				papiAttributeListAddString(&list,
				    PAPI_ATTR_EXCL,
				    "job-hold-until", "no-hold");
			else
				papiAttributeListAddString(&list,
				    PAPI_ATTR_EXCL,
				    "job-hold-until", optarg);
			break;
		case 'P': {	/* page list */
			char buf[BUFSIZ];

			snprintf(buf, sizeof (buf), "page-ranges=%s", optarg);
			papiAttributeListFromString(&list,
			    PAPI_ATTR_EXCL, buf);
			}
			break;
		case 'S':	/* charset */
			papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
			    "lp-charset", optarg);
			break;
		case 'T':	/* type */
			papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
			    "document-format",
			    lp_type_to_mime_type(optarg));
			break;
		case 'D':	/* dump */
			dump = 1;
			break;
		case 'c':	/* copy */
			copy = 1;
			break;
		case 'd':	/* destination */
			printer = optarg;
			break;
		case 'f':	/* form */
			papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
			    "form", optarg);
			break;
		case 'i':	/* modify job */
			if ((get_printer_id(optarg, &printer, &modify) < 0) ||
			    (modify < 0)) {
				fprintf(stderr,
				    gettext("invalid request id: %s\n"),
				    optarg);
				exit(1);
			}
			break;
		case 'm':	/* mail when complete */
			papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL,
			    "rfc-1179-mail", 1);
			break;
		case 'n':	/* copies */
			papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL,
			    "copies", atoi(optarg));
			break;
		case 'o':	/* lp "options" */
			papiAttributeListFromString(&list,
			    PAPI_ATTR_REPLACE, optarg);
			break;
		case 'p':	/* Solaris - notification */
			papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL,
			    "rfc-1179-mail", 1);
			break;
		case 'q': {	/* priority */
			int i = atoi(optarg);

			i = 100 - (i * 2.5);
			if ((i < 1) || (i > 100)) {
				fprintf(stderr, gettext("UX:lp: "));
				fprintf(stderr, gettext("ERROR: "));
				fprintf(stderr, gettext("Bad priority"
				    " value \"%s\"."), optarg);
				fprintf(stderr, gettext("\n      "));
				fprintf(stderr, gettext("TO FIX"));
				fprintf(stderr, gettext(": "));
				fprintf(stderr, gettext("Use an integer value"
				    " from 0 to 39."));
				fprintf(stderr, gettext("\n"));
				exit(1);
			}
			papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL,
			    "job-priority", i);
			}
			break;
		case 'r':	/* "raw" mode */
			papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
			    "document-format",
			    "application/octet-stream");
			papiAttributeListAddString(&list, PAPI_ATTR_APPEND,
			    "stty", "raw");
			break;
		case 's':	/* suppress message */
			silent = 1;
			break;
		case 't':	/* title */
			papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
			    "job-name", optarg);
			break;
		case 'V':	/* validate */
			validate = 1;
			break;
		case 'w':
			papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL,
			    "rfc-1179-mail", 1);
			break;
		case 'y':	/* lp "modes" */
			papiAttributeListAddString(&list, PAPI_ATTR_APPEND,
			    "lp-modes", optarg);
			break;
		case 'E':
			encryption = PAPI_ENCRYPT_REQUIRED;
			break;
		default:
			usage(av[0]);
		}

	/* convert "banner", "nobanner" to "job-sheet" */
	if (papiAttributeListGetBoolean(list, NULL, "banner", &b) == PAPI_OK) {
		(void) papiAttributeListDelete(&list, "banner");
		if (b == PAPI_FALSE)
			papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
			    "job-sheets", "none");
	}

	if ((printer == NULL) &&
	    ((printer = getenv("PRINTER")) == NULL) &&
	    ((printer = getenv("LPDEST")) == NULL))
		printer = DEFAULT_DEST;

	if (((optind + 1) == ac) && (strcmp(av[optind], "-") == 0))
		optind = ac;

	if (modify == -1) {
		char *document_format = "text/plain";

		if (optind != ac) {
			/* get the mime type of the file data */
#ifdef MAGIC_MIME
			magic_t ms = NULL;

			if ((ms = magic_open(MAGIC_MIME)) != NULL) {
				document_format = magic_file(ms, av[optind]);
				magic_close(ms);
			}
#else
			if (is_postscript(av[optind]) == 1)
				document_format = "application/postscript";
#endif
		} else {
			if (is_postscript_stream(0, prefetch, &prefetch_len)
			    == 1)
				document_format = "application/postscript";
		}

		papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, "copies", 1);
		papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
		    "document-format", document_format);
		papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
		    "job-sheets", "standard");
	}

	status = papiServiceCreate(&svc, printer, NULL, NULL, cli_auth_callback,
	    encryption, NULL);
	if (status != PAPI_OK) {
		fprintf(stderr, gettext(
		    "Failed to contact service for %s: %s\n"), printer,
		    verbose_papi_message(svc, status));
		exit(1);
	}

	if (dump != 0) {
		printf("requesting attributes:\n");
		papiAttributeListPrint(stdout, list, "\t");
		printf("\n");
	}

	if (modify != -1)
		status = papiJobModify(svc, printer, modify, list, &job);
	else if (optind == ac)	/* no file list, use stdin */
		status = jobSubmitSTDIN(svc, printer, prefetch, prefetch_len,
		    list, &job);
	else if (validate == 1)	/* validate the request can be processed */
		status = papiJobValidate(svc, printer, list,
		    NULL, &av[optind], &job);
	else if (copy == 0)	/* reference the files in the job, default */
		status = papiJobSubmitByReference(svc, printer, list,
		    NULL, &av[optind], &job);
	else			/* copy the files before return, -c */
		status = papiJobSubmit(svc, printer, list,
		    NULL, &av[optind], &job);

	papiAttributeListFree(list);

	if (status != PAPI_OK) {
		fprintf(stderr, gettext("%s: %s\n"), printer,
		    verbose_papi_message(svc, status));
		papiJobFree(job);
		papiServiceDestroy(svc);
		exit(1);
	}

	if (((silent == 0) || (dump != 0)) &&
	    ((list = papiJobGetAttributeList(job)) != NULL)) {
		int32_t id = -1;

		if (printer == NULL)
			papiAttributeListGetString(list, NULL,
			    "printer-name", &printer);

		papiAttributeListGetInteger(list, NULL,
		    "job-id-requested", &id);
		if (id == -1) {
			papiAttributeListGetInteger(list, NULL, "job-id", &id);
		}

		printf(gettext("request id is %s-%d "), printer, id);
		if (ac != optind)
			printf("(%d file(s))\n", ac - optind);
		else
			printf("(standard input)\n");

		if (dump != 0) {
			printf("job attributes:\n");
			papiAttributeListPrint(stdout, list, "\t");
			printf("\n");
		}
	}

	papiJobFree(job);
	papiServiceDestroy(svc);

	return (0);
}