Fix more GCC warnings
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 18 Apr 2013 21:31:11 +0000 (17:31 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 18 Apr 2013 21:31:11 +0000 (17:31 -0400)
src/include/radiusd.h
src/modules/rlm_ldap/groups.c
src/modules/rlm_ldap/ldap.c
src/modules/rlm_linelog/rlm_linelog.c
src/modules/rlm_radutmp/rlm_radutmp.c
src/modules/rlm_sql/drivers/rlm_sql_sqlite/rlm_sql_sqlite.c

index 876f58c..33ca4eb 100644 (file)
@@ -485,6 +485,7 @@ typedef struct main_config_t {
 
 #if __GNUC__ >= 3
 #define RDEBUG(fmt, ...)    if(request && request->radlog) request->radlog(L_DBG, 1, request, fmt, ## __VA_ARGS__)
+#define RDEBUGI(fmt, ...)   if(request && request->radlog) request->radlog(L_INFO, 1, request, fmt, ## __VA_ARGS__)
 #define RDEBUGW(fmt, ...)   if(request && request->radlog) request->radlog(L_DBG_WARN, 1, request, fmt, ## __VA_ARGS__)
 #define RDEBUGE(fmt, ...)   do { if(request) { \
                                        module_failure_msg(request, fmt, ## __VA_ARGS__); \
index 00a0dc4..2cda28c 100644 (file)
@@ -443,7 +443,6 @@ rlm_rcode_t rlm_ldap_check_groupobj_dynamic(const ldap_instance_t *inst, REQUEST
                                            VALUE_PAIR *check)
                                            
 {
-       rlm_rcode_t     rcode = RLM_MODULE_NOTFOUND;
        ldap_rcode_t    status;
 
        char            base_dn[LDAP_MAX_DN_STR_LEN + 1];
@@ -486,9 +485,7 @@ rlm_rcode_t rlm_ldap_check_groupobj_dynamic(const ldap_instance_t *inst, REQUEST
                 *      rlm_ldap_find_user does this, too.  Oh well.
                 */
                if (radius_xlat(base_dn, sizeof(base_dn), request, inst->groupobj_base_dn, 
-                               rlm_ldap_escape_func, NULL) < 0) {
-                       rcode = RLM_MODULE_INVALID;
-                       
+                               rlm_ldap_escape_func, NULL) < 0) {              
                        RDEBUGE("Failed creating base_dn");
                
                        return RLM_MODULE_INVALID;
index 671bdf3..57d938b 100644 (file)
@@ -155,7 +155,7 @@ static size_t rlm_ldap_common_dn(const char *full, const char *part)
 ssize_t rlm_ldap_xlat_filter(REQUEST *request, const char **sub, size_t sublen, char *out, size_t outlen)
 {
        char buffer[LDAP_MAX_FILTER_STR_LEN + 1];
-       const char *in;
+       const char *in = NULL;
        char *p = buffer;
        
        ssize_t len = 0;
index f4260a0..fedf0c2 100644 (file)
@@ -313,7 +313,12 @@ static rlm_rcode_t do_linelog(void *instance, REQUEST *request)
        if (fd >= 0) {
                strcat(line, "\n");
                
-               write(fd, line, strlen(line));
+               if (write(fd, line, strlen(line)) < 0) {
+                       DEBUGE("rlm_linelog: Failed writing: %s", strerror(errno));
+                       
+                       return RLM_MODULE_FAIL;
+               }
+               
                close(fd);
 
 #ifdef HAVE_SYSLOG_H
index fae09ba..3e1e386 100644 (file)
@@ -76,10 +76,7 @@ static const CONF_PARSER module_config[] = {
 /*
  *     Zap all users on a NAS from the radutmp file.
  */
-static int radutmp_zap(REQUEST *request,
-                      const char *filename,
-                      uint32_t nasaddr,
-                      time_t t)
+static rlm_rcode_t radutmp_zap(REQUEST *request, const char *filename, uint32_t nasaddr, time_t t)
 {
        struct radutmp  u;
        int             fd;
@@ -88,42 +85,46 @@ static int radutmp_zap(REQUEST *request,
 
        fd = open(filename, O_RDWR);
        if (fd < 0) {
-               RDEBUGE("Error accessing file %s: %s",
-                      filename, strerror(errno));
+               RDEBUGE("Error accessing file %s: %s", filename, strerror(errno));
                return RLM_MODULE_FAIL;
        }
 
        /*
-        *      Lock the utmp file, prefer lockf() over flock().
-        */
+             Lock the utmp file, prefer lockf() over flock().
+       */
        if (rad_lockfd(fd, LOCK_LEN) < 0) {
-               RDEBUGE("Failed to acquire lock on file %s:"
-                      " %s", filename, strerror(errno));
+               RDEBUGE("Failed to acquire lock on file %s: %s", filename, strerror(errno));
                close(fd);
                return RLM_MODULE_FAIL;
        }
 
        /*
-        *      Find the entry for this NAS / portno combination.
-        */
+             Find the entry for this NAS / portno combination.
+       */
        while (read(fd, &u, sizeof(u)) == sizeof(u)) {
-         if ((nasaddr != 0 && nasaddr != u.nas_address) ||
-             u.type != P_LOGIN)
-           continue;
-         /*
-          *    Match. Zap it.
-          */
-         if (lseek(fd, -(off_t)sizeof(u), SEEK_CUR) < 0) {
-           RDEBUGE("radutmp_zap: negative lseek!");
-           lseek(fd, (off_t)0, SEEK_SET);
-         }
-         u.type = P_IDLE;
-         u.time = t;
-         write(fd, &u, sizeof(u));
+               if ((nasaddr != 0 && nasaddr != u.nas_address) || u.type != P_LOGIN) {
+                       continue;
+               }
+               /*
+                *      Match. Zap it.
+                */
+               if (lseek(fd, -(off_t)sizeof(u), SEEK_CUR) < 0) {
+                       RDEBUGE("radutmp_zap: negative lseek!");
+                       lseek(fd, (off_t)0, SEEK_SET);
+               }
+               u.type = P_IDLE;
+               u.time = t;
+
+               if (write(fd, &u, sizeof(u)) < 0) {
+                       RDEBUGE("Failed writing: %s", strerror(errno));
+       
+                       close(fd);
+                       return RLM_MODULE_FAIL;
+               }
        }
        close(fd);      /* and implicitely release the locks */
 
-       return 0;
+       return RLM_MODULE_OK;
 }
 
 /*
@@ -318,17 +319,15 @@ static rlm_rcode_t mod_accounting(void *instance, REQUEST *request)
         *      UDP packets out of order.
         */
        if (status == PW_STATUS_ACCOUNTING_ON && (ut.nas_address != htonl(INADDR_NONE))) {
-               radlog(L_INFO, "rlm_radutmp: NAS %s restarted (Accounting-On packet seen)", nas);
-               radutmp_zap(request, filename, ut.nas_address, ut.time);
-               rcode = RLM_MODULE_OK;
+               RDEBUGI("NAS %s restarted (Accounting-On packet seen)", nas);
+               rcode = radutmp_zap(request, filename, ut.nas_address, ut.time);
                
                goto finish;
        }
 
        if (status == PW_STATUS_ACCOUNTING_OFF && (ut.nas_address != htonl(INADDR_NONE))) {
-               radlog(L_INFO, "rlm_radutmp: NAS %s rebooted (Accounting-Off packet seen)", nas);
-               radutmp_zap(request, filename, ut.nas_address, ut.time);
-               rcode = RLM_MODULE_OK;
+               RDEBUGI("NAS %s rebooted (Accounting-Off packet seen)", nas);   
+               rcode = radutmp_zap(request, filename, ut.nas_address, ut.time);
                
                goto finish;
        }
@@ -486,7 +485,12 @@ static rlm_rcode_t mod_accounting(void *instance, REQUEST *request)
                }
 
                ut.type = P_LOGIN;
-               write(fd, &ut, sizeof(u));
+               if (write(fd, &ut, sizeof(u)) < 0) {
+                       RDEBUGE("Failed writing: %s", strerror(errno));
+                       
+                       rcode = RLM_MODULE_FAIL;
+                       goto finish;
+               }
        }
 
        /*
@@ -498,7 +502,12 @@ static rlm_rcode_t mod_accounting(void *instance, REQUEST *request)
                        u.type = P_IDLE;
                        u.time = ut.time;
                        u.delay = ut.delay;
-                       write(fd, &u, sizeof(u));
+                       if (write(fd, &u, sizeof(u)) < 0) {
+                               RDEBUGE("Failed writing: %s", strerror(errno));
+                       
+                               rcode = RLM_MODULE_FAIL;
+                               goto finish;
+                       }
                } else if (r == 0) {
                        RDEBUGW("Logout for NAS %s port %u, but no Login record", nas, ut.nas_port);
                }
@@ -512,7 +521,7 @@ static rlm_rcode_t mod_accounting(void *instance, REQUEST *request)
                close(fd);      /* and implicitely release the locks */
        }
        
-       return RLM_MODULE_OK;
+       return rcode;
 }
 #endif
 
index 5dd3f30..b8790a0 100644 (file)
@@ -81,7 +81,7 @@ static int sql_check_error(sqlite3 *db)
        case SQLITE_FULL:
        case SQLITE_CONSTRAINT:
        case SQLITE_MISMATCH:
-               DEBUGE("rlm_sql_sqlite: Error (%d): %s", error, sqlite3_errmsg(db));
+               radlog(L_ERR, "rlm_sql_sqlite: Error (%d): %s", error, sqlite3_errmsg(db));
                
                return -1;
                break;
@@ -90,7 +90,7 @@ static int sql_check_error(sqlite3 *db)
         *      Errors with the handle, that probably require reinitialisation
         */
        default:
-               DEBUGE("rlm_sql_sqlite: Handle is unusable, error (%d): %s", error, sqlite3_errmsg(db));
+               radlog(L_ERR, "rlm_sql_sqlite: Handle is unusable, error (%d): %s", error, sqlite3_errmsg(db));
                return SQL_DOWN;
                break;
        }
@@ -114,14 +114,14 @@ static int sql_loadfile(TALLOC_CTX *ctx, sqlite3 *db, const char *filename)
 
        f = fopen(filename, "r");
        if (!f) {
-               DEBUGE("rlm_sql_sqlite: Failed opening SQL file \"%s\": %s", filename,
+               radlog(L_ERR, "rlm_sql_sqlite: Failed opening SQL file \"%s\": %s", filename,
                       strerror(errno));
        
                return -1;
        }
        
        if (fstat(fileno(f), &finfo) < 0) {
-               DEBUGE("rlm_sql_sqlite: Failed stating SQL file \"%s\": %s", filename,
+               radlog(L_ERR, "rlm_sql_sqlite: Failed stating SQL file \"%s\": %s", filename,
                       strerror(errno));
                
                fclose(f);
@@ -131,7 +131,7 @@ static int sql_loadfile(TALLOC_CTX *ctx, sqlite3 *db, const char *filename)
        
        if (finfo.st_size > BOOTSTRAP_MAX) {
                too_big:
-               DEBUGE("rlm_sql_sqlite: Size of SQL (%zu) file exceeds limit (%uk)",
+               radlog(L_ERR, "rlm_sql_sqlite: Size of SQL (%zu) file exceeds limit (%uk)",
                       (size_t) finfo.st_size / 1024, BOOTSTRAP_MAX / 1024);
                
                fclose(f);
@@ -148,7 +148,7 @@ static int sql_loadfile(TALLOC_CTX *ctx, sqlite3 *db, const char *filename)
        
        if (!len) {
                if (ferror(f)) {
-                       DEBUGE("rlm_sql_sqlite: Error reading SQL file: %s", strerror(errno));
+                       radlog(L_ERR, "rlm_sql_sqlite: Error reading SQL file: %s", strerror(errno));
                        
                        fclose(f);
                        talloc_free(buffer);
@@ -156,7 +156,7 @@ static int sql_loadfile(TALLOC_CTX *ctx, sqlite3 *db, const char *filename)
                        return -1;
                }
                
-               DEBUG("rlm_sql_sqlite: Ignoring empty SQL file");
+               radlog(L_DBG, "rlm_sql_sqlite: Ignoring empty SQL file");
                
                fclose(f);
                talloc_free(buffer);
@@ -181,7 +181,7 @@ static int sql_loadfile(TALLOC_CTX *ctx, sqlite3 *db, const char *filename)
        }
        
        if ((p - buffer) != len) {
-               DEBUGE("rlm_sql_sqlite: Bootstrap file contains non-UTF8 char at offset %zu", p - buffer);
+               radlog(L_ERR, "rlm_sql_sqlite: Bootstrap file contains non-UTF8 char at offset %zu", p - buffer);
                talloc_free(buffer);
                return -1;
        }
@@ -245,7 +245,7 @@ static int mod_instantiate(CONF_SECTION *conf, rlm_sql_config_t *config)
        
        exists = rad_file_exists(driver->filename);
        if (exists < 0) {
-               DEBUGE("rlm_sql_sqlite: Database exists, but couldn't be opened: %s", strerror(errno));
+               radlog(L_ERR, "rlm_sql_sqlite: Database exists, but couldn't be opened: %s", strerror(errno));
        
                return -1;
        }
@@ -271,7 +271,7 @@ static int mod_instantiate(CONF_SECTION *conf, rlm_sql_config_t *config)
                }
                
                if (rad_mkdir(buff, 0700) < 0) {
-                       DEBUGE("rlm_sql_sqlite: Failed creating directory for SQLite database");
+                       radlog(L_ERR, "rlm_sql_sqlite: Failed creating directory for SQLite database");
                        
                        talloc_free(buff);
                        
@@ -282,7 +282,7 @@ static int mod_instantiate(CONF_SECTION *conf, rlm_sql_config_t *config)
 
                status = sqlite3_open_v2(driver->filename, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
                if (!db) {
-                       DEBUGE("rlm_sql_sqlite: Failed creating opening/creating SQLite database, error "
+                       radlog(L_ERR, "rlm_sql_sqlite: Failed creating opening/creating SQLite database, error "
                               "code (%u)", status);
                        
                        goto unlink;
@@ -298,14 +298,14 @@ static int mod_instantiate(CONF_SECTION *conf, rlm_sql_config_t *config)
                
                status = sqlite3_close(db);
                if (status != SQLITE_OK) {
-                       DEBUGE("rlm_sql_sqlite: Error closing SQLite handle, error code (%u)", status);
+                       radlog(L_ERR, "rlm_sql_sqlite: Error closing SQLite handle, error code (%u)", status);
                        goto unlink;
                }
                
                if (ret < 0) {
                        unlink:
                        if (unlink(driver->filename) < 0) {
-                               DEBUGE("rlm_sql_sqlite: Error removing partially initialised database: %s",
+                               radlog(L_ERR, "rlm_sql_sqlite: Error removing partially initialised database: %s",
                                       strerror(errno));
                        }
                        return -1;
@@ -354,7 +354,7 @@ static int sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *config)
        status = sqlite3_open(driver->filename, &(conn->db));
 #endif
        if (!conn->db) {
-               DEBUGE("rlm_sql_sqlite: Failed creating opening/creating SQLite database error code (%u)",
+               radlog(L_ERR, "rlm_sql_sqlite: Failed creating opening/creating SQLite database error code (%u)",
                       status);
                
                return -1;