1.\" $OpenBSD: authenticate.3,v 1.3 2000/12/24 00:30:46 aaron Exp $ 2.\" 3.\" Copyright (c) 1997 Berkeley Software Design, Inc. All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 1. Redistributions of source code must retain the above copyright 9.\" notice, this list of conditions and the following disclaimer. 10.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" notice, this list of conditions and the following disclaimer in the 12.\" documentation and/or other materials provided with the distribution. 13.\" 3. All advertising materials mentioning features or use of this software 14.\" must display the following acknowledgement: 15.\" This product includes software developed by Berkeley Software Design, 16.\" Inc. 17.\" 4. The name of Berkeley Software Design, Inc. may not be used to endorse 18.\" or promote products derived from this software without specific prior 19.\" written permission. 20.\" 21.\" THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN, INC. ``AS IS'' AND 22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24.\" ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN, INC. BE LIABLE 25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" SUCH DAMAGE. 32.\" 33.\" BSDI $From: authenticate.3,v 2.7 1998/09/03 20:27:20 prb Exp $ 34.Dd March 26, 1997 35.Dt AUTHENTICATE 3 36.Os 37.Sh NAME 38.Nm auth_approval , 39.Nm auth_cat , 40.Nm auth_checknologin , 41.Nm auth_mkvalue , 42.Nm auth_userchallenge , 43.Nm auth_usercheck , 44.Nm auth_userokay , 45.Nm auth_userresponse , 46.Nm auth_verify 47.Nd simplified interface to the BSD Authentication system 48.Sh SYNOPSIS 49.Fd #include <login_cap.h> 50.Fd #include <bsd_auth.h> 51.Ft int 52.Fn auth_userokay "char *name" "char *style" "char *type" "char *password" 53.Ft auth_session_t * 54.Fn auth_userchallenge "char *name" "char *style" "char *type" "char **challengep" 55.Ft auth_session_t * 56.Fn auth_usercheck "char *name" "char *style" "char *type" "char *password" 57.Ft int 58.Fn auth_userresponse "auth_session_t *as" "char *response" "int more" 59.Ft int 60.Fn auth_approval "auth_session_t *as" "login_cap_t *lc" "char *name" "char *type" 61.Ft int 62.Fn auth_cat "char *file" 63.Ft void 64.Fn auth_checknologin "login_cap_t *lc" 65.Ft char * 66.Fn auth_mkvalue "char *value" 67.Ft auth_session_t * 68.Fn auth_verify "auth_session_t *as" "char *style" "char *name" "..." 69.Sh DESCRIPTION 70These functions provide a simplified interface to the BSD Authentication 71system 72.Pq see Xr bsd_auth 3 Ns . 73The 74.Fn auth_userokay 75function provides a single function call interface. 76Provided a user's name in 77.Ar name 78and an optional 79.Ar style , 80.Ar type , 81and 82.Ar password 83the 84.Fn auth_userokay 85function returns a simple yes/no response. 86A return value of 0 implies failure, a non-zero return value implies success. 87If 88.Ar style 89is not 90.Dv NULL 91it specifies the desired style of authentication to be used. 92If it is 93.Dv NULL 94then the default style for the user is used. 95In this case 96.Ar name 97may include the desired style by appending it to the user's name with a 98single colon 99.Pq Sq \: 100as a separator. 101If 102.Ar type 103is not 104.Dv NULL 105then it is used as the authentication type (such as 106.Dq auth-myservice ) . 107If 108.Ar password 109is 110.Dv NULL 111then 112.Fn auth_userokay 113operates in an interactive mode with the user on standard input, output, 114and error. 115If 116.Ar password 117is specified, 118.Fn auth_userokay 119operates in a non-interactive mode and only tests the specified passwords. 120This non-interactive method does not work with challenge-response 121authentication styles. 122.Pp 123The 124.Fn auth_usercheck 125function operates the same as the 126.Fn auth_userokay 127function except that it does not close the BSD Authentication session created. 128Rather than returning the status of the session it returns 129a pointer to the newly created BSD Authentication session. 130.Pp 131The 132.Fn auth_userchallenge 133function takes the same 134.Ar name , style , 135and 136.Ar type 137arguments as does 138.Fn auth_userokay . 139However, rather than authenticating the user, it returns a possible 140challenge in the pointer pointed to by 141.Ar challengep . 142The return value of the function is a pointer to a newly created 143BSD Authentication session. 144This challenge, if not 145.Dv NULL , 146should be displayed to the user. 147In any case, the user should provide a password which is 148the 149.Ar response 150in a call to 151.Fn auth_userresponse. 152In addition to the password, the pointer returned by 153.Fn auth_userchallenge 154should be passed in as 155.Ar as 156and the value of 157.Va more 158should be non-zero if the program wishes to allow more attempts. 159If 160.Va more 161is zero then the session will be closed. 162The 163.Fn auth_userresponse 164function closes the BSD Authentication session and has the same 165return value as 166.Fn auth_userokay . 167.Pp 168The 169.Fn auth_approval 170function calls the approval script for the user of the specified 171.Ar type . 172The string 173.Dq approve- 174will be prepended to 175.Ar type 176if missing. 177The resulting type is used to lookup an entry in the 178.Pa /etc/login.conf 179for the user's class. 180If the entry is missing the generic entry for 181.Dq approve 182will be used. 183The 184.Ar name 185argument will be passed to the approval program as the name of the user. 186The 187.Ar lc 188argument points to a login class structure. 189If it is 190.Dv NULL 191then a login class structure will be looked up for the class of 192user 193.Ar name . 194The 195.Fn auth_approval 196function returns a value of 0 on failure to approve the user. 197.Pp 198Prior to actually calling the approval script, the account's 199expiration time, the associated nologin file, and existence 200of the account's home directory 201.Po 202if 203.Li requirehome 204is set for this class 205.Pc 206are checked. 207Failure on any of these points causes the 208.Fn auth_approval 209function to return a value of 0 and not actually call the approval script. 210.Pp 211The 212.Fn auth_cat 213function opens 214.Ar file 215for reading and copies its contents to standard output. 216It returns 0 if it was unable to open 217.Ar file 218and 1 otherwise. 219.Pp 220The 221.Fn auth_checknologin 222function must be provided with a pointer to a login class. 223If the class has a 224.Dq nologin 225entry defined and it points to a file that can be opened, 226the contents of the file will be copied to standard output and 227.Xr exit 3 228will be called with a value of 1. 229If the class does not have the field 230.Dq ignorenologin 231and the file 232.Pa /etc/nologin 233exists its contents will be copied to standard output and 234.Xr exit 3 235will be called with a value of 1. 236.Pp 237The 238.Fn auth_verify 239function is a front end to the 240.Fn auth_call 241function 242.Pq see Xr auth_subr 3 Ns . 243It will open a BSD Authentication session, if needed, and will set 244the style and user name based on the 245.Ar style 246and 247.Ar name 248arguments, if not 249.Dv NULL . 250The variable arguments are passed to 251.Fn auth_call 252via the 253.Fn auth_set_va_list 254function 255.Pq see Xr auth_subr 3 Ns . 256The, possibly created, BSD Authentication session is returned. 257The 258.Fn auth_getstate 259or 260.Fn auth_close 261function 262.Pq see Xr auth_subr 3 263should be used to determine the outcome of the authentication request. 264.Pp 265The 266.Fn auth_mkvalue 267function takes a null terminated string pointed to by 268.Ar value 269and returns a null terminated string suitable for passing 270back to a calling program on the back channel. 271This function is for use by the login scripts themselves. 272The string returned should be freed by 273.Xr free 3 274when it is no longer needed. 275A value of 276.Dv NULL 277is returned if no memory was available for the new copy of the string. 278.Sh SEE ALSO 279.Xr auth_subr 3 280