1da2e3ebchin/***********************************************************************
2da2e3ebchin*                                                                      *
3da2e3ebchin*               This software is part of the ast package               *
43e14f97Roger A. Faulkner*          Copyright (c) 1985-2010 AT&T Intellectual Property          *
5da2e3ebchin*                      and is licensed under the                       *
6da2e3ebchin*                  Common Public License, Version 1.0                  *
77c2fbfbApril Chin*                    by AT&T Intellectual Property                     *
8da2e3ebchin*                                                                      *
9da2e3ebchin*                A copy of the License is available at                 *
10da2e3ebchin*            http://www.opensource.org/licenses/cpl1.0.txt             *
11da2e3ebchin*         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12da2e3ebchin*                                                                      *
13da2e3ebchin*              Information and Software Systems Research               *
14da2e3ebchin*                            AT&T Research                             *
15da2e3ebchin*                           Florham Park NJ                            *
16da2e3ebchin*                                                                      *
17da2e3ebchin*                 Glenn Fowler <gsf@research.att.com>                  *
18da2e3ebchin*                  David Korn <dgk@research.att.com>                   *
19da2e3ebchin*                   Phong Vo <kpv@research.att.com>                    *
20da2e3ebchin*                                                                      *
21da2e3ebchin***********************************************************************/
22da2e3ebchin#pragma prototyped
23da2e3ebchin
24da2e3ebchin/*
25da2e3ebchin * check if package+tool is ok to run
26da2e3ebchin * a no-op here except for PARANOID packages
27da2e3ebchin * this allows PARANOID_COMPANY to post PARANOID binaries to the www
28da2e3ebchin *
29da2e3ebchin * warn that the user should pay up if
30da2e3ebchin *
31da2e3ebchin *	(1) the tool matches PARANOID
32da2e3ebchin *	(2) $_ is more than 90 days old
33da2e3ebchin *	(3) running on an PARANOID_PAY machine
34da2e3ebchin *	(4) (1)-(3) have not been defeated
35da2e3ebchin *
36da2e3ebchin * hows that
37da2e3ebchin */
38da2e3ebchin
39da2e3ebchin#define PARANOID_TOOLS		PARANOID
40da2e3ebchin#define PARANOID_COMPANY	"Lucent Technologies"
41da2e3ebchin#define PARANOID_MAIL		"stc@lucent.com"
42da2e3ebchin#define PARANOID_PAY		"135.*&!(135.104.*)"
43da2e3ebchin#define PARANOID_FREE		"(192|224).*"
44da2e3ebchin
45da2e3ebchin#include <ast.h>
46da2e3ebchin#include <ls.h>
47da2e3ebchin#include <error.h>
48da2e3ebchin#include <times.h>
49da2e3ebchin#include <ctype.h>
50da2e3ebchin
51da2e3ebchinint
52da2e3ebchinpathcheck(const char* package, const char* tool, Pathcheck_t* pc)
53da2e3ebchin{
54da2e3ebchin#ifdef PARANOID
55da2e3ebchin	register char*	s;
56da2e3ebchin	struct stat	st;
57da2e3ebchin
58da2e3ebchin	if (strmatch(tool, PARANOID) && environ && (s = *environ) && *s++ == '_' && *s++ == '=' && !stat(s, &st))
59da2e3ebchin	{
60da2e3ebchin		unsigned long	n;
61da2e3ebchin		unsigned long	o;
62da2e3ebchin		Sfio_t*		sp;
63da2e3ebchin
64da2e3ebchin		n = time(NiL);
65da2e3ebchin		o = st.st_ctime;
66da2e3ebchin		if (n > o && (n - o) > (unsigned long)(60 * 60 * 24 * 90) && (sp = sfopen(NiL, "/etc/hosts", "r")))
67da2e3ebchin		{
68da2e3ebchin			/*
69da2e3ebchin			 * this part is infallible
70da2e3ebchin			 */
71da2e3ebchin
72da2e3ebchin			n = 0;
73da2e3ebchin			o = 0;
74da2e3ebchin			while (n++ < 64 && (s = sfgetr(sp, '\n', 0)))
75da2e3ebchin				if (strmatch(s, PARANOID_PAY))
76da2e3ebchin				{
77da2e3ebchin					error(1, "licensed for external use -- %s employees should contact %s for the internal license", PARANOID_COMPANY, PARANOID_MAIL);
78da2e3ebchin					break;
79da2e3ebchin				}
80da2e3ebchin				else if (*s != '#' && !isspace(*s) && !strneq(s, "127.", 4) && !strmatch(s, PARANOID_FREE) && o++ > 4)
81da2e3ebchin					break;
82da2e3ebchin			sfclose(sp);
83da2e3ebchin		}
84da2e3ebchin	}
85da2e3ebchin#else
86da2e3ebchin	NoP(tool);
87da2e3ebchin#endif
88da2e3ebchin	NoP(package);
89da2e3ebchin	if (pc) memzero(pc, sizeof(*pc));
90da2e3ebchin	return(0);
91da2e3ebchin}
92