1/*	$NetBSD: os.c,v 1.2 2024/02/21 22:51:00 christos Exp $	*/
2
3/*
4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5 *
6 * SPDX-License-Identifier: MPL-2.0
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
11 *
12 * See the COPYRIGHT file distributed with this work for additional
13 * information regarding copyright ownership.
14 */
15
16/*! \file */
17
18#include <errno.h>
19#include <fcntl.h>
20#include <pwd.h>
21#include <stdio.h>
22#include <sys/stat.h>
23#include <sys/types.h>
24#include <unistd.h>
25
26#include <confgen/os.h>
27
28int
29set_user(FILE *fd, const char *user) {
30	struct passwd *pw;
31
32	pw = getpwnam(user);
33	if (pw == NULL) {
34		errno = EINVAL;
35		return (-1);
36	}
37	return (fchown(fileno(fd), pw->pw_uid, -1));
38}
39