System and Network Administration lecture in color

Providing services

Where we are:

Providing services is a long story

UNIX consists of four kinds of programs:

Process concepts:

Forms of process spawning:

Process spawning rules:

Viewing processes:

Stupid process tricks:

Awk:

EX: simple program to figure out how many processes people have:

 BEGIN {       # BEGIN is done before any input read. 
     count=0; 
 }
 $2 != "PID" { # skip first line of ps. 
     # for each new UID, put into people. 
     # then increment procs[uid]. 
     if (!procs[$1]) { people[count++]=$1; }
     procs[$1]++;      # count for each PERSON of processes. 
 }
 END {                 # END is done after eof on input. 
     for (i=0; i<count; i++) { 
       print people[i],procs[people[i]]; 
     }
 }
 
 ps -ef | awk -f count.awk

Controlling processes:

In /usr/include/sys/signal.h:

 #define SIGHUP     1    /* hangup, generated when terminal disconnects */
 #define SIGINT     2    /* interrupt, generated from terminal special char */
 #define SIGQUIT    3    /* (*) quit, generated from terminal special char */
 #define SIGILL     4    /* (*) illegal instruction (not reset when caught)*/
 #define SIGTRAP    5    /* (*) trace trap (not reset when caught) */
 #define SIGABRT    6    /* (*) abort process */
 #define SIGEMT     7    /* (*) EMT instruction */
 #define SIGFPE     8    /* (*) floating point exception */
 #define SIGKILL    9    /* kill (cannot be caught or ignored) */
 #define SIGBUS    10    /* (*) bus error (specification exception) */
 #define SIGSEGV   11    /* (*) segmentation violation */
 #define SIGSYS    12    /* (*) bad argument to system call */
 #define SIGPIPE   13    /* write on a pipe with no one to read it */
 #define SIGALRM   14    /* alarm clock timeout */
 #define SIGTERM   15    /* software termination signal */
 #define SIGURG    16    /* (+) urgent contition on I/O channel */
 #define SIGSTOP   17    /* (@) stop (cannot be caught or ignored) */
 #define SIGTSTP   18    /* (@) interactive stop */
 #define SIGCONT   19    /* (!) continue if stopped */
 #define SIGCHLD   20    /* (+) sent to parent on child stop or exit */
 #define SIGTTIN   21    /* (@) background read attempted from control terminal*/
 #define SIGTTOU   22    /* (@) background write attempted to control terminal */
 #define SIGPOLL   23    /* I/O possible, or completed */
 #define SIGXCPU   24    /* cpu time limit exceeded (see setrlimit()) */
 #define SIGXFSZ   25    /* file size limit exceeded (see setrlimit()) */
 #define SIGVTALRM 26    /* virtual time alarm (see setitimer) */
 #define SIGPROF   27    /* profiling time alarm (see setitimer) */
 #define SIGWINCH  28    /* (+) window size changed */
 #define SIGINFO   29    /* (+) information request */
 #define SIGUSR1   30    /* user defined signal 1 */
 #define SIGUSR2   31    /* user defined signal 2 */
 #define SIGRESV   32    /* reserved by Digital for future use */

Special signals:

Signal handling:

Configuring a service:

When daemons are started: run-levels:

Two ways to start services:

Reconfiguring a service:

Must remember what to do for each specific daemon

Classes of daemons:

Inetd configuration

EX: BOOTP has a line:

 #name  socktyp proto   wait    user    command                 arguments
 bootps dgram   udp     wait    root    /usr/sbin/bootpd        bootpd
 ^ SERVICE NAME (from /etc/services) 
        ^ SOCKET TYPE: dgram, stream, raw, rdm, seqpacket. 
                ^ PROTOCOL: udp, tcp, or any other protocol in /etc/protocols. 
                        ^ wait or nowait. 
                              ^ user to run this as
                                      ^ COMMAND to execute 

Sample inetd file

 # Syntax for socket-based Internet services:
 #  <service_name> <socket_type> <proto> <flags> <user> <server_pathname> <args>
 #
 # Syntax for TLI-based Internet services:
 #  <service_name> tli <proto> <flags> <user> <server_pathname> <args>
 #
 # Ftp and telnet are standard Internet services.
 #
 ftp   stream  tcp     nowait  root    /usr/sbin/tcpd  in.ftpd
 telnet        stream  tcp     nowait  root    /usr/sbin/tcpd  in.telnetd
 #
 # Tnamed serves the obsolete IEN-116 name server protocol.
 #
 name  dgram   udp     wait    root    /usr/sbin/tcpd  in.tnamed
 #
 # Shell, login, exec, comsat and talk are BSD protocols.
 #
 shell stream  tcp     nowait  root    /usr/sbin/tcpd  in.rshd
 login stream  tcp     nowait  root    /usr/sbin/tcpd  in.rlogind
 exec  stream  tcp     nowait  root    /usr/sbin/tcpd  in.rexecd
 comsat        dgram   udp     wait    root    /usr/sbin/tcpd  in.comsat
 talk  dgram   udp     wait    root    /usr/sbin/tcpd  in.talkd
 #
 # Must run as root (to read /etc/shadow); "-n" turns off logging in utmp/wtmp.
 #
 uucp  stream  tcp     nowait  root    /usr/sbin/tcpd  in.uucpd
 #
 # Tftp service is provided primarily for booting.  Most sites run this
 # only on machines acting as "boot servers." 
 #
 #tftp dgram   udp     wait    root    /usr/sbin/in.tftpd      in.tftpd -s /tftpboot
 #
 # Finger, systat and netstat give out user information which may be
 # valuable to potential "system crackers."  Many sites choose to disable 
 # some or all of these services to improve security.
 #
 finger        stream  tcp     nowait  nobody  /usr/sbin/tcpd  in.fingerd
 #systat       stream  tcp     nowait  root    /usr/bin/ps             ps -ef
 #netstat      stream  tcp     nowait  root    /usr/bin/netstat        netstat -f inet
 #
 # Time service is used for clock synchronization.
 #
 time  stream  tcp     nowait  root    internal
 time  dgram   udp     wait    root    internal
 # 
 # Echo, discard, daytime, and chargen are used primarily for testing.
 #
 echo  stream  tcp     nowait  root    internal
 echo  dgram   udp     wait    root    internal
 discard       stream  tcp     nowait  root    internal
 discard       dgram   udp     wait    root    internal
 daytime       stream  tcp     nowait  root    internal
 daytime       dgram   udp     wait    root    internal
 chargen       stream  tcp     nowait  root    internal
 chargen       dgram   udp     wait    root    internal
 ...

Recall /etc/services: what are network services?

 tcpmux                1/tcp
 echo          7/tcp
 echo          7/udp
 discard               9/tcp           sink null
 discard               9/udp           sink null
 systat                11/tcp          users
 daytime               13/tcp
 daytime               13/udp
 netstat               15/tcp
 chargen               19/tcp          ttytst source
 chargen               19/udp          ttytst source
 ftp-data      20/tcp
 ftp           21/tcp
 telnet                23/tcp
 smtp          25/tcp          mail
 time          37/tcp          timserver
 time          37/udp          timserver
 name          42/udp          nameserver
 whois         43/tcp          nicname         # usually to sri-nic
 domain                53/udp
 domain                53/tcp
 bootps                67/udp                          # BOOTP/DHCP server
 bootpc                68/udp                          # BOOTP/DHCP client
 hostnames     101/tcp         hostname        # usually to sri-nic
 pop2          109/tcp         pop-2           # Post Office Protocol - V2
 pop3          110/tcp                         # Post Office Protocol - Version 3
 sunrpc                111/udp         rpcbind
 sunrpc                111/tcp         rpcbind
 imap          143/tcp         imap2           # Internet Mail Access Protocol v2
 ldap          389/tcp                         # Lightweight Directory Access Protocol 
 ldap          389/udp                         # Lightweight Directory Access Protocol
 ldaps         636/tcp                         # LDAP protocol over TLS/SSL (was sldap)
 ldaps         636/udp                         # LDAP protocol over TLS/SSL (was sldap)
 #
 # Host specific functions
 #
 tftp          69/udp
 rje           77/tcp
 finger                79/tcp
 link          87/tcp          ttylink
 supdup                95/tcp
 iso-tsap      102/tcp
 x400          103/tcp                         # ISO Mail
 x400-snd      104/tcp
 csnet-ns      105/tcp
 pop-2         109/tcp                         # Post Office
 uucp-path     117/tcp
 nntp            119/tcp         usenet                # Network News Transfer
 ntp           123/tcp                         # Network Time Protocol
 ntp           123/udp                         # Network Time Protocol
 NeWS          144/tcp         news            # Window System
 cvc_hostd     442/tcp                         # Network Console
 #
 # UNIX specific services
 #
 # these are NOT officially assigned
 #
 exec          512/tcp
 login         513/tcp
 shell         514/tcp         cmd             # no passwords used
 printer               515/tcp         spooler         # line printer spooler
 courier               530/tcp         rpc             # experimental
 uucp          540/tcp         uucpd           # uucp daemon
 biff          512/udp         comsat
 who           513/udp         whod
 syslog                514/udp
 talk          517/udp
 route         520/udp         router routed
 klogin                543/tcp                         # Kerberos authenticated rlogin
 new-rwho      550/udp         new-who         # experimental
 rmonitor      560/udp         rmonitord       # experimental
 monitor               561/udp                         # experimental
 pcserver      600/tcp                         # ECD Integrated PC board srvr
 kerberos-adm  749/tcp                         # Kerberos V5 Administration
 kerberos-adm  749/udp                         # Kerberos V5 Administration
 kerberos      750/udp         kdc             # Kerberos key server
 kerberos      750/tcp         kdc             # Kerberos key server
 krb5_prop     754/tcp                         # Kerberos V5 KDC propogation
 ufsd          1008/tcp        ufsd            # UFS-aware server
 ufsd          1008/udp        ufsd
 cvc           1495/tcp                        # Network Console
 ingreslock      1524/tcp
 www-ldap-gw   1760/tcp                        # HTTP to LDAP gateway
 www-ldap-gw   1760/udp                        # HTTP to LDAP gateway
 listen          2766/tcp                        # System V listener port
 nfsd          2049/udp        nfs             # NFS server daemon (clts)
 nfsd          2049/tcp        nfs             # NFS server daemon (cots)
 eklogin               2105/tcp                        # Kerberos encrypted rlogin
 lockd         4045/udp                        # NFS lock daemon/manager
 lockd         4045/tcp
 dtspc         6112/tcp                        # CDE subprocess control
 fs            7100/tcp                        # Font server
 ...
/etc/protocols: what are names of protocols?
 ip            0       IP              # internet protocol, pseudo protocol number
 icmp          1       ICMP            # internet control message protocol
 ggp           3       GGP             # gateway-gateway protocol
 tcp           6       TCP             # transmission control protocol
 egp           8       EGP             # exterior gateway protocol
 pup           12      PUP             # PARC universal packet protocol
 udp           17      UDP             # user datagram protocol
 hmp           20      HMP             # host monitoring protocol
 xns-idp               22      XNS-IDP         # Xerox NS IDP
 rdp           27      RDP             # "reliable datagram" protocol
 
 #
 # Internet (IPv6) extension headers
 #
 ipv6          41      IPv6            # IPv6 in IP encapsulation
 ipv6-route    43      IPv6-Route      # Routing header for IPv6
 ipv6-frag     44      IPv6-Frag       # Fragment header for IPv6
 esp           50      ESP             # Encap Security Payload for IPv6
 ah            51      AH              # Authentication Header for IPv6
 ipv6-icmp     58      IPv6-ICMP       # IPv6 internet control message protocol
 ipv6-nonxt    59      IPv6-NoNxt      # No next header extension header for IPv6
 ipv6-opts     60      IPv6-Opts       # Destination Options for IPv6

Inetd function:

How to read inetd.conf

The awful truth: names are fake

Two kinds of inetd daemons

Time/space tradeoff


lecture in color

/comp/150NET/notes/service-old.php
downloaded on Nov-23-2009 03:54:25 PM,
was last modified on Feb-17-2004 10:49:51 PM.

All lecture note content is copyright 2004 by
Alva L. Couch, Computer Science, Tufts University