1999-08-24 04:48:37 +04:00
|
|
|
/* $NetBSD: futil.c,v 1.8 1999/08/24 00:48:38 hubertf Exp $ */
|
1997-06-05 16:59:18 +04:00
|
|
|
|
1997-10-17 18:53:18 +04:00
|
|
|
#include <sys/cdefs.h>
|
1997-06-05 12:54:23 +04:00
|
|
|
#ifndef lint
|
1997-06-05 16:59:18 +04:00
|
|
|
#if 0
|
1997-10-16 04:31:32 +04:00
|
|
|
static const char *rcsid = "from FreeBSD Id: futil.c,v 1.7 1997/10/08 07:45:39 charnier Exp";
|
1997-06-05 16:59:18 +04:00
|
|
|
#else
|
1999-08-24 04:48:37 +04:00
|
|
|
__RCSID("$NetBSD: futil.c,v 1.8 1999/08/24 00:48:38 hubertf Exp $");
|
1997-06-05 16:59:18 +04:00
|
|
|
#endif
|
1997-06-05 12:54:23 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FreeBSD install - a package for the installation and maintainance
|
|
|
|
* of non-core utilities.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* Jordan K. Hubbard
|
|
|
|
* 18 July 1993
|
|
|
|
*
|
|
|
|
* Miscellaneous file access utilities.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1997-10-16 04:31:32 +04:00
|
|
|
#include <err.h>
|
1997-06-05 12:54:23 +04:00
|
|
|
#include "lib.h"
|
|
|
|
#include "add.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Assuming dir is a desired directory name, make it and all intervening
|
|
|
|
* directories necessary.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
make_hierarchy(char *dir)
|
|
|
|
{
|
1999-08-24 04:48:37 +04:00
|
|
|
char *cp1, *cp2;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
1999-08-24 04:48:37 +04:00
|
|
|
if (dir[0] == '/')
|
|
|
|
cp1 = cp2 = dir + 1;
|
|
|
|
else
|
|
|
|
cp1 = cp2 = dir;
|
|
|
|
while (cp2) {
|
|
|
|
if ((cp2 = strchr(cp1, '/')) != NULL)
|
|
|
|
*cp2 = '\0';
|
|
|
|
if (fexists(dir)) {
|
|
|
|
if (!(isdir(dir) || islinktodir(dir)))
|
|
|
|
return FAIL;
|
|
|
|
} else {
|
|
|
|
if (vsystem("mkdir %s", dir))
|
|
|
|
return FAIL;
|
|
|
|
apply_perms(NULL, dir);
|
|
|
|
}
|
|
|
|
/* Put it back */
|
|
|
|
if (cp2) {
|
|
|
|
*cp2 = '/';
|
|
|
|
cp1 = cp2 + 1;
|
|
|
|
}
|
1997-06-05 12:54:23 +04:00
|
|
|
}
|
1999-08-24 04:48:37 +04:00
|
|
|
return SUCCESS;
|
1997-06-05 12:54:23 +04:00
|
|
|
}
|
|
|
|
|
1999-08-24 04:48:37 +04:00
|
|
|
/*
|
|
|
|
* Using permission defaults, apply them as necessary
|
|
|
|
*/
|
1997-06-05 12:54:23 +04:00
|
|
|
void
|
|
|
|
apply_perms(char *dir, char *arg)
|
|
|
|
{
|
1999-08-24 04:48:37 +04:00
|
|
|
char *cd_to;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
1999-08-24 04:48:37 +04:00
|
|
|
if (!dir || *arg == '/')/* absolute path? */
|
|
|
|
cd_to = "/";
|
|
|
|
else
|
|
|
|
cd_to = dir;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
1999-08-24 04:48:37 +04:00
|
|
|
if (Mode)
|
|
|
|
if (vsystem("cd %s && %s -R %s %s", cd_to, CHMOD, Mode, arg))
|
|
|
|
warnx("couldn't change modes of '%s' to '%s'", arg, Mode);
|
|
|
|
if (Owner && Group) {
|
|
|
|
if (vsystem("cd %s && %s -R %s.%s %s", cd_to, CHOWN, Owner, Group, arg))
|
|
|
|
warnx("couldn't change owner/group of '%s' to '%s.%s'",
|
|
|
|
arg, Owner, Group);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Owner) {
|
|
|
|
if (vsystem("cd %s && %s -R %s %s", cd_to, CHOWN, Owner, arg))
|
|
|
|
warnx("couldn't change owner of '%s' to '%s'", arg, Owner);
|
|
|
|
return;
|
|
|
|
} else if (Group)
|
|
|
|
if (vsystem("cd %s && %s -R %s %s", cd_to, CHGRP, Group, arg))
|
|
|
|
warnx("couldn't change group of '%s' to '%s'", arg, Group);
|
1997-06-05 12:54:23 +04:00
|
|
|
}
|