man-pages/man3/setaliasent.3

149 lines
3.5 KiB
Groff
Raw Normal View History

2004-11-03 13:51:07 +00:00
.\" Copyright 2003 Walter Harms (walter.harms@informatik.uni-oldenburg.de)
.\" Distributed under GPL
.\"
.\" Polished a bit, added a little, aeb
.\"
.TH SETALIASENT 3 2003-09-09 "GNU" "Linux Programmer's Manual"
2004-11-03 13:51:07 +00:00
.SH NAME
setaliasent, endaliasent, getaliasent, getaliasent_r,
getaliasbyname, getaliasbyname_r \- read an alias entry
.SH SYNOPSIS
.B #include <aliases.h>
.sp
2007-09-20 16:26:31 +00:00
.B "void setaliasent(void);"
.sp
2007-09-20 16:26:31 +00:00
.B "void endaliasent(void);"
2004-11-03 13:51:07 +00:00
.sp
2007-09-20 16:26:31 +00:00
.B "struct aliasent *getaliasent(void);"
2004-11-03 13:51:07 +00:00
.sp
.BI "int getaliasent_r(struct aliasent *" result ","
.br
2007-04-03 15:32:52 +00:00
.BI " char *" buffer ", size_t " buflen ", struct aliasent **" res );
2004-11-03 13:51:07 +00:00
.sp
.BI "struct aliasent *getaliasbyname(const char *" name );
.sp
2007-04-03 15:32:52 +00:00
.BI "int getaliasbyname_r(const char *" name ", struct aliasent *" result ,
2004-11-03 13:51:07 +00:00
.br
2007-04-03 15:32:52 +00:00
.BI " char *" buffer ", size_t " buflen ", struct aliasent **" res );
2004-11-03 13:51:07 +00:00
.SH DESCRIPTION
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 \fIgetent \-\-help\fP.)
2004-11-03 13:51:07 +00:00
Six functions are provided to access the aliases database.
.PP
The
.BR getaliasent ()
2004-11-03 13:51:07 +00:00
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;
2004-11-03 13:51:07 +00:00
thereafter, it returns successive entries.
.PP
The
.BR setaliasent ()
2004-11-03 13:51:07 +00:00
function rewinds the file pointer to the beginning of the
aliases database.
.PP
The
.BR endaliasent ()
2004-11-03 13:51:07 +00:00
function closes the aliases database.
.PP
.BR getaliasent_r ()
is the reentrant version of the previous function.
2007-04-03 15:32:52 +00:00
The requested structure
2004-11-03 13:51:07 +00:00
is stored via the first argument but the programmer needs to fill the other
2007-04-03 15:32:52 +00:00
arguments also.
Not providing enough space causes the function to fail.
2004-11-03 13:51:07 +00:00
.PP
The function
.BR getaliasbyname ()
takes the name argument and searches the aliases database.
The entry is returned as a pointer to a
.IR "struct aliasent" .
2004-11-03 13:51:07 +00:00
.PP
.BR getaliasbyname_r ()
is the reentrant version of the previous function.
2007-04-03 15:32:52 +00:00
The requested structure
2007-04-03 17:53:26 +00:00
is stored via the second argument but the programmer needs to fill the other
arguments also.
2007-04-03 15:32:52 +00:00
Not providing enough space causes the function to fail.
2004-11-03 13:51:07 +00:00
.PP
The
2007-04-03 15:32:52 +00:00
.I "struct aliasent"
is defined in
2007-04-03 15:32:52 +00:00
.IR <aliases.h> :
2007-07-09 21:52:33 +00:00
.in +0.5i
2004-11-03 13:51:07 +00:00
.nf
2007-04-03 15:32:52 +00:00
2004-11-03 13:51:07 +00:00
struct aliasent {
2007-04-03 15:32:52 +00:00
char *alias_name; /* alias name */
size_t alias_members_len;
2007-08-27 08:36:21 +00:00
char **alias_members; /* alias name list */
2007-04-03 15:32:52 +00:00
int alias_local;
2004-11-03 13:51:07 +00:00
};
.fi
.SH "RETURN VALUE"
The functions
.BR getaliasent_r ()
2004-11-03 13:51:07 +00:00
and
.BR getaliasbyname_r ()
2004-11-03 13:51:07 +00:00
return a non-zero value on error.
.SH FILES
The default alias database is the file
.IR /etc/aliases .
This can be changed in the
.I /etc/nsswitch.conf
file.
.SH "CONFORMING TO"
These routines are glibc-specific.
2007-06-13 22:21:38 +00:00
The NeXT has similar routines:
.RS
.nf
2007-06-13 22:21:38 +00:00
#include <aliasdb.h>
2007-06-13 22:21:38 +00:00
void alias_setent(void);
void alias_endent(void);
alias_ent *alias_getent(void);
alias_ent *alias_getbyname(char *name);
.fi
.RE
2004-11-03 13:51:07 +00:00
.SH EXAMPLE
The following example compiles with
2005-07-06 08:00:30 +00:00
.IR "gcc example.c \-o example" .
2004-11-03 13:51:07 +00:00
It will dump all names in the alias database.
.sp
.nf
#include <aliases.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
int
main(void)
2007-04-05 12:36:57 +00:00
{
struct aliasent *al;
setaliasent();
for (;;) {
al = getaliasent();
if (al == NULL)
2007-04-05 12:36:57 +00:00
break;
2007-06-20 21:39:45 +00:00
printf("Name: %s\\n", al\->alias_name);
2007-04-05 12:36:57 +00:00
}
if (errno) {
perror("reading alias");
exit(EXIT_FAILURE);
}
endaliasent();
exit(EXIT_SUCCESS);
2004-11-03 13:51:07 +00:00
}
.fi
.SH "SEE ALSO"
.BR getgrent (3),
.BR getpwent (3),
.BR getspent (3),
.BR aliases (5)
.\"
.\" /etc/sendmail/aliases
.\" Yellow Pages
.\" newaliases, postalias