summaryrefslogtreecommitdiffstats
path: root/ax25
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>2015-06-19 20:42:04 +0200
committerRalf Baechle <ralf@linux-mips.org>2015-06-19 20:42:04 +0200
commit18fa7fa6776da35da34a7e148fa2d96be8921e2e (patch)
treed3bf0e4cf856549f727b2906b99a90977b2b9e4c /ax25
parentd33b07fe9207c73d7195d942b13097a81013a19d (diff)
axparms: Accept numeric user ID.
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'ax25')
-rw-r--r--ax25/axparms.82
-rw-r--r--ax25/axparms.c27
2 files changed, 22 insertions, 7 deletions
diff --git a/ax25/axparms.8 b/ax25/axparms.8
index 3187158..d4b1b7c 100644
--- a/ax25/axparms.8
+++ b/ax25/axparms.8
@@ -21,7 +21,7 @@ and so no generalised command format can be given.
The format of this option is:
.LP
.nf
-.B axparms --assoc <callsign> <username>
+.B axparms --assoc <callsign> <username|uid>
.br
.B axparms --assoc <callsign> delete
.br
diff --git a/ax25/axparms.c b/ax25/axparms.c
index a3795e3..5c49e58 100644
--- a/ax25/axparms.c
+++ b/ax25/axparms.c
@@ -1,3 +1,4 @@
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -168,9 +169,10 @@ int setifcall(int s, char *ifn, char *name)
int associate(int s, int argc, char *argv[])
{
- char buffer[80], *u, *c;
+ char buffer[80], *u, *c, *endp;
struct sockaddr_ax25 sax25;
struct passwd *pw;
+ uid_t uid;
int opt;
FILE *fp;
@@ -254,12 +256,25 @@ int associate(int s, int argc, char *argv[])
return 0;
}
- if ((pw = getpwnam(argv[3])) == NULL) {
- fprintf(stderr, "axparms: associate: unknown username %s\n", argv[3]);
- return 1;
- }
+ /*
+ * Tolerate spaces following a UID, it may happen in scripts
+ */
+ errno = 0;
+ uid = strtol(argv[3], &endp, 0);
+ if (!errno && (*endp == '\0' || isspace(*endp))) {
+ sax25.sax25_uid = uid;
+ } else {
+ pw = getpwnam(argv[3]);
+
+ if (pw == NULL) {
+ fprintf(stderr,
+ "axparms: associate: unknown username %s\n",
+ argv[3]);
+ return 1;
+ }
- sax25.sax25_uid = pw->pw_uid;
+ sax25.sax25_uid = pw->pw_uid;
+ }
if (ioctl(s, SIOCAX25ADDUID, &sax25) == -1) {
perror("axparms: SIOCAX25ADDUID");