/*- * Copyright (c) 1996 by * Sean Eric Fagan * David Nugent * All rights reserved. * * Portions copyright (c) 1995,1997 by * Berkeley Software Design, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, is permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice immediately at the beginning of the file, without modification, * this list of conditions, and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. This work was done expressly for inclusion into FreeBSD. Other use * is permitted provided this notation is included. * 4. Absolutely no warranty of function or purpose is made by the authors. * 5. Modifications may be freely made to this file providing the above * conditions are met. * * Low-level routines relating to the user capabilities database * * $Id: login_auth.c,v 1.6 1997/02/22 15:08:18 peter Exp $ */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef LOGIN_CAP_AUTH /* * Comment from BSDI's authenticate.c module: * NOTE: THIS MODULE IS TO BE DEPRECATED. FUTURE VERSIONS OF BSD/OS WILL * HAVE AN UPDATED API, THOUGH THESE FUNCTIONS WILL CONTINUE TO BE AVAILABLE * FOR BACKWARDS COMPATABILITY */ #define AUTHMAXSPOOL (8 * 1024) /* Max size of authentication data */ #define AUTHCOMM_FD 3 /* Handle used to read/write auth data */ struct rmfiles { struct rmfiles *next; char file[1]; }; struct authopts { struct authopts *next; char opt[1]; }; static char *spoolbuf = NULL; static int spoolidx = 0; static struct rmfiles *rmfirst = NULL; static struct authopts *optfirst = NULL; /* * Setup a known environment for all authentication scripts. */ static char *auth_environ[] = { "PATH=" _PATH_DEFPATH, "SHELL=" _PATH_BSHELL, NULL, }; /* * nextline() * Get the next line from the data buffer collected from * the authentication program. This function relies on the * fact that lines are nul terminated. */ static char * nextline(int *idx) { char *ptr = NULL; if (spoolbuf != NULL && *idx < spoolidx) { ptr = spoolbuf + *idx; *idx += strlen(ptr) + 1; } return ptr; } /* * spooldata() * Read data returned on authentication backchannel and * stuff it into our spool buffer. We also replace \n with nul * to make parsing easier later. */ static int spooldata(int fd) { if (spoolbuf) free(spoolbuf); spoolidx = 0; if (spoolbuf == NULL && (spoolbuf = malloc(AUTHMAXSPOOL)) == NULL) syslog(LOG_ERR, "authbuffer malloc: %m"); else while (spoolidx < sizeof(spoolbuf) - 1) { int r = read(fd, spoolbuf + spoolidx, sizeof(spoolbuf)-spoolidx); char *b; if (r <= 0) { spoolbuf[spoolidx] = '\0'; return 0; } /* * Convert newlines into NULs to allow * easier scanning of the file. */ while ((b = memchr(spoolbuf + spoolidx, '\n', r)) != NULL) *b = '\0'; spoolidx += r; } return -1; } /* * auth_check() * Starts an auth_script() for the given , with a class , * style