Get rid of warnings about undefined crypt() and assignment in if().
[ircu2.10.12-pk.git] / ircd / iauth.c
1 /************************************************************************
2  *   IRC - Internet Relay Chat, src/listener.c
3  *   Copyright (C) 2001 Perry Lorier <isomer@coders.net>
4  *
5  *   This program is free software; you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation; either version 1, or (at your option)
8  *   any later version.
9  *
10  *   This program 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
13  *   GNU General Public License for more details.
14  *
15  *   You should have received a copy of the GNU General Public License
16  *   along with this program; if not, write to the Free Software
17  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  *  $Id$
20  */
21 #include "config.h"
22 #include "iauth.h"
23 #include <sys/types.h>
24 #include <sys/socket.h>
25
26 struct Iauth_Outstanding {
27         struct iauth_outstanding *next;
28         int client_id;
29 }
30
31 static struct Iauth_Outstanding *iauth_freelist=NULL;
32 struct Iauth IauthPollList = NULL;
33
34 void iauth_new(char *service)
35 {
36         /* TODO: Check to see if the service is a hostname, and if so
37          *       connect to it like hybrid does.  Hybrid uses a blocking
38          *       gethostbyname here (bletch!!).  On the other hand a
39          *       nonblocking solutions likely to be worse....
40          */     
41         struct Iauth* tmp = (struct Iauth *)malloc(sizeof(struct Iauth));
42         int fd[2];
43         tmp->next = IauthPollList;
44         tmp->fd = 0;
45         tmp->service=strdup(service);
46         tmp->ref_count=0;
47         tmp->active=0;
48         if (socketpair(domain,type,protocol,fd)<0) {
49                 free(tmp->service);
50                 free(tmp);
51                 return;         
52         }
53         tmp->fd=fd[0];
54         if (0 == fork()) {
55                 (void)close(pi[0]);
56                 (void)dup2(pi[1],0);
57                 (void)dup2(pi[1],1);
58                 for (i = 2; i < MAXCONNECTIONS; i++)
59                        (void)close(i);
60                 if (pi[1] != 0 && pi[1] != 1)
61                       (void)close(pi[1]);
62                 (void)execlp(tmp->service, tmp->service, 0);
63                 exit(-1);
64         } else {
65                 /* TODO: Put the real servername in there */
66                 (void)write(tmp->fd,"Server undernet.org 1.1");
67         }
68         IauthPollList=tmp;
69 }