66
77#include <grp.h>
88
9+ #include "clinic/grpmodule.c.h"
10+ /*[clinic input]
11+ output preset file
12+ module grp
13+ [clinic start generated code]*/
14+ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=68180a9a9efb8506]*/
15+
916static PyStructSequence_Field struct_group_type_fields [] = {
1017 {"gr_name" , "group name" },
1118 {"gr_passwd" , "password" },
@@ -76,14 +83,25 @@ mkgrent(struct group *p)
7683 return v ;
7784}
7885
86+ /*[clinic input]
87+ grp.getgrgid
88+
89+ id: object
90+
91+ Return the group database entry for the given numeric group ID.
92+
93+ If id is not valid, raise KeyError.
94+ [clinic start generated code]*/
95+
7996static PyObject *
80- grp_getgrgid (PyObject * self , PyObject * pyo_id )
97+ grp_getgrgid_impl (PyModuleDef * module , PyObject * id )
98+ /*[clinic end generated code: output=8a11f5fdeb8c78a0 input=15fa0e2ccf5cda25]*/
8199{
82100 PyObject * py_int_id ;
83101 gid_t gid ;
84102 struct group * p ;
85103
86- py_int_id = PyNumber_Long (pyo_id );
104+ py_int_id = PyNumber_Long (id );
87105 if (!py_int_id )
88106 return NULL ;
89107 if (!_Py_Gid_Converter (py_int_id , & gid )) {
@@ -103,22 +121,31 @@ grp_getgrgid(PyObject *self, PyObject *pyo_id)
103121 return mkgrent (p );
104122}
105123
124+ /*[clinic input]
125+ grp.getgrnam
126+
127+ name: unicode
128+
129+ Return the group database entry for the given group name.
130+
131+ If name is not valid, raise KeyError.
132+ [clinic start generated code]*/
133+
106134static PyObject *
107- grp_getgrnam (PyObject * self , PyObject * args )
135+ grp_getgrnam_impl (PyModuleDef * module , PyObject * name )
136+ /*[clinic end generated code: output=cd47511f4854da8e input=08ded29affa3c863]*/
108137{
109- char * name ;
138+ char * name_chars ;
110139 struct group * p ;
111- PyObject * arg , * bytes , * retval = NULL ;
140+ PyObject * bytes , * retval = NULL ;
112141
113- if (!PyArg_ParseTuple (args , "U:getgrnam" , & arg ))
114- return NULL ;
115- if ((bytes = PyUnicode_EncodeFSDefault (arg )) == NULL )
142+ if ((bytes = PyUnicode_EncodeFSDefault (name )) == NULL )
116143 return NULL ;
117- if (PyBytes_AsStringAndSize (bytes , & name , NULL ) == -1 )
144+ if (PyBytes_AsStringAndSize (bytes , & name_chars , NULL ) == -1 )
118145 goto out ;
119146
120- if ((p = getgrnam (name )) == NULL ) {
121- PyErr_Format (PyExc_KeyError , "getgrnam(): name not found: %s" , name );
147+ if ((p = getgrnam (name_chars )) == NULL ) {
148+ PyErr_Format (PyExc_KeyError , "getgrnam(): name not found: %s" , name_chars );
122149 goto out ;
123150 }
124151 retval = mkgrent (p );
@@ -127,8 +154,18 @@ grp_getgrnam(PyObject *self, PyObject *args)
127154 return retval ;
128155}
129156
157+ /*[clinic input]
158+ grp.getgrall
159+
160+ Return a list of all available group entries, in arbitrary order.
161+
162+ An entry whose name starts with '+' or '-' represents an instruction
163+ to use YP/NIS and may not be accessible via getgrnam or getgrgid.
164+ [clinic start generated code]*/
165+
130166static PyObject *
131- grp_getgrall (PyObject * self , PyObject * ignore )
167+ grp_getgrall_impl (PyModuleDef * module )
168+ /*[clinic end generated code: output=add9037a20c202de input=d7df76c825c367df]*/
132169{
133170 PyObject * d ;
134171 struct group * p ;
@@ -151,20 +188,10 @@ grp_getgrall(PyObject *self, PyObject *ignore)
151188}
152189
153190static PyMethodDef grp_methods [] = {
154- {"getgrgid" , grp_getgrgid , METH_O ,
155- "getgrgid(id) -> tuple\n\
156- Return the group database entry for the given numeric group ID. If\n\
157- id is not valid, raise KeyError." },
158- {"getgrnam" , grp_getgrnam , METH_VARARGS ,
159- "getgrnam(name) -> tuple\n\
160- Return the group database entry for the given group name. If\n\
161- name is not valid, raise KeyError." },
162- {"getgrall" , grp_getgrall , METH_NOARGS ,
163- "getgrall() -> list of tuples\n\
164- Return a list of all available group entries, in arbitrary order.\n\
165- An entry whose name starts with '+' or '-' represents an instruction\n\
166- to use YP/NIS and may not be accessible via getgrnam or getgrgid." },
167- {NULL , NULL } /* sentinel */
191+ GRP_GETGRGID_METHODDEF
192+ GRP_GETGRNAM_METHODDEF
193+ GRP_GETGRALL_METHODDEF
194+ {NULL , NULL }
168195};
169196
170197PyDoc_STRVAR (grp__doc__ ,
0 commit comments