Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8d2f2b2

Browse files
committed
From Sam Rushing's Medusa, via SF patch #100858: add & document
os.seteuid(), os.setegid(), os.setreuid(), os.setregid().
1 parent 4d5d5bf commit 8d2f2b2

5 files changed

Lines changed: 263 additions & 141 deletions

File tree

Doc/lib/libos.tex

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@ \subsection{Process Parameters \label{os-procinfo}}
181181
actually preferable to assign to items of \code{os.environ}.
182182
\end{funcdesc}
183183

184+
\begin{funcdesc}{setegid}{egid}
185+
Set the current process's effective group id.
186+
Availability: \UNIX{}.
187+
\end{funcdesc}
188+
189+
\begin{funcdesc}{seteuid}{euid}
190+
Set the current process's effective user id.
191+
Availability: \UNIX{}.
192+
\end{funcdesc}
193+
184194
\begin{funcdesc}{setgid}{gid}
185195
Set the current process' group id.
186196
Availability: \UNIX{}.
@@ -199,6 +209,16 @@ \subsection{Process Parameters \label{os-procinfo}}
199209
Availability: \UNIX{}.
200210
\end{funcdesc}
201211

212+
\begin{funcdesc}{setreuid}{ruid, euid}
213+
Set the current process's real and effective user ids.
214+
Availability: \UNIX{}.
215+
\end{funcdesc}
216+
217+
\begin{funcdesc}{setregid}{rgid, egid}
218+
Set the current process's real and effective group ids.
219+
Availability: \UNIX{}.
220+
\end{funcdesc}
221+
202222
\begin{funcdesc}{setsid}{}
203223
Calls the system call \cfunction{setsid()}. See the \UNIX{} manual
204224
for the semantics.

Modules/posixmodule.c

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,6 +2618,82 @@ posix_setuid(PyObject *self, PyObject *args)
26182618
#endif /* HAVE_SETUID */
26192619

26202620

2621+
#ifdef HAVE_SETEUID
2622+
static char posix_seteuid__doc__[] =
2623+
"seteuid(uid) -> None\n\
2624+
Set the current process's effective user id.";
2625+
static PyObject *
2626+
posix_seteuid (PyObject *self, PyObject *args)
2627+
{
2628+
int euid;
2629+
if (!PyArg_ParseTuple(args, "i", &euid)) {
2630+
return NULL;
2631+
} else if (seteuid(euid) < 0) {
2632+
return posix_error();
2633+
} else {
2634+
Py_INCREF(Py_None);
2635+
return Py_None;
2636+
}
2637+
}
2638+
#endif /* HAVE_SETEUID */
2639+
2640+
#ifdef HAVE_SETEGID
2641+
static char posix_setegid__doc__[] =
2642+
"setegid(gid) -> None\n\
2643+
Set the current process's effective group id.";
2644+
static PyObject *
2645+
posix_setegid (PyObject *self, PyObject *args)
2646+
{
2647+
int egid;
2648+
if (!PyArg_ParseTuple(args, "i", &egid)) {
2649+
return NULL;
2650+
} else if (setegid(egid) < 0) {
2651+
return posix_error();
2652+
} else {
2653+
Py_INCREF(Py_None);
2654+
return Py_None;
2655+
}
2656+
}
2657+
#endif /* HAVE_SETEGID */
2658+
2659+
#ifdef HAVE_SETREUID
2660+
static char posix_setreuid__doc__[] =
2661+
"seteuid(ruid, euid) -> None\n\
2662+
Set the current process's real and effective user ids.";
2663+
static PyObject *
2664+
posix_setreuid (PyObject *self, PyObject *args)
2665+
{
2666+
int ruid, euid;
2667+
if (!PyArg_ParseTuple(args, "ii", &ruid, &euid)) {
2668+
return NULL;
2669+
} else if (setreuid(ruid, euid) < 0) {
2670+
return posix_error();
2671+
} else {
2672+
Py_INCREF(Py_None);
2673+
return Py_None;
2674+
}
2675+
}
2676+
#endif /* HAVE_SETREUID */
2677+
2678+
#ifdef HAVE_SETREGID
2679+
static char posix_setregid__doc__[] =
2680+
"setegid(rgid, egid) -> None\n\
2681+
Set the current process's real and effective group ids.";
2682+
static PyObject *
2683+
posix_setregid (PyObject *self, PyObject *args)
2684+
{
2685+
int rgid, egid;
2686+
if (!PyArg_ParseTuple(args, "ii", &rgid, &egid)) {
2687+
return NULL;
2688+
} else if (setregid(rgid, egid) < 0) {
2689+
return posix_error();
2690+
} else {
2691+
Py_INCREF(Py_None);
2692+
return Py_None;
2693+
}
2694+
}
2695+
#endif /* HAVE_SETREGID */
2696+
26212697
#ifdef HAVE_SETGID
26222698
static char posix_setgid__doc__[] =
26232699
"setgid(gid) -> None\n\
@@ -4898,6 +4974,18 @@ static PyMethodDef posix_methods[] = {
48984974
#ifdef HAVE_SETUID
48994975
{"setuid", posix_setuid, METH_VARARGS, posix_setuid__doc__},
49004976
#endif /* HAVE_SETUID */
4977+
#ifdef HAVE_SETEUID
4978+
{"seteuid", posix_seteuid, METH_VARARGS, posix_seteuid__doc__},
4979+
#endif /* HAVE_SETEUID */
4980+
#ifdef HAVE_SETEGID
4981+
{"setegid", posix_setegid, METH_VARARGS, posix_setegid__doc__},
4982+
#endif /* HAVE_SETEGID */
4983+
#ifdef HAVE_SETREUID
4984+
{"setreuid", posix_setreuid, METH_VARARGS, posix_setreuid__doc__},
4985+
#endif /* HAVE_SETREUID */
4986+
#ifdef HAVE_SETREGID
4987+
{"setregid", posix_setregid, METH_VARARGS, posix_setregid__doc__},
4988+
#endif /* HAVE_SETREGID */
49014989
#ifdef HAVE_SETGID
49024990
{"setgid", posix_setgid, METH_VARARGS, posix_setgid__doc__},
49034991
#endif /* HAVE_SETGID */

config.h.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,12 @@
407407
/* Define if you have the select function. */
408408
#undef HAVE_SELECT
409409

410+
/* Define if you have the setegid function. */
411+
#undef HAVE_SETEGID
412+
413+
/* Define if you have the seteuid function. */
414+
#undef HAVE_SETEUID
415+
410416
/* Define if you have the setgid function. */
411417
#undef HAVE_SETGID
412418

@@ -419,6 +425,12 @@
419425
/* Define if you have the setpgrp function. */
420426
#undef HAVE_SETPGRP
421427

428+
/* Define if you have the setregid function. */
429+
#undef HAVE_SETREGID
430+
431+
/* Define if you have the setreuid function. */
432+
#undef HAVE_SETREUID
433+
422434
/* Define if you have the setsid function. */
423435
#undef HAVE_SETSID
424436

0 commit comments

Comments
 (0)