Article View: comp.soft-sys.andrew
Article #2128Local Validation Using YP Database
From: Tom Crockett
Date: Mon, 26 Feb 1990 20:24
Date: Mon, 26 Feb 1990 20:24
169 lines
6166 bytes
6166 bytes
Excerpts from mail: 22-Feb-90 Re: Simple fix to core dump..
Craig_Everhart@transarc. (641)
> Yup, if you're using mswp.c's recipient validation, you'll have to get
> it to know about the valid aliases that the icase.edu mail server knows
> about. Is there any sensible way of doing that? How would you go about
> to write a YP client to do that? Is it simply a matter of calling the
> native getpwnam() routine? (Probably not, or else AMS_PasswdValidation
> would be doing the right thing for you.)
> If you can answer this, maybe we can extend mswp.c to do the right thing
> for your case, either extending CheckGlobalAlias() (which, as you noted,
> checks only /usr/lib/aliases), or extending the LookupInLocalDatabase
> case for you.
Well, I worked on the code for CheckGlobalAlias() in ams/libs/ms/mswp.c
and here is what I came up with. It's pretty straightforward, so it
should be easy to adapt as needed. The strategy is:
(1) If AMS_AliasesValidation is true, then validate the address
against any globally-defined aliases by calling CheckGlobalAlias().
(No change here -- this is the way it currently works.)
(2) CheckGlobalAliases() first looks for the alias in
/usr/lib/aliases. If it can't find it there, then if
YELLOWPAGES_ENV is defined, it will look in the "mail.aliases"
database of the default local YP domain.
I've tested this on our system (SunOS 4.0.3) and it seems to do what we
want. I've enclosed the patches to mswp.c.
There are a few things which you may want to consider before
incorporating my code as is:
Should we look in both the /usr/lib/aliases file and the YP
database, or only one or the other? If both, then which should take
precedence, the file or the YP database? Finer control over this
could be achieved by adding some more variables to the AndrewSetup
file (at the expense of ever more complexity -- ugh.)
I've done nothing when encountering YP errors, except to say that
the alias was not found. By checking the error codes returned by
yp_get_default_domain() and yp_match(), you could be a bit more
intelligent and helpful to the user when things go wrong.
There's been some discussion on info-andrew lately about looking for
aliases in a global (sitewide) .AMS_aliases file. It seems to me
that it might be fairly easy to incorporate this feature into
CheckGlobalAlias(), as long as you're mucking with this piece of
code anyway. Maybe just steal some code from CheckPersonalAlias()
and incorporate it into CheckGlobalAlias(), then parameterize
RefreshAliasFile() to accept different pathnames for the local vs.
global .AMS_alias files. Maybe. I haven't really looked at the
guts of RefreshAliasFile().
This is my first foray ever into programming with the yp_ routines.
You might want to run this past someone who has a little more
experience to be sure I haven't overlooked anything important.
I hope this will be helpful to others at non-WP sites who are running
Yellow Pages.
Tom Crockett
ICASE
Institute for Computer Applications in Science and Engineering
M.S. 132C e-mail: tom@icase.edu
NASA Langley Research Center phone: (804) 864-2182
Hampton, VA 23665-5225
---- Enclosure ----
*** ams/libs/ms/mswp.c.save Wed Nov 22 11:34:10 1989
--- ams/libs/ms/mswp.c Mon Feb 26 14:41:22 1990
***************
*** 2297,2303 ****
--- 2297,2305 ----
{
char LineBuf[1000], *s;
FILE *fp;
+ int found = FALSE;
+ /* Look in /usr/lib/aliases first */
errno = 0;
fp = fopen("/usr/lib/aliases", "r");
if (!fp) {
***************
*** 2313,2324 ****
*s = '\0';
s = StripWhiteEnds(LineBuf);
if (!ULstrcmp(s, name)) {
! *code = (CheckAMSFmtOK(Domain) <= 0 ? MSWP_GOODNETMAIL : MSWP_GOODUSER);
! debug(16, ("CheckGlobalAlias: given %s/%s, returning %d\n", name,
Domain, *code));
! break;
! }
}
fclose(fp);
return(0);
}
--- 2315,2371 ----
*s = '\0';
s = StripWhiteEnds(LineBuf);
if (!ULstrcmp(s, name)) {
! found = TRUE;
! break;
! }
}
fclose(fp);
+
+ #ifdef YELLOWPAGES_ENV
+
+ /* If not found in the aliases file, look in the YP database */
+
+ /* This code needs to be improved to do something intelligent
+ about errors based on the return values from the yp_ routines. */
+
+ if (!found) {
+
+ static char *LocalYPDomain = NULL;
+ char *alias;
+ int len;
+
+ if (name != NULL) { /* Possibly unnecessary bullet-proofing */
+ if (LocalYPDomain == NULL) { /* just call this once! */
+ if (yp_get_default_domain(&LocalYPDomain)) {
+ return(0); /* couldn't get YP domain name */
+ }
+ }
+
+ if (LocalYPDomain != NULL) {
+ alias = NULL;
+ if (!yp_match(LocalYPDomain, "mail.aliases", name,
+ strlen(name)+1, &alias, &len)) {
+ found = TRUE;
+ if (len >= sizeof(LineBuf)) {
+ len = sizeof(LineBuf)-1; /* more bullet-proofing */
+ }
+ *(alias+len) = '\0';
+ strcpy(LineBuf, alias);
+ s = StripWhiteEnds(LineBuf);
+ }
+ if (alias != NULL) free(alias);
+ }
+ }
+ }
+
+ #endif /* YELLOWPAGES_ENV */
+
+ if (found)
+ {
+ *code = (CheckAMSFmtOK(Domain) <= 0 ? MSWP_GOODNETMAIL :
MSWP_GOODUSER);
+ debug(16, ("CheckGlobalAlias: given %s/%s, returning %d\n",
name, Domain, *code));
+ }
+
return(0);
}
---- Enclosure ----
Technical Details
Message-ID:
<0ZuN1y=0_csm0en2JR@sparc01.icase.edu>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!fernwood!decwrl!shelby!agate!ucbvax!sparc01.icase.edu!tomReferences:
<wZt2MlT0BwwO0NbIM7@transarc.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!fernwood!decwrl!shelby!agate!ucbvax!sparc01.icase.edu!tom From: tom@sparc01.icase.edu (Tom Crockett) Newsgroups: comp.soft-sys.andrew Subject: Local Validation Using YP Database Message-ID: <0ZuN1y=0_csm0en2JR@sparc01.icase.edu> Date: 26 Feb 90 20:24:30 GMT References: <wZt2MlT0BwwO0NbIM7@transarc.com> Sender: usenet@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 169