diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2009-05-29 21:22:58 +0000 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2009-05-29 21:22:58 +0000 |
commit | f91b33e7b87b0447029e9b7593b796c3b9d0d0b0 (patch) | |
tree | cb66705231e6c4480c62c3b690867c426cf2763b /pam/common.h | |
parent | 7c32d0121c95bbb05ab064b29bf7ec2ba5defc00 (diff) |
refactor protocol reading and writing macros to the common directory, use more logical names and in the PAM module no longer use NSS status codes (import of r887 from nss-pam-ldapd)
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-ldapd@904 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'pam/common.h')
-rw-r--r-- | pam/common.h | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/pam/common.h b/pam/common.h new file mode 100644 index 0000000..32c6d88 --- /dev/null +++ b/pam/common.h @@ -0,0 +1,84 @@ +/* + common.h - common functions for PAM lookups + + Copyright (C) 2009 Arthur de Jong + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA +*/ + +#ifndef _PAM_COMMON_H +#define _PAM_COMMON_H 1 + +#include <stdio.h> + +#include "nslcd.h" +#include "common/nslcd-prot.h" +#include "compat/attrs.h" + +/* These are macros for handling read and write problems, they are + PAM specific due to the return code so are defined here. They + genrally close the open file, set an error code and return with + an error status. */ + +/* Macro is called to handle errors in opening a client connection. */ +#define ERROR_OUT_OPENERROR \ + return PAM_AUTHINFO_UNAVAIL; + +/* Macro is called to handle errors on read operations. */ +#define ERROR_OUT_READERROR(fp) \ + (void)tio_close(fp); \ + fp=NULL; \ + return PAM_AUTHINFO_UNAVAIL; + +/* Macro is called to handle problems with too small a buffer. */ +#define ERROR_OUT_BUFERROR(fp) \ + return PAM_SYSTEM_ERR; + +/* This macro is called if there was a problem with a write + operation. */ +#define ERROR_OUT_WRITEERROR(fp) \ + ERROR_OUT_READERROR(fp) + +/* This macro is called if the read status code is not + NSLCD_RESULT_BEGIN. */ +#define ERROR_OUT_NOSUCCESS(fp) \ + (void)tio_close(fp); \ + fp=NULL; \ + return PAM_USER_UNKNOWN; + +/* This is a generic PAM request generation macro. The action + parameter is the NSLCD_ACTION_.. action, the writefn is the + operation for writing the parameter and readfn is the function + name for reading a single result entry. The function is assumed + to have result, buffer, buflen and errnop parameters that define + the result structure, the user buffer with length and the + errno to return. This macro should be called through some of + the customized ones below. */ +#define PAM_REQUEST(action,writefn,readfn) \ + TFILE *fp; \ + int32_t tmpint32; \ + int retv; \ + /* open socket and write request */ \ + NSLCD_REQUEST(fp,action,writefn); \ + /* read response */ \ + READ_RESPONSE_CODE(fp); \ + retv=readfn; \ + /* close socket and we're done */ \ + if (retv==PAM_SUCCESS) \ + (void)tio_close(fp); \ + return retv; + +#endif /* not _PAM_COMMON_H */ |