rda-python-setuid 1.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rda_python_setuid-1.0.1/LICENSE +21 -0
- rda_python_setuid-1.0.1/MANIFEST.in +1 -0
- rda_python_setuid-1.0.1/PKG-INFO +16 -0
- rda_python_setuid-1.0.1/README.md +1 -0
- rda_python_setuid-1.0.1/pyproject.toml +40 -0
- rda_python_setuid-1.0.1/setup.cfg +4 -0
- rda_python_setuid-1.0.1/src/rda_python_setuid/__init__.py +1 -0
- rda_python_setuid-1.0.1/src/rda_python_setuid/pgstart.py +83 -0
- rda_python_setuid-1.0.1/src/rda_python_setuid/pywrapper.c +81 -0
- rda_python_setuid-1.0.1/src/rda_python_setuid/pywrapper.py +70 -0
- rda_python_setuid-1.0.1/src/rda_python_setuid.egg-info/PKG-INFO +16 -0
- rda_python_setuid-1.0.1/src/rda_python_setuid.egg-info/SOURCES.txt +15 -0
- rda_python_setuid-1.0.1/src/rda_python_setuid.egg-info/dependency_links.txt +1 -0
- rda_python_setuid-1.0.1/src/rda_python_setuid.egg-info/entry_points.txt +3 -0
- rda_python_setuid-1.0.1/src/rda_python_setuid.egg-info/requires.txt +1 -0
- rda_python_setuid-1.0.1/src/rda_python_setuid.egg-info/top_level.txt +1 -0
- rda_python_setuid-1.0.1/tests/test_setuid.py +6 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 National Center for Atmospheric Research
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include src/rda_python_setuid/pywrapper.c
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: rda_python_setuid
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: RDA Python Package to setuid for program executions as an effective or common user
|
|
5
|
+
Author-email: Zaihua Ji <zji@ucar.edu>
|
|
6
|
+
Project-URL: Homepage, https://github.com/NCAR/rda-python-setuid
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Requires-Python: >=3.7
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: rda_python_common
|
|
15
|
+
|
|
16
|
+
RDA python package, including a C code wrapper, to execute commandline applications via setuid for effective and common user names.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
RDA python package, including a C code wrapper, to execute commandline applications via setuid for effective and common user names.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = [
|
|
3
|
+
"setuptools>=61.0",
|
|
4
|
+
]
|
|
5
|
+
build-backend = "setuptools.build_meta"
|
|
6
|
+
|
|
7
|
+
[project]
|
|
8
|
+
name = "rda_python_setuid"
|
|
9
|
+
version = "1.0.1"
|
|
10
|
+
authors = [
|
|
11
|
+
{ name="Zaihua Ji", email="zji@ucar.edu" },
|
|
12
|
+
]
|
|
13
|
+
description = "RDA Python Package to setuid for program executions as an effective or common user"
|
|
14
|
+
readme = "README.md"
|
|
15
|
+
requires-python = ">=3.7"
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Development Status :: 5 - Production/Stable",
|
|
21
|
+
]
|
|
22
|
+
dependencies = [
|
|
23
|
+
"rda_python_common",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[tool.setuptools]
|
|
27
|
+
include-package-data = true
|
|
28
|
+
|
|
29
|
+
[tool.setuptools.packages.find]
|
|
30
|
+
where = ["src"]
|
|
31
|
+
|
|
32
|
+
[tool.setuptools.package-data]
|
|
33
|
+
"rda_python_setuid" = ["pywrapper.c"]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
"Homepage" = "https://github.com/NCAR/rda-python-setuid"
|
|
37
|
+
|
|
38
|
+
[project.scripts]
|
|
39
|
+
"pywrapper.py" = "rda_python_setuid.pywrapper:main"
|
|
40
|
+
"pgstart.py" = "rda_python_setuid.pgstart:main"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
#
|
|
3
|
+
##################################################################################
|
|
4
|
+
#
|
|
5
|
+
# Title: pgstart
|
|
6
|
+
# Author: Zaihua Ji, zji@ucar.edu
|
|
7
|
+
# Date: 10/17/2020
|
|
8
|
+
# 2025-03-18 transferred to package rda_python_setuid from
|
|
9
|
+
# https://github.com/NCAR/rda-utility-programs.git
|
|
10
|
+
# Purpose: python script to start up an application in background
|
|
11
|
+
# for individual specialist
|
|
12
|
+
#
|
|
13
|
+
# Github: https://github.com/NCAR/rda-python-setuid.git
|
|
14
|
+
#
|
|
15
|
+
##################################################################################
|
|
16
|
+
|
|
17
|
+
import os
|
|
18
|
+
import sys
|
|
19
|
+
import re
|
|
20
|
+
import pwd
|
|
21
|
+
from rda_python_common import PgLOG
|
|
22
|
+
|
|
23
|
+
#
|
|
24
|
+
# main function to excecute this script
|
|
25
|
+
#
|
|
26
|
+
def main():
|
|
27
|
+
|
|
28
|
+
permit = 1
|
|
29
|
+
PgLOG.PGLOG['LOGFILE'] = "pgstart.log"
|
|
30
|
+
aname = PgLOG.get_command()
|
|
31
|
+
bckgrd = ""
|
|
32
|
+
workdir = None
|
|
33
|
+
argv = sys.argv[1:]
|
|
34
|
+
|
|
35
|
+
PgLOG.set_suid(PgLOG.PGLOG['EUID'])
|
|
36
|
+
if PgLOG.PGLOG['CURUID'] != PgLOG.PGLOG['RDAUSER'] and PgLOG.PGLOG['CURUID'] != "zji": permit = 0
|
|
37
|
+
|
|
38
|
+
if argv:
|
|
39
|
+
ms = re.match(r'^-(\w+)$', argv[0])
|
|
40
|
+
if ms:
|
|
41
|
+
opt = ms.group(1)
|
|
42
|
+
display_message(opt)
|
|
43
|
+
|
|
44
|
+
if not (permit and argv):
|
|
45
|
+
ruid = PgLOG.PGLOG['RUID']
|
|
46
|
+
euid = PgLOG.PGLOG['EUID']
|
|
47
|
+
ruser = pwd.getpwuid(ruid).pw_name
|
|
48
|
+
euser = pwd.getpwuid(euid).pw_name
|
|
49
|
+
print("********************************************************************")
|
|
50
|
+
print("* Your Login Name is {}({}) & Effective User Name is {}({}).".format(ruser, ruid, euser, euid))
|
|
51
|
+
print("* Pass a command or options -(plg|env|inc) to run '{}'.".format(aname))
|
|
52
|
+
if not permit:
|
|
53
|
+
print("* You must be '{}' to execute a command as user '{}'.".format(PgLOG.PGLOG['RDAUSER'], euser))
|
|
54
|
+
print("********************************************************************")
|
|
55
|
+
|
|
56
|
+
sys.exit(0)
|
|
57
|
+
|
|
58
|
+
#
|
|
59
|
+
# display message acording to the option passed in
|
|
60
|
+
#
|
|
61
|
+
def display_message(option):
|
|
62
|
+
|
|
63
|
+
if option == "env":
|
|
64
|
+
print("Environment Variables:")
|
|
65
|
+
for ename in sorted(os.environ):
|
|
66
|
+
print("{}: {}".format(ename, os.environ[ename]))
|
|
67
|
+
elif option == "inc":
|
|
68
|
+
print("Including Paths:")
|
|
69
|
+
for pname in sorted(sys.path):
|
|
70
|
+
print(pname)
|
|
71
|
+
elif option == "plg":
|
|
72
|
+
print("PGLOG variables:")
|
|
73
|
+
for vname in sorted(PgLOG.PGLOG):
|
|
74
|
+
print("{}: {}".format(vname, PgLOG.PGLOG[vname]))
|
|
75
|
+
else:
|
|
76
|
+
print("* {}: Unknown option".format(option))
|
|
77
|
+
|
|
78
|
+
sys.exit(0)
|
|
79
|
+
|
|
80
|
+
#
|
|
81
|
+
# call main() to start program
|
|
82
|
+
#
|
|
83
|
+
if __name__ == "__main__": main()
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/***************************************************************************************\
|
|
2
|
+
*
|
|
3
|
+
* Title: pywrapper.c
|
|
4
|
+
* Author: Zaihua Ji, zji@ucar.edu
|
|
5
|
+
* Date: 2025-03-17
|
|
6
|
+
* Purpose: C wrapper to start any executable python code as an effective user
|
|
7
|
+
*
|
|
8
|
+
* Instruction:
|
|
9
|
+
* python -m venv $ENVHOME
|
|
10
|
+
* python -m pip install rda_python_setuid
|
|
11
|
+
* cd $ENVHOME/bin/
|
|
12
|
+
* cp ../lib/python3.N/site-packages/rda_python_setuid/pywrapper.c ./
|
|
13
|
+
* sudo -u CommonUser gcc -o pywrapper $ENVHOME/bin/pywrapper.c
|
|
14
|
+
* sudo -u CommonUser chmod 4750 pywrapper
|
|
15
|
+
*
|
|
16
|
+
* For an existing python program, $ENVHOME/bin/CommonProgram.py, to execute it
|
|
17
|
+
* as the common user:
|
|
18
|
+
* sudo -u CommonUser ln -s pywrapper CommonProgram
|
|
19
|
+
* CommonProgram [options]
|
|
20
|
+
*
|
|
21
|
+
* For an existing python program, $ENVHOME/bin/EffectProgram.py, to execute it
|
|
22
|
+
* as the effective user:
|
|
23
|
+
* sudo -u EffectUser cp pywrapper pgstart_EffectUser
|
|
24
|
+
* sudo -u EffectUser chmod 4750 pgstart_EffectUser
|
|
25
|
+
* pgstart_EffectUser EffectProgram [options]
|
|
26
|
+
*
|
|
27
|
+
* N: python 3 release number, it is 10 for Python 3.10.12
|
|
28
|
+
* CommonUser: a common user login name, such as rdadata, for RDAMS configuration
|
|
29
|
+
* EffectUser: any user login name in the same group of the common user
|
|
30
|
+
* $ENVHOME: /glade/u/home/rdadata/rdamsenv (venv) on DECS machines, and
|
|
31
|
+
* /glade/work/rdadata/conda-envs/pg-rda (conda) on DAV
|
|
32
|
+
*
|
|
33
|
+
\***************************************************************************************/
|
|
34
|
+
|
|
35
|
+
#include <sys/types.h>
|
|
36
|
+
#include <sys/stat.h>
|
|
37
|
+
#include <unistd.h>
|
|
38
|
+
#include <stdio.h>
|
|
39
|
+
#include <string.h>
|
|
40
|
+
#include <libgen.h>
|
|
41
|
+
|
|
42
|
+
int is_executable(const char *filename) {
|
|
43
|
+
struct stat sb;
|
|
44
|
+
|
|
45
|
+
if(stat(filename, &sb) == 0) {
|
|
46
|
+
if(sb.st_mode & S_IXUSR) {
|
|
47
|
+
return 1;
|
|
48
|
+
} else {
|
|
49
|
+
printf("%s: not executable\n", prog);
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
printf("%s: not exists\n", prog);
|
|
53
|
+
}
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* main program */
|
|
58
|
+
int main(int argc, char *argv[]) {
|
|
59
|
+
char *name;
|
|
60
|
+
char cname[80], prog[255];
|
|
61
|
+
char file[] = __FILE__;
|
|
62
|
+
char pgstart[] = "pgstart";
|
|
63
|
+
|
|
64
|
+
name = strrchr(argv[0], '/');
|
|
65
|
+
strcpy(cname, (name == NULL ? argv[0] : ++name));
|
|
66
|
+
|
|
67
|
+
if(strstr(cname, pgstart) == cname) {
|
|
68
|
+
if(argc == 1 or argv[1][0] == '-') {
|
|
69
|
+
strcpy(cname, pgstart);
|
|
70
|
+
} else {
|
|
71
|
+
argv += 1;
|
|
72
|
+
name = strrchr(argv[0], '/');
|
|
73
|
+
strcpy(cname, (name == NULL ? argv[0] : ++name));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
sprintf(prog, "%s/%s.py", dirname(file), cname);
|
|
77
|
+
|
|
78
|
+
if(is_executable(prog) {
|
|
79
|
+
execv(prog, argv); /* call Python script */
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
#
|
|
3
|
+
##################################################################################
|
|
4
|
+
#
|
|
5
|
+
# Title: pywrapper
|
|
6
|
+
# Author: Zaihua Ji, zji@ucar.edu
|
|
7
|
+
# Date: 10/17/2020
|
|
8
|
+
# 2025-03-18 transferred to package rda_python_setuid from
|
|
9
|
+
# https://github.com/NCAR/rda-utility-programs.git
|
|
10
|
+
# Purpose: default python script for pywrapper.c program to show the instruction
|
|
11
|
+
# of how to wrapper a python script under pywrapper
|
|
12
|
+
#
|
|
13
|
+
# Github: https://github.com/NCAR/rda-python-setuid.git
|
|
14
|
+
#
|
|
15
|
+
##################################################################################
|
|
16
|
+
|
|
17
|
+
import os
|
|
18
|
+
import sys
|
|
19
|
+
import pwd
|
|
20
|
+
from rda_python_common import PgLOG
|
|
21
|
+
|
|
22
|
+
#
|
|
23
|
+
# main function to excecute this script
|
|
24
|
+
#
|
|
25
|
+
def main():
|
|
26
|
+
|
|
27
|
+
PgLOG.set_suid(PgLOG.PGLOG['EUID'])
|
|
28
|
+
inc = 1
|
|
29
|
+
print("********************************************************************")
|
|
30
|
+
argv = sys.argv[1:]
|
|
31
|
+
if argv:
|
|
32
|
+
if argv[0] == "-env":
|
|
33
|
+
print("Environment Variables:")
|
|
34
|
+
for ename in sorted(os.environ):
|
|
35
|
+
print("{}: {}".format(ename, os.environ[ename]))
|
|
36
|
+
inc = 0
|
|
37
|
+
elif argv[0] == "-inc":
|
|
38
|
+
print("Including Paths:")
|
|
39
|
+
for pname in sorted(sys.path):
|
|
40
|
+
print(pname)
|
|
41
|
+
inc = 0
|
|
42
|
+
elif argv[0] == "-plg":
|
|
43
|
+
print("PGLOG variables:")
|
|
44
|
+
for vname in sorted(PgLOG.PGLOG):
|
|
45
|
+
print("{}: {}".format(vname, PgLOG.PGLOG[vname]))
|
|
46
|
+
inc = 0
|
|
47
|
+
else:
|
|
48
|
+
print("* {}: Unknown option".format(argv[0]))
|
|
49
|
+
else:
|
|
50
|
+
ruid = PgLOG.PGLOG['RUID']
|
|
51
|
+
euid = PgLOG.PGLOG['EUID']
|
|
52
|
+
ruser = pwd.getpwuid(ruid).pw_name
|
|
53
|
+
euser = pwd.getpwuid(euid).pw_name
|
|
54
|
+
print("* Your Login Name is {}({}) & Effective User Name is {}({}).".format(ruser, ruid, euser,euid))
|
|
55
|
+
print("* To wrap your python script 'yourscript.py', you install it as")
|
|
56
|
+
print("* an executable under $ENVHOME/bin/ and create a link to 'pywrapper'")
|
|
57
|
+
print("* under $ENVHOME/bin/ as 'ln -s pywrapper yourscript'.")
|
|
58
|
+
if inc:
|
|
59
|
+
print("* Include -env to show environment variables")
|
|
60
|
+
print("* Include -inc to show included paths")
|
|
61
|
+
print("* Include -plg to show PGLOG variables")
|
|
62
|
+
|
|
63
|
+
print("********************************************************************\n")
|
|
64
|
+
|
|
65
|
+
sys.exit(0)
|
|
66
|
+
|
|
67
|
+
#
|
|
68
|
+
# call main() to start program
|
|
69
|
+
#
|
|
70
|
+
if __name__ == "__main__": main()
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: rda_python_setuid
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: RDA Python Package to setuid for program executions as an effective or common user
|
|
5
|
+
Author-email: Zaihua Ji <zji@ucar.edu>
|
|
6
|
+
Project-URL: Homepage, https://github.com/NCAR/rda-python-setuid
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Requires-Python: >=3.7
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: rda_python_common
|
|
15
|
+
|
|
16
|
+
RDA python package, including a C code wrapper, to execute commandline applications via setuid for effective and common user names.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
src/rda_python_setuid/__init__.py
|
|
6
|
+
src/rda_python_setuid/pgstart.py
|
|
7
|
+
src/rda_python_setuid/pywrapper.c
|
|
8
|
+
src/rda_python_setuid/pywrapper.py
|
|
9
|
+
src/rda_python_setuid.egg-info/PKG-INFO
|
|
10
|
+
src/rda_python_setuid.egg-info/SOURCES.txt
|
|
11
|
+
src/rda_python_setuid.egg-info/dependency_links.txt
|
|
12
|
+
src/rda_python_setuid.egg-info/entry_points.txt
|
|
13
|
+
src/rda_python_setuid.egg-info/requires.txt
|
|
14
|
+
src/rda_python_setuid.egg-info/top_level.txt
|
|
15
|
+
tests/test_setuid.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rda_python_common
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rda_python_setuid
|