Back to index

python3.2  3.2.2
Defines | Functions | Variables
pwdmodule.c File Reference
#include "Python.h"
#include <sys/types.h>
#include <pwd.h>

Go to the source code of this file.

Defines

#define SETI(i, val)   PyStructSequence_SET_ITEM(v, i, PyLong_FromLong((long) val))
#define SETS(i, val)   sets(v, i, val)

Functions

 PyDoc_STRVAR (struct_passwd__doc__,"pwd.struct_passwd: Results from getpw*() routines.\n\n\ This object may be accessed either as a tuple of\n\ (pw_name,pw_passwd,pw_uid,pw_gid,pw_gecos,pw_dir,pw_shell)\n\ or via the object attributes as named in the above tuple.")
 PyDoc_STRVAR (pwd__doc__,"This module provides access to the Unix password database.\n\ It is available on all Unix versions.\n\ \n\ Password database entries are reported as 7-tuples containing the following\n\ items from the password database (see `<pwd.h>'), in order:\n\ pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell.\n\ The uid and gid items are integers, all others are strings. An\n\ exception is raised if the entry asked for cannot be found.")
static void sets (PyObject *v, int i, const char *val)
static PyObjectmkpwent (struct passwd *p)
 PyDoc_STRVAR (pwd_getpwuid__doc__,"getpwuid(uid) -> (pw_name,pw_passwd,pw_uid,\n\ pw_gid,pw_gecos,pw_dir,pw_shell)\n\ Return the password database entry for the given numeric user ID.\n\ See help(pwd) for more on password database entries.")
static PyObjectpwd_getpwuid (PyObject *self, PyObject *args)
 PyDoc_STRVAR (pwd_getpwnam__doc__,"getpwnam(name) -> (pw_name,pw_passwd,pw_uid,\n\ pw_gid,pw_gecos,pw_dir,pw_shell)\n\ Return the password database entry for the given user name.\n\ See help(pwd) for more on password database entries.")
static PyObjectpwd_getpwnam (PyObject *self, PyObject *args)
PyMODINIT_FUNC PyInit_pwd (void)

Variables

static PyStructSequence_Field struct_pwd_type_fields []
static PyStructSequence_Desc struct_pwd_type_desc
static int initialized
static PyTypeObject StructPwdType
static PyMethodDef pwd_methods []
static struct PyModuleDef

Define Documentation

#define SETI (   i,
  val 
)    PyStructSequence_SET_ITEM(v, i, PyLong_FromLong((long) val))
#define SETS (   i,
  val 
)    sets(v, i, val)

Function Documentation

static PyObject* mkpwent ( struct passwd *  p) [static]

Definition at line 61 of file pwdmodule.c.

{
    int setIndex = 0;
    PyObject *v = PyStructSequence_New(&StructPwdType);
    if (v == NULL)
        return NULL;

#define SETI(i,val) PyStructSequence_SET_ITEM(v, i, PyLong_FromLong((long) val))
#define SETS(i,val) sets(v, i, val)

    SETS(setIndex++, p->pw_name);
#ifdef __VMS
    SETS(setIndex++, "");
#else
    SETS(setIndex++, p->pw_passwd);
#endif
    SETI(setIndex++, p->pw_uid);
    SETI(setIndex++, p->pw_gid);
#ifdef __VMS
    SETS(setIndex++, "");
#else
    SETS(setIndex++, p->pw_gecos);
#endif
    SETS(setIndex++, p->pw_dir);
    SETS(setIndex++, p->pw_shell);

#undef SETS
#undef SETI

    if (PyErr_Occurred()) {
        Py_XDECREF(v);
        return NULL;
    }

    return v;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* pwd_getpwnam ( PyObject self,
PyObject args 
) [static]

Definition at line 126 of file pwdmodule.c.

{
    char *name;
    struct passwd *p;
    PyObject *arg, *bytes, *retval = NULL;

    if (!PyArg_ParseTuple(args, "U:getpwnam", &arg))
        return NULL;
    if ((bytes = PyUnicode_EncodeFSDefault(arg)) == NULL)
        return NULL;
    if (PyBytes_AsStringAndSize(bytes, &name, NULL) == -1)
        goto out;
    if ((p = getpwnam(name)) == NULL) {
        PyErr_Format(PyExc_KeyError,
                     "getpwnam(): name not found: %s", name);
        goto out;
    }
    retval = mkpwent(p);
out:
    Py_DECREF(bytes);
    return retval;
}

Here is the call graph for this function:

static PyObject* pwd_getpwuid ( PyObject self,
PyObject args 
) [static]

Definition at line 105 of file pwdmodule.c.

{
    unsigned int uid;
    struct passwd *p;
    if (!PyArg_ParseTuple(args, "I:getpwuid", &uid))
        return NULL;
    if ((p = getpwuid(uid)) == NULL) {
        PyErr_Format(PyExc_KeyError,
                     "getpwuid(): uid not found: %d", uid);
        return NULL;
    }
    return mkpwent(p);
}

Here is the call graph for this function:

PyDoc_STRVAR ( struct_passwd__doc__  ,
"pwd.struct_passwd: Results from getpw*() routines.\n\n\This object may be accessed either as a tuple of\n\ (pw_name,pw_passwd,pw_uid,pw_gid,pw_gecos,pw_dir,pw_shell)\n\or via the object attributes as named in the above tuple."   
)
PyDoc_STRVAR ( pwd__doc__  ,
"This module provides access to the Unix password database.\n\It is available on all Unix versions.\n\\n\Password database entries are reported as 7-tuples containing the following\n\items from the password database   see `<pwd.h>',
in order:\n\  pw_name,
pw_passwd  ,
pw_uid  ,
pw_gid  ,
pw_gecos  ,
pw_dir  ,
pw_shell.\n\The uid and gid items are  integers,
all others are strings.An\n\exception is raised if the entry asked for cannot be found."   
)
PyDoc_STRVAR ( pwd_getpwuid__doc__  ,
"getpwuid(uid) -> (pw_name,pw_passwd,pw_uid,\n\ pw_gid,pw_gecos,pw_dir,pw_shell)\n\Return the password database entry for the given numeric user ID.\n\See help(pwd) for more on password database entries."   
)
PyDoc_STRVAR ( pwd_getpwnam__doc__  ,
"getpwnam(name) -> (pw_name,pw_passwd,pw_uid,\n\ pw_gid,pw_gecos,pw_dir,pw_shell)\n\Return the password database entry for the given user name.\n\See help(pwd) for more on password database entries."   
)

Definition at line 207 of file pwdmodule.c.

Here is the call graph for this function:

static void sets ( PyObject v,
int  i,
const char *  val 
) [static]

Definition at line 48 of file pwdmodule.c.

Here is the call graph for this function:


Variable Documentation

int initialized [static]

Definition at line 44 of file pwdmodule.c.

Initial value:
 {
    {"getpwuid",        pwd_getpwuid, METH_VARARGS, pwd_getpwuid__doc__},
    {"getpwnam",        pwd_getpwnam, METH_VARARGS, pwd_getpwnam__doc__},




    {NULL,              NULL}           
}

Definition at line 183 of file pwdmodule.c.

struct PyModuleDef [static]
Initial value:
 {
    PyModuleDef_HEAD_INIT,
    "pwd",
    pwd__doc__,
    -1,
    pwd_methods,
    NULL,
    NULL,
    NULL,
    NULL
}

Definition at line 193 of file pwdmodule.c.

Initial value:
 {
    "pwd.struct_passwd",
    struct_passwd__doc__,
    struct_pwd_type_fields,
    7,
}

Definition at line 26 of file pwdmodule.c.

Initial value:
 {
    {"pw_name", "user name"},
    {"pw_passwd", "password"},
    {"pw_uid", "user id"},
    {"pw_gid", "group id"},
    {"pw_gecos", "real name"},
    {"pw_dir", "home directory"},
    {"pw_shell", "shell program"},
    {0}
}

Definition at line 9 of file pwdmodule.c.

Definition at line 45 of file pwdmodule.c.