home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / gcc / ixemulsrc.lha / ixemul / ixnet / getpwent.c < prev    next >
C/C++ Source or Header  |  1996-12-11  |  5KB  |  198 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.     register struct ixnet *p = (struct ixnet *)u.u_ixnet;
  124.     register int network_protocol = p->u_networkprotocol;
  125.  
  126.     if (network_protocol == IX_NETWORK_AMITCP) {
  127.     UG_setpwent();
  128.     }
  129.     else /* if (network_protocol == IX_NETWORK_AS225) */ {
  130.     SOCK_setpwent(0);
  131.     }
  132.     return 1;
  133. }
  134.  
  135. int
  136. setpwent(void)
  137. {
  138.     register struct ixnet *p = (struct ixnet *)u.u_ixnet;
  139.     register int network_protocol = p->u_networkprotocol;
  140.  
  141.     if (network_protocol == IX_NETWORK_AMITCP) {
  142.     UG_setpwent();
  143.     }
  144.     else /* if (network_protocol == IX_NETWORK_AS225) */ {
  145.     SOCK_setpwent(0);
  146.     }
  147.     return 1;
  148. }
  149.  
  150. void
  151. endpwent(void)
  152. {
  153.     register struct ixnet *p = (struct ixnet *)u.u_ixnet;
  154.     register int network_protocol = p->u_networkprotocol;
  155.  
  156.     if (network_protocol == IX_NETWORK_AMITCP) {
  157.     UG_endpwent();
  158.     }
  159.     else /* if (network_protocol == IX_NETWORK_AS225)*/ {
  160.     SOCK_endpwent();
  161.     }
  162. }
  163.  
  164. /* change the AmiTCP password structure to the global format */
  165. static struct passwd *__TCP2InetPwd(struct TCP_passwd *pwd)
  166. {
  167.     u.u_passwd.pw_name = pwd->pw_name;
  168.     u.u_passwd.pw_passwd = pwd->pw_passwd;
  169.     u.u_passwd.pw_uid = pwd->pw_uid;
  170.     u.u_passwd.pw_gid = pwd->pw_gid;
  171.     u.u_passwd.pw_change = time((time_t *)NULL);
  172.     u.u_passwd.pw_class = NULL;
  173.     u.u_passwd.pw_gecos = pwd->pw_gecos;
  174.     u.u_passwd.pw_dir = pwd->pw_dir;
  175.     u.u_passwd.pw_shell = pwd->pw_shell;
  176.     u.u_passwd.pw_expire = (time_t)-1;
  177.     return &u.u_passwd;
  178. }
  179.  
  180. /* change the AS225/INet225's password structure to the global format */
  181. static struct passwd *__AS225InetPwd(struct AS225_passwd *pwd)
  182. {
  183.     u.u_passwd.pw_name = pwd->pw_name;
  184.     u.u_passwd.pw_passwd = pwd->pw_passwd;
  185.     u.u_passwd.pw_uid = pwd->pw_uid;
  186.     u.u_passwd.pw_gid = pwd->pw_gid;
  187.     u.u_passwd.pw_change = time((time_t *)NULL);
  188.     u.u_passwd.pw_class = NULL;
  189.     u.u_passwd.pw_gecos = pwd->pw_gecos;
  190.     u.u_passwd.pw_dir = pwd->pw_dir;
  191.     u.u_passwd.pw_shell = pwd->pw_shell;
  192.     u.u_passwd.pw_expire = (time_t)-1;
  193.     u.u_passwd.pw_change = (time_t)-1;
  194.     return &u.u_passwd;
  195. }
  196.  
  197. #define errno (* u.u_errno)
  198.