2016-02-15 13:02:05 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2020-06-02 15:26:54 +00:00
|
|
|
#ifdef WITH_NSS
|
2016-05-13 10:46:35 +00:00
|
|
|
# include "virmock.h"
|
2016-02-15 13:02:05 +00:00
|
|
|
# include <sys/types.h>
|
|
|
|
# include <dirent.h>
|
|
|
|
# include <sys/stat.h>
|
|
|
|
# include <fcntl.h>
|
2016-11-29 12:48:53 +00:00
|
|
|
# include <unistd.h>
|
2016-02-15 13:02:05 +00:00
|
|
|
|
|
|
|
# include "configmake.h"
|
|
|
|
|
2016-05-13 10:46:35 +00:00
|
|
|
static int (*real_open)(const char *path, int flags, ...);
|
2024-03-13 16:25:35 +00:00
|
|
|
# if WITH___OPEN_2
|
|
|
|
static int (*real___open_2)(const char *path, int flags);
|
|
|
|
# endif
|
2016-05-13 10:46:35 +00:00
|
|
|
static DIR * (*real_opendir)(const char *name);
|
2016-11-29 12:48:53 +00:00
|
|
|
static int (*real_access)(const char *path, int mode);
|
2016-02-15 13:02:05 +00:00
|
|
|
|
|
|
|
# define LEASEDIR LOCALSTATEDIR "/lib/libvirt/dnsmasq/"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Functions to load the symbols and init the environment
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
init_syms(void)
|
|
|
|
{
|
2016-05-13 10:46:35 +00:00
|
|
|
if (real_open)
|
2016-02-15 13:02:05 +00:00
|
|
|
return;
|
|
|
|
|
2016-05-13 10:46:35 +00:00
|
|
|
VIR_MOCK_REAL_INIT(open);
|
2024-03-13 16:25:35 +00:00
|
|
|
# if WITH___OPEN_2
|
|
|
|
VIR_MOCK_REAL_INIT(__open_2);
|
|
|
|
# endif
|
2016-05-13 10:46:35 +00:00
|
|
|
VIR_MOCK_REAL_INIT(opendir);
|
2016-11-29 12:48:53 +00:00
|
|
|
VIR_MOCK_REAL_INIT(access);
|
2016-02-15 13:02:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
getrealpath(char **newpath,
|
|
|
|
const char *path)
|
|
|
|
{
|
|
|
|
if (STRPREFIX(path, LEASEDIR)) {
|
2019-10-22 13:26:14 +00:00
|
|
|
*newpath = g_strdup_printf("%s/nssdata/%s",
|
|
|
|
abs_srcdir,
|
|
|
|
path + strlen(LEASEDIR));
|
2016-02-15 13:02:05 +00:00
|
|
|
} else {
|
2019-10-20 11:49:46 +00:00
|
|
|
*newpath = g_strdup(path);
|
2016-02-15 13:02:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
open(const char *path, int flags, ...)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char *newpath = NULL;
|
|
|
|
|
|
|
|
init_syms();
|
|
|
|
|
|
|
|
if (STRPREFIX(path, LEASEDIR) &&
|
|
|
|
getrealpath(&newpath, path) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (flags & O_CREAT) {
|
|
|
|
va_list ap;
|
|
|
|
mode_t mode;
|
|
|
|
va_start(ap, flags);
|
2018-04-30 15:30:12 +00:00
|
|
|
mode = (mode_t) va_arg(ap, int);
|
2016-02-15 13:02:05 +00:00
|
|
|
va_end(ap);
|
2016-05-13 10:46:35 +00:00
|
|
|
ret = real_open(newpath ? newpath : path, flags, mode);
|
2016-02-15 13:02:05 +00:00
|
|
|
} else {
|
2016-05-13 10:46:35 +00:00
|
|
|
ret = real_open(newpath ? newpath : path, flags);
|
2016-02-15 13:02:05 +00:00
|
|
|
}
|
|
|
|
|
2016-11-29 13:59:25 +00:00
|
|
|
free(newpath);
|
2016-02-15 13:02:05 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-03-13 16:25:35 +00:00
|
|
|
# if WITH___OPEN_2
|
|
|
|
int
|
|
|
|
__open_2(const char *path, int flags)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char *newpath = NULL;
|
|
|
|
|
|
|
|
init_syms();
|
|
|
|
|
|
|
|
if (STRPREFIX(path, LEASEDIR) &&
|
|
|
|
getrealpath(&newpath, path) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
ret = real___open_2(newpath ? newpath : path, flags);
|
|
|
|
|
|
|
|
free(newpath);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
2016-02-15 13:02:05 +00:00
|
|
|
DIR *
|
|
|
|
opendir(const char *path)
|
|
|
|
{
|
|
|
|
DIR *ret;
|
|
|
|
char *newpath = NULL;
|
|
|
|
|
|
|
|
init_syms();
|
|
|
|
|
|
|
|
if (STRPREFIX(path, LEASEDIR) &&
|
|
|
|
getrealpath(&newpath, path) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
2016-05-13 10:46:35 +00:00
|
|
|
ret = real_opendir(newpath ? newpath : path);
|
2016-02-15 13:02:05 +00:00
|
|
|
|
2016-11-29 13:59:25 +00:00
|
|
|
free(newpath);
|
2016-02-15 13:02:05 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2016-11-29 12:48:53 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
access(const char *path, int mode)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char *newpath = NULL;
|
|
|
|
|
|
|
|
init_syms();
|
|
|
|
|
|
|
|
if (STRPREFIX(path, LEASEDIR) &&
|
|
|
|
getrealpath(&newpath, path) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
ret = real_access(newpath ? newpath : path, mode);
|
|
|
|
|
|
|
|
free(newpath);
|
|
|
|
return ret;
|
|
|
|
}
|
2016-02-15 13:02:05 +00:00
|
|
|
#else
|
2016-03-27 18:07:10 +00:00
|
|
|
/* Nothing to override if NSS plugin is not enabled */
|
2016-02-15 13:02:05 +00:00
|
|
|
#endif
|