Services

Parses /etc/services

Author: Raphael Pinson rap.nosp@m.hink@gmai.nosp@m.l.com

Summary
ServicesParses /etc/services
ReferenceThis lens tries to keep as close as possible to ‘man services’ where possible.
LicenseThis file is licensed under the LGPL v2+, like the rest of Augeas.
Lens UsageSample usage of this lens in augtool
Configuration filesThis lens applies to /etc/services.
USEFUL PRIMITIVES
Generic primitives
eol
Separators
LENSES
port
port_range
protocol
alias
recordA standard /etc/services record TODO: make sure a space is added before a comment on new nodes
lnsThe services lens is either <empty>, comment or record
filter

Reference

This lens tries to keep as close as possible to ‘man services’ where possible.

The definitions from ‘man services’ are put as commentaries for reference throughout the file.  More information can be found in the manual.

License

This file is licensed under the LGPL v2+, like the rest of Augeas.

Lens Usage

Sample usage of this lens in augtool

  • Get the name of the service running on port 22 with protocol tcp
match "/files/etc/services/service-name[port = '22'][protocol = 'tcp']"
  • Remove the tcp entry for “domain” service
rm "/files/etc/services/service-name[. = 'domain'][protocol = 'tcp']"
  • Add a tcp service named “myservice” on port 55234
ins service-name after /files/etc/services/service-name[last()]
set /files/etc/services/service-name[last()] "myservice"
set "/files/etc/services/service-name[. = 'myservice']/port" "55234"
set "/files/etc/services/service-name[. = 'myservice']/protocol" "tcp"

Configuration files

This lens applies to /etc/services.  See filter.

USEFUL PRIMITIVES

Generic primitives

eol

let eol = del /[ \t]*(#)?[ \t]*\n/ "\n"

Separators

LENSES

port

let port = [ label "port" . store num_re ]

port_range

let port_range = [ label "start" . store num_re ] . Util.del_str "-" . [ label "end" . store num_re ]

protocol

let protocol = [ label "protocol" . store protocol_re ]

alias

let alias = [ label "alias" . store word_re ]

record

let record = [ label "service-name" . store word_re . sep_spc . (port | port_range) . del "/" "/" . protocol . ( sep_spc . alias )* . comment_or_eol ]

A standard /etc/services record TODO: make sure a space is added before a comment on new nodes

lns

let lns = ( empty | comment | record )*

The services lens is either <empty>, comment or record

filter

let eol = del /[ \t]*(#)?[ \t]*\n/ "\n"
let port = [ label "port" . store num_re ]
let port_range = [ label "start" . store num_re ] . Util.del_str "-" . [ label "end" . store num_re ]
let protocol = [ label "protocol" . store protocol_re ]
let alias = [ label "alias" . store word_re ]
let record = [ label "service-name" . store word_re . sep_spc . (port | port_range) . del "/" "/" . protocol . ( sep_spc . alias )* . comment_or_eol ]
A standard /etc/services record TODO: make sure a space is added before a comment on new nodes
let lns = ( empty | comment | record )*
The services lens is either empty, comment or record
let comment = IniFile.comment "#" "#"
Only supports “#” as commentary
Close