-/* $Cambridge: exim/src/src/lookups/lf_check_file.c,v 1.5 2009/11/16 19:50:38 nm4 Exp $ */
-
/*************************************************
* Exim - an Internet mail transport agent *
*************************************************/
+/* Copyright (c) The Exim Maintainers 2020 - 2023 */
/* Copyright (c) University of Cambridge 1995 - 2009 */
/* See the file NOTICE for conditions of use and distribution. */
+/* SPDX-License-Identifier: GPL-2.0-or-later */
#include "../exim.h"
*/
int
-lf_check_file(int fd, uschar *filename, int s_type, int modemask, uid_t *owners,
- gid_t *owngroups, const char *type, uschar **errmsg)
+lf_check_file(int fd, const uschar * filename, int s_type, int modemask,
+ uid_t * owners, gid_t * owngroups, const char * type, uschar ** errmsg)
{
-int i;
struct stat statbuf;
-if ((fd >= 0 && fstat(fd, &statbuf) != 0) ||
- (fd < 0 && Ustat(filename, &statbuf) != 0))
+if ((fd < 0 ? Ustat(filename, &statbuf) : fstat(fd, &statbuf)) != 0)
{
int save_errno = errno;
*errmsg = string_sprintf("%s: stat failed", filename);
return +1;
}
-if (owners != NULL)
+if (owners)
{
BOOL uid_ok = FALSE;
- for (i = 1; i <= (int)owners[0]; i++)
+ for (int i = 1; i <= (int)owners[0]; i++)
if (owners[i] == statbuf.st_uid) { uid_ok = TRUE; break; }
if (!uid_ok)
{
}
}
-if (owngroups != NULL)
+if (owngroups)
{
BOOL gid_ok = FALSE;
- for (i = 1; i <= (int)owngroups[0]; i++)
+ for (int i = 1; i <= (int)owngroups[0]; i++)
if (owngroups[i] == statbuf.st_gid) { gid_ok = TRUE; break; }
if (!gid_ok)
{