Guido van Rossum | 20882d5 | 1994-06-23 11:15:44 +0000 | [diff] [blame] | 1 | |
| 2 | /* UNIX group file access module */ |
| 3 | |
Roger E. Masse | b2b44e5 | 1996-12-18 19:37:32 +0000 | [diff] [blame] | 4 | #include "Python.h" |
Serhiy Storchaka | 7cf5599 | 2013-02-10 21:56:49 +0200 | [diff] [blame] | 5 | #include "posixmodule.h" |
Guido van Rossum | 20882d5 | 1994-06-23 11:15:44 +0000 | [diff] [blame] | 6 | |
Guido van Rossum | 20882d5 | 1994-06-23 11:15:44 +0000 | [diff] [blame] | 7 | #include <grp.h> |
| 8 | |
Brett Cannon | 8fb7bb2 | 2014-08-22 11:52:46 -0400 | [diff] [blame] | 9 | #include "clinic/grpmodule.c.h" |
| 10 | /*[clinic input] |
Brett Cannon | 8fb7bb2 | 2014-08-22 11:52:46 -0400 | [diff] [blame] | 11 | module grp |
| 12 | [clinic start generated code]*/ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 13 | /*[clinic end generated code: output=da39a3ee5e6b4b0d input=cade63f2ed1bd9f8]*/ |
Brett Cannon | 8fb7bb2 | 2014-08-22 11:52:46 -0400 | [diff] [blame] | 14 | |
Martin v. Löwis | dbd55b3 | 2002-03-01 10:38:44 +0000 | [diff] [blame] | 15 | static PyStructSequence_Field struct_group_type_fields[] = { |
| 16 | {"gr_name", "group name"}, |
| 17 | {"gr_passwd", "password"}, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 18 | {"gr_gid", "group id"}, |
Mark Dickinson | fb29a16 | 2013-08-05 17:57:01 +0100 | [diff] [blame] | 19 | {"gr_mem", "group members"}, |
Martin v. Löwis | dbd55b3 | 2002-03-01 10:38:44 +0000 | [diff] [blame] | 20 | {0} |
| 21 | }; |
| 22 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 23 | PyDoc_STRVAR(struct_group__doc__, |
Martin v. Löwis | dbd55b3 | 2002-03-01 10:38:44 +0000 | [diff] [blame] | 24 | "grp.struct_group: Results from getgr*() routines.\n\n\ |
| 25 | This object may be accessed either as a tuple of\n\ |
| 26 | (gr_name,gr_passwd,gr_gid,gr_mem)\n\ |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 27 | or via the object attributes as named in the above tuple.\n"); |
Martin v. Löwis | dbd55b3 | 2002-03-01 10:38:44 +0000 | [diff] [blame] | 28 | |
| 29 | static PyStructSequence_Desc struct_group_type_desc = { |
| 30 | "grp.struct_group", |
| 31 | struct_group__doc__, |
| 32 | struct_group_type_fields, |
| 33 | 4, |
| 34 | }; |
| 35 | |
| 36 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 37 | static int initialized; |
Martin v. Löwis | dbd55b3 | 2002-03-01 10:38:44 +0000 | [diff] [blame] | 38 | static PyTypeObject StructGrpType; |
Fred Drake | 51b6bc5 | 2000-07-08 16:56:26 +0000 | [diff] [blame] | 39 | |
William Grzybowski | 23e65b2 | 2018-09-07 09:06:15 -0300 | [diff] [blame] | 40 | #define DEFAULT_BUFFER_SIZE 1024 |
| 41 | |
Fred Drake | 51b6bc5 | 2000-07-08 16:56:26 +0000 | [diff] [blame] | 42 | static PyObject * |
| 43 | mkgrent(struct group *p) |
Guido van Rossum | 20882d5 | 1994-06-23 11:15:44 +0000 | [diff] [blame] | 44 | { |
Martin v. Löwis | dbd55b3 | 2002-03-01 10:38:44 +0000 | [diff] [blame] | 45 | int setIndex = 0; |
| 46 | PyObject *v = PyStructSequence_New(&StructGrpType), *w; |
Fred Drake | 51b6bc5 | 2000-07-08 16:56:26 +0000 | [diff] [blame] | 47 | char **member; |
Martin v. Löwis | dbd55b3 | 2002-03-01 10:38:44 +0000 | [diff] [blame] | 48 | |
| 49 | if (v == NULL) |
| 50 | return NULL; |
| 51 | |
Fred Drake | 51b6bc5 | 2000-07-08 16:56:26 +0000 | [diff] [blame] | 52 | if ((w = PyList_New(0)) == NULL) { |
Martin v. Löwis | dbd55b3 | 2002-03-01 10:38:44 +0000 | [diff] [blame] | 53 | Py_DECREF(v); |
Fred Drake | 51b6bc5 | 2000-07-08 16:56:26 +0000 | [diff] [blame] | 54 | return NULL; |
| 55 | } |
| 56 | for (member = p->gr_mem; *member != NULL; member++) { |
Victor Stinner | 97c18ab | 2010-05-07 16:34:53 +0000 | [diff] [blame] | 57 | PyObject *x = PyUnicode_DecodeFSDefault(*member); |
Fred Drake | 51b6bc5 | 2000-07-08 16:56:26 +0000 | [diff] [blame] | 58 | if (x == NULL || PyList_Append(w, x) != 0) { |
| 59 | Py_XDECREF(x); |
| 60 | Py_DECREF(w); |
Martin v. Löwis | dbd55b3 | 2002-03-01 10:38:44 +0000 | [diff] [blame] | 61 | Py_DECREF(v); |
Fred Drake | 51b6bc5 | 2000-07-08 16:56:26 +0000 | [diff] [blame] | 62 | return NULL; |
| 63 | } |
| 64 | Py_DECREF(x); |
| 65 | } |
Martin v. Löwis | dbd55b3 | 2002-03-01 10:38:44 +0000 | [diff] [blame] | 66 | |
| 67 | #define SET(i,val) PyStructSequence_SET_ITEM(v, i, val) |
Victor Stinner | 97c18ab | 2010-05-07 16:34:53 +0000 | [diff] [blame] | 68 | SET(setIndex++, PyUnicode_DecodeFSDefault(p->gr_name)); |
Martin v. Löwis | ceb7c18 | 2002-09-17 07:05:25 +0000 | [diff] [blame] | 69 | if (p->gr_passwd) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 70 | SET(setIndex++, PyUnicode_DecodeFSDefault(p->gr_passwd)); |
Martin v. Löwis | ceb7c18 | 2002-09-17 07:05:25 +0000 | [diff] [blame] | 71 | else { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 72 | SET(setIndex++, Py_None); |
| 73 | Py_INCREF(Py_None); |
Martin v. Löwis | ceb7c18 | 2002-09-17 07:05:25 +0000 | [diff] [blame] | 74 | } |
Serhiy Storchaka | 7cf5599 | 2013-02-10 21:56:49 +0200 | [diff] [blame] | 75 | SET(setIndex++, _PyLong_FromGid(p->gr_gid)); |
Martin v. Löwis | dbd55b3 | 2002-03-01 10:38:44 +0000 | [diff] [blame] | 76 | SET(setIndex++, w); |
| 77 | #undef SET |
| 78 | |
| 79 | if (PyErr_Occurred()) { |
| 80 | Py_DECREF(v); |
Martin v. Löwis | dbd55b3 | 2002-03-01 10:38:44 +0000 | [diff] [blame] | 81 | return NULL; |
| 82 | } |
| 83 | |
Fred Drake | 51b6bc5 | 2000-07-08 16:56:26 +0000 | [diff] [blame] | 84 | return v; |
Guido van Rossum | 20882d5 | 1994-06-23 11:15:44 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Brett Cannon | 8fb7bb2 | 2014-08-22 11:52:46 -0400 | [diff] [blame] | 87 | /*[clinic input] |
| 88 | grp.getgrgid |
| 89 | |
| 90 | id: object |
| 91 | |
| 92 | Return the group database entry for the given numeric group ID. |
| 93 | |
| 94 | If id is not valid, raise KeyError. |
| 95 | [clinic start generated code]*/ |
| 96 | |
Fred Drake | 51b6bc5 | 2000-07-08 16:56:26 +0000 | [diff] [blame] | 97 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 98 | grp_getgrgid_impl(PyObject *module, PyObject *id) |
| 99 | /*[clinic end generated code: output=30797c289504a1ba input=15fa0e2ccf5cda25]*/ |
Guido van Rossum | 20882d5 | 1994-06-23 11:15:44 +0000 | [diff] [blame] | 100 | { |
William Grzybowski | 23e65b2 | 2018-09-07 09:06:15 -0300 | [diff] [blame] | 101 | PyObject *py_int_id, *retval = NULL; |
| 102 | int nomem = 0; |
| 103 | char *buf = NULL, *buf2 = NULL; |
Serhiy Storchaka | 7cf5599 | 2013-02-10 21:56:49 +0200 | [diff] [blame] | 104 | gid_t gid; |
Fred Drake | 51b6bc5 | 2000-07-08 16:56:26 +0000 | [diff] [blame] | 105 | struct group *p; |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 106 | |
Serhiy Storchaka | 9cc4ed5 | 2016-01-18 18:49:57 +0200 | [diff] [blame] | 107 | if (!_Py_Gid_Converter(id, &gid)) { |
| 108 | if (!PyErr_ExceptionMatches(PyExc_TypeError)) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 109 | return NULL; |
Serhiy Storchaka | 9cc4ed5 | 2016-01-18 18:49:57 +0200 | [diff] [blame] | 110 | } |
| 111 | PyErr_Clear(); |
| 112 | if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, |
| 113 | "group id must be int, not %.200", |
| 114 | id->ob_type->tp_name) < 0) { |
| 115 | return NULL; |
| 116 | } |
| 117 | py_int_id = PyNumber_Long(id); |
| 118 | if (!py_int_id) |
| 119 | return NULL; |
| 120 | if (!_Py_Gid_Converter(py_int_id, &gid)) { |
| 121 | Py_DECREF(py_int_id); |
| 122 | return NULL; |
| 123 | } |
Serhiy Storchaka | 7cf5599 | 2013-02-10 21:56:49 +0200 | [diff] [blame] | 124 | Py_DECREF(py_int_id); |
Serhiy Storchaka | 7cf5599 | 2013-02-10 21:56:49 +0200 | [diff] [blame] | 125 | } |
William Grzybowski | 23e65b2 | 2018-09-07 09:06:15 -0300 | [diff] [blame] | 126 | #ifdef HAVE_GETGRGID_R |
William Grzybowski | 23e65b2 | 2018-09-07 09:06:15 -0300 | [diff] [blame] | 127 | int status; |
| 128 | Py_ssize_t bufsize; |
Alexey Izbyshev | e359bc2 | 2018-11-04 18:44:16 +0300 | [diff] [blame] | 129 | /* Note: 'grp' will be used via pointer 'p' on getgrgid_r success. */ |
William Grzybowski | 23e65b2 | 2018-09-07 09:06:15 -0300 | [diff] [blame] | 130 | struct group grp; |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 131 | |
Alexey Izbyshev | e359bc2 | 2018-11-04 18:44:16 +0300 | [diff] [blame] | 132 | Py_BEGIN_ALLOW_THREADS |
William Grzybowski | 23e65b2 | 2018-09-07 09:06:15 -0300 | [diff] [blame] | 133 | bufsize = sysconf(_SC_GETGR_R_SIZE_MAX); |
| 134 | if (bufsize == -1) { |
| 135 | bufsize = DEFAULT_BUFFER_SIZE; |
| 136 | } |
| 137 | |
| 138 | while (1) { |
| 139 | buf2 = PyMem_RawRealloc(buf, bufsize); |
| 140 | if (buf2 == NULL) { |
| 141 | p = NULL; |
| 142 | nomem = 1; |
| 143 | break; |
| 144 | } |
| 145 | buf = buf2; |
| 146 | status = getgrgid_r(gid, &grp, buf, bufsize, &p); |
| 147 | if (status != 0) { |
| 148 | p = NULL; |
| 149 | } |
| 150 | if (p != NULL || status != ERANGE) { |
| 151 | break; |
| 152 | } |
| 153 | if (bufsize > (PY_SSIZE_T_MAX >> 1)) { |
| 154 | nomem = 1; |
| 155 | break; |
| 156 | } |
| 157 | bufsize <<= 1; |
| 158 | } |
| 159 | |
| 160 | Py_END_ALLOW_THREADS |
| 161 | #else |
| 162 | p = getgrgid(gid); |
| 163 | #endif |
| 164 | if (p == NULL) { |
| 165 | PyMem_RawFree(buf); |
| 166 | if (nomem == 1) { |
| 167 | return PyErr_NoMemory(); |
| 168 | } |
Serhiy Storchaka | 7cf5599 | 2013-02-10 21:56:49 +0200 | [diff] [blame] | 169 | PyObject *gid_obj = _PyLong_FromGid(gid); |
| 170 | if (gid_obj == NULL) |
| 171 | return NULL; |
| 172 | PyErr_Format(PyExc_KeyError, "getgrgid(): gid not found: %S", gid_obj); |
| 173 | Py_DECREF(gid_obj); |
Fred Drake | 51b6bc5 | 2000-07-08 16:56:26 +0000 | [diff] [blame] | 174 | return NULL; |
| 175 | } |
William Grzybowski | 23e65b2 | 2018-09-07 09:06:15 -0300 | [diff] [blame] | 176 | retval = mkgrent(p); |
| 177 | #ifdef HAVE_GETGRGID_R |
| 178 | PyMem_RawFree(buf); |
| 179 | #endif |
| 180 | return retval; |
Guido van Rossum | 20882d5 | 1994-06-23 11:15:44 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Brett Cannon | 8fb7bb2 | 2014-08-22 11:52:46 -0400 | [diff] [blame] | 183 | /*[clinic input] |
| 184 | grp.getgrnam |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 185 | |
Brett Cannon | 8fb7bb2 | 2014-08-22 11:52:46 -0400 | [diff] [blame] | 186 | name: unicode |
| 187 | |
| 188 | Return the group database entry for the given group name. |
| 189 | |
| 190 | If name is not valid, raise KeyError. |
| 191 | [clinic start generated code]*/ |
| 192 | |
| 193 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 194 | grp_getgrnam_impl(PyObject *module, PyObject *name) |
| 195 | /*[clinic end generated code: output=67905086f403c21c input=08ded29affa3c863]*/ |
Brett Cannon | 8fb7bb2 | 2014-08-22 11:52:46 -0400 | [diff] [blame] | 196 | { |
William Grzybowski | 23e65b2 | 2018-09-07 09:06:15 -0300 | [diff] [blame] | 197 | char *buf = NULL, *buf2 = NULL, *name_chars; |
| 198 | int nomem = 0; |
Brett Cannon | 8fb7bb2 | 2014-08-22 11:52:46 -0400 | [diff] [blame] | 199 | struct group *p; |
| 200 | PyObject *bytes, *retval = NULL; |
| 201 | |
| 202 | if ((bytes = PyUnicode_EncodeFSDefault(name)) == NULL) |
Martin v. Löwis | b6a748b | 2009-05-29 15:23:17 +0000 | [diff] [blame] | 203 | return NULL; |
Serhiy Storchaka | f7eae0a | 2017-06-28 08:30:06 +0300 | [diff] [blame] | 204 | /* check for embedded null bytes */ |
Brett Cannon | 8fb7bb2 | 2014-08-22 11:52:46 -0400 | [diff] [blame] | 205 | if (PyBytes_AsStringAndSize(bytes, &name_chars, NULL) == -1) |
Martin v. Löwis | b6a748b | 2009-05-29 15:23:17 +0000 | [diff] [blame] | 206 | goto out; |
William Grzybowski | 23e65b2 | 2018-09-07 09:06:15 -0300 | [diff] [blame] | 207 | #ifdef HAVE_GETGRNAM_R |
William Grzybowski | 23e65b2 | 2018-09-07 09:06:15 -0300 | [diff] [blame] | 208 | int status; |
| 209 | Py_ssize_t bufsize; |
Alexey Izbyshev | e359bc2 | 2018-11-04 18:44:16 +0300 | [diff] [blame] | 210 | /* Note: 'grp' will be used via pointer 'p' on getgrnam_r success. */ |
William Grzybowski | 23e65b2 | 2018-09-07 09:06:15 -0300 | [diff] [blame] | 211 | struct group grp; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 212 | |
Alexey Izbyshev | e359bc2 | 2018-11-04 18:44:16 +0300 | [diff] [blame] | 213 | Py_BEGIN_ALLOW_THREADS |
William Grzybowski | 23e65b2 | 2018-09-07 09:06:15 -0300 | [diff] [blame] | 214 | bufsize = sysconf(_SC_GETGR_R_SIZE_MAX); |
| 215 | if (bufsize == -1) { |
| 216 | bufsize = DEFAULT_BUFFER_SIZE; |
| 217 | } |
| 218 | |
| 219 | while(1) { |
| 220 | buf2 = PyMem_RawRealloc(buf, bufsize); |
| 221 | if (buf2 == NULL) { |
| 222 | p = NULL; |
| 223 | nomem = 1; |
| 224 | break; |
| 225 | } |
| 226 | buf = buf2; |
| 227 | status = getgrnam_r(name_chars, &grp, buf, bufsize, &p); |
| 228 | if (status != 0) { |
| 229 | p = NULL; |
| 230 | } |
| 231 | if (p != NULL || status != ERANGE) { |
| 232 | break; |
| 233 | } |
| 234 | if (bufsize > (PY_SSIZE_T_MAX >> 1)) { |
| 235 | nomem = 1; |
| 236 | break; |
| 237 | } |
| 238 | bufsize <<= 1; |
| 239 | } |
| 240 | |
| 241 | Py_END_ALLOW_THREADS |
| 242 | #else |
| 243 | p = getgrnam(name_chars); |
| 244 | #endif |
| 245 | if (p == NULL) { |
| 246 | if (nomem == 1) { |
| 247 | PyErr_NoMemory(); |
| 248 | } |
| 249 | else { |
William Grzybowski | 34c7f0c | 2018-12-05 17:10:18 -0200 | [diff] [blame] | 250 | PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %R", name); |
William Grzybowski | 23e65b2 | 2018-09-07 09:06:15 -0300 | [diff] [blame] | 251 | } |
Martin v. Löwis | b6a748b | 2009-05-29 15:23:17 +0000 | [diff] [blame] | 252 | goto out; |
Fred Drake | 51b6bc5 | 2000-07-08 16:56:26 +0000 | [diff] [blame] | 253 | } |
Martin v. Löwis | b6a748b | 2009-05-29 15:23:17 +0000 | [diff] [blame] | 254 | retval = mkgrent(p); |
| 255 | out: |
William Grzybowski | 23e65b2 | 2018-09-07 09:06:15 -0300 | [diff] [blame] | 256 | PyMem_RawFree(buf); |
Martin v. Löwis | b6a748b | 2009-05-29 15:23:17 +0000 | [diff] [blame] | 257 | Py_DECREF(bytes); |
| 258 | return retval; |
Guido van Rossum | 20882d5 | 1994-06-23 11:15:44 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Brett Cannon | 8fb7bb2 | 2014-08-22 11:52:46 -0400 | [diff] [blame] | 261 | /*[clinic input] |
| 262 | grp.getgrall |
| 263 | |
| 264 | Return a list of all available group entries, in arbitrary order. |
| 265 | |
| 266 | An entry whose name starts with '+' or '-' represents an instruction |
| 267 | to use YP/NIS and may not be accessible via getgrnam or getgrgid. |
| 268 | [clinic start generated code]*/ |
| 269 | |
Fred Drake | 51b6bc5 | 2000-07-08 16:56:26 +0000 | [diff] [blame] | 270 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 271 | grp_getgrall_impl(PyObject *module) |
| 272 | /*[clinic end generated code: output=585dad35e2e763d7 input=d7df76c825c367df]*/ |
Guido van Rossum | 20882d5 | 1994-06-23 11:15:44 +0000 | [diff] [blame] | 273 | { |
Fred Drake | 51b6bc5 | 2000-07-08 16:56:26 +0000 | [diff] [blame] | 274 | PyObject *d; |
| 275 | struct group *p; |
| 276 | |
Fred Drake | 51b6bc5 | 2000-07-08 16:56:26 +0000 | [diff] [blame] | 277 | if ((d = PyList_New(0)) == NULL) |
| 278 | return NULL; |
| 279 | setgrent(); |
| 280 | while ((p = getgrent()) != NULL) { |
| 281 | PyObject *v = mkgrent(p); |
| 282 | if (v == NULL || PyList_Append(d, v) != 0) { |
| 283 | Py_XDECREF(v); |
| 284 | Py_DECREF(d); |
Martin v. Löwis | e23c868 | 2009-05-29 16:01:34 +0000 | [diff] [blame] | 285 | endgrent(); |
Fred Drake | 51b6bc5 | 2000-07-08 16:56:26 +0000 | [diff] [blame] | 286 | return NULL; |
| 287 | } |
| 288 | Py_DECREF(v); |
| 289 | } |
Fred Drake | 8e68eb6 | 2001-03-11 03:03:07 +0000 | [diff] [blame] | 290 | endgrent(); |
Fred Drake | 51b6bc5 | 2000-07-08 16:56:26 +0000 | [diff] [blame] | 291 | return d; |
Guido van Rossum | 20882d5 | 1994-06-23 11:15:44 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Roger E. Masse | b2b44e5 | 1996-12-18 19:37:32 +0000 | [diff] [blame] | 294 | static PyMethodDef grp_methods[] = { |
Brett Cannon | 8fb7bb2 | 2014-08-22 11:52:46 -0400 | [diff] [blame] | 295 | GRP_GETGRGID_METHODDEF |
| 296 | GRP_GETGRNAM_METHODDEF |
| 297 | GRP_GETGRALL_METHODDEF |
| 298 | {NULL, NULL} |
Guido van Rossum | 20882d5 | 1994-06-23 11:15:44 +0000 | [diff] [blame] | 299 | }; |
| 300 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 301 | PyDoc_STRVAR(grp__doc__, |
Fred Drake | 51b6bc5 | 2000-07-08 16:56:26 +0000 | [diff] [blame] | 302 | "Access to the Unix group database.\n\ |
| 303 | \n\ |
| 304 | Group entries are reported as 4-tuples containing the following fields\n\ |
| 305 | from the group database, in order:\n\ |
| 306 | \n\ |
Georg Brandl | 41ea1f4 | 2014-10-02 08:34:41 +0200 | [diff] [blame] | 307 | gr_name - name of the group\n\ |
| 308 | gr_passwd - group password (encrypted); often empty\n\ |
| 309 | gr_gid - numeric ID of the group\n\ |
| 310 | gr_mem - list of members\n\ |
Fred Drake | 51b6bc5 | 2000-07-08 16:56:26 +0000 | [diff] [blame] | 311 | \n\ |
| 312 | The gid is an integer, name and password are strings. (Note that most\n\ |
| 313 | users are not explicitly listed as members of the groups they are in\n\ |
| 314 | according to the password database. Check both databases to get\n\ |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 315 | complete membership information.)"); |
Fred Drake | 51b6bc5 | 2000-07-08 16:56:26 +0000 | [diff] [blame] | 316 | |
| 317 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 318 | |
| 319 | static struct PyModuleDef grpmodule = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 320 | PyModuleDef_HEAD_INIT, |
| 321 | "grp", |
| 322 | grp__doc__, |
| 323 | -1, |
| 324 | grp_methods, |
| 325 | NULL, |
| 326 | NULL, |
| 327 | NULL, |
| 328 | NULL |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 329 | }; |
| 330 | |
Mark Hammond | fe51c6d | 2002-08-02 02:27:13 +0000 | [diff] [blame] | 331 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 332 | PyInit_grp(void) |
Guido van Rossum | 20882d5 | 1994-06-23 11:15:44 +0000 | [diff] [blame] | 333 | { |
Martin v. Löwis | dbd55b3 | 2002-03-01 10:38:44 +0000 | [diff] [blame] | 334 | PyObject *m, *d; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 335 | m = PyModule_Create(&grpmodule); |
Neal Norwitz | 1ac754f | 2006-01-19 06:09:39 +0000 | [diff] [blame] | 336 | if (m == NULL) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 337 | return NULL; |
Martin v. Löwis | dbd55b3 | 2002-03-01 10:38:44 +0000 | [diff] [blame] | 338 | d = PyModule_GetDict(m); |
Victor Stinner | 1c8f059 | 2013-07-22 22:24:54 +0200 | [diff] [blame] | 339 | if (!initialized) { |
| 340 | if (PyStructSequence_InitType2(&StructGrpType, |
| 341 | &struct_group_type_desc) < 0) |
| 342 | return NULL; |
| 343 | } |
| 344 | if (PyDict_SetItemString(d, "struct_group", |
| 345 | (PyObject *)&StructGrpType) < 0) |
| 346 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 347 | initialized = 1; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 348 | return m; |
Guido van Rossum | 20882d5 | 1994-06-23 11:15:44 +0000 | [diff] [blame] | 349 | } |