diff options
Diffstat (limited to 'ubifs-utils/common')
-rw-r--r-- | ubifs-utils/common/crypto.c | 5 | ||||
-rw-r--r-- | ubifs-utils/common/defs.h | 21 | ||||
-rw-r--r-- | ubifs-utils/common/devtable.c | 59 | ||||
-rw-r--r-- | ubifs-utils/common/fscrypt.c | 25 | ||||
-rw-r--r-- | ubifs-utils/common/hashtable/hashtable.c | 6 | ||||
-rw-r--r-- | ubifs-utils/common/lpt.c | 7 | ||||
-rw-r--r-- | ubifs-utils/common/sign.c | 24 |
7 files changed, 62 insertions, 85 deletions
diff --git a/ubifs-utils/common/crypto.c b/ubifs-utils/common/crypto.c index 614a16d..2ecd8da 100644 --- a/ubifs-utils/common/crypto.c +++ b/ubifs-utils/common/crypto.c @@ -27,11 +27,6 @@ #include "defs.h" #include "ubifs.h" -/* common.h requires the PROGRAM_NAME macro */ -extern struct ubifs_info info_; -#define PROGRAM_NAME (info_.program_name) -#include "common.h" - static int do_hash(const EVP_MD *md, const unsigned char *in, size_t len, unsigned char *out) { unsigned int out_len; diff --git a/ubifs-utils/common/defs.h b/ubifs-utils/common/defs.h index 143f6c6..3dafc6d 100644 --- a/ubifs-utils/common/defs.h +++ b/ubifs-utils/common/defs.h @@ -12,6 +12,13 @@ #include <byteswap.h> #include <errno.h> +#include "ubifs.h" + +/* common.h requires the PROGRAM_NAME macro */ +extern struct ubifs_info info_; +#define PROGRAM_NAME (info_.program_name) +#include "common.h" + #define MKFS_PROGRAM_NAME "mkfs.ubifs" enum { MKFS_PROGRAM_TYPE = 0 }; @@ -19,21 +26,9 @@ enum { MKFS_PROGRAM_TYPE = 0 }; extern int debug_level; #define dbg_msg(lvl, fmt, ...) do {if (debug_level >= lvl) \ - printf("mkfs.ubifs: %s: " fmt "\n", __FUNCTION__, ##__VA_ARGS__); \ + printf("%s: %s: " fmt "\n", PROGRAM_NAME, __FUNCTION__, ##__VA_ARGS__); \ } while(0) -#define err_msg(fmt, ...) ({ \ - fprintf(stderr, "Error: " fmt "\n", ##__VA_ARGS__); \ - -1; \ -}) - -#define sys_err_msg(fmt, ...) ({ \ - int err_ = errno; \ - fprintf(stderr, "Error: " fmt "\n", ##__VA_ARGS__); \ - fprintf(stderr, " %s (error %d)\n", strerror(err_), err_); \ - -1; \ -}) - #define t16(x) ({ \ uint16_t __b = (x); \ (__LITTLE_ENDIAN==__BYTE_ORDER) ? __b : bswap_16(__b); \ diff --git a/ubifs-utils/common/devtable.c b/ubifs-utils/common/devtable.c index 2b9c6ef..3903264 100644 --- a/ubifs-utils/common/devtable.c +++ b/ubifs-utils/common/devtable.c @@ -52,6 +52,7 @@ #include <sys/sysmacros.h> #include "devtable.h" +#include "ubifs.h" #include "defs.h" #include "hashtable/hashtable.h" #include "hashtable/hashtable_itr.h" @@ -117,7 +118,7 @@ static int separate_last(const char *buf, int len, char **path, char **name) *path = malloc(path_len + 1); if (!*path) - return err_msg("cannot allocate %d bytes of memory", + return errmsg("cannot allocate %d bytes of memory", path_len + 1); memcpy(*path, buf, path_len); (*path)[path_len] = '\0'; @@ -125,7 +126,7 @@ static int separate_last(const char *buf, int len, char **path, char **name) *name = malloc(name_len + 1); if (!*name) { free(*path); - return err_msg("cannot allocate %d bytes of memory", + return errmsg("cannot allocate %d bytes of memory", name_len + 1); } memcpy(*name, n, name_len + 1); @@ -145,7 +146,7 @@ static int interpret_table_entry(const char *line) if (sscanf(line, "%1023s %c %o %u %u %u %u %u %u %u", buf, &type, &mode, &uid, &gid, &major, &minor, &start, &increment, &count) < 0) - return sys_err_msg("sscanf failed"); + return sys_errmsg("sscanf failed"); dbg_msg(3, "name %s, type %c, mode %o, uid %u, gid %u, major %u, " "minor %u, start %u, inc %u, cnt %u", @@ -154,20 +155,20 @@ static int interpret_table_entry(const char *line) len = strnlen(buf, 1024); if (len == 0) - return err_msg("empty path"); + return errmsg("empty path"); if (len == 1024) - return err_msg("too long path"); + return errmsg("too long path"); if (buf[0] != '/') - return err_msg("device table entries require absolute paths"); + return errmsg("device table entries require absolute paths"); if (strstr(buf, "//")) - return err_msg("'//' cannot be used in the path"); + return errmsg("'//' cannot be used in the path"); if (len > 1 && buf[len - 1] == '/') - return err_msg("do not put '/' at the end"); + return errmsg("do not put '/' at the end"); if (strstr(buf, "/./") || strstr(buf, "/../") || !strcmp(buf + len - 2, "/.") || !strcmp(buf + len - 3, "/..")) - return err_msg("'.' and '..' cannot be used in the path"); + return errmsg("'.' and '..' cannot be used in the path"); switch (type) { case 'd': @@ -188,10 +189,10 @@ static int interpret_table_entry(const char *line) case 'l': mode |= S_IFLNK; if ((mode & 0777) != 0777) - return err_msg("link permission must be 0777"); + return errmsg("link permission must be 0777"); break; default: - return err_msg("unsupported file type '%c'", type); + return errmsg("unsupported file type '%c'", type); } if (separate_last(buf, len, &path, &name)) @@ -206,13 +207,13 @@ static int interpret_table_entry(const char *line) dbg_msg(3, "inserting '%s' into path hash table", path); ph_elt = malloc(sizeof(struct path_htbl_element)); if (!ph_elt) { - err_msg("cannot allocate %zd bytes of memory", + errmsg("cannot allocate %zd bytes of memory", sizeof(struct path_htbl_element)); goto out_free; } if (!hashtable_insert(path_htbl, path, ph_elt)) { - err_msg("cannot insert into path hash table"); + errmsg("cannot insert into path hash table"); goto out_free; } @@ -221,13 +222,13 @@ static int interpret_table_entry(const char *line) ph_elt->name_htbl = create_hashtable(128, &r5_hash, &is_equivalent); if (!ph_elt->name_htbl) { - err_msg("cannot create name hash table"); + errmsg("cannot create name hash table"); goto out_free; } } if (increment != 0 && count == 0) { - err_msg("count cannot be zero if increment is non-zero"); + errmsg("count cannot be zero if increment is non-zero"); goto out_free; } @@ -241,7 +242,7 @@ static int interpret_table_entry(const char *line) /* This entry does not require any iterating */ nh_elt = malloc(sizeof(struct name_htbl_element)); if (!nh_elt) { - err_msg("cannot allocate %zd bytes of memory", + errmsg("cannot allocate %zd bytes of memory", sizeof(struct name_htbl_element)); goto out_free; } @@ -255,13 +256,13 @@ static int interpret_table_entry(const char *line) name, major(nh_elt->dev), minor(nh_elt->dev)); if (hashtable_search(ph_elt->name_htbl, name)) { - err_msg("'%s' is referred twice", buf); + errmsg("'%s' is referred twice", buf); goto out_free; } nh_elt->name = name; if (!hashtable_insert(ph_elt->name_htbl, name, nh_elt)) { - err_msg("cannot insert into name hash table"); + errmsg("cannot insert into name hash table"); goto out_free; } } else { @@ -271,7 +272,7 @@ static int interpret_table_entry(const char *line) for (i = start; i < num; i++) { nh_elt = malloc(sizeof(struct name_htbl_element)); if (!nh_elt) { - err_msg("cannot allocate %zd bytes of memory", + errmsg("cannot allocate %zd bytes of memory", sizeof(struct name_htbl_element)); goto out_free; } @@ -283,7 +284,7 @@ static int interpret_table_entry(const char *line) nm = malloc(len); if (!nm) { - err_msg("cannot allocate %d bytes of memory", len); + errmsg("cannot allocate %d bytes of memory", len); goto out_free; } @@ -294,13 +295,13 @@ static int interpret_table_entry(const char *line) nm, major(nh_elt->dev), minor(nh_elt->dev)); if (hashtable_search(ph_elt->name_htbl, nm)) { - err_msg("'%s' is referred twice", buf); + errmsg("'%s' is referred twice", buf); free (nm); goto out_free; } if (!hashtable_insert(ph_elt->name_htbl, nm, nh_elt)) { - err_msg("cannot insert into name hash table"); + errmsg("cannot insert into name hash table"); free (nm); goto out_free; } @@ -339,19 +340,19 @@ int parse_devtable(const char *tbl_file) path_htbl = create_hashtable(128, &r5_hash, &is_equivalent); if (!path_htbl) - return err_msg("cannot create path hash table"); + return errmsg("cannot create path hash table"); f = fopen(tbl_file, "r"); if (!f) - return sys_err_msg("cannot open '%s'", tbl_file); + return sys_errmsg("cannot open '%s'", tbl_file); if (fstat(fileno(f), &st) < 0) { - sys_err_msg("cannot stat '%s'", tbl_file); + sys_errmsg("cannot stat '%s'", tbl_file); goto out_close; } if (st.st_size < 10) { - sys_err_msg("'%s' is too short", tbl_file); + sys_errmsg("'%s' is too short", tbl_file); goto out_close; } @@ -376,7 +377,7 @@ int parse_devtable(const char *tbl_file) /* If this is not a comment line, try to interpret it */ if (len && *line != '#') { if (interpret_table_entry(line)) { - err_msg("cannot parse '%s'", line); + errmsg("cannot parse '%s'", line); goto out_close; } } @@ -448,13 +449,13 @@ int override_attributes(struct stat *st, struct path_htbl_element *ph_elt, if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode) || S_ISFIFO(st->st_mode)) - return err_msg("%s/%s both exists at UBIFS root at host, " + return errmsg("%s/%s both exists at UBIFS root at host, " "and is referred from the device table", strcmp(ph_elt->path, "/") ? ph_elt->path : "", nh_elt->name); if ((st->st_mode & S_IFMT) != (nh_elt->mode & S_IFMT)) - return err_msg("%s/%s is referred from the device table also exists in " + return errmsg("%s/%s is referred from the device table also exists in " "the UBIFS root directory at host, but the file type is " "different", strcmp(ph_elt->path, "/") ? ph_elt->path : "", nh_elt->name); diff --git a/ubifs-utils/common/fscrypt.c b/ubifs-utils/common/fscrypt.c index cc98963..895d5c7 100644 --- a/ubifs-utils/common/fscrypt.c +++ b/ubifs-utils/common/fscrypt.c @@ -24,11 +24,6 @@ #include "defs.h" #include "ubifs.h" -/* common.h requires the PROGRAM_NAME macro */ -extern struct ubifs_info info_; -#define PROGRAM_NAME (info_.program_name) -#include "common.h" - static __u8 fscrypt_masterkey[FS_MAX_KEY_SIZE]; static struct cipher *fscrypt_cipher; @@ -40,7 +35,7 @@ unsigned char *calc_fscrypt_subkey(struct fscrypt_context *fctx) ret = derive_key_aes(fctx->nonce, fscrypt_masterkey, fscrypt_cipher->key_length, new_key); if (ret < 0) { - err_msg("derive_key_aes failed: %i\n", ret); + errmsg("derive_key_aes failed: %i\n", ret); free(new_key); new_key = NULL; @@ -116,7 +111,7 @@ int encrypt_path(void **outbuf, void *data, unsigned int data_len, if (!crypt_key) { free(inbuf); free(*outbuf); - return err_msg("could not compute subkey"); + return errmsg("could not compute subkey"); } ret = fscrypt_cipher->encrypt_fname(inbuf, cryptlen, @@ -124,7 +119,7 @@ int encrypt_path(void **outbuf, void *data, unsigned int data_len, if (ret < 0) { free(inbuf); free(*outbuf); - return err_msg("could not encrypt filename"); + return errmsg("could not encrypt filename"); } free(crypt_key); @@ -149,7 +144,7 @@ int encrypt_data_node(struct fscrypt_context *fctx, unsigned int block_no, if (!crypt_key) { free(inbuf); free(outbuf); - return err_msg("could not compute subkey"); + return errmsg("could not compute subkey"); } ret = fscrypt_cipher->encrypt_block(inbuf, pad_len, @@ -159,7 +154,7 @@ int encrypt_data_node(struct fscrypt_context *fctx, unsigned int block_no, free(inbuf); free(outbuf); free(crypt_key); - return err_msg("encrypt_block returned %zi " + return errmsg("encrypt_block returned %zi " "instead of %zi", ret, pad_len); } @@ -189,11 +184,11 @@ static int parse_key_descriptor(const char *desc, __u8 *dst) for (i = 0; i < FS_KEY_DESCRIPTOR_SIZE; ++i) { if (!desc[i * 2] || !desc[i * 2 + 1]) { - err_msg("key descriptor '%s' is too short", desc); + errmsg("key descriptor '%s' is too short", desc); return -1; } if (!isxdigit(desc[i * 2]) || !isxdigit(desc[i * 2 + 1])) { - err_msg("invalid key descriptor '%s'", desc); + errmsg("invalid key descriptor '%s'", desc); return -1; } @@ -204,7 +199,7 @@ static int parse_key_descriptor(const char *desc, __u8 *dst) } if (desc[i * 2]) { - err_msg("key descriptor '%s' is too long", desc); + errmsg("key descriptor '%s' is too long", desc); return -1; } return 0; @@ -227,11 +222,11 @@ static int load_master_key(const char *key_file, struct cipher *fsc) goto fail; } if (keysize == 0) { - err_msg("loading key from '%s': file is empty", key_file); + errmsg("loading key from '%s': file is empty", key_file); goto fail; } if (keysize < fsc->key_length) { - err_msg("key '%s' is too short (at least %u bytes required)", + errmsg("key '%s' is too short (at least %u bytes required)", key_file, fsc->key_length); goto fail; } diff --git a/ubifs-utils/common/hashtable/hashtable.c b/ubifs-utils/common/hashtable/hashtable.c index 071afd2..af7fed9 100644 --- a/ubifs-utils/common/hashtable/hashtable.c +++ b/ubifs-utils/common/hashtable/hashtable.c @@ -6,14 +6,10 @@ #include <math.h> #include "ubifs.h" +#include "defs.h" #include "hashtable.h" #include "hashtable_private.h" -/* common.h requires the PROGRAM_NAME macro */ -extern struct ubifs_info info_; -#define PROGRAM_NAME (info_.program_name) -#include "common.h" - /* Credit for primes table: Aaron Krowne http://br.endernet.org/~akrowne/ diff --git a/ubifs-utils/common/lpt.c b/ubifs-utils/common/lpt.c index 746fc7d..9c1143f 100644 --- a/ubifs-utils/common/lpt.c +++ b/ubifs-utils/common/lpt.c @@ -30,11 +30,6 @@ #include "crc16.h" #include "sign.h" -/* common.h requires the PROGRAM_NAME macro */ -extern struct ubifs_info info_; -#define PROGRAM_NAME (info_.program_name) -#include "common.h" - /** * do_calc_lpt_geom - calculate sizes for the LPT area. * @c: the UBIFS file-system description object @@ -166,7 +161,7 @@ int calc_dflt_lpt_geom(struct ubifs_info *c, int *main_lebs, int *big_lpt) continue; } if (c->ltab_sz > c->leb_size) { - err_msg("LPT ltab too big"); + errmsg("LPT ltab too big"); return -EINVAL; } *main_lebs = c->main_lebs; diff --git a/ubifs-utils/common/sign.c b/ubifs-utils/common/sign.c index 93399ff..9c53e67 100644 --- a/ubifs-utils/common/sign.c +++ b/ubifs-utils/common/sign.c @@ -110,7 +110,7 @@ static void drain_openssl_errors(void) #define ssl_err_msg(fmt, ...) ({ \ display_openssl_errors(__LINE__); \ - err_msg(fmt, ## __VA_ARGS__); \ + errmsg(fmt, ## __VA_ARGS__); \ -1; \ }) @@ -215,9 +215,9 @@ static X509 *read_x509(const char *x509_name) n = BIO_read(b, buf, 2); if (n != 2) { if (BIO_should_retry(b)) - err_msg("%s: Read wanted retry", x509_name); + errmsg("%s: Read wanted retry", x509_name); if (n >= 0) - err_msg("%s: Short read", x509_name); + errmsg("%s: Short read", x509_name); goto out; } @@ -270,7 +270,7 @@ int sign_superblock_node(void *node) if (!cert) { if (!c->auth_cert_filename) - return err_msg("authentication certificate not provided (--auth-cert)"); + return errmsg("authentication certificate not provided (--auth-cert)"); cert = read_x509(c->auth_cert_filename); } @@ -284,23 +284,23 @@ int sign_superblock_node(void *node) CMS_NOCERTS | CMS_PARTIAL | CMS_BINARY | CMS_DETACHED | CMS_STREAM); if (!cms) - return err_msg("CMS_sign failed"); + return errmsg("CMS_sign failed"); pret = CMS_add1_signer(cms, cert, private_key, md, CMS_NOCERTS | CMS_BINARY | CMS_NOSMIMECAP | CMS_NOATTR); if (!pret) - return err_msg("CMS_add1_signer failed"); + return errmsg("CMS_add1_signer failed"); ret = CMS_final(cms, bm, NULL, CMS_NOCERTS | CMS_BINARY); if (!ret) - return err_msg("CMS_final failed"); + return errmsg("CMS_final failed"); bd = BIO_new(BIO_s_mem()); ret = i2d_CMS_bio_stream(bd, cms, NULL, 0); if (!ret) - return err_msg("i2d_CMS_bio_stream failed"); + return errmsg("i2d_CMS_bio_stream failed"); len = BIO_get_mem_data(bd, &obuf); @@ -386,10 +386,10 @@ int init_authentication(void) return 0; if (!c->auth_key_filename) - return err_msg("authentication key not given (--auth-key)"); + return errmsg("authentication key not given (--auth-key)"); if (!c->hash_algo_name) - return err_msg("Hash algorithm not given (--hash-algo)"); + return errmsg("Hash algorithm not given (--hash-algo)"); OPENSSL_config(NULL); @@ -398,14 +398,14 @@ int init_authentication(void) md = EVP_get_digestbyname(c->hash_algo_name); if (!md) - return err_msg("Unknown message digest %s", c->hash_algo_name); + return errmsg("Unknown message digest %s", c->hash_algo_name); hash_md = EVP_MD_CTX_create(); c->hash_len = EVP_MD_size(md); hash_algo = match_string(hash_algo_name, HASH_ALGO__LAST, c->hash_algo_name); if (hash_algo < 0) - return err_msg("Unsupported message digest %s", c->hash_algo_name); + return errmsg("Unsupported message digest %s", c->hash_algo_name); c->hash_algo = hash_algo; |