aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kelly <mike@pair.com>2011-12-20 10:27:53 -0500
committerMiklos Szeredi <mszeredi@suse.cz>2011-12-21 10:05:08 +0100
commite8e26c0bc10213ab99d437992e8037093d6b6c0f (patch)
tree7c9e30813a0209d0ad9ab7f65548be8adff5ead5
parentcfcae008e3370706c353146773d3b8dff04abe1c (diff)
downloadsshfs-e8e26c0bc10213ab99d437992e8037093d6b6c0f.tar
sshfs-e8e26c0bc10213ab99d437992e8037093d6b6c0f.tar.gz
sshfs-e8e26c0bc10213ab99d437992e8037093d6b6c0f.tar.bz2
sshfs-e8e26c0bc10213ab99d437992e8037093d6b6c0f.zip
increase portability
getline() isn't widely available yet, use fgets() instead
-rw-r--r--sshfs.c34
1 files changed, 15 insertions, 19 deletions
diff --git a/sshfs.c b/sshfs.c
index 8111f9c..2ba4659 100644
--- a/sshfs.c
+++ b/sshfs.c
@@ -37,6 +37,7 @@
#include <glib.h>
#include <pwd.h>
#include <grp.h>
+#include <limits.h>
#include "cache.h"
@@ -3483,23 +3484,23 @@ static int ssh_connect(void)
return 0;
}
-/* remove trailing '\n', like the perl func of the same name */
-static inline void chomp(char *line)
-{
- char *p = line;
- if ((p = strrchr(line, '\n')))
- *p = '\0';
-}
-
/* number of ':' separated fields in a passwd/group file that we care
* about */
#define IDMAP_FIELDS 3
/* given a line from a uidmap or gidmap, parse out the name and id */
static void parse_idmap_line(char *line, const char* filename,
- const unsigned int lineno, uint32_t *ret_id, char **ret_name)
+ const unsigned int lineno, uint32_t *ret_id, char **ret_name,
+ const int eof)
{
- chomp(line);
+ /* chomp off the trailing newline */
+ char *p = line;
+ if ((p = strrchr(line, '\n')))
+ *p = '\0';
+ else if (!eof) {
+ fprintf(stderr, "%s:%u: line too long\n", filename, lineno);
+ exit(1);
+ }
char *tokens[IDMAP_FIELDS];
char *tok;
int i;
@@ -3517,8 +3518,7 @@ static void parse_idmap_line(char *line, const char* filename,
name_tok = tokens[0];
id_tok = tokens[2];
} else {
- fprintf(stderr, "Unknown format at line %u of '%s'\n",
- lineno, filename);
+ fprintf(stderr, "%s:%u: unknown format\n", filename, lineno);
exit(1);
}
@@ -3541,8 +3541,7 @@ static void read_id_map(char *file, uint32_t *(*map_fn)(char *),
*idmap = g_hash_table_new(NULL, NULL);
*r_idmap = g_hash_table_new(NULL, NULL);
FILE *fp;
- char *line = NULL;
- size_t len = 0;
+ char line[LINE_MAX];
unsigned int lineno = 0;
fp = fopen(file, "r");
@@ -3552,12 +3551,12 @@ static void read_id_map(char *file, uint32_t *(*map_fn)(char *),
exit(1);
}
- while (getline(&line, &len, fp) != EOF) {
+ while (fgets(line, LINE_MAX, fp) != NULL) {
lineno++;
uint32_t remote_id;
char *name;
- parse_idmap_line(line, file, lineno, &remote_id, &name);
+ parse_idmap_line(line, file, lineno, &remote_id, &name, feof(fp));
uint32_t *local_id = map_fn(name);
if (local_id == NULL) {
@@ -3580,9 +3579,6 @@ static void read_id_map(char *file, uint32_t *(*map_fn)(char *),
file, strerror(errno));
exit(1);
}
-
- if (line)
- free(line);
}
/* given a username, return a pointer to its uid, or NULL if it doesn't