1.\" $OpenBSD: auth_subr.3,v 1.3 2001/03/01 20:16:34 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: auth_subr.3,v 2.5 2000/03/30 19:11:27 polk Exp $ 34.Dd March 20, 1997 35.Dt BSD_AUTH 3 36.Os 37.Sh NAME 38.Nm auth_open , 39.Nm auth_call , 40.Nm auth_challenge , 41.Nm auth_check_change , 42.Nm auth_check_expire , 43.Nm auth_clean , 44.Nm auth_close , 45.Nm auth_clrenv , 46.Nm auth_clroption , 47.Nm auth_clroptions , 48.Nm auth_getitem 49.Nm auth_getstate , 50.Nm auth_getvalue , 51.Nm auth_set_va_list , 52.Nm auth_setdata , 53.Nm auth_setenv , 54.Nm auth_setitem 55.Nm auth_setoption , 56.Nm auth_setpwd , 57.Nm auth_setstate 58.Nd interface to the BSD Authentication system 59.Sh SYNOPSIS 60.Fd #include <login_cap.h> 61.Fd #include <bsd_auth.h> 62.Ft auth_session_t * 63.Fn auth_open 64.Ft int 65.Fn auth_close "auth_session_t *as" 66.Ft int 67.Fn auth_call "auth_session_t *as" "char *path" "..." 68.Ft char * 69.Fn auth_challenge "auth_session_t *as" 70.Ft quad_t 71.Fn auth_check_change "auth_session_t *as" 72.Ft quad_t 73.Fn auth_check_expire "auth_session_t *as" 74.Ft void 75.Fn auth_clean "auth_session_t *as" 76.Ft void 77.Fn auth_clrenv "auth_session_t *as" 78.Ft void 79.Fn auth_clroption "auth_session_t * as" "char *name" 80.Ft void 81.Fn auth_clroptions "auth_session_t *as" 82.Ft char * 83.Fn auth_getitem "auth_session_t *as" "auth_item_t item" 84.Ft int 85.Fn auth_getstate "auth_session_t *as" 86.Ft char * 87.Fn auth_getvalue "auth_session_t *as" "char *what" 88.Ft void 89.Fn auth_set_va_list "auth_session_t *as" "va_list ap" 90.Ft int 91.Fn auth_setdata "auth_session_t *as" "void *ptr" "size_t len" 92.Ft void 93.Fn auth_setenv "auth_session_t *as" 94.Ft int 95.Fn auth_setitem "auth_session_t *as" "auth_item_t item" "char *value" 96.Ft int 97.Fn auth_setoption "auth_session_t *as" "char *name" "char *value" 98.Ft int 99.Fn auth_setpwd "auth_session_t *as" "struct passwd *pwd" 100.Ft int 101.Fn auth_setstate "auth_session_t *as" "int state" 102.Sh DESCRIPTION 103These functions provide the lower level interface to the BSD 104Authentication system. 105They all operate on a BSD Authentication session pointer, 106.Fa as , 107which is returned by 108.Fn auth_open . 109The session pointer 110must be passed to all other BSD Authentication functions called. 111The 112.Fn auth_open 113function returns 114.Dv NULL 115if it was unable to allocate memory for the session. 116The session is terminated by the 117.Fn auth_close 118function, 119which also sets any environment variables requested by the login script 120(assuming the user was not rejected) or removes files created by the 121login script if the authentication was not successful. 122It returns the final state of the authentication request. 123A return value of 0 implies the user was not authenticated. 124A non-zero return value is made up the 1 or more of the following values 125ORed together: 126.Bl -tag -width AUTH_ROOTOKAYXX 127.It Li AUTH_OKAY 128The user was authenticated. 129.It Li AUTH_ROOTOKAY 130The user was authenticated with a root instance. 131.It Li AUTH_SECURE 132The user was authenticated via a mechanism which is not subject to 133eavesdropping attacks (such as provided by token cards). 134.El 135.sp 136The full state of the session is returned by the 137.Fn auth_getstate 138function. 139In addition to the values above, it also may contain the bits: 140.Bl -tag -width AUTH_ROOTOKAYXX 141.It Li AUTH_SILENT 142Do not report an error, the user was not authenticated for access and 143was not expected to be. 144This is returned by login scripts that allow changing of the users password, 145for instance. 146This value is stripped off for normal returns. 147.It Li AUTH_CHALLENGE 148The user was not authenticated for access and a challenge was issued. 149The challenge should be displayed to the user, a response retrieved, 150and the result verified. 151This value is stripped off for normal returns. 152.It Li AUTH_EXPIRED 153The user's account has expired. 154.It Li AUTH_PWEXPIRED 155The user's password has expired and needs to be changed. 156.El 157.sp 158A session may be cleaned 159by calling 160.Fn auth_clean . 161This function causes any files created by a login script in this 162session and clears all state associated with this session. 163It is not necessary to call 164.Fn auth_clean 165if 166.Fn auth_close 167is called. 168.sp 169The remaining functions are described in alphabetical order. 170.sp 171The fundamental function for doing BSD Authentication is 172.Fn auth_call . 173In addition to the pointer to the BSD Authentication session, it takes 174the following parameters: 175.Bl -tag -width indent 176.It Ar path 177The full path name of the login script to run. 178The call will fail if 179.Ar path 180does not pass the requirements of the 181.Xr secure_path 3 182function. 183.It Ar ... 184The remaining arguments, which should be of type 185.Ft char * 186and terminated with a 187.Dv NULL 188are passed to the login script at the end of the command line. 189.El 190.Pp 191The 192.Fn auth_call 193function, after verifying the 194.Ar path , 195creates a bi-directional pipe (socketpair) which is located on 196file descriptor 3 for the child (the login script). 197This is known as the 198.Dq back channel . 199The actual command line passed to the child is made up of 2003 parts. 201The parameters passed to 202.Fn auth_call 203following 204.Ar path 205have appended to them any arguments specified by the 206.Fn auth_set_va_list 207function. 208These are typically the variable arguments passed to the function 209that calls 210.Fn auth_call . 211Any option values set by the 212.Fn auth_setoption 213function are inserted between the first argument (the command 214name) and the second argument with a preceding 215.Fl v 216flag. 217The name and value are separated by an 218.Sq = : 219.sp 220.Li Ta Fl v Ar name=value 221 222.sp 223Once the login script has been spawned, any data specified by the 224.Fn auth_setdata 225is written to the back channel. 226Multiple blocks of data may have been specified and they will be sent 227in the same order they were specified. 228As the data is sent, the storage for the data is zeroed out and then freed 229(the data is zeroed out since it may contain sensitive information, 230such as a password). 231Once any data is written out, 232.Fn auth_call 233reads up to 8192 bytes of data from the back channel. 234The state of the session is determined from this data (see 235.Xr login.conf 5 236for details). 237If the login script exits with a 0 and does not specify any return state 238on the back channel, the state prior to the call to 239.Fn auth_call 240is retained. 241.sp 242The data read from the back channel is also used by the 243.Fn auth_getvalue 244and 245.Fn auth_close 246functions. 247Subsequent calls to 248.Fn auth_call 249will cause this data to be lost and overwritten with the new data read 250from the new call. 251.sp 252The environment passed to the login script by 253.Fn auth_call 254only contains two values: 255.Ev PATH 256and 257.Ev SHELL . 258The 259.Ev PATH 260is set to the default path ( 261.Pa /bin 262and 263.Pa /usr/bin ) 264while the 265.Ev SHELL 266is set to the default system shell ( 267.Pa /bin/sh ) . 268.sp 269The 270.Fn auth_challenge 271function queries the login script defined by the current 272.Ar style 273for a challenge for the user specified by 274.Ar name . 275(See below for the setting of the 276.Ar style 277and 278.Ar name ) . 279It internally uses the 280.Fn auth_call 281function. 282The generated challenge is returned. 283.Dv NULL 284is returned on error or if no challenge was generated. 285The challenge can also be extracted by the 286.Fn auth_getchallenge 287function, which simply returns the last challenge generated 288for this session. 289.sp 290The 291.Fn auth_check_change 292and 293.Fn auth_check_expire 294functions check the password expiration (change) and account expiration 295times. 296They return 0 if no change or expiration time is set for the account. 297They return a negative value of how many seconds have passed since 298the password or account expired. 299In this case the state of the session is marked with either 300.Li AUTH_PWEXPIRED 301or 302.Li AUTH_EXPIRED 303as well as clearing any bits which would indicate the authentication was 304successful. 305If the password or account has not expired they return the number of 306seconds left until the account does expire. 307The return value of -1 can either indicate the password or account 308just expired or that no password entry was set for the current session. 309.sp 310The 311.Fn auth_clrenv 312function clears any requests set by a login script for 313environment variables to be set. 314.sp 315The 316.Fn auth_clroption 317function clears the previously set option 318.Fa name . 319.sp 320The 321.Fn auth_clroptions 322function clears all previously set options. 323.sp 324The 325.Fn auth_getitem 326function returns the value of of 327.Fa item . 328The 329.Fa item 330may be one of: 331.Bl -tag -width AUTH_ROOTOKAYXX 332.It Li AUTH_CHALLENGE 333The latest challenge, if any, set for the session. 334.It Li AUTH_CLASS 335The class of the user, as defined by the 336.Pa /etc/login.conf 337file. 338This value is not directly used by BSD Authentication, rather, it is 339passed to the login scripts for their possible use. 340.It Li AUTH_INTERACTIVE 341If set to any value then the session is tagged as interactive. 342If not set the session is not interactive. 343When the value is requested it is always either 344.Dv NULL 345or 346.Dq True . 347The auth subroutines may choose to provide additional information to 348standard output or standard error when the session is interactive. 349There is no functional change in the operation of the subroutines. 350.It Li AUTH_NAME 351The name of the user being authenticated. 352The name should include the instance, if any, that is being requested. 353.It Li AUTH_SERVICE 354The service requesting the authentication. 355Initially it is set to the default service which provides the traditional 356interactive service. 357.It Li AUTH_STYLE 358The style of authentication being performed, as defined by the 359.Pa /etc/login.conf file. 360The style determines which login script should actually be used. 361.El 362.sp 363The 364.Fn auth_getvalue 365function returns the value, if any, associated with the specified internal 366variable 367.Ar what. 368These variables are set by login scripts. 369When a new login script is run 370(by the 371.Fn auth_call function) 372the values from the previous login script are lost. 373(See 374.Xr login.conf 5 375for details on internal variables.) 376.sp 377The 378.Fn auth_set_va_list 379function establishes a variable argument list to be used by the 380.Fn auth_call 381function. 382It is intended to be used by functions which need to call 383.Fn auth_call 384but take a variable number of arguments themselves. 385Since the arguments are not copied, the call to 386.Fn auth_call 387must be placed within the scope of 388.Fa ap . 389The 390.Fn auth_call 391function will call 392.Xr va_end 3 393on 394.Fa ap . 395.sp 396The 397.Fn auth_setdata 398function makes a copy of 399.Fa len 400bytes of data pointed to by 401.Fa ptr 402for use by 403.Fn auth_call . 404The data will be passed on the back channel to the next login script called. 405.sp 406The 407.Fn auth_setenv 408function adds/deletes any environment variables requested by the 409login script to the current environment. 410.sp 411The 412.Fn auth_setitem 413function assigns 414.Fa value 415to the specified 416.Fa item . 417The items are described above with the 418.Fn auth_getitem 419function. 420In addition, if 421.Fa item 422is 423.Li AUTH_ALL 424and 425.Fa value 426is 427.Dv NULL 428then all items are cleared. 429.sp 430The 431.Fn auth_setoption 432function requests that the option 433.Fa name 434be set with the value of 435.Fa value 436when a script is executed by 437.Fn auth_call . 438The actual arguments to the script will be placed at the beginning 439of the argument vector. 440For each option two arguments will be issued: 441.Li -v name=value . 442.sp 443The function 444.Fn auth_setpwd 445establishes the password file entry for the authentication session. 446If the name has already been set by 447.Fn auth_setitem 448then the 449.Fa pwd 450argument may be 451.Dv NULL , 452else it must be the password entry to use. 453.sp 454The function 455.Fn auth_setstate 456sets the sessions state to 457.Fa state. 458Typically this is either 459.Li AUTH_OKAY 460or 0. 461.Sh SEE ALSO 462.Xr authenticate 3 , 463.Xr login_cap 3 , 464.Xr login.conf 5 465