2 * Copyright (C) 2016 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see
16 * <http://www.gnu.org/licenses/>.
23 # include <sys/types.h>
25 # include <sys/stat.h>
29 # include "configmake.h"
30 # include "virstring.h"
31 # include "viralloc.h"
33 static int (*real_open
)(const char *path
, int flags
, ...);
34 static DIR * (*real_opendir
)(const char *name
);
35 static int (*real_access
)(const char *path
, int mode
);
37 # define LEASEDIR LOCALSTATEDIR "/lib/libvirt/dnsmasq/"
40 * Functions to load the symbols and init the environment
48 VIR_MOCK_REAL_INIT(open
);
49 VIR_MOCK_REAL_INIT(opendir
);
50 VIR_MOCK_REAL_INIT(access
);
54 getrealpath(char **newpath
,
57 if (STRPREFIX(path
, LEASEDIR
)) {
58 if (virAsprintfQuiet(newpath
, "%s/nssdata/%s",
60 path
+ strlen(LEASEDIR
)) < 0) {
65 if (VIR_STRDUP_QUIET(*newpath
, path
) < 0)
73 open(const char *path
, int flags
, ...)
80 if (STRPREFIX(path
, LEASEDIR
) &&
81 getrealpath(&newpath
, path
) < 0)
84 if (flags
& O_CREAT
) {
88 mode
= (mode_t
) va_arg(ap
, int);
90 ret
= real_open(newpath
? newpath
: path
, flags
, mode
);
92 ret
= real_open(newpath
? newpath
: path
, flags
);
100 opendir(const char *path
)
103 char *newpath
= NULL
;
107 if (STRPREFIX(path
, LEASEDIR
) &&
108 getrealpath(&newpath
, path
) < 0)
111 ret
= real_opendir(newpath
? newpath
: path
);
118 access(const char *path
, int mode
)
121 char *newpath
= NULL
;
125 if (STRPREFIX(path
, LEASEDIR
) &&
126 getrealpath(&newpath
, path
) < 0)
129 ret
= real_access(newpath
? newpath
: path
, mode
);
135 /* Nothing to override if NSS plugin is not enabled */