1993-08-26 01:19:55 +00:00
|
|
|
#ifndef lint
|
1995-05-30 03:57:47 +00:00
|
|
|
static const char *rcsid = "$Id: futil.c,v 1.3 1994/12/06 00:51:32 jkh Exp $";
|
1993-08-26 01:19:55 +00: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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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) {
|
|
|
|
if ((cp2 = index(cp1, '/')) !=NULL )
|
|
|
|
*cp2 = '\0';
|
|
|
|
if (fexists(dir)) {
|
|
|
|
if (!isdir(dir))
|
|
|
|
return FAIL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (vsystem("mkdir %s", dir))
|
|
|
|
return FAIL;
|
|
|
|
apply_perms(NULL, dir);
|
|
|
|
}
|
|
|
|
/* Put it back */
|
|
|
|
if (cp2) {
|
|
|
|
*cp2 = '/';
|
|
|
|
cp1 = cp2 + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Using permission defaults, apply them as necessary */
|
|
|
|
void
|
1994-12-06 00:51:50 +00:00
|
|
|
apply_perms(char *dir, char *arg)
|
1993-08-26 01:19:55 +00:00
|
|
|
{
|
1994-12-06 00:51:50 +00:00
|
|
|
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)
|
1994-12-06 00:51:50 +00:00
|
|
|
if (vsystem("cd %s && chmod -R %s %s", cd_to, Mode, arg))
|
|
|
|
whinge("Couldn't change modes of '%s' to '%s'.",
|
|
|
|
arg, Mode);
|
|
|
|
if (Owner && Group) {
|
|
|
|
if (vsystem("cd %s && chown -R %s.%s %s", cd_to, Owner, Group, arg))
|
|
|
|
whinge("Couldn't change owner/group of '%s' to '%s.%s'.",
|
|
|
|
arg, Owner, Group);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Owner) {
|
|
|
|
if (vsystem("cd %s && chown -R %s %s", cd_to, Owner, arg))
|
1993-08-26 01:19:55 +00:00
|
|
|
whinge("Couldn't change owner of '%s' to '%s'.",
|
1994-12-06 00:51:50 +00:00
|
|
|
arg, Owner);
|
|
|
|
return;
|
|
|
|
} else if (Group)
|
|
|
|
if (vsystem("cd %s && chgrp -R %s %s", cd_to, Group, arg))
|
1993-08-26 01:19:55 +00:00
|
|
|
whinge("Couldn't change group of '%s' to '%s'.",
|
1994-12-06 00:51:50 +00:00
|
|
|
arg, Group);
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
|