Skip to content

Commit 219c9e0

Browse files
committed
v.0.2 first commit
1 parent 6a764eb commit 219c9e0

23 files changed

+2484
-1
lines changed

COPYING

+339
Large diffs are not rendered by default.

Makefile.am

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
bin_PROGRAMS = nshold nslist nsrelease netnsjoin
2+
3+
nshold_SOURCES = nshold.c catargv.c prefix.c
4+
5+
nshold_LDADD = -lbsd -lcap
6+
7+
nslist_SOURCES = nslist.c catargv.c memogetusername.c prefix.c printflen.c
8+
9+
nsrelease_SOURCES = nsrelease.c nssearch.c catargv.c prefix.c
10+
11+
netnsjoin_SOURCES = netnsjoin.c nssearch.c catargv.c prefix.c
12+
13+
netnsjoin_LDADD = -lcap
14+
15+
man_MANS = netnsjoin.1 nshold.1 nslist.1 nsrelease.1
16+
17+
install-exec-hook:
18+
ln -sf nshold $(DESTDIR)$(bindir)/cgroupnshold
19+
ln -sf nslist $(DESTDIR)$(bindir)/cgroupnslist
20+
ln -sf nsrelease $(DESTDIR)$(bindir)/cgroupnsrelease
21+
ln -sf nshold $(DESTDIR)$(bindir)/ipcnshold
22+
ln -sf nslist $(DESTDIR)$(bindir)/ipcnslist
23+
ln -sf nsrelease $(DESTDIR)$(bindir)/ipcnsrelease
24+
ln -sf nshold $(DESTDIR)$(bindir)/mntnshold
25+
ln -sf nslist $(DESTDIR)$(bindir)/mntnslist
26+
ln -sf nsrelease $(DESTDIR)$(bindir)/mntnsrelease
27+
ln -sf nshold $(DESTDIR)$(bindir)/netnshold
28+
ln -sf nslist $(DESTDIR)$(bindir)/netnslist
29+
ln -sf nsrelease $(DESTDIR)$(bindir)/netnsrelease
30+
ln -sf nshold $(DESTDIR)$(bindir)/pidnshold
31+
ln -sf nslist $(DESTDIR)$(bindir)/pidnslist
32+
ln -sf nsrelease $(DESTDIR)$(bindir)/pidnsrelease
33+
ln -sf nshold $(DESTDIR)$(bindir)/usernshold
34+
ln -sf nslist $(DESTDIR)$(bindir)/usernslist
35+
ln -sf nsrelease $(DESTDIR)$(bindir)/usernsrelease
36+
ln -sf nshold $(DESTDIR)$(bindir)/utsnshold
37+
ln -sf nslist $(DESTDIR)$(bindir)/utsnslist
38+
ln -sf nsrelease $(DESTDIR)$(bindir)/utsnsrelease
39+
setcap cap_sys_ptrace,cap_sys_admin+p $(DESTDIR)$(bindir)/netnsjoin
40+
ln -sf nshold.1 $(DESTDIR)$(man1dir)/cgroupnshold.1
41+
ln -sf nslist.1 $(DESTDIR)$(man1dir)/cgroupnslist.1
42+
ln -sf nsrelease.1 $(DESTDIR)$(man1dir)/cgroupnsrelease.1
43+
ln -sf nshold.1 $(DESTDIR)$(man1dir)/ipcnshold.1
44+
ln -sf nslist.1 $(DESTDIR)$(man1dir)/ipcnslist.1
45+
ln -sf nsrelease.1 $(DESTDIR)$(man1dir)/ipcnsrelease.1
46+
ln -sf nshold.1 $(DESTDIR)$(man1dir)/mntnshold.1
47+
ln -sf nslist.1 $(DESTDIR)$(man1dir)/mntnslist.1
48+
ln -sf nsrelease.1 $(DESTDIR)$(man1dir)/mntnsrelease.1
49+
ln -sf nshold.1 $(DESTDIR)$(man1dir)/netnshold.1
50+
ln -sf nslist.1 $(DESTDIR)$(man1dir)/netnslist.1
51+
ln -sf nsrelease.1 $(DESTDIR)$(man1dir)/netnsrelease.1
52+
ln -sf nshold.1 $(DESTDIR)$(man1dir)/pidnshold.1
53+
ln -sf nslist.1 $(DESTDIR)$(man1dir)/pidnslist.1
54+
ln -sf nsrelease.1 $(DESTDIR)$(man1dir)/pidnsrelease.1
55+
ln -sf nshold.1 $(DESTDIR)$(man1dir)/usernshold.1
56+
ln -sf nslist.1 $(DESTDIR)$(man1dir)/usernslist.1
57+
ln -sf nsrelease.1 $(DESTDIR)$(man1dir)/usernsrelease.1
58+
ln -sf nshold.1 $(DESTDIR)$(man1dir)/utsnshold.1
59+
ln -sf nslist.1 $(DESTDIR)$(man1dir)/utsnslist.1
60+
ln -sf nsrelease.1 $(DESTDIR)$(man1dir)/utsnsrelease.1

README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1-
# nsutils
1+
#NSUTILS: Linux namespace utilities
2+
3+
Nsutils include a number of utilities to list, add/remove tag, and join namespaces.
4+
5+
INSTALL:
6+
7+
get the source code, from the root of the source tree run:
8+
```
9+
$ autoreconf -if
10+
$ ./configure
11+
$ make
12+
$ sudo make install
13+
14+

catargv.c

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* nsutils: namespace utilities
3+
* Copyright (C) 2016 Renzo Davoli, University of Bologna
4+
*
5+
* catargv: create a malloc-ed copy of all the argv arguments as a string
6+
*
7+
* Cado is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU General Public License
9+
* as published by the Free Software Foundation; either version 2
10+
* of the License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
*/
21+
22+
#include <stdio.h>
23+
24+
/* join all the args in a single string */
25+
char *catargv(char *argv[]) {
26+
char *out = NULL;
27+
size_t len = 0;
28+
FILE *fout = open_memstream(&out, &len);
29+
if (fout) {
30+
while (*argv) {
31+
fprintf(fout, "%s",*argv++);
32+
if (*argv) fprintf(fout," ");
33+
}
34+
fclose(fout);
35+
}
36+
return out;
37+
}

catargv.h

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef CATARGV_H
2+
#define CATARGV_H
3+
#include <stdio.h>
4+
5+
char *catargv(char *argv[]);
6+
7+
#endif //CATARGV_H

config.h

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/* config.h. Generated from config.h.in by configure. */
2+
/* config.h.in. Generated from configure.ac by autoheader. */
3+
4+
/* Define to 1 if you have the <fcntl.h> header file. */
5+
#define HAVE_FCNTL_H 1
6+
7+
/* Define to 1 if you have the <inttypes.h> header file. */
8+
#define HAVE_INTTYPES_H 1
9+
10+
/* Define to 1 if you have the <memory.h> header file. */
11+
#define HAVE_MEMORY_H 1
12+
13+
/* Define to 1 if you have the <regex.h> header file. */
14+
#define HAVE_REGEX_H 1
15+
16+
/* Define to 1 if you have the <stdint.h> header file. */
17+
#define HAVE_STDINT_H 1
18+
19+
/* Define to 1 if you have the <stdlib.h> header file. */
20+
#define HAVE_STDLIB_H 1
21+
22+
/* Define to 1 if you have the `strdup' function. */
23+
#define HAVE_STRDUP 1
24+
25+
/* Define to 1 if you have the <strings.h> header file. */
26+
#define HAVE_STRINGS_H 1
27+
28+
/* Define to 1 if you have the <string.h> header file. */
29+
#define HAVE_STRING_H 1
30+
31+
/* Define to 1 if you have the `strtoull' function. */
32+
#define HAVE_STRTOULL 1
33+
34+
/* Define to 1 if you have the <sys/capability.h> header file. */
35+
#define HAVE_SYS_CAPABILITY_H 1
36+
37+
/* Define to 1 if you have the <sys/stat.h> header file. */
38+
#define HAVE_SYS_STAT_H 1
39+
40+
/* Define to 1 if you have the <sys/types.h> header file. */
41+
#define HAVE_SYS_TYPES_H 1
42+
43+
/* Define to 1 if you have the <unistd.h> header file. */
44+
#define HAVE_UNISTD_H 1
45+
46+
/* Name of package */
47+
#define PACKAGE "nsutils"
48+
49+
/* Define to the address where bug reports for this package should be sent. */
50+
#define PACKAGE_BUGREPORT "[email protected]"
51+
52+
/* Define to the full name of this package. */
53+
#define PACKAGE_NAME "nsutils"
54+
55+
/* Define to the full name and version of this package. */
56+
#define PACKAGE_STRING "nsutils 0.2"
57+
58+
/* Define to the one symbol short name of this package. */
59+
#define PACKAGE_TARNAME "nsutils"
60+
61+
/* Define to the home page for this package. */
62+
#define PACKAGE_URL ""
63+
64+
/* Define to the version of this package. */
65+
#define PACKAGE_VERSION "0.2"
66+
67+
/* Define to 1 if you have the ANSI C header files. */
68+
#define STDC_HEADERS 1
69+
70+
/* Version number of package */
71+
#define VERSION "0.2"
72+
73+
/* Define for Solaris 2.5.1 so the uint32_t typedef from <sys/synch.h>,
74+
<pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
75+
#define below would cause a syntax error. */
76+
/* #undef _UINT32_T */
77+
78+
/* Define for Solaris 2.5.1 so the uint64_t typedef from <sys/synch.h>,
79+
<pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
80+
#define below would cause a syntax error. */
81+
/* #undef _UINT64_T */
82+
83+
/* Define to `int' if <sys/types.h> doesn't define. */
84+
/* #undef gid_t */
85+
86+
/* Define to `int' if <sys/types.h> does not define. */
87+
/* #undef pid_t */
88+
89+
/* Define to `int' if <sys/types.h> does not define. */
90+
/* #undef ssize_t */
91+
92+
/* Define to `int' if <sys/types.h> doesn't define. */
93+
/* #undef uid_t */
94+
95+
/* Define to the type of an unsigned integer type of width exactly 32 bits if
96+
such a type exists and the standard includes do not define it. */
97+
/* #undef uint32_t */
98+
99+
/* Define to the type of an unsigned integer type of width exactly 64 bits if
100+
such a type exists and the standard includes do not define it. */
101+
/* #undef uint64_t */

configure.ac

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
utoconf -*-
2+
# Process this file with autoconf to produce a configure script.
3+
4+
AC_PREREQ([2.69])
5+
AC_INIT([nsutils], [0.2], [[email protected]])
6+
AM_INIT_AUTOMAKE([foreign dist-bzip2])
7+
AC_CONFIG_SRCDIR([nssearch.h])
8+
AC_CONFIG_HEADERS([config.h])
9+
CFLAGS="$CFLAGS -Wall"
10+
11+
# Checks for programs.
12+
AC_PROG_CC
13+
AC_PROG_INSTALL
14+
15+
# Checks for libraries.
16+
17+
# Checks for header files.
18+
AC_CHECK_HEADERS([fcntl.h stdint.h stdlib.h string.h unistd.h regex.h])
19+
AC_CHECK_HEADERS([sys/capability.h],
20+
[],
21+
[AC_MSG_ERROR([missing libcap header])])
22+
23+
# Checks for typedefs, structures, and compiler characteristics.
24+
AC_TYPE_UID_T
25+
AC_TYPE_PID_T
26+
AC_TYPE_SSIZE_T
27+
AC_TYPE_UINT32_T
28+
AC_TYPE_UINT64_T
29+
30+
# Checks for library functions.
31+
AC_CHECK_FUNCS([strdup strtoull])
32+
33+
AC_OUTPUT([Makefile])

memogetusername.c

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* nsutils: namespace utilities
3+
* Copyright (C) 2016 Renzo Davoli, University of Bologna
4+
*
5+
* memogetpwuid: memoize version of getpwuid
6+
*
7+
* Cado is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU General Public License
9+
* as published by the Free Software Foundation; either version 2
10+
* of the License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
*/
21+
22+
#define _GNU_SOURCE
23+
#include <stdio.h>
24+
#include <stdlib.h>
25+
#include <string.h>
26+
#include <pwd.h>
27+
#include <sys/types.h>
28+
29+
struct memopw {
30+
uid_t pw_uid; /* user ID */
31+
char *pw_name; /* username */
32+
struct memopw *next;
33+
};
34+
35+
static struct memopw *memohead;
36+
37+
static char *memogetpw(struct memopw **scan, uid_t pw_uid) {
38+
while (*scan != NULL && (*scan)->pw_uid < pw_uid)
39+
scan = &((*scan)->next);
40+
if (*scan != NULL && (*scan)->pw_uid == pw_uid)
41+
return (*scan)->pw_name;
42+
else {
43+
struct passwd *pwd = getpwuid(pw_uid);
44+
struct memopw *new = malloc(sizeof(struct memopw));
45+
if (new) {
46+
new->pw_uid = pw_uid;
47+
if (pwd)
48+
new->pw_name = strdup(pwd->pw_name);
49+
else
50+
asprintf(&new->pw_name,"%d",pw_uid);
51+
new->next = *scan;
52+
*scan = new;
53+
return new->pw_name;
54+
} else
55+
return pwd ? pwd->pw_name : "";
56+
}
57+
}
58+
59+
/* return the username from the uid. Memoize the results */
60+
char *memogetusername(uid_t pw_uid) {
61+
return memogetpw(&memohead, pw_uid);
62+
}
63+
64+
#if 0
65+
#include <stdio.h>
66+
int main(int argc, char *argv[]) {
67+
while (1) {
68+
uid_t uid;
69+
scanf("%d", &uid);
70+
printf("%d %s\n",uid,memogetusername(uid));
71+
}
72+
}
73+
#endif

memogetusername.h

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef MEMOGETPWUID_C
2+
#define MEMOGETPWUID_C
3+
#define _GNU_SOURCE
4+
#include <pwd.h>
5+
6+
char *memogetusername(uid_t pw_uid);
7+
8+
#endif // MEMOGETPWUID_C

netnsjoin.1

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.TH NETNSJOIN 1 "August 14, 2016" "VirtualSquare Labs"
2+
.SH NAME
3+
netnsjoin \- Join the net namespace of another process
4+
.SH SYNOPSIS
5+
6+
.B cado
7+
.I pid_or_net_namespace_id_or_placeholder_tag
8+
.I command
9+
[
10+
.I args
11+
]
12+
13+
.B cado
14+
.I long placeholder tag
15+
.R --
16+
.I command
17+
[
18+
.I args
19+
]
20+
21+
.SH DESCRIPTION
22+
\fBnetnsjoin\fR joins the net namespace of another process.
23+
24+
The namespace to join can be identified by the pid of a process belonging to
25+
that namespace, by the namespace id (e.g. net:[1234567890]) or using a tag defined by \fBnetnshold(1)\fR
26+
27+
Root access or CAP_NET_ADMIN is required to run the program. CAP_NET_ADMIN can be delegated to
28+
specific users by \fBcado(1)\fR (if installed).
29+
30+
.SH SEE ALSO
31+
\fBnetnshold\fR(1)
32+
\fBnetnslist\fR(1)
33+
\fBnetnsrelease\fR(1)
34+
\fBcado\fR(1)

0 commit comments

Comments
 (0)