]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
libpts: Use path_base|dirname()
authorTobias Brunner <tobias@strongswan.org>
Mon, 24 Feb 2014 10:26:46 +0000 (11:26 +0100)
committerTobias Brunner <tobias@strongswan.org>
Mon, 24 Feb 2014 11:04:11 +0000 (12:04 +0100)
src/libpts/plugins/imv_attestation/attest.c
src/libpts/pts/pts.c
src/libpts/pts/pts_database.c
src/libpts/pts/pts_file_meas.c

index 6e63c26531dbd4d82e538b1439e84312e6f49922..b8a6854cb43a176424dc85ab98bb348570e48244 100644 (file)
@@ -266,19 +266,20 @@ static void do_args(int argc, char *argv[])
                                continue;
                        case 'F':
                        {
-                               char *path = strdup(optarg);
-                               char *dir = dirname(path);
-                               char *file = basename(optarg);
+                               char *dir = path_dirname(optarg);
+                               char *file = path_basename(optarg);
 
                                if (*dir != '.')
                                {
                                        if (!attest->set_directory(attest, dir, op == OP_ADD))
                                        {
-                                               free(path);
+                                               free(file);
+                                               free(dir);
                                                exit(EXIT_FAILURE);
                                        }
                                }
-                               free(path);
+                               free(file);
+                               free(dir);
                                if (!attest->set_file(attest, file, op == OP_ADD))
                                {
                                        exit(EXIT_FAILURE);
index f528d4520b82b6d264f06e5c5abb053eb36976d0..8699282f06b5a8e3df6b6eaf0d48a9f31d60dc4d 100644 (file)
@@ -627,7 +627,7 @@ METHOD(pts_t, get_metadata, pts_file_meta_t*,
                        metadata->destroy(metadata);
                        return NULL;
                }
-               entry->filename = strdup(basename(pathname));
+               entry->filename = path_basename(pathname);
                metadata->add(metadata, entry);
        }
 
index 95b1114f6ec36793363b73e21497efc9c1240c34..07e8ae1dac6ebe3b7b6b9e2275c247a3bace0a51 100644 (file)
@@ -249,7 +249,7 @@ METHOD(pts_database_t, check_file_measurement, status_t,
        enumerator_t *e;
        chunk_t hash;
        status_t status = NOT_FOUND;
-       char *path, *dir, *file;
+       char *dir, *file;
 
        if (strlen(filename) < 1)
        {
@@ -257,9 +257,8 @@ METHOD(pts_database_t, check_file_measurement, status_t,
        }
 
        /* separate filename into directory and basename components */
-       path = strdup(filename);
-       dir = dirname(path);
-       file = basename(filename);
+       dir = path_dirname(filename);
+       file = path_basename(filename);
 
        if (*dir == '.')
        {       /* relative pathname */
@@ -281,7 +280,8 @@ METHOD(pts_database_t, check_file_measurement, status_t,
                                DB_TEXT, dir, DB_INT);
                if (!e)
                {
-                       free(path);
+                       free(file);
+                       free(dir);
                        return FAILED;
                }
                dir_found = e->enumerate(e, &did);
@@ -289,7 +289,8 @@ METHOD(pts_database_t, check_file_measurement, status_t,
 
                if (!dir_found)
                {
-                       free(path);
+                       free(file);
+                       free(dir);
                        return NOT_FOUND;
                }
 
@@ -301,7 +302,8 @@ METHOD(pts_database_t, check_file_measurement, status_t,
                                DB_TEXT, product, DB_INT, did, DB_TEXT, file, DB_INT, algo,
                                DB_BLOB);
        }
-       free(path);
+       free(file);
+       free(dir);
 
        if (!e)
        {
index f684087d7cfa3a4ff1d93df30c51b6b3b447bfb6..77a0957bbb41960652538e0726d51f13644df488 100644 (file)
@@ -341,9 +341,10 @@ pts_file_meas_t *pts_file_meas_create_from_path(u_int16_t request_id,
                        success = FALSE;
                        goto end;
                }
-               filename = use_rel_name ? basename(pathname) : pathname;
+               filename = use_rel_name ? path_basename(pathname) : strdup(pathname);
                DBG2(DBG_PTS, "  %#B for '%s'", &measurement, filename);
                add(this, filename, measurement);
+               free(filename);
        }
 
 end: