diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2007-03-04 21:03:06 +0100 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2007-03-04 21:03:06 +0100 |
commit | 48d51b66fac883fc8648fb6b9df487382b8addc2 (patch) | |
tree | e85684c4247e33f12417a95989210df016a35109 | |
parent | 03fdef7f5c7667fd92232f6d055f98833bcfef19 (diff) |
code improvements by making type casts explicit, flagging ignored return values, renames and flagging of parameters and some miscelanious improvements (thanks to gcc warnings, splint, rats and flawfinder)
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-ldapd@265 ef36b2f9-881f-0410-afb5-c4e39611909c
-rw-r--r-- | nslcd-common.h | 8 | ||||
-rw-r--r-- | nslcd/alias.c | 9 | ||||
-rw-r--r-- | nslcd/ether.c | 6 | ||||
-rw-r--r-- | nslcd/group.c | 9 | ||||
-rw-r--r-- | nslcd/ldap-nss.c | 11 | ||||
-rw-r--r-- | nslcd/ldap-nss.h | 22 | ||||
-rw-r--r-- | nslcd/ldap-schema.c | 10 | ||||
-rw-r--r-- | nslcd/ldap-schema.h | 4 | ||||
-rw-r--r-- | nslcd/log.c | 4 | ||||
-rw-r--r-- | nslcd/nslcd.c | 139 | ||||
-rw-r--r-- | nslcd/passwd.c | 5 | ||||
-rw-r--r-- | nslcd/protocol.c | 2 | ||||
-rw-r--r-- | nslcd/rpc.c | 2 | ||||
-rw-r--r-- | nslcd/shadow.c | 2 | ||||
-rw-r--r-- | nslcd/util.c | 15 | ||||
-rw-r--r-- | nslcd/util.h | 6 | ||||
-rw-r--r-- | nss/common.c | 8 | ||||
-rw-r--r-- | nss/common.h | 25 | ||||
-rw-r--r-- | nss/group.c | 6 | ||||
-rw-r--r-- | nss/hosts.c | 13 | ||||
-rw-r--r-- | nss/netgroup.c | 2 | ||||
-rw-r--r-- | nss/networks.c | 8 | ||||
-rw-r--r-- | nss/prototypes.h | 4 | ||||
-rw-r--r-- | nss/services.c | 2 |
24 files changed, 168 insertions, 154 deletions
diff --git a/nslcd-common.h b/nslcd-common.h index 5d0f763..56a1093 100644 --- a/nslcd-common.h +++ b/nslcd-common.h @@ -65,7 +65,7 @@ static void debug_dump(const void *ptr,size_t size) #define WRITE(fp,ptr,size) \ DEBUG_PRINT("WRITE : var="__STRING(ptr)" size=%d",(int)size); \ DEBUG_DUMP(ptr,size); \ - if (fwrite(ptr,size,1,fp)<1) \ + if (fwrite(ptr,(size_t)size,(size_t)1,fp)<(size_t)1) \ { \ DEBUG_PRINT("WRITE : var="__STRING(ptr)" error: %s",strerror(errno)); \ ERROR_OUT_WRITEERROR(fp); \ @@ -133,7 +133,7 @@ static void debug_dump(const void *ptr,size_t size) */ #define READ(fp,ptr,size) \ - if (fread(ptr,size,1,fp)<1) \ + if (fread(ptr,(size_t)size,(size_t)1,fp)<(size_t)1) \ { \ DEBUG_PRINT("READ : var="__STRING(ptr)" error: %s",strerror(errno)); \ ERROR_OUT_READERROR(fp); \ @@ -189,11 +189,11 @@ static void debug_dump(const void *ptr,size_t size) /* align to the specified type width */ \ BUF_ALIGN(fp,type); \ /* check that we have enough room */ \ - BUF_CHECK(fp,(num)*sizeof(type)); \ + BUF_CHECK(fp,(size_t)(num)*sizeof(type)); \ /* store the pointer */ \ (ptr)=(type *)BUF_CUR; \ /* reserve the space */ \ - BUF_SKIP((num)*sizeof(type)); + BUF_SKIP((size_t)(num)*sizeof(type)); /* read string in the buffer (using buffer, buflen and bufptr) and store the actual location of the string in field */ diff --git a/nslcd/alias.c b/nslcd/alias.c index d7b7f1c..adcef4d 100644 --- a/nslcd/alias.c +++ b/nslcd/alias.c @@ -44,10 +44,13 @@ #include "log.h" static enum nss_status _nss_ldap_parse_alias( - LDAPMessage *e,struct ldap_state *pvt,void *result, + LDAPMessage *e,struct ldap_state UNUSED(*pvt),void *result, char *buffer,size_t buflen) { - + /* FIXME: fix following problem: + if the entry has multiple cn fields we may end up + sending the wrong cn, we should return the requested + CN instead, otherwise write an entry for each cn */ struct aliasent *alias=(struct aliasent *)result; enum nss_status stat; @@ -60,7 +63,7 @@ static enum nss_status _nss_ldap_parse_alias( return stat; } -static int write_alias(LDAPMessage *e,struct ldap_state *pvt,FILE *fp) +static int write_alias(LDAPMessage *e,struct ldap_state UNUSED(*pvt),FILE *fp) { int stat; if ((stat=_nss_ldap_write_rndvalue(fp,e,ATM(LM_ALIASES,cn)))!=NSLCD_RESULT_SUCCESS) diff --git a/nslcd/ether.c b/nslcd/ether.c index de8f7bc..249b426 100644 --- a/nslcd/ether.c +++ b/nslcd/ether.c @@ -75,6 +75,10 @@ struct ether #ifdef NEW static int write_ether(LDAPMessage *e,struct ldap_state *pvt,FILE *fp) { + /* FIXME: fix following problem: + if the entry has multiple cn fields we may end up + sending the wrong cn, we should return the requested + CN instead, otherwise write an entry for each cn */ int stat; char buffer[1024]; /* write NSLCD_STRING(ETHER_NAME) */ @@ -95,7 +99,7 @@ static int write_ether(LDAPMessage *e,struct ldap_state *pvt,FILE *fp) static enum nss_status _nss_ldap_parse_ether (LDAPMessage * e, - struct ldap_state * pvt, + struct ldap_state UNUSED(*pvt), void *result, char *buffer, size_t buflen) { struct ether *ether = (struct ether *) result; diff --git a/nslcd/group.c b/nslcd/group.c index 5753932..56ada1a 100644 --- a/nslcd/group.c +++ b/nslcd/group.c @@ -50,6 +50,11 @@ #include "log.h" #include "cfg.h" +/* FIXME: fix following problem: + if the entry has multiple cn fields we may end up + sending the wrong cn, we should return the requested + cn instead, otherwise write an entry for each cn */ + struct name_list { char *name; @@ -1175,7 +1180,7 @@ int nslcd_group_byname(FILE *fp) if (1024<LDAP_NSS_BUFLEN_GROUP) { log_log(LOG_CRIT,"allocated buffer in nslcd_group_byname() too small"); - exit(1); + exit(EXIT_FAILURE); } /* do the LDAP request */ LA_INIT(a); @@ -1213,7 +1218,7 @@ int nslcd_group_bygid(FILE *fp) if (1024<LDAP_NSS_BUFLEN_GROUP) { log_log(LOG_CRIT,"allocated buffer in nslcd_group_byname() too small"); - exit(1); + exit(EXIT_FAILURE); } /* do the LDAP request */ LA_INIT(a); diff --git a/nslcd/ldap-nss.c b/nslcd/ldap-nss.c index f423d75..46ed56a 100644 --- a/nslcd/ldap-nss.c +++ b/nslcd/ldap-nss.c @@ -118,8 +118,8 @@ static int __sigaction_retval = -1; static void (*__sigpipe_handler) (int) = SIG_DFL; #endif /* HAVE_SIGACTION */ -static const char *_nss_ldap_map_ov (const char *pChar); -static const char *_nss_ldap_map_df (const char *pChar); +static const char *_nss_ldap_map_ov (const char *attribute); +static const char *_nss_ldap_map_df (const char *attribute); static const char *_nss_ldap_locate_userpassword (char **vals); /* @@ -3032,6 +3032,11 @@ _nss_ldap_shadow_handle_flag (struct spwd *sp) } #endif /* HAVE_SHADOW_H */ +static enum nss_status +_nss_ldap_map_get (enum ldap_map_selector sel, + enum ldap_map_type type, + const char *from, const char **to); + const char * _nss_ldap_map_at (enum ldap_map_selector sel, const char *attribute) { @@ -3096,7 +3101,7 @@ _nss_ldap_map_df (const char *attribute) return value; } -enum nss_status +static enum nss_status _nss_ldap_map_get (enum ldap_map_selector sel, enum ldap_map_type type, const char *from, const char **to) diff --git a/nslcd/ldap-nss.h b/nslcd/ldap-nss.h index 3907d08..18c394c 100644 --- a/nslcd/ldap-nss.h +++ b/nslcd/ldap-nss.h @@ -331,21 +331,21 @@ enum nss_status _nss_ldap_search_s (const struct ldap_args * args, /* IN */ enum ldap_map_selector sel, /* IN */ const char **user_attrs, /* IN */ int sizelimit, /* IN */ - LDAPMessage ** pRes /* OUT */ ); + LDAPMessage ** res /* OUT */ ); /* * Emulate X.500 read operation. */ enum nss_status _nss_ldap_read (const char *dn, /* IN */ const char **attributes, /* IN */ - LDAPMessage ** pRes /* OUT */ ); + LDAPMessage ** res /* OUT */ ); /* * extended enumeration routine; uses asynchronous API. * Caller must have acquired the global mutex */ enum nss_status _nss_ldap_getent_ex (struct ldap_args * args, /* IN */ - struct ent_context ** key, /* IN/OUT */ + struct ent_context ** ctx, /* IN/OUT */ void *result, /* IN/OUT */ char *buffer, /* IN */ size_t buflen, /* IN */ @@ -359,7 +359,7 @@ enum nss_status _nss_ldap_getent_ex (struct ldap_args * args, /* IN */ * common enumeration routine; uses asynchronous API. * Acquires the global mutex */ -enum nss_status _nss_ldap_getent (struct ent_context ** key, /* IN/OUT */ +enum nss_status _nss_ldap_getent (struct ent_context ** ctx, /* IN/OUT */ void *result, /* IN/OUT */ char *buffer, /* IN */ size_t buflen, /* IN */ @@ -386,8 +386,8 @@ enum nss_status _nss_ldap_assign_attrvals (LDAPMessage * e, /* IN */ const char *attr, /* IN */ const char *omitvalue, /* IN */ char ***valptr, /* OUT */ - char **buffer, /* IN/OUT */ - size_t * buflen, /* IN/OUT */ + char **pbuffer, /* IN/OUT */ + size_t * pbuflen, /* IN/OUT */ size_t * pvalcount /* OUT */ ); @@ -411,15 +411,11 @@ int has_objectclass(LDAPMessage *entry,const char *objectclass); int _nss_ldap_shadow_date(const char *val); void _nss_ldap_shadow_handle_flag(struct spwd *sp); -enum nss_status _nss_ldap_map_get(enum ldap_map_selector sel, - enum ldap_map_type map, - const char *key, const char **value); - -const char *_nss_ldap_map_at (enum ldap_map_selector sel, const char *pChar2); +const char *_nss_ldap_map_at (enum ldap_map_selector sel, const char *attribute); const char *_nss_ldap_unmap_at (enum ldap_map_selector sel, const char *attribute); -const char *_nss_ldap_map_oc (enum ldap_map_selector sel, const char *pChar); -const char *_nss_ldap_unmap_oc (enum ldap_map_selector sel, const char *pChar); +const char *_nss_ldap_map_oc (enum ldap_map_selector sel, const char *objectclass); +const char *_nss_ldap_unmap_oc (enum ldap_map_selector sel, const char *objectclass); enum nss_status _nss_ldap_init (void); diff --git a/nslcd/ldap-schema.c b/nslcd/ldap-schema.c index ebdc8a2..b335abe 100644 --- a/nslcd/ldap-schema.c +++ b/nslcd/ldap-schema.c @@ -57,9 +57,6 @@ char _nss_ldap_filt_getaliasbyname[LDAP_FILT_MAXSIZ]; char _nss_ldap_filt_getaliasent[LDAP_FILT_MAXSIZ]; -/* boot parameters */ -char _nss_ldap_filt_getbootparamsbyname[LDAP_FILT_MAXSIZ]; - /* MAC address mappings */ char _nss_ldap_filt_gethostton[LDAP_FILT_MAXSIZ]; char _nss_ldap_filt_getntohost[LDAP_FILT_MAXSIZ]; @@ -127,11 +124,6 @@ _nss_ldap_init_filters () snprintf (_nss_ldap_filt_getaliasent, LDAP_FILT_MAXSIZ, "(%s=%s)", AT (objectClass), OC (nisMailAlias)); - /* boot parameters */ - snprintf (_nss_ldap_filt_getbootparamsbyname, LDAP_FILT_MAXSIZ, - "(&(%s=%s)(%s=%s))", AT (objectClass), OC (bootableDevice), - ATM (LM_BOOTPARAMS, cn), "%d"); - /* MAC address mappings */ snprintf (_nss_ldap_filt_gethostton, LDAP_FILT_MAXSIZ, "(&(%s=%s)(%s=%s))", AT (objectClass), OC (ieee802Device), @@ -242,8 +234,6 @@ _nss_ldap_init_filters () snprintf (_nss_ldap_filt_getnetgrent, LDAP_FILT_MAXSIZ, "(&(%s=%s)(%s=%s))", AT (objectClass), OC (nisNetgroup), ATM (LM_NETGROUP, cn), "%s"); - snprintf (_nss_ldap_filt_innetgr, LDAP_FILT_MAXSIZ, - "(&(%s=%s)(%s=%s))", AT (objectClass), OC (nisNetgroup), AT (memberNisNetgroup), "%s"); } diff --git a/nslcd/ldap-schema.h b/nslcd/ldap-schema.h index 7d19874..4ccbcd2 100644 --- a/nslcd/ldap-schema.h +++ b/nslcd/ldap-schema.h @@ -40,9 +40,6 @@ void _nss_ldap_init_attributes(const char ***attrtab); extern char _nss_ldap_filt_getaliasbyname[]; extern char _nss_ldap_filt_getaliasent[]; -/* boot parameters */ -extern char _nss_ldap_filt_getbootparamsbyname[]; - /* MAC address mappings */ extern char _nss_ldap_filt_gethostton[]; extern char _nss_ldap_filt_getntohost[]; @@ -95,7 +92,6 @@ extern char _nss_ldap_filt_getspent[]; /* netgroups */ extern char _nss_ldap_filt_getnetgrent[]; -extern char _nss_ldap_filt_innetgr[]; /** * Initialize attribute vector table indexed by map diff --git a/nslcd/log.c b/nslcd/log.c index d5f89de..888c53f 100644 --- a/nslcd/log.c +++ b/nslcd/log.c @@ -68,7 +68,7 @@ static void log_addlogging_fp(FILE *fp,int loglevel) { fprintf(stderr,"malloc() failed: %s",strerror(errno)); /* since this is done during initialisation it's best to bail out */ - exit(1); + exit(EXIT_FAILURE); } tmp->fp=fp; tmp->loglevel=loglevel; @@ -92,7 +92,7 @@ void log_addlogging_file(const char *filename,int loglevel) if (fp==NULL) { log_log(LOG_ERR,"cannot open logfile (%s) for appending: %s",filename,strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } log_addlogging_fp(fp,loglevel); } diff --git a/nslcd/nslcd.c b/nslcd/nslcd.c index 4d54b48..997a236 100644 --- a/nslcd/nslcd.c +++ b/nslcd/nslcd.c @@ -70,7 +70,7 @@ static int nslcd_serversocket=-1; /* thread ids of all running threads */ #define NUM_THREADS 5 -pthread_t nslcd_threads[NUM_THREADS]; +static pthread_t nslcd_threads[NUM_THREADS]; /* display version information */ @@ -122,16 +122,16 @@ static void parse_cmdline(int argc,char *argv[]) break; case 'h': /* --help display this help and exit */ display_usage(stdout,argv[0]); - exit(0); + exit(EXIT_SUCCESS); case 'V': /* --version output version information and exit */ display_version(stdout); - exit(0); + exit(EXIT_SUCCESS); case ':': /* missing required parameter */ case '?': /* unknown option character or extraneous parameter */ default: fprintf(stderr,"Try `%s --help' for more information.\n", argv[0]); - exit(1); + exit(EXIT_FAILURE); } } /* check for remaining arguments */ @@ -141,7 +141,7 @@ static void parse_cmdline(int argc,char *argv[]) argv[0],argv[optind]); fprintf(stderr,"Try `%s --help' for more information.\n", argv[0]); - exit(1); + exit(EXIT_FAILURE); } } @@ -209,8 +209,10 @@ static RETSIGTYPE sigexit_handler(int signum) nslcd_exitsignal=signum; /* cancel all running threads */ for (i=0;i<NUM_THREADS;i++) - pthread_cancel(nslcd_threads[i]); - + if (pthread_cancel(nslcd_threads[i])) + { + log_log(LOG_WARNING,"failed to stop thread %d (ignored): %s",i,strerror(errno)); + } } @@ -251,7 +253,7 @@ static int open_socket(void) if ( (sock=socket(PF_UNIX,SOCK_STREAM,0))<0 ) { log_log(LOG_ERR,"cannot create socket: %s",strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } /* remove existing named socket */ @@ -273,7 +275,7 @@ static int open_socket(void) strerror(errno)); if (close(sock)) log_log(LOG_WARNING,"problem closing socket: %s",strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } /* close the file descriptor on exit */ @@ -282,16 +284,16 @@ static int open_socket(void) log_log(LOG_ERR,"fctnl(F_SETFL,O_NONBLOCK) failed: %s",strerror(errno)); if (close(sock)) log_log(LOG_WARNING,"problem closing socket: %s",strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } /* set permissions of socket so anybody can do requests */ - if (fchmod(sock,0666)) + if (fchmod(sock,(mode_t)0666)) { log_log(LOG_ERR,"fctnl(F_SETFL,O_NONBLOCK) failed: %s",strerror(errno)); if (close(sock)) log_log(LOG_WARNING,"problem closing socket: %s",strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } /* start listening for connections */ @@ -300,7 +302,7 @@ static int open_socket(void) log_log(LOG_ERR,"listen() failed: %s",strerror(errno)); if (close(sock)) log_log(LOG_WARNING,"problem closing socket: %s",strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } /* we're done */ @@ -314,7 +316,7 @@ static int read_header(FILE *fp,int32_t *action) int32_t tmpint32; /* read the protocol version */ READ_TYPE(fp,tmpint32,int32_t); - if (tmpint32 != NSLCD_VERSION) + if (tmpint32 != (int32_t)NSLCD_VERSION) { log_log(LOG_DEBUG,"wrong nslcd version id (%d)",(int)tmpint32); return -1; @@ -333,8 +335,13 @@ static void handleconnection(int sock) struct ucred client; int32_t action; + /* initialize client information (in case getsockopt() breaks) */ + client.pid=(pid_t)0; + client.uid=(uid_t)-1; + client.gid=(gid_t)-1; + /* look up process information from client */ - alen=sizeof(struct ucred); + alen=(socklen_t)sizeof(struct ucred); if (getsockopt(sock,SOL_SOCKET,SO_PEERCRED,&client,&alen) < 0) { log_log(LOG_ERR,"getsockopt(SO_PEERCRED) failed: %s",strerror(errno)); @@ -351,57 +358,57 @@ static void handleconnection(int sock) if ((fp=fdopen(sock,"w+"))==NULL) { log_log(LOG_WARNING,"cannot create stream for writing: %s",strerror(errno)); - close(sock); + (void)close(sock); return; } /* read request */ if (read_header(fp,&action)) { - fclose(fp); + (void)fclose(fp); return; } /* handle request */ switch (action) { - case NSLCD_ACTION_ALIAS_BYNAME: nslcd_alias_byname(fp); break; - case NSLCD_ACTION_ALIAS_ALL: nslcd_alias_all(fp); break; - case NSLCD_ACTION_ETHER_BYNAME: nslcd_ether_byname(fp); break; - case NSLCD_ACTION_ETHER_BYETHER: nslcd_ether_byether(fp); break; - case NSLCD_ACTION_ETHER_ALL: nslcd_ether_all(fp); break; - case NSLCD_ACTION_GROUP_BYNAME: nslcd_group_byname(fp); break; - case NSLCD_ACTION_GROUP_BYGID: nslcd_group_bygid(fp); break; - case NSLCD_ACTION_GROUP_BYMEMBER: nslcd_group_bymember(fp); break; - case NSLCD_ACTION_GROUP_ALL: nslcd_group_all(fp); break; - case NSLCD_ACTION_HOST_BYNAME: nslcd_host_byname(fp); break; - case NSLCD_ACTION_HOST_BYADDR: nslcd_host_byaddr(fp); break; - case NSLCD_ACTION_HOST_ALL: nslcd_host_all(fp); break; - case NSLCD_ACTION_NETGROUP_BYNAME: nslcd_netgroup_byname(fp); break; - case NSLCD_ACTION_NETWORK_BYNAME: nslcd_network_byname(fp); break; - case NSLCD_ACTION_NETWORK_BYADDR: nslcd_network_byaddr(fp); break; - case NSLCD_ACTION_NETWORK_ALL: nslcd_network_all(fp); break; - case NSLCD_ACTION_PASSWD_BYNAME: nslcd_passwd_byname(fp); break; - case NSLCD_ACTION_PASSWD_BYUID: nslcd_passwd_byuid(fp); break; - case NSLCD_ACTION_PASSWD_ALL: nslcd_passwd_all(fp); break; - case NSLCD_ACTION_PROTOCOL_BYNAME: nslcd_protocol_byname(fp); break; - case NSLCD_ACTION_PROTOCOL_BYNUMBER:nslcd_protocol_bynumber(fp); break; - case NSLCD_ACTION_PROTOCOL_ALL: nslcd_protocol_all(fp); break; - case NSLCD_ACTION_RPC_BYNAME: nslcd_rpc_byname(fp); break; - case NSLCD_ACTION_RPC_BYNUMBER: nslcd_rpc_bynumber(fp); break; - case NSLCD_ACTION_RPC_ALL: nslcd_rpc_all(fp); break; - case NSLCD_ACTION_SERVICE_BYNAME: nslcd_service_byname(fp); break; - case NSLCD_ACTION_SERVICE_BYNUMBER: nslcd_service_bynumber(fp); break; - case NSLCD_ACTION_SERVICE_ALL: nslcd_service_all(fp); break; - case NSLCD_ACTION_SHADOW_BYNAME: nslcd_shadow_byname(fp); break; - case NSLCD_ACTION_SHADOW_ALL: nslcd_shadow_all(fp); break; + case NSLCD_ACTION_ALIAS_BYNAME: (void)nslcd_alias_byname(fp); break; + case NSLCD_ACTION_ALIAS_ALL: (void)nslcd_alias_all(fp); break; + case NSLCD_ACTION_ETHER_BYNAME: (void)nslcd_ether_byname(fp); break; + case NSLCD_ACTION_ETHER_BYETHER: (void)nslcd_ether_byether(fp); break; + case NSLCD_ACTION_ETHER_ALL: (void)nslcd_ether_all(fp); break; + case NSLCD_ACTION_GROUP_BYNAME: (void)nslcd_group_byname(fp); break; + case NSLCD_ACTION_GROUP_BYGID: (void)nslcd_group_bygid(fp); break; + case NSLCD_ACTION_GROUP_BYMEMBER: (void)nslcd_group_bymember(fp); break; + case NSLCD_ACTION_GROUP_ALL: (void)nslcd_group_all(fp); break; + case NSLCD_ACTION_HOST_BYNAME: (void)nslcd_host_byname(fp); break; + case NSLCD_ACTION_HOST_BYADDR: (void)nslcd_host_byaddr(fp); break; + case NSLCD_ACTION_HOST_ALL: (void)nslcd_host_all(fp); break; + case NSLCD_ACTION_NETGROUP_BYNAME: (void)nslcd_netgroup_byname(fp); break; + case NSLCD_ACTION_NETWORK_BYNAME: (void)nslcd_network_byname(fp); break; + case NSLCD_ACTION_NETWORK_BYADDR: (void)nslcd_network_byaddr(fp); break; + case NSLCD_ACTION_NETWORK_ALL: (void)nslcd_network_all(fp); break; + case NSLCD_ACTION_PASSWD_BYNAME: (void)nslcd_passwd_byname(fp); break; + case NSLCD_ACTION_PASSWD_BYUID: (void)nslcd_passwd_byuid(fp); break; + case NSLCD_ACTION_PASSWD_ALL: (void)nslcd_passwd_all(fp); break; + case NSLCD_ACTION_PROTOCOL_BYNAME: (void)nslcd_protocol_byname(fp); break; + case NSLCD_ACTION_PROTOCOL_BYNUMBER:(void)nslcd_protocol_bynumber(fp); break; + case NSLCD_ACTION_PROTOCOL_ALL: (void)nslcd_protocol_all(fp); break; + case NSLCD_ACTION_RPC_BYNAME: (void)nslcd_rpc_byname(fp); break; + case NSLCD_ACTION_RPC_BYNUMBER: (void)nslcd_rpc_bynumber(fp); break; + case NSLCD_ACTION_RPC_ALL: (void)nslcd_rpc_all(fp); break; + case NSLCD_ACTION_SERVICE_BYNAME: (void)nslcd_service_byname(fp); break; + case NSLCD_ACTION_SERVICE_BYNUMBER: (void)nslcd_service_bynumber(fp); break; + case NSLCD_ACTION_SERVICE_ALL: (void)nslcd_service_all(fp); break; + case NSLCD_ACTION_SHADOW_BYNAME: (void)nslcd_shadow_byname(fp); break; + case NSLCD_ACTION_SHADOW_ALL: (void)nslcd_shadow_all(fp); break; default: log_log(LOG_WARNING,"invalid request id: %d",(int)action); break; } /* we're done with the request */ - fclose(fp); + (void)fclose(fp); return; } @@ -457,17 +464,17 @@ static void write_pidfile(const char *filename) if ((fp=fopen(filename,"w"))==NULL) { log_log(LOG_ERR,"cannot open pid file (%s): %s",filename,strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } if (fprintf(fp,"%d\n",(int)getpid())<=0) { log_log(LOG_ERR,"error writing pid file (%s)",filename); - exit(1); + exit(EXIT_FAILURE); } if (fclose(fp)) { log_log(LOG_ERR,"error writing pid file (%s): %s",filename,strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } } } @@ -484,7 +491,7 @@ static void install_sighandler(int signum,RETSIGTYPE (*handler) (int)) if (sigaction(signum,&act,NULL)!=0) { log_log(LOG_ERR,"error installing signal handler for '%s': %s",signame(signum),strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } } @@ -503,8 +510,8 @@ static void *worker(void UNUSED(*arg)) /* the main program... */ int main(int argc,char *argv[]) { - gid_t mygid=-1; - uid_t myuid=-1; + gid_t mygid=(gid_t)-1; + uid_t myuid=(uid_t)-1; int i; /* parse the command line */ @@ -526,11 +533,11 @@ int main(int argc,char *argv[]) if ((!nslcd_debugging)&&(daemon(0,0)<0)) { log_log(LOG_ERR,"unable to daemonize: %s",strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } /* set default mode for pidfile and socket */ - umask(0022); + (void)umask((mode_t)0022); /* intilialize logging */ if (!nslcd_debugging) @@ -538,7 +545,11 @@ int main(int argc,char *argv[]) log_log(LOG_INFO,"version %s starting",VERSION); /* install handler to close stuff off on exit and log notice */ - atexit(exithandler); + if (atexit(exithandler)) + { + log_log(LOG_ERR,"atexit() failed: %s",strerror(errno)); + exit(EXIT_FAILURE); + } /* write pidfile */ write_pidfile(NSLCD_PIDFILE); @@ -566,7 +577,7 @@ int main(int argc,char *argv[]) if (prctl(PR_SET_KEEPCAPS,1)) { log_log(LOG_ERR,"cannot prctl(PR_SET_KEEPCAPS,1): %s",strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } log_log(LOG_DEBUG,"debug: prctl(PR_SET_KEEPCAPS,1) done"); /* dump the current capabilities */ @@ -581,7 +592,7 @@ int main(int argc,char *argv[]) if (setgid(mygid)!=0) { log_log(LOG_ERR,"cannot setgid(%d): %s",(int)mygid,strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } log_log(LOG_DEBUG,"debug: setgid(%d) done",mygid); } @@ -592,7 +603,7 @@ int main(int argc,char *argv[]) if (setuid(myuid)!=0) { log_log(LOG_ERR,"cannot setuid(%d): %s",(int)myuid,strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } log_log(LOG_DEBUG,"debug: setuid(%d) done",myuid); } @@ -602,7 +613,7 @@ int main(int argc,char *argv[]) if (cap_set_proc(mycapabilities)!=0) { log_log(LOG_ERR,"cannot cap_set_proc(%s): %s",cap_to_text(mycapabilities,NULL),strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } log_log(LOG_DEBUG,"debug: cap_set_proc(%2) done",cap_to_text(mycapabilities,NULL)); /* we no longer need this so we should free it */ @@ -632,7 +643,7 @@ int main(int argc,char *argv[]) if (pthread_create(&nslcd_threads[i],NULL,worker,NULL)) { log_log(LOG_ERR,"unable to start worker thread %d: %s",i,strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } } @@ -642,7 +653,7 @@ int main(int argc,char *argv[]) if (pthread_join(nslcd_threads[i],NULL)) { log_log(LOG_ERR,"unable to wait for worker thread %d: %s",i,strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } } @@ -653,5 +664,5 @@ int main(int argc,char *argv[]) signame(nslcd_exitsignal),nslcd_exitsignal); } - return 1; + return EXIT_FAILURE; } diff --git a/nslcd/passwd.c b/nslcd/passwd.c index 02c0d6d..e80a691 100644 --- a/nslcd/passwd.c +++ b/nslcd/passwd.c @@ -78,6 +78,11 @@ static enum nss_status _nss_ldap_parse_pw (LDAPMessage * e, struct ldap_state * pvt, void *result, char *buffer, size_t buflen) { + /* FIXME: fix following problem: + if the entry has multiple uid fields we may end up + sending the wrong uid, we should return the requested + uid instead, otherwise write an entry for each uid + (maybe also for uidNumber) */ struct passwd *pw = (struct passwd *) result; char *uid, *gid; enum nss_status stat; diff --git a/nslcd/protocol.c b/nslcd/protocol.c index 30e42d4..c2a14cf 100644 --- a/nslcd/protocol.c +++ b/nslcd/protocol.c @@ -54,7 +54,7 @@ #include "log.h" static enum nss_status _nss_ldap_parse_proto (LDAPMessage *e, - struct ldap_state *pvt, + struct ldap_state UNUSED(*pvt), void *result, char *buffer, size_t buflen) { diff --git a/nslcd/rpc.c b/nslcd/rpc.c index edb54d9..6ce4198 100644 --- a/nslcd/rpc.c +++ b/nslcd/rpc.c @@ -74,7 +74,7 @@ static int write_rpcent(FILE *fp,struct rpcent *result) } static enum nss_status _nss_ldap_parse_rpc (LDAPMessage * e, - struct ldap_state * pvt, + struct ldap_state UNUSED(*pvt), void *result, char *buffer, size_t buflen) { diff --git a/nslcd/shadow.c b/nslcd/shadow.c index e2473af..86514c2 100644 --- a/nslcd/shadow.c +++ b/nslcd/shadow.c @@ -50,7 +50,7 @@ #include "log.h" static enum nss_status _nss_ldap_parse_sp(LDAPMessage *e, - struct ldap_state *pvt, + struct ldap_state UNUSED(*pvt), void *result,char *buffer,size_t buflen) { struct spwd *sp = (struct spwd *) result; diff --git a/nslcd/util.c b/nslcd/util.c index 68ee0b1..0f4d7dd 100644 --- a/nslcd/util.c +++ b/nslcd/util.c @@ -109,7 +109,7 @@ do_find_last (struct ldap_dictionary *dict) } static enum nss_status -do_dup_datum (unsigned flags, struct ldap_datum * dst, const struct ldap_datum * src) +do_dup_datum (struct ldap_datum * dst, const struct ldap_datum * src) { dst->data = malloc (src->size); if (dst->data == NULL) @@ -142,7 +142,6 @@ do_free_dictionary (struct ldap_dictionary *dict) static enum nss_status old_dict_put( struct ldap_dictionary *db, - unsigned flags, const struct ldap_datum *key, const struct ldap_datum *value) { @@ -168,13 +167,13 @@ static enum nss_status old_dict_put( return NSS_STATUS_TRYAGAIN; } - if (do_dup_datum(flags,&q->key,key)!=NSS_STATUS_SUCCESS) + if (do_dup_datum(&q->key,key)!=NSS_STATUS_SUCCESS) { do_free_dictionary(q); return NSS_STATUS_TRYAGAIN; } - if (do_dup_datum(flags,&q->value,value)!=NSS_STATUS_SUCCESS) + if (do_dup_datum(&q->value,value)!=NSS_STATUS_SUCCESS) { do_free_dictionary(q); return NSS_STATUS_TRYAGAIN; @@ -235,7 +234,7 @@ dn2uid_cache_put (const char *dn, const char *uid) val.data = (void *) uid; val.size = strlen (uid); - status = old_dict_put (__cache, 0, &key, &val); + status = old_dict_put (__cache, &key, &val); cache_unlock (); @@ -282,9 +281,9 @@ dn2uid_cache_get (const char *dn, char **uid, char **buffer, size_t * buflen) return NSS_STATUS_SUCCESS; } -enum nss_status -_nss_ldap_dn2uid (const char *dn, char **uid, char **buffer, size_t * buflen, - int *pIsNestedGroup, LDAPMessage ** pRes) +enum nss_status _nss_ldap_dn2uid(const char *dn,char **uid,char **buffer, + size_t * buflen,int *pIsNestedGroup, + LDAPMessage **pRes) { enum nss_status status; diff --git a/nslcd/util.h b/nslcd/util.h index 18cf06a..f329daf 100644 --- a/nslcd/util.h +++ b/nslcd/util.h @@ -32,7 +32,7 @@ */ enum nss_status _nss_ldap_getrdnvalue(LDAPMessage *entry, const char *rdntype, - char **rval, char **buf, size_t * len); + char **rval, char **buffer, size_t * buflen); int _nss_ldap_write_rndvalue(FILE *fp,LDAPMessage *entry,const char *rdntype); @@ -40,13 +40,13 @@ int _nss_ldap_write_rndvalue(FILE *fp,LDAPMessage *entry,const char *rdntype); * map a distinguished name to a login name, or group entry */ enum nss_status _nss_ldap_dn2uid (const char *dn, - char **uid, char **buf, size_t * len, + char **uid, char **buffer, size_t * buflen, int *pIsNestedGroup, LDAPMessage ** pRes); /* * Escape '*' in a string for use as a filter */ -int _nss_ldap_escape_string(const char *str,char *buf,size_t buflen); +int _nss_ldap_escape_string(const char *src,char *buffer,size_t buflen); #endif /* _LDAP_NSS_LDAP_UTIL_H */ diff --git a/nss/common.c b/nss/common.c index da4c68f..29e06f2 100644 --- a/nss/common.c +++ b/nss/common.c @@ -37,7 +37,7 @@ /* translates a nsklcd return code (as defined in nslcd.h) to a nss code (as defined in nss.h) */ -enum nss_status nslcd2nss(int code) +enum nss_status nslcd2nss(int32_t code) { switch (code) { @@ -62,15 +62,15 @@ FILE *nslcd_client_open() addr.sun_family=AF_UNIX; strcpy(addr.sun_path,NSLCD_SOCKET); /* connect to the socket */ - if (connect(sock,(struct sockaddr *)&addr,sizeof(struct sockaddr_un))<0) + if (connect(sock,(struct sockaddr *)&addr,(socklen_t)sizeof(struct sockaddr_un))<0) { - close(sock); + (void)close(sock); return NULL; } /* create a stream object */ if ((fp=fdopen(sock,"w+"))==NULL) { - close(sock); + (void)close(sock); return NULL; } /* return the stream */ diff --git a/nss/common.h b/nss/common.h index 723d203..03c60b4 100644 --- a/nss/common.h +++ b/nss/common.h @@ -32,8 +32,7 @@ /* This function maps an nslcd return code (as defined in nslcd.h) to an nss code (as defined in nss.h). */ -enum nss_status nslcd2nss(int code) - PURE MUST_USE; +enum nss_status nslcd2nss(int32_t code); /* returns a socket to the server or NULL on error (see errno), socket should be closed with fclose() */ @@ -51,24 +50,24 @@ FILE *nslcd_client_open(void) /* Write a request header with a request code. */ #define WRITE_REQUEST(fp,req) \ - WRITE_INT32(fp,NSLCD_VERSION) \ - WRITE_INT32(fp,req) + WRITE_INT32(fp,(int32_t)NSLCD_VERSION) \ + WRITE_INT32(fp,(int32_t)req) /* Read a response header and check that the returned request code equals the expected code. */ #define READ_RESPONSEHEADER(fp,req) \ READ_TYPE(fp,tmpint32,int32_t); \ - if (tmpint32!=NSLCD_VERSION) \ + if (tmpint32!=(int32_t)NSLCD_VERSION) \ { ERROR_OUT_READERROR(fp) } \ READ_TYPE(fp,tmpint32,int32_t); \ - if (tmpint32!=(req)) \ + if (tmpint32!=(int32_t)(req)) \ { ERROR_OUT_READERROR(fp) } /* Read the response code (the result code of the query) from the stream. */ #define READ_RESPONSE_CODE(fp) \ READ_TYPE(fp,tmpint32,int32_t); \ - if (tmpint32!=NSLCD_RESULT_SUCCESS) \ + if (tmpint32!=(int32_t)NSLCD_RESULT_SUCCESS) \ { ERROR_OUT_NOSUCCESS(fp,tmpint32) } /* These are macros for handling read and write problems, they are @@ -83,7 +82,7 @@ FILE *nslcd_client_open(void) /* Macro is called to handle errors on fread(). */ #define ERROR_OUT_READERROR(fp) \ - fclose(fp); \ + (void)fclose(fp); \ fp=NULL; \ *errnop=ENOENT; \ return NSS_STATUS_UNAVAIL; @@ -94,7 +93,7 @@ FILE *nslcd_client_open(void) Something more inteligent (e.g. ungetting the read data from the stream) should be implemented. */ #define ERROR_OUT_BUFERROR(fp) \ - fclose(fp); \ + (void)fclose(fp); \ fp=NULL; \ *errnop=ERANGE; \ return NSS_STATUS_TRYAGAIN; @@ -107,7 +106,7 @@ FILE *nslcd_client_open(void) /* This macro is called if the read status code is not NSLCD_RESULT_SUCCESS. */ #define ERROR_OUT_NOSUCCESS(fp,retv) \ - fclose(fp); \ + (void)fclose(fp); \ fp=NULL; \ *errnop=ENOENT; \ return nslcd2nss(retv); @@ -141,7 +140,7 @@ FILE *nslcd_client_open(void) retv=readfn; \ /* close socket and we're done */ \ if (retv==NSS_STATUS_SUCCESS) \ - fclose(fp); \ + (void)fclose(fp); \ return retv; /* This macro can be used to generate a get..byname() function @@ -169,7 +168,7 @@ FILE *nslcd_client_open(void) errnop=&errnocp; \ /* close the existing stream if it is still open */ \ if (fp!=NULL) \ - fclose(fp); \ + (void)fclose(fp); \ /* open a new stream and write the request */ \ OPEN_SOCK(fp); \ WRITE_REQUEST(fp,action); \ @@ -202,7 +201,7 @@ FILE *nslcd_client_open(void) #define NSS_ENDENT(fp) \ if (fp!=NULL) \ { \ - fclose(fp); \ + (void)fclose(fp); \ fp=NULL; \ } \ return NSS_STATUS_SUCCESS; diff --git a/nss/group.c b/nss/group.c index 4e51f94..ebf09a9 100644 --- a/nss/group.c +++ b/nss/group.c @@ -50,12 +50,12 @@ static enum nss_status read_gids( FILE *fp,long int *start,long int *size, gid_t **groupsp,long int limit,int *errnop) { - int32_t res=NSLCD_RESULT_SUCCESS; + int32_t res=(int32_t)NSLCD_RESULT_SUCCESS; int32_t tmpint32,tmp2int32,tmp3int32; gid_t gid; int num=0; /* loop over results */ - while (res==NSLCD_RESULT_SUCCESS) + while (res==(int32_t)NSLCD_RESULT_SUCCESS) { /* skip group name */ SKIP_STRING(fp); @@ -77,7 +77,7 @@ static enum nss_status read_gids( READ_TYPE(fp,res,int32_t); } /* return the proper status code */ - return (res==NSLCD_RESULT_NOTFOUND)?NSS_STATUS_SUCCESS:nslcd2nss(res); + return (res==(int32_t)NSLCD_RESULT_NOTFOUND)?NSS_STATUS_SUCCESS:nslcd2nss(res); } #endif /* REENABLE_WHEN_WORKING */ diff --git a/nss/hosts.c b/nss/hosts.c index 2720b54..2eae67d 100644 --- a/nss/hosts.c +++ b/nss/hosts.c @@ -40,7 +40,7 @@ #undef ERROR_OUT_READERROR #define ERROR_OUT_READERROR(fp) \ - fclose(fp); \ + (void)fclose(fp); \ fp=NULL; \ *errnop=ENOENT; \ *h_errnop=NO_RECOVERY; \ @@ -48,7 +48,7 @@ #undef ERROR_OUT_BUFERROR #define ERROR_OUT_BUFERROR(fp) \ - fclose(fp); \ + (void)fclose(fp); \ fp=NULL; \ *errnop=ERANGE; \ *h_errnop=TRY_AGAIN; \ @@ -60,7 +60,7 @@ #undef ERROR_OUT_NOSUCCESS #define ERROR_OUT_NOSUCCESS(fp,retv) \ - fclose(fp); \ + (void)fclose(fp); \ fp=NULL; \ *errnop=ENOENT; \ *h_errnop=HOST_NOT_FOUND; \ @@ -75,7 +75,8 @@ static enum nss_status read_hostent( char *buffer,size_t buflen,int *errnop,int *h_errnop) { int32_t tmpint32,tmp2int32,tmp3int32; - int numaddr,i; + int32_t numaddr; + int i; int readaf; size_t bufptr=0; /* read the host entry */ @@ -88,7 +89,7 @@ static enum nss_status read_hostent( /* allocate memory for array */ /* Note: this may allocate too much memory (e.g. also for address records of other address families) but - this is an easy way to do it */ + this is a simple way to do it */ BUF_ALLOC(fp,result->h_addr_list,char *,numaddr+1); /* go through the address list and filter on af */ i=0; @@ -134,7 +135,7 @@ static enum nss_status read_hostent_erronempty( { *errnop=ENOENT; *h_errnop=NO_ADDRESS; - fclose(fp); + (void)fclose(fp); return NSS_STATUS_NOTFOUND; } return NSS_STATUS_SUCCESS; diff --git a/nss/netgroup.c b/nss/netgroup.c index 3f0a60f..39f77f6 100644 --- a/nss/netgroup.c +++ b/nss/netgroup.c @@ -35,7 +35,7 @@ if we have sucessfully read some entries */ #undef ERROR_OUT_NOSUCCESS #define ERROR_OUT_NOSUCCESS(fp,retv) \ - fclose(fp); \ + (void)fclose(fp); \ fp=NULL; \ if (result->first) \ { \ diff --git a/nss/networks.c b/nss/networks.c index 37653f3..91dfc52 100644 --- a/nss/networks.c +++ b/nss/networks.c @@ -40,7 +40,7 @@ #undef ERROR_OUT_READERROR #define ERROR_OUT_READERROR(fp) \ - fclose(fp); \ + (void)fclose(fp); \ fp=NULL; \ *errnop=ENOENT; \ *h_errnop=NO_RECOVERY; \ @@ -48,7 +48,7 @@ #undef ERROR_OUT_BUFERROR #define ERROR_OUT_BUFERROR(fp) \ - fclose(fp); \ + (void)fclose(fp); \ fp=NULL; \ *errnop=ERANGE; \ *h_errnop=TRY_AGAIN; \ @@ -60,7 +60,7 @@ #undef ERROR_OUT_NOSUCCESS #define ERROR_OUT_NOSUCCESS(fp,retv) \ - fclose(fp); \ + (void)fclose(fp); \ fp=NULL; \ *errnop=ENOENT; \ *h_errnop=HOST_NOT_FOUND; \ @@ -94,7 +94,7 @@ static enum nss_status read_netent( { /* read address and translate to host byte order */ READ_TYPE(fp,tmpint32,int32_t); - result->n_net=ntohl(tmpint32); + result->n_net=ntohl((uint32_t)tmpint32); /* signal that we've read a proper entry */ retv=NSS_STATUS_SUCCESS; /* don't return here to not upset the stream */ diff --git a/nss/prototypes.h b/nss/prototypes.h index 6cf039e..c41e797 100644 --- a/nss/prototypes.h +++ b/nss/prototypes.h @@ -99,8 +99,8 @@ enum nss_status _nss_ldap_getaliasent_r(struct aliasent *result,char *buffer,siz enum nss_status _nss_ldap_endaliasent(void); /* ethers - ethernet numbers */ -enum nss_status _nss_ldap_gethostton_r(const char *name,struct etherent *resut,char *buffer,size_t buflen,int *errnop); -enum nss_status _nss_ldap_getntohost_r(const struct ether_addr *addr,struct etherent *eth,char *buffer,size_t buflen,int *errnop); +enum nss_status _nss_ldap_gethostton_r(const char *name,struct etherent *result,char *buffer,size_t buflen,int *errnop); +enum nss_status _nss_ldap_getntohost_r(const struct ether_addr *addr,struct etherent *result,char *buffer,size_t buflen,int *errnop); enum nss_status _nss_ldap_setetherent(int stayopen); enum nss_status _nss_ldap_getetherent_r(struct etherent *result,char *buffer,size_t buflen,int *errnop); enum nss_status _nss_ldap_endetherent(void); diff --git a/nss/services.c b/nss/services.c index f79012a..f9ec7c5 100644 --- a/nss/services.c +++ b/nss/services.c @@ -40,7 +40,7 @@ static enum nss_status read_servent( READ_STRINGLIST_NULLTERM(fp,result->s_aliases); /* store port number in network byte order */ READ_TYPE(fp,tmpint32,int32_t); - result->s_port=ntohs(tmpint32); + result->s_port=ntohs((uint16_t)tmpint32); READ_STRING_BUF(fp,result->s_proto); /* we're done */ return NSS_STATUS_SUCCESS; |