Mercurial > cpython-lru_cache-weakref
annotate Modules/pwdmodule.c @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | 65d2d8e67da3 |
| children | d800841b57a8 |
| 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 |
| 34 #include "allobjects.h" | |
| 35 #include "modsupport.h" | |
| 36 | |
| 37 #include <sys/types.h> | |
| 38 #include <pwd.h> | |
| 39 | |
| 40 static object *mkpwent(p) | |
| 41 struct passwd *p; | |
| 42 { | |
|
1252
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
43 return mkvalue("(ssllsss)", |
|
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
44 p->pw_name, |
|
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
45 p->pw_passwd, |
|
2297
9717f6a8f5fa
patches for NeXT weirdness
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
46 #if defined(NeXT) && defined(_POSIX_SOURCE) && defined(__LITTLE_ENDIAN__) |
|
9717f6a8f5fa
patches for NeXT weirdness
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
47 /* 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
|
48 for later versions you may have to remove this */ |
|
9717f6a8f5fa
patches for NeXT weirdness
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
49 (long)p->pw_short_pad1, /* ugh-NeXT broke the padding */ |
|
9717f6a8f5fa
patches for NeXT weirdness
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
50 (long)p->pw_short_pad2, |
|
9717f6a8f5fa
patches for NeXT weirdness
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
51 #else |
|
1252
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
52 (long)p->pw_uid, |
|
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
53 (long)p->pw_gid, |
|
2297
9717f6a8f5fa
patches for NeXT weirdness
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
54 #endif |
|
1252
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
55 p->pw_gecos, |
|
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
56 p->pw_dir, |
|
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
57 p->pw_shell); |
| 201 | 58 } |
| 59 | |
| 60 static object *pwd_getpwuid(self, args) | |
| 61 object *self, *args; | |
| 62 { | |
| 63 int uid; | |
| 64 struct passwd *p; | |
| 65 if (!getintarg(args, &uid)) | |
| 66 return NULL; | |
| 67 if ((p = getpwuid(uid)) == NULL) { | |
|
513
9896dcf08e16
Raise KeyError instead of RuntimeError when a uid or name (etc) is not found.
Guido van Rossum <guido@python.org>
parents:
201
diff
changeset
|
68 err_setstr(KeyError, "getpwuid(): uid not found"); |
| 201 | 69 return NULL; |
| 70 } | |
| 71 return mkpwent(p); | |
| 72 } | |
| 73 | |
| 74 static object *pwd_getpwnam(self, args) | |
| 75 object *self, *args; | |
| 76 { | |
|
643
02d3f161b7f5
Use getargs() function.
Guido van Rossum <guido@python.org>
parents:
513
diff
changeset
|
77 char *name; |
| 201 | 78 struct passwd *p; |
| 79 if (!getstrarg(args, &name)) | |
| 80 return NULL; | |
|
643
02d3f161b7f5
Use getargs() function.
Guido van Rossum <guido@python.org>
parents:
513
diff
changeset
|
81 if ((p = getpwnam(name)) == NULL) { |
|
513
9896dcf08e16
Raise KeyError instead of RuntimeError when a uid or name (etc) is not found.
Guido van Rossum <guido@python.org>
parents:
201
diff
changeset
|
82 err_setstr(KeyError, "getpwnam(): name not found"); |
| 201 | 83 return NULL; |
| 84 } | |
| 85 return mkpwent(p); | |
| 86 } | |
| 87 | |
| 88 static object *pwd_getpwall(self, args) | |
| 89 object *self, *args; | |
| 90 { | |
| 91 object *d; | |
| 92 struct passwd *p; | |
| 93 if (!getnoarg(args)) | |
| 94 return NULL; | |
| 95 if ((d = newlistobject(0)) == NULL) | |
| 96 return NULL; | |
| 97 setpwent(); | |
| 98 while ((p = getpwent()) != NULL) { | |
| 99 object *v = mkpwent(p); | |
| 100 if (v == NULL || addlistitem(d, v) != 0) { | |
| 101 XDECREF(v); | |
| 102 DECREF(d); | |
| 103 return NULL; | |
| 104 } | |
| 105 } | |
| 106 return d; | |
| 107 } | |
| 108 | |
| 109 static struct methodlist pwd_methods[] = { | |
| 110 {"getpwuid", pwd_getpwuid}, | |
| 111 {"getpwnam", pwd_getpwnam}, | |
| 112 {"getpwall", pwd_getpwall}, | |
| 113 {NULL, NULL} /* sentinel */ | |
| 114 }; | |
| 115 | |
| 116 void | |
| 117 initpwd() | |
| 118 { | |
| 119 initmodule("pwd", pwd_methods); | |
| 120 } |
