1 /* $OpenBSD: login.c,v 1.10 2012/06/01 01:43:19 dlg Exp $ */
4 * Copyright (c) 1995 Berkeley Software Design, Inc. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Berkeley Software Design,
18 * 4. The name of Berkeley Software Design, Inc. may not be used to endorse
19 * or promote products derived from this software without specific prior
22 * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN, INC. ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN, INC. BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * BSDI $From: login_passwd.c,v 1.11 1997/08/08 18:58:24 prb Exp $
42 main(int argc
, char **argv
)
44 int opt
, mode
= 0, ret
, lastchance
= 0;
45 char *username
, *password
= NULL
;
47 int arg_login
= 0, arg_notickets
= 0;
48 char invokinguser
[LOGIN_NAME_MAX
];
49 char *wheel
= NULL
, *class = NULL
;
51 invokinguser
[0] = '\0';
53 setpriority(PRIO_PROCESS
, 0, 0);
55 openlog(NULL
, LOG_ODELAY
, LOG_AUTH
);
57 while ((opt
= getopt(argc
, argv
, "ds:v:")) != -1) {
62 case 's': /* service */
63 if (strcmp(optarg
, "login") == 0)
65 else if (strcmp(optarg
, "challenge") == 0)
66 mode
= MODE_CHALLENGE
;
67 else if (strcmp(optarg
, "response") == 0)
70 syslog(LOG_ERR
, "%s: invalid service", optarg
);
75 if (strncmp(optarg
, "wheel=", 6) == 0)
77 else if (strncmp(optarg
, "lastchance=", 11) == 0)
78 lastchance
= (strcmp(optarg
+ 11, "yes") == 0);
79 else if (strcmp(optarg
, "login=yes") == 0)
81 else if (strcmp(optarg
, "notickets=yes") == 0)
83 else if (strncmp(optarg
, "invokinguser=", 13) == 0)
84 snprintf(invokinguser
, sizeof(invokinguser
),
86 /* Silently ignore unsupported variables */
89 syslog(LOG_ERR
, "usage error1");
94 switch (argc
- optind
) {
96 class = argv
[optind
+ 1];
99 username
= argv
[optind
];
102 syslog(LOG_ERR
, "usage error2");
106 if (back
== NULL
&& (back
= fdopen(3, "r+")) == NULL
) {
107 syslog(LOG_ERR
, "reopening back channel: %m");
112 * Read password, either as from the terminal or if the
113 * response mode is active from the caller program.
115 * XXX This is completely ungrokkable, and should be rewritten.
118 case MODE_RESPONSE
: {
122 while (++count
< sizeof(response
) &&
123 read(3, &response
[count
], (size_t)1) == (ssize_t
)1) {
124 if (response
[count
] == '\0' && ++mode
== 2)
126 if (response
[count
] == '\0' && mode
== 1) {
127 password
= response
+ count
+ 1;
131 syslog(LOG_ERR
, "protocol error on back channel");
138 password
= getpass("Password:");
141 fprintf(back
, BI_AUTH
"\n");
145 syslog(LOG_ERR
, "%d: unknown mode", mode
);
152 ret
= krb5_login(username
, invokinguser
, password
, arg_login
,
153 !arg_notickets
, class);
157 ret
= pwd_login(username
, password
, wheel
, lastchance
, class);
160 if (password
!= NULL
)
161 memset(password
, 0, strlen(password
));
163 fprintf(back
, BI_REJECT
"\n");