1993-08-26 01:19:55 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2002-04-01 09:39:07 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1997-10-08 07:48:21 +00:00
|
|
|
#include <err.h>
|
1993-08-26 01:19:55 +00: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)
|
|
|
|
{
|
|
|
|
char *cp1, *cp2;
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
if (dir[0] == '/')
|
|
|
|
cp1 = cp2 = dir + 1;
|
|
|
|
else
|
|
|
|
cp1 = cp2 = dir;
|
|
|
|
while (cp2) {
|
2000-10-22 09:53:27 +00:00
|
|
|
if ((cp2 = strchr(cp1, '/')) !=NULL )
|
1993-08-26 01:19:55 +00:00
|
|
|
*cp2 = '\0';
|
|
|
|
if (fexists(dir)) {
|
2000-02-19 08:52:52 +00:00
|
|
|
if (!isdir(dir)) {
|
|
|
|
if (cp2)
|
|
|
|
*cp2 = '/';
|
1993-08-26 01:19:55 +00:00
|
|
|
return FAIL;
|
2000-02-19 08:52:52 +00:00
|
|
|
}
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
else {
|
2004-06-29 19:06:42 +00:00
|
|
|
if (vsystem("/bin/mkdir %s", dir)) {
|
2000-02-19 08:52:52 +00:00
|
|
|
if (cp2)
|
|
|
|
*cp2 = '/';
|
1993-08-26 01:19:55 +00:00
|
|
|
return FAIL;
|
2000-02-19 08:52:52 +00:00
|
|
|
}
|
1993-08-26 01:19:55 +00:00
|
|
|
apply_perms(NULL, dir);
|
|
|
|
}
|
|
|
|
/* Put it back */
|
|
|
|
if (cp2) {
|
|
|
|
*cp2 = '/';
|
|
|
|
cp1 = cp2 + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Using permission defaults, apply them as necessary */
|
|
|
|
void
|
2001-10-10 06:58:42 +00:00
|
|
|
apply_perms(const char *dir, const char *arg)
|
1993-08-26 01:19:55 +00:00
|
|
|
{
|
2001-10-10 06:58:42 +00:00
|
|
|
const char *cd_to;
|
1993-08-26 01:19:55 +00:00
|
|
|
|
1994-12-06 00:51:50 +00:00
|
|
|
if (!dir || *arg == '/') /* absolute path? */
|
|
|
|
cd_to = "/";
|
1993-08-26 01:19:55 +00:00
|
|
|
else
|
1994-12-06 00:51:50 +00:00
|
|
|
cd_to = dir;
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
if (Mode)
|
2004-06-29 19:06:42 +00:00
|
|
|
if (vsystem("cd %s && /bin/chmod -R %s %s", cd_to, Mode, arg))
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("couldn't change modes of '%s' to '%s'", arg, Mode);
|
1994-12-06 00:51:50 +00:00
|
|
|
if (Owner && Group) {
|
2004-06-29 19:06:42 +00:00
|
|
|
if (vsystem("cd %s && /usr/sbin/chown -R %s:%s %s", cd_to, Owner, Group, arg))
|
2001-09-11 11:11:38 +00:00
|
|
|
warnx("couldn't change owner/group of '%s' to '%s:%s'",
|
1994-12-06 00:51:50 +00:00
|
|
|
arg, Owner, Group);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Owner) {
|
2004-06-29 19:06:42 +00:00
|
|
|
if (vsystem("cd %s && /usr/sbin/chown -R %s %s", cd_to, Owner, arg))
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("couldn't change owner of '%s' to '%s'", arg, Owner);
|
1994-12-06 00:51:50 +00:00
|
|
|
return;
|
|
|
|
} else if (Group)
|
2004-06-29 19:06:42 +00:00
|
|
|
if (vsystem("cd %s && /usr/bin/chgrp -R %s %s", cd_to, Group, arg))
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("couldn't change group of '%s' to '%s'", arg, Group);
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
|