xref: /onnv-gate/usr/src/lib/libast/common/path/pathcheck.c (revision 12068:08a39a083754)
14887Schin /***********************************************************************
24887Schin *                                                                      *
34887Schin *               This software is part of the ast package               *
4*12068SRoger.Faulkner@Oracle.COM *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
54887Schin *                      and is licensed under the                       *
64887Schin *                  Common Public License, Version 1.0                  *
78462SApril.Chin@Sun.COM *                    by AT&T Intellectual Property                     *
84887Schin *                                                                      *
94887Schin *                A copy of the License is available at                 *
104887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
114887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
124887Schin *                                                                      *
134887Schin *              Information and Software Systems Research               *
144887Schin *                            AT&T Research                             *
154887Schin *                           Florham Park NJ                            *
164887Schin *                                                                      *
174887Schin *                 Glenn Fowler <gsf@research.att.com>                  *
184887Schin *                  David Korn <dgk@research.att.com>                   *
194887Schin *                   Phong Vo <kpv@research.att.com>                    *
204887Schin *                                                                      *
214887Schin ***********************************************************************/
224887Schin #pragma prototyped
234887Schin 
244887Schin /*
254887Schin  * check if package+tool is ok to run
264887Schin  * a no-op here except for PARANOID packages
274887Schin  * this allows PARANOID_COMPANY to post PARANOID binaries to the www
284887Schin  *
294887Schin  * warn that the user should pay up if
304887Schin  *
314887Schin  *	(1) the tool matches PARANOID
324887Schin  *	(2) $_ is more than 90 days old
334887Schin  *	(3) running on an PARANOID_PAY machine
344887Schin  *	(4) (1)-(3) have not been defeated
354887Schin  *
364887Schin  * hows that
374887Schin  */
384887Schin 
394887Schin #define PARANOID_TOOLS		PARANOID
404887Schin #define PARANOID_COMPANY	"Lucent Technologies"
414887Schin #define PARANOID_MAIL		"stc@lucent.com"
424887Schin #define PARANOID_PAY		"135.*&!(135.104.*)"
434887Schin #define PARANOID_FREE		"(192|224).*"
444887Schin 
454887Schin #include <ast.h>
464887Schin #include <ls.h>
474887Schin #include <error.h>
484887Schin #include <times.h>
494887Schin #include <ctype.h>
504887Schin 
514887Schin int
pathcheck(const char * package,const char * tool,Pathcheck_t * pc)524887Schin pathcheck(const char* package, const char* tool, Pathcheck_t* pc)
534887Schin {
544887Schin #ifdef PARANOID
554887Schin 	register char*	s;
564887Schin 	struct stat	st;
574887Schin 
584887Schin 	if (strmatch(tool, PARANOID) && environ && (s = *environ) && *s++ == '_' && *s++ == '=' && !stat(s, &st))
594887Schin 	{
604887Schin 		unsigned long	n;
614887Schin 		unsigned long	o;
624887Schin 		Sfio_t*		sp;
634887Schin 
644887Schin 		n = time(NiL);
654887Schin 		o = st.st_ctime;
664887Schin 		if (n > o && (n - o) > (unsigned long)(60 * 60 * 24 * 90) && (sp = sfopen(NiL, "/etc/hosts", "r")))
674887Schin 		{
684887Schin 			/*
694887Schin 			 * this part is infallible
704887Schin 			 */
714887Schin 
724887Schin 			n = 0;
734887Schin 			o = 0;
744887Schin 			while (n++ < 64 && (s = sfgetr(sp, '\n', 0)))
754887Schin 				if (strmatch(s, PARANOID_PAY))
764887Schin 				{
774887Schin 					error(1, "licensed for external use -- %s employees should contact %s for the internal license", PARANOID_COMPANY, PARANOID_MAIL);
784887Schin 					break;
794887Schin 				}
804887Schin 				else if (*s != '#' && !isspace(*s) && !strneq(s, "127.", 4) && !strmatch(s, PARANOID_FREE) && o++ > 4)
814887Schin 					break;
824887Schin 			sfclose(sp);
834887Schin 		}
844887Schin 	}
854887Schin #else
864887Schin 	NoP(tool);
874887Schin #endif
884887Schin 	NoP(package);
894887Schin 	if (pc) memzero(pc, sizeof(*pc));
904887Schin 	return(0);
914887Schin }
92