static char rcsid[] = "@(#)$Id: getfullnam.c,v 1.8 2006/04/09 07:37:05 hurtta Exp $";

/******************************************************************************
 *  The Elm (ME+) Mail System  -  $Revision: 1.8 $   $State: Exp $
 *
 *  Modified by: Kari Hurtta <hurtta+elm@posti.FMI.FI>
 *                           (was hurtta+elm@ozone.FMI.FI)
 ******************************************************************************
 *  The Elm Mail System 
 *
 *			Copyright (c) 1988-1992 USENET Community Trust
 *			Copyright (c) 1986,1987 Dave Taylor
 *****************************************************************************/

/** 

**/

#include "headers.h"
#ifdef PWDINSYS
#  include <sys/pwd.h>
#else
#  include <pwd.h>
#endif

char * get_full_name(logname)
     char *logname;
{
    /* return a pointer to the full user name for the passed logname
     * or NULL if cannot be found
     * If PASSNAMES get it from the gcos field, otherwise get it
     * from ~/.fullname.
     */
    
    struct passwd *pass;
    
    if((pass = getpwnam(logname)) == NULL)
	return(NULL);
    
    return get_fullname1(pass,logname);
}

char * get_fullname1(pass,logname)
     struct passwd *pass;
     CONST char *logname;
{
#ifndef PASSNAMES
    FILE *fp;
    char fullnamefile[SLEN];
#endif
    static char fullname[SLEN];

#ifdef PASSNAMES	/* get full_username from gcos field */
    strfcpy(fullname, gcos_name(pass->pw_gecos, logname),
		sizeof fullname);
#else			/* get full_username from ~/.fullname file */
    elm_sfprintf(fullnamefile, sizeof fullnamefile,
		 FRM("%s/.fullname"), pass->pw_dir);
    
    if(can_access(fullnamefile, READ_ACCESS) != 0)
	return(NULL);		/* fullname file not accessible to user */
    if((fp = fopen(fullnamefile, "r")) == NULL)
	return(NULL);		/* fullname file cannot be opened! */
    if(fgets(fullname, SLEN, fp) == NULL) {
	fclose(fp);
	return(NULL);		/* fullname file empty! */
    }
    fclose(fp);
    no_ret(fullname);	/* remove trailing '\n' */
#endif
    return(fullname);
}

 
/*
 * Local Variables:
 *  mode:c
 *  c-basic-offset:4
 *  buffer-file-coding-system: iso-8859-1
 * End:
 */


syntax highlighted by Code2HTML, v. 0.9.1