da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/***********************************************************************
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* This software is part of the ast package *
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner* Copyright (c) 1985-2010 AT&T Intellectual Property *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* and is licensed under the *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Common Public License, Version 1.0 *
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin* by AT&T Intellectual Property *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* A copy of the License is available at *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Information and Software Systems Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* AT&T Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Florham Park NJ *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Glenn Fowler <gsf@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* David Korn <dgk@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Phong Vo <kpv@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin***********************************************************************/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Glenn Fowler
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * AT&T Research
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * return in path the full path name of the probe(1)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * information for lang and tool using proc
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * if attr != 0 then path attribute assignments placed here
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * if path==0 then the space is malloc'd
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * -3 return non-writable path name with no generation
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * -2 return path name with no generation
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * -1 return no $HOME path name with no generation
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * 0 verbose probe
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * 1 silent probe
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * 0 returned if the info does not exist and cannot be generated
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * return non-0 if path is in a readonly or non-setuid fs
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if ((vfs.f_flag & ST_NOSUID) && (stat(path, &st) || st.st_uid != getuid() && st.st_uid != geteuid()))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinpathprobe(char* path, char* attr, const char* lang, const char* tool, const char* aproc, int op)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char* p;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char* k;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char* x;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(proc = pathpath(cmd, proc, NiL, PATH_ABSOLUTE|PATH_REGULAR|PATH_EXECUTE)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (p)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (pathpath(path, lib, "", PATH_ABSOLUTE) && !stat(path, &st) && (st.st_mode & S_IWUSR))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!pathpath(path, lib, "", PATH_ABSOLUTE|PATH_EXECUTE) || stat(path, &ps))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!stat(path, &st) && st.st_size && ptime < (unsigned long)st.st_mtime)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * yes lib/probe/<lang>/<proc>/probe
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * do a manual pathaccess() to find a dir with both
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfsprintf(exe, sizeof(exe), "lib/%s/%s", probe, probe);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (*path == '/' && pathexists(path, PATH_REGULAR|PATH_EXECUTE))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (*path == '/' && pathexists(path, PATH_REGULAR|PATH_EXECUTE) && !stat(path, &ps))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (op >= -1 && (!(st.st_mode & S_ISUID) && ps.st_uid != geteuid() || rofs(path)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin p = path + sfsprintf(path, PATH_MAX - 1, "%s/.%s/%s/", p, probe, HOSTTYPE);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin strncopy(p, k, x - p);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (ptime <= (unsigned long)st.st_mtime || ptime <= (unsigned long)st.st_ctime)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * verify (<sep><name><sep><option><sep><value>)* header
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (*x && *x != ' ')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (*x == ' ')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (n = *x++)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (k = x; *x && *x != n; x++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (p = x; *x && *x != n; x++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (e = x; *x && *x != n; x++);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if ((v = x - e) >= sizeof(ver))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (k = p = ver;; k++)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (k >= p)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin p = k + r;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (*k == n)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(0, "probe processor %s version \"%s\" changed -- expected \"%s\"", proc, ver, e);