~ubuntu-branches/ubuntu/trusty/clamav/trusty-proposed

« back to all changes in this revision

Viewing changes to clamscan/others.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Gran
  • Date: 2005-09-19 09:05:59 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050919090559-hikpqduq8yx5qxo2
Tags: 0.87-1
* New upstream version
  - Fixes CAN-2005-2920 and CAN-2005-2919 (closes: #328660)
* New logcheck line for clamav-daemon (closes: #323132)
* relibtoolize and apply kfreebsd patch (closes: #327707)
* Make sure init.d script starts freshclam up again after upgrade when run
  from if-up.d (closes: #328912)

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
#include <signal.h>
41
41
#include <target.h>
42
42
 
 
43
#ifdef HAVE_REGEX_H
 
44
#include <regex.h>
 
45
#endif
 
46
 
43
47
#include "output.h"
44
48
#include "others.h"
45
49
 
73
77
        struct passwd *user;
74
78
        int ret = 0, status;
75
79
 
76
 
    if(!getuid()) {
 
80
    if(!geteuid()) {
77
81
 
78
82
        if((user = getpwnam(username)) == NULL) {
79
83
            return -1;
113
117
    return ret;
114
118
}
115
119
 
116
 
int filecopy(const char *src, const char *dest)
117
 
{
118
 
        char buffer[FILEBUFF];
119
 
        int s, d, bytes;
120
 
 
121
 
    if((s = open(src, O_RDONLY)) == -1)
122
 
        return -1;
123
 
 
124
 
    if((d = open(dest, O_CREAT|O_WRONLY|O_TRUNC)) == -1) {
125
 
        close(s);
126
 
        return -1;
127
 
    }
128
 
 
129
 
    while((bytes = read(s, buffer, FILEBUFF)) > 0)
130
 
        write(d, buffer, bytes);
131
 
 
132
 
    close(s);
133
 
 
134
 
    /* njh@bandsman.co.uk: check result of close for NFS file */
135
 
    return close(d);
136
 
}
137
 
 
138
 
int isnumb(const char *str)
139
 
{
140
 
        int i;
141
 
 
142
 
    for(i = 0; i < strlen(str); i++)
143
 
        if(!isdigit(str[i]))
144
 
            return 0;
145
 
 
146
 
    return 1;
 
120
int match_regex(const char *filename, const char *pattern)
 
121
{
 
122
#ifdef HAVE_REGEX_H
 
123
        regex_t reg;
 
124
        int match, flags;
 
125
#if !defined(C_CYGWIN) && !defined(C_OS2)
 
126
        flags = REG_EXTENDED;
 
127
#else
 
128
        flags = REG_EXTENDED | REG_ICASE; /* case insensitive on Windows */
 
129
#endif  
 
130
        if(regcomp(&reg, pattern, flags) != 0) {
 
131
            mprintf("!%s: Could not parse regular expression %s.\n", filename, pattern);
 
132
            logg("!%s: Could not parse regular expression %s.\n", filename, pattern);
 
133
                return 2;
 
134
        }
 
135
        match = (regexec(&reg, filename, 0, NULL, 0) == REG_NOMATCH) ? 0 : 1;
 
136
        regfree(&reg);
 
137
        return match;
 
138
#else /* HAVE_REGEX_H */
 
139
        return strstr(filename, pattern) ? 1 : 0;
 
140
#endif
147
141
}