Home | History | Annotate | Download | only in lpsched
      1      0   stevel /*
      2      0   stevel  * CDDL HEADER START
      3      0   stevel  *
      4      0   stevel  * The contents of this file are subject to the terms of the
      5   1676      jpk  * Common Development and Distribution License (the "License").
      6   1676      jpk  * You may not use this file except in compliance with the License.
      7      0   stevel  *
      8      0   stevel  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9      0   stevel  * or http://www.opensolaris.org/os/licensing.
     10      0   stevel  * See the License for the specific language governing permissions
     11      0   stevel  * and limitations under the License.
     12      0   stevel  *
     13      0   stevel  * When distributing Covered Code, include this CDDL HEADER in each
     14      0   stevel  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15      0   stevel  * If applicable, add the following below this CDDL HEADER, with the
     16      0   stevel  * fields enclosed by brackets "[]" replaced with your own identifying
     17      0   stevel  * information: Portions Copyright [yyyy] [name of copyright owner]
     18      0   stevel  *
     19      0   stevel  * CDDL HEADER END
     20      0   stevel  */
     21    320  ceastha /*
     22   9331    Sonam  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
     23    320  ceastha  * Use is subject to license terms.
     24    320  ceastha  */
     25    320  ceastha 
     26      0   stevel /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
     27      0   stevel /*	  All Rights Reserved  	*/
     28      0   stevel 
     29      0   stevel #include "dispatch.h"
     30      0   stevel #include <sys/types.h>
     31      0   stevel #include <sys/stat.h>
     32      0   stevel #include <syslog.h>
     33      0   stevel 
     34    320  ceastha static char	*reqpath(char *, char **);
     35    320  ceastha static int	mv_file(RSTATUS *, char *);
     36      0   stevel 
     37      0   stevel 
     38      0   stevel RSTATUS			*NewRequest;
     39      0   stevel 
     40   9984    Sonam /*
     41   9984    Sonam  * s_alloc_files()
     42   9984    Sonam  */
     43      0   stevel 
     44   9984    Sonam void
     45   9984    Sonam s_alloc_files(char *m, MESG *md)	/* funcdef */
     46      0   stevel {
     47   9984    Sonam 	char		*file_prefix;
     48   9984    Sonam 	ushort_t	count;
     49   9984    Sonam 	mode_t		old_msk;
     50      0   stevel 
     51      0   stevel 
     52   9984    Sonam 	/*
     53   9984    Sonam 	 * Bugid 4140311
     54   9984    Sonam 	 * Set umask to 0 before creating files.
     55   9984    Sonam 	 */
     56   9984    Sonam 	old_msk = umask((mode_t)0);
     57      0   stevel 
     58   9984    Sonam 	getmessage(m, S_ALLOC_FILES, &count);
     59   9984    Sonam 	syslog(LOG_DEBUG, "s_alloc_files(%d)", count);
     60      0   stevel 
     61   9984    Sonam 	if ((file_prefix = _alloc_files(count, (char *)0, md->uid, md->gid))) {
     62   9984    Sonam 		mputm(md, R_ALLOC_FILES, MOK, file_prefix);
     63   9984    Sonam 		add_flt_act(md, FLT_FILES, file_prefix, count);
     64   9984    Sonam 	} else if (errno == EEXIST)
     65   9984    Sonam 		mputm(md, R_ALLOC_FILES, MERRDEST, "");
     66   9984    Sonam 	else
     67   9984    Sonam 		mputm(md, R_ALLOC_FILES, MNOMEM, "");
     68      0   stevel 
     69   9984    Sonam 	(void) umask(old_msk);
     70      0   stevel 
     71      0   stevel }
     72      0   stevel 
     73   9984    Sonam /*
     74   9984    Sonam  * s_print_request()
     75   9984    Sonam  */
     76      0   stevel 
     77   9984    Sonam void
     78   9984    Sonam s_print_request(char *m, MESG *md)
     79      0   stevel {
     80   9984    Sonam 	extern char		*Local_System;
     81   9984    Sonam 	char			*file;
     82   9984    Sonam 	char			*idno;
     83   9984    Sonam 	char			*path;
     84   9984    Sonam 	char			*req_file;
     85   9984    Sonam 	char			*req_id	= 0;
     86   9984    Sonam 	RSTATUS			*rp;
     87   9984    Sonam 	REQUEST			*r;
     88   9984    Sonam 	SECURE			*s;
     89   9984    Sonam 	struct passwd		*pw;
     90   9984    Sonam 	short			err;
     91   9984    Sonam 	short			status;
     92   9984    Sonam 	off_t			size;
     93   9984    Sonam 	uid_t			org_uid;
     94   9984    Sonam 	gid_t			org_gid;
     95      0   stevel #ifdef LP_USE_PAPI_ATTR
     96   9984    Sonam 	struct stat		tmpBuf;
     97   9984    Sonam 	char 			tmpName[BUFSIZ];
     98      0   stevel #endif
     99      0   stevel 
    100      0   stevel 
    101   9984    Sonam 	(void) getmessage(m, S_PRINT_REQUEST, &file);
    102   9984    Sonam 	syslog(LOG_DEBUG, "s_print_request(%s)", (file ? file : "NULL"));
    103      0   stevel 
    104   9984    Sonam 	/*
    105   9984    Sonam 	 * "NewRequest" points to a request that's not yet in the
    106   9984    Sonam 	 * request list but is to be considered with the rest of the
    107   9984    Sonam 	 * requests (e.g. calculating # of requests awaiting a form).
    108   9984    Sonam 	 */
    109   9984    Sonam 	if ((rp = NewRequest = new_rstatus(NULL, NULL)) == NULL)
    110   9984    Sonam 		status = MNOMEM;
    111      0   stevel 
    112      0   stevel 	else
    113      0   stevel 	{
    114   9984    Sonam 		req_file = reqpath(file, &idno);
    115   9984    Sonam 		path = makepath(Lp_Tmp, req_file, (char *)0);
    116   9984    Sonam 		(void) chownmod(path, Lp_Uid, Lp_Gid, 0644);
    117   9984    Sonam 		Free(path);
    118      0   stevel 
    119   9984    Sonam 		if (!(r = Getrequest(req_file)))
    120   9984    Sonam 			status = MNOOPEN;
    121   3125   jacobs 
    122   9984    Sonam 		else
    123   9984    Sonam 		{
    124   9984    Sonam 			rp->req_file = Strdup(req_file);
    125   3125   jacobs 
    126   9984    Sonam 			freerequest(rp->request);
    127   9984    Sonam 			rp->request = r;
    128   3125   jacobs 
    129   9984    Sonam 			rp->request->outcome = 0;
    130   9984    Sonam 			rp->secure->uid = md->uid;
    131   9984    Sonam 			rp->secure->gid = md->gid;
    132   9984    Sonam 			if (md->slabel != NULL)
    133   9984    Sonam 				rp->secure->slabel = Strdup(md->slabel);
    134   3125   jacobs 
    135   9984    Sonam 			pw = getpwuid(md->uid);
    136   9984    Sonam 			endpwent();
    137   9984    Sonam 			if (pw && pw->pw_name && *pw->pw_name)
    138   9984    Sonam 				rp->secure->user = Strdup(pw->pw_name);
    139   9984    Sonam 			else {
    140   9984    Sonam 				rp->secure->user = Strdup(BIGGEST_NUMBER_S);
    141   9984    Sonam 				(void) sprintf(rp->secure->user, "%u",
    142   9984    Sonam 				    md->uid);
    143   9984    Sonam 			}
    144      0   stevel 
    145   9984    Sonam 			if ((rp->request->actions & ACT_SPECIAL) == ACT_HOLD)
    146   9984    Sonam 				rp->request->outcome |= RS_HELD;
    147   9984    Sonam 			if ((rp->request->actions & ACT_SPECIAL) == ACT_RESUME)
    148   9984    Sonam 				rp->request->outcome &= ~RS_HELD;
    149   9984    Sonam 			if ((rp->request->actions & ACT_SPECIAL) ==
    150   9984    Sonam 			    ACT_IMMEDIATE) {
    151   9984    Sonam 				if (!md->admin) {
    152   9984    Sonam 					status = MNOPERM;
    153   9984    Sonam 					goto Return;
    154   9984    Sonam 				}
    155   9984    Sonam 				rp->request->outcome |= RS_IMMEDIATE;
    156   9984    Sonam 			}
    157      0   stevel 
    158   9984    Sonam 			size = chfiles(rp->request->file_list, Lp_Uid, Lp_Gid);
    159      0   stevel 
    160   9984    Sonam 			if (size < 0) {
    161   9984    Sonam 				/*
    162   9984    Sonam 				 * at this point, chfiles() may have
    163   9984    Sonam 				 * failed because the file may live on
    164   9984    Sonam 				 * an NFS mounted filesystem, under
    165   9984    Sonam 				 * a directory of mode 700. such a
    166   9984    Sonam 				 * directory isn't accessible even by
    167   9984    Sonam 				 * root, according to the NFS protocol
    168   9984    Sonam 				 * (i.e. the Stat() in chfiles() failed).
    169   9984    Sonam 				 * this most commonly happens via the
    170   9984    Sonam 				 * automounter, and rlogin. thus we
    171   9984    Sonam 				 * change our euid/egid to that of the
    172   9984    Sonam 				 * user, and try again. if *this* fails,
    173   9984    Sonam 				 * then the file must really be
    174   9984    Sonam 				 * inaccessible.
    175   9984    Sonam 				 */
    176   9984    Sonam 				org_uid = geteuid();
    177   9984    Sonam 				org_gid = getegid();
    178      0   stevel 
    179   9984    Sonam 				if (setegid(md->gid) != 0) {
    180   9984    Sonam 					status = MUNKNOWN;
    181   9984    Sonam 					goto Return;
    182   9984    Sonam 				}
    183      0   stevel 
    184   9984    Sonam 				if (seteuid(md->uid) != 0) {
    185   9984    Sonam 					setgid(org_gid);
    186   9984    Sonam 					status = MUNKNOWN;
    187   9984    Sonam 					goto Return;
    188   9984    Sonam 				}
    189      0   stevel 
    190   9984    Sonam 				size = chfiles(rp->request->file_list,
    191   9984    Sonam 				    Lp_Uid, Lp_Gid);
    192      0   stevel 
    193   9984    Sonam 				if (seteuid(org_uid) != 0) {
    194   9984    Sonam 					/* should never happen */
    195   9984    Sonam 					note("s_print_request(): ");
    196   9984    Sonam 					note("seteuid back to uid=%d "
    197   9984    Sonam 					    "failed!!\n", org_uid);
    198   9984    Sonam 					size = -1;
    199   9984    Sonam 				}
    200      0   stevel 
    201   9984    Sonam 				if (setegid(org_gid) != 0) {
    202   9984    Sonam 					/* should never happen */
    203   9984    Sonam 					note("s_print_request(): ");
    204   9984    Sonam 					note("setegid back to uid=%d "
    205   9984    Sonam 					    "failed!!\n", org_uid);
    206   9984    Sonam 					size = -1;
    207   9984    Sonam 				}
    208      0   stevel 
    209   9984    Sonam 				if (size < 0) {
    210   9984    Sonam 					status = MUNKNOWN;
    211   9984    Sonam 					goto Return;
    212   9984    Sonam 				}
    213   9984    Sonam 			}
    214   9984    Sonam 			if (!(rp->request->outcome & RS_HELD) && size == 0) {
    215   9984    Sonam 				status = MNOPERM;
    216   9984    Sonam 				goto Return;
    217   9984    Sonam 			}
    218   9984    Sonam 			rp->secure->size = size;
    219   9984    Sonam 
    220   9984    Sonam 			(void) time(&rp->secure->date);
    221   9984    Sonam 			rp->secure->req_id = NULL;
    222   9984    Sonam 
    223   9984    Sonam 			if (!rp->request->title) {
    224   9984    Sonam 				if (strlen(*rp->request->file_list) <
    225   9984    Sonam 				    (size_t)24)
    226   9984    Sonam 					rp->request->title =
    227   9984    Sonam 					    Strdup(*rp->request->file_list);
    228   9984    Sonam 				else {
    229  10634    Sonam 					/*
    230  10634    Sonam 					 * In case of standard input
    231  10634    Sonam 					 * the title page should be
    232  10634    Sonam 					 * 'standard input'
    233  10634    Sonam 					 */
    234   9984    Sonam 					rp->request->title = malloc(25);
    235   9984    Sonam 					sprintf(rp->request->title,
    236  10634    Sonam 					    "%-.24s", "standard input");
    237   9984    Sonam 				}
    238   9984    Sonam 			}
    239   9984    Sonam 
    240   9984    Sonam 			if ((err = validate_request(rp, &req_id, 0)) != MOK)
    241   9984    Sonam 				status = err;
    242   9984    Sonam 			else {
    243   9984    Sonam 				/*
    244   9984    Sonam 				 * "req_id" will be supplied if this is from a
    245   9984    Sonam 				 * remote system.
    246   9984    Sonam 				 */
    247   9984    Sonam 				if (rp->secure->req_id == NULL) {
    248   9984    Sonam 					req_id = makestr(req_id, "-",
    249   9984    Sonam 					    idno, (char *)0);
    250   9984    Sonam 					rp->secure->req_id = req_id;
    251   9984    Sonam 				} else
    252   9984    Sonam 					req_id = rp->secure->req_id;
    253      0   stevel 
    254      0   stevel #ifdef LP_USE_PAPI_ATTR
    255   9984    Sonam 				/*
    256   9984    Sonam 				 * Check if the PAPI job attribute file
    257   9984    Sonam 				 * exists, if it does change the
    258   9984    Sonam 				 * permissions and ownership of the file.
    259   9984    Sonam 				 * This file is created when print jobs
    260   9984    Sonam 				 * are submitted via the PAPI interface,
    261   9984    Sonam 				 * the file pathname of this file is
    262   9984    Sonam 				 * passed to the slow-filters and printer
    263   9984    Sonam 				 * interface script as an environment
    264   9984    Sonam 				 * variable when they are executed
    265   9984    Sonam 				 */
    266   9984    Sonam 				snprintf(tmpName, sizeof (tmpName),
    267   9984    Sonam 				    "%s-%s", idno, LP_PAPIATTRNAME);
    268   9984    Sonam 				path = makepath(Lp_Temp, tmpName, (char *)0);
    269   9984    Sonam 
    270   9984    Sonam 				if (stat(path, &tmpBuf) == 0) {
    271   9984    Sonam 					syslog(LOG_DEBUG,
    272   9984    Sonam 					    "s_print_request: "\
    273   9984    Sonam 					    "attribute file ='%s'", path);
    274   9984    Sonam 
    275   9984    Sonam 					/*
    276   9984    Sonam 					 * IPP job attribute file exists
    277   9984    Sonam 					 * for this job so change
    278   9984    Sonam 					 * permissions and ownership of
    279   9984    Sonam 					 * the file
    280   9984    Sonam 					 */
    281   9984    Sonam 					(void) chownmod(path, Lp_Uid,
    282   9984    Sonam 					    Lp_Gid, 0644);
    283   9984    Sonam 					Free(path);
    284   9984    Sonam 				}
    285   9984    Sonam 				else
    286   9984    Sonam 				{
    287   9984    Sonam 					syslog(LOG_DEBUG,
    288   9984    Sonam 					    "s_print_request: "\
    289   9984    Sonam 					    "no attribute file");
    290   9984    Sonam 				}
    291   9984    Sonam #endif
    292   9984    Sonam 
    293   9984    Sonam 				/*
    294   9984    Sonam 				 * fix for bugid 1103890.
    295   9984    Sonam 				 * use Putsecure instead.
    296   9984    Sonam 				 */
    297   9984    Sonam 				if ((Putsecure(req_file, rp->secure) == -1) ||
    298   9984    Sonam 				    (putrequest(req_file, rp->request) == -1))
    299   9984    Sonam 					status = MNOMEM;
    300   9984    Sonam 				else
    301   9984    Sonam 				{
    302   9984    Sonam 					status = MOK;
    303   9984    Sonam 
    304   9984    Sonam 					insertr(rp);
    305   9984    Sonam 					NewRequest = 0;
    306   9984    Sonam 
    307   9984    Sonam 					if (rp->slow)
    308   9984    Sonam 						schedule(EV_SLOWF, rp);
    309   9984    Sonam 					else
    310   9984    Sonam 						schedule(EV_INTERF,
    311   9984    Sonam 						    rp->printer);
    312   9984    Sonam 
    313   9984    Sonam 					del_flt_act(md, FLT_FILES);
    314   9984    Sonam 				}
    315   9984    Sonam 			}
    316   9984    Sonam 		}
    317   9984    Sonam 	}
    318   9984    Sonam 
    319   9984    Sonam Return:
    320   9984    Sonam 	NewRequest = 0;
    321   9984    Sonam 	Free(req_file);
    322   9984    Sonam 	Free(idno);
    323   9984    Sonam 	if (status != MOK && rp) {
    324   9984    Sonam 		rmfiles(rp, 0);
    325   9984    Sonam 		free_rstatus(rp);
    326   9984    Sonam 	}
    327   9984    Sonam 	mputm(md, R_PRINT_REQUEST, status, NB(req_id), chkprinter_result);
    328   9984    Sonam }
    329   9984    Sonam 
    330   9984    Sonam /*
    331   9984    Sonam  * s_start_change_request()
    332   9984    Sonam  */
    333   9984    Sonam 
    334   9984    Sonam void
    335   9984    Sonam s_start_change_request(char *m, MESG *md)
    336   9984    Sonam {
    337   9984    Sonam 	char		*req_id;
    338   9984    Sonam 	char		*req_file	= "";
    339   9984    Sonam 	short		status;
    340   9984    Sonam 	RSTATUS		*rp;
    341   9984    Sonam 	char		*path;
    342   9984    Sonam 	char		tmpName[BUFSIZ];
    343   9984    Sonam 	struct stat	tmpBuf;
    344   9984    Sonam 
    345   9984    Sonam 	(void) getmessage(m, S_START_CHANGE_REQUEST, &req_id);
    346   9984    Sonam 	syslog(LOG_DEBUG, "s_start_change_request(%s)",
    347   9984    Sonam 	    (req_id ? req_id : "NULL"));
    348   9984    Sonam 
    349   9984    Sonam 	if (!(rp = request_by_id(req_id)))
    350   9984    Sonam 		status = MUNKNOWN;
    351   9984    Sonam 	else if ((md->admin == 0) && (is_system_labeled()) &&
    352   9984    Sonam 	    (md->slabel != NULL) && (rp->secure->slabel != NULL) &&
    353   9984    Sonam 	    (!STREQU(md->slabel, rp->secure->slabel)))
    354   9984    Sonam 		status = MUNKNOWN;
    355   9984    Sonam 	else if (rp->request->outcome & RS_DONE)
    356   9984    Sonam 		status = M2LATE;
    357   9984    Sonam 	else if (!md->admin && md->uid != rp->secure->uid)
    358   9984    Sonam 		status = MNOPERM;
    359   9984    Sonam 	else if (rp->request->outcome & RS_CHANGING)
    360   9984    Sonam 		status = MNOOPEN;
    361   9984    Sonam 	else if (rp->request->outcome & RS_NOTIFYING)
    362   9984    Sonam 		status = MBUSY;
    363   9984    Sonam 	else {
    364   9984    Sonam 		status = MOK;
    365   9984    Sonam 
    366   9984    Sonam 		if (rp->request->outcome & RS_FILTERING &&
    367   9984    Sonam 		    !(rp->request->outcome & RS_STOPPED)) {
    368   9984    Sonam 			rp->request->outcome |= (RS_REFILTER|RS_STOPPED);
    369   9984    Sonam 			terminate(rp->exec);
    370   9984    Sonam 		}
    371   9984    Sonam 
    372   9984    Sonam 		if (rp->request->outcome & RS_PRINTING &&
    373   9984    Sonam 		    !(rp->request->outcome & RS_STOPPED)) {
    374   9984    Sonam 			rp->request->outcome |= RS_STOPPED;
    375   9984    Sonam 			terminate(rp->printer->exec);
    376   9984    Sonam 		}
    377   9984    Sonam 
    378   9984    Sonam 		rp->request->outcome |= RS_CHANGING;
    379   9984    Sonam 
    380   9984    Sonam 		/*
    381   9984    Sonam 		 * Change the ownership of the request file to be "md->uid".
    382   9984    Sonam 		 * Either this is identical to "rp->secure->uid", or it is
    383   9984    Sonam 		 * "Lp_Uid" or it is root. The idea is that the
    384   9984    Sonam 		 * person at the other end needs access, and that may not
    385   9984    Sonam 		 * be who queued the request.
    386   9984    Sonam 		 */
    387   9984    Sonam 
    388   9984    Sonam 		path = makepath(Lp_Tmp, rp->req_file, (char *)0);
    389   9984    Sonam 		(void) Chown(path, md->uid, rp->secure->gid);
    390   9984    Sonam 		Free(path);
    391   9984    Sonam 
    392   9984    Sonam #ifdef LP_USE_PAPI_ATTR
    393   9984    Sonam 
    394      0   stevel 		/*
    395      0   stevel 		 * Check if the PAPI job attribute file exists, if it does
    396   9984    Sonam 		 * change the ownership of the file to be "md->uid".
    397   9984    Sonam 		 * Either this is identical to "rp->secure->uid", or it is
    398   9984    Sonam 		 * "Lp_Uid" or it is root. The idea is that the
    399   9984    Sonam 		 * person at the other end needs access, and that may not
    400   9984    Sonam 		 * be who queued the request.
    401      0   stevel 		 */
    402   9984    Sonam 
    403      0   stevel 		snprintf(tmpName, sizeof (tmpName),
    404   9984    Sonam 		    "%s-%s", strtok(strdup(rp->req_file), "-"),
    405   9984    Sonam 		    LP_PAPIATTRNAME);
    406      0   stevel 
    407   9984    Sonam 		path = makepath(Lp_Tmp, tmpName, (char *)0);
    408   9984    Sonam 
    409   9984    Sonam 		if (stat(path, &tmpBuf) == 0) {
    410      0   stevel 			syslog(LOG_DEBUG,
    411   9984    Sonam 			    "s_start_change_request: attribute file ='%s'",
    412   9984    Sonam 			    path);
    413      0   stevel 
    414      0   stevel 			/*
    415      0   stevel 			 * IPP job attribute file exists for this job so
    416      0   stevel 			 * change permissions and ownership of the file
    417      0   stevel 			 */
    418   9984    Sonam 			(void) Chown(path, md->uid, rp->secure->gid);
    419      0   stevel 			Free(path);
    420      0   stevel 		}
    421      0   stevel 		else
    422      0   stevel 		{
    423   9984    Sonam 			syslog(LOG_DEBUG,
    424   9984    Sonam 			    "s_start_change_request: no attribute file");
    425      0   stevel 		}
    426      0   stevel #endif
    427      0   stevel 
    428   9984    Sonam 		add_flt_act(md, FLT_CHANGE, rp);
    429   9984    Sonam 		req_file = rp->req_file;
    430      0   stevel 
    431   9984    Sonam 	}
    432      0   stevel 
    433   9984    Sonam 	mputm(md, R_START_CHANGE_REQUEST, status, req_file);
    434      0   stevel }
    435      0   stevel 
    436   9984    Sonam /*
    437   9984    Sonam  * s_end_change_request()
    438   9984    Sonam  */
    439      0   stevel 
    440   9984    Sonam void
    441   9984    Sonam s_end_change_request(char *m, MESG *md)
    442      0   stevel {
    443   9984    Sonam 	char		*req_id;
    444   9984    Sonam 	RSTATUS		*rp;
    445   9984    Sonam 	off_t		size;
    446   9984    Sonam 	off_t		osize;
    447   9984    Sonam 	short		err;
    448   9984    Sonam 	short		status;
    449   9984    Sonam 	REQUEST		*r = 0;
    450   9984    Sonam 	REQUEST		oldr;
    451   9984    Sonam 	int		call_schedule = 0;
    452   9984    Sonam 	int		move_ok	= 0;
    453   9984    Sonam 	char		*path;
    454   9984    Sonam 	char		tmpName[BUFSIZ];
    455   9984    Sonam 	struct stat	tmpBuf;
    456   9984    Sonam 
    457   9984    Sonam 	(void) getmessage(m, S_END_CHANGE_REQUEST, &req_id);
    458   9984    Sonam 	syslog(LOG_DEBUG, "s_end_change_request(%s)",
    459   9984    Sonam 	    (req_id ? req_id : "NULL"));
    460   9984    Sonam 
    461   9984    Sonam 	if (!(rp = request_by_id(req_id)))
    462   9984    Sonam 		status = MUNKNOWN;
    463   9984    Sonam 	else if ((md->admin == 0) && (is_system_labeled()) &&
    464   1676      jpk 	    (md->slabel != NULL) && (rp->secure->slabel != NULL) &&
    465   1676      jpk 	    (!STREQU(md->slabel, rp->secure->slabel)))
    466   9984    Sonam 		status = MUNKNOWN;
    467   9984    Sonam 	else if (!(rp->request->outcome & RS_CHANGING))
    468   9984    Sonam 		status = MNOSTART;
    469   9984    Sonam 	else {
    470   9984    Sonam 		path = makepath(Lp_Tmp, rp->req_file, (char *)0);
    471   9984    Sonam 		(void) chownmod(path, Lp_Uid, Lp_Gid, 0644);
    472   9984    Sonam 		Free(path);
    473   8448    Sonam 
    474   8448    Sonam #ifdef LP_USE_PAPI_ATTR
    475   8448    Sonam 
    476   9984    Sonam 		/*
    477   9984    Sonam 		 * Check if the PAPI job attribute file exists,
    478   9984    Sonam 		 * if it does change the permission and the ownership
    479   9984    Sonam 		 * of the file to be "Lp_Uid".
    480   9984    Sonam 		 */
    481   8448    Sonam 
    482   9984    Sonam 		snprintf(tmpName, sizeof (tmpName),
    483   9984    Sonam 		    "%s-%s", strtok(strdup(rp->req_file), "-"),
    484   9984    Sonam 		    LP_PAPIATTRNAME);
    485   9984    Sonam 
    486   9984    Sonam 		path = makepath(Lp_Tmp, tmpName, (char *)0);
    487   9984    Sonam 
    488   9984    Sonam 		if (stat(path, &tmpBuf) == 0) {
    489   9984    Sonam 			syslog(LOG_DEBUG,
    490   9984    Sonam 			    "s_end_change_request: attribute file ='%s'",
    491   9984    Sonam 			    path);
    492   9984    Sonam 
    493   9984    Sonam 			/*
    494   9984    Sonam 			 * IPP job attribute file exists for this job so
    495   9984    Sonam 			 * change permissions and ownership of the file
    496   9984    Sonam 			 */
    497   9984    Sonam 			(void) chownmod(path, Lp_Uid, Lp_Gid, 0644);
    498   9984    Sonam 			Free(path);
    499   9984    Sonam 		}
    500   9984    Sonam 		else
    501   9984    Sonam 		{
    502   9984    Sonam 			syslog(LOG_DEBUG,
    503   9984    Sonam 			    "s_end_change_request: no attribute file");
    504   9984    Sonam 		}
    505   9984    Sonam #endif
    506   9984    Sonam 		rp->request->outcome &= ~(RS_CHANGING);
    507   9984    Sonam 		del_flt_act(md, FLT_CHANGE);
    508   8448    Sonam 		/*
    509   9984    Sonam 		 * The RS_CHANGING bit may have been the only thing
    510   9984    Sonam 		 * preventing this request from filtering or printing,
    511   9984    Sonam 		 * so regardless of what happens below,
    512   9984    Sonam 		 * we must check to see if the request can proceed.
    513   8448    Sonam 		 */
    514   9984    Sonam 		call_schedule = 1;
    515   9984    Sonam 
    516   9984    Sonam 		if (!(r = Getrequest(rp->req_file)))
    517   9984    Sonam 			status = MNOOPEN;
    518   9984    Sonam 		else {
    519   9984    Sonam 			oldr = *(rp->request);
    520   9984    Sonam 			*(rp->request) = *r;
    521   9984    Sonam 
    522   9984    Sonam 			move_ok =
    523   9984    Sonam 			    STREQU(oldr.destination, r->destination);
    524   9984    Sonam 
    525   9984    Sonam 			/*
    526   9984    Sonam 			 * Preserve the current request status!
    527   9984    Sonam 			 */
    528   9984    Sonam 			rp->request->outcome = oldr.outcome;
    529   9984    Sonam 
    530   9984    Sonam 			/*
    531   9984    Sonam 			 * Here's an example of the dangers one meets
    532   9984    Sonam 			 * when public flags are used for private
    533   9984    Sonam 			 * purposes. ".actions" (indeed, anything in the
    534   9984    Sonam 			 * REQUEST structure) is set by the person
    535   9984    Sonam 			 * changing the job. However, lpsched uses
    536   9984    Sonam 			 * ".actions" as place to indicate that a job
    537   9984    Sonam 			 * came from a remote system and we must send
    538   9984    Sonam 			 * back job completion--this is a strictly
    539   9984    Sonam 			 * private flag that we must preserve.
    540   9984    Sonam 			 */
    541   9984    Sonam 			rp->request->actions |=
    542   9984    Sonam 			    (oldr.actions & ACT_NOTIFY);
    543   9984    Sonam 
    544   9984    Sonam 			if ((rp->request->actions & ACT_SPECIAL) ==
    545   9984    Sonam 			    ACT_HOLD) {
    546   9984    Sonam 				rp->request->outcome |= RS_HELD;
    547   9984    Sonam 				/*
    548   9984    Sonam 				 * To be here means either the user owns
    549   9984    Sonam 				 * the request or he or she is the
    550   9984    Sonam 				 * administrator. Since we don't want to
    551   9984    Sonam 				 * set the RS_ADMINHELD flag if the user
    552   9984    Sonam 				 * is the administrator, the following
    553   9984    Sonam 				 * compare will work.
    554   9984    Sonam 				 */
    555   9984    Sonam 				if (md->uid != rp->secure->uid)
    556   9984    Sonam 					rp->request->outcome |=
    557   9984    Sonam 					    RS_ADMINHELD;
    558   9984    Sonam 			}
    559   9984    Sonam 
    560   9984    Sonam 			if ((rp->request->actions & ACT_SPECIAL) ==
    561   9984    Sonam 			    ACT_RESUME) {
    562   9984    Sonam 				if ((rp->request->outcome & RS_ADMINHELD) &&
    563   9984    Sonam 				    !md->admin) {
    564   9984    Sonam 					status = MNOPERM;
    565   9984    Sonam 					goto Return;
    566   9984    Sonam 				}
    567   9984    Sonam 				rp->request->outcome &=
    568   9984    Sonam 				    ~(RS_ADMINHELD|RS_HELD);
    569   9984    Sonam 			}
    570   9984    Sonam 
    571   9984    Sonam 			if ((rp->request->actions & ACT_SPECIAL)
    572   9984    Sonam 			    == ACT_IMMEDIATE) {
    573   9984    Sonam 				if (!md->admin) {
    574   9984    Sonam 					status = MNOPERM;
    575   9984    Sonam 					goto Return;
    576   9984    Sonam 				}
    577   9984    Sonam 				rp->request->outcome |= RS_IMMEDIATE;
    578   9984    Sonam 			}
    579   9984    Sonam 
    580   9984    Sonam 			size = chfiles(rp->request->file_list, Lp_Uid,
    581   9984    Sonam 			    Lp_Gid);
    582   9984    Sonam 			if (size < 0) {
    583   9984    Sonam 				status = MUNKNOWN;
    584   9984    Sonam 				goto Return;
    585   9984    Sonam 			}
    586   9984    Sonam 			if (!(rp->request->outcome & RS_HELD) &&
    587   9984    Sonam 			    size == 0) {
    588   9984    Sonam 				status = MNOPERM;
    589   9984    Sonam 				goto Return;
    590   9984    Sonam 			}
    591   9984    Sonam 
    592   9984    Sonam 			osize = rp->secure->size;
    593   9984    Sonam 			rp->secure->size = size;
    594   9984    Sonam 
    595   9984    Sonam 			if (move_ok == 0) {
    596   9984    Sonam 				char *dest = strdup(r->destination);
    597   9984    Sonam 				if ((status = mv_file(rp, dest)) == MOK)
    598   9984    Sonam 					rp->secure->size = osize;
    599   9984    Sonam 				free(dest);
    600   9984    Sonam 			} else if ((err = validate_request(rp, (char **)0,
    601   9984    Sonam 			    move_ok)) != MOK) {
    602   9984    Sonam 				status = err;
    603   9984    Sonam 				rp->secure->size = osize;
    604   9984    Sonam 			} else {
    605   9984    Sonam 				status = MOK;
    606   9984    Sonam 
    607   9984    Sonam 				if ((rp->request->outcome & RS_IMMEDIATE) ||
    608   9984    Sonam 				    (rp->request->priority != oldr.priority)) {
    609   9984    Sonam 					remover(rp);
    610   9984    Sonam 					insertr(rp);
    611   9984    Sonam 				}
    612   9984    Sonam 
    613   9984    Sonam 				freerequest(&oldr);
    614   9984    Sonam 				(void) putrequest(rp->req_file, rp->request);
    615   9984    Sonam 				/*
    616   9984    Sonam 				 * fix for bugid 1103890.
    617   9984    Sonam 				 * use Putsecure instead.
    618   9984    Sonam 				 */
    619   9984    Sonam 				(void) Putsecure(rp->req_file, rp->secure);
    620   9984    Sonam 			}
    621   9984    Sonam 		}
    622   8448    Sonam 	}
    623   9984    Sonam 
    624   9984    Sonam Return:
    625   9984    Sonam 	if (status != MOK && rp) {
    626   9984    Sonam 		if (r) {
    627   9984    Sonam 			freerequest(r);
    628   9984    Sonam 			*(rp->request) = oldr;
    629   9984    Sonam 		}
    630   9984    Sonam 		if (status != MNOSTART)
    631   9984    Sonam 			(void) putrequest(rp->req_file, rp->request);
    632   8448    Sonam 	}
    633      0   stevel 
    634   9984    Sonam 	if (call_schedule)
    635   9984    Sonam 		maybe_schedule(rp);
    636      0   stevel 
    637   9984    Sonam 	mputm(md, R_END_CHANGE_REQUEST, status, chkprinter_result);
    638      0   stevel }
    639      0   stevel 
    640   9984    Sonam /*
    641   9984    Sonam  * _cancel()
    642   9984    Sonam  *	user may be (host!user)
    643   9984    Sonam  */
    644      0   stevel 
    645      0   stevel static char *
    646      0   stevel _cancel(MESG *md, char *dest, char *user, char *req_id)
    647      0   stevel {
    648   9984    Sonam 	static RSTATUS	*rp;
    649   9984    Sonam 	static char		*s_dest;
    650   9984    Sonam 	static char		*s_user;
    651   9984    Sonam 	static char		*s_req_id;
    652   9984    Sonam 	static int		current;
    653   9984    Sonam 	RSTATUS		*crp;
    654   9984    Sonam 	char		*creq_id;
    655      0   stevel 
    656   9984    Sonam 	syslog(LOG_DEBUG, "_cancel(%s, %s, %s)", (dest ? dest : "NULL"),
    657   9984    Sonam 	    (user ? user : "NULL"), (req_id ? req_id : "NULL"));
    658      0   stevel 
    659   9984    Sonam 	if (dest || user || req_id) {
    660   9984    Sonam 		s_dest = dest;
    661   9984    Sonam 		if (STREQU(user, "!"))
    662   9984    Sonam 			s_user = strdup("all!all");
    663   9984    Sonam 		else
    664   9984    Sonam 			s_user = user;
    665   9984    Sonam 		s_req_id = req_id;
    666   9984    Sonam 		rp = Request_List;
    667   9984    Sonam 		current = 0;
    668   9984    Sonam 		if (STREQU(s_req_id, CURRENT_REQ)) {
    669   9984    Sonam 			current = 1;
    670   9984    Sonam 			s_req_id = NULL;
    671   9984    Sonam 		}
    672      0   stevel 	}
    673      0   stevel 
    674   9984    Sonam 	while (rp != NULL) {
    675   9984    Sonam 		crp = rp;
    676   9984    Sonam 		rp = rp->next;
    677   1676      jpk 
    678   9984    Sonam 		if (*s_dest && !STREQU(s_dest, crp->request->destination))
    679   9984    Sonam 			continue;
    680      0   stevel 
    681   9984    Sonam 		if (current && !(crp->request->outcome & RS_PRINTING))
    682   9984    Sonam 			continue;
    683      0   stevel 
    684   9984    Sonam 		if (s_req_id && *s_req_id &&
    685   9984    Sonam 		    !STREQU(s_req_id, crp->secure->req_id))
    686   9984    Sonam 			continue;
    687      0   stevel 
    688   9984    Sonam 		if (*s_user && !bangequ(s_user, crp->secure->user))
    689   9984    Sonam 			continue;
    690   9984    Sonam 
    691   9984    Sonam 		if (!md->admin && md->uid != crp->secure->uid) {
    692   9984    Sonam 			errno = MNOPERM;
    693   9984    Sonam 			return (Strdup(crp->secure->req_id));
    694   9984    Sonam 		}
    695   9984    Sonam 
    696   9984    Sonam 		/*
    697   9984    Sonam 		 * For Trusted Extensions, we need to check the
    698   9984    Sonam 		 * sensitivity label of the
    699   9984    Sonam 		 * connection and job before we try to cancel it.
    700   9984    Sonam 		 */
    701   9984    Sonam 		if ((md->admin == 0) && (is_system_labeled()) &&
    702   9984    Sonam 		    (md->slabel != NULL) && (crp->secure->slabel != NULL) &&
    703   9984    Sonam 		    (!STREQU(md->slabel, crp->secure->slabel)))
    704   9984    Sonam 			continue;
    705   9984    Sonam 
    706   9984    Sonam 		crp->reason = MOK;
    707   9984    Sonam 		creq_id = Strdup(crp->secure->req_id);
    708   9984    Sonam 
    709   9984    Sonam 		syslog(LOG_DEBUG, "cancel reqid (%s) uid: %d, secureuid: %d",
    710   9984    Sonam 		    creq_id, md->uid, crp->secure->uid);
    711   9984    Sonam 
    712   9984    Sonam 		if (cancel(crp, (md->uid != crp->secure->uid)))
    713   9984    Sonam 			errno = MOK;
    714   9984    Sonam 		else
    715   9984    Sonam 			errno = M2LATE;
    716   9984    Sonam 		return (creq_id);
    717   9984    Sonam 	}
    718   9984    Sonam 
    719   9984    Sonam 	errno = MUNKNOWN;
    720   9984    Sonam 	return (NULL);
    721      0   stevel }
    722      0   stevel 
    723   9984    Sonam /*
    724   9984    Sonam  * s_cancel_request()
    725   9984    Sonam  */
    726      0   stevel 
    727   9984    Sonam void
    728   9984    Sonam s_cancel_request(char *m, MESG *md)
    729      0   stevel {
    730      0   stevel 	char	*req_id, *rid;
    731      0   stevel 	short	status;
    732      0   stevel 
    733      0   stevel 	(void) getmessage(m, S_CANCEL_REQUEST, &req_id);
    734      0   stevel 	syslog(LOG_DEBUG, "s_cancel_request(%s)", (req_id ? req_id : "NULL"));
    735      0   stevel 
    736      0   stevel 	if ((rid = _cancel(md, "", "", req_id)) != NULL)
    737      0   stevel 		Free(rid);
    738      0   stevel 	status = (short)errno;
    739   9984    Sonam 
    740      0   stevel 	mputm(md, R_CANCEL_REQUEST, status);
    741      0   stevel }
    742      0   stevel 
    743   9984    Sonam /*
    744   9984    Sonam  * s_cancel()
    745   9984    Sonam  */
    746      0   stevel 
    747   9984    Sonam void
    748   9984    Sonam s_cancel(char *m, MESG *md)
    749      0   stevel {
    750   9984    Sonam 	char	*req_id;
    751   9984    Sonam 	char	*user;
    752   9984    Sonam 	char	*destination;
    753   9984    Sonam 	char	*rid;
    754   9984    Sonam 	char	*nrid;
    755   9984    Sonam 	int		nerrno;
    756   9984    Sonam 	int		oerrno;
    757      0   stevel 
    758   9984    Sonam 	(void) getmessage(m, S_CANCEL, &destination, &user, &req_id);
    759   9984    Sonam 	syslog(LOG_DEBUG, "s_cancel(%s, %s, %s)",
    760   9984    Sonam 	    (destination ? destination : "NULL"), (user ? user : "NULL"),
    761   9984    Sonam 	    (req_id ? req_id : "NULL"));
    762      0   stevel 
    763   9984    Sonam 	if (STREQU(destination, NAME_ALL))
    764   9984    Sonam 		destination = "";
    765   9984    Sonam 	if (STREQU(req_id, NAME_ALL))
    766   9984    Sonam 		req_id = "";
    767      0   stevel 
    768   9984    Sonam 	if (rid = _cancel(md, destination, user, req_id)) {
    769   9984    Sonam 		oerrno = errno;
    770      0   stevel 
    771   9984    Sonam 		while ((nrid = _cancel(md, NULL, NULL, NULL)) != NULL) {
    772   9984    Sonam 			nerrno = errno;
    773   9984    Sonam 			mputm(md, R_CANCEL, MOKMORE, oerrno, rid);
    774   9984    Sonam 			Free(rid);
    775   9984    Sonam 			rid = nrid;
    776   9984    Sonam 			oerrno = nerrno;
    777   9984    Sonam 		}
    778   9984    Sonam 		mputm(md, R_CANCEL, MOK, oerrno, rid);
    779   9984    Sonam 		Free(rid);
    780   9984    Sonam 		return;
    781      0   stevel 	}
    782      0   stevel 
    783   9984    Sonam 	mputm(md, R_CANCEL, MOK, MUNKNOWN, "");
    784      0   stevel }
    785      0   stevel 
    786      0   stevel /*
    787      0   stevel  * s_inquire_request_rank()
    788      0   stevel  */
    789      0   stevel 
    790   9984    Sonam void
    791   9984    Sonam s_inquire_request_rank(char *m, MESG *md)
    792      0   stevel {
    793      0   stevel 	char		*form;
    794      0   stevel 	char		*dest;
    795      0   stevel 	char		*pwheel;
    796      0   stevel 	char		*user;
    797      0   stevel 	char		*req_id;
    798      0   stevel 	RSTATUS		*rp;
    799      0   stevel 	RSTATUS		*found = NULL;
    800      0   stevel 	int		found_rank = 0;
    801      0   stevel 	short		prop;
    802      0   stevel 	char		files[BUFSIZ];
    803   3125   jacobs 	int 		i;
    804      0   stevel 
    805      0   stevel 	(void) getmessage(m, S_INQUIRE_REQUEST_RANK, &prop, &form, &dest,
    806   9984    Sonam 	    &req_id, &user, &pwheel);
    807      0   stevel 	syslog(LOG_DEBUG, "s_inquire_request_rank(%d, %s, %s, %s, %s, %s)",
    808   9984    Sonam 	    prop, (form ? form : "NULL"), (dest ? dest : "NULL"),
    809   9984    Sonam 	    (req_id ? req_id : "NULL"), (user ? user : "NULL"),
    810   9984    Sonam 	    (pwheel ? pwheel : "NULL"));
    811      0   stevel 
    812   3125   jacobs 	for (i = 0; PStatus != NULL && PStatus[i] != NULL; i++)
    813   3125   jacobs 		PStatus[i]->nrequests = 0;
    814      0   stevel 
    815      0   stevel 	for (rp = Request_List; rp != NULL; rp = rp->next) {
    816      0   stevel 		if (rp->printer && !(rp->request->outcome & RS_DONE))
    817      0   stevel 			rp->printer->nrequests++;
    818      0   stevel 
    819      0   stevel 		if (*form && !SAME(form, rp->request->form))
    820      0   stevel 			continue;
    821      0   stevel 
    822      0   stevel 		if (*dest && !STREQU(dest, rp->request->destination)) {
    823      0   stevel 			if (!rp->printer)
    824      0   stevel 				continue;
    825      0   stevel 			if (!STREQU(dest, rp->printer->printer->name))
    826      0   stevel 				continue;
    827      0   stevel 		}
    828   9984    Sonam 
    829      0   stevel 		if (*req_id && !STREQU(req_id, rp->secure->req_id))
    830      0   stevel 			continue;
    831      0   stevel 
    832      0   stevel 		if (*user && !bangequ(user, rp->secure->user))
    833      0   stevel 			continue;
    834      0   stevel 
    835      0   stevel 		if (*pwheel && !SAME(pwheel, rp->pwheel_name))
    836      0   stevel 			continue;
    837   1676      jpk 		/*
    838   1676      jpk 		 * For Trusted Extensions, we need to check the sensitivity
    839   1676      jpk 		 * label of the connection and job before we return it to the
    840   1676      jpk 		 * client.
    841   1676      jpk 		 */
    842   1676      jpk 		if ((md->admin <= 0) && (is_system_labeled()) &&
    843   1676      jpk 		    (md->slabel != NULL) && (rp->secure->slabel != NULL) &&
    844   1676      jpk 		    (!STREQU(md->slabel, rp->secure->slabel)))
    845   1676      jpk 			continue;
    846      0   stevel 
    847      0   stevel 		if (found) {
    848   9984    Sonam 			GetRequestFiles(found->request, files, sizeof (files));
    849      0   stevel 			mputm(md, R_INQUIRE_REQUEST_RANK,
    850   9984    Sonam 			    MOKMORE,
    851   9984    Sonam 			    found->secure->req_id,
    852   9984    Sonam 			    found->request->user,
    853   9984    Sonam 			    /* bgolden 091996, bug 1257405 */
    854   9984    Sonam 			    found->secure->slabel,
    855   9984    Sonam 			    found->secure->size,
    856   9984    Sonam 			    found->secure->date,
    857   9984    Sonam 			    found->request->outcome,
    858   9984    Sonam 			    found->printer->printer->name,
    859   9984    Sonam 			    (found->form? found->form->form->name : ""),
    860   9984    Sonam 			    NB(found->pwheel_name),
    861   9984    Sonam 			    found_rank,
    862   9984    Sonam 			    files);
    863      0   stevel 		}
    864      0   stevel 		found = rp;
    865      0   stevel 		found_rank = found->printer->nrequests;
    866      0   stevel 	}
    867      0   stevel 
    868      0   stevel 	if (found) {
    869   9984    Sonam 		GetRequestFiles(found->request, files, sizeof (files));
    870      0   stevel 		mputm(md, R_INQUIRE_REQUEST_RANK,
    871   9984    Sonam 		    MOK,
    872   9984    Sonam 		    found->secure->req_id,
    873   9984    Sonam 		    found->request->user, /* bgolden 091996, bug 1257405 */
    874   9984    Sonam 		    found->secure->slabel,
    875   9984    Sonam 		    found->secure->size,
    876   9984    Sonam 		    found->secure->date,
    877   9984    Sonam 		    found->request->outcome,
    878   9984    Sonam 		    found->printer->printer->name,
    879   9984    Sonam 		    (found->form? found->form->form->name : ""),
    880   9984    Sonam 		    NB(found->pwheel_name),
    881   9984    Sonam 		    found_rank,
    882   9984    Sonam 		    files);
    883      0   stevel 	} else
    884   1676      jpk 		mputm(md, R_INQUIRE_REQUEST_RANK, MNOINFO, "", "", "", 0L, 0L,
    885   9984    Sonam 		    0, "", "", "", 0, "");
    886      0   stevel }
    887      0   stevel 
    888      0   stevel static int
    889      0   stevel mv_file(RSTATUS *rp, char *dest)
    890      0   stevel {
    891      0   stevel 	int	stat;
    892      0   stevel 	char	*olddest;
    893      0   stevel 	EXEC	*oldexec;
    894      0   stevel 	SECURE * securep;
    895      0   stevel 	RSTATUS * prs;
    896   9984    Sonam 	char *reqno;
    897      0   stevel 
    898      0   stevel 	oldexec = rp->printer->exec;
    899      0   stevel 	olddest = rp->request->destination;
    900      0   stevel 	rp->request->destination = Strdup(dest);
    901      0   stevel 	if ((stat = validate_request(rp, (char **)0, 1)) == MOK) {
    902      0   stevel 		Free(olddest);
    903      0   stevel 
    904      0   stevel 		if (rp->request->outcome & RS_FILTERED) {
    905      0   stevel 			int cnt = 0;
    906      0   stevel 			char *reqno;
    907      0   stevel 			char **listp;
    908      0   stevel 			char tmp_nam[MAXPATHLEN];
    909      0   stevel 
    910      0   stevel 			reqno = getreqno(rp->secure->req_id);
    911      0   stevel 			for (listp = rp->request->file_list; *listp; listp++) {
    912      0   stevel 				cnt++;
    913      0   stevel 				snprintf(tmp_nam, sizeof (tmp_nam),
    914   9984    Sonam 				    "%s/F%s-%d", Lp_Temp, reqno, cnt);
    915      0   stevel 				unlink(tmp_nam);
    916      0   stevel 
    917      0   stevel 			}
    918      0   stevel 			rp->request->outcome &= ~RS_FILTERED;
    919      0   stevel 		}
    920      0   stevel 
    921      0   stevel 		/* update /var/spool/lp/tmp/<host>/nnn-0 */
    922      0   stevel 		if (putrequest(rp->req_file, rp->request) < 0) {
    923      0   stevel 			note("putrequest failed\n");
    924      0   stevel 			return (MNOMEM);
    925      0   stevel 		}
    926      0   stevel 
    927      0   stevel 		/* update /var/spool/lp/requests/<host>/nnn-0 */
    928      0   stevel 		if ((securep = Getsecure(rp->req_file))) {
    929      0   stevel 			reqno = strdup(getreqno(securep->req_id));
    930      0   stevel 			(void) free(securep->req_id);
    931      0   stevel 			if ((securep->req_id = calloc(strlen(dest) + 1 +
    932   9984    Sonam 			    strlen(reqno) +1, sizeof (char))) == NULL)
    933      0   stevel 				return (MNOMEM);
    934      0   stevel 			(void) sprintf(securep->req_id, "%s-%s", dest, reqno);
    935      0   stevel 			/* remove the old request file; save new one */
    936      0   stevel 			(void) rmsecure(rp->secure->req_id);
    937      0   stevel 			if (Putsecure(rp->req_file, securep) < 0) {
    938      0   stevel 				/* Putsecure includes note/errmessage */
    939      0   stevel 				return (MNOMEM);
    940      0   stevel 			}
    941      0   stevel 		} else {
    942      0   stevel 			note("Getsecure failed\n");
    943      0   stevel 			return (MNOMEM);
    944      0   stevel 		}
    945      0   stevel 
    946      0   stevel 		/* update internal jobs list: Request_list */
    947      0   stevel 		if (prs = request_by_id(rp->secure->req_id)) {
    948      0   stevel 			free(prs->secure->req_id);
    949      0   stevel 			prs->secure->req_id = strdup(securep->req_id);
    950      0   stevel 
    951      0   stevel 			/*
    952      0   stevel 			 * We calloc'd securep->reqid earlier, now we free it
    953      0   stevel 			 * here because we no longer call 'freesecure' from
    954      0   stevel 			 * Putsecure() if we use a static structure
    955      0   stevel 			 */
    956      0   stevel 
    957      0   stevel 			free(securep->req_id);
    958      0   stevel 		} else {
    959      0   stevel 			note("request_by_id failed\n");
    960      0   stevel 			return (MUNKNOWN);
    961      0   stevel 		}
    962      0   stevel 
    963      0   stevel 		/*
    964      0   stevel 		 * If the request was being filtered or was printing,
    965      0   stevel 		 * it would have been stopped in "validate_request()",
    966      0   stevel 		 * but only if it has to be refiltered. Thus, the
    967      0   stevel 		 * filtering has been stopped if it has to be stopped,
    968      0   stevel 		 * but the printing may still be going.
    969      0   stevel 		 */
    970      0   stevel 		if (rp->request->outcome & RS_PRINTING &&
    971      0   stevel 		    !(rp->request->outcome & RS_STOPPED)) {
    972      0   stevel 			rp->request->outcome |= RS_STOPPED;
    973   9984    Sonam 			terminate(oldexec);
    974   9984    Sonam 		}
    975      0   stevel 
    976      0   stevel 		maybe_schedule(rp);
    977      0   stevel 		return (MOK);
    978      0   stevel 	}
    979      0   stevel 
    980      0   stevel 	Free(rp->request->destination);
    981      0   stevel 	rp->request->destination = olddest;
    982      0   stevel 	return (stat);
    983      0   stevel }
    984      0   stevel 
    985      0   stevel /*
    986      0   stevel  * s_move_request()
    987      0   stevel  */
    988      0   stevel 
    989   9984    Sonam void
    990   9984    Sonam s_move_request(char *m, MESG *md)
    991      0   stevel {
    992      0   stevel 	RSTATUS	*rp;
    993      0   stevel 	short	err;
    994      0   stevel 	char	*req_id;
    995      0   stevel 	char	*dest;
    996      0   stevel 
    997      0   stevel 	(void) getmessage(m, S_MOVE_REQUEST, &req_id, &dest);
    998      0   stevel 	syslog(LOG_DEBUG, "s_move_request(%s, %s)", (req_id ? req_id : "NULL"),
    999   9984    Sonam 	    (dest ? dest : "NULL"));
   1000      0   stevel 
   1001      0   stevel 
   1002   3125   jacobs 	if (!(search_pstatus(dest)) && !(search_cstatus(dest))) {
   1003      0   stevel 		mputm(md, R_MOVE_REQUEST, MNODEST, 0L);
   1004      0   stevel 		return;
   1005      0   stevel 	}
   1006      0   stevel 
   1007      0   stevel 	if ((rp = request_by_id(req_id))) {
   1008      0   stevel 		if (STREQU(rp->request->destination, dest)) {
   1009      0   stevel 			mputm(md, R_MOVE_REQUEST, MOK, 0L);
   1010      0   stevel 			return;
   1011      0   stevel 		}
   1012      0   stevel 		if (rp->request->outcome & (RS_DONE|RS_NOTIFYING)) {
   1013      0   stevel 			mputm(md, R_MOVE_REQUEST, M2LATE, 0L);
   1014      0   stevel 			return;
   1015      0   stevel 		}
   1016      0   stevel 		if (rp->request->outcome & RS_CHANGING)	{
   1017      0   stevel 			mputm(md, R_MOVE_REQUEST, MBUSY, 0L);
   1018      0   stevel 			return;
   1019      0   stevel 		}
   1020      0   stevel 		if ((err = mv_file(rp, dest)) == MOK) {
   1021      0   stevel 			mputm(md, R_MOVE_REQUEST, MOK, 0L);
   1022      0   stevel 			return;
   1023      0   stevel 		}
   1024      0   stevel 		mputm(md, R_MOVE_REQUEST, err, chkprinter_result);
   1025      0   stevel 		return;
   1026      0   stevel 	}
   1027      0   stevel 	mputm(md, R_MOVE_REQUEST, MUNKNOWN, 0L);
   1028      0   stevel }
   1029      0   stevel 
   1030   9984    Sonam /*
   1031   9984    Sonam  * s_move_dest()
   1032   9984    Sonam  */
   1033      0   stevel 
   1034   9984    Sonam void
   1035   9984    Sonam s_move_dest(char *m, MESG *md)
   1036      0   stevel {
   1037   9984    Sonam 	char		*dest;
   1038   9984    Sonam 	char		*fromdest;
   1039   9984    Sonam 	RSTATUS		*rp;
   1040   9984    Sonam 	char		*found = (char *)0;
   1041   9984    Sonam 	short		num_ok = 0;
   1042      0   stevel 
   1043   9984    Sonam 	(void) getmessage(m, S_MOVE_DEST, &fromdest, &dest);
   1044   9984    Sonam 	syslog(LOG_DEBUG, "s_move_dest(%s, %s)", (fromdest ? fromdest : "NULL"),
   1045   9984    Sonam 	    (dest ? dest : "NULL"));
   1046      0   stevel 
   1047   9984    Sonam 	if (!search_pstatus(fromdest) && !search_cstatus(fromdest)) {
   1048   9984    Sonam 		mputm(md, R_MOVE_DEST, MNODEST, fromdest, 0);
   1049   9984    Sonam 		return;
   1050   9984    Sonam 	}
   1051      0   stevel 
   1052   9984    Sonam 	if (!(search_pstatus(dest)) && !(search_cstatus(dest))) {
   1053   9984    Sonam 		mputm(md, R_MOVE_DEST, MNODEST, dest, 0);
   1054   9984    Sonam 		return;
   1055   9984    Sonam 	}
   1056      0   stevel 
   1057   9984    Sonam 	if (STREQU(dest, fromdest)) {
   1058   9984    Sonam 		mputm(md, R_MOVE_DEST, MOK, "", 0);
   1059   9984    Sonam 		return;
   1060   9984    Sonam 	}
   1061      0   stevel 
   1062   9984    Sonam 	for (rp = Request_List; rp != NULL; rp = rp->next) {
   1063   9984    Sonam 		if ((STREQU(rp->request->destination, fromdest)) &&
   1064   9984    Sonam 		    (!(rp->request->outcome &
   1065   9984    Sonam 		    (RS_DONE|RS_CHANGING|RS_NOTIFYING)))) {
   1066   9984    Sonam 			if (mv_file(rp, dest) == MOK) {
   1067   9984    Sonam 				num_ok++;
   1068   9984    Sonam 				continue;
   1069   9984    Sonam 			}
   1070   9984    Sonam 		}
   1071   9984    Sonam 
   1072   9984    Sonam 		if (found)
   1073   9984    Sonam 			mputm(md, R_MOVE_DEST, MMORERR, found, 0);
   1074   9984    Sonam 
   1075   9984    Sonam 		found = rp->secure->req_id;
   1076      0   stevel 	}
   1077      0   stevel 
   1078      0   stevel 	if (found)
   1079   9984    Sonam 		mputm(md, R_MOVE_DEST, MERRDEST, found, num_ok);
   1080   9984    Sonam 	else
   1081   9984    Sonam 		mputm(md, R_MOVE_DEST, MOK, "", num_ok);
   1082      0   stevel }
   1083      0   stevel 
   1084   9984    Sonam /*
   1085   9984    Sonam  * reqpath
   1086   9984    Sonam  */
   1087      0   stevel 
   1088      0   stevel static char *
   1089      0   stevel reqpath(char *file, char **idnumber)
   1090      0   stevel {
   1091   9984    Sonam 	char	*path;
   1092   9984    Sonam 	char	*cp;
   1093   9984    Sonam 	char	*cp2;
   1094      0   stevel 
   1095   9984    Sonam 	/*
   1096   9984    Sonam 	 *	/var/spool/lp/tmp/machine/123-0
   1097   9984    Sonam 	 *	/var/spool/lp/temp/123-0
   1098   9984    Sonam 	 *	/usr/spool/lp/temp/123-0
   1099   9984    Sonam 	 *	/usr/spool/lp/tmp/machine/123-0
   1100   9984    Sonam 	 *	123-0
   1101   9984    Sonam 	 *	machine/123-0
   1102   9984    Sonam 	 *
   1103   9984    Sonam 	 *	/var/spool/lp/tmp/machine/123-0 + 123
   1104   9984    Sonam 	 */
   1105   9984    Sonam 	if (*file == '/') {
   1106   9984    Sonam 		/*CONSTCOND*/
   1107   9984    Sonam 		if (STRNEQU(file, Lp_Spooldir, strlen(Lp_Spooldir)))
   1108   9984    Sonam 			cp = file + strlen(Lp_Spooldir) + 1;
   1109   9984    Sonam 		else {
   1110   9984    Sonam 			if (STRNEQU(file, "/usr/spool/lp", 13))
   1111   9984    Sonam 				cp = file + strlen("/usr/spool/lp") + 1;
   1112   9984    Sonam 			else {
   1113   9984    Sonam 				*idnumber = NULL;
   1114   9984    Sonam 				return (NULL);
   1115   9984    Sonam 			}
   1116   9984    Sonam 		}
   1117   9984    Sonam 
   1118   9984    Sonam 		if (STRNEQU(cp, "temp", 4)) {
   1119   9984    Sonam 			cp += 5;
   1120   9984    Sonam 			path = makepath(Local_System, cp, NULL);
   1121   9984    Sonam 		}
   1122   9984    Sonam 		else
   1123   9984    Sonam 			path = Strdup(cp);
   1124      0   stevel 	}
   1125      0   stevel 	else
   1126   9984    Sonam 	{
   1127   9984    Sonam 		if (strchr(file, '/'))
   1128   9984    Sonam 			path = makepath(file, NULL);
   1129   9984    Sonam 		else
   1130   9984    Sonam 			path = makepath(Local_System, file, NULL);
   1131   9984    Sonam 	}
   1132   9984    Sonam 
   1133   9984    Sonam 	cp = strrchr(path, '/');
   1134   9984    Sonam 	cp++;
   1135   9984    Sonam 	if ((cp2 = strrchr(cp, '-')) == NULL)
   1136   9984    Sonam 		*idnumber = Strdup(cp);
   1137      0   stevel 	else
   1138   9984    Sonam 	{
   1139   9984    Sonam 		*cp2 = '\0';
   1140   9984    Sonam 		*idnumber = Strdup(cp);
   1141   9984    Sonam 		*cp2 = '-';
   1142   9984    Sonam 	}
   1143      0   stevel 
   1144   9984    Sonam 	return (path);
   1145      0   stevel }
   1146   1676      jpk 
   1147   1676      jpk /*
   1148   5331      amw  * The client is sending a peer connection to retrieve label information
   1149   1676      jpk  * from.  This is used in the event that the client is an intermediary for
   1150   1676      jpk  * the actual requestor in a Trusted environment.
   1151   1676      jpk  */
   1152   9984    Sonam void
   1153   9984    Sonam s_pass_peer_connection(char *m, MESG *md)
   1154   1676      jpk {
   1155   1676      jpk 	short	status = MTRANSMITERR;
   1156   1676      jpk 	char	*dest;
   1157   1676      jpk 	struct strrecvfd recv_fd;
   1158   1676      jpk 
   1159   1676      jpk 	(void) getmessage(m, S_PASS_PEER_CONNECTION);
   1160   1676      jpk 	syslog(LOG_DEBUG, "s_pass_peer_connection()");
   1161   1676      jpk 
   1162   1676      jpk 	memset(&recv_fd, NULL, sizeof (recv_fd));
   1163   1676      jpk 	if (ioctl(md->readfd, I_RECVFD, &recv_fd) == 0) {
   1164   1676      jpk 		int fd = recv_fd.fd;
   1165   1676      jpk 
   1166   1676      jpk 		if (get_peer_label(fd, &md->slabel) == 0) {
   1167   1676      jpk 			if (md->admin == 1)
   1168   1676      jpk 				md->admin = -1; /* turn off query privilege */
   1169   1676      jpk 			status = MOK;
   1170   1676      jpk 		}
   1171   1676      jpk 
   1172   1676      jpk 		close(fd);
   1173   1676      jpk 	}
   1174   1676      jpk 
   1175   1676      jpk 	mputm(md, R_PASS_PEER_CONNECTION, status);
   1176   1676      jpk }
   1177