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