mirror of
https://github.com/troglobit/finit.git
synced 2026-10-29 12:40:44 +00:00
Refactor, change API for create()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
a90cfd4a75
commit
bd4efb59ca
2 files changed
+34
-17
No files matched your search
+4
-14
@@ -197,21 +197,11 @@ static void setup(void *arg)
|
|||||||
* UTMP actually needs multiple db files
|
* UTMP actually needs multiple db files
|
||||||
*/
|
*/
|
||||||
if (has_utmp()) {
|
if (has_utmp()) {
|
||||||
int gid;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If /etc/group or "utmp" group is missing, default to
|
|
||||||
* "root", or "wheel", group.
|
|
||||||
*/
|
|
||||||
dbg("Setting up necessary UTMP files ...");
|
dbg("Setting up necessary UTMP files ...");
|
||||||
gid = getgroup("utmp");
|
create("/var/run/utmp", 0644, "root", "utmp"); /* Currently logged in */
|
||||||
if (gid < 0)
|
create("/var/log/wtmp", 0644, "root", "utmp"); /* Login history */
|
||||||
gid = 0;
|
create("/var/log/btmp", 0600, "root", "utmp"); /* Failed logins */
|
||||||
|
create("/var/log/lastlog", 0644, "root", "utmp");
|
||||||
create("/var/run/utmp", 0644, 0, gid); /* Currently logged in */
|
|
||||||
create("/var/log/wtmp", 0644, 0, gid); /* Login history */
|
|
||||||
create("/var/log/btmp", 0600, 0, gid); /* Failed logins */
|
|
||||||
create("/var/log/lastlog", 0644, 0, gid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set BOOT_TIME UTMP entry */
|
/* Set BOOT_TIME UTMP entry */
|
||||||
|
|||||||
+30
-3
@@ -26,9 +26,11 @@
|
|||||||
#define FINIT_HELPERS_H_
|
#define FINIT_HELPERS_H_
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/ttydefaults.h> /* Not included by default in musl libc */
|
#include <sys/ttydefaults.h> /* Not included by default in musl libc */
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
@@ -88,10 +90,35 @@ pid_t run_getty (char *tty, char *cmd, char *args[], int noclear, int no
|
|||||||
pid_t run_sh (char *tty, int noclear, int nowait, struct rlimit rlimit[]);
|
pid_t run_sh (char *tty, int noclear, int nowait, struct rlimit rlimit[]);
|
||||||
int run_parts (char *dir, char *cmd, const char *env[], int progress);
|
int run_parts (char *dir, char *cmd, const char *env[], int progress);
|
||||||
|
|
||||||
static inline int create(char *path, mode_t mode, uid_t uid, gid_t gid)
|
/*
|
||||||
|
* Defaults to user "root" and group "wheel" (root) if:
|
||||||
|
* 1) the user is missing
|
||||||
|
* 2) the group or the file /etc/group is missing
|
||||||
|
*/
|
||||||
|
static inline int create(char *path, mode_t mode, char *user, char *group)
|
||||||
{
|
{
|
||||||
if (touch(path) || chmod(path, mode) || chown(path, uid, gid)) {
|
int fd, uid, gid;
|
||||||
warnx("Failed creating %s properly.", path);
|
|
||||||
|
if (!path) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uid = getuser(user, NULL);
|
||||||
|
if (uid < 0)
|
||||||
|
uid = 0;
|
||||||
|
gid = getgroup(group);
|
||||||
|
if (gid < 0)
|
||||||
|
gid = 0;
|
||||||
|
|
||||||
|
fd = creat(path, mode);
|
||||||
|
if (fd == -1) {
|
||||||
|
warn("Failed creating %s properly", path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
if (chown(path, uid, gid)) {
|
||||||
|
warn("Failed chowning %s properly", path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user