man-pages/man3/setaliasent.3.html
2021-03-31 01:06:50 +01:00

278 lines
7.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of SETALIASENT</TITLE>
</HEAD><BODY>
<H1>SETALIASENT</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
setaliasent, endaliasent, getaliasent, getaliasent_r,
getaliasbyname, getaliasbyname_r - read an alias entry
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:///usr/include/aliases.h">aliases.h</A>&gt;</B>
<P>
<B>void setaliasent(void);</B>
<P>
<B>void endaliasent(void);</B>
<P>
<B>struct aliasent *getaliasent(void);</B>
<P>
<B>int getaliasent_r(struct aliasent *</B><I>result</I><B>,</B>
<BR>
<B> char *</B><I>buffer</I><B>, size_t </B><I>buflen</I><B>, struct aliasent **</B><I>res</I><B>);</B>
<P>
<B>struct aliasent *getaliasbyname(const char *</B><I>name</I><B>);</B>
<P>
<B>int getaliasbyname_r(const char *</B><I>name</I><B>, struct aliasent *</B><I>result</I><B>,</B>
<BR>
<B> char *</B><I>buffer</I><B>, size_t </B><I>buflen</I><B>, struct aliasent **</B><I>res</I><B>);</B>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
One of the databases available with the Name Service Switch (NSS)
is the aliases database, that contains mail aliases.
(To find out which databases are supported, try
<I>getent --help</I>.)
Six functions are provided to access the aliases database.
<P>
The
<B>getaliasent</B>()
function returns a pointer to a structure containing
the group information from the aliases database.
The first time it is called it returns the first entry;
thereafter, it returns successive entries.
<P>
The
<B>setaliasent</B>()
function rewinds the file pointer to the beginning of the
aliases database.
<P>
The
<B>endaliasent</B>()
function closes the aliases database.
<P>
<B>getaliasent_r</B>()
is the reentrant version of the previous function.
The requested structure
is stored via the first argument but the programmer needs to fill the other
arguments also.
Not providing enough space causes the function to fail.
<P>
The function
<B>getaliasbyname</B>()
takes the name argument and searches the aliases database.
The entry is returned as a pointer to a
<I>struct aliasent</I>.
<P>
<B>getaliasbyname_r</B>()
is the reentrant version of the previous function.
The requested structure
is stored via the second argument but the programmer needs to fill the other
arguments also.
Not providing enough space causes the function to fail.
<P>
The
<I>struct aliasent</I>
is defined in
<I>&lt;<A HREF="file:///usr/include/aliases.h">aliases.h</A>&gt;</I>:
<P>
struct aliasent {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;&nbsp;&nbsp;&nbsp;*alias_name;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;alias&nbsp;name&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;size_t&nbsp;&nbsp;&nbsp;alias_members_len;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;&nbsp;&nbsp;**alias_members;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;alias&nbsp;name&nbsp;list&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alias_local;
};
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
The functions
<B>getaliasent_r</B>()
and
<B>getaliasbyname_r</B>()
return a nonzero value on error.
<A NAME="lbAF">&nbsp;</A>
<H2>FILES</H2>
The default alias database is the file
<I>/etc/aliases</I>.
This can be changed in the
<I>/etc/nsswitch.conf</I>
file.
<A NAME="lbAG">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>setaliasent</B>(),
<B>endaliasent</B>(),
<B>getaliasent_r</B>(),
<B>getaliasbyname_r</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe locale<BR></TD></TR>
<TR VALIGN=top><TD>
<B>getaliasent</B>(),
<B>getaliasbyname</B>()
</TD><TD>Thread safety</TD><TD>MT-Unsafe<BR></TD></TR>
</TABLE>
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
These routines are glibc-specific.
The NeXT system has similar routines:
<P>
#include &lt;<A HREF="file:///usr/include/aliasdb.h">aliasdb.h</A>&gt;
<P>
void alias_setent(void);
void alias_endent(void);
alias_ent *alias_getent(void);
alias_ent *alias_getbyname(char *name);
<A NAME="lbAI">&nbsp;</A>
<H2>EXAMPLE</H2>
The following example compiles with
<I>gcc example.c -o example</I>.
It will dump all names in the alias database.
<P>
#include &lt;<A HREF="file:///usr/include/aliases.h">aliases.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/stdio.h">stdio.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/errno.h">errno.h</A>&gt;
<P>
int
main(void)
{
<BR>&nbsp;&nbsp;&nbsp;&nbsp;struct&nbsp;aliasent&nbsp;*al;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;setaliasent();
<BR>&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(;;)&nbsp;{
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;al&nbsp;=&nbsp;getaliasent();
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(al&nbsp;==&nbsp;NULL)
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;Name:&nbsp;%s\n&quot;,&nbsp;al-&gt;alias_name);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;}
<BR>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(errno)&nbsp;{
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;perror(&quot;reading&nbsp;alias&quot;);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(EXIT_FAILURE);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;}
<BR>&nbsp;&nbsp;&nbsp;&nbsp;endaliasent();
<BR>&nbsp;&nbsp;&nbsp;&nbsp;exit(EXIT_SUCCESS);
}
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?3+getgrent">getgrent</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+getpwent">getpwent</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+getspent">getspent</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?5+aliases">aliases</A></B>(5)
<A NAME="lbAK">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
<DT id="2"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="3"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="4"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="5"><A HREF="#lbAF">FILES</A><DD>
<DT id="6"><A HREF="#lbAG">ATTRIBUTES</A><DD>
<DT id="7"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="8"><A HREF="#lbAI">EXAMPLE</A><DD>
<DT id="9"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="10"><A HREF="#lbAK">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:56 GMT, March 31, 2021
</BODY>
</HTML>