Ejemplo n.º 1
0
/*
 * interface for passing a peer's connection to gather sensitivity labeling
 * from for Trusted Solaris.
 */
papi_status_t
papiServiceSetPeer(papi_service_t handle, int peerfd)
{
    papi_status_t result = PAPI_OK;
    service_t *svc = handle;

    if (svc == NULL)
        return (PAPI_BAD_ARGUMENT);

    if (is_system_labeled()) {
        short status;

        if ((snd_msg(svc, S_PASS_PEER_CONNECTION) < 0) ||
                (ioctl(svc->md->writefd, I_SENDFD, peerfd) < 0) ||
                (rcv_msg(svc, R_PASS_PEER_CONNECTION, &status) < 0))
            status = MTRANSMITERR;

        if (status != MOK) {
            detailed_error(svc,
                           gettext("failed to send peer connection: %s"),
                           lpsched_status_string(status));
            result = lpsched_status_to_papi_status(status);
        }
    }

    return (result);
}
Ejemplo n.º 2
0
papi_status_t
papiJobMove(papi_service_t handle, char *printer, int32_t job_id,
		char *destination)
{
	papi_status_t result = PAPI_OK;
	long bits;
	service_t *svc = handle;
	char req_id[64];
	char *queue;
	char *user = NULL;

	if ((svc == NULL) || (printer == NULL) || (job_id < 0) ||
	    (destination == NULL))
		return (PAPI_BAD_ARGUMENT);

	queue = printer_name_from_uri_id(printer, job_id);
	snprintf(req_id, sizeof (req_id), "%s-%d", queue, job_id);
	free(queue);

	if (papiAttributeListGetString(svc->attributes, NULL, "user-name",
	    &user) == PAPI_OK) {
		REQUEST *r = getrequest(req_id);

		if ((r != NULL) && (r->user != NULL) &&
		    (strcmp(r->user, user) != 0))
			result = PAPI_NOT_AUTHORIZED;
		freerequest(r);
	}

	if (result == PAPI_OK) {
		short status = MOK;
		char *dest = printer_name_from_uri_id(destination, -1);

		if ((snd_msg(svc, S_MOVE_REQUEST, req_id, dest) < 0) ||
		    (rcv_msg(svc, R_MOVE_REQUEST, &status, &bits) < 0))
			status = MTRANSMITERR;

		free(dest);

		result = lpsched_status_to_papi_status(status);
	}

	return (result);
}
Ejemplo n.º 3
0
papi_status_t
papiJobCancel(papi_service_t handle, char *printer, int32_t job_id)
{
	papi_status_t result = PAPI_OK;
	service_t *svc = handle;
	char req_id[64];
	char *dest;
	char *user = NULL;

	if ((svc == NULL) || (printer == NULL) || (job_id < 0))
		return (PAPI_BAD_ARGUMENT);

	dest = printer_name_from_uri_id(printer, job_id);
	snprintf(req_id, sizeof (req_id), "%s-%d", dest, job_id);
	free(dest);

	if (papiAttributeListGetString(svc->attributes, NULL, "user-name",
	    &user) == PAPI_OK) {
		REQUEST *r = getrequest(req_id);

		if ((result = authorized(handle, job_id)) != PAPI_OK)
			result = PAPI_NOT_AUTHORIZED;

		if ((r != NULL) && (r->user != NULL) &&
		    (strcmp(r->user, user) != 0))
			result = PAPI_NOT_AUTHORIZED;
		freerequest(r);
	}

	if (result == PAPI_OK) {
		short status = MOK;

		if ((snd_msg(svc, S_CANCEL_REQUEST, req_id) < 0) ||
		    (rcv_msg(svc, R_CANCEL_REQUEST, &status) < 0))
			status = MTRANSMITERR;

		result = lpsched_status_to_papi_status(status);
	}

	return (result);
}
Ejemplo n.º 4
0
papi_status_t
papiPrinterListJobs(papi_service_t handle, char *name,
		char **requested_attrs, int type_mask,
		int max_num_jobs, papi_job_t **jobs)
{
	service_t *svc = handle;
	char *dest;
	short rc;
	int count = 1;

	if ((handle == NULL) || (name == NULL) || (jobs == NULL))
		return (PAPI_BAD_ARGUMENT);

	dest = printer_name_from_uri_id(name, -1);

	rc = snd_msg(svc, S_INQUIRE_REQUEST_RANK, 0, "", dest, "", "", "");
	free(dest);
	if (rc < 0)
		return (PAPI_SERVICE_UNAVAILABLE);

	do {
		job_t *job = NULL;
		char *dest = NULL,
			*ptr,
			*form = NULL,
			*req_id = NULL,
			*charset = NULL,
			*owner = NULL,
			*slabel = NULL,
			*file = NULL;
		time_t date = 0;
		size_t size = 0;
		short  rank = 0, state = 0;

		if (rcv_msg(svc, R_INQUIRE_REQUEST_RANK, &rc, &req_id,
				&owner, &slabel, &size, &date, &state, &dest,
				&form, &charset, &rank, &file) < 0)
			return (PAPI_SERVICE_UNAVAILABLE);

		if ((rc != MOK) && (rc != MOKMORE))
			continue;
		/*
		 * at this point, we should check to see if the job matches the
		 * selection criterion defined in "type_mask".
		 */

		/* too many yet? */
		if ((max_num_jobs != 0) && (count++ > max_num_jobs))
			continue;

		if ((job = calloc(1, sizeof (*job))) == NULL)
			continue;

		job_status_to_attributes(job, req_id, owner, slabel, size,
				date, state, dest, form, charset, rank, file);

		if ((ptr = strrchr(file, '-')) != NULL) {
			*++ptr = '0';
			*++ptr = NULL;
		}

		lpsched_read_job_configuration(svc, job, file);

		list_append(jobs, job);

	} while (rc == MOKMORE);

	if (rc == MNOINFO)	/* If no jobs are found, it's still ok */
		rc = MOK;

	return (lpsched_status_to_papi_status(rc));
}