home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / ixemul-45.0-src.tgz / tar.out / contrib / ixemul / ixnet / getpwent.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  5KB  |  189 lines

  1. /*
  2.  *  This file is part of ixnet.library for the Amiga.
  3.  *  Copyright (C) 1996 Jeff Shepherd
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  $Id:$
  20.  *
  21.  *  $Log:$
  22.  *
  23.  */
  24.  
  25. #define _KERNEL
  26. #include <pwd.h>
  27. #include "ixnet.h"
  28.  
  29. #include <fcntl.h>
  30. #include <utmp.h>
  31. #include <errno.h>
  32. #include <unistd.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include <limits.h>
  36. #include <time.h>
  37.  
  38. /* prototypes */
  39. static struct passwd *__TCP2InetPwd(struct TCP_passwd *pwd);
  40. static struct passwd *__AS225InetPwd(struct AS225_passwd *pwd);
  41.  
  42. #undef errno
  43. int errno;
  44.  
  45. struct passwd *
  46. getpwent(void)
  47. {
  48.     register struct ixnet *p = (struct ixnet *)u.u_ixnet;
  49.     register int network_protocol = p->u_networkprotocol;
  50.  
  51.     if (network_protocol == IX_NETWORK_AMITCP) {
  52.     struct TCP_passwd *err = UG_getpwent();
  53.  
  54.     if (err == NULL) {
  55.         *u.u_errno = ug_GetErr();
  56.         return NULL;
  57.     }
  58.     else {
  59.         return __TCP2InetPwd(err);
  60.     }
  61.     }
  62.     else /*if (network_protocol == IX_NETWORK_AS225)*/ {
  63.     struct AS225_passwd *pwd = SOCK_getpwent();
  64.  
  65.     return (pwd ? __AS225InetPwd(pwd) : NULL);
  66.     }
  67. }
  68.  
  69. struct passwd *
  70. getpwnam(const char *name)
  71. {
  72.     register struct ixnet *p = (struct ixnet *)u.u_ixnet;
  73.     register int network_protocol = p->u_networkprotocol;
  74.  
  75.     if (network_protocol == IX_NETWORK_AMITCP) {
  76.     struct TCP_passwd *err = UG_getpwnam(name);
  77.  
  78.     if (err == NULL) {
  79.         *u.u_errno = ug_GetErr();
  80.         return NULL;
  81.     }
  82.     return __TCP2InetPwd(err);
  83.     }
  84.     else /* if (network_protocol == IX_NETWORK_AS225)*/ {
  85.     struct AS225_passwd *pwd = SOCK_getpwnam((char *)name);
  86.  
  87.     return (pwd ? __AS225InetPwd(pwd) : NULL);
  88.     }
  89. }
  90.  
  91. struct passwd *
  92. getpwuid(uid_t uid)
  93. {
  94.     register struct ixnet *p = (struct ixnet *)u.u_ixnet;
  95.     register int network_protocol = p->u_networkprotocol;
  96.  
  97.     /* Don't do this if uid == -2 (nobody2) */
  98.     /* This happens when someone doesn't use AmiTCP's login */
  99.     if (network_protocol == IX_NETWORK_AMITCP) {
  100.     if (uid != (uid_t)-2) {
  101.         struct TCP_passwd *err = UG_getpwuid(uid);
  102.  
  103.         if (err == NULL) {
  104.         *u.u_errno = ug_GetErr();
  105.         return NULL;
  106.         }
  107.         return __TCP2InetPwd(err);
  108.     }
  109.     else {
  110.         return getpwnam(getenv("USER"));
  111.     }
  112.     }
  113.     else /*if (network_protocol == IX_NETWORK_AS225)*/  {
  114.         struct AS225_passwd *pwd = SOCK_getpwuid(uid);
  115.  
  116.     return (pwd ? __AS225InetPwd(pwd) : NULL);
  117.     }
  118. }
  119.  
  120. int
  121. setpassent(int stayopen)
  122. {
  123.     return(1);
  124. }
  125.  
  126. int
  127. setpwent(void)
  128. {
  129.     register struct ixnet *p = (struct ixnet *)u.u_ixnet;
  130.     register int network_protocol = p->u_networkprotocol;
  131.  
  132.     if (network_protocol == IX_NETWORK_AMITCP) {
  133.     UG_setpwent();
  134.     }
  135.     else /* if (network_protocol == IX_NETWORK_AS225) */ {
  136.     SOCK_setpwent(0);
  137.     }
  138.     return 1;
  139. }
  140.  
  141. void
  142. endpwent(void)
  143. {
  144.     register struct ixnet *p = (struct ixnet *)u.u_ixnet;
  145.     register int network_protocol = p->u_networkprotocol;
  146.  
  147.     if (network_protocol == IX_NETWORK_AMITCP) {
  148.     UG_endpwent();
  149.     }
  150.     else /* if (network_protocol == IX_NETWORK_AS225)*/ {
  151.     SOCK_endpwent();
  152.     }
  153. }
  154.  
  155. /* change the AmiTCP password structure to the global format */
  156. static struct passwd *__TCP2InetPwd(struct TCP_passwd *pwd)
  157. {
  158.     u.u_passwd.pw_name = pwd->pw_name;
  159.     u.u_passwd.pw_passwd = pwd->pw_passwd;
  160.     u.u_passwd.pw_uid = pwd->pw_uid;
  161.     u.u_passwd.pw_gid = pwd->pw_gid;
  162.     u.u_passwd.pw_change = time((time_t *)NULL);
  163.     u.u_passwd.pw_class = NULL;
  164.     u.u_passwd.pw_gecos = pwd->pw_gecos;
  165.     u.u_passwd.pw_dir = pwd->pw_dir;
  166.     u.u_passwd.pw_shell = pwd->pw_shell;
  167.     u.u_passwd.pw_expire = (time_t)-1;
  168.     return &u.u_passwd;
  169. }
  170.  
  171. /* change the AS225/INet225's password structure to the global format */
  172. static struct passwd *__AS225InetPwd(struct AS225_passwd *pwd)
  173. {
  174.     u.u_passwd.pw_name = pwd->pw_name;
  175.     u.u_passwd.pw_passwd = pwd->pw_passwd;
  176.     u.u_passwd.pw_uid = pwd->pw_uid;
  177.     u.u_passwd.pw_gid = pwd->pw_gid;
  178.     u.u_passwd.pw_change = time((time_t *)NULL);
  179.     u.u_passwd.pw_class = NULL;
  180.     u.u_passwd.pw_gecos = pwd->pw_gecos;
  181.     u.u_passwd.pw_dir = pwd->pw_dir;
  182.     u.u_passwd.pw_shell = pwd->pw_shell;
  183.     u.u_passwd.pw_expire = (time_t)-1;
  184.     u.u_passwd.pw_change = (time_t)-1;
  185.     return &u.u_passwd;
  186. }
  187.  
  188. #define errno (* u.u_errno)
  189.