summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2012-12-22 21:38:26 +0000
committerArthur de Jong <arthur@arthurdejong.org>2012-12-22 21:38:26 +0000
commitc7bb19c55c7a902e25bdd33b0d49a2ddcf62e07a (patch)
treeb3a75ef2719bc2f334041460fd21fbdf86a23a82 /compat
parentd336cd6b429f8ce40c58ea287f79bbc7c23d0966 (diff)
update C coding style to a more commonly used style
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd@1873 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'compat')
-rw-r--r--compat/attrs.h22
-rw-r--r--compat/daemon.c44
-rw-r--r--compat/daemon.h4
-rw-r--r--compat/ether.c18
-rw-r--r--compat/ether.h6
-rw-r--r--compat/getopt_long.c52
-rw-r--r--compat/getopt_long.h6
-rw-r--r--compat/getpeercred.c72
-rw-r--r--compat/getpeercred.h4
-rw-r--r--compat/ldap_compat.h16
-rw-r--r--compat/ldap_initialize.c26
-rw-r--r--compat/ldap_passwd_s.c50
-rw-r--r--compat/nss_compat.h21
-rw-r--r--compat/pam_compat.h25
-rw-r--r--compat/pam_get_authtok.c56
-rw-r--r--compat/pam_prompt.c35
-rw-r--r--compat/socket.h2
-rw-r--r--compat/strndup.c12
-rw-r--r--compat/strndup.h4
19 files changed, 243 insertions, 232 deletions
diff --git a/compat/attrs.h b/compat/attrs.h
index 0bc0f30..daffd13 100644
--- a/compat/attrs.h
+++ b/compat/attrs.h
@@ -1,7 +1,7 @@
/*
attrs.h - wrapper macros for the gcc __attribute__(()) directive
- Copyright (C) 2007, 2008 Arthur de Jong
+ Copyright (C) 2007, 2008, 2012 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
@@ -23,7 +23,7 @@
#define COMPAT__ATTRS_H 1
/* macro for testing the version of GCC */
-#define GCC_VERSION(major,minor) \
+#define GCC_VERSION(major, minor) \
((__GNUC__ > (major)) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
/* These are macros to use some gcc-specific flags in case the're available
@@ -34,7 +34,7 @@
/* this is used to flag function parameters that are not used in the function
body. */
-#if GCC_VERSION(3,0)
+#if GCC_VERSION(3, 0)
#define UNUSED(x) x __attribute__((__unused__))
#else
#define UNUSED(x) x
@@ -42,16 +42,16 @@
/* this is used to add extra format checking to the function calls as if this
was a printf()-like function */
-#if GCC_VERSION(3,0)
-#define LIKE_PRINTF(format_idx,arg_idx) \
- __attribute__((__format__(__printf__,format_idx,arg_idx)))
+#if GCC_VERSION(3, 0)
+#define LIKE_PRINTF(format_idx, arg_idx) \
+ __attribute__((__format__(__printf__, format_idx, arg_idx)))
#else
-#define LIKE_PRINTF(format_idx,arg_idx) /* no attribute */
+#define LIKE_PRINTF(format_idx, arg_idx) /* no attribute */
#endif
/* indicates that the function is "pure": it's result is purely based on
the parameters and has no side effects or used static data */
-#if GCC_VERSION(3,0)
+#if GCC_VERSION(3, 0)
#define PURE __attribute__((__pure__))
#else
#define PURE /* no attribute */
@@ -59,21 +59,21 @@
/* the function returns a new data structure that has been freshly
allocated */
-#if GCC_VERSION(3,0)
+#if GCC_VERSION(3, 0)
#define LIKE_MALLOC __attribute__((__malloc__))
#else
#define LIKE_MALLOC /* no attribute */
#endif
/* the function's return value should be used by the caller */
-#if GCC_VERSION(3,4)
+#if GCC_VERSION(3, 4)
#define MUST_USE __attribute__((__warn_unused_result__))
#else
#define MUST_USE /* no attribute */
#endif
/* the function's return value should be used by the caller */
-#if GCC_VERSION(2,5)
+#if GCC_VERSION(2, 5)
#define NORETURN __attribute__((__noreturn__))
#else
#define NORETURN /* no attribute */
diff --git a/compat/daemon.c b/compat/daemon.c
index cd8e0f3..e3d5aea 100644
--- a/compat/daemon.c
+++ b/compat/daemon.c
@@ -1,7 +1,7 @@
/*
daemon.c - implementation of daemon() for systems that lack it
- Copyright (C) 2002, 2003, 2008 Arthur de Jong
+ Copyright (C) 2002, 2003, 2008, 2012 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
@@ -26,46 +26,46 @@
#include <sys/stat.h>
#include <fcntl.h>
-int daemon(int nochdir,int noclose)
+int daemon(int nochdir, int noclose)
{
/* change directory */
if (!nochdir)
- if (chdir("/")!=0)
+ if (chdir("/") != 0)
return -1;
/* fork() and exit() to detach from the parent process */
switch (fork())
{
- case 0: /* we are the child */
- break;
- case -1: /* we are the parent, but have an error */
- return -1;
- default: /* we are the parent and we're done*/
- _exit(0);
+ case 0: /* we are the child */
+ break;
+ case -1: /* we are the parent, but have an error */
+ return -1;
+ default: /* we are the parent and we're done */
+ _exit(0);
}
/* become process leader */
- if (setsid()<0)
+ if (setsid() < 0)
{
return -1;
}
/* fork again so we cannot allocate a pty */
switch (fork())
{
- case 0: /* we are the child */
- break;
- case -1: /* we are the parent, but have an error */
- return -1;
- default: /* we are the parent and we're done*/
- _exit(0);
+ case 0: /* we are the child */
+ break;
+ case -1: /* we are the parent, but have an error */
+ return -1;
+ default: /* we are the parent and we're done */
+ _exit(0);
}
/* close stdin, stdout and stderr and reconnect to /dev/null */
if (!noclose)
{
- close(0); /* stdin */
- close(1); /* stdout */
- close(2); /* stderr */
- open("/dev/null",O_RDWR); /* stdin, fd=0 */
- dup(0); /* stdout, fd=1 */
- dup(0); /* stderr, fd=2 */
+ close(0); /* stdin */
+ close(1); /* stdout */
+ close(2); /* stderr */
+ open("/dev/null", O_RDWR); /* stdin, fd=0 */
+ dup(0); /* stdout, fd=1 */
+ dup(0); /* stderr, fd=2 */
}
return 0;
}
diff --git a/compat/daemon.h b/compat/daemon.h
index 5a2b02a..0de27cc 100644
--- a/compat/daemon.h
+++ b/compat/daemon.h
@@ -1,7 +1,7 @@
/*
daemon.h - definition of daemon() for systems that lack it
- Copyright (C) 2002, 2003, 2008, 2011 Arthur de Jong
+ Copyright (C) 2002, 2003, 2008, 2011, 2012 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
@@ -28,7 +28,7 @@
/* we define daemon() here because on some platforms the function is
undefined: deamonize process, optionally chdir to / and optionally
close stdin, strdout and stderr and redirect them to /dev/null */
-int daemon(int nochdir,int noclose);
+int daemon(int nochdir, int noclose);
#endif /* not HAVE_DECL_DAEMON */
#endif /* not COMPAT__DAEMON_H */
diff --git a/compat/ether.c b/compat/ether.c
index ec42909..7204b9d 100644
--- a/compat/ether.c
+++ b/compat/ether.c
@@ -1,7 +1,7 @@
/*
ether.c - useful ethernet functions for systems lacking those
- Copyright (C) 2008, 2009, 2010 Arthur de Jong
+ Copyright (C) 2008, 2009, 2010, 2012 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
@@ -36,25 +36,25 @@
/* these functions are not really reentrant */
#ifndef HAVE_ETHER_NTOA_R
-char *ether_ntoa_r(const struct ether_addr *addr,char *buf)
+char *ether_ntoa_r(const struct ether_addr *addr, char *buf)
{
char *tmp;
- tmp=ether_ntoa(addr);
- if (tmp==NULL)
+ tmp = ether_ntoa(addr);
+ if (tmp == NULL)
return NULL;
- strcpy(buf,tmp);
+ strcpy(buf, tmp);
return buf;
}
#endif /* not HAVE_ETHER_NTOA_R */
#ifndef HAVE_ETHER_ATON_R
-struct ether_addr *ether_aton_r(const char *asc,struct ether_addr *addr)
+struct ether_addr *ether_aton_r(const char *asc, struct ether_addr *addr)
{
struct ether_addr *tmp;
- tmp=ether_aton(asc);
- if (tmp==NULL)
+ tmp = ether_aton(asc);
+ if (tmp == NULL)
return NULL;
- memcpy(addr,tmp,sizeof(struct ether_addr));
+ memcpy(addr, tmp, sizeof(struct ether_addr));
return addr;
}
#endif /* not HAVE_ETHER_ATON_R */
diff --git a/compat/ether.h b/compat/ether.h
index ac328da..4528517 100644
--- a/compat/ether.h
+++ b/compat/ether.h
@@ -1,7 +1,7 @@
/*
ether.h - ethernet definitions for systems lacking those
- Copyright (C) 2008, 2010 Arthur de Jong
+ Copyright (C) 2008, 2010, 2011, 2012 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
@@ -38,11 +38,11 @@ struct ether_addr {
#endif /* not HAVE_STRUCT_ETHER_ADDR */
#ifndef HAVE_ETHER_NTOA_R
-char *ether_ntoa_r(const struct ether_addr *addr,char *buf);
+char *ether_ntoa_r(const struct ether_addr *addr, char *buf);
#endif /* not HAVE_ETHER_NTOA_R */
#ifndef HAVE_ETHER_ATON_R
-struct ether_addr *ether_aton_r(const char *asc,struct ether_addr *addr);
+struct ether_addr *ether_aton_r(const char *asc, struct ether_addr *addr);
#endif /* not HAVE_ETHER_ATON_R */
#ifdef HAVE_ETHER_NTOA
diff --git a/compat/getopt_long.c b/compat/getopt_long.c
index a276dd5..eba9079 100644
--- a/compat/getopt_long.c
+++ b/compat/getopt_long.c
@@ -1,7 +1,7 @@
/*
getopt_long.c - implementation of getopt_long() for systems that lack it
- Copyright (C) 2001, 2002, 2008 Arthur de Jong
+ Copyright (C) 2001, 2002, 2008, 2012 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
@@ -31,55 +31,53 @@
to options and options following filenames is not quite right, allso
minimal error checking is provided
*/
-int getopt_long(int argc,char * const argv[],
+int getopt_long(int argc, char *const argv[],
const char *optstring,
- const struct option *longopts,int *longindex)
+ const struct option *longopts, int *longindex)
{
- int i; /* for looping through options */
- int l; /* for length */
-
+ int i, l;
/* first check if there realy is a -- option */
- if ( (optind>0)&&(optind<argc) &&
- (strncmp(argv[optind],"--",2)==0) &&
- (argv[optind][2]!='\0') )
+ if ((optind > 0) && (optind < argc) &&
+ (strncmp(argv[optind], "--", 2) == 0) &&
+ (argv[optind][2] != '\0'))
{
/* check the longopts list for a valid option */
- for (i=0;longopts[i].name!=NULL;i++)
+ for (i = 0; longopts[i].name != NULL; i++)
{
/* save the length for later */
- l=strlen(longopts[i].name);
- if (strncmp(argv[optind]+2,longopts[i].name,l)==0)
+ l = strlen(longopts[i].name);
+ if (strncmp(argv[optind] + 2, longopts[i].name, l) == 0)
{
/* we have a match */
- if ( (longopts[i].has_arg==no_argument) &&
- (argv[optind][2+l]=='\0') )
+ if ((longopts[i].has_arg == no_argument) &&
+ (argv[optind][2 + l] == '\0'))
{
optind++;
return longopts[i].val;
}
- else if ( (longopts[i].has_arg==required_argument) &&
- (argv[optind][2+l]=='=') )
+ else if ((longopts[i].has_arg == required_argument) &&
+ (argv[optind][2 + l] == '='))
{
- optarg=argv[optind]+3+l;
+ optarg = argv[optind] + 3 + l;
optind++;
return longopts[i].val;
}
- else if ( (longopts[i].has_arg==required_argument) &&
- (argv[optind][2+l]=='\0') )
+ else if ((longopts[i].has_arg == required_argument) &&
+ (argv[optind][2 + l] == '\0'))
{
- optarg=argv[optind+1];
- optind+=2;
+ optarg = argv[optind + 1];
+ optind += 2;
return longopts[i].val;
}
- else if ( (longopts[i].has_arg==optional_argument) &&
- (argv[optind][2+l]=='=') )
+ else if ((longopts[i].has_arg == optional_argument) &&
+ (argv[optind][2 + l] == '='))
{
- optarg=argv[optind]+3+l;
+ optarg = argv[optind] + 3 + l;
optind++;
return longopts[i].val;
}
- else if ( (longopts[i].has_arg==optional_argument) &&
- (argv[optind][2+l]=='\0') )
+ else if ((longopts[i].has_arg == optional_argument) &&
+ (argv[optind][2 + l] == '\0'))
{
optind++;
return longopts[i].val;
@@ -88,5 +86,5 @@ int getopt_long(int argc,char * const argv[],
}
}
/* if all else fails use plain getopt() */
- return getopt(argc,argv,optstring);
+ return getopt(argc, argv, optstring);
}
diff --git a/compat/getopt_long.h b/compat/getopt_long.h
index 2500f64..6182be3 100644
--- a/compat/getopt_long.h
+++ b/compat/getopt_long.h
@@ -1,7 +1,7 @@
/*
getopt_long.h - definition of getopt_long() for systems that lack it
- Copyright (C) 2001, 2002, 2008 Arthur de Jong
+ Copyright (C) 2001, 2002, 2008, 2010, 2012 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
@@ -41,9 +41,9 @@ struct option {
to options and options following filenames is not quite right, allso
minimal error checking
*/
-int getopt_long(int argc,char * const argv[],
+int getopt_long(int argc, char *const argv[],
const char *optstring,
- const struct option *longopts,int *longindex);
+ const struct option *longopts, int *longindex);
#endif /* not HAVE_GETOPT_LONG */
diff --git a/compat/getpeercred.c b/compat/getpeercred.c
index f7ac430..4b3f781 100644
--- a/compat/getpeercred.c
+++ b/compat/getpeercred.c
@@ -3,7 +3,7 @@
other end of a unix socket
This file is part of the nss-pam-ldapd library.
- Copyright (C) 2008 Arthur de Jong
+ Copyright (C) 2008, 2009, 2011, 2012 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
@@ -40,67 +40,81 @@
/* Note: most of this code is untested, except for the first
implementation (it may even fail to compile) */
-int getpeercred(int sock,uid_t *uid,gid_t *gid,pid_t *pid)
+int getpeercred(int sock, uid_t *uid, gid_t *gid, pid_t *pid)
{
#if defined(SO_PEERCRED)
socklen_t l;
struct ucred cred;
/* initialize client information (in case getsockopt() breaks) */
- cred.pid=(pid_t)0;
- cred.uid=(uid_t)-1;
- cred.gid=(gid_t)-1;
+ cred.pid = (pid_t)0;
+ cred.uid = (uid_t)-1;
+ cred.gid = (gid_t)-1;
/* look up process information from peer */
- l=(socklen_t)sizeof(struct ucred);
- if (getsockopt(sock,SOL_SOCKET,SO_PEERCRED,&cred,&l) < 0)
+ l = (socklen_t)sizeof(struct ucred);
+ if (getsockopt(sock, SOL_SOCKET, SO_PEERCRED, &cred, &l) < 0)
return -1; /* errno already set */
/* return the data */
- if (uid!=NULL) *uid=cred.uid;
- if (gid!=NULL) *gid=cred.gid;
- if (pid!=NULL) *pid=cred.pid;
+ if (uid != NULL)
+ *uid = cred.uid;
+ if (gid != NULL)
+ *gid = cred.gid;
+ if (pid != NULL)
+ *pid = cred.pid;
return 0;
#elif defined(LOCAL_PEERCRED)
socklen_t l;
struct xucred cred;
/* look up process information from peer */
- l=(socklen_t)sizeof(struct xucred);
- if (getsockopt(sock,0,LOCAL_PEERCRED,&cred,&l) < 0)
+ l = (socklen_t)sizeof(struct xucred);
+ if (getsockopt(sock, 0, LOCAL_PEERCRED, &cred, &l) < 0)
return -1; /* errno already set */
- if (cred.cr_version!=XUCRED_VERSION)
+ if (cred.cr_version != XUCRED_VERSION)
{
- errno=EINVAL;
+ errno = EINVAL;
return -1;
}
/* return the data */
- if (uid!=NULL) *uid=cred.cr_uid;
- if (gid!=NULL) *gid=cred.cr_gid;
- if (pid!=NULL) *pid=(pid_t)-1;
+ if (uid != NULL)
+ *uid = cred.cr_uid;
+ if (gid != NULL)
+ *gid = cred.cr_gid;
+ if (pid != NULL)
+ *pid = (pid_t)-1;
return 0;
#elif defined(HAVE_GETPEERUCRED)
- ucred_t *cred=NULL;
- if (getpeerucred(sock,&cred))
+ ucred_t *cred = NULL;
+ if (getpeerucred(sock, &cred))
return -1;
/* save the data */
- if (uid!=NULL) *uid=ucred_geteuid(cred);
- if (gid!=NULL) *gid=ucred_getegid(cred);
- if (pid!=NULL) *pid=ucred_getpid(cred);
+ if (uid != NULL)
+ *uid = ucred_geteuid(cred);
+ if (gid != NULL)
+ *gid = ucred_getegid(cred);
+ if (pid != NULL)
+ *pid = ucred_getpid(cred);
/* free cred and return */
ucred_free(cred);
return 0;
#elif defined(HAVE_GETPEEREID)
uid_t tuid;
gid_t tgid;
- if (uid==NULL) uid=&tuid;
- if (gid==NULL) gid=&tguid;
- if (getpeereid(sock,uid,gid))
+ if (uid == NULL)
+ uid = &tuid;
+ if (gid == NULL)
+ gid = &tguid;
+ if (getpeereid(sock, uid, gid))
return -1;
/* return the data */
- if (uid!=NULL) *uid=cred.uid;
- if (gid!=NULL) *gid=cred.gid;
- if (pid!=NULL) *pid=-1; /* we return a -1 pid because we have no usable pid */
+ if (uid != NULL)
+ *uid = cred.uid;
+ if (gid != NULL)
+ *gid = cred.gid;
+ if (pid != NULL)
+ *pid = -1; /* we return a -1 pid because we have no usable pid */
return 0;
#else
/* nothing found that is supported */
- errno=ENOSYS;
+ errno = ENOSYS;
return -1;
#endif
}
diff --git a/compat/getpeercred.h b/compat/getpeercred.h
index afa049f..5f96cc1 100644
--- a/compat/getpeercred.h
+++ b/compat/getpeercred.h
@@ -3,7 +3,7 @@
other end of a unix socket
This file is part of the nss-pam-ldapd library.
- Copyright (C) 2008 Arthur de Jong
+ Copyright (C) 2008, 2009, 2010, 2012 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
@@ -30,6 +30,6 @@
that information.
On success, zero is returned. On error, -1 is returned, and errno
is set appropriately. */
-int getpeercred(int sock,uid_t *uid,gid_t *gid,pid_t *pid);
+int getpeercred(int sock, uid_t *uid, gid_t *gid, pid_t *pid);
#endif /* not COMPAT__GETPEERCRED_H */
diff --git a/compat/ldap_compat.h b/compat/ldap_compat.h
index 039932c..55e75a5 100644
--- a/compat/ldap_compat.h
+++ b/compat/ldap_compat.h
@@ -1,7 +1,7 @@
/*
ldap_compat.h - provide a replacement definitions for some ldap functions
- Copyright (C) 2009, 2010 Arthur de Jong
+ Copyright (C) 2009, 2010, 2012 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
@@ -36,25 +36,25 @@
#ifndef HAVE_LDAP_INITIALIZE
/* provide a wrapper around ldap_init() if the system doesn't have
ldap_initialize() */
-int ldap_initialize(LDAP **ldp,const char *url);
+int ldap_initialize(LDAP **ldp, const char *url);
#endif /* not HAVE_LDAP_INITIALIZE */
#ifndef HAVE_LDAP_CREATE_PAGE_CONTROL
-int ldap_create_page_control(LDAP *ld,unsigned long pagesize,
- struct berval *cookiep,int iscritical,
+int ldap_create_page_control(LDAP *ld, unsigned long pagesize,
+ struct berval *cookiep, int iscritical,
LDAPControl **ctrlp);
#endif /* not HAVE_LDAP_CREATE_PAGE_CONTROL */
#ifndef HAVE_LDAP_PARSE_PAGE_CONTROL
-int ldap_parse_page_control(LDAP *ld,LDAPControl **ctrls,
+int ldap_parse_page_control(LDAP *ld, LDAPControl **ctrls,
unsigned long *list_countp,
struct berval **cookiep);
#endif /* not HAVE_LDAP_PARSE_PAGE_CONTROL */
#ifndef HAVE_LDAP_PASSWD_S
-int ldap_passwd_s(LDAP *ld,struct berval *user,struct berval *oldpw,
- struct berval *newpw,struct berval *newpasswd,
- LDAPControl **sctrls,LDAPControl **cctrls);
+int ldap_passwd_s(LDAP *ld, struct berval *user, struct berval *oldpw,
+ struct berval *newpw, struct berval *newpasswd,
+ LDAPControl **sctrls, LDAPControl **cctrls);
#endif /* not HAVE_LDAP_PASSWD_S */
/* compatibility definition */
diff --git a/compat/ldap_initialize.c b/compat/ldap_initialize.c
index d397784..8c75507 100644
--- a/compat/ldap_initialize.c
+++ b/compat/ldap_initialize.c
@@ -1,7 +1,7 @@
/*
ldap_initialize.c - replacement function for ldap_initialize()
- Copyright (C) 2009 Arthur de Jong
+ Copyright (C) 2009, 2012 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
@@ -36,29 +36,29 @@
/* provide a wrapper around ldap_init() if the system doesn't have
ldap_initialize() */
-int ldap_initialize(LDAP **ldp,const char *url)
+int ldap_initialize(LDAP **ldp, const char *url)
{
char host[80];
/* check schema part */
- if (strncasecmp(url,"ldap://",7)==0)
+ if (strncasecmp(url, "ldap://", 7) == 0)
{
- strncpy(host,url+7,sizeof(host));
- host[sizeof(host)-1]='\0';
+ strncpy(host, url + 7, sizeof(host));
+ host[sizeof(host) - 1] = '\0';
}
- else if (strncasecmp(url,"ldaps://",8)==0)
+ else if (strncasecmp(url, "ldaps://", 8) == 0)
{
- strncpy(host,url+8,sizeof(host));
- host[sizeof(host)-1]='\0';
+ strncpy(host, url + 8, sizeof(host));
+ host[sizeof(host) - 1] = '\0';
}
else
{
- log_log(LOG_ERR,"ldap_initialize(): schema not supported: %s",url);
+ log_log(LOG_ERR, "ldap_initialize(): schema not supported: %s", url);
exit(EXIT_FAILURE);
}
/* strip trailing slash */
- if ((strlen(host)>0)&&(host[strlen(host)-1]=='/'))
- host[strlen(host)-1]='\0';
+ if ((strlen(host) > 0) && (host[strlen(host) - 1] == '/'))
+ host[strlen(host) - 1] = '\0';
/* call ldap_init() */
- *ldp=ldap_init(host,LDAP_PORT);
- return (*ldp==NULL)?LDAP_OPERATIONS_ERROR:LDAP_SUCCESS;
+ *ldp = ldap_init(host, LDAP_PORT);
+ return (*ldp == NULL) ? LDAP_OPERATIONS_ERROR : LDAP_SUCCESS;
}
diff --git a/compat/ldap_passwd_s.c b/compat/ldap_passwd_s.c
index 6fc5cff..b239ae3 100644
--- a/compat/ldap_passwd_s.c
+++ b/compat/ldap_passwd_s.c
@@ -4,7 +4,7 @@
(taken from _update_authtok() in pam_ldap.c).
Copyright (C) 1998-2004 Luke Howard
- Copyright (C) 2009, 2010 Arthur de Jong
+ Copyright (C) 2009, 2010, 20120 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
@@ -39,9 +39,9 @@
#define LDAP_TAG_EXOP_MODIFY_PASSWD_NEW LDAP_TAG_EXOP_X_MODIFY_PASSWD_NEW
#else /* not LDAP_EXOP_X_MODIFY_PASSWD */
#define LDAP_EXOP_MODIFY_PASSWD "1.3.6.1.4.1.4203.1.11.1"
-#define LDAP_TAG_EXOP_MODIFY_PASSWD_ID ((ber_tag_t) 0x80U)
-#define LDAP_TAG_EXOP_MODIFY_PASSWD_OLD ((ber_tag_t) 0x81U)
-#define LDAP_TAG_EXOP_MODIFY_PASSWD_NEW ((ber_tag_t) 0x82U)
+#define LDAP_TAG_EXOP_MODIFY_PASSWD_ID ((ber_tag_t)0x80U)
+#define LDAP_TAG_EXOP_MODIFY_PASSWD_OLD ((ber_tag_t)0x81U)
+#define LDAP_TAG_EXOP_MODIFY_PASSWD_NEW ((ber_tag_t)0x82U)
#endif /* not LDAP_EXOP_X_MODIFY_PASSWD */
#endif /* not LDAP_EXOP_MODIFY_PASSWD */
@@ -56,18 +56,18 @@
#if !HAVE_DECL_LDAP_EXTENDED_OPERATION_S
/* we define this ourselves here because some LDAP header versions don't
seem to define this */
-extern int ldap_extended_operation_s(LDAP *ld,LDAP_CONST char *reqoid,
- struct berval *reqdata,LDAPControl **serverctrls,LDAPControl **clientctrls,
- char **retoidp,struct berval **retdatap);
+extern int ldap_extended_operation_s(LDAP *ld, LDAP_CONST char *reqoid,
+ struct berval *reqdata, LDAPControl **serverctrls,
+ LDAPControl **clientctrls, char **retoidp, struct berval **retdatap);
#endif /* not HAVE_DECL_LDAP_EXTENDED_OPERATION_S */
/* Replacement for password modification. user is the DN of the entry to
change, oldpw is the old password (may not always be needed?), newpw is
the new password to set and newpasswd is sometimes returned (though not
- by us). See RFC 3062 for details.*/
-int ldap_passwd_s(LDAP *ld,struct berval *user,struct berval *oldpw,
- struct berval *newpw,struct berval UNUSED(*newpasswd),
- LDAPControl **sctrls,LDAPControl **cctrls)
+ by us). See RFC 3062 for details. */
+int ldap_passwd_s(LDAP *ld, struct berval *user, struct berval *oldpw,
+ struct berval *newpw, struct berval UNUSED(*newpasswd),
+ LDAPControl **sctrls, LDAPControl **cctrls)
{
#ifndef HAVE_LDAP_EXTENDED_OPERATION_S
return LDAP_OPERATIONS_ERROR;
@@ -78,25 +78,25 @@ int ldap_passwd_s(LDAP *ld,struct berval *user,struct berval *oldpw,
char *retoid;
struct berval *retdata;
/* set up request data */
- ber=ber_alloc_t(LBER_USE_DER);
- if (ber==NULL)
+ ber = ber_alloc_t(LBER_USE_DER);
+ if (ber == NULL)
return LDAP_NO_MEMORY;
- ber_printf(ber,"{");
- ber_printf(ber,"tO",LDAP_TAG_EXOP_MODIFY_PASSWD_ID,user);
- if (oldpw!=NULL)
- ber_printf(ber,"tO",LDAP_TAG_EXOP_MODIFY_PASSWD_OLD,oldpw);
- ber_printf(ber,"tO",LDAP_TAG_EXOP_MODIFY_PASSWD_NEW,newpw);
- ber_printf(ber,"N}");
- rc=ber_flatten(ber,&bv);
- ber_free(ber,1);
- if (rc<0)
+ ber_printf(ber, "{");
+ ber_printf(ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_ID, user);
+ if (oldpw != NULL)
+ ber_printf(ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_OLD, oldpw);
+ ber_printf(ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_NEW, newpw);
+ ber_printf(ber, "N}");
+ rc = ber_flatten(ber, &bv);
+ ber_free(ber, 1);
+ if (rc < 0)
return LDAP_NO_MEMORY;
/* perform the operation */
- rc=ldap_extended_operation_s(ld,LDAP_EXOP_MODIFY_PASSWD,bv,sctrls,cctrls,
- &retoid,&retdata);
+ rc = ldap_extended_operation_s(ld, LDAP_EXOP_MODIFY_PASSWD, bv, sctrls,
+ cctrls, &retoid, &retdata);
/* free data */
ber_bvfree(bv);
- if (rc==LDAP_SUCCESS)
+ if (rc == LDAP_SUCCESS)
{
ber_bvfree(retdata);
ber_memfree(retoid);
diff --git a/compat/nss_compat.h b/compat/nss_compat.h
index 2588034..dc1d32d 100644
--- a/compat/nss_compat.h
+++ b/compat/nss_compat.h
@@ -81,8 +81,7 @@ typedef enum nss_status nss_status_t;
/* Define an aliasent if it was not found on the system. */
#ifndef HAVE_STRUCT_ALIASENT
-struct aliasent
-{
+struct aliasent {
char *alias_name;
size_t alias_members_len;
char **alias_members;
@@ -92,8 +91,7 @@ struct aliasent
/* Define an rpcent if it was not found on the system */
#ifndef HAVE_STRUCT_RPCENT
-struct rpcent
-{
+struct rpcent {
char *r_name;
char **r_aliases;
int r_number;
@@ -105,8 +103,7 @@ struct rpcent
by glibc. This is taken from include/netinet/ether.h
of the glibc (2.3.6) source tarball. */
#ifndef HAVE_STRUCT_ETHERENT
-struct etherent
-{
+struct etherent {
const char *e_name;
struct ether_addr e_addr;
};
@@ -118,13 +115,10 @@ struct etherent
The first part of the struct is the only part that is modified
by our getnetgrent() function, all the other fields are not
touched at all. */
-struct __netgrent
-{
+struct __netgrent {
enum { triple_val, group_val } type;
- union
- {
- struct
- {
+ union {
+ struct {
const char *host;
const char *user;
const char *domain;
@@ -137,8 +131,7 @@ struct __netgrent
by our caller */
char *data;
size_t data_size;
- union
- {
+ union {
char *cursor;
unsigned long int position;
} insertedname; /* added name to union to avoid warning */
diff --git a/compat/pam_compat.h b/compat/pam_compat.h
index 4109b77..ac94986 100644
--- a/compat/pam_compat.h
+++ b/compat/pam_compat.h
@@ -1,7 +1,7 @@
/*
pam_compat.h - provide a replacement definitions for some pam functions
- Copyright (C) 2009, 2010 Arthur de Jong
+ Copyright (C) 2009, 2010, 2011, 2012 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
@@ -48,32 +48,35 @@
/* define our own replacement pam_get_authtok() if it wasn't found */
#ifndef HAVE_PAM_GET_AUTHTOK
-int pam_get_authtok(pam_handle_t *pamh,int item,const char **authtok,const char *prompt);
+int pam_get_authtok(pam_handle_t *pamh, int item, const char **authtok,
+ const char *prompt);
#endif /* not HAVE_PAM_GET_AUTHTOK */
/* replace pam_prompt() if needed */
#ifndef HAVE_PAM_PROMPT
-int pam_prompt(pam_handle_t *pamh,int style,char **response,const char *format,...)
- LIKE_PRINTF(4,5);
+int pam_prompt(pam_handle_t *pamh, int style, char **response,
+ const char *format, ...)
+ LIKE_PRINTF(4, 5);
#endif /* not HAVE_PAM_PROMPT */
/* provide pam_info() if needed */
#ifndef pam_info
-#define pam_info(pamh,format...) \
- pam_prompt(pamh,PAM_TEXT_INFO,NULL,##format)
+#define pam_info(pamh, format...) \
+ pam_prompt(pamh, PAM_TEXT_INFO, NULL, ##format)
#endif /* not pam_info */
/* provide pam_error() if needed */
#ifndef pam_error
-#define pam_error(pamh,format...) \
- pam_prompt(pamh,PAM_ERROR_MSG,NULL,##format)
+#define pam_error(pamh, format...) \
+ pam_prompt(pamh, PAM_ERROR_MSG, NULL, ##format)
#endif /* not pam_error */
/* fall back to using getpwnam() if pam_modutil_getpwnam() isn't defined */
#ifndef HAVE_PAM_MODUTIL_GETGWNAM
#include <sys/types.h>
#include <pwd.h>
-#define pam_modutil_getpwnam(pamh,user) getpwnam(user)
+#define pam_modutil_getpwnam(pamh, user) \
+ getpwnam(user)
#endif /* not HAVE_PAM_MODUTIL_GETGWNAM */
/* fall back to using syslog() if pam_syslog() doesn't exist */
@@ -81,8 +84,8 @@ int pam_prompt(pam_handle_t *pamh,int style,char **response,const char *format,.
#ifndef LOG_AUTHPRIV
#define LOG_AUTHPRIV LOG_AUTH
#endif /* not LOG_AUTHPRIV */
-#define pam_syslog(pamh,priority,format...) \
- syslog(LOG_AUTHPRIV|(priority),##format)
+#define pam_syslog(pamh, priority, format...) \
+ syslog(LOG_AUTHPRIV|(priority), ##format)
#endif /* not HAVE_PAM_SYSLOG */
#endif /* _COMPAT_LDAP_COMPAT_H */
diff --git a/compat/pam_get_authtok.c b/compat/pam_get_authtok.c
index b9cec51..9b8825b 100644
--- a/compat/pam_get_authtok.c
+++ b/compat/pam_get_authtok.c
@@ -1,7 +1,7 @@
/*
pam_get_authtok.c - replacement function for pam_get_authtok()
- Copyright (C) 2009, 2010 Arthur de Jong
+ Copyright (C) 2009, 2010, 2012 Arthur de Jong
Copyright (C) 2010 Symas Corporation
This library is free software; you can redistribute it and/or
@@ -35,58 +35,60 @@
/* warning: this version assumes that try_first_pass is specified */
-int pam_get_authtok(pam_handle_t *pamh,int item,const char **authtok,const char *prompt)
+int pam_get_authtok(pam_handle_t *pamh, int item, const char **authtok,
+ const char *prompt)
{
int rc;
- char *passwd=NULL,*retype_passwd=NULL;
+ char *passwd = NULL, *retype_passwd = NULL;
const void *oldauthtok;
char retype_prompt[80];
/* first try to see if the value is already on the stack */
- *authtok=NULL;
- rc=pam_get_item(pamh,item,(const void **)authtok);
- if ((rc==PAM_SUCCESS)&&(*authtok!=NULL))
+ *authtok = NULL;
+ rc = pam_get_item(pamh, item, (const void **)authtok);
+ if ((rc == PAM_SUCCESS) && (*authtok != NULL))
return PAM_SUCCESS;
/* check what to prompt for and provide default prompt */
- *retype_prompt='\0';
- if (item==PAM_OLDAUTHTOK)
- prompt=(prompt!=NULL)?prompt:"Old Password: ";
+ *retype_prompt = '\0';
+ if (item == PAM_OLDAUTHTOK)
+ prompt = (prompt != NULL) ? prompt : "Old Password: ";
else
{
- rc=pam_get_item(pamh,PAM_OLDAUTHTOK,(const void **)&oldauthtok);
- if ((rc==PAM_SUCCESS)&&(oldauthtok!=NULL))
+ rc = pam_get_item(pamh, PAM_OLDAUTHTOK, (const void **)&oldauthtok);
+ if ((rc == PAM_SUCCESS) && (oldauthtok != NULL))
{
- prompt=(prompt!=NULL)?prompt:"New Password: ";
- snprintf(retype_prompt,sizeof(retype_prompt),"Retype %s",prompt);
- retype_prompt[sizeof(retype_prompt)-1]='\0';
+ prompt = (prompt != NULL) ? prompt : "New Password: ";
+ snprintf(retype_prompt, sizeof(retype_prompt), "Retype %s", prompt);
+ retype_prompt[sizeof(retype_prompt) - 1] = '\0';
}
else
- prompt=(prompt!=NULL)?prompt:"Password: ";
+ prompt = (prompt != NULL) ? prompt : "Password: ";
}
/* prepare prompt and get password */
- rc=pam_prompt(pamh,PAM_PROMPT_ECHO_OFF,&passwd,"%s",prompt);
- if (rc!=PAM_SUCCESS)
+ rc = pam_prompt(pamh, PAM_PROMPT_ECHO_OFF, &passwd, "%s", prompt);
+ if (rc != PAM_SUCCESS)
return rc;
/* if a second prompt should be presented, do it */
if (*retype_prompt)
{
- rc=pam_prompt(pamh,PAM_PROMPT_ECHO_OFF,&retype_passwd,"%s",retype_prompt);
+ rc = pam_prompt(pamh, PAM_PROMPT_ECHO_OFF, &retype_passwd, "%s",
+ retype_prompt);
/* check passwords */
- if ((rc==PAM_SUCCESS)&&(strcmp(retype_passwd,passwd)!=0))
- rc=PAM_AUTHTOK_RECOVERY_ERR;
+ if ((rc == PAM_SUCCESS) && (strcmp(retype_passwd, passwd) != 0))
+ rc = PAM_AUTHTOK_RECOVERY_ERR;
}
/* store the password if everything went ok */
- if (rc==PAM_SUCCESS)
- rc=pam_set_item(pamh,item,passwd);
+ if (rc == PAM_SUCCESS)
+ rc = pam_set_item(pamh, item, passwd);
/* clear and free any password information */
- memset(passwd,0,strlen(passwd));
+ memset(passwd, 0, strlen(passwd));
free(passwd);
- if (retype_passwd!=NULL)
+ if (retype_passwd != NULL)
{
- memset(retype_passwd,0,strlen(retype_passwd));
+ memset(retype_passwd, 0, strlen(retype_passwd));
free(retype_passwd);
}
- if (rc!=PAM_SUCCESS)
+ if (rc != PAM_SUCCESS)
return rc;
/* return token from the stack */
- return pam_get_item(pamh,item,(const void **)authtok);
+ return pam_get_item(pamh, item, (const void **)authtok);
}
diff --git a/compat/pam_prompt.c b/compat/pam_prompt.c
index 6e1b779..d2fd761 100644
--- a/compat/pam_prompt.c
+++ b/compat/pam_prompt.c
@@ -1,7 +1,7 @@
/*
pam_prompt.c - replacement function for pam_prompt()
- Copyright (C) 2010 Arthur de Jong
+ Copyright (C) 2010, 2012 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
@@ -28,7 +28,8 @@
#include "compat/attrs.h"
#include "compat/pam_compat.h"
-int pam_prompt(pam_handle_t *pamh,int style,char **response,const char *format,...)
+int pam_prompt(pam_handle_t *pamh, int style, char **response,
+ const char *format, ...)
{
int rc;
struct pam_conv *aconv;
@@ -37,33 +38,33 @@ int pam_prompt(pam_handle_t *pamh,int style,char **response,const char *format,.
struct pam_message msg, *pmsg;
struct pam_response *resp;
/* the the conversion function */
- rc=pam_get_item(pamh,PAM_CONV,(const void **)&aconv);
- if (rc!=PAM_SUCCESS)
+ rc = pam_get_item(pamh, PAM_CONV, (const void **)&aconv);
+ if (rc != PAM_SUCCESS)
return rc;
/* make the message string */
- va_start(ap,format);
- vsnprintf(buffer,sizeof(buffer),format,ap);
- buffer[sizeof(buffer)-1]='\0';
+ va_start(ap, format);
+ vsnprintf(buffer, sizeof(buffer), format, ap);
+ buffer[sizeof(buffer) - 1] = '\0';
va_end(ap);
/* build the message */
- msg.msg_style=style;
- msg.msg=buffer;
- pmsg=&msg;
- resp=NULL;
- rc=aconv->conv(1,(const struct pam_message **)&pmsg,&resp,aconv->appdata_ptr);
- if (rc!=PAM_SUCCESS)
+ msg.msg_style = style;
+ msg.msg = buffer;
+ pmsg = &msg;
+ resp = NULL;
+ rc = aconv->conv(1, (const struct pam_message **)&pmsg, &resp, aconv->appdata_ptr);
+ if (rc != PAM_SUCCESS)
return rc;
/* assign response if it is set */
- if (response!=NULL)
+ if (response != NULL)
{
- if (resp==NULL)
+ if (resp == NULL)
return PAM_CONV_ERR;
- if (resp[0].resp==NULL)
+ if (resp[0].resp == NULL)
{
free(resp);
return PAM_CONV_ERR;
}
- *response=resp[0].resp;
+ *response = resp[0].resp;
}
else
free(resp[0].resp);
diff --git a/compat/socket.h b/compat/socket.h
index 9e44b95..7f69950 100644
--- a/compat/socket.h
+++ b/compat/socket.h
@@ -28,7 +28,7 @@
/* provide a definition for SUN_LEN for systems without it */
#ifndef SUN_LEN
-#define SUN_LEN(addr) (sizeof((addr)->sun_family)+strlen((addr)->sun_path)+1)
+#define SUN_LEN(addr) (sizeof((addr)->sun_family) + strlen((addr)->sun_path) + 1)
#endif /* not SUN_LEN */
#endif /* not COMPAT__SOCKET_H */
diff --git a/compat/strndup.c b/compat/strndup.c
index 9eb38a0..bd7c5d6 100644
--- a/compat/strndup.c
+++ b/compat/strndup.c
@@ -1,7 +1,7 @@
/*
strndup.c - implementation of strndup() for systems that lack it
- Copyright (C) 2011 Arthur de Jong
+ Copyright (C) 2011, 2012 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
@@ -28,14 +28,14 @@
/* this is a strndup() replacement for systems that don't have it
(strndup() is in POSIX 2008 now) */
-char *strndup(const char *s,size_t size)
+char *strndup(const char *s, size_t size)
{
char *result;
- result=(char *)malloc(size+1);
- if (result!=NULL)
+ result = (char *)malloc(size + 1);
+ if (result != NULL)
{
- strncpy(result,s,size);
- result[size]='\0';
+ strncpy(result, s, size);
+ result[size] = '\0';
}
return result;
}
diff --git a/compat/strndup.h b/compat/strndup.h
index abedd22..461ec86 100644
--- a/compat/strndup.h
+++ b/compat/strndup.h
@@ -1,7 +1,7 @@
/*
strndup.h - definition of strndup() for systems that lack it
- Copyright (C) 2011 Arthur de Jong
+ Copyright (C) 2011, 2012 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
@@ -26,7 +26,7 @@
/* this is a strndup() replacement for systems that don't have it
(strndup() is in POSIX 2008 now) */
-char *strndup(const char *s,size_t size);
+char *strndup(const char *s, size_t size);
#endif /* not HAVE_STRNDUP */