Mercurial > cpython-lru_cache-weakref
annotate Modules/pwdmodule.c @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | 1bcd4972da7e |
| children | 144db635b49d |
| rev | line source |
|---|---|
| 201 | 1 /*********************************************************** |
|
2061
172ba04a5191
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
172ba04a5191
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
3 The Netherlands. |
| 201 | 4 |
| 5 All Rights Reserved | |
| 6 | |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2297
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2297
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
| 201 | 9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2297
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
| 201 | 11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2297
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2297
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2297
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2297
diff
changeset
|
15 permission. |
| 201 | 16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2297
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2297
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2297
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2297
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2297
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2297
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2297
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2297
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2297
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2297
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2297
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2297
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
| 201 | 29 |
| 30 ******************************************************************/ | |
| 31 | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1351
diff
changeset
|
32 /* UNIX password file access module */ |
| 201 | 33 |
| 4684 | 34 #include "Python.h" |
| 201 | 35 |
| 36 #include <sys/types.h> | |
| 37 #include <pwd.h> | |
| 38 | |
| 4684 | 39 static PyObject * |
| 40 mkpwent(p) | |
| 201 | 41 struct passwd *p; |
| 42 { | |
| 4786 | 43 return Py_BuildValue( |
| 44 "(ssllsss)", | |
| 45 p->pw_name, | |
| 46 p->pw_passwd, | |
|
2297
9717f6a8f5fa
patches for NeXT weirdness
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
47 #if defined(NeXT) && defined(_POSIX_SOURCE) && defined(__LITTLE_ENDIAN__) |
|
9717f6a8f5fa
patches for NeXT weirdness
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
48 /* Correct a bug present on Intel machines in NextStep 3.2 and 3.3; |
|
9717f6a8f5fa
patches for NeXT weirdness
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
49 for later versions you may have to remove this */ |
| 4786 | 50 (long)p->pw_short_pad1, /* ugh-NeXT broke the padding */ |
| 51 (long)p->pw_short_pad2, | |
|
2297
9717f6a8f5fa
patches for NeXT weirdness
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
52 #else |
| 4786 | 53 (long)p->pw_uid, |
| 54 (long)p->pw_gid, | |
|
2297
9717f6a8f5fa
patches for NeXT weirdness
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
55 #endif |
| 4786 | 56 p->pw_gecos, |
| 57 p->pw_dir, | |
| 58 p->pw_shell); | |
| 201 | 59 } |
| 60 | |
| 4684 | 61 static PyObject * |
| 62 pwd_getpwuid(self, args) | |
| 63 PyObject *self; | |
| 64 PyObject *args; | |
| 201 | 65 { |
| 66 int uid; | |
| 67 struct passwd *p; | |
| 4684 | 68 if (!PyArg_Parse(args, "i", &uid)) |
| 201 | 69 return NULL; |
| 70 if ((p = getpwuid(uid)) == NULL) { | |
| 4684 | 71 PyErr_SetString(PyExc_KeyError, "getpwuid(): uid not found"); |
| 201 | 72 return NULL; |
| 73 } | |
| 74 return mkpwent(p); | |
| 75 } | |
| 76 | |
| 4684 | 77 static PyObject * |
| 78 pwd_getpwnam(self, args) | |
| 79 PyObject *self; | |
| 80 PyObject *args; | |
| 201 | 81 { |
|
643
02d3f161b7f5
Use getargs() function.
Guido van Rossum <guido@python.org>
parents:
513
diff
changeset
|
82 char *name; |
| 201 | 83 struct passwd *p; |
| 4684 | 84 if (!PyArg_Parse(args, "s", &name)) |
| 201 | 85 return NULL; |
|
643
02d3f161b7f5
Use getargs() function.
Guido van Rossum <guido@python.org>
parents:
513
diff
changeset
|
86 if ((p = getpwnam(name)) == NULL) { |
| 4684 | 87 PyErr_SetString(PyExc_KeyError, "getpwnam(): name not found"); |
| 201 | 88 return NULL; |
| 89 } | |
| 90 return mkpwent(p); | |
| 91 } | |
| 92 | |
| 4684 | 93 static PyObject * |
| 94 pwd_getpwall(self, args) | |
| 95 PyObject *self; | |
| 96 PyObject *args; | |
| 201 | 97 { |
| 4684 | 98 PyObject *d; |
| 201 | 99 struct passwd *p; |
| 4684 | 100 if (!PyArg_NoArgs(args)) |
| 201 | 101 return NULL; |
| 4684 | 102 if ((d = PyList_New(0)) == NULL) |
| 201 | 103 return NULL; |
| 104 setpwent(); | |
| 105 while ((p = getpwent()) != NULL) { | |
| 4684 | 106 PyObject *v = mkpwent(p); |
| 107 if (v == NULL || PyList_Append(d, v) != 0) { | |
| 108 Py_XDECREF(v); | |
| 109 Py_DECREF(d); | |
| 201 | 110 return NULL; |
| 111 } | |
|
4917
1bcd4972da7e
Nailed a couple of memory leaks, caught by Purify.
Barry Warsaw <barry@python.org>
parents:
4786
diff
changeset
|
112 Py_DECREF(v); |
| 201 | 113 } |
| 114 return d; | |
| 115 } | |
| 116 | |
| 4684 | 117 static PyMethodDef pwd_methods[] = { |
| 201 | 118 {"getpwuid", pwd_getpwuid}, |
| 119 {"getpwnam", pwd_getpwnam}, | |
| 120 {"getpwall", pwd_getpwall}, | |
| 121 {NULL, NULL} /* sentinel */ | |
| 122 }; | |
| 123 | |
| 124 void | |
| 125 initpwd() | |
| 126 { | |
| 4684 | 127 Py_InitModule("pwd", pwd_methods); |
| 201 | 128 } |
