2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* Daemon that implements remote procedure call service for non-vendor system
11 * calls (currently setpag and pioctl). The AFS cache manager daemon, afsd,
12 * currently fires up this module, when the "-rmtsys" flag is given.
13 * This module resides in the lib/afs/librmtsys.a library.
15 #include <afsconfig.h>
16 #include <afs/param.h>
23 /*#include <afs/cellconfig.h>*/
25 #include "sys_prototypes.h"
27 #define NFS_EXPORTER 1 /* To probably handle more later */
28 #define PSETPAG 110 /* Also defined in afs/afs_pioctl.c */
29 #define PIOCTL_HEADER 6 /* # of words prepended to special pioctl */
30 #define PSetClientContext 99 /* Sets up caller's creds */
31 #define N_SECURITY_OBJECTS 1 /* No real security yet */
33 #define SETCLIENTCONTEXT(BLOB, host, uid, group0, group1, cmd, exportertype) { \
36 (BLOB)[2] = (group0); \
37 (BLOB)[3] = (group1); \
39 (BLOB)[5] = (exportertype); \
43 /* Main routine of the remote AFS system call server. The calling process will
44 * never return; this is currently called from afsd (when "-rmtsys" is passed
49 /* void catchsig(int); */
50 struct rx_securityClass
*(securityObjects
[N_SECURITY_OBJECTS
]);
51 struct rx_service
*service
;
54 * Ignore SIGHUP signal since apparently is sent to the processes that
55 * start up from /etc/rc for some systems like hpux and aix3.1...
57 signal(SIGHUP
, SIG_IGN
);
59 /* Initialize the rx-based RMTSYS server */
60 if (rx_Init(htons(AFSCONF_RMTSYSPORT
)) < 0)
62 securityObjects
[RX_SECIDX_NULL
] = rxnull_NewServerSecurityObject();
63 if (securityObjects
[RX_SECIDX_NULL
] == (struct rx_securityClass
*)0)
64 rmt_Quit("rxnull_NewServerSecurityObject");
66 rx_NewService(0, RMTSYS_SERVICEID
, AFSCONF_RMTSYSSERVICE
,
67 securityObjects
, N_SECURITY_OBJECTS
,
68 RMTSYS_ExecuteRequest
);
70 rmt_Quit("rx_NewService");
71 /* One may wish to tune some default RX params for better performance
73 rx_SetMaxProcs(service
, 2);
74 rx_StartServer(1); /* Donate this process to the server process pool */
78 /* Implements the remote setpag(2) call. Note that unlike the standard call,
79 * here we also get back the new pag value; we need this so that the caller
80 * can add it to its group list via setgroups() */
82 SRMTSYS_SetPag(struct rx_call
*call
, clientcred
*creds
, afs_int32
*newpag
,
83 afs_int32
*errornumber
)
85 afs_uint32 blob
[PIOCTL_HEADER
];
86 struct ViceIoctl data
;
90 SETCLIENTCONTEXT(blob
, rx_HostOf(rx_PeerOf(rx_ConnectionOf(call
))), creds
->uid
,
91 creds
->group0
, creds
->group1
, PSETPAG
, NFS_EXPORTER
);
92 data
.in
= (caddr_t
) blob
;
93 data
.in_size
= sizeof(blob
);
94 data
.out
= (caddr_t
) blob
;
95 data
.out_size
= sizeof(blob
);
96 /* force local pioctl call */
97 error
= lpioctl(0, _VICEIOCTL(PSetClientContext
), &data
, 1);
99 if (errno
== PSETPAG
) {
100 *newpag
= blob
[0]; /* new pag value */
102 *errornumber
= errno
;
108 /* Implements the remote pioctl(2) call */
110 SRMTSYS_Pioctl(struct rx_call
*call
, clientcred
*creds
, char *path
,
111 afs_int32 cmd
, afs_int32 follow
, rmtbulk
*InData
,
112 rmtbulk
*OutData
, afs_int32
*errornumber
)
115 struct ViceIoctl data
;
117 afs_uint32 blob
[PIOCTL_HEADER
];
120 SETCLIENTCONTEXT(blob
, rx_HostOf(rx_PeerOf(rx_ConnectionOf(call
))), creds
->uid
,
121 creds
->group0
, creds
->group1
, cmd
, NFS_EXPORTER
);
122 data
.in
= malloc(InData
->rmtbulk_len
+ PIOCTL_HEADER
* sizeof(afs_int32
));
124 return (-1); /* helpless here */
125 if (!strcmp(path
, NIL_PATHP
))
126 pathp
= (char *)0; /* It meant to be NIL */
127 memcpy(data
.in
, blob
, sizeof(blob
));
128 inparam_conversion(cmd
, InData
->rmtbulk_val
, 1);
129 memcpy(data
.in
+ sizeof(blob
), InData
->rmtbulk_val
, InData
->rmtbulk_len
);
130 data
.in_size
= InData
->rmtbulk_len
+ PIOCTL_HEADER
* sizeof(afs_int32
);
131 data
.out
= OutData
->rmtbulk_val
;
132 data
.out_size
= OutData
->rmtbulk_len
;
133 /* force local pioctl call */
134 error
= lpioctl(pathp
, _VICEIOCTL(PSetClientContext
), &data
, follow
);
136 *errornumber
= errno
;
138 /* Send the results back in network order */
139 outparam_conversion(cmd
, data
.out
, 0);
142 /* Note that we return success (i.e. 0) even when pioctl fails; that's
143 * because the actual errno is passed back via 'errornumber' and this call
144 * MUST return success error in order to get that OUT params back (YUCK!)
150 rmt_Quit(char *msg
, ...)
155 vfprintf(stderr
, msg
, ap
);