b151ef55 |
/* |
41b894c7 |
* Copyright (C) 1999 - 2004 Tomasz Kojm <tkojm@clamav.net> |
b151ef55 |
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software |
30738099 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA. |
b151ef55 |
*
* Sat May 18 15:20:26 CEST 2002: included detectCpu() from Magnus Ekdahl
* Sat Jun 29 12:19:26 CEST 2002: fixed non386 detectCpu (Magnus Ekdahl)
*
*/
|
8b242bb9 |
#if HAVE_CONFIG_H
#include "clamav-config.h"
#endif
|
b151ef55 |
#include <stdio.h>
#include <stdlib.h> |
36f2038b |
#include <string.h> |
b151ef55 |
#include <ctype.h>
#include <unistd.h> |
e225f17c |
#include <errno.h> |
36f2038b |
#include <pwd.h> |
b151ef55 |
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <time.h>
#include <fcntl.h>
#include <signal.h>
#include <target.h>
|
4cc291aa |
#ifdef HAVE_REGEX_H
#include <regex.h>
#endif
|
36f2038b |
#include "output.h" |
ad640f0b |
#include "others.h" |
b151ef55 |
int fileinfo(const char *filename, short i)
{
struct stat infostruct;
if(stat(filename, &infostruct) == -1)
return(-1);
switch(i) {
case 1: /* size */
return infostruct.st_size;
case 2: /* permissions */
return (mode_t)infostruct.st_mode;
case 3: /* modification time */
return infostruct.st_mtime;
case 4: /* UID */
return infostruct.st_uid;
case 5: /* GID */
return infostruct.st_gid;
default: |
f1c4563e |
logg("!fileinfo(): Unknown option.\n"); |
b151ef55 |
exit(1);
}
}
|
941f3ab8 |
int checkaccess(const char *path, const char *username, int mode) |
b151ef55 |
{
struct passwd *user; |
941f3ab8 |
int ret = 0, status; |
b151ef55 |
|
a6c3fdb9 |
if(!geteuid()) { |
b151ef55 |
if((user = getpwnam(username)) == NULL) {
return -1;
}
|
941f3ab8 |
switch(fork()) {
case -1:
return -2;
case 0: |
eeb69538 |
if(setgid(user->pw_gid)) {
fprintf(stderr, "ERROR: setgid(%d) failed.\n", (int) user->pw_gid);
exit(0);
}
if(setuid(user->pw_uid)) {
fprintf(stderr, "ERROR: setuid(%d) failed.\n", (int) user->pw_uid);
exit(0);
}
|
941f3ab8 |
if(access(path, mode))
exit(0);
else
exit(1);
default:
wait(&status);
if(WIFEXITED(status) && WEXITSTATUS(status) == 1)
ret = 1; |
b151ef55 |
}
|
941f3ab8 |
} else {
if(!access(path, mode))
ret = 1; |
b151ef55 |
}
|
941f3ab8 |
return ret; |
b151ef55 |
}
|
4cc291aa |
int match_regex(const char *filename, const char *pattern)
{
#ifdef HAVE_REGEX_H
regex_t reg;
int match, flags;
#if !defined(C_CYGWIN) && !defined(C_OS2) |
65ae67b7 |
flags = REG_EXTENDED; |
4cc291aa |
#else |
65ae67b7 |
flags = REG_EXTENDED | REG_ICASE; /* case insensitive on Windows */ |
4cc291aa |
#endif
if(regcomp(®, pattern, flags) != 0) {
logg("!%s: Could not parse regular expression %s.\n", filename, pattern);
return 2;
}
match = (regexec(®, filename, 0, NULL, 0) == REG_NOMATCH) ? 0 : 1;
regfree(®);
return match;
#else /* HAVE_REGEX_H */
return strstr(filename, pattern) ? 1 : 0;
#endif
} |