Renamed.
This commit is contained in:
parent
d96dfb72ea
commit
50c5cf132a
|
@ -31,16 +31,16 @@ PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
/* UNIX password file access module */
|
/* UNIX password file access module */
|
||||||
|
|
||||||
#include "allobjects.h"
|
#include "Python.h"
|
||||||
#include "modsupport.h"
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
|
||||||
static object *mkpwent(p)
|
static PyObject *
|
||||||
|
mkpwent(p)
|
||||||
struct passwd *p;
|
struct passwd *p;
|
||||||
{
|
{
|
||||||
return mkvalue("(ssllsss)",
|
return Py_BuildValue("(ssllsss)",
|
||||||
p->pw_name,
|
p->pw_name,
|
||||||
p->pw_passwd,
|
p->pw_passwd,
|
||||||
#if defined(NeXT) && defined(_POSIX_SOURCE) && defined(__LITTLE_ENDIAN__)
|
#if defined(NeXT) && defined(_POSIX_SOURCE) && defined(__LITTLE_ENDIAN__)
|
||||||
|
@ -57,56 +57,62 @@ static object *mkpwent(p)
|
||||||
p->pw_shell);
|
p->pw_shell);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *pwd_getpwuid(self, args)
|
static PyObject *
|
||||||
object *self, *args;
|
pwd_getpwuid(self, args)
|
||||||
|
PyObject *self;
|
||||||
|
PyObject *args;
|
||||||
{
|
{
|
||||||
int uid;
|
int uid;
|
||||||
struct passwd *p;
|
struct passwd *p;
|
||||||
if (!getintarg(args, &uid))
|
if (!PyArg_Parse(args, "i", &uid))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((p = getpwuid(uid)) == NULL) {
|
if ((p = getpwuid(uid)) == NULL) {
|
||||||
err_setstr(KeyError, "getpwuid(): uid not found");
|
PyErr_SetString(PyExc_KeyError, "getpwuid(): uid not found");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return mkpwent(p);
|
return mkpwent(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *pwd_getpwnam(self, args)
|
static PyObject *
|
||||||
object *self, *args;
|
pwd_getpwnam(self, args)
|
||||||
|
PyObject *self;
|
||||||
|
PyObject *args;
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
struct passwd *p;
|
struct passwd *p;
|
||||||
if (!getstrarg(args, &name))
|
if (!PyArg_Parse(args, "s", &name))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((p = getpwnam(name)) == NULL) {
|
if ((p = getpwnam(name)) == NULL) {
|
||||||
err_setstr(KeyError, "getpwnam(): name not found");
|
PyErr_SetString(PyExc_KeyError, "getpwnam(): name not found");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return mkpwent(p);
|
return mkpwent(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *pwd_getpwall(self, args)
|
static PyObject *
|
||||||
object *self, *args;
|
pwd_getpwall(self, args)
|
||||||
|
PyObject *self;
|
||||||
|
PyObject *args;
|
||||||
{
|
{
|
||||||
object *d;
|
PyObject *d;
|
||||||
struct passwd *p;
|
struct passwd *p;
|
||||||
if (!getnoarg(args))
|
if (!PyArg_NoArgs(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((d = newlistobject(0)) == NULL)
|
if ((d = PyList_New(0)) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
setpwent();
|
setpwent();
|
||||||
while ((p = getpwent()) != NULL) {
|
while ((p = getpwent()) != NULL) {
|
||||||
object *v = mkpwent(p);
|
PyObject *v = mkpwent(p);
|
||||||
if (v == NULL || addlistitem(d, v) != 0) {
|
if (v == NULL || PyList_Append(d, v) != 0) {
|
||||||
XDECREF(v);
|
Py_XDECREF(v);
|
||||||
DECREF(d);
|
Py_DECREF(d);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct methodlist pwd_methods[] = {
|
static PyMethodDef pwd_methods[] = {
|
||||||
{"getpwuid", pwd_getpwuid},
|
{"getpwuid", pwd_getpwuid},
|
||||||
{"getpwnam", pwd_getpwnam},
|
{"getpwnam", pwd_getpwnam},
|
||||||
{"getpwall", pwd_getpwall},
|
{"getpwall", pwd_getpwall},
|
||||||
|
@ -116,5 +122,5 @@ static struct methodlist pwd_methods[] = {
|
||||||
void
|
void
|
||||||
initpwd()
|
initpwd()
|
||||||
{
|
{
|
||||||
initmodule("pwd", pwd_methods);
|
Py_InitModule("pwd", pwd_methods);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue