NIS(3pm)
π Net::NIS β the manual, but make it slay π
okay bestie, sit down, hydrate, and let me tell you about Net::NIS πΈ β the Perl interface to Sun's Network Information Service. (Yes, yes, the manpage name is NIS(3pm) and it lives in User Contributed Perl Documentation. We're keeping it cute, not renaming anything. π
)
β¨ SYNOPSIS β¨
use Net::NIS;
tie %hash, 'Net::NIS', $mapname [, $domainname];
$value = $hash{$key};
or, y'know, if you're feeling β¨proceduralβ¨:
($status, $value) = Net::NIS::yp_match
(Net::NIS::yp_get_default_domain(),
$mapname, $key);
π DESCRIPTION π
The Net::NIS interface comes in three parts, like a very iconic trio π«Ά:
- raw The first part is the raw implementation of the NIS API. No frills, just vibes and function calls.
- OO The second is the object interface, described in
Net::NIS::Table. Go read that one too, bestie. - Tie The third is a new 'Tied' interface, allowing simple access to NIS maps using Perl hashes. This is the one that makes you go "wait, that's it? ate." π₯
This document describes the NIS API implementation and the 'Tied' mechanism. Two for one, we love to see it.
π Tied Implementation π
NIS maps are simple key/value pairs β literally born to be Perl hashes. It's giving match made in heaven π. Net::NIS lets any given NIS map be treated as a hash (read-only, so no, you can't just start rewriting your company's passwd map, girl please π). Usage:
tie %hash, 'Net::NIS', $mapname [, $domainname];
$mapname must be specified, and be a valid map in the given domain. If the file /var/yp/nicknames exists, it is used to obtain a list of acceptable shortcut names, such as "aliases" for "mail.aliases". Otherwise, a hardcoded set of the "usual suspects" is consulted. (The fallback squad. They showed up anyway. π«‘)
If $domainname is not given, the yp_get_default_domain function is used to determine the current NIS domain. This is usually the same as will be displayed by the domainname command. Yes, lowercase, no underscore. iykyk.
If Net::NIS cannot tie to a given map, it returns undef, with an appropriate error value in the variable $yperr. See "ERRORS" below, bestie, don't skip it πΈ.
To look up an entry in a YP map, simply use the entry name as a key in the tied hash. Net::NIS returns a string if the key exists in the map, or undef if it is not found. For any errors other than YPERR_KEY, Net::NIS raises a fatal exception through croak. So like, if it's just "key not here" it's chill, but anything else? It's screaming π.
Example
tie %alias, 'Net::NIS', 'mail.aliases'
or die "Cannot tie to mail.aliases YP map: $yperr\n";
print "postmaster is ", $alias{postmaster} || "<unknown>", "\n";
As a special case, the magic map __YPMASTER can be used as an equivalent to 'ypwhich -m':
tie %ypmaster, 'Net::NIS', '__YPMASTER' or die ...;
printf "ypmaster(passwd) = %s\n", $ypmaster{'passwd.byname'};
print $_, "\n" for sort keys %ypmaster; # Only works on Linux!
Note thatkeys()only works on Linux, because Linux includes a helpfulyp_maplist()function. On Linux, you can get a list of existing YP maps. On other OSes, you can't β but given the name of an existing map,$ypmaster{$map}will work as expected. So like, Linux girlies get the full menu, everyone else gets Γ la carte π .
π NIS API Implementation π
The NIS package implements all functions described in the ypclnt(3N) manual page. Every single one. No crumbs left.
The following commands have been implemented:
yp_bind($domain)β Bind the process to a NIS server for the domain$domain. This function is rarely needed. Seeyp_bind(3N). Lowkey a background character.yp_unbind($domain)β Unbind the process from the specified$domain. This function is also rarely required. Seeyp_unbind(3N). Also a background character. Besties fr.$domain = yp_get_default_domain()β Return the host's local domain. (The same as thedomainnameprogram). Seeyp_get_default_domain(3N).($status, $value) = yp_match($domain, $map, $key)β Return the$valuefor the given$keyin the$mapfor the domain$domain. The$keymust be an exact match for an item in the map (i.e.yp_matchdoes no partial matching β it is not doing fuzzy find for you, no cap). The$valueis only valid if$statusis equal toYPERR_SUCCESS. If called in scalar context,yp_matchreturns only$value, and it is up to the user to check$yperr. So the responsibility is on you, bestie. Eyes open π.($status, $key, $value) = yp_first($domain, $map)β Return the first key-value pair from$mapin$domain. As the NIS maps are stored in a DBM table, the order of the returned values is not obvious. Do not expect alphabetical. Do not expect anything. Just accept the gift. π($status, $key, $value) = yp_next($domain, $map, $key)β Return the next key-value pair from$mapin$domain. The$keymust be provided from the previousyp_firstoryp_next. Theyp_first/yp_nextmethod is not recommended, as under some circumstances, entries can be skipped or returned twice.yp_allis a better interface to use. Yeah. That's the tea. Useyp_all. β($status, \%values) = yp_all($domain, $map)β Theyp_allcall returns an entire map in the%valuesassociative array. The whole thing. One shot. Iconic behavior. β¨($status, $order) = yp_order($domain, $map)β This function returns the order number for$domain. Whatever that is. It mustn't be very important, since it's not implemented on NIS+ servers running in "YP-compatibility mode". I put it in for completeness. (Author said it, not me. π)($status, $name) = yp_master($domain, $map)β Returns the machine name of the master server for a map. Main character server energy π.$error = yperr_string($status)β [DEPRECATED, use$yperr] Returns a string representation of the error code passed in$status. She's retired, send her flowers π.$status = ypprot_err($code)β [DEPRECATED] Translates a NIS name service protocol error code to a ypclnt layer error code. Only used for the C version ofyp_all, and it is only implemented here for completeness. A true "technically present" moment.
π EXPORT π
The magic variable $yperr is exported by default (see "ERRORS"). She comes included, no extra charge π.
β Exportable constants β
The following error status constants can be imported individually, or by using the ':all' symbol. Collect them all, PokΓ©mon style:
YPERR_SUCCESS There is no error
YPERR_BADARGS Args to function are bad
YPERR_RPC RPC failure
YPERR_DOMAIN Can't bind to a server with this domain
YPERR_MAP No such map in server's domain
YPERR_KEY No such key in map
YPERR_YPERR Internal yp server or client error
YPERR_RESRC Local resource allocation failure
YPERR_NOMORE No more records in map database
YPERR_PMAP Can't communicate with portmapper
YPERR_YPBIND Can't communicate with ypbind
YPERR_YPSERV Can't communicate with ypserv
YPERR_NODOM Local domain name not set
YPERR_BADDB yp data base is bad
YPERR_VERS YP version mismatch
YPERR_ACCESS Access violation
YPERR_BUSY Database is busy
π ERRORS π
Instead of having 'tie' succeed and the first access fail (a betrayal we simply cannot allow π
), TIEHASH() (the function executed when performing a tie) performs some sanity checks: it ensures the validity of the domain and map names. On failure, 'tie' returns undef, with an appropriate error value in $yperr:
tie %myhash, 'Net::NIS', 'foo-bar'
or die "Unable to access foo-bar map: $yperr\n"
Note that the$yperrvariable is magic, like Perl's$!. If accessed in a string context, it returns a human-friendly string obtained from theyperr_stringlibrary function. In a numeric context,$yperrreturns the numeric status code returned from the last YP function. This can be compared against the error constants above, if you so desire. She shapeshifts, basically. π¦
πΈ Other Errors πΈ
Your vendor has not defined Net::NIS macro YPERR_xxxx
This indicates that one of the standard YPERR_xxx constants is not defined in your host's <rpcsct/ypclnt.h> file. You might see this during make test on an old system, perhaps. (Blame the vendor, not yourself, bestie. π«Ά)
Unable to find 'KEY' in 'MAP'. Reason: ...
If an attempt to access a tied variable fails for any reason other than 'no such key in map', FETCH() raises this fatal exception. It probably indicates that YP has gone down, or there is some other fatal error. This can be caught with eval{}, but I'm not sure what you can do about it... π The author really said "good luck, girl."
π«Ά AUTHOR π«Ά
Copyright (c) 1995, 2002 Rik Harris (rik.harris@fulcrum.com.au), 2002-2014 Ed Santiago. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Net::NIS is currently maintained by Ed Santiago <esm@cpan.org>. Give him a round of applause π.
The Network Information Service (NIS) was formerly known as Sun Yellow Pages (YP). The functionality of the two remains the same; only the name has changed. The name Yellow Pages is a registered trademark in the United Kingdom of British Telecommunications plc, and may not be used without permission. So like β same girl, new name badge, and please respect the trademark, we're not trying to get a letter π β¨.
that's the whole manual, bestie, nothing skipped, nothing summarised. π
and for the little sign-off at the bottom: this page is from perl v5.42.3, dated 2026-08-19 β from me and the NIS(3pm) girlies, mwah π go tie a hash, you've got this π¦ππΈ
π¦ where this page comes from
- ubuntu stonking: libnet-nis-perl 0.44-4build2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms