osfc2.c revision 78527
11590Srgrimes/*
21590Srgrimes * Copyright (c) 1998 Kungliga Tekniska H�gskolan
31590Srgrimes * (Royal Institute of Technology, Stockholm, Sweden).
41590Srgrimes * All rights reserved.
51590Srgrimes *
61590Srgrimes * Redistribution and use in source and binary forms, with or without
71590Srgrimes * modification, are permitted provided that the following conditions
81590Srgrimes * are met:
91590Srgrimes *
101590Srgrimes * 1. Redistributions of source code must retain the above copyright
111590Srgrimes *    notice, this list of conditions and the following disclaimer.
121590Srgrimes *
131590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141590Srgrimes *    notice, this list of conditions and the following disclaimer in the
151590Srgrimes *    documentation and/or other materials provided with the distribution.
161590Srgrimes *
171590Srgrimes * 3. Neither the name of the Institute nor the names of its contributors
181590Srgrimes *    may be used to endorse or promote products derived from this software
191590Srgrimes *    without specific prior written permission.
201590Srgrimes *
211590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
221590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241590Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
251590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311590Srgrimes * SUCH DAMAGE.
321590Srgrimes */
331590Srgrimes
341590Srgrimes#include "login_locl.h"
351590SrgrimesRCSID("$Id: osfc2.c,v 1.4 2001/02/20 01:44:46 assar Exp $");
361590Srgrimes
371590Srgrimesint
381590Srgrimesdo_osfc2_magic(uid_t uid)
391590Srgrimes{
401590Srgrimes#ifdef HAVE_OSFC2
411590Srgrimes    struct es_passwd *epw;
421590Srgrimes    char *argv[2];
431590Srgrimes
441590Srgrimes    /* fake */
451590Srgrimes    argv[0] = (char*)getprogname();
461590Srgrimes    argv[1] = NULL;
471590Srgrimes    set_auth_parameters(1, argv);
481590Srgrimes
491590Srgrimes    epw = getespwuid(uid);
501590Srgrimes    if(epw == NULL) {
511590Srgrimes	syslog(LOG_AUTHPRIV|LOG_NOTICE,
521590Srgrimes	       "getespwuid failed for %d", uid);
531590Srgrimes	printf("Sorry.\n");
541590Srgrimes	return 1;
551590Srgrimes    }
561590Srgrimes    /* We don't check for auto-retired, foo-retired,
571590Srgrimes       bar-retired, or any other kind of retired accounts
581590Srgrimes       here; neither do we check for time-locked accounts, or
591590Srgrimes       any other kind of serious C2 mumbo-jumbo. We do,
601590Srgrimes       however, call setluid, since failing to do so is not
611590Srgrimes       very good (take my word for it). */
621590Srgrimes
631590Srgrimes    if(!epw->uflg->fg_uid) {
641590Srgrimes	syslog(LOG_AUTHPRIV|LOG_NOTICE,
65	       "attempted login by %s (has no uid)", epw->ufld->fd_name);
66	printf("Sorry.\n");
67	return 1;
68    }
69    setluid(epw->ufld->fd_uid);
70    if(getluid() != epw->ufld->fd_uid) {
71	syslog(LOG_AUTHPRIV|LOG_NOTICE,
72	       "failed to set LUID for %s (%d)",
73	       epw->ufld->fd_name, epw->ufld->fd_uid);
74	printf("Sorry.\n");
75	return 1;
76    }
77#endif /* HAVE_OSFC2 */
78    return 0;
79}
80