1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
/*
* This file is part of the sn package.
* Distribution of sn is covered by the GNU GPL. See file COPYING.
* Copyright 1998-2000 Harold Tay.
* Copyright 2000- Patrik Rdman.
*/
/*
* Check if a newsgroup name is valid.
* Thanks pradman.
*/
#include <sys/stat.h>
#include <string.h>
#include "config.h"
#include "parameters.h"
static const char rcsid[] = "$Id$";
#define C(x) case x:
int is_valid_name (char *name)
{
register char *p;
if (!*name)
return (0);
for (p = name; *p; p++)
switch (*p)
{
C('-') C('.') if (p == name || *p == p[1] || !p[1])
return (0);
C('a') C('b') C('c') C('d') C('e') C('f') C('g') C('h') C('i')
C('j') C('k') C('l') C('m') C('n') C('o') C('p') C('q') C('r')
C('s') C('t') C('u') C('v') C('w') C('x') C('y') C('z')
C('A') C('B') C('C') C('D') C('E') C('F') C('G') C('H') C('I')
C('J') C('K') C('L') C('M') C('N') C('O') C('P') C('Q') C('R')
C('S') C('T') C('U') C('V') C('W') C('X') C('Y') C('Z')
C('_') C('+')
C('0') C('1') C('2') C('3') C('4') C('5') C('6') C('7') C('8') C('9')
continue;
default:
return (0);
}
if (p - name > GROUPNAMELEN)
return (0);
return (1);
}
int is_valid_group (char *name)
{
char path[GROUPNAMELEN + sizeof ("/.created")];
struct stat st;
if (!is_valid_name(name))
return (0);
strcat(strcpy(path, name), "/.created");
if (0 == stat(path, &st))
if (S_ISREG(st.st_mode))
if (0 == stat(name, &st))
if (snuid == st.st_uid)
if (sngid == st.st_gid)
return (1);
return (0);
}
|