6324 Add an `ndp' tool for manipulating the neighbors table
[illumos-gate.git] / usr / src / man / man1m / saf.1m
bloba113e43576e20bcf162135f34414e6357870620a
1 '\" te
2 .\"  Copyright (c) 1998, Sun Microsystems, Inc. All Rights Reserved
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH SAF 1M "Jul 30, 1998"
7 .SH NAME
8 saf \- Service Access Facility
9 .SH DESCRIPTION
10 .sp
11 .LP
12 The \fBSAF\fR generalizes the procedures for service access so that login
13 access on the local system and network access to local services are managed in
14 similar ways. Under the \fBSAF,\fR systems may access services using a variety
15 of port monitors, including ttymon, the listener, and port monitors written
16 expressly for a user's application. The manner in which a port monitor observes
17 and manages access ports is specific to the port monitor and not to any
18 component of the \fBSAF.\fR Users may therefore extend their systems by
19 developing and installing their own port monitors. One of the important
20 features of the \fBSAF\fR is that it can be extended in this way by users.
21 .sp
22 .LP
23 Relative to the \fBSAF,\fR a service is a process that is started. There are no
24 restrictions on the functions a service may provide. The \fBSAF\fR consists of
25 a controlling process, the service access controller (SAC), and two
26 administrative levels corresponding to two levels in the supporting directory
27 structure. The top administrative level is concerned with port monitor
28 administration, the lower level with service administration. The \fBSAC\fR is
29 documented in the \fBsac\fR(1M) man page. The administrative levels and
30 associated utilities are documented in the \fISystem Administration Guide -
31 Volume II\fR. The requirements for writing port monitors and the functions a
32 port monitor must perform to run under the \fBSAF\fR and the \fBSAC\fR are
33 documented here.
34 .SS "Port Monitors"
35 .sp
36 .LP
37 A port monitor is a process that is responsible for monitoring a set of
38 homogeneous, incoming ports on a machine. A port monitor's major purpose is to
39 detect incoming service requests and to dispatch them appropriately.
40 .sp
41 .LP
42 A port is an externally seen access point on a system. A port may be an address
43 on a network (TSAP or PSAP), a hardwired terminal line, an incoming phone line,
44 etc. The definition of what constitutes a port is strictly a function of the
45 port monitor itself.
46 .sp
47 .LP
48 A port monitor performs certain basic functions. Some of these are required to
49 conform to the \fBSAF;\fR others may be specified by the requirements and
50 design of the port monitor itself. Port monitors have two main functions:
51 managing ports and monitoring ports for indications of activity.
52 .sp
53 .ne 2
54 .na
55 \fBPort Management\fR
56 .ad
57 .RS 23n
58 The first function of a port monitor is to manage a port. The actual details of
59 how a port is managed are defined by the person who defines the port monitor. A
60 port monitor is not restricted to handling a single port; it may handle
61 multiple ports simultaneously.
62 .sp
63 Some examples of port management are setting the line speed on incoming phone
64 connections, binding an appropriate network address, reinitializing the port
65 when the service terminates, outputting a prompt, etc.
66 .RE
68 .sp
69 .ne 2
70 .na
71 \fBActivity Monitoring\fR
72 .ad
73 .RS 23n
74 The second function of a port monitor is to monitor the port or ports for which
75 it is responsible for indications of activity. Two types of activity may be
76 detected.
77 .sp
78 The first is an indication to the port monitor to take some port
79 monitor-specific action. Pressing the break key to indicate that the line speed
80 should be cycled is an example of a port monitor activity. Not all port
81 monitors need to recognize and respond to the same indications. The indication
82 used to attract the attention of the port monitor is defined by the person who
83 defines the port monitor.
84 .sp
85 The second is an incoming service request. When a service request is received,
86 a port monitor must be able to determine which service is being requested from
87 the port on which the request is received. The same service may be available on
88 more than one port.
89 .RE
91 .SS "Other Port Monitor Functions"
92 .sp
93 .LP
94 This section briefly describes other port monitor functions.
95 .sp
96 .ne 2
97 .na
98 \fBRestricting Access to the System\fR
99 .ad
100 .sp .6
101 .RS 4n
102 A port monitor must be able to restrict access to the system without disturbing
103 services that are still running. In order to do this, a port monitor must
104 maintain two internal states: enabled and disabled. The port monitor starts in
105 the state indicated by the \fBISTATE\fR environment variable provided by the
106 \fBsac.\fR See sac(1M) for details. Enabling or disabling a port monitor
107 affects all ports for which the port monitor is responsible. If a port monitor
108 is responsible for a single port, only that port will be affected. If a port
109 monitor is responsible for multiple ports, the entire collection of ports will
110 be affected. Enabling or disabling a port monitor is a dynamic operation: it
111 causes the port monitor to change its internal state. The effect does not
112 persist across new invocations of the port monitor. Enabling or disabling an
113 individual port, however, is a static operation: it causes a change to an
114 administrative file. The effect of this change will persist across new
115 invocations of the port monitor.
119 .ne 2
121 \fBCreating \fButmpx\fR Entries\fR
123 .sp .6
124 .RS 4n
125 Port monitors are responsible for creating \fButmpx\fR entries with the type
126 field set to USER_PROCESS for services they start. If this action has been
127 specified, by using the \fB-fu\fR option in the \fBpmadm\fR command line that
128 added the service, these \fButmpx\fR entries may in turn be modified by the
129 service. When the service terminates, the \fButmpx\fR entry must be set to
130 DEAD_PROCESS.
134 .ne 2
136 \fBPort Monitor Process IDs and Lock Files\fR
138 .sp .6
139 .RS 4n
140 When a port monitor starts, it writes its process id into a file named
141 \fB_pid\fR in the current directory and places an advisory lock on the file.
145 .ne 2
147 \fBChanging the Service Environment: Running\fR
149 .sp .6
150 .RS 4n
151 \fBdoconfig\fR(3NSL) Before invoking the service designated in the port monitor
152 administrative file, \fB_pmtab\fR, a port monitor must arrange for the
153 per-service configuration script to be run, if one exists, by calling the
154 library function \fBdoconfig\fR(3NSL). Because the per-service configuration
155 script may specify the execution of restricted commands, as well as for other
156 security reasons, port monitors are invoked with root permissions. The details
157 of how services are invoked are specified by the person who defines the port
158 monitor.
162 .ne 2
164 \fBTerminating a Port Monitor\fR
166 .sp .6
167 .RS 4n
168 A port monitor must terminate itself gracefully on receipt of the signal
169 \fBSIGTERM.\fR The termination sequence is the following:
170 .RS +4
173 The port monitor enters the stopping state; no further service requests are
174 accepted.
176 .RS +4
179 Any attempt to re-enable the port monitor will be ignored.
181 .RS +4
184 The port monitor yields control of all ports for which it is responsible. It
185 must be possible for a new instantiation of the port monitor to start correctly
186 while a previous instantiation is stopping.
188 .RS +4
191 The advisory lock on the process id file is released. Once this lock is
192 released, the contents of the process id file are undefined and a new
193 invocation of the port monitor may be started.
197 .SS "SAF Files"
200 This section briefly covers the files used by the \fBSAF.\fR
202 .ne 2
204 \fBThe Port Monitor Administrative File\fR
206 .sp .6
207 .RS 4n
208 A port monitor's current directory contains an administrative file named
209 \fB_pmtab\fR; \fB_pmtab\fR is maintained by the \fBpmadm\fR command in
210 conjunction with a port monitor-specific administrative command.
212 The port monitor administrative command for a listen port monitor is
213 \fBnlsadmin\fR(1M); the port monitor administrative command for ttymon is
214 \fBttyadm\fR(1M). Any port monitor written by a user must be provided with an
215 administrative command specific to that port monitor to perform similar
216 functions.
220 .ne 2
222 \fBPer-Service Configuration Files\fR
224 .sp .6
225 .RS 4n
226 A port monitor's current directory also contains the per-service configuration
227 scripts, if they exist. The names of the per-service configuration scripts
228 correspond to the service tags in the \fB_pmtab\fR file.
232 .ne 2
234 \fBPrivate Port Monitor Files\fR
236 .sp .6
237 .RS 4n
238 A port monitor may create private files in the directory
239 \fB/var/saf/\fR\fItag\fR, where \fItag\fR is the name of the port monitor.
240 Examples of private files are log files or temporary files.
243 .SS "The SAC/Port Monitor Interface"
246 The \fBSAC\fR creates two environment variables for each port monitor it
247 starts:\fBPMTAG\fR and \fBISTATE\fR.
250 This variable is set to a unique port monitor tag by the \fBSAC.\fR The port
251 monitor uses this tag to identify itself in response to \fBsac\fR messages.
252 \fBISTATE\fR is used to indicate to the port monitor what its initial internal
253 state should be. \fBISTATE\fR is set to "enabled" or "disabled" to indicate
254 that the port monitor is to start in the enabled or disabled state
255 respectively.
258 The \fBSAC\fR performs a periodic sanity poll of the port monitors. The
259 \fBSAC\fR communicates with port monitors through FIFOs. A port monitor should
260 open _pmpipe, in the current directory, to receive messages from the \fBSAC\fR
261 and \fB\&../_sacpipe\fR to send return messages to the \fBSAC.\fR
262 .SS "Message Formats"
265 This section describes the messages that may be sent from the \fBSAC\fR to a
266 port monitor (\fBsac\fR messages), and from a port monitor to the \fBSAC\fR
267 (port monitor messages). These messages are sent through FIFOs and are in the
268 form of C structures.
270 .ne 2
272 \fB\fBsac\fR Messages\fR
274 .RS 16n
275 The format of messages from the \fBSAC\fR is defined by the structure
276 \fBsacmsg\fR:
278 .in +2
280 struct sacmsg
282         int sc_size; /* size of optional data portion */
283         char sc_type; /* type of message */
286 .in -2
293 The \fBSAC\fR may send four types of messages to port monitors. The type of
294 message is indicated by setting the \fBsc_type\fR field of the \fBsacmsg\fR
295 structure to one of the following:
297 .ne 2
299 \fBSC_STATUS\|\fR
301 .RS 15n
302 status request
306 .ne 2
308 \fBSC_ENABLE\|\fR
310 .RS 15n
311 enable message
315 .ne 2
317 \fBSC_DISABLE\fR
319 .RS 15n
320 disable message
324 .ne 2
326 \fBSC_READDB\|\fR
328 .RS 15n
329 message indicating that the port monitor's _pmtab file should be read
334 The \fBsc_size\fR field indicates the size of the optional data part of the
335 message. See "Message Classes." For Solaris, \fBsc_size\fR should always be set
336 to 0. A port monitor must respond to every message sent by the \fBsac.\fR
337 .SS "Port Monitor Messages"
340 The format of messages from a port monitor to the \fBSAC\fR is defined by the
341 structure \fBpmmsg\fR:
343 .in +2
345 struct pmmsg {
346         char pm_type;                /* type of message */
347         unchar_t pm_state;           /* current state of port monitor */
348         char pm_maxclass;            /* maximum message class this port
349                                                monitor understands */
350         char pm_tag[PMTAGSIZE + 1];  /* port monitor's tag */
351         int pm_size;                 /* size of optional data portion */
354 .in -2
358 Port monitors may send two types of messages to the \fBSAC.\fR The type of
359 message is indicated by setting the \fBpm_type\fR field of the \fBpmmsg\fR
360 structure to one of the following:
362 .ne 2
364 \fBPM_STATUS\fR
366 .RS 14n
367 state information
371 .ne 2
373 \fBPM_UNKNOWN\fR
375 .RS 14n
376 negative acknowledgment
381 For both types of messages, the \fBpm_tag\fR field is set to the port monitor's
382 tag and the \fBpm_state\fR field is set to the port monitor's current state.
383 Valid states are:
385 .ne 2
387 \fBPM_STARTING\fR
389 .RS 15n
390 starting
394 .ne 2
396 \fBPM_ENABLED\fR
398 .RS 15n
399 enabled
403 .ne 2
405 \fBPM_DISABLED\fR
407 .RS 15n
408 disabled
412 .ne 2
414 \fBPM_STOPPING\fR
416 .RS 15n
417 stopping
422 The current state reflects any changes caused by the last message from the
423 \fBSAC.\fR The status message is the normal return message. The negative
424 acknowledgment should be sent only when the message received is not understood.
425 \fBpm_size\fR indicates the size of the optional data part of the message.
426 \fBpm_maxclass\fR is used to specify a message class. Both are discussed under
427 "Message Classes." In Solaris, always set \fBpm_maxclass\fR to 1 and
428 \fBsc_size\fR to 0. Port monitors may never initiate messages; they may only
429 respond to messages that they receive.
430 .SS "Message Classes"
433 The concept of message class has been included to accommodate possible
434 \fBSAF\fR extensions. The messages described above are all class 1 messages.
435 None of these messages contains a variable data portion; all pertinent
436 information is contained in the message header. If new messages are added to
437 the protocol, they will be defined as new message classes (for example, class
438 2). The first message the \fBSAC\fR sends to a port monitor will always be a
439 class 1 message. Since all port monitors, by definition, understand class 1
440 messages, the first message the \fBSAC\fR sends is guaranteed to be understood.
441 In its response to the \fBSAC,\fR the port monitor sets the \fBpm_maxclass\fR
442 field to the maximum message class number for that port monitor. The \fBSAC\fR
443 will not send messages to a port monitor from a class with a larger number than
444 the value of \fBpm_maxclass\fR. Requests that require messages of a higher
445 class than the port monitor can understand will fail. For Solaris, always set
446 \fBpm_maxclass\fR to 1.
449 For any given port monitor, messages of class \fBpm_maxclass\fR and messages of
450 all classes with values lower than \fBpm_maxclass\fR are valid. Thus, if the
451 \fBpm_maxclass\fR field is set to 3, the port monitor understands messages of
452 classes 1, 2, and 3. Port monitors may not generate messages; they may only
453 respond to messages. A port monitor's response must be of the same class as the
454 originating message. Since only the \fBSAC\fR can generate messages, this
455 protocol will function even if the port monitor is capable of dealing with
456 messages of a higher class than the \fBSAC\fR can generate. \fBpm_size\fR (an
457 element of the pmmsg structure) and \fBsc_size\fR (an element of the
458 \fBsacmsg\fR structure) indicate the size of the optional data part of the
459 message. The format of this part of the message is undefined. Its definition is
460 inherent in the type of message. For Solaris, always set both \fBsc_size\fR and
461 \fBpm_size\fR to \fB0\fR.
462 .SS "Administrative Interface"
465 This section discusses the port monitor administrative files available under
466 the \fBSAC.\fR
467 .SS "The SAC Administrative File _sactab"
470 The service access controller's administrative file contains information about
471 all the port monitors for which the \fBSAC\fR is responsible. This file exists
472 on the delivered system. Initially, it is empty except for a single comment
473 line that contains the version number of the \fBSAC.\fR Port monitors are added
474 to the system by making entries in the \fBSAC's\fR administrative file. These
475 entries should be made using the administrative command \fBsacadm\fR(1M) with a
476 \fB-a\fR option. \fBsacadm\fR(1M) is also used to remove entries from the
477 \fBSAC's\fR administrative file. Each entry in the \fBSAC's\fR administrative
478 file contains the following information.
480 .ne 2
482 \fB\fBPMTAG\fR\fR
484 .RS 11n
485 A unique tag that identifies a particular port monitor. The system
486 administrator is responsible for naming a port monitor. This tag is then used
487 by the \fBSAC\fR to identify the port  monitor for all administrative purposes.
488 \fBPMTAG\fR may consist of up to 14 alphanumeric characters.
492 .ne 2
494 \fB\fBPMTYPE\fR\fR
496 .RS 11n
497 The type of the port monitor. In addition to its unique tag, each port monitor
498 has a type designator. The type designator identifies a group of port monitors
499 that are different invocations of the same entity. ttymon and listen are
500 examples of valid port monitor types. The type designator is used to facilitate
501 the administration of groups of related port monitors. Without a type
502 designator, the system administrator has no way of knowing which port monitor
503 tags correspond to port monitors of the same type. \fBPMTYPE\fR may consist of
504 up to 14 alphanumeric characters.
508 .ne 2
510 \fB\fBFLGS\fR\fR
512 .RS 11n
513 The flags that are currently defined are:
515 .ne 2
517 \fBd\fR
519 .RS 5n
520 When started, do not enable the port monitor.
524 .ne 2
526 \fBx\fR
528 .RS 5n
529 Do not start the port monitor.
532 If no flag is specified, the default action is taken. By default a port monitor
533 is started and enabled.
537 .ne 2
539 \fB\fBRCNT\fR\fR
541 .RS 11n
542 The number of times a port monitor may fail before being placed in a failed
543 state. Once a port monitor enters the failed state, the \fBSAC\fR will not try
544 to restart it. If a count is not specified when the entry is created, this
545 field is set to 0. A restart count of 0 indicates that the port monitor is not
546 to be restarted when it fails.
550 .ne 2
552 \fB\fBCOMMAND\fR\fR
554 .RS 11n
555 A string representing the command that will start the port monitor. The first
556 component of the string, the command itself, must be a full path name.
559 .SS "The Port Monitor Administrative File _pmtab"
562 Each port monitor will have two directories for its exclusive use. The current
563 directory will contain files defined by the \fBSAF\fR (\fB_pmtab\fR,
564 \fB_pid\fR) and the per-service configuration scripts, if they exist. The
565 directory \fB/var/saf/\fR\fIpmtag,\fR where \fIpmtag\fR is the tag of the port
566 monitor, is available for the port monitor's private files. Each port monitor
567 has its own administrative file. The \fBpmadm\fR(1M) command should be used to
568 add, remove, or modify service entries in this file. Each time a change is made
569 using \fBpmadm\fR(1M), the corresponding port monitor rereads its
570 administrative file. Each entry in a port monitor's administrative file defines
571 how the port monitor treats a specific port and what service is to be invoked
572 on that port. Some fields must be present for all types of port monitors. Each
573 entry must include a service tag to identify the service uniquely and an
574 identity to be assigned to the service when it is started (for example, root).
577 The combination of a service tag and a port monitor tag uniquely define an
578 instance of a service. The same service tag may be used to identify a service
579 under a different port monitor. The record must also contain port monitor
580 specific data (for example, for a ttymon port monitor, this will include the
581 prompt string which is meaningful to ttymon). Each type of port monitor must
582 provide a command that takes the necessary port monitor-specific data as
583 arguments and outputs these data in a form suitable for storage in the file.
584 The \fBttyadm\fR(1M) command does this for ttymon and \fBnlsadmin\fR(1M) does
585 it for listen. For a user-defined port monitor, a similar administrative
586 command must also be supplied. Each service entry in the port monitor
587 administrative file must have the following format and contain the information
588 listed below:
590 .in +2
592 svctag:flgs:id:reserved:reserved:reserved:pmspecific# comment
594 .in -2
599 \fBSVCTAG\fR is a unique tag that identifies a service. This tag is unique only
600 for the port monitor through which the service is available. Other port
601 monitors may offer the same or other services with the same tag. A service
602 requires both a port monitor tag and a service tag to identify it uniquely.
603 \fBSVCTAG\fR may consist of up to 14 alphanumeric characters. The service
604 entries are defined as:
606 .ne 2
608 \fB\fBFLGS\fR\fR
610 .RS 14n
611 Flags with the following meanings may currently be included in this field:
613 .ne 2
615 \fBx\fR
617 .RS 5n
618 Do not enable this port. By default the port is enabled.
622 .ne 2
624 \fBu\fR
626 .RS 5n
627 Create a utmpx entry for this service. By default no utmpx entry is created
628 for the service.
634 .ne 2
636 \fB\fBID\fR\fR
638 .RS 14n
639 The identity under which the service is to be started. The identity has the
640 form of a login name as it appears in \fB/etc/passwd\fR.
644 .ne 2
646 \fB\fBPMSPECIFIC\fR\fR
648 .RS 14n
649 Examples of port monitor information are addresses, the name of a process to
650 execute, or the name of a STREAMS-based pipe to pass a connection through. This
651 information will vary to meet the needs of each different type of port monitor.
655 .ne 2
657 \fB\fBCOMMENT\fR\fR
659 .RS 14n
660 A comment associated with the service entry. Port monitors may ignore the
661 \fIu\fR flag if creating a utmpx entry for the service is not appropriate to
662 the manner in which the service is to be invoked. Some services may not start
663 properly unless utmpx entries have been created for them (for example, login).
664 Each port monitor administrative file must contain one special comment of the
665 form:
667 # VERSION=value
669 where \fIvalue\fR is an integer that represents the port monitor's version
670 number. The version number defines the format of the port monitor
671 administrative file. This comment line is created automatically when a port
672 monitor is added to the system. It appears on a line by itself, before the
673 service entries.
676 .SS "Monitor-Specific Administrative Command"
679 Previously, two pieces of information included in the \fB_pmtab\fR file were
680 described: the port monitor's version number and the port monitor part of the
681 service entries in the port monitor's \fB_pmtab\fR file. When a new port
682 monitor is added, the version number must be known so that the \fB_pmtab\fR
683 file can be correctly initialized. When a new service is added, the port
684 monitor part of the \fB_pmtab\fR entry must be formatted correctly. Each port
685 monitor must have an administrative command to perform these two tasks. The
686 person who defines the port monitor must also define such an administrative
687 command and its input options. When the command is invoked with these options,
688 the information required for the port monitor part of the service entry must be
689 correctly formatted for inclusion in the port monitor's \fB_pmtab\fR file and
690 must be written to the standard output. To request the version number the
691 command must be invoked with a \fB-V\fR option; when it is invoked in this way,
692 the port monitor's current version number must be written to the standard
693 output. If the command fails for any reason during the execution of either of
694 these tasks, no data should be written to standard output.
695 .SS "The Port Monitor/Service Interface"
698 The interface between a port monitor and a service is determined solely by the
699 service. Two mechanisms for invoking a service are presented here as examples.
701 .ne 2
703 \fBNew Service Invocations\fR
705 .sp .6
706 .RS 4n
707 The first interface is for services that are started anew with each request.
708 This interface requires the port monitor to first \fBfork\fR(2) a child
709 process. The child will eventually become the designated service by performing
710 an \fBexec\fR(1). Before the \fBexec\fR(1) happens, the port monitor may take
711 some port monitor-specific action; however, one action that must occur is the
712 interpretation of the per-service configuration script, if one is present. This
713 is done by calling the library routine \fBdoconfig\fR(3NSL).
717 .ne 2
719 \fBStanding Service Invocations\fR
721 .sp .6
722 .RS 4n
723 The second interface is for invocations of services that are actively running.
724 To use this interface, a service must have one end of a stream pipe open and be
725 prepared to receive connections through it.
728 .SS "Port Monitor Requirements"
731 To implement a port monitor, several generic requirements must be met. This
732 section summarizes these requirements. In addition to the port monitor itself,
733 an administrative command must be supplied.
735 .ne 2
737 \fBInitial Environment\fR
739 .RS 23n
740 When a port monitor is started, it expects an initial execution environment in
741 which:
742 .RS +4
744 .ie t \(bu
745 .el o
746 It has no file descriptors open
748 .RS +4
750 .ie t \(bu
751 .el o
752 It cannot be a process group leader
754 .RS +4
756 .ie t \(bu
757 .el o
758 It has an entry in \fB/etc/utmpx\fR of type LOGIN_PROCESS
760 .RS +4
762 .ie t \(bu
763 .el o
764 An environment variable, \fBISTATE,\fR is set to "enabled" or "disabled" to
765 indicate the port monitor's correct initial state
767 .RS +4
769 .ie t \(bu
770 .el o
771 An environment variable, \fBPMTAG,\fR is set to the port monitor's assigned tag
773 .RS +4
775 .ie t \(bu
776 .el o
777 The directory that contains the port monitor's administrative files is its
778 current directory
780 .RS +4
782 .ie t \(bu
783 .el o
784 pThe port monitor is able to create private files in the directory
785 \fB/var/saf/\fR\fItag\fR, where \fItag\fR is the port monitor's tag
787 .RS +4
789 .ie t \(bu
790 .el o
791 The port monitor is running with user id 0 (root)
796 .ne 2
798 \fBImportant Files\fR
800 .RS 23n
801 Relative to its current directory, the following key files exist for a port
802 monitor.
804 .ne 2
806 \fB\fB_config\fR\fR
808 .RS 17n
809 The port monitor's configuration script. The port monitor configuration script
810 is run by the SAC. The \fBSAC\fR is started by \fBinit\fR(1M) as a result of an
811 entry in \fB/etc/inittab\fR that calls \fBsac\fR(1M).
815 .ne 2
817 \fB\fB_pid\fR\fR
819 .RS 17n
820 The file into which the port monitor writes its process id.
824 .ne 2
826 \fB\fB_pmtab\fR\fR
828 .RS 17n
829 The port monitor's administrative file. This file contains information about
830 the ports and services for which the port monitor is responsible.
834 .ne 2
836 \fB\fB_pmpipe\fR\fR
838 .RS 17n
839 The\fB FIFO\fR through which the port monitor will receive messages from the
840 \fBSAC.\fR
844 .ne 2
846 \fB\fBsvctag\fR\fR
848 .RS 17n
849 The per-service configuration script for the service with the tag \fIsvctag\fR.
853 .ne 2
855 \fB\fB\&../_sacpipe\fR\fR
857 .RS 17n
858 The \fBFIFO\fR through which the port monitor will send messages to
859 \fBsac\fR(1M).
864 .SS "Port Monitor Responsibilities"
867 A port monitor is responsible for performing the following tasks in addition to
868 its port monitor function:
869 .RS +4
871 .ie t \(bu
872 .el o
873 Write its process id into the file \fB_pid\fR and place an advisory lock on the
874 file
876 .RS +4
878 .ie t \(bu
879 .el o
880 Terminate gracefully on receipt of the signal SIGTERM
882 .RS +4
884 .ie t \(bu
885 .el o
886 Follow the protocol for message exchange with the \fBSAC\fR
890 A port monitor must perform the following tasks during service invocation:
891 .RS +4
893 .ie t \(bu
894 .el o
895 Create a \fButmpx\fR entry if the requested service has the \fBu\fR flag set in
896 \fB_pmtab\fR
898 .RS +4
900 .ie t \(bu
901 .el o
902 Port monitors may ignore this flag if creating a \fButmpx\fR entry for the
903 service does not make sense because of the manner in which the service is to be
904 invoked. On the other hand, some services may not start properly unless utmpx
905 entries have been created for them.
907 .RS +4
909 .ie t \(bu
910 .el o
911 Interpret the per-service configuration script for the requested service, if it
912 exists, by calling the \fBdoconfig\fR(3NSL) library routine
914 .SS "Configuration Files and Scripts"
917 The library routine \fBdoconfig\fR(3NSL), defined in \fBlibnsl.so\fR,
918 interprets the configuration scripts contained in the files
919 \fB/etc/saf/_sysconfig\fR (the per-system configuration file), and
920 \fB/etc/saf/\fR\fIpmtag\fR\fB/_config\fR (per-port monitor configuration
921 files); and in \fB/etc/saf/\fR\fIpmtag\fR\fB/svctag\fR (per-service
922 configuration files). Its syntax is:
924 .in +2
926 #include <sac.h>
927         int doconfig (int fd, char *script, long rflag);
929 .in -2
934 \fBscript\fR is the name of the configuration script; \fIfd\fR is a file
935 descriptor that designates the stream to which stream manipulation operations
936 are to be applied; \fIrflag\fR is a bitmask that indicates the mode in which
937 script is to be interpreted. \fIrflag\fR may take two values, \fBNORUN\fR and
938 \fBNOASSIGN,\fR which may be or'd. If \fIrflag\fR is zero, all commands in the
939 configuration script are eligible to be interpreted. If \fIrflag\fR has the
940 \fBNOASSIGN\fR bit set, the assign command is considered illegal and will
941 generate an error return. If \fIrflag\fR has the \fBNORUN\fR bit set, the run
942 and runwait commands are considered illegal and will generate error returns. If
943 a command in the script fails, the interpretation of the script ceases at that
944 point and a positive integer is returned; this number indicates which line in
945 the script failed. If a system error occurs, a value of \(mi1 is returned. If a
946 script fails, the process whose environment was being established should not be
947 started. In the example, \fBdoconfig\fR(3NSL) is used to interpret a
948 per-service configuration script.
950 .in +2
952 \|.\|.\|.
953                 if ((i = doconfig (fd, svctag, 0)) != 0){
954                 error ("doconfig failed on line %d of script %s",i,svctag);
955         }
957 .in -2
961 .ne 2
963 \fBThe Per-System Configuration File\fR
965 .sp .6
966 .RS 4n
967 The per-system configuration file, \fB/etc/saf/_sysconfig\fR, is delivered
968 empty. It may be used to customize the environment for all services on the
969 system by writing a command script in the interpreted language described in
970 this chapter and on the \fBdoconfig\fR(3NSL) manpage. When the \fBSAC\fR is
971 started, it calls the \fBdoconfig\fR(3NSL) function to interpret the per-system
972 configuration script. The \fBSAC\fR is started when the system enters multiuser
973 mode.
977 .ne 2
979 \fBPer-Port Monitor Configuration Files\fR
981 .sp .6
982 .RS 4n
983 Per-port monitor configuration scripts
984 (\fB/etc/saf/\fR\fIpmtag\fR\fB/_config)\fR are optional. They allow the user to
985 customize the environment for any given port monitor and for the services that
986 are available through the ports for which that port monitor is responsible.
987 Per-port monitor configuration scripts are written in the same language used
988 for per-system configuration scripts. The per-port monitor configuration script
989 is interpreted when the port monitor is started. The port monitor is started by
990 the \fBSAC\fR after the \fBSAC\fR has itself been started and after it has run
991 its own configuration script, \fB/etc/saf/_sysconfig\fR. The per-port monitor
992 configuration script may override defaults provided by the per-system
993 configuration script.
997 .ne 2
999 \fBPer-Service Configuration Files\fR
1001 .sp .6
1002 .RS 4n
1003 Per-service configuration files allow the user to customize the environment for
1004 a specific service. For example, a service may require special privileges that
1005 are not available to the general user. Using the language described in the
1006 \fBdoconfig\fR(3NSL) manpage, you can write a script that will grant or limit
1007 such special privileges to a particular service offered through a particular
1008 port monitor. The per-service configuration may override defaults provided by
1009 higher-level configuration scripts. For example, the per-service configuration
1010 script may specify a set of STREAMS modules other than the default set.
1013 .SS "The Configuration Language"
1016 The language in which configuration scripts are written consists of a sequence
1017 of commands, each of which is interpreted separately. The following reserved
1018 keywords are defined: \fBassign\fR, \fBpush\fR, \fBpop\fR, \fBrunwait\fR, and
1019 \fBrun\fR. The comment character is #. Blank lines are not significant. No line
1020 in a command script may exceed 1024 characters.
1022 .ne 2
1024 \fB\fBassign\fR \fIvariable\fR=\fIvalue\fR\fR
1026 .sp .6
1027 .RS 4n
1028 Used to define environment variables; \fIvariable\fR is the name of the
1029 environment variable and \fIvalue\fR is the value to be assigned to it. The
1030 value assigned must be a string constant; no form of parameter substitution is
1031 available. \fIvalue\fR may be quoted. The quoting rules are those used by the
1032 shell for defining environment variables. \fBassign\fR will fail if space
1033 cannot be allocated for the new variable or if any part of the specification is
1034 invalid.
1038 .ne 2
1040 \fB\fBpush\fR \fImodule1\fR[,\fImodule2, module3\fR, . . .]\fR
1042 .sp .6
1043 .RS 4n
1044 Used to push STREAMS modules onto the stream designated by \fBfd\fR;
1045 \fImodule1\fR is the name of the first module to be pushed, \fImodule2\fR is
1046 the name of the second module to be pushed, and so on. The command will fail if
1047 any of the named modules cannot be pushed. If a module cannot be pushed, the
1048 subsequent modules on the same command line will be ignored and modules that
1049 have already been pushed will be popped.
1053 .ne 2
1055 \fB\fBpop\fR [\fImodule\fR]\fR
1057 .sp .6
1058 .RS 4n
1059 Used to pop STREAMS modules off the designated stream. If \fBpop\fR is invoked
1060 with no arguments, the top module on the stream is popped. If an argument is
1061 given, modules will be popped one at a time until the named module is at the
1062 top of the stream. If the named module is not on the designated stream, the
1063 stream is left as it was and the command fails. If \fImodule\fR is the special
1064 keyword \fBALL\fR, then all modules on the stream will be popped. Only modules
1065 above the topmost driver are affected.
1069 .ne 2
1071 \fB\fBrunwait\fR \fBcommand\fR\fR
1073 .sp .6
1074 .RS 4n
1075 The \fBrunwait\fR command runs a command and waits for it to complete;
1076 \fBcommand\fR is the path name of the command to be run. The command is run
1077 with \fB/bin/sh\fR \fB-c\fR prepended to it; shell scripts may thus be executed
1078 from configuration scripts. The \fBrunwait\fR command will fail if command
1079 cannot be found or cannot be executed, or if \fBcommand\fR exits with a nonzero
1080 status.
1084 .ne 2
1086 \fB\fBrun\fR \fBcommand\fR\fR
1088 .sp .6
1089 .RS 4n
1090 The \fBrun\fR command is identical to \fBrunwait\fR except that it does not
1091 wait for command to complete; \fBcommand\fR is the path name of the command to
1092 be run.  \fBrun\fR will not fail unless it is unable to create achild process
1093 to execute the command. Although they are syntactically indistinguishable, some
1094 of the commands available to \fBrun\fR and \fBrunwait\fR are interpreter
1095 built-in commands. Interpreter built-ins are used when it is necessary to alter
1096 the state of a process within the context of that process. The \fBdoconfig\fR
1097 interpreter built-in commands are similar to the shell special commands and,
1098 like these, they do not spawn another process for execution. See the
1099 \fBsh\fR(1) man page. The initial set of built-in commands is: \fBcd\fR,
1100 \fBulimit\fR, \fBumask\fR.
1103 .SS "Sample Port Monitor Code"
1106 This example shows an example of a "null" port monitor that simply responds to
1107 messages from the \fBSAC.\fR
1109 .in +2
1111 ># include <stdlib.h>
1112 # include <stdio.h>
1113 # include <unistd.h>
1114 # include <fcntl.h>
1115 # include <signal.h>
1116 # include <sac.h>
1118 char Scratch[BUFSIZ]; /* scratch buffer */
1119 char Tag[PMTAGSIZE + 1]; /* port monitor's tag */
1120 FILE *Fp; /* file pointer for log file */
1121 FILE *Tfp; /* file pointer for pid file */
1122 char State; /* portmonitor's current state*/
1124 main(argc, argv)
1125         int argc;
1126         char *argv[];
1128         char *istate;
1129         strcpy(Tag, getenv("PMTAG"));
1131  * open up a log file in port monitor's private directory
1132  */
1133         sprintf(Scratch, "/var/saf/%s/log", Tag);
1134         Fp = fopen(Scratch, "a+");
1135         if (Fp == (FILE *)NULL)
1136                 exit(1);
1137         log(Fp, "starting");
1139  * retrieve initial state (either "enabled" or "disabled") and set
1140  * State accordingly
1141  */
1142         istate = getenv("ISTATE");
1143         sprintf(Scratch, "ISTATE is %s", istate);
1144         log(Fp, Scratch);
1145         if (!strcmp(istate, "enabled"))
1146                 State = PM_ENABLED;
1147         else if (!strcmp(istate, "disabled"))
1148                 State = PM_DISABLED;
1149         else {
1150                 log(Fp, "invalid initial state");
1151                 exit(1);
1152         }
1153         sprintf(Scratch, "PMTAG is %s", Tag);
1154         log(Fp, Scratch);
1156  * set up pid file and lock it to indicate that we are active
1157  */
1158         Tfp = fopen("_pid", "w");
1159         if (Tfp == (FILE *)NULL) {
1160                 log(Fp, "couldn't open pid file");
1161                 exit(1);
1162         }
1163         if (lockf(fileno(Tfp), F_TEST, 0) < 0) {
1164                 log(Fp, "pid file already locked");
1165                 exit(1);
1166         }
1168         log(Fp, "locking file");
1169         if (lockf(fileno(Tfp), F_LOCK, 0) < 0) {
1170                 log(Fp, "lock failed");
1171                 exit(1);
1172         }
1173         fprintf(Tfp, "%d", getpid());
1174         fflush(Tfp);
1177  * handle poll messages from the sac ... this function never returns
1178  */
1179         handlepoll();
1180         pause();
1181         fclose(Tfp);
1182         fclose(Fp);
1185 handlepoll()
1187         int pfd; /* file descriptor for incoming pipe */
1188         int sfd; /* file descriptor for outgoing pipe */
1189         struct sacmsg sacmsg; /* incoming message */
1190         struct pmmsg pmmsg; /* outgoing message */
1192  * open pipe for incoming messages from the sac
1193  */
1194         pfd = open("_pmpipe", O_RDONLY|O_NONBLOCK);
1195         if (pfd < 0) {
1196                 log(Fp, "_pmpipe open failed");
1197                 exit(1);
1198         }
1200  * open pipe for outgoing messages to the sac
1201  */
1202         sfd = open("../_sacpipe", O_WRONLY);
1203         if (sfd < 0) {
1204                 log(Fp, "_sacpipe open failed");
1205                 exit(1);
1206         }
1208  * start to build a return message; we only support class 1 messages
1209  */
1210         strcpy(pmmsg.pm_tag, Tag);
1211         pmmsg.pm_size = 0;
1212         pmmsg.pm_maxclass = 1;
1214  * keep responding to messages from the sac
1215  */
1216         for (;;) {
1217                 if (read(pfd, &sacmsg, sizeof(sacmsg)) != sizeof(sacmsg)) {
1218                         log(Fp, "_pmpipe read failed");
1219                         exit(1);
1220                 }
1222  * determine the message type and respond appropriately
1223  */
1224                 switch (sacmsg.sc_type) {
1225                         case SC_STATUS:
1226                                 log(Fp, "Got SC_STATUS message");
1227                                 pmmsg.pm_type = PM_STATUS;
1228                                 pmmsg.pm_state = State;
1229                                 break;
1230                         case SC_ENABLE:
1231                                 /*note internal state change below*/
1232                                 log(Fp, "Got SC_ENABLE message");
1233                                 pmmsg.pm_type = PM_STATUS;
1234                                 State = PM_ENABLED;
1235                                 pmmsg.pm_state = State;
1236                                 break;
1237                         case SC_DISABLE:
1238                                 /*note internal state change below*/
1239                                 log(Fp, "Got SC_DISABLE message");
1240                                 pmmsg.pm_type = PM_STATUS;
1241                                 State = PM_DISABLED;
1242                                 pmmsg.pm_state = State;
1243                                 break;
1244                         case SC_READDB:
1245                                 /*
1246                                  * if this were a fully functional port
1247                                  * monitor it would read _pmtab here
1248                                  * and take appropriate action
1249                                  */
1250                                 log(Fp, "Got SC_READDB message");
1251                                 pmmsg.pm_type = PM_STATUS;
1252                                 pmmsg.pm_state = State;
1253                                 break;
1254                         default:
1255                                 sprintf(Scratch, "Got unknown message <%d>",
1256                                 sacmsg.sc_type);
1257                                 log(Fp, Scratch);
1258                                 pmmsg.pm_type = PM_UNKNOWN;
1259                                 pmmsg.pm_state = State;
1260                                 break;
1261                 }
1263  * send back a response to the poll
1264  * indicating current state
1265  */
1266                 if (write(sfd, &pmmsg, sizeof(pmmsg)) != sizeof(pmmsg))
1267                         log(Fp, "sanity response failed");
1268         }
1271  * general logging function
1272  */
1273 log(fp, msg)
1274         FILE *fp;
1275         char *msg;
1277         fprintf(fp, "%d; %s\en", getpid(), msg);
1278         fflush(fp);
1281 .in -2
1284 .SS "The sac.h Header File"
1287 The following example shows the sac.h header file.
1289 .in +2
1291 /* length in bytes of a utmpx id */
1292 # define IDLEN 4
1293 /* wild character for utmpx ids */
1294 # define SC_WILDC 0xff
1295 /* max len in bytes for port monitor tag */
1296 # define PMTAGSIZE 14
1298  * values for rflag in doconfig()
1299  */
1300 /* don't allow assign operations */
1301 # define NOASSIGN 0x1
1302 /* don't allow run or runwait operations */
1303 # define NORUN 0x2
1305  * message to SAC (header only). This header is forever fixed. The
1306  * size field (pm_size) defines the size of the data portion of the
1307  * message, which follows the header. The form of this optional data
1308  * portion is defined strictly by the message type (pm_type).
1309  */
1310 struct pmmsg {
1311         char pm_type;               /* type of message */
1312         unchar_t pm_state;            /* current state of pm */
1313         char pm_maxclass;           /* max message class this port monitor
1314                                                         understands */
1315         char pm_tag[PMTAGSIZE + 1]; /* pm's tag */
1316         int pm_size;                /* size of opt data portion */
1319  * pm_type values
1320  */
1321 # define PM_STATUS 1 /* status response */
1322 # define PM_UNKNOWN 2 /* unknown message was received */
1324  * pm_state values
1325  */
1327  * Class 1 responses
1328  */
1329 # define PM_STARTING 1   /* monitor in starting state */
1330 # define PM_ENABLED 2    /* monitor in enabled state */
1331 # define PM_DISABLED 3   /* monitor in disabled state */
1332 # define PM_STOPPING 4   /* monitor in stopping state */
1334  * message to port monitor
1335  */
1336 struct sacmsg {
1337         int sc_size;         /* size of optional data portion */
1338         char sc_type;        /* type of message */
1341  * sc_type values
1342  * These represent commands that the SAC sends to a port monitor.
1343  * These commands are divided into "classes" for extensibility. Each
1344  * subsequent "class" is a superset of the previous "classes" plus
1345  * the new commands defined within that "class". The header for all
1346  * commands is identical; however, a command may be defined such that
1347  * an optional data portion may be sent in addition to the header.
1348  * The format of this optional data piece is self-defining based on
1349  * the command. The first message sent by the SAC
1350  * will always be a class 1 message. The port monitor response
1351  * indicates the maximum class that it is able to understand. Another
1352  * note is that port monitors should only respond to a message with
1353  * an equivalent class response (i.e. a class 1 command causes a
1354  * class 1 response).
1355  */
1357  * Class 1 commands (currently, there are only class 1 commands)
1358  */
1359 # define SC_STATUS 1    /* status request *
1360 # define SC_ENABLE 2    /* enable request */
1361 # define SC_DISABLE 3   /* disable request */
1362 # define SC_READDB 4    /* read pmtab request */
1364  * `errno' values for Saferrno, note that Saferrno is used by both
1365  * pmadm and sacadm and these values are shared between them
1366  */
1367 # define E_BADARGS 1   /* bad args/ill-formed cmd line */
1368 # define E_NOPRIV 2    /* user not priv for operation */
1369 # define E_SAFERR 3    /* generic SAF error */
1370 # define E_SYSERR 4    /* system error */
1371 # define E_NOEXIST 5   /* invalid specification */
1372 # define E_DUP 6       /* entry already exists */
1373 # define E_PMRUN 7     /* port monitor is running */
1374 # define E_PMNOTRUN 8  /* port monitor is not running */
1375 # define E_RECOVER 9
1376    /* in recovery */
1378 .in -2
1381 .SS "Directory Structure"
1384 This section gives a description of the \fBSAF\fR files and directories.
1386 .ne 2
1388 \fB\fB/etc/saf/_sysconfig\fR\fR
1390 .RS 28n
1391 The per-system configuration script.
1395 .ne 2
1397 \fB\fB/etc/saf/_sactab\fR\fR
1399 .RS 28n
1400 The \fBSAC's\fR administrative file. Contains information about the port
1401 monitors for which the SAC is responsible.
1405 .ne 2
1407 \fB\fB/etc/saf/\fR\fIpmtag\fR\fR
1409 .RS 28n
1410 The home directory for port monitor \fIpmtag\fR.
1414 .ne 2
1416 \fB\fB/etc/saf/\fR\fIpmtag\fR\fB/_config\fR\fR
1418 .RS 28n
1419 The per-port monitor configuration script for port monitor pmtag.
1423 .ne 2
1425 \fB\fB/etc/saf/\fR\fIpmtag\fR\fB/_pmtab\fR\fR
1427 .RS 28n
1428 Port monitor pmtag's administrative file. Contains information about the
1429 services for which \fIpmtag\fR is responsible.
1433 .ne 2
1435 \fB\fB/etc/saf/\fR\fIpmtag\fR\fB/\fR\fIsvctag\fR\fR
1437 .RS 28n
1438 The file in which the per-service configuration script for service \fIsvctag\fR
1439 (available through port monitor  \fBpmtag\fR) is placed.
1443 .ne 2
1445 \fB\fB/etc/saf/\fR\fIpmtag\fR\fB/_pid\fR\fR
1447 .RS 28n
1448 The file in which a port monitor writes its process id in the current directory
1449 and places an advisory lock on the file.
1453 .ne 2
1455 \fB\fB/etc/saf/\fR \fBpmtag\fR \fB/_pmpipe\fR\fR
1457 .RS 28n
1458 The file in which the port monitor receives messages from the \fBSAC\fR and
1459 \fB\&../_sacpipe\fR and sends return messages to the \fBSAC.\fR
1463 .ne 2
1465 \fB\fB/var/saf/_log\fR\fR
1467 .RS 28n
1468 The \fBSAC's\fR log file.
1472 .ne 2
1474 \fB\fB/var/saf/\fR\fIpmtag\fR\fR
1476 .RS 28n
1477 The directory for files created by port monitor \fIpmtag,\fR for example its
1478 log file.
1481 .SH LIST OF COMMANDS
1484 The following administrative commands relate to \fBSAF.\fR
1486 .ne 2
1488 \fB\fBsacadm\fR(1M)\fR
1490 .RS 14n
1491 port monitor administrative command
1495 .ne 2
1497 \fB\fBpmadm\fR(1M)\fR
1499 .RS 14n
1500 service administration command
1503 .SH SEE ALSO
1506 \fBexec\fR(1), \fBsh\fR(1), \fBinit\fR(1M), \fBnlsadmin\fR(1M),
1507 \fBpmadm\fR(1M), \fBsac\fR(1M), \fBsacadm\fR(1M), \fBttyadm\fR(1M),
1508 \fBfork\fR(2), \fBdoconfig\fR(3NSL), \fBattributes\fR(5)