Subject: | rpc.quotad authorize patch |
I had i problem with Quota.pm because on FreeBSD (and probably on Linux too) rpc.rquotad checkd if authentification uid send by rpc is the same as uid of rpc.rquotad.
In our network quota deamons are owned by root (probably as always) but i dont want to run programs that check quota witch by root permissions.
So i wrote a little patch that allow setting of uid, gid and hostname thru authunix_create function.
From user site new function is enabled
Quota::rpcauth(uid=getuid(),gid=getgid(),hostname=NULL)
If hostneme is NULL the gethostname is used to set hostname.
Patch was tested on Quota 1.5.0 on Perl 5.8.0 on FreeBSD 4.9 and on Perl 5.8.4 on Linux 2.6.11.8.
Best regards,
Karol Lassak
diff -ur Quota-1.5.0/Quota.pm Quota-1.5.0+auth/Quota.pm
--- Quota-1.5.0/Quota.pm Sun Nov 21 13:19:47 2004
+++ Quota-1.5.0+auth/Quota.pm Mon May 30 15:48:33 2005
@@ -127,6 +127,8 @@
Quota::rpcquery($host, $path [,$uid]);
Quota::rpcpeer([$port [,$use_tcp [,timeout]]]);
+
+ Quota::rpcauth([$uid [,$gid [,$hostname]]]);
Quota::setqlim($dev, $uid, $block_soft, $block_hard,
$inode_soft, $inode_hard [,$tlo [,isgrp]]);
@@ -244,6 +246,12 @@
optional. By default the portmapper on the remote host is used
(i.e. default port is 0, protocol is UDP) The default timeout is
4 seconds.
+
+=item I<Quota::rpcauth($uid,$gid,$hostname)>
+
+Configure authorization parameters for subsequent RPC queries;
+all parameters are optional. By default uid and gid are taken from
+owner of the process and hostname is the host name of current machine.
=item I<$arg = Quota::getqcarg($path)>
diff -ur Quota-1.5.0/Quota.xs Quota-1.5.0+auth/Quota.xs
--- Quota-1.5.0/Quota.xs Sun Nov 21 13:25:25 2004
+++ Quota-1.5.0+auth/Quota.xs Mon May 30 15:46:11 2005
@@ -47,6 +47,13 @@
unsigned timeout;
} quota_rpc_cfg = {FALSE, 0, 4000};
+static struct
+{
+ int uid;
+ int gid;
+ char hostname[MAX_MACHINE_NAME + 1];
+} quota_rpc_auth = {-1, -1, NULL};
+
/*
* fetch quotas from remote host
*/
@@ -93,8 +100,16 @@
if (client == NULL)
return ((int) rpc_createerr.cf_stat);
-
- client->cl_auth = authunix_create_default();
+
+ /*
+ * Authorization
+ */
+ if (quota_rpc_auth.uid > -1 && quota_rpc_auth.gid > -1) {
+ client->cl_auth = authunix_create(quota_rpc_auth.hostname, quota_rpc_auth.uid, quota_rpc_auth.gid, 0, 0);
+ }
+ else {
+ client->cl_auth = authunix_create_default();
+ }
/*
* Call remote server
@@ -623,6 +638,23 @@
quota_rpc_cfg.port = port;
quota_rpc_cfg.use_tcp = use_tcp;
quota_rpc_cfg.timeout = timeout;
+#endif
+ }
+
+void
+rpcauth(uid=getuid(),gid=getgid(),hostname=NULL)
+ int uid
+ int gid
+ char * hostname
+ PPCODE:
+ {
+#ifndef NO_RPC
+ quota_rpc_auth.uid = uid;
+ quota_rpc_auth.gid = gid;
+ if (hostname == NULL)
+ gethostname(quota_rpc_auth.hostname, MAX_MACHINE_NAME);
+ else
+ strncpy(quota_rpc_auth.hostname, hostname, MAX_MACHINE_NAME);
#endif
}
diff -ur Quota-1.5.0/README Quota-1.5.0+auth/README
--- Quota-1.5.0/README Sun Nov 21 13:19:47 2004
+++ Quota-1.5.0+auth/README Mon May 30 15:59:30 2005
@@ -174,6 +174,12 @@
the remote host is used (i.e. default port is 0,
protocol is UDP) The default timeout is 4 seconds.
+ Quota::rpcauth($uid,$gid,$hostname)
+ Configure authorization parameters for subsequent
+ RPC queries; all parameters are optional. By default
+ uid and gid are taken from owner of the process and
+ hostname is the host name of current machine.
+
$arg = Quota::getqcarg($path)
Get the required $dev argument for Quota::query and
Quota::setqlim for the file system you want to operate