0

I want to use curl to control features of a IPcam. This works fine in a shell (/bin/sh) but fails when called from knockd. I am trying this on a QNAP NAS (Busybox Linux).

The script I am using is:

#!/bin/sh
cd /share/Marc/.scripts
curl -v --upload-file /share/CACHEDEV1_DATA/Marc/.scripts/on.txt --user admin:xxxxx --digest http://192.168.178.28/PSIA/Custom/SelfExt/Event/triggers/VMD-1

It yields the following output (piped to a file for debugging):

<!DOCTYPE html>
<html><head><title>Document Error: Unauthorized</title></head>
<body><h2>Access Error: 401 -- Unauthorized</h2>
<p>Authentication Error: Access Denied! Authorization required.</p>
</body>
</html>

When calling curl from a shell, I get:

* About to connect() to 192.168.178.28 port 80 (#0)
*   Trying 192.168.178.28...   
[...]
connected
* Connected to 192.168.178.28 (192.168.178.28) port 80 (#0)
* Server auth using Digest with user 'admin'
> PUT /PSIA/Custom/SelfExt/Event/triggers/VMD-1 HTTP/1.1
> User-Agent: curl/7.21.0 (arm-openwrt-linux-gnu) libcurl/7.21.0 OpenSSL/1.0.0s zlib/1.2.7 libidn/1.9
> Host: 192.168.178.28
> Accept: */*
> Content-Length: 0
> Expect: 100-continue
> 
< HTTP/1.1 401 Unauthorized
< Date: Tue, 17 Nov 2015 07:03:21 GMT
< Server: App-webs/
< Content-Length: 218
< Content-Type: text/html
< Connection: keep-alive
< Keep-Alive: timeout=60, max=99
< WWW-Authenticate: Digest realm="TV-IP320PI",nonce="ZjY1MWVmNThiNzY0YmVmOTEwMzFiY2E0YmZhNzQwNzZmMjBjMzNmNmU0OGQ0ZjczMzZiMzZkNGMxOWZlM2QxNTo6MTQ0MTQ3OTU6VFYtSVAzMjBQSQ=="
< 
* Ignoring the response-body
{ [data not shown]
[...]
Connection #0 to host 192.168.178.28 left intact
* Issue another request to this URL: 'http://192.168.178.28/PSIA/Custom/SelfExt/Event/triggers/VMD-1'
* Re-using existing connection! (#0) with host 192.168.178.28
* Connected to 192.168.178.28 (192.168.178.28) port 80 (#0)
* Server auth using Digest with user 'admin'
> PUT /PSIA/Custom/SelfExt/Event/triggers/VMD-1 HTTP/1.1
> Authorization: Digest username="admin", realm="TV-IP320PI", nonce="ZjY1MWVmNThiNzY0YmVmOTEwMzFiY2E0YmZhNzQwNzZmMjBjMzNmNmU0OGQ0ZjczMzZiMzZkNGMxOWZlM2QxNTo6MTQ0MTQ3OTU6VFYtSVAzMjBQSQ==", uri="/PSIA/Custom/SelfExt/Event/triggers/VMD-1", response="1e4ca05ee7ac23230232de3a611bb7b3"
> User-Agent: curl/7.21.0 (arm-openwrt-linux-gnu) libcurl/7.21.0 OpenSSL/1.0.0s zlib/1.2.7 libidn/1.9
> Host: 192.168.178.28
> Accept: */*
> Content-Length: 470
> Expect: 100-continue
> 
[...]
< HTTP/1.1 200 OK
< Date: Tue, 17 Nov 2015 07:03:22 GMT
< Server: App-webs/
< Connection: close
< Content-Length: 242
< Content-Type: application/xml
< 
{ [data not shown]
[...]
Closing connection #0

Somehow curl seems to stop prematurely when called from knockd. The knockd.conf is:

[EnableOutdoors]
        sequence    = x,y
        seq_timeout = 5
        command     = /share/CACHEDEV1_DATA/Marc/.scripts/enableOutdoors.sh
        tcpflags    = syn

Why is curl behaving differently? I also tried to include all exports as set in the shell in the script enableOutdoors.sh, but this did not help.

2
  • Do you have special characters in your password? In other words. are there characters which need to be ESCaped? Nov 17, 2015 at 10:14
  • No, the password is purely alphanumerical. (Low security, but it's behind a firewall.)
    – Marc
    Nov 19, 2015 at 20:18

1 Answer 1

0

For reasons unknown to me, there were two instances of curl on the NAS. (Maybe one introduced by an OS update?) Somehow the exporting of environment variable did not work. Explicitly calling the "right" curl in the script solved the issue.

# /sbin/curl -V 
curl 7.21.0 (arm-openwrt-linux-gnu) libcurl/7.21.0 OpenSSL/1.0.0s zlib/1.2.7 libidn/1.9
Protocols: dict file ftp ftps http https imap imaps ldap ldaps pop3 pop3s rtsp smtp smtps telnet tftp 
Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz 

# /share/CACHEDEV1_DATA/.qpkg/Entware/bin/curl -V
curl 7.43.0 (arm-openwrt-linux-gnueabi) libcurl/7.43.0 OpenSSL/1.0.2d zlib/1.2.8
Protocols: file ftp ftps http https imap imaps pop3 pop3s rtsp smtp smtps tftp 
Features: IPv6 Largefile SSL libz 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .