/[mailutils]/mailutils/libmu_scm/mu_util.c
ViewVC logotype

Diff of /mailutils/libmu_scm/mu_util.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by gray, Thu May 16 11:18:29 2002 UTC revision 1.2 by gray, Tue Aug 13 13:24:57 2002 UTC
# Line 16  Line 16 
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
17    
18  #include "mu_scm.h"  #include "mu_scm.h"
19  #include <pwd.h>  #include <mailutils/mu_auth.h>
20    
21  SCM_DEFINE (mu_scm_getpwuid, "mu_getpwuid", 0, 1, 0,  SCM_DEFINE (mu_scm_getpwuid, "mu-getpwuid", 1, 0, 0,
22              (SCM USER),              (SCM USER),
23              "Look up an entry in the user database. USER can be an integer,\n"              "Look up an entry in the user database. USER can be an integer,\n"
24              "a string, or omitted, giving the behaviour of mu_getpwuid, mu_getpwnam\n"              "or a string, giving the behaviour of mu_get_auth_by_uid or mu_get_auth_by_name\n"
25              "or (system) getpwent respectively.\n"              "respectively.\n"
26              "Returns a vector with fields corresponding to those of the passwd\n"              "Returns a vector with fields corresponding to those of the mu_auth_data\n"
27              "entry in question. If no matching entry was found, returns #f.\n")              "entry in question. If no matching entry was found, returns #f.\n")
28  #define FUNC_NAME s_mu_scm_getpwuid  #define FUNC_NAME s_mu_scm_getpwuid
29  {  {
30    SCM result;    SCM result;
31    struct passwd *entry;    struct mu_auth_data *entry;
32    SCM *ve;    SCM *ve;
33    
34    result = scm_make_vector (SCM_MAKINUM (7), SCM_UNSPECIFIED);    result = scm_make_vector (SCM_MAKINUM (8), SCM_UNSPECIFIED);
35    ve = SCM_VELTS (result);    ve = SCM_VELTS (result);
36    if (SCM_UNBNDP (USER) || SCM_FALSEP (USER))    if (SCM_INUMP (USER))
37      {      {
38        entry = getpwent ();        entry = mu_get_auth_by_uid (SCM_INUM (USER));
     }  
   else if (SCM_INUMP (USER))  
     {  
       entry = mu_getpwuid (SCM_INUM (USER));  
39      }      }
40    else    else
41      {      {
42        SCM_VALIDATE_ROSTRING (1, USER);        SCM_VALIDATE_ROSTRING (1, USER);
43        if (SCM_SUBSTRP (USER))        if (SCM_SUBSTRP (USER))
44          USER = scm_makfromstr (SCM_ROCHARS (USER), SCM_ROLENGTH (USER), 0);          USER = scm_makfromstr (SCM_ROCHARS (USER), SCM_ROLENGTH (USER), 0);
45        entry = mu_getpwnam (SCM_ROCHARS (USER));        entry = mu_get_auth_by_name (SCM_ROCHARS (USER));
46      }      }
47    if (!entry)    if (!entry)
48      return SCM_BOOL_F;      return SCM_BOOL_F;
49    
50    ve[0] = scm_makfrom0str (entry->pw_name);    ve[0] = scm_makfrom0str (entry->name);
51    ve[1] = scm_makfrom0str (entry->pw_passwd);    ve[1] = scm_makfrom0str (entry->passwd);
52    ve[2] = scm_ulong2num ((unsigned long) entry->pw_uid);    ve[2] = scm_ulong2num ((unsigned long) entry->uid);
53    ve[3] = scm_ulong2num ((unsigned long) entry->pw_gid);    ve[3] = scm_ulong2num ((unsigned long) entry->gid);
54    ve[4] = scm_makfrom0str (entry->pw_gecos);    ve[4] = scm_makfrom0str (entry->gecos);
55    if (!entry->pw_dir)    if (!entry->dir)
56      ve[5] = scm_makfrom0str ("");      ve[5] = scm_makfrom0str ("");
57    else    else
58      ve[5] = scm_makfrom0str (entry->pw_dir);      ve[5] = scm_makfrom0str (entry->dir);
59    if (!entry->pw_shell)    if (!entry->shell)
60      ve[6] = scm_makfrom0str ("");      ve[6] = scm_makfrom0str ("");
61    else    else
62      ve[6] = scm_makfrom0str (entry->pw_shell);      ve[6] = scm_makfrom0str (entry->shell);
63      ve[7] = scm_makfrom0str (entry->mailbox);
64      mu_auth_data_free (entry);
65    return result;    return result;
66  }  }
67  #undef FUNC_NAME  #undef FUNC_NAME

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26