diff options
author | Russ Allbery <rra@stanford.edu> | 2011-09-21 19:23:28 -0700 |
---|---|---|
committer | Russ Allbery <rra@stanford.edu> | 2011-09-21 19:23:28 -0700 |
commit | c221eaac6dbc285f819c9bc14e9b90607a3061fd (patch) | |
tree | 885cd913acb355b35cbe435af0bdbfadc9d8b560 /php | |
parent | ac2d4bb47f3026ccc34f731ab4c2926b0768b378 (diff) |
Add PHP bindings for remctl_set_source_ip
Diffstat (limited to 'php')
-rw-r--r-- | php/README | 7 | ||||
-rw-r--r-- | php/php_remctl.c | 39 | ||||
-rw-r--r-- | php/php_remctl.h.in | 1 | ||||
-rw-r--r-- | php/tests/004.phpt | 44 |
4 files changed, 84 insertions, 7 deletions
@@ -109,6 +109,13 @@ FULL INTERFACE Returns, as a string, the error message from the last failed operation on the connection object CONNECTION. + remctl_set_source_ip(SOURCE) + Sets the source IP for outgoing connections to SOURCE, which can be + either an IPv4 or an IPv6 address (if IPv6 is supported). It must + be an IP address, not a host name. This method must be called prior + to calling remctl_open() and will affect all subsequent + remctl_open() calls on the same object. + remctl_open(CONNECTION, HOSTNAME[, PORT[, PRINCIPAL]]) Connect to HOSTNAME on port PORT using PRINCIPAL as the remote server's principal for authentication. If PORT is omitted or 0, use diff --git a/php/php_remctl.c b/php/php_remctl.c index 34315b5..70f2154 100644 --- a/php/php_remctl.c +++ b/php/php_remctl.c @@ -29,13 +29,14 @@ static int le_remctl_internal; static zend_function_entry remctl_functions[] = { - ZEND_FE(remctl, NULL) - ZEND_FE(remctl_new, NULL) - ZEND_FE(remctl_open, NULL) - ZEND_FE(remctl_close, NULL) - ZEND_FE(remctl_command, NULL) - ZEND_FE(remctl_output, NULL) - ZEND_FE(remctl_error, NULL) + ZEND_FE(remctl, NULL) + ZEND_FE(remctl_new, NULL) + ZEND_FE(remctl_set_source_ip, NULL) + ZEND_FE(remctl_open, NULL) + ZEND_FE(remctl_close, NULL) + ZEND_FE(remctl_command, NULL) + ZEND_FE(remctl_output, NULL) + ZEND_FE(remctl_error, NULL) { NULL, NULL, NULL, 0, 0 } }; @@ -214,6 +215,30 @@ ZEND_FUNCTION(remctl_new) /* + * Set the source IP for subsequent connections with remctl_open. + */ +ZEND_FUNCTION(remctl_set_source_ip) +{ + struct remctl *r; + zval *zrem; + char *source; + int slen, status; + + status = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &zrem, + &source, &slen); + if (status == FAILURE) { + zend_error(E_WARNING, "remctl_set_source_ip: invalid parameters\n"); + RETURN_FALSE; + } + ZEND_FETCH_RESOURCE(r, struct remctl *, &zrem, -1, PHP_REMCTL_RES_NAME, + le_remctl_internal); + if (!remctl_set_source_ip(r, source)) + RETURN_FALSE; + RETURN_TRUE; +} + + +/* * Open a connection to the remote host. Only the host parameter is required; * the rest are optional. PHP may require something be passed in for * principal, but the empty string is taken to mean "use the library default." diff --git a/php/php_remctl.h.in b/php/php_remctl.h.in index d346f7a..599ed70 100644 --- a/php/php_remctl.h.in +++ b/php/php_remctl.h.in @@ -20,6 +20,7 @@ PHP_MINIT_FUNCTION(remctl); PHP_FUNCTION(remctl); PHP_FUNCTION(remctl_new); +PHP_FUNCTION(remctl_set_source_ip); PHP_FUNCTION(remctl_open); PHP_FUNCTION(remctl_command); PHP_FUNCTION(remctl_output); diff --git a/php/tests/004.phpt b/php/tests/004.phpt new file mode 100644 index 0000000..818bde5 --- /dev/null +++ b/php/tests/004.phpt @@ -0,0 +1,44 @@ +--TEST-- +Check setting source IP +--ENV-- +KRB5CCNAME=remctl-test.cache +LD_LIBRARY_PATH=../client/.libs +--SKIPIF-- +<?php + if (!file_exists("remctl-test.pid")) + echo "skip remctld not running"; +?> +--FILE-- +<?php + $fh = fopen("remctl-test.princ", "r"); + $principal = rtrim(fread($fh, filesize("remctl-test.princ"))); + $r = remctl_new(); + if ($r == null) { + echo "remctl_new failed\n"; + exit(2); + } + echo "Created object\n"; + if (!remctl_set_source_ip($r, "127.0.0.1")) { + echo "remctl_set_source_ip failed\n"; + exit(2); + } + if (!remctl_open($r, "127.0.0.1", 14373, $principal)) { + echo "remctl_open failed\n"; + exit(2); + } + echo "Opened connection with source 127.0.0.1\n"; + if (!remctl_set_source_ip($r, "::1")) { + echo "remctl_set_source_ip failed\n"; + exit(2); + } + if (remctl_open($r, "127.0.0.1", 14373, $principal)) { + echo "remctl_open unexpectedly succeeded\n"; + exit(2); + } + echo "Open failed with source ::1\n"; + remctl_close($r); +?> +--EXPECT-- +Created object +Opened connection with source 127.0.0.1 +Open failed with source ::1 |