From 48d51b66fac883fc8648fb6b9df487382b8addc2 Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Sun, 4 Mar 2007 20:03:06 +0000 Subject: 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 --- nslcd-common.h | 8 +-- nslcd/alias.c | 9 ++-- nslcd/ether.c | 6 ++- nslcd/group.c | 9 +++- nslcd/ldap-nss.c | 11 +++-- nslcd/ldap-nss.h | 22 ++++----- nslcd/ldap-schema.c | 10 ---- nslcd/ldap-schema.h | 4 -- nslcd/log.c | 4 +- nslcd/nslcd.c | 139 ++++++++++++++++++++++++++++------------------------ nslcd/passwd.c | 5 ++ nslcd/protocol.c | 2 +- nslcd/rpc.c | 2 +- nslcd/shadow.c | 2 +- nslcd/util.c | 15 +++--- nslcd/util.h | 6 +-- nss/common.c | 8 +-- nss/common.h | 25 +++++----- nss/group.c | 6 +-- nss/hosts.c | 13 ++--- nss/netgroup.c | 2 +- nss/networks.c | 8 +-- nss/prototypes.h | 4 +- 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 (1024fp=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;idata = 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; -- cgit v1.2.3