aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2018-07-18 12:09:37 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2018-07-18 14:14:21 +0200
commit1f6af159ab2de1f26311d753bcfb7c8047dc877f (patch)
tree1f384227ccffc17addb872d812a13055b873c75b
parent721dfa576f7690a0816400aa849bb6aa908423d3 (diff)
downloadalpine_aports-1f6af159ab2de1f26311d753bcfb7c8047dc877f.tar.bz2
alpine_aports-1f6af159ab2de1f26311d753bcfb7c8047dc877f.tar.xz
alpine_aports-1f6af159ab2de1f26311d753bcfb7c8047dc877f.zip
main/mqtt-exec: backport password auth support
and remove unused patch
-rw-r--r--main/mqtt-exec/0001-authentication-expose-authentication-with-credential.patch89
-rw-r--r--main/mqtt-exec/0001-implement-v-verbose-to-optionally-pass-the-the-topic.patch77
-rw-r--r--main/mqtt-exec/APKBUILD4
3 files changed, 92 insertions, 78 deletions
diff --git a/main/mqtt-exec/0001-authentication-expose-authentication-with-credential.patch b/main/mqtt-exec/0001-authentication-expose-authentication-with-credential.patch
new file mode 100644
index 0000000000..aba1cee9fa
--- /dev/null
+++ b/main/mqtt-exec/0001-authentication-expose-authentication-with-credential.patch
@@ -0,0 +1,89 @@
1From 5ee7377172dc0f30a64d009210db7efbf5d2219f Mon Sep 17 00:00:00 2001
2From: Kevin Daudt <me@ikke.info>
3Date: Wed, 14 Mar 2018 22:50:28 +0100
4Subject: [PATCH] authentication: expose authentication with credentials
5
6libmosquitto supports authentication with credentials, so allow settings
7credentials through parameters.
8---
9 mqtt-exec.c | 20 +++++++++++++++++++-
10 1 file changed, 19 insertions(+), 1 deletion(-)
11
12diff --git a/mqtt-exec.c b/mqtt-exec.c
13index fc5ab03..28251fb 100644
14--- a/mqtt-exec.c
15+++ b/mqtt-exec.c
16@@ -71,8 +71,10 @@ int usage(int retcode)
17 " -i,--id ID The id to use for this client\n"
18 " -k,--keepalive SEC Set keepalive to SEC. Default is 60\n"
19 " -p,--port PORT Set TCP port to PORT. Default is 1883\n"
20+" -P,--password PASSWORD Set password for authentication\n"
21 " -q,--qos QOS Set Quality of Serive to level. Default is 0\n"
22 " -t,--topic TOPIC Set MQTT topic to TOPIC. May be repeated\n"
23+" -u,--username USERNAME Set username for authentication\n"
24 " -v,--verbose Pass over the topic to application as firs arg\n"
25 " --will-topic TOPIC Set the client Will topic to TOPIC\n"
26 " --will-payload MSG Set the client Will message to MSG\n"
27@@ -119,6 +121,8 @@ int main(int argc, char *argv[])
28 {"qos", required_argument, 0, 'q' },
29 {"topic", required_argument, 0, 't' },
30 {"verbose", no_argument, 0, 'v' },
31+ {"username", required_argument, 0, 'u' },
32+ {"password", required_argument, 0, 'P' },
33 {"will-topic", required_argument, 0, 0x1001 },
34 {"will-payload", required_argument, 0, 0x1002 },
35 {"will-qos", required_argument, 0, 0x1003 },
36@@ -145,6 +149,8 @@ int main(int argc, char *argv[])
37 char hostname[256];
38 static char id[MOSQ_MQTT_ID_MAX_LENGTH+1];
39 struct mosquitto *mosq = NULL;
40+ char *username = NULL;
41+ char *password = NULL;
42
43 char *will_payload = NULL;
44 int will_qos = 0;
45@@ -166,7 +172,7 @@ int main(int argc, char *argv[])
46 memset(hostname, 0, sizeof(hostname));
47 memset(id, 0, sizeof(id));
48
49- while ((c = getopt_long(argc, argv, "cdh:i:k:p:q:t:v", opts, &i)) != -1) {
50+ while ((c = getopt_long(argc, argv, "cdh:i:k:p:P:q:t:u:v", opts, &i)) != -1) {
51 switch(c) {
52 case 'c':
53 clean_session = false;
54@@ -191,6 +197,8 @@ int main(int argc, char *argv[])
55 case 'p':
56 port = atoi(optarg);
57 break;
58+ case 'P':
59+ password = optarg;
60 case 'q':
61 ud.qos = atoi(optarg);
62 if (!valid_qos_range(ud.qos, "QoS"))
63@@ -202,6 +210,8 @@ int main(int argc, char *argv[])
64 sizeof(char *) * ud.topic_count);
65 ud.topics[ud.topic_count-1] = optarg;
66 break;
67+ case 'u':
68+ username = optarg;
69 case 'v':
70 ud.verbose = 1;
71 break;
72@@ -286,6 +296,14 @@ int main(int argc, char *argv[])
73 goto cleanup;
74 }
75
76+ if (!username != !password) {
77+ fprintf(stderr, "Need to set both username and password\n");
78+ goto cleanup;
79+ }
80+
81+ if (username && password)
82+ mosquitto_username_pw_set(mosq, username, password);
83+
84 #ifdef WITH_TLS
85 if ((cafile || capath) && mosquitto_tls_set(mosq, cafile, capath, certfile,
86 keyfile, NULL)) {
87--
882.18.0
89
diff --git a/main/mqtt-exec/0001-implement-v-verbose-to-optionally-pass-the-the-topic.patch b/main/mqtt-exec/0001-implement-v-verbose-to-optionally-pass-the-the-topic.patch
deleted file mode 100644
index e2ea3dbe1e..0000000000
--- a/main/mqtt-exec/0001-implement-v-verbose-to-optionally-pass-the-the-topic.patch
+++ /dev/null
@@ -1,77 +0,0 @@
1From 9b550ad2043dee35b42d053899fed62b6ac53c92 Mon Sep 17 00:00:00 2001
2From: Natanael Copa <ncopa@alpinelinux.org>
3Date: Wed, 4 Dec 2013 15:27:47 +0100
4Subject: [PATCH] implement -v/--verbose to optionally pass the the topic
5
6---
7 mqtt-exec.c | 21 +++++++++++++--------
8 1 file changed, 13 insertions(+), 8 deletions(-)
9
10diff --git a/mqtt-exec.c b/mqtt-exec.c
11index be52ba4..e6ab0ee 100644
12--- a/mqtt-exec.c
13+++ b/mqtt-exec.c
14@@ -25,9 +25,12 @@ void message_cb(struct mosquitto *mosq, void *obj,
15 const struct mosquitto_message *msg)
16 {
17 struct userdata *ud = (struct userdata *)obj;
18- if (msg->payloadlen) {
19+ if (msg->payloadlen || ud->verbose) {
20 if (ud->command_argv && fork() == 0) {
21- ud->command_argv[ud->command_argc-1] = msg->payload;
22+ if (ud->verbose)
23+ ud->command_argv[ud->command_argc-2] = msg->topic;
24+ ud->command_argv[ud->command_argc-1] =
25+ msg->payloadlen ? msg->payload : NULL;
26 execv(ud->command_argv[0], ud->command_argv);
27 perror(ud->command_argv[0]);
28 _exit(1);
29@@ -74,6 +77,7 @@ int main(int argc, char *argv[])
30 {"keepalive", required_argument, 0, 'k' },
31 {"port", required_argument, 0, 'p' },
32 {"topic", required_argument, 0, 't' },
33+ {"verbose", no_argument, 0, 'v' },
34 { 0, 0, 0, 0}
35 };
36 int debug = 0;
37@@ -91,7 +95,7 @@ int main(int argc, char *argv[])
38 memset(hostname, 0, sizeof(hostname));
39 memset(id, 0, sizeof(id));
40
41- while ((c = getopt_long(argc, argv, "dh:k:p:t:", opts, &i)) != -1) {
42+ while ((c = getopt_long(argc, argv, "dh:k:p:t:v", opts, &i)) != -1) {
43 switch(c) {
44 case 'd':
45 debug = 1;
46@@ -108,6 +112,9 @@ int main(int argc, char *argv[])
47 case 't':
48 ud.topic = optarg;
49 break;
50+ case 'v':
51+ ud.verbose = 1;
52+ break;
53 case '?':
54 return usage(1);
55 }
56@@ -116,15 +123,13 @@ int main(int argc, char *argv[])
57 if ((ud.topic == NULL) || (optind == argc))
58 return usage(1);
59
60- ud.command_argc = (argc - optind) + 1;
61+ ud.command_argc = (argc - optind) + 1 + ud.verbose;
62 ud.command_argv = malloc((ud.command_argc + 1) * sizeof(char *));
63 if (ud.command_argv == NULL)
64 return perror_ret("malloc");
65
66- for (i=0; i < ud.command_argc; i++)
67- ud.command_argv[i] = argv[optind+i];
68- ud.command_argv[ud.command_argc-1] = NULL;
69- ud.command_argv[ud.command_argc] = NULL;
70+ for (i=0; i <= ud.command_argc; i++)
71+ ud.command_argv[i] = optind+i < argc ? argv[optind+i] : NULL;
72
73 /* generate an id */
74 gethostname(hostname, sizeof(hostname)-1);
75--
761.8.5.1
77
diff --git a/main/mqtt-exec/APKBUILD b/main/mqtt-exec/APKBUILD
index ec35fb1398..6996f0d13c 100644
--- a/main/mqtt-exec/APKBUILD
+++ b/main/mqtt-exec/APKBUILD
@@ -1,7 +1,7 @@
1# Maintainer: Natanael Copa <ncopa@alpinelinux.org> 1# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
2pkgname=mqtt-exec 2pkgname=mqtt-exec
3pkgver=0.4 3pkgver=0.4
4pkgrel=0 4pkgrel=1
5pkgdesc="simple MQTT client that executes a command on messages" 5pkgdesc="simple MQTT client that executes a command on messages"
6url="https://github.com/ncopa/mqtt-exec" 6url="https://github.com/ncopa/mqtt-exec"
7arch="all" 7arch="all"
@@ -12,6 +12,7 @@ makedepends="$depends_dev mosquitto-dev"
12install="" 12install=""
13subpackages="" 13subpackages=""
14source="mqtt-exec-$pkgver.tar.gz::https://github.com/ncopa/mqtt-exec/archive/v$pkgver.tar.gz 14source="mqtt-exec-$pkgver.tar.gz::https://github.com/ncopa/mqtt-exec/archive/v$pkgver.tar.gz
15 0001-authentication-expose-authentication-with-credential.patch
15 mqtt-exec.initd 16 mqtt-exec.initd
16 " 17 "
17 18
@@ -39,4 +40,5 @@ package() {
39} 40}
40 41
41sha512sums="1448b2dda0f27a5275c113331ea2bc073ec1740797c1bb5b472ee3e0fd4d3ef4bcdfa6dc42e7540ee154b291c3d70df89f0646899ebb1bfe585d1384797de5e7 mqtt-exec-0.4.tar.gz 42sha512sums="1448b2dda0f27a5275c113331ea2bc073ec1740797c1bb5b472ee3e0fd4d3ef4bcdfa6dc42e7540ee154b291c3d70df89f0646899ebb1bfe585d1384797de5e7 mqtt-exec-0.4.tar.gz
43418058ecc05922df186d0dcbfeab7656977256a143f0346406598d1cf7331d3ba95a9b004bf3b6581be2e3cb2fbf5e69d7954b4c7ac488863f0318506c7f1c7c 0001-authentication-expose-authentication-with-credential.patch
42b04b3f43d9079783d5a9af01aba49fa20431e528237e80790cd6ef89ea019d632866d1e2acfc619c3a90ed2cf4469422bac44727088392394792be68a6d13fae mqtt-exec.initd" 44b04b3f43d9079783d5a9af01aba49fa20431e528237e80790cd6ef89ea019d632866d1e2acfc619c3a90ed2cf4469422bac44727088392394792be68a6d13fae mqtt-exec.initd"