File: pytcpwrap.c

package info (click to toggle)
python-tcpwrap 0.2-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 84 kB
  • ctags: 25
  • sloc: python: 72; makefile: 49; ansic: 24
file content (56 lines) | stat: -rw-r--r-- 1,992 bytes parent folder | download | duplicates (4)
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
/*
    <pytcpwrap - Python wrapper for libwrap used for hosts.allow/hosts.deny access control>
    Copyright (C) <2004>  <Eugene Coetzee>

    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, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

   e-mail author : eugene@reedflute.com
   postal address   : Dwarsstreet 75, Potchefstroom,NW Province, 2531, Rebublic of South Africa		
*/

#include "Python.h"
#include <tcpd.h>

int deny_severity=0;
int allow_severity=0;

//use STRING_UNKNOWN if parameter is not available  
int hosts_ctl(char *daemon,char *client_name,char *client_addr, char *client_user);

PyObject * pytcpwrap_hosts_ctl(PyObject *self, PyObject *args) {
    char *program,*host,*ip,*username;
    int access_ok=0;
    PyObject *result;
    
    if (! PyArg_ParseTuple(args, "ssss", &program, &host, &ip,&username)) {
        return NULL;
    }
    access_ok=hosts_ctl(program,host,ip,username);
    //printf("%s %s %s %s\n",program,host,ip,username);
    result=Py_BuildValue("i",access_ok);
    return result;

}

static PyMethodDef pytcpwrap_methods[] = {
    {"hosts_ctl", (PyCFunction)pytcpwrap_hosts_ctl, METH_VARARGS, "hosts_ctl(program,host,ip,username)a\n"},
    {NULL, NULL, 0, NULL}
};

DL_EXPORT(void) initlibtcpwrap(void)
{
    Py_InitModule3("libtcpwrap", pytcpwrap_methods, "Interface to TCP wrapppers libwrap\n");   
}