~ubuntu-branches/ubuntu/utopic/libuser/utopic-proposed

« back to all changes in this revision

Viewing changes to python/libusermodule.c

  • Committer: Bazaar Package Importer
  • Author(s): Ghe Rivero
  • Date: 2005-09-30 16:22:04 UTC
  • Revision ID: james.westby@ubuntu.com-20050930162204-qubxaa7e2lbovdgh
Tags: upstream-0.54.dfsg.1
ImportĀ upstreamĀ versionĀ 0.54.dfsg.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2001,2002 Red Hat, Inc.
 
2
 *
 
3
 * This is free software; you can redistribute it and/or modify it under
 
4
 * the terms of the GNU Library General Public License as published by
 
5
 * the Free Software Foundation; either version 2 of the License, or
 
6
 * (at your option) any later version.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
 * General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Library General Public
 
14
 * License along with this program; if not, write to the Free Software
 
15
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
16
 */
 
17
 
 
18
#ident "$Id: libusermodule.c,v 1.30 2004/12/13 20:37:07 mitr Exp $"
 
19
 
 
20
#include <Python.h>
 
21
#ifdef HAVE_CONFIG_H
 
22
#include "config.h"
 
23
#endif
 
24
#include <pwd.h>
 
25
#include <grp.h>
 
26
#include <stdlib.h>
 
27
#include <unistd.h>
 
28
#include <utmp.h>
 
29
#include <glib.h>
 
30
#include "../lib/user.h"
 
31
#include "../lib/user_private.h"
 
32
#include "common.h"
 
33
 
 
34
#include "admin.c"
 
35
#include "ent.c"
 
36
#include "misc.c"
 
37
 
 
38
/* Return a list of the valid shells in the system, picked up from
 
39
 * getusershells(). */
 
40
static PyObject *
 
41
libuser_get_user_shells(PyObject * ignored)
 
42
{
 
43
        PyObject *ret = NULL;
 
44
        const char *shell;
 
45
 
 
46
        (void)ignored;
 
47
        DEBUG_ENTRY;
 
48
 
 
49
        ret = PyList_New(0);
 
50
        setusershell();
 
51
        while ((shell = getusershell()) != NULL) {
 
52
                PyObject *str;
 
53
 
 
54
                str = PyString_FromString(shell);
 
55
                PyList_Append(ret, str);
 
56
                Py_DECREF(str);
 
57
        }
 
58
        endusershell();
 
59
 
 
60
        DEBUG_EXIT;
 
61
        return ret;
 
62
}
 
63
 
 
64
static PyMethodDef libuser_methods[] = {
 
65
        {"admin", (PyCFunction) libuser_admin_new, METH_VARARGS | METH_KEYWORDS,
 
66
         "create a new administration context"},
 
67
        {"prompt", (PyCFunction) libuser_prompt_new, 0,
 
68
         "create and return a new prompt record"},
 
69
        {"get_user_shells", (PyCFunction) libuser_get_user_shells, 0,
 
70
         "return a list of valid shells"},
 
71
        {"ADMIN", (PyCFunction) libuser_admin_new, METH_VARARGS | METH_KEYWORDS,
 
72
         "create a new administration context"},
 
73
        {"PROMPT", (PyCFunction) libuser_prompt_new, 0,
 
74
         "create and return a new prompt record"},
 
75
        {"getUserShells", (PyCFunction) libuser_get_user_shells, 0,
 
76
         "return a list of valid shells"},
 
77
        {NULL, NULL, 0, NULL},
 
78
};
 
79
 
 
80
void
 
81
initlibuser(void)
 
82
{
 
83
        PyObject *module, *dict;
 
84
        DEBUG_ENTRY;
 
85
        module = Py_InitModule("libuser", libuser_methods);
 
86
        dict = PyModule_GetDict(module);
 
87
        PyDict_SetItemString(dict, "USER", PyInt_FromLong(lu_user));
 
88
        PyDict_SetItemString(dict, "GROUP", PyInt_FromLong(lu_group));
 
89
 
 
90
        /* User attributes. */
 
91
        PyDict_SetItemString(dict, "USERNAME",
 
92
                             PyString_FromString(LU_USERNAME));
 
93
        PyDict_SetItemString(dict, "USERPASSWORD",
 
94
                             PyString_FromString(LU_USERPASSWORD));
 
95
        PyDict_SetItemString(dict, "UIDNUMBER",
 
96
                             PyString_FromString(LU_UIDNUMBER));
 
97
        PyDict_SetItemString(dict, "GIDNUMBER",
 
98
                             PyString_FromString(LU_GIDNUMBER));
 
99
        PyDict_SetItemString(dict, "GECOS", PyString_FromString(LU_GECOS));
 
100
        PyDict_SetItemString(dict, "HOMEDIRECTORY",
 
101
                             PyString_FromString(LU_HOMEDIRECTORY));
 
102
        PyDict_SetItemString(dict, "LOGINSHELL",
 
103
                             PyString_FromString(LU_LOGINSHELL));
 
104
 
 
105
        /* Group attributes. */
 
106
        PyDict_SetItemString(dict, "GROUPNAME",
 
107
                             PyString_FromString(LU_GROUPNAME));
 
108
        PyDict_SetItemString(dict, "GROUPPASSWORD",
 
109
                             PyString_FromString(LU_GROUPPASSWORD));
 
110
        PyDict_SetItemString(dict, "ADMINISTRATORNAME",
 
111
                             PyString_FromString(LU_ADMINISTRATORNAME));
 
112
        PyDict_SetItemString(dict, "MEMBERNAME",
 
113
                             PyString_FromString(LU_MEMBERNAME));
 
114
 
 
115
        /* Shadow attributes. */
 
116
        PyDict_SetItemString(dict, "SHADOWNAME",
 
117
                             PyString_FromString(LU_SHADOWNAME));
 
118
        PyDict_SetItemString(dict, "SHADOWPASSWORD",
 
119
                             PyString_FromString(LU_SHADOWPASSWORD));
 
120
        PyDict_SetItemString(dict, "SHADOWLASTCHANGE",
 
121
                             PyString_FromString(LU_SHADOWLASTCHANGE));
 
122
        PyDict_SetItemString(dict, "SHADOWMIN",
 
123
                             PyString_FromString(LU_SHADOWMIN));
 
124
        PyDict_SetItemString(dict, "SHADOWMAX",
 
125
                             PyString_FromString(LU_SHADOWMAX));
 
126
        PyDict_SetItemString(dict, "SHADOWWARNING",
 
127
                             PyString_FromString(LU_SHADOWWARNING));
 
128
        PyDict_SetItemString(dict, "SHADOWINACTIVE",
 
129
                             PyString_FromString(LU_SHADOWINACTIVE));
 
130
        PyDict_SetItemString(dict, "SHADOWEXPIRE",
 
131
                             PyString_FromString(LU_SHADOWEXPIRE));
 
132
        PyDict_SetItemString(dict, "SHADOWFLAG",
 
133
                             PyString_FromString(LU_SHADOWFLAG));
 
134
 
 
135
        /* Additional fields. */
 
136
        PyDict_SetItemString(dict, "COMMONNAME",
 
137
                             PyString_FromString(LU_COMMONNAME));
 
138
        PyDict_SetItemString(dict, "GIVENNAME",
 
139
                             PyString_FromString(LU_GIVENNAME));
 
140
        PyDict_SetItemString(dict, "SN", PyString_FromString(LU_SN));
 
141
        PyDict_SetItemString(dict, "ROOMNUMBER",
 
142
                             PyString_FromString(LU_ROOMNUMBER));
 
143
        PyDict_SetItemString(dict, "TELEPHONENUMBER",
 
144
                             PyString_FromString(LU_TELEPHONENUMBER));
 
145
        PyDict_SetItemString(dict, "HOMEPHONE",
 
146
                             PyString_FromString(LU_HOMEPHONE));
 
147
        PyDict_SetItemString(dict, "EMAIL", PyString_FromString(LU_EMAIL));
 
148
 
 
149
        /* Miscellaneous. */
 
150
        PyDict_SetItemString(dict, "UT_NAMESIZE", PyInt_FromLong(UT_NAMESIZE));
 
151
 
 
152
        DEBUG_EXIT;
 
153
}