mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-25 06:25:04 +00:00
Also delete the user directory in deluser().
This commit is contained in:
parent
0d78deef42
commit
92fe93362c
1 changed files with 38 additions and 0 deletions
38
utils.c
38
utils.c
|
@ -7,6 +7,7 @@
|
|||
#include "xs_time.h"
|
||||
#include "xs_openssl.h"
|
||||
#include "xs_random.h"
|
||||
#include "xs_glob.h"
|
||||
|
||||
#include "snac.h"
|
||||
|
||||
|
@ -339,6 +340,41 @@ int resetpwd(snac *snac)
|
|||
}
|
||||
|
||||
|
||||
void rm_rf(const char *dir)
|
||||
/* does an rm -rf (yes, I'm also scared) */
|
||||
{
|
||||
xs *d = xs_str_cat(xs_dup(dir), "/" "*");
|
||||
xs *l = xs_glob(d, 0, 0);
|
||||
xs_list *p = l;
|
||||
xs_str *v;
|
||||
|
||||
if (dbglevel >= 1)
|
||||
printf("Deleting directory %s\n", dir);
|
||||
|
||||
while (xs_list_iter(&p, &v)) {
|
||||
struct stat st;
|
||||
|
||||
if (stat(v, &st) != -1) {
|
||||
if (st.st_mode & S_IFDIR) {
|
||||
rm_rf(v);
|
||||
}
|
||||
else {
|
||||
if (dbglevel >= 1)
|
||||
printf("Deleting file %s\n", v);
|
||||
|
||||
if (unlink(v) == -1)
|
||||
printf("ERROR: cannot delete file %s\n", v);
|
||||
}
|
||||
}
|
||||
else
|
||||
printf("ERROR: stat() fail for %s\n", v);
|
||||
}
|
||||
|
||||
if (rmdir(dir) == -1)
|
||||
printf("ERROR: cannot delete directory %s\n", dir);
|
||||
}
|
||||
|
||||
|
||||
int deluser(snac *user)
|
||||
/* deletes a user */
|
||||
{
|
||||
|
@ -361,5 +397,7 @@ int deluser(snac *user)
|
|||
}
|
||||
}
|
||||
|
||||
rm_rf(user->basedir);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue