1/* tcalou.c 2 Find callout login name and password from Taylor UUCP configuration files. 3 4 Copyright (C) 1992, 1993 Ian Lance Taylor 5 6 This file is part of the Taylor UUCP uuconf library. 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU Library General Public License 10 as published by the Free Software Foundation; either version 2 of 11 the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, but 14 WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 Library General Public License for more details. 17 18 You should have received a copy of the GNU Library General Public 19 License along with this library; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 21 22 The author of the program may be contacted at ian@airs.com. 23 */ 24 25#include "uucnfi.h" 26 27#if USE_RCS_ID 28const char _uuconf_tcalou_rcsid[] = "$Id: tcalou.c,v 1.9 2002/03/05 19:10:42 ian Rel $"; 29#endif 30 31#include <errno.h> 32 33static int icsys P((pointer pglobal, int argc, char **argv, pointer pvar, 34 pointer pinfo)); 35 36/* Find the callout login name and password for a system from the 37 Taylor UUCP configuration files. */ 38 39int 40uuconf_taylor_callout (pglobal, qsys, pzlog, pzpass) 41 pointer pglobal; 42 const struct uuconf_system *qsys; 43 char **pzlog; 44 char **pzpass; 45{ 46 struct sglobal *qglobal = (struct sglobal *) pglobal; 47 boolean flookup; 48 struct uuconf_cmdtab as[2]; 49 char **pz; 50 int iret; 51 pointer pinfo; 52 53 *pzlog = NULL; 54 *pzpass = NULL; 55 56 flookup = FALSE; 57 58 if (qsys->uuconf_zcall_login != NULL) 59 { 60 if (strcmp (qsys->uuconf_zcall_login, "*") == 0) 61 flookup = TRUE; 62 else 63 { 64 *pzlog = strdup (qsys->uuconf_zcall_login); 65 if (*pzlog == NULL) 66 { 67 qglobal->ierrno = errno; 68 return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO; 69 } 70 } 71 } 72 73 if (qsys->uuconf_zcall_password != NULL) 74 { 75 if (strcmp (qsys->uuconf_zcall_password, "*") == 0) 76 flookup = TRUE; 77 else 78 { 79 *pzpass = strdup (qsys->uuconf_zcall_password); 80 if (*pzpass == NULL) 81 { 82 qglobal->ierrno = errno; 83 if (*pzlog != NULL) 84 { 85 free ((pointer) *pzlog); 86 *pzlog = NULL; 87 } 88 return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO; 89 } 90 } 91 } 92 93 if (! flookup) 94 { 95 if (*pzlog == NULL && *pzpass == NULL) 96 return UUCONF_NOT_FOUND; 97 return UUCONF_SUCCESS; 98 } 99 100 as[0].uuconf_zcmd = qsys->uuconf_zname; 101 as[0].uuconf_itype = UUCONF_CMDTABTYPE_FN | 0; 102 if (*pzlog == NULL) 103 as[0].uuconf_pvar = (pointer) pzlog; 104 else 105 as[0].uuconf_pvar = NULL; 106 as[0].uuconf_pifn = icsys; 107 108 as[1].uuconf_zcmd = NULL; 109 110 if (*pzpass == NULL) 111 pinfo = (pointer) pzpass; 112 else 113 pinfo = NULL; 114 115 iret = UUCONF_SUCCESS; 116 117 for (pz = qglobal->qprocess->pzcallfiles; *pz != NULL; pz++) 118 { 119 FILE *e; 120 121 e = fopen (*pz, "r"); 122 if (e == NULL) 123 { 124 if (FNO_SUCH_FILE ()) 125 continue; 126 qglobal->ierrno = errno; 127 iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO; 128 break; 129 } 130 131 iret = uuconf_cmd_file (pglobal, e, as, pinfo, 132 (uuconf_cmdtabfn) NULL, 0, 133 qsys->uuconf_palloc); 134 (void) fclose (e); 135 136 if (iret != UUCONF_SUCCESS) 137 break; 138 if (*pzlog != NULL) 139 break; 140 } 141 142 if (iret != UUCONF_SUCCESS) 143 { 144 qglobal->zfilename = *pz; 145 return iret | UUCONF_ERROR_FILENAME; 146 } 147 148 if (*pzlog == NULL && *pzpass == NULL) 149 return UUCONF_NOT_FOUND; 150 151 return UUCONF_SUCCESS; 152} 153 154/* Copy the login name and password onto the heap and set the 155 pointers. The pzlog argument is passed in pvar, and the pzpass 156 argument is passed in pinfo. */ 157 158static int 159icsys (pglobal, argc, argv, pvar, pinfo) 160 pointer pglobal; 161 int argc; 162 char **argv; 163 pointer pvar; 164 pointer pinfo; 165{ 166 struct sglobal *qglobal = (struct sglobal *) pglobal; 167 char **pzlog = (char **) pvar; 168 char **pzpass = (char **) pinfo; 169 170 if (argc < 2 || argc > 3) 171 return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT; 172 173 if (pzlog != NULL) 174 { 175 *pzlog = strdup (argv[1]); 176 if (*pzlog == NULL) 177 { 178 qglobal->ierrno = errno; 179 return (UUCONF_MALLOC_FAILED 180 | UUCONF_ERROR_ERRNO 181 | UUCONF_CMDTABRET_EXIT); 182 } 183 } 184 185 if (pzpass != NULL) 186 { 187 if (argc < 3) 188 *pzpass = strdup (""); 189 else 190 *pzpass = strdup (argv[2]); 191 if (*pzpass == NULL) 192 { 193 qglobal->ierrno = errno; 194 if (pzlog != NULL) 195 { 196 free ((pointer) *pzlog); 197 *pzlog = NULL; 198 } 199 return (UUCONF_MALLOC_FAILED 200 | UUCONF_ERROR_ERRNO 201 | UUCONF_CMDTABRET_EXIT); 202 } 203 } 204 205 return UUCONF_CMDTABRET_EXIT; 206} 207