From 50de7cf286da508aa87d730fe67f1c1bb8f0c0fd Mon Sep 17 00:00:00 2001 From: zaihuaji Date: Fri, 31 Jan 2025 13:08:38 -0600 Subject: [PATCH] add dsarch.c to rda_python_dsarch --- pyproject.toml | 4 +-- src/rda_python_dsarch/dsarch.c | 48 ++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/rda_python_dsarch/dsarch.c diff --git a/pyproject.toml b/pyproject.toml index f0d5441..deecee2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta" [project] name = "rda_python_dsarch" -version = "1.0.2" +version = "1.0.3" authors = [ { name="Zaihua Ji", email="zji@ucar.edu" }, ] @@ -28,7 +28,7 @@ include-package-data = true where = ["src"] [tool.setuptools.package-data] -"rda_pyhton_dsarch" = ["dsarch.usg"] +"rda_pyhton_dsarch" = ["dsarch.usg", "dsarch.c"] [project.urls] "Homepage" = "https://github.com/NCAR/rda-python-dsarch" diff --git a/src/rda_python_dsarch/dsarch.c b/src/rda_python_dsarch/dsarch.c new file mode 100644 index 0000000..2ae3afc --- /dev/null +++ b/src/rda_python_dsarch/dsarch.c @@ -0,0 +1,48 @@ +/***************************************************************************************\ + * + * Title: dsarch.c + * Author: Zaihua Ji, zji@ucar.edu + * Date: 2024-01-30 + * Purpose: C wrapper to setuid for dsarch python scripts + * + * Instruction: + * + * dsarch.c $LOCHOME/bin/dsarch.c + * cd $LOCHOME/bin/ + * gcc -o dsarch dsarch.c + * chmod 4750 dsarch + * + * $LOCHOME: /usr/local/decs On DECS machines, and /ncar/rda/setuid on DAV + * $ENVHOME: /glade/u/home/rdadata/rdamsenv on DECS machines, and + * /glade/work/zji/conda-envs/pg-rda on DAV + * + \***************************************************************************************/ + +#include +#include +#include +#include +#include + +/* main program */ +int main(int argc, char *argv[]) { + char *name; + char prog[128]; + char pext[] = ".py"; + + strcpy(prog, getenv("ENVHOME")); + strcat(prog, "/bin/"); + name = strrchr(argv[0], '/'); + if(name == (char *)NULL) { + strcat(prog, argv[0]); + } else { + strcat(prog, ++name); + } + name = strrchr(prog, '.'); + if(name == (char *)NULL || strcmp(name, pext) != 0) { + strcat(prog, pext); + } + + /* call Python script */ + execv(prog, argv); +}