Exemple #1
0
/** \ingroup rpmcli
 * Verify file attributes (including file digest).
 * @param vf		file data to verify
 * #param spew		should verify results be printed?
 * @return		0 on success (or not installed), 1 on error
 */
static int rpmvfVerify(rpmvf vf, int spew)
	/*@globals h_errno, fileSystem, internalState @*/
	/*@modifies vf, fileSystem, internalState @*/
{
    rpmVerifyAttrs res = RPMVERIFY_NONE;
    struct stat sb;
    int ec = 0;

    /* Check to see if the file was installed - if not pretend all is OK. */
    switch (vf->fstate) {
    default:
    case RPMFILE_STATE_NETSHARED:
    case RPMFILE_STATE_REPLACED:
    case RPMFILE_STATE_NOTINSTALLED:
    case RPMFILE_STATE_WRONGCOLOR:
	goto exit;
	/*@notreached@*/ break;
    case RPMFILE_STATE_NORMAL:
	break;
    }

assert(vf->fn != NULL);
    if (vf->fn == NULL || Lstat(vf->fn, &sb) != 0) {
	res |= RPMVERIFY_LSTATFAIL;
	ec = 1;
	goto exit;
    }

    /* Not all attributes of non-regular files can be verified. */
    if (S_ISDIR(sb.st_mode))
	vf->vflags &= ~(RPMVERIFY_FDIGEST | RPMVERIFY_FILESIZE | RPMVERIFY_MTIME |
			RPMVERIFY_LINKTO | RPMVERIFY_HMAC);
    else if (S_ISLNK(sb.st_mode)) {
	vf->vflags &= ~(RPMVERIFY_FDIGEST | RPMVERIFY_FILESIZE | RPMVERIFY_MTIME |
		RPMVERIFY_MODE | RPMVERIFY_HMAC);
#if CHOWN_FOLLOWS_SYMLINK
	vf->vflags &= ~(RPMVERIFY_USER | RPMVERIFY_GROUP);
#endif
    }
    else if (S_ISFIFO(sb.st_mode))
	vf->vflags &= ~(RPMVERIFY_FDIGEST | RPMVERIFY_FILESIZE | RPMVERIFY_MTIME |
			RPMVERIFY_LINKTO | RPMVERIFY_HMAC);
    else if (S_ISCHR(sb.st_mode))
	vf->vflags &= ~(RPMVERIFY_FDIGEST | RPMVERIFY_FILESIZE | RPMVERIFY_MTIME |
			RPMVERIFY_LINKTO | RPMVERIFY_HMAC);
    else if (S_ISBLK(sb.st_mode))
	vf->vflags &= ~(RPMVERIFY_FDIGEST | RPMVERIFY_FILESIZE | RPMVERIFY_MTIME |
			RPMVERIFY_LINKTO | RPMVERIFY_HMAC);
    else
	vf->vflags &= ~(RPMVERIFY_LINKTO);

    if (vf->vflags & (RPMVERIFY_FDIGEST | RPMVERIFY_HMAC)) {
	if (vf->digest == NULL || vf->dlen == 0)
	    res |= RPMVERIFY_FDIGEST;
	else {
	/* XXX If --nofdigest, then prelinked library sizes fail to verify. */
	    unsigned char * fdigest = memset(alloca(vf->dlen), 0, vf->dlen);
	    size_t fsize = 0;
#define	_mask	(RPMVERIFY_FDIGEST|RPMVERIFY_HMAC)
	    unsigned dflags = (vf->vflags & _mask) == RPMVERIFY_HMAC
		? 0x2 : 0x0;
#undef	_mask
	    int rc = dodigest(vf->dalgo, vf->fn, fdigest, dflags, &fsize);
	    sb.st_size = fsize;
	    if (rc)
		res |= (RPMVERIFY_READFAIL|RPMVERIFY_FDIGEST);
	    else
	    if (memcmp(fdigest, vf->digest, vf->dlen))
		res |= RPMVERIFY_FDIGEST;
	}
    }

    if (vf->vflags & RPMVERIFY_LINKTO) {
	char linkto[1024+1];
	int size = 0;

	if ((size = Readlink(vf->fn, linkto, sizeof(linkto)-1)) == -1)
	    res |= (RPMVERIFY_READLINKFAIL|RPMVERIFY_LINKTO);
	else {
	    linkto[size] = '\0';
	    if (vf->flink == NULL || strcmp(linkto, vf->flink))
		res |= RPMVERIFY_LINKTO;
	}
    }

    if (vf->vflags & RPMVERIFY_FILESIZE) {
	if (sb.st_size != vf->sb.st_size)
	    res |= RPMVERIFY_FILESIZE;
    }

    if (vf->vflags & RPMVERIFY_MODE) {
	/* XXX AIX has sizeof(mode_t) > sizeof(unsigned short) */
	unsigned short metamode = (unsigned short)vf->sb.st_mode;
	unsigned short filemode = (unsigned short)sb.st_mode;

	/* Comparing type of %ghost files is meaningless, but perms are OK. */
	if (vf->fflags & RPMFILE_GHOST) {
	    metamode &= ~0xf000;
	    filemode &= ~0xf000;
	}
	if (metamode != filemode)
	    res |= RPMVERIFY_MODE;
    }

    if (vf->vflags & RPMVERIFY_RDEV) {
	if (S_ISCHR(vf->sb.st_mode) != S_ISCHR(sb.st_mode)
	 || S_ISBLK(vf->sb.st_mode) != S_ISBLK(sb.st_mode))
	    res |= RPMVERIFY_RDEV;
	else if (S_ISDEV(vf->sb.st_mode) && S_ISDEV(sb.st_mode)) {
	    rpmuint16_t st_rdev = (rpmuint16_t)(sb.st_rdev & 0xffff);
	    rpmuint16_t frdev = (rpmuint16_t)(vf->sb.st_rdev & 0xffff);
	    if (st_rdev != frdev)
		res |= RPMVERIFY_RDEV;
	}
    }

    if (vf->vflags & RPMVERIFY_MTIME) {
	if (sb.st_mtime != vf->sb.st_mtime)
	    res |= RPMVERIFY_MTIME;
    }

    if (vf->vflags & RPMVERIFY_USER) {
	const char * fuser = uidToUname(sb.st_uid);
	if (fuser == NULL || vf->fuser == NULL || strcmp(fuser, vf->fuser))
	    res |= RPMVERIFY_USER;
    }

    if (vf->vflags & RPMVERIFY_GROUP) {
	const char * fgroup = gidToGname(sb.st_gid);
	if (fgroup == NULL || vf->fgroup == NULL || strcmp(fgroup, vf->fgroup))
	    res |= RPMVERIFY_GROUP;
    }

exit:

    if (spew) {	/* XXX no output w verify(...) probe. */
	char buf[BUFSIZ];
	char * t = buf;
	char * te = t;
	*te = '\0';
	if (ec) {
	    if (!(vf->fflags & (RPMFILE_MISSINGOK|RPMFILE_GHOST))
	     || rpmIsVerbose())
	    {
		sprintf(te, _("missing   %c %s"),
			((vf->fflags & RPMFILE_CONFIG)	? 'c' :
			 (vf->fflags & RPMFILE_DOC)	? 'd' :
			 (vf->fflags & RPMFILE_GHOST)	? 'g' :
			 (vf->fflags & RPMFILE_LICENSE)	? 'l' :
			 (vf->fflags & RPMFILE_PUBKEY)	? 'P' :
			 (vf->fflags & RPMFILE_README)	? 'r' : ' '),
			vf->fn);
                if ((res & RPMVERIFY_LSTATFAIL) != 0 && errno != ENOENT) {
		    te += strlen(te);
                    sprintf(te, " (%s)", strerror(errno));
                }
	    }
	} else if (res || rpmIsVerbose()) {
	    /*@observer@*/ static const char aok[] = ".";
	    /*@observer@*/ static const char unknown[] = "?";

#define	_verify(_RPMVERIFY_F, _C)	\
	((res & _RPMVERIFY_F) ? _C : aok)
#define	_verifylink(_RPMVERIFY_F, _C)	\
	((res & RPMVERIFY_READLINKFAIL) ? unknown : \
	 (res & _RPMVERIFY_F) ? _C : aok)
#define	_verifyfile(_RPMVERIFY_F, _C)	\
	((res & RPMVERIFY_READFAIL) ? unknown : \
	 (res & _RPMVERIFY_F) ? _C : aok)
	
	    const char * digest = _verifyfile(RPMVERIFY_FDIGEST, "5");
	    const char * size = _verify(RPMVERIFY_FILESIZE, "S");
	    const char * link = _verifylink(RPMVERIFY_LINKTO, "L");
	    const char * mtime = _verify(RPMVERIFY_MTIME, "T");
	    const char * rdev = _verify(RPMVERIFY_RDEV, "D");
	    const char * user = _verify(RPMVERIFY_USER, "U");
	    const char * group = _verify(RPMVERIFY_GROUP, "G");
	    const char * mode = _verify(RPMVERIFY_MODE, "M");

#undef _verifyfile
#undef _verifylink
#undef _verify

	    sprintf(te, "%s%s%s%s%s%s%s%s  %c %s",
		    size, mode, digest, rdev, link, user, group, mtime,
			((vf->fflags & RPMFILE_CONFIG)	? 'c' :
			 (vf->fflags & RPMFILE_DOC)	? 'd' :
			 (vf->fflags & RPMFILE_GHOST)	? 'g' :
			 (vf->fflags & RPMFILE_LICENSE)	? 'l' :
			 (vf->fflags & RPMFILE_PUBKEY)	? 'P' :
			 (vf->fflags & RPMFILE_README)	? 'r' : ' '),
			vf->fn);

	}

	if (t && *t)
	    rpmlog(RPMLOG_NOTICE, "%s\n", t);

    }

    return (res != 0);
}
Exemple #2
0
struct mounts *
readmnt()
{
    char *dn = (char *)NULL;
    char *ln;
    FILE *mfp;
    struct mntent *mp;
    struct mounts *mtp;
    char *opt, *opte;
    struct stat sb;

    if (Lmi || Lmist)
        return(Lmi);
    /*
     * Open access to the mount table.
     */
    if (!(mfp = setmntent(MOUNTED, "r"))) {
        (void) fprintf(stderr, "%s: can't access %s\n", Pn, MOUNTED);
        Exit(1);
    }
    /*
     * Read mount table entries.
     */
    while ((mp = getmntent(mfp))) {

#if	defined(MNTSKIP)
        /*
         * Specfy in the MNTSKIP macro the decisions needed to determine
         * that this entry should be skipped.
         *
         * Typically entries whose mnt_type is MNTTYPE_IGNORE are skipped.
         *
         * The MNTSKIP macro allows the caller to use other tests.
         */
        MNTSKIP
#endif	/* MNTSKIP */

        /*
         * Interpolate a possible symbolic directory link.
         */
        if (dn)
            (void) free((FREE_P *)dn);
        if (!(dn = mkstrcpy(mp->mnt_dir, (MALLOC_S *)NULL)))
            goto no_space_for_mount;
        if (!(ln = Readlink(dn))) {
            if (!Fwarn)
                (void) fprintf(stderr,
                               "      Output information may be incomplete.\n");
            continue;
        }
        if (ln != dn) {
            (void) free((FREE_P *)dn);
            dn = ln;
        }
        if (*dn != '/')
            continue;
        /*
         * Stat() the directory.
         */
        if (statsafely(dn, &sb)) {
            if (!Fwarn) {
                (void) fprintf(stderr, "%s: WARNING: can't stat() ", Pn);
                safestrprt(mp->mnt_type, stderr, 0);
                (void) fprintf(stderr, " file system ");
                safestrprt(mp->mnt_dir, stderr, 1);
                (void) fprintf(stderr,
                               "      Output information may be incomplete.\n");
            }
            if ((opt = strstr(mp->mnt_opts, "dev="))) {
                (void) zeromem(&sb, sizeof(sb));
                if ((opte = x2dev(opt + 4, (dev_t *)&sb.st_dev))) {
                    sb.st_mode = S_IFDIR | 0777;
                    if (!Fwarn)
                        (void) fprintf(stderr,
                                       "      assuming \"%.*s\" from %s\n",
                                       (int)(opte - opt), opt, MOUNTED);
                } else
                    opt = (char *)NULL;
            }
            if (!opt)
                continue;
        }
        /*
         * Allocate and fill a local mounts structure with the directory
         * (mounted) information.
         */
        if (!(mtp = (struct mounts *)malloc(sizeof(struct mounts)))) {

no_space_for_mount:

            (void) fprintf(stderr, "%s: no space for mount at ", Pn);
            safestrprt(mp->mnt_fsname, stderr, 0);
            (void) fprintf(stderr, " (");
            safestrprt(mp->mnt_dir, stderr, 0);
            (void) fprintf(stderr, ")\n");
            Exit(1);
        }
        mtp->dir = dn;
        dn = (char *)NULL;
        mtp->next = Lmi;
        mtp->dev = RMNT_EXPDEV(sb.st_dev);
        mtp->rdev = RMNT_EXPDEV(sb.st_rdev);
        mtp->inode = (INODETYPE)sb.st_ino;
        mtp->mode = sb.st_mode;

# if	defined(RMNT_FSTYPE) && defined(MOUNTS_FSTYPE)
        /*
         * Make a copy of RMNT_FSTYPE in MOUNTS_FSTYPE.
         */
        if (!(mtp->MOUNTS_FSTYPE = mkstrcpy(mp->RMNT_FSTYPE,
                                            (MALLOC_S *)NULL)))
        {
            (void) fprintf(stderr, "%s: no space for fstype (%s): %s\n",
                           Pn, mtp->dir, mp->RMNT_FSTYPE);
            Exit(1);
        }
        (void) strcpy(mtp->MOUNTS_FSTYPE, mp->RMNT_FSTYPE);
# endif	/* defined(RMNT_FSTYP) && defined(MOUNTS_FSTYP) */

# if	defined(RMNT_STAT_FSTYPE) && defined(MOUNTS_STAT_FSTYPE)
        /*
         * Make a copy of RMNT_STAT_FSTYPE in MOUNTS_STAT_FSTYPE.
         */
        mtp->MOUNTS_STAT_FSTYPE = (int)sb.RMNT_STAT_FSTYPE;
# endif	/* defined(RMNT_STAT_FSTYP) && defined(MOUNTS_STAT_FSTYP) */

        /*
         * Interpolate a possible file system (mounted-on device) name link.
         */
        if (!(dn = mkstrcpy(mp->mnt_fsname, (MALLOC_S *)NULL)))
            goto no_space_for_mount;
        mtp->fsname = dn;
        ln = Readlink(dn);
        dn = (char *)NULL;
        /*
         * Stat() the file system (mounted-on) name and add file system
         * information to the local mounts structure.
         */
        if (!ln || statsafely(ln, &sb))
            sb.st_mode = 0;
        mtp->fsnmres = ln;
        mtp->fs_mode = sb.st_mode;
        Lmi = mtp;
    }
    (void) endmntent(mfp);
    /*
     * Clean up and return the local nount info table address.
     */
    if (dn)
        (void) free((FREE_P *)dn);
    Lmist = 1;
    return(Lmi);
}
Exemple #3
0
struct mounts *
readmnt()
{
    int br, fd;
    int bx = sizeof(struct mnttab);
    char *cp;
    char dvnm[MAXPATHLEN], fsnm[MAXPATHLEN];
    MALLOC_S dvnml, fsnml;
    MALLOC_S len;
    char *ln = (char *)NULL;
    struct mnttab m;
    struct mounts *mtp;
    struct stat sb;

    if (Lmi || Lmist)
        return(Lmi);
    /*
     * Open access to the mount table.
     */
    if ((fd = open(MNTTAB, O_RDONLY, 0)) < 0) {
        (void) fprintf(stderr, "%s: can't open %s\n", Pn, MNTTAB);
        Exit(1);
    }
    /*
     * Read the first mount table entry.
     */
    br = read(fd, (char *)&m, bx);
    dvnml = fsnml = 0;
    /*
     * Process the next complete mount table entry.
     */
    while (br == bx) {
        if (!dvnml) {

            /*
             * Start the device and file system name assemblies.
             */
            dvnml = strlen(m.mt_dev);
            if (dvnml >= MAXPATHLEN)
                dvnml = MAXPATHLEN - 1;
            (void) strncpy(dvnm, m.mt_dev, dvnml);
            dvnm[dvnml] = '\0';
            fsnml = strlen(m.mt_filsys);
            if (fsnml >= MAXPATHLEN)
                fsnml = MAXPATHLEN - 1;
            (void) strncpy(fsnm, m.mt_filsys, fsnml);
            fsnm[fsnml] = '\0';
        }
        while ((br = read(fd, (char *)&m, bx)) == bx
                &&      strcmp(m.mt_filsys, "nothing") == 0
                &&	    strcmp(m.mt_dev,    "nowhere") == 0) {

            /*
             * Add the "nothing/nowhere" extensions to the assemblies.
             */
            len = strlen(&m.mt_dev[8]);
            if (len >= (MAXPATHLEN - dvnml))
                len = MAXPATHLEN - dvnml - 1;
            if (len) {
                (void) strncpy(&dvnm[dvnml], &m.mt_dev[8], len);
                dvnml += len;
                dvnm[dvnml] = '\0';
            }
            len = strlen(&m.mt_filsys[8]);
            if (len >= (MAXPATHLEN - fsnml))
                len = MAXPATHLEN - fsnml - 1;
            if (len) {
                (void) strncpy(&fsnm[fsnml], &m.mt_filsys[8], len);
                fsnml += len;
                fsnm[fsnml] = '\0';
            }
        }
        /*
         * Skip automount place markers.
         */
        if ((cp = strrchr(dvnm, ':')) && strncmp(cp, ":(pid", 5) == 0) {
            dvnml = fsnml = 0;
            continue;
        }
        /*
         * Interpolate a possible symbolic directory link.
         */
        if (ln) {
            (void) free((FREE_P *)ln);
            ln = (char *)NULL;
        }
        if (!(ln = Readlink(fsnm))) {
            if (!Fwarn) {
                (void) fprintf(stderr,
                               "      Output information may be incomplete.\n");
            }
            dvnml = fsnml = 0;
            continue;
        }
        if (*ln != '/')
            continue;
        if (ln == fsnm) {

            /*
             * Allocate space for a copy of the file system name.
             */
            if (!(ln = mkstrcpy(fsnm, (MALLOC_S *)NULL))) {

no_space_for_mount:

                (void) fprintf(stderr, "%s: no space for mount at ", Pn);
                safestrprt(fsnm, stderr, 0);
                (void) fprintf(stderr, " (");
                safestrprt(dvnm, stderr, 0);
                (void) fprintf(stderr, ")\n");
                Exit(1);
            }
        }
        /*
         * Stat() the directory.
         */
        if (statsafely(ln, &sb)) {
            if (!Fwarn) {
                (void) fprintf(stderr,
                               "%s: WARNING: can't stat() file system: ", Pn);
                safestrprt(fsnm, stderr, 1);
                (void) fprintf(stderr,
                               "      Output information may be incomplete.\n");
            }
            dvnml = fsnml = 0;
            continue;
        }
        /*
         * Allocate and fill a local mount structure.
         */
        if (!(mtp = (struct mounts *)malloc(sizeof(struct mounts))))
            goto no_space_for_mount;
        mtp->dir = ln;
        ln = (char *)NULL;
        mtp->next = Lmi;
        mtp->dev = sb.st_dev;
        mtp->rdev = sb.st_rdev;
        mtp->inode = (INODETYPE)sb.st_ino;
        mtp->mode = sb.st_mode;
        /*
         * Interpolate a possible file system (mounted-on) device name link
         */
        if (!(cp = mkstrcpy(dvnm, (MALLOC_S *)NULL)))
            goto no_space_for_mount;
        mtp->fsname = cp;
        ln = Readlink(cp);
        /*
         * Stat() the file system (mounted-on) name and add file system
         * information to the local mount table entry.
         */
        if (statsafely(ln, &sb))
            sb.st_mode = 0;
        mtp->fsnmres = ln;
        ln = (char *)NULL;
        mtp->fs_mode = sb.st_mode;
        Lmi = mtp;
        dvnml = fsnml = 0;
    }
    (void) close(fd);
    /*
     * Clean up and return the local mount information table address.
     */
    if (ln)
        (void) free((FREE_P *)ln);
    Lmist = 1;
    return(Lmi);
}
Exemple #4
0
struct mounts *
readmnt()
{
	char *dn = (char *)NULL;
	char *ln;
	struct mnttab me;
	FILE *mfp;
	struct mounts *mtp;
	char *opt, *opte;
	struct stat sb;

#if	defined(HASPROCFS)
	int procfs = 0;
#endif

	if (Lmi || Lmist)
	    return(Lmi);
/*
 * Open access to the mount table and read mount table entries.
 */
	if (!(mfp = fopen(MNTTAB, "r"))) {
	    (void) fprintf(stderr, "%s: can't access %s\n", Pn, MNTTAB);
	    return(0);
        }
	while (!getmntent(mfp, &me)) {

	/*
	 * Skip loop-back mounts, since they are aliases for legitimate file
	 * systems and there is no way to determine that a vnode refers to a
	 * loop-back alias.
	 *
	 * Also skip file systems of type MNTTYPE_IGNORE or with the option
	 * MNTOPT_IGNORE, since they are auto-mounted file systems whose
	 * real entries (if they are mounted) will be separately identified
	 * by getmntent().
	 */
	    if (!strcmp(me.mnt_fstype, MNTTYPE_LO)
	    ||  !strcmp(me.mnt_fstype, MNTTYPE_IGNORE))
		continue;
	/*
	 * Interpolate a possible symbolic directory link.
	 */
	    if (dn)
		(void) free((FREE_P *)dn);
	    if (!(dn = mkstrcpy(me.mnt_mountp, (MALLOC_S *)NULL))) {

no_space_for_mount:

		(void) fprintf(stderr, "%s: no space for mount at ",Pn);
		safestrprt(me.mnt_special, stderr, 0);
		(void) fprintf(stderr, " (");
		safestrprt(me.mnt_mountp, stderr, 0);
		(void) fprintf(stderr, ")\n");
		Exit(1);
	    }
	    if (!(ln = Readlink(dn))) {
		if (!Fwarn) {
		    (void) fprintf(stderr,
			"      Output information may be incomplete.\n");
		}
		continue;
	    }
	    if (ln != dn) {
		(void) free((FREE_P *)dn);
		dn = ln;
	    }
	    if (*dn != '/')
		continue;
	/*
	 * Stat() the directory.
	 */
	    if (statsafely(dn, &sb)) {
		if (!Fwarn) {
		    (void) fprintf(stderr, "%s: can't stat()", Pn);

#if	defined(HASFSTYPE)
		    putc(' ', stderr);
		    safestrprt(me.mnt_fstype, stderr, 0);
#endif	/* defined(HASFSTYPE) */

		    (void) fprintf(stderr, " file system ");
		    safestrprt(me.mnt_mountp, stderr, 1);
		    (void) fprintf(stderr,
			"      Output information may be incomplete.\n");
		}
		if (!(opt = strstr(me.mnt_mntopts, "dev="))) {
		    (void) memset(&sb, 0, sizeof(sb));
		    if (!(opte = x2dev(opt + 4, &sb.st_dev))) {
			sb.st_mode = S_IFDIR | 0777;

#if	defined(HASFSTYPE)
			(void) strncpy(sb.st_fstype, me.mnt_fstype,
				       sizeof(sb.st_fstype));
			sb.st_fstype[sizeof(sb.st_fstype) - 1 ] = '\0';
#endif	/* HASFSTYPE */

			if (!Fwarn) {
			    (void) fprintf(stderr,
				"      assuming \"%.*s\" from %s\n",
				(opte - opt), opt, MNTTAB);
			}
		    } else
			opt = (char *)NULL;
		}
		if (!opt)
		    continue;
	    }
	/*
	 * Allocate and fill a local mount structure.
	 */
	    if (!(mtp = (struct mounts *)malloc(sizeof(struct mounts))))
		goto no_space_for_mount;

#if	defined(HASFSTYPE)
	    if (!(mtp->fstype = mkstrcpy(sb.st_fstype, (MALLOC_S *)NULL)))
		goto no_space_for_mount;
#endif	/* HASFSTYPE */

	    mtp->dir = dn;
	    dn = (char *)NULL;
	    mtp->next = Lmi;
	    mtp->dev = sb.st_dev;
	    mtp->rdev = sb.st_rdev;
	    mtp->inode = (INODETYPE)sb.st_ino;
	    mtp->mode = sb.st_mode;

#if	defined(HASPROCFS)
# if	defined(HASFSTYPE)
	    if (!strcmp(sb.st_fstype, HASPROCFS))
# else	/* !defined*HASFSTYPE) */
	    if (!strcmp(me.mnt_special, "/proc"))
# endif	/* defined(HASFSTYPE) */

	    {

	    /*
	     * Save information on exactly one procfs file system.
	     */
		if (procfs)
		    Mtprocfs = (struct mounts *)NULL;
		else {
		    procfs = 1;
		    Mtprocfs = mtp;
		}
	    }
#endif	/* defined(HASPROCFS) */

	/*
	 * Interpolate a possible file system (mounted-on device) name link.
	 */
	    if (!(dn = mkstrcpy(me.mnt_special, (MALLOC_S *)NULL)))
		goto no_space_for_mount;
	    mtp->fsname = dn;
	    ln = Readlink(dn);
	    dn = (char *)NULL;
	/*
	 * Stat() the file system (mounted-on) name and add file system
	 * information to the local mounts structure.
	 */
	    if (!ln || statsafely(ln, &sb))
		sb.st_mode = 0;
	    mtp->fsnmres = ln;
	    mtp->fs_mode = sb.st_mode;
	    Lmi = mtp;
        }
	(void) fclose(mfp);
/*
 * Clean up and return local mount info table address.
 */
	if (dn)
	    (void) free((FREE_P *)dn);
	Lmist = 1;
	return(Lmi);
}
Exemple #5
0
int procan(FILE *outfile) {

   /*filan(0, outfile);*/

   /* controlling terminal */
   fprintf(outfile, "process id = "F_pid"\n", Getpid());
   fprintf(outfile, "process parent id = "F_pid"\n", Getppid());
   {
      int fd;
      if ((fd = Open("/dev/tty", O_NOCTTY, 0)) < 0) {
	 fprintf(outfile, "controlling terminal: -\n");
      } else {
#if 1
	 fprintf(outfile, "controlling terminal: \"%s\"\n", Ttyname(fd));
#else
	 char procpath[PATH_MAX], devpath[PATH_MAX+1];
	 int devlen;
	 sprintf(procpath, "/proc/"F_pid"/fd/%d", Getpid(), 0 /*! fd*/);
	 if ((devlen = Readlink(procpath, devpath, sizeof(devpath))) < 0) {
	    ;
	 } else {
	    devpath[devlen] = '\0';
	    fprintf(outfile, "controlling terminal: \"%s\"\n", devpath);
	 }
#endif
      }
   }
   fprintf(outfile, "process group id = "F_pid"\n", Getpgrp());
#if HAVE_GETSID
   fprintf(outfile, "process session id = "F_pid"\n", Getsid(0));
#endif
   fprintf(outfile, "process group id if fg process / stdin = "F_pid"\n", Tcgetpgrp(0));
   fprintf(outfile, "process group id if fg process / stdout = "F_pid"\n", Tcgetpgrp(1));
   fprintf(outfile, "process group id if fg process / stderr = "F_pid"\n", Tcgetpgrp(2));
   {
      int fd;
      if ((fd = Open("/dev/tty", O_RDWR, 0600)) >= 0) {
	 fprintf(outfile, "process has a controlling terminal\n");
	 Close(fd);
      } else {
	 fprintf(outfile, "process does not have a controlling terminal\n");
      }
   }

   /* process owner, groups */
   fprintf(outfile, "user id  = "F_uid"\n", Getuid());
   fprintf(outfile, "effective user id  = "F_uid"\n", Geteuid());
   fprintf(outfile, "group id = "F_gid"\n", Getgid());
   fprintf(outfile, "effective group id = "F_gid"\n", Getegid());

   {
      struct rlimit rlim;

      fprintf(outfile, "\nRESOURCE LIMITS\n");
      fprintf(outfile, "resource                         current         maximum\n");
      if (getrlimit(RLIMIT_CPU, &rlim) < 0) {
	 Warn2("getrlimit(RLIMIT_CPU, %p): %s", &rlim, strerror(errno));
      } else {
	 fprintf(outfile,
		 "cpu time (seconds)      %16"F_rlim_max"%16"F_rlim_max"\n",
		 rlim.rlim_cur, rlim.rlim_max);
      }
      if (getrlimit(RLIMIT_FSIZE, &rlim) < 0) {
	 Warn2("getrlimit(RLIMIT_FSIZE, %p): %s", &rlim, strerror(errno));
      } else {
	 fprintf(outfile,
		 "file size (blocks)      %16"F_rlim_max"%16"F_rlim_max"\n",
		 rlim.rlim_cur, rlim.rlim_max);
      }
      if (getrlimit(RLIMIT_DATA, &rlim) < 0) {
	 Warn2("getrlimit(RLIMIT_DATA, %p): %s", &rlim, strerror(errno));
      } else {
	 fprintf(outfile,
		 "data seg size (kbytes)  %16"F_rlim_max"%16"F_rlim_max"\n",
		 rlim.rlim_cur, rlim.rlim_max);
      }
      if (getrlimit(RLIMIT_STACK, &rlim) < 0) {
	 Warn2("getrlimit(RLIMIT_STACK, %p): %s", &rlim, strerror(errno));
      } else {
	 fprintf(outfile,
		 "stack size (blocks)     %16"F_rlim_max"%16"F_rlim_max"\n",
		 rlim.rlim_cur, rlim.rlim_max);
      }
      if (getrlimit(RLIMIT_CORE, &rlim) < 0) {
	 Warn2("getrlimit(RLIMIT_CORE, %p): %s", &rlim, strerror(errno));
      } else {
	 fprintf(outfile,
		 "core file size (blocks) %16"F_rlim_max"%16"F_rlim_max"\n",
		 rlim.rlim_cur, rlim.rlim_max);
      }
#ifdef RLIMIT_RSS	/* Linux, AIX; not Cygwin */
      if (getrlimit(RLIMIT_RSS, &rlim) < 0) {
	 Warn2("getrlimit(RLIMIT_RSS, %p): %s", &rlim, strerror(errno));
      } else {
	 fprintf(outfile,
		 "max resident set size   %16"F_rlim_max"%16"F_rlim_max"\n",
		 rlim.rlim_cur, rlim.rlim_max);
      }
#endif
#ifdef RLIMIT_NPROC	/* Linux, not AIX, Cygwin */
      if (getrlimit(RLIMIT_NPROC, &rlim) < 0) {
	 Warn2("getrlimit(RLIMIT_NPROC, %p): %s", &rlim, strerror(errno));
      } else {
	 fprintf(outfile,
		 "max user processes      %16"F_rlim_max"%16"F_rlim_max"\n",
		 rlim.rlim_cur, rlim.rlim_max);
      }
#endif
#ifdef RLIMIT_NOFILE	/* not AIX 4.1 */
      if (getrlimit(RLIMIT_NOFILE, &rlim) < 0) {
	 Warn2("getrlimit(RLIMIT_NOFILE, %p): %s", &rlim, strerror(errno));
      } else {
	 fprintf(outfile,
		 "open files              %16"F_rlim_max"%16"F_rlim_max"\n",
		 rlim.rlim_cur, rlim.rlim_max);
      }
#endif
#ifdef RLIMIT_MEMLOCK	/* Linux, not AIX, Cygwin */
      if (getrlimit(RLIMIT_MEMLOCK, &rlim) < 0) {
	 Warn2("getrlimit(RLIMIT_MEMLOCK, %p): %s", &rlim, strerror(errno));
      } else {
	 fprintf(outfile,
		 "max locked-in-memory address space %16"F_rlim_max"%16"F_rlim_max"\n",
		 rlim.rlim_cur, rlim.rlim_max);
      }
#endif
#ifdef RLIMIT_AS
      if (getrlimit(RLIMIT_AS, &rlim) < 0) {
	 Warn2("getrlimit(RLIMIT_AS, %p): %s", &rlim, strerror(errno));
      } else {
	 fprintf(outfile,
		 "virtual memory (kbytes) %16"F_rlim_max"%16"F_rlim_max"\n",
		 rlim.rlim_cur, rlim.rlim_max);
      }
#endif
   }

   /* file descriptors */

   /* what was this for?? */
   /*Sleep(1);*/
   return 0;
}