* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
* This code is derived from software donated to Berkeley by
* %sccs.include.redist.c%
* @(#)activate.c 8.2 (Berkeley) %G%
* $Id: activate.c,v 1.2 1992/05/27 07:09:27 jsp Exp jsp $
* Scan the providers list and call the
static int activate_argv(pcr
, key
, v
, so
, fdp
)
for (pr
= providers
; pr
->pr_match
; pr
++)
if (strcmp(v
[0], pr
->pr_match
) == 0)
return ((*pr
->pr_func
)(pcr
, key
, v
, so
, fdp
));
static int get_request(so
, pcr
, key
, klen
)
iov
[0].iov_base
= (caddr_t
) pcr
;
iov
[0].iov_len
= sizeof(*pcr
);
bzero((char *) &msg
, sizeof(msg
));
n
= recvmsg(so
, &msg
, 0);
static void send_reply(so
, fd
, error
)
* Line up error code. Don't worry about byte ordering
* because we must be sending to the local machine.
iov
.iov_base
= (caddr_t
) &error
;
iov
.iov_len
= sizeof(error
);
bzero((char *) &msg
, sizeof(msg
));
* If there is a file descriptor to send then
* construct a suitable rights control message.
ctl
.cmsg
.cmsg_len
= sizeof(ctl
);
ctl
.cmsg
.cmsg_level
= SOL_SOCKET
;
ctl
.cmsg
.cmsg_type
= SCM_RIGHTS
;
msg
.msg_control
= (caddr_t
) &ctl
;
msg
.msg_controllen
= ctl
.cmsg
.cmsg_len
;
if ((n
= sendmsg(so
, &msg
, MSG_EOR
)) < 0)
syslog(LOG_ERR
, "send: %s", strerror(errno
));
fprintf(stderr
, "sent %d bytes\n", n
);
syslog(LOG_ERR
, "shutdown: %s", strerror(errno
));
* Throw away the open file descriptor
struct portal_cred pcred
;
* Read the key from the socket
error
= get_request(so
, &pcred
, key
, sizeof(key
));
syslog(LOG_ERR
, "activate: recvmsg: %s", strerror(error
));
fprintf(stderr
, "lookup key %s\n", key
);
* Find a match in the configuration file
* If a match existed, then find an appropriate portal
* otherwise simply return ENOENT.
error
= activate_argv(&pcred
, key
, v
, so
, &fd
);
send_reply(so
, fd
, error
);