Ejemplo n.º 1
0
int				be_almost_sorted_2(t_lst *l, t_options *options, int *tri)
{
	t_elem	*tmp;
	t_elem	*switch_next;
	int		count;

	tmp = (l->a)->head;
	switch_next = NULL;
	count = 0;
	while (tmp != NULL)
	{
		if (tmp->next != NULL && NB(tmp)->n > NB(tmp->next)->n)
			count++;
		if (count > 0)
			return (0);
		tmp = tmp->next;
	}
	sa(l);
	if (options->v == 1)
		show_piles(l, "sa");
	rra(l);
	if (options->v == 1)
		show_piles(l, "rra");
	*tri = 1;
	return (1);
}
Ejemplo n.º 2
0
int				a_is_almost_sorted(t_lst *l, t_options *options, int *tri)
{
	t_elem	*tmp;
	t_elem	*first;
	t_elem	*second;
	int		count;

	tmp = (l->a)->head;
	first = NULL;
	second = NULL;
	count = 0;
	while (tmp != NULL)
	{
		if (tmp->next != NULL && NB(tmp)->n < NB(tmp->next)->n)
		{
			first = tmp;
			second = tmp->next;
			count++;
		}
		tmp = tmp->next;
	}
	if (count != 1 || !(check_next_second(first, second))
		|| !(check_prev_first(first, second)))
		return (0);
	switch_and_sort(l, second, options);
	*tri = 4;
	return (1);
}
Ejemplo n.º 3
0
void _$Nprelude(int *argc, char ***argv, char ***env) {
  atexit(_$Npostlude);

  struct NLANG_CREF() cref_sysheap = {
    .ref = (void *) &n$builtins$sysheap,
    .cnt = &n$builtins$sysheap_cnt,
  };
  *cref_sysheap.cnt = 1;

  sysheap_header.Env = NLANG_MKCDYN(struct _$Ncdyn_n$builtins$_$Ni_Heap,
                                    &n$mem$Sysheap$Dyntable__n$builtins$_$Ni_Heap,
                                    cref_sysheap);
  sysheap_header.Parent = NULL;
  n$builtins$Install_sysheap(&sysheap_header);

  {
    // It's a pretty useless signal.
    struct sigaction act = { 0 };
    act.sa_handler = SIG_IGN;
    (void)sigaction(SIGPIPE, &act, NULL);
  }

  n$stdio$Install_sys();
  n$logging$Install_sys();
  n$env$Install_sys(*argc, (NB(U8) **) *argv);
  n$time$Install_sys();
  n$fs$Install_sys();
  n$math$rand$Install_sys();
  n$crypto$cryptorand$Install_sys();
}

extern struct NB(Error) _$Nmain(void);

int _$Ninvoke_main(void) {
  return NB(Main_except)(_$Nmain());
}

// This is available to _$Npostlude and is both set by main() using the return
// value of _$Nmain() (aka. Main), and by n.builtins.Exit (but not by
// syscall.Exit).
int NB(last_exit_code);

void NB(Exit)(NB(I32) status) {
  NB(last_exit_code) = status;
  exit(status);
}

void _$Npostlude(void) {
  n$stdio$Uninstall_sys();
}
Ejemplo n.º 4
0
void
fdprintsdn(int fd, SCALED sdn)
{
	register char		*dec = "9999.999",
				*z;

	if (sdn.val <= 0)
		return;

	(void)fdprintf (fd, "%s", NB(print_prefix));

	/*
	 * Let's try to be a bit clever in dealing with decimal
	 * numbers. If the number is an integer, don't print
	 * a decimal point. If it isn't an integer, strip trailing
	 * zeros from the fraction part, and don't print more
	 * than the thousandths place.
	 */
	if (-1000. < sdn.val && sdn.val < 10000.) {

		/*
		 * Printing 0 will give us 0.000.
		 */
		sprintf (dec, "%.3f", sdn.val);

		/*
		 * Skip zeroes from the end until we hit
		 * '.' or not-0. If we hit '.', clobber it;
		 * if we hit not-0, it has to be in fraction
		 * part, so leave it.
		 */
		z = dec + strlen(dec) - 1;
		while (*z == '0' && *z != '.')
			z--;
		if (*z == '.')
			*z = '\0';
		else
			*++z = '\0';

		(void)fdprintf(fd, "%s", dec);

	} else
		(void)fdprintf(fd, "%.3f", sdn.val);

	if (sdn.sc == 'i' || sdn.sc == 'c')
		fdputc(sdn.sc, fd);

	(void)fdprintf(fd, "%s%s", NB(print_suffix), NB(print_newline));
	return;
}
Ejemplo n.º 5
0
int main (void) 
{
	double Hn[100];
	double Pn[100];
	double k, c, a, x;
	int n, i;
	printf("how many generations?");
	scanf("%d", &n);
	printf("a?");
	scanf("%lf", &a);
	printf("c?");
	scanf("%lf", &c);
	printf("k?");
	scanf("%lf", &k);
	printf("initial host?");
	scanf("%lf", &Hn[0]);
	printf("initial parasite");
	scanf("%lf", &Pn[0]);
	 
	x = NB(Hn, Pn, k, c, a, n);
	
	printf("Gen       Host    Parasitoid\n");
		for (i=0; i<n; i++)
		printf("%3d  %9.4lf  %12.4lf\n", i+1, Hn[i], x);
	
	
	return 0;
		
}
Ejemplo n.º 6
0
void		print_map(t_box *box)
{
	int				y;
	int				x;
	static int		boul;

	if ((y = -1) && boul == 1)
	{
		ft_putstr_fd("\033[", 2);
		NB(box->ord + 1, 2);
		C('A', 2);
	}
	while (++y < box->ord && (x = -1))
	{
		while (++x < box->abs)
		{
			if (box->map[y][x] == box->player)
				ft_putstr_fd("\033[36m", 2);
			if (box->map[y][x] == box->ennemy)
				ft_putstr_fd("\033[32m", 2);
			C(box->map[y][x], 2);
			ft_putstr_fd("\033[0m", 2);
		}
		C('\n', 2);
	}
	boul = 1;
	C('\n', 2);
}
Ejemplo n.º 7
0
static int		check_prev_first(t_elem *first, t_elem *second)
{
	t_elem	*tmp;

	tmp = NULL;
	if (first->prev)
		tmp = first->prev;
	else
		return (1);
	while (tmp != NULL)
	{
		if (tmp != second && NB(first)->n > NB(tmp)->n)
			return (0);
		tmp = tmp->prev;
	}
	return (1);
}
Ejemplo n.º 8
0
static int		check_next_second(t_elem *first, t_elem *second)
{
	t_elem	*tmp;

	tmp = NULL;
	if (second->next)
		tmp = second->next;
	else
		return (1);
	while (tmp != NULL)
	{
		if (tmp != second && NB(first)->n < NB(tmp)->n)
			return (0);
		tmp = tmp->next;
	}
	return (1);
}
Ejemplo n.º 9
0
t_elem	*find_min(t_dbllist **pile)
{
	t_elem	*tmp;
	t_elem	*min;

	tmp = NULL;
	min = NULL;
	if ((*pile)->length < 1)
		return (NULL);
	tmp = (*pile)->head;
	min = (*pile)->head;
	while (tmp != NULL)
	{
		if (tmp->next != NULL && NB(min)->n > NB(tmp->next)->n)
			min = tmp->next;
		tmp = tmp->next;
	}
	return (min);
}
Ejemplo n.º 10
0
void
s_disable_dest(char *m, MESG *md)
{
	char			*destination,
				*reason,
				*req_id		= 0;
	ushort			when,
				status;
	register PSTATUS	*pps;

	getmessage (m, S_DISABLE_DEST, &destination, &reason, &when);
	syslog(LOG_DEBUG, "s_disable_dest(%s, %s, %d)",
	       (destination ? destination : "NULL"),
	       (reason ? reason : "NULL"), when);


	/*
	 * Have we seen this printer before?
	 */
	if ((pps = search_ptable(destination))) {

		/*
		 * If we are to cancel a currently printing request,
		 * we will send back the request's ID.
		 * Save a copy of the ID before calling "disable()",
		 * in case the disabling loses it (e.g. the request
		 * might get attached to another printer). (Actually,
		 * the current implementation won't DETACH the request
		 * from this printer until the child process responds,
		 * but a future implementation might.)
		 */
		if (pps->request && when == 2)
			req_id = Strdup(pps->request->secure->req_id);

		if (disable(pps, reason, (int)when) == -1) {
			if (req_id) {
				Free (req_id);
				req_id = 0;
			}
			status = MERRDEST;
		} else
			status = MOK;

	} else
		status = MNODEST;

	mputm (md, R_DISABLE_DEST, status, NB(req_id));
	if (req_id)
		Free (req_id);

	return;
}
Ejemplo n.º 11
0
Archivo: n.n.c Proyecto: nanocritical/n
#include <unistd.h>

#ifdef NLANG_DEFINE_FUNCTIONS

#define NB(x) n$builtins$##x

static void n$write_buf(NB(I32) fd, NB(U8) *s, NB(Uint) count) {
  write(fd, s, count);
}

#undef NB

#endif
Ejemplo n.º 12
0
	.name = "pxa2xx-ac97"
};

void __init mxm_8x10_ac97_init(void)
{
	platform_device_register(&mxm_8x10_ac97_device);
}

/* NAND flash Support */
#if defined(CONFIG_MTD_NAND_PXA3xx) || defined(CONFIG_MTD_NAND_PXA3xx_MODULE)
#define NAND_BLOCK_SIZE SZ_128K
#define NB(x)           (NAND_BLOCK_SIZE * (x))
static struct mtd_partition mxm_8x10_nand_partitions[] = {
	[0] = {
	       .name = "boot",
	       .size = NB(0x002),
	       .offset = NB(0x000),
	       .mask_flags = MTD_WRITEABLE
	},
	[1] = {
	       .name = "kernel",
	       .size = NB(0x010),
	       .offset = NB(0x002),
	       .mask_flags = MTD_WRITEABLE
	},
	[2] = {
	       .name = "root",
	       .size = NB(0x36c),
	       .offset = NB(0x012)
	},
	[3] = {
Ejemplo n.º 13
0
void
s_inquire_request_rank(char *m, MESG *md)
{
	char		*form;
	char		*dest;
	char		*pwheel;
	char		*user;
	char		*req_id;
	RSTATUS		*rp;
	RSTATUS		*found = NULL;
	int		found_rank = 0;
	short		prop;
	char		files[BUFSIZ];
	int 		i;

	(void) getmessage(m, S_INQUIRE_REQUEST_RANK, &prop, &form, &dest,
	    &req_id, &user, &pwheel);
	syslog(LOG_DEBUG, "s_inquire_request_rank(%d, %s, %s, %s, %s, %s)",
	    prop, (form ? form : "NULL"), (dest ? dest : "NULL"),
	    (req_id ? req_id : "NULL"), (user ? user : "******"),
	    (pwheel ? pwheel : "NULL"));

	for (i = 0; PStatus != NULL && PStatus[i] != NULL; i++)
		PStatus[i]->nrequests = 0;

	for (rp = Request_List; rp != NULL; rp = rp->next) {
		if (rp->printer && !(rp->request->outcome & RS_DONE))
			rp->printer->nrequests++;

		if (*form && !SAME(form, rp->request->form))
			continue;

		if (*dest && !STREQU(dest, rp->request->destination)) {
			if (!rp->printer)
				continue;
			if (!STREQU(dest, rp->printer->printer->name))
				continue;
		}

		if (*req_id && !STREQU(req_id, rp->secure->req_id))
			continue;

		if (*user && !bangequ(user, rp->secure->user))
			continue;

		if (*pwheel && !SAME(pwheel, rp->pwheel_name))
			continue;
		/*
		 * For Trusted Extensions, we need to check the sensitivity
		 * label of the connection and job before we return it to the
		 * client.
		 */
		if ((md->admin <= 0) && (is_system_labeled()) &&
		    (md->slabel != NULL) && (rp->secure->slabel != NULL) &&
		    (!STREQU(md->slabel, rp->secure->slabel)))
			continue;

		if (found) {
			GetRequestFiles(found->request, files, sizeof (files));
			mputm(md, R_INQUIRE_REQUEST_RANK,
			    MOKMORE,
			    found->secure->req_id,
			    found->request->user,
			    /* bgolden 091996, bug 1257405 */
			    found->secure->slabel,
			    found->secure->size,
			    found->secure->date,
			    found->request->outcome,
			    found->printer->printer->name,
			    (found->form? found->form->form->name : ""),
			    NB(found->pwheel_name),
			    found_rank,
			    files);
		}
		found = rp;
		found_rank = found->printer->nrequests;
	}

	if (found) {
		GetRequestFiles(found->request, files, sizeof (files));
		mputm(md, R_INQUIRE_REQUEST_RANK,
		    MOK,
		    found->secure->req_id,
		    found->request->user, /* bgolden 091996, bug 1257405 */
		    found->secure->slabel,
		    found->secure->size,
		    found->secure->date,
		    found->request->outcome,
		    found->printer->printer->name,
		    (found->form? found->form->form->name : ""),
		    NB(found->pwheel_name),
		    found_rank,
		    files);
	} else
		mputm(md, R_INQUIRE_REQUEST_RANK, MNOINFO, "", "", "", 0L, 0L,
		    0, "", "", "", 0, "");
}
Ejemplo n.º 14
0
void
s_print_request(char *m, MESG *md)
{
	extern char		*Local_System;
	char			*file;
	char			*idno;
	char			*path;
	char			*req_file;
	char			*req_id	= 0;
	RSTATUS			*rp;
	REQUEST			*r;
	SECURE			*s;
	struct passwd		*pw;
	short			err;
	short			status;
	off_t			size;
	uid_t			org_uid;
	gid_t			org_gid;
#ifdef LP_USE_PAPI_ATTR
	struct stat		tmpBuf;
	char 			tmpName[BUFSIZ];
#endif


	(void) getmessage(m, S_PRINT_REQUEST, &file);
	syslog(LOG_DEBUG, "s_print_request(%s)", (file ? file : "NULL"));

	/*
	 * "NewRequest" points to a request that's not yet in the
	 * request list but is to be considered with the rest of the
	 * requests (e.g. calculating # of requests awaiting a form).
	 */
	if ((rp = NewRequest = new_rstatus(NULL, NULL)) == NULL)
		status = MNOMEM;

	else
	{
		req_file = reqpath(file, &idno);
		path = makepath(Lp_Tmp, req_file, (char *)0);
		(void) chownmod(path, Lp_Uid, Lp_Gid, 0644);
		Free(path);

		if (!(r = Getrequest(req_file)))
			status = MNOOPEN;

		else
		{
			rp->req_file = Strdup(req_file);

			freerequest(rp->request);
			rp->request = r;

			rp->request->outcome = 0;
			rp->secure->uid = md->uid;
			rp->secure->gid = md->gid;
			if (md->slabel != NULL)
				rp->secure->slabel = Strdup(md->slabel);

			pw = getpwuid(md->uid);
			endpwent();
			if (pw && pw->pw_name && *pw->pw_name)
				rp->secure->user = Strdup(pw->pw_name);
			else {
				rp->secure->user = Strdup(BIGGEST_NUMBER_S);
				(void) sprintf(rp->secure->user, "%u",
				    md->uid);
			}

			if ((rp->request->actions & ACT_SPECIAL) == ACT_HOLD)
				rp->request->outcome |= RS_HELD;
			if ((rp->request->actions & ACT_SPECIAL) == ACT_RESUME)
				rp->request->outcome &= ~RS_HELD;
			if ((rp->request->actions & ACT_SPECIAL) ==
			    ACT_IMMEDIATE) {
				if (!md->admin) {
					status = MNOPERM;
					goto Return;
				}
				rp->request->outcome |= RS_IMMEDIATE;
			}

			size = chfiles(rp->request->file_list, Lp_Uid, Lp_Gid);

			if (size < 0) {
				/*
				 * at this point, chfiles() may have
				 * failed because the file may live on
				 * an NFS mounted filesystem, under
				 * a directory of mode 700. such a
				 * directory isn't accessible even by
				 * root, according to the NFS protocol
				 * (i.e. the Stat() in chfiles() failed).
				 * this most commonly happens via the
				 * automounter, and rlogin. thus we
				 * change our euid/egid to that of the
				 * user, and try again. if *this* fails,
				 * then the file must really be
				 * inaccessible.
				 */
				org_uid = geteuid();
				org_gid = getegid();

				if (setegid(md->gid) != 0) {
					status = MUNKNOWN;
					goto Return;
				}

				if (seteuid(md->uid) != 0) {
					setgid(org_gid);
					status = MUNKNOWN;
					goto Return;
				}

				size = chfiles(rp->request->file_list,
				    Lp_Uid, Lp_Gid);

				if (seteuid(org_uid) != 0) {
					/* should never happen */
					note("s_print_request(): ");
					note("seteuid back to uid=%d "
					    "failed!!\n", org_uid);
					size = -1;
				}

				if (setegid(org_gid) != 0) {
					/* should never happen */
					note("s_print_request(): ");
					note("setegid back to uid=%d "
					    "failed!!\n", org_uid);
					size = -1;
				}

				if (size < 0) {
					status = MUNKNOWN;
					goto Return;
				}
			}
			if (!(rp->request->outcome & RS_HELD) && size == 0) {
				status = MNOPERM;
				goto Return;
			}
			rp->secure->size = size;

			(void) time(&rp->secure->date);
			rp->secure->req_id = NULL;

			if (!rp->request->title) {
				if (strlen(*rp->request->file_list) <
				    (size_t)24)
					rp->request->title =
					    Strdup(*rp->request->file_list);
				else {
					char *r;
					if (r = strrchr(
					    *rp->request->file_list, '/'))
						r++;
					else
						r = *rp->request->file_list;

					rp->request->title = malloc(25);
					sprintf(rp->request->title,
					    "%-.24s", r);
				}
			}

			if ((err = validate_request(rp, &req_id, 0)) != MOK)
				status = err;
			else {
				/*
				 * "req_id" will be supplied if this is from a
				 * remote system.
				 */
				if (rp->secure->req_id == NULL) {
					req_id = makestr(req_id, "-",
					    idno, (char *)0);
					rp->secure->req_id = req_id;
				} else
					req_id = rp->secure->req_id;

#ifdef LP_USE_PAPI_ATTR
				/*
				 * Check if the PAPI job attribute file
				 * exists, if it does change the
				 * permissions and ownership of the file.
				 * This file is created when print jobs
				 * are submitted via the PAPI interface,
				 * the file pathname of this file is
				 * passed to the slow-filters and printer
				 * interface script as an environment
				 * variable when they are executed
				 */
				snprintf(tmpName, sizeof (tmpName),
				    "%s-%s", idno, LP_PAPIATTRNAME);
				path = makepath(Lp_Temp, tmpName, (char *)0);

				if (stat(path, &tmpBuf) == 0) {
					syslog(LOG_DEBUG,
					    "s_print_request: "\
					    "attribute file ='%s'", path);

					/*
					 * IPP job attribute file exists
					 * for this job so change
					 * permissions and ownership of
					 * the file
					 */
					(void) chownmod(path, Lp_Uid,
					    Lp_Gid, 0644);
					Free(path);
				}
				else
				{
					syslog(LOG_DEBUG,
					    "s_print_request: "\
					    "no attribute file");
				}
#endif

				/*
				 * fix for bugid 1103890.
				 * use Putsecure instead.
				 */
				if ((Putsecure(req_file, rp->secure) == -1) ||
				    (putrequest(req_file, rp->request) == -1))
					status = MNOMEM;
				else
				{
					status = MOK;

					insertr(rp);
					NewRequest = 0;

					if (rp->slow)
						schedule(EV_SLOWF, rp);
					else
						schedule(EV_INTERF,
						    rp->printer);

					del_flt_act(md, FLT_FILES);
				}
			}
		}
	}

Return:
	NewRequest = 0;
	Free(req_file);
	Free(idno);
	if (status != MOK && rp) {
		rmfiles(rp, 0);
		free_rstatus(rp);
	}
	mputm(md, R_PRINT_REQUEST, status, NB(req_id), chkprinter_result);
}
Ejemplo n.º 15
0
/*VARARGS1*/
int
exec(int type, ...)
{
	va_list			args;

	int			i;
	int			procuid;
	int			procgid;
	int			ret;
	int			fr_flg;

	char			*cp;
	char			*infile;
	char			*outfile;
	char			*errfile;
	char			*sep;

	char			**listp;
	char			**file_list;
	char			*printerName;
	char			*printerNameToShow;
	static char		nameBuf[100];
	char			*clean_title;

	PSTATUS			*printer;

	RSTATUS			*request;

	FSTATUS			*form;

	EXEC			*ep;

	PWSTATUS		*pwheel;
	time_t			now;
	struct passwd		*pwp;
#ifdef LP_USE_PAPI_ATTR
	struct stat		tmpBuf;
	char 			tmpName[BUFSIZ];
	char			*path = NULL;
#endif
	char *av[ARG_MAX];
	char **envp = NULL;
	int ac = 0;
	char	*mail_zonename = NULL;
	char	*slabel = NULL;

	syslog(LOG_DEBUG, "exec(%s)", _exec_name(type));

	memset(av, 0, sizeof (*av));

	va_start (args, type);

	switch (type) {

	case EX_INTERF:
		printer = va_arg(args, PSTATUS *);
		request = printer->request;
		ep = printer->exec;
		break;
		
	case EX_FAULT_MESSAGE:
		printer = va_arg(args, PSTATUS *);
		request = va_arg(args, RSTATUS *);
		if (! ( printer->status & (PS_FORM_FAULT | PS_SHOW_FAULT))) {
			return(0);
		}
		ep = printer->fault_exec;
		printerName = (printer->printer && printer->printer->name 
				  ? printer->printer->name : "??");
			snprintf(nameBuf, sizeof (nameBuf),
				"%s (on %s)\n", printerName, Local_System);

		printerNameToShow = nameBuf;

		(void) time(&now);
		(void) strftime(time_buf, sizeof (time_buf),
			NULL, localtime(&now));
		break;

	case EX_SLOWF:
		request = va_arg(args, RSTATUS *);
		ep = request->exec;
		break;

	case EX_NOTIFY:
		request = va_arg(args, RSTATUS *);
		if (request->request->actions & ACT_NOTIFY) {
			errno = EINVAL;
			return (-1);
		}
		ep = request->exec;
		break;

	case EX_ALERT:
		printer = va_arg(args, PSTATUS *);
		if (!(printer->printer->fault_alert.shcmd)) {
			errno = EINVAL;
			return(-1);
		}
		ep = printer->alert->exec;
		break;

	case EX_PALERT:
		pwheel = va_arg(args, PWSTATUS *);
		ep = pwheel->alert->exec;
		break;

	case EX_FORM_MESSAGE:
		(void) time(&now);
		(void) strftime(time_buf, sizeof (time_buf),
			NULL, localtime(&now));

		/*FALLTHRU*/
	case EX_FALERT:
		form = va_arg(args, FSTATUS *);
		ep = form->alert->exec;
		break;

	default:
		errno = EINVAL;
		return(-1);

	}
	va_end (args);

	if (!ep || (ep->pid > 0)) {
		errno = EBUSY;
		return(-1);
	}

	ep->flags = 0;

	key = ep->key = getkey();

	switch ((ep->pid = Fork1(ep))) {

	case -1:
		relock ();
		return(-1);

	case 0:
		/*
		 * We want to be able to tell our parent how we died.
		 */
		lp_alloc_fail_handler = child_mallocfail;
		break;

	default:
		switch(type) {

		case EX_INTERF:
			request->request->outcome |= RS_PRINTING;
			break;

		case EX_NOTIFY:
			request->request->outcome |= RS_NOTIFYING;
			break;

		case EX_SLOWF:
			request->request->outcome |= RS_FILTERING;
			request->request->outcome &= ~RS_REFILTER;
			break;

		}
		return(0);

	}

	for (i = 0; i < NSIG; i++)
		(void)signal (i, SIG_DFL);
	(void)signal (SIGALRM, SIG_IGN);
	(void)signal (SIGTERM, sigtrap);

	closelog();
	for (i = 0; i < OpenMax; i++)
		if (i != ChildMd->writefd)
			Close (i);
	openlog("lpsched", LOG_PID|LOG_NDELAY|LOG_NOWAIT, LOG_LPR);

	setpgrp();

	/* Set a default path */
	addenv (&envp, "PATH", "/usr/lib/lp/bin:/usr/bin:/bin:/usr/sbin:/sbin");
	/* copy locale related variables */
	addenv (&envp, "TZ", getenv("TZ"));
	addenv (&envp, "LANG", getenv("LANG"));
	addenv (&envp, "LC_ALL", getenv("LC_ALL"));
	addenv (&envp, "LC_COLLATE", getenv("LC_COLLATE"));
	addenv (&envp, "LC_CTYPE", getenv("LC_CTYPE"));
	addenv (&envp, "LC_MESSAGES", getenv("LC_MESSAGES"));
	addenv (&envp, "LC_MONETARY", getenv("LC_MONETARY"));
	addenv (&envp, "LC_NUMERIC", getenv("LC_NUMERIC"));
	addenv (&envp, "LC_TIME", getenv("LC_TIME"));

	sprintf ((cp = BIGGEST_NUMBER_S), "%ld", key);
	addenv (&envp, "SPOOLER_KEY", cp);

#if	defined(DEBUG)
	addenv (&envp, "LPDEBUG", (debug? "1" : "0"));
#endif

	/*
	 * Open the standard input, standard output, and standard error.
	 */
	switch (type) {
		
	case EX_SLOWF:
	case EX_INTERF:
		/*
		 * stdin:  /dev/null
		 * stdout: /dev/null (EX_SLOWF), printer port (EX_INTERF)
		 * stderr: req#
		 */
		infile = 0;
		outfile = 0;
		errfile = makereqerr(request);
		break;

	case EX_NOTIFY:
		/*
		 * stdin:  req#
		 * stdout: /dev/null
		 * stderr: /dev/null
		 */
		infile = makereqerr(request);
		outfile = 0;
		errfile = 0;

		break;

	case EX_ALERT:
	case EX_FALERT:
	case EX_PALERT:
	case EX_FAULT_MESSAGE:
	case EX_FORM_MESSAGE:
		/*
		 * stdin:  /dev/null
		 * stdout: /dev/null
		 * stderr: /dev/null
		 */
		infile = 0;
		outfile = 0;
		errfile = 0;
		break;

	}

	if (infile) {
		if (Open(infile, O_RDONLY) == -1)
			Done (EXEC_EXIT_NOPEN, errno);
	} else {
		if (Open("/dev/null", O_RDONLY) == -1)
			Done (EXEC_EXIT_NOPEN, errno);
	}

	if (outfile) {
		if (Open(outfile, O_CREAT|O_TRUNC|O_WRONLY, 0600) == -1)
			Done (EXEC_EXIT_NOPEN, errno);
	} else {
		/*
		 * If EX_INTERF, this is still needed to cause the
		 * standard error channel to be #2.
		 */
		if (Open("/dev/null", O_WRONLY) == -1)
			Done (EXEC_EXIT_NOPEN, errno);
	}

	if (errfile) {
		if (Open(errfile, O_CREAT|O_TRUNC|O_WRONLY, 0600) == -1)
			Done (EXEC_EXIT_NOPEN, errno);
	} else {
		if (Open("/dev/null", O_WRONLY) == -1)
			Done (EXEC_EXIT_NOPEN, errno);
	}

	switch (type) {

	case EX_INTERF:
		/*
		 * Opening a ``port'' can be dangerous to our health:
		 *
		 *	- Hangups can occur if the line is dropped.
		 *	- The printer may send an interrupt.
		 *	- A FIFO may be closed, generating SIGPIPE.
		 *
		 * We catch these so we can complain nicely.
		 */
		trap_fault_signals ();

		(void)Close (1);

		if (strchr (request->request->user, '@'))
		{
			procuid = Lp_Uid;
			procgid = Lp_Gid;
		}
		else
		{
			procuid = request->secure->uid;
			procgid = request->secure->gid;
		}
		if (printer->printer->dial_info)
		{
			ret = open_dialup(request->printer_type,
				printer->printer);
			if (ret == 0)
				do_undial = 1;
		}
		else
		{
			ret = open_direct(request->printer_type,
				printer->printer);
			do_undial = 0;
			/* this is a URI */
			if (is_printer_uri(printer->printer->device) == 0)
				addenv(&envp, "DEVICE_URI",
					 printer->printer->device);
		}
				addenv(&envp, "DEVICE_URI",
					 printer->printer->device);
		if (ret != 0)
			Done (ret, errno);
			
		if (!(request->request->outcome & RS_FILTERED))
			file_list = request->request->file_list;

		else {
			register int		count	= 0;
			register char *		num	= BIGGEST_REQID_S;
			register char *		prefix;

			prefix = makestr(
				Lp_Temp,
				"/F",
				getreqno(request->secure->req_id),
				"-",
				(char *)0
			);

			file_list = (char **)Malloc(
				(lenlist(request->request->file_list) + 1)
			      * sizeof(char *)
			);

			for (
				listp = request->request->file_list;
				*listp;
				listp++
			) {
				sprintf (num, "%d", count + 1);
				file_list[count] = makestr(
					prefix,
					num,
					(char *)0
				);
				count++;
			}
			file_list[count] = 0;
		}

#ifdef LP_USE_PAPI_ATTR
		/*
		 * Check if the PAPI job attribute file exists, if it does
		 * pass the file's pathname to the printer interface script
		 * in an environment variable. This file is created when
		 * print jobs are submitted via the PAPI interface.
		 */
		snprintf(tmpName, sizeof (tmpName), "%s-%s",
			getreqno(request->secure->req_id), LP_PAPIATTRNAME);
		path = makepath(Lp_Temp, tmpName, (char *)0);
		if ((path != NULL) && (stat(path, &tmpBuf) == 0))
		{
			/*
			 * IPP job attribute file exists for this job so
			 * set the environment variable
			 */
			addenv(&envp, "ATTRPATH", path);
		}
		Free(path);

		/*
		 * now set environment variable for the printer's PostScript
		 * Printer Description (PPD) file, this is used by the filter
		 * when forming the print data for this printer.
		 */
		if ((request->printer != NULL) &&
		    (request->printer->printer != NULL) &&
		    (request->printer->printer->name != NULL))
		{
			snprintf(tmpName, sizeof (tmpName), "%s.ppd",
				request->printer->printer->name);
			path = makepath(ETCDIR, "ppd", tmpName, (char *)0);
			if ((path != NULL) && (stat(path, &tmpBuf) == 0))
			{
				addenv(&envp, "PPD", path);
			}
			Free(path);
		}
#endif

		if (request->printer_type)
			addenv(&envp, "TERM", request->printer_type);

		if (!(printer->printer->daisy)) {
			register char *	chset = 0;
			register char *	csp;

			if (
				request->form
			     && request->form->form->chset
			     && request->form->form->mandatory
			     && !STREQU(NAME_ANY, request->form->form->chset)
			)
				chset = request->form->form->chset;

			else if (
				request->request->charset
			     && !STREQU(NAME_ANY, request->request->charset)
			)
				chset = request->request->charset;

			if (chset) {
				csp = search_cslist(
					chset,
					printer->printer->char_sets
				);

				/*
				 * The "strtok()" below wrecks the string
				 * for future use, but this is a child
				 * process where it won't be needed again.
				 */
				addenv (&envp, "CHARSET",
					(csp? strtok(csp, "=") : chset)
				);
			}
		}

		if (request->fast)
			addenv(&envp, "FILTER", request->fast);

		/*
		 * Add the sensitivity label to the environment for
		 * banner page and header/footer processing
		 */

		if (is_system_labeled() && request->secure->slabel != NULL)
			addenv(&envp, "SLABEL", request->secure->slabel);

		/*
		 * Add the system name to the user name (ala system!user)
		 * unless it is already there. RFS users may have trouble
		 * here, sorry!
		 */
		cp = strchr(request->secure->user, '@');

		allTraysWithForm(printer, request->form); 

		/*
		 * Fix for 4137389
		 * Remove double quotes from title string.
		 */
		fr_flg = 1;
		clean_title = strdup(NB(request->request->title));
		if (clean_title == NULL) {
			/*
			 * strdup failed. We're probably hosed
			 * but try setting clean_title
			 * to original title and continuing.
			 */
			clean_title = NB(request->request->title);
			fr_flg = 0;
		} else if (strcmp(clean_title, "") != 0) {
			char *ct_p;

			for (ct_p = clean_title; *ct_p != NULL; ct_p++) {
				if (*ct_p == '"')
					*ct_p = ' ';
			}
		}

		av[ac++] = arg_string(TRUSTED, "%s/%s", Lp_A_Interfaces,
					printer->printer->name);
		av[ac++] = arg_string(TRUSTED, "%s", request->secure->req_id);
		av[ac++] = arg_string(UNTRUSTED, "%s", request->request->user);
		av[ac++] = arg_string(TRUSTED, "%s", clean_title);
		av[ac++] = arg_string(TRUSTED, "%d", request->copies);

		if (fr_flg)
			free (clean_title);

		sep = "";

		/*
		 * Do the administrator defined key=value pair options
		 */

		argbuf[0] = '\0';
				
		if (printer->printer->options) {
			char **tmp = printer->printer->options;
			while(*tmp != NULL) {
				STRLCAT(argbuf, sep, sizeof (argbuf));
				sep = " ";
				STRLCAT(argbuf, *tmp++, sizeof (argbuf));
			}
		}

		/*
		 * Do the administrator defined ``stty'' stuff before
		 * the user's -o options, to allow the user to override.
		 */
		if (printer->printer->stty) {
			STRLCAT (argbuf, sep, sizeof (argbuf));
			sep = " ";
			STRLCAT (argbuf, "stty='", sizeof (argbuf));
			STRLCAT (argbuf, printer->printer->stty,
			    sizeof (argbuf));
			STRLCAT (argbuf, "'", sizeof (argbuf));
		}

		/*
		 * Do all of the user's options except the cpi/lpi/etc.
		 * stuff, which is done separately.
		 */
		if (request->request->options) {
			listp = dashos(request->request->options);
			while (*listp) {
				if (
					!STRNEQU(*listp, "cpi=", 4)
				     && !STRNEQU(*listp, "lpi=", 4)
				     && !STRNEQU(*listp, "width=", 6)
				     && !STRNEQU(*listp, "length=", 7)
				) {
					STRLCAT (argbuf, sep, sizeof (argbuf));
					sep = " ";
					STRLCAT (argbuf, *listp,
					    sizeof (argbuf));
				}
				listp++;
			}
		}

		/*
		 * The "pickfilter()" routine (from "validate()")
		 * stored the cpi/lpi/etc. stuff that should be
		 * used for this request. It chose form over user,
		 * and user over printer.
		 */
		if (request->cpi) {
			STRLCAT (argbuf, sep, sizeof (argbuf));
			sep = " ";
			STRLCAT (argbuf, "cpi=", sizeof (argbuf));
			STRLCAT (argbuf, request->cpi, sizeof (argbuf));
		}
		if (request->lpi) {
			STRLCAT (argbuf, sep, sizeof (argbuf));
			sep = " ";
			STRLCAT (argbuf, "lpi=", sizeof (argbuf));
			STRLCAT (argbuf, request->lpi, sizeof (argbuf));
		}
		if (request->pwid) {
			STRLCAT (argbuf, sep, sizeof (argbuf));
			sep = " ";
			STRLCAT (argbuf, "width=", sizeof (argbuf));
			STRLCAT (argbuf, request->pwid, sizeof (argbuf));
		}
		if (request->plen) {
			STRLCAT (argbuf, sep, sizeof (argbuf));
			sep = " ";
			STRLCAT (argbuf, "length=", sizeof (argbuf));
			STRLCAT (argbuf, request->plen, sizeof (argbuf));
		}

		/*
		 * Do the ``raw'' bit last, to ensure it gets
		 * done. If the user doesn't want this, then he or
		 * she can do the correct thing using -o stty=
		 * and leaving out the -r option.
		 */
		if (request->request->actions & ACT_RAW) {
			STRLCAT (argbuf, sep, sizeof (argbuf));
			sep = " ";
			STRLCAT (argbuf, "stty=-opost", sizeof (argbuf));
		}


		/* the "options" */
		av[ac++] = arg_string(UNTRUSTED, "%s", argbuf);

		for (listp = file_list; *listp; listp++)
			av[ac++] = arg_string(TRUSTED, "%s", *listp);

		(void)chfiles (file_list, procuid, procgid);

		break;


	case EX_SLOWF:
		if (request->slow)
			addenv(&envp, "FILTER", request->slow);

		if (strchr (request->request->user, '@'))
		{
			procuid = Lp_Uid;
			procgid = Lp_Gid;
		}
		else
		{
			procuid = request->secure->uid;
			procgid = request->secure->gid;
		}
		cp = _alloc_files(
			lenlist(request->request->file_list),
			getreqno(request->secure->req_id),
			procuid, procgid);

		av[ac++] = arg_string(TRUSTED, "%s", Lp_Slow_Filter);
		av[ac++] = arg_string(TRUSTED, "%s/%s", Lp_Temp, cp);
		for (listp = request->request->file_list; *listp; listp++)
			av[ac++] = arg_string(TRUSTED, "%s", *listp);

		(void)chfiles (request->request->file_list, procuid, procgid);

#ifdef LP_USE_PAPI_ATTR
		/*
		 * Check if the PAPI job attribute file exists, if it does
		 * pass the file's pathname to the slow-filters in an
		 * environment variable. Note: this file is created when
		 * print jobs are submitted via the PAPI interface.
		 */
		snprintf(tmpName, sizeof (tmpName), "%s-%s",
			getreqno(request->secure->req_id), LP_PAPIATTRNAME);
		path = makepath(Lp_Temp, tmpName, (char *)0);
		if ((path != NULL) && (stat(path, &tmpBuf) == 0))
		{
			/*
			 * IPP job attribute file exists for this job so
			 * set the environment variable
			 */
			addenv(&envp, "ATTRPATH", path);
		}
		Free(path);


		/*
		 * now set environment variable for the printer's PostScript
		 * Printer Description (PPD) file, this is used by the filter
		 * when forming the print data for this printer.
		 */
		if ((request->printer != NULL) &&
		    (request->printer->printer != NULL) &&
		    (request->printer->printer->name != NULL))
		{
			snprintf(tmpName, sizeof (tmpName), "%s.ppd",
				request->printer->printer->name);
			path = makepath(ETCDIR, "ppd", tmpName, (char *)0);
			if ((path != NULL) && (stat(path, &tmpBuf) == 0))
			{
				addenv(&envp, "PPD", path);
			}
			Free(path);
		}
#endif
		break;

	case EX_ALERT:
		procuid = Lp_Uid;
		procgid = Lp_Gid;
		(void)Chown (printer->alert->msgfile, procuid, procgid);

		av[ac++] = arg_string(TRUSTED, "%s/%s/%s", Lp_A_Printers,
				printer->printer->name, ALERTSHFILE);
		av[ac++] = arg_string(TRUSTED, "%s", printer->alert->msgfile);

		break;

	case EX_PALERT:
		procuid = Lp_Uid;
		procgid = Lp_Gid;
		(void)Chown (pwheel->alert->msgfile, procuid, procgid);

		av[ac++] = arg_string(TRUSTED, "%s/%s/%s", Lp_A_PrintWheels,
				pwheel->pwheel->name, ALERTSHFILE);
		av[ac++] = arg_string(TRUSTED, "%s", printer->alert->msgfile);

		break;

	case EX_FALERT:
		procuid = Lp_Uid;
		procgid = Lp_Gid;
		(void)Chown (form->alert->msgfile, procuid, procgid);

		av[ac++] = arg_string(TRUSTED, "%s/%s/%s", Lp_A_Forms,
				form->form->name, ALERTSHFILE);
		av[ac++] = arg_string(TRUSTED, "%s", printer->alert->msgfile);

		break;

	case EX_FORM_MESSAGE:
		procuid = Lp_Uid;
		procgid = Lp_Gid;

		av[ac++] = arg_string(TRUSTED, "%s/form", Lp_A_Faults);
		av[ac++] = arg_string(TRUSTED, "%s", form->form->name);
		av[ac++] = arg_string(TRUSTED, "%s", time_buf);
		av[ac++] = arg_string(TRUSTED, "%s/%s/%s", Lp_A_Forms,
				form->form->name, FORMMESSAGEFILE);

		break;

	case EX_FAULT_MESSAGE:
		procuid = Lp_Uid;
		procgid = Lp_Gid;

		av[ac++] = arg_string(TRUSTED, "%s/printer", Lp_A_Faults);
		av[ac++] = arg_string(TRUSTED, "%s", printerNameToShow);
		av[ac++] = arg_string(TRUSTED, "%s", time_buf);
		av[ac++] = arg_string(TRUSTED, "%s/%s/%s", Lp_A_Printers,
				printerName, FAULTMESSAGEFILE);

		break;

	case EX_NOTIFY:
		if (request->request->alert) {
			if (strchr(request->request->user, '@')) {
				procuid = Lp_Uid;
				procgid = Lp_Gid;
			} else {
				procuid = request->secure->uid;
				procgid = request->secure->gid;
			}
			av[ac++] = arg_string(TRUSTED, "%s",
					request->request->alert);
		} else {
			char *user = strdup(request->request->user);
			clean_string(user);
			slabel = request->secure->slabel;

			if (request->request->actions & ACT_WRITE) {
				av[ac++] = arg_string(TRUSTED, "%s", BINWRITE);
				snprintf(argbuf, sizeof (argbuf),
					"%s %s || %s %s",
					BINWRITE, user,
					BINMAIL, user
				);
				av[ac++] = arg_string(TRUSTED, "/bin/sh");
				av[ac++] = arg_string(TRUSTED, "-c");
				av[ac++] = arg_string(TRUSTED, "%s", argbuf);
			} else if ((getzoneid() == GLOBAL_ZONEID) &&
				   is_system_labeled() && (slabel != NULL)) {
				/*
				 * If in the global zone and the system is
				 * labeled, mail is handled via a local
				 * labeled zone that is the same label as
				 * the request.
				 */
				if ((mail_zonename =
				    get_labeled_zonename(slabel)) ==
				    (char *)-1) {
					/*
					 * Cannot find labeled zone, just
					 * return 0.
					 */
					return(0);
				}
			}
			if (mail_zonename == NULL) {
				procuid = Lp_Uid;
				procgid = Lp_Gid;
				av[ac++] = arg_string(TRUSTED, "%s", BINMAIL);
				av[ac++] = arg_string(UNTRUSTED, "%s", user);
			} else {
				procuid = getuid();
				procgid = getgid();
				av[ac++] = arg_string(TRUSTED, "%s",
				    "/usr/sbin/zlogin");
				av[ac++] = arg_string(TRUSTED, "%s",
				    mail_zonename);
				av[ac++] = arg_string(TRUSTED, "%s",
				    BINMAIL);
				av[ac++] = arg_string(UNTRUSTED, "%s",
				    user);
				Free(mail_zonename);
			}

			free(user);
		}
		break;
	}

	av[ac++] = NULL;

	Fork2 ();
	/* only the child returns */

	/*
	 * Correctly set up the supplemental group list
	 * for proper file access (before execl the interface program)
	 */

	pwp = getpwuid(procuid);
	if (pwp == NULL) {
		note("getpwuid(%d) call failed\n", procuid);
	} else if (initgroups(pwp->pw_name, procgid) < 0) {
		note("initgroups() call failed %d\n", errno);
	}
	
	setgid (procgid);
	setuid (procuid);

	/*
	 * The shell doesn't allow the "trap" builtin to set a trap
	 * for a signal ignored when the shell is started. Thus, don't
	 * turn off signals in the last child!
	 */

#ifdef DEBUG
	for (i = 0; av[i] != NULL; i++)
		note("exec(%s): av[%d] = %s", _exec_name(type), i, av[i]);
	for (i = 0; envp[i] != NULL; i++)
		note("exec(%s): envp[%d] = %s", _exec_name(type), i, envp[i]);
#endif

	execvpe(av[0], av, envp);
	Done (EXEC_EXIT_NEXEC, errno);
	/*NOTREACHED*/
	return (0);
}
Ejemplo n.º 16
0
struct NBDYN(Any) NB(__cdyn_release)(void *r) {
  struct NBCDYN(Any) *dr = r;
  void *ref = NLANG_CREF($Release)(&dr->ref);
  return NLANG_MKDYN(struct NBDYN(Any), dr->dyntable, ref);
}

#define heap_header _$Ngen_n$builtins$Envheader$$n$builtins$_$Ni_Heap$$_$Ncdyn_n$builtins$_$Ni_Heap_genN$_

static struct heap_header sysheap_header;
extern const struct _$Ndyntable_n$builtins$_$Ni_Heap n$mem$Sysheap$Dyntable__n$builtins$_$Ni_Heap;

extern void n$stdio$Install_sys(void);
extern void n$stdio$Uninstall_sys(void);
extern void n$logging$Install_sys(void);
extern void n$env$Install_sys(NB(Uint) argc, NB(U8) **argv);
extern void n$time$Install_sys(void);
extern void n$fs$Install_sys(void);
extern void n$math$rand$Install_sys(void);
extern void n$crypto$cryptorand$Install_sys(void);

void _$Npostlude(void);

void _$Nprelude(int *argc, char ***argv, char ***env) {
  atexit(_$Npostlude);

  struct NLANG_CREF() cref_sysheap = {
    .ref = (void *) &n$builtins$sysheap,
    .cnt = &n$builtins$sysheap_cnt,
  };
  *cref_sysheap.cnt = 1;
Ejemplo n.º 17
0
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <time.h>
#include <signal.h>
#include <arpa/inet.h>

#define NB(t) n$builtins$##t
#define SY(t) n$syscall$##t

#define SY_int n$builtins$I32
#define SY_clockid_t n$builtins$I32

#ifdef NLANG_DEFINE_FUNCTIONS

NB(Uint) SY(Strlen)(NB(U8) *s) {
  return strlen((char *) s);
}

NB(I32) SY(_EPERM) = EPERM;
NB(I32) SY(_ENOENT) = ENOENT;
NB(I32) SY(_ESRCH) = ESRCH;
NB(I32) SY(_EINTR) = EINTR;
NB(I32) SY(_EIO) = EIO;
NB(I32) SY(_ENXIO) = ENXIO;
NB(I32) SY(_E2BIG) = E2BIG;
NB(I32) SY(_ENOEXEC) = ENOEXEC;
NB(I32) SY(_EBADF) = EBADF;
NB(I32) SY(_ECHILD) = ECHILD;
NB(I32) SY(_EAGAIN) = EAGAIN;
NB(I32) SY(_ENOMEM) = ENOMEM;
Ejemplo n.º 18
0
SmartPointer<Batch> Batch::Merge(SmartPointer<Batch> _A,SmartPointer<Batch> _B)
{
	if (!_A) return _B;
	if (!_B) return _A;

	Batch* A=_A.get();
	Batch* B=_B.get();

	if (A->primitive!=B->primitive) 
		return SmartPointer<Batch>();

	if (A->ambient  !=B->ambient  ) 
		return SmartPointer<Batch>();

	if (A->diffuse  !=B->diffuse  ) 
		return SmartPointer<Batch>();

	if (A->specular !=B->specular ) 
		return SmartPointer<Batch>();

	if (A->emission !=B->emission ) 
		return SmartPointer<Batch>();

	if (A->shininess!=B->shininess) 
		return SmartPointer<Batch>();

	if ((A->vertices && !B->vertices) || (!A->vertices && B->vertices)) 
		return SmartPointer<Batch>();

	if ((A->normals  && !B->normals ) || (!A->normals  && B->normals )) 
		return SmartPointer<Batch>();

	if ((A->colors   && !B->colors  ) || (!A->colors   && B->colors  )) 
		return SmartPointer<Batch>();

	bool ATex0=(A->texture0) && (A->texture0coords);
	bool BTex0=(B->texture0) && (B->texture0coords);
	if ((ATex0 && !BTex0) || (!ATex0 && BTex0) || (ATex0 && BTex0 && A->texture0.get()!=B->texture0.get())) 
		return SmartPointer<Batch>();

	bool ATex1=(A->texture1) && (A->texture1coords);
	bool BTex1=(B->texture1) && (B->texture1coords);
	if ((ATex1 && !BTex1) || (!ATex1 && BTex1) || (ATex1 && BTex1 && A->texture1.get()!=B->texture1.get())) 
		return SmartPointer<Batch>();

	SmartPointer<Batch> ret(new Batch());
	ret->matrix=Mat4f();
	ret->primitive=A->primitive;
	ret->ambient  =A->ambient;
	ret->diffuse  =A->diffuse;
	ret->specular =A->specular;
	ret->emission =A->emission;
	ret->shininess=A->shininess;

	//vertices
	if (A->vertices)
	{
		Vector VA(*(A->vertices));
		{
			Mat4f T=A->matrix;
			float* p=VA.mem();
			for (int i=0;i<VA.size();i+=3,p+=3)
			{
				Vec3f V=T * Vec3f(p[0],p[1],p[2]);
				p[0]=V.x;p[1]=V.y;p[2]=V.z;
			}
		}

		Vector VB(*(B->vertices));
		{
			Mat4f T=B->matrix;
			float* p=VB.mem();
			for (int i=0;i<VB.size();i+=3,p+=3)
			{
				Vec3f V=T * Vec3f(p[0],p[1],p[2]);
				p[0]=V.x;p[1]=V.y;p[2]=V.z;
			}
		}

		ret->vertices.reset(new Vector(VA));
		ret->vertices->append(VB);
	}

	//normals
	if (A->normals)
	{
		Vector NA(*(A->normals));
		{
			Mat4f T=A->matrix.invert();
			float* p=NA.mem();
			for (int i=0;i<NA.size();i+=3,p+=3)
			{
				Vec4f _N=Vec4f(p[0],p[1],p[2],0.0) *  T;
				Vec3f  N=Vec3f(_N.x,_N.y,_N.z).normalize();
				p[0]=N.x;p[1]=N.y;p[2]=N.z;
			}
		}

		Vector NB(*(B->normals));
		{
			Mat4f T=B->matrix.invert();
			float* p=NB.mem();
			for (int i=0;i<NB.size();i+=3,p+=3)
			{
				Vec4f _N=Vec4f(p[0],p[1],p[2],0.0) *  T;
				Vec3f  N=Vec3f(_N.x,_N.y,_N.z).normalize();
				p[0]=N.x;p[1]=N.y;p[2]=N.z;
			}
		}

		ret->normals.reset(new Vector(NA));
		ret->normals->append(NB);
	}

	//colors
	if (A->colors)
	{
		ret->colors.reset(new Vector(*(A->colors)));
		ret->colors->append(*(B->colors));
	}

	//texture 0
	if (ATex0)
	{
		ret->texture0=A->texture0;
		ret->texture0coords.reset(new Vector(*(A->texture0coords)));
		ret->texture0coords->append(*(B->texture0coords));
	}
	
	//texture 1
	if (ATex1)
	{
		ret->texture1=A->texture1;
		ret->texture1coords.reset(new Vector(*(A->texture1coords)));
		ret->texture1coords->append(*(B->texture1coords));
	}

	return ret;
}
Ejemplo n.º 19
0
void EncodingEDSRSA(char *M_fname, char *nA_fname, char *eA_fname, char *dA_fname, char *nB_fname, char *eB_fname, char *dB_fname)
{
	std::ifstream in(M_fname);
	int *M_hash = (int*)md5(&in), i;
    BigInt  M(intToChar(M_hash[3])), NA(nA_fname, false), EA(eA_fname, false), DA(dA_fname, false);
    M *= BigInt("10000000000"); M += BigInt(intToChar(M_hash[2]));
    M *= BigInt("10000000000"); M += BigInt(intToChar(M_hash[1]));
    M *= BigInt("10000000000"); M += BigInt(intToChar(M_hash[0]));
    BigInt NB(nB_fname, false), EB(eB_fname, false), DB(dB_fname, false);
    BigInt Signature("1"), Code("1"), Encode("1"), CheckSign("1");
    BigInt DegreeNet[RNet];
	DegreeNet[0] = M;
	DegreeNet[0] %= NA;
	for(i = 1; i < RNet; i++)
	{
		DegreeNet[i] = DegreeNet[i-1] * DegreeNet[i-1];
		DegreeNet[i] %= NA;
	}
    BigInt degreeNum[RNet];
    degreeNum[0] = BigInt("1");
	for(int i = 1; i < RNet; i++)
        degreeNum[i] = degreeNum[i-1] * BigInt("2");
    BigInt I("0");
	for(int j = RNet-1; j >= 0;)
	{
		if(DA >= I + degreeNum[j])
		{
			Signature *= DegreeNet[j];
			Signature %= NA;
			I += degreeNum[j];
		}
		else
			j--;
	}
	//////////////////////////////
	DegreeNet[0] = Signature;
	DegreeNet[0] %= NB;
	for(i = 1; i < RNet; i++)
	{
		DegreeNet[i] = DegreeNet[i-1] * DegreeNet[i-1];
		DegreeNet[i] %= NB;
	}
    I = BigInt("0");
	for(int j = RNet-1; j >= 0;)
	{
		if(EB >= I + degreeNum[j])
		{
			Code *= DegreeNet[j];
			Code %= NB;
			I += degreeNum[j];
		}
		else
			j--;
	}
	//////////////////////////////
	DegreeNet[0] = Code;
	DegreeNet[0] %= NB;
	for(i = 1; i < RNet; i++)
	{
		DegreeNet[i] = DegreeNet[i-1] * DegreeNet[i-1];
		DegreeNet[i] %= NB;
	}
    I = BigInt("0");
	for(int j = RNet-1; j >= 0;)
	{
		if(DB >= I + degreeNum[j])
		{
			Encode *= DegreeNet[j];
			Encode %= NB;
			I += degreeNum[j];
		}
		else
			j--;
	}
	//////////////////////////////
	DegreeNet[0] = Encode;
	DegreeNet[0] %= NA;
	for(i = 1; i < RNet; i++)
	{
		DegreeNet[i] = DegreeNet[i-1] * DegreeNet[i-1];
		DegreeNet[i] %= NA;
	}
    I = BigInt("0");
	for(int j = RNet - 1; j >= 0;)
	{
		if(EA >= I + degreeNum[j])
		{
			CheckSign *= DegreeNet[j];
			CheckSign %= NA;
			I += degreeNum[j];
		}
		else
			j--;
	}
	//////////////////////////////
	M.TextWrite("hash.txt");
	Code.TextWrite("code.txt");
	Encode.TextWrite("encode.txt");
	CheckSign.TextWrite("checksign.txt");
	if( M % NA == CheckSign)
		std::cout<<"OK\n";
	else
		std::cout<<"NOT OK\n";
}