X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/763d5e6ad88ef3ba1cd1d7742d060e4f1e54c6b8..fb4c61dadb5bc3f21ff6f9488eaf7019b28a3f8a:/lib/user.c diff --git a/lib/user.c b/lib/user.c index 2616de3..488caf9 100644 --- a/lib/user.c +++ b/lib/user.c @@ -1,27 +1,28 @@ /* * This file is part of DisOrder - * Copyright (C) 2005 Richard Kettlewell + * Copyright (C) 2005, 2007 Richard Kettlewell * - * This program is free software; you can redistribute it and/or modify + * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA + * along with this program. If not, see . + */ +/** @file lib/user.c + * @brief Jukebox user management */ -#include -#include "types.h" +#include "common.h" #include +#include #include #include #include @@ -30,7 +31,12 @@ #include "user.h" #include "log.h" #include "configuration.h" +#include "mem.h" +/** @brief Become the jukebox user + * + * If a jukebox user is configured then becomes that user. + */ void become_mortal(void) { struct passwd *pw; @@ -54,6 +60,41 @@ void become_mortal(void) { } } +/** @brief Create the jukebox state directory + * + * If the home directory does not exist then creates it and assigns + * it suitable permissions. + */ +void make_home(void) { + struct stat sb; + struct passwd *pw; + char *home, *p; + + if(stat(config->home, &sb) < 0) { + /* create parent directories */ + home = xstrdup(config->home); + p = home; + while(*p) { + if(*p == '/' && p > home) { + *p = 0; + mkdir(home, 0755); + *p = '/'; + } + ++p; + } + /* create the directory itself */ + if(mkdir(config->home, 02755) < 0) + fatal(errno, "error creating %s", config->home); + /* make sure it has the right ownership */ + if(config->user) { + if(!(pw = getpwnam(config->user))) + fatal(0, "cannot find user %s", config->user); + if(chown(config->home, pw->pw_uid, pw->pw_gid) < 0) + fatal(errno, "error chowning %s", config->home); + } + } +} + /* Local Variables: c-basic-offset:2