-/* $OpenBSD: table_ldap.c,v 1.14 2015/10/06 14:02:25 stsp Exp $ */
+/* $OpenBSD: table_ldap.c,v 1.15 2015/10/11 12:50:00 sunil Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
static int
ldap_config(void)
{
- size_t flen;
+ size_t sz = 0;
+ ssize_t flen;
FILE *fp;
- char *key, *value, *buf, *lbuf;
+ char *key, *value, *buf = NULL;
fp = fopen(config, "r");
if (fp == NULL)
return (0);
- lbuf = NULL;
- while ((buf = fgetln(fp, &flen))) {
+ while ((flen = getline(&buf, &sz, fp)) != -1) {
if (buf[flen - 1] == '\n')
buf[flen - 1] = '\0';
- else {
- lbuf = malloc(flen + 1);
- if (lbuf == NULL) {
- log_warn("warn: table-ldap: malloc");
- return (0);
- }
- memcpy(lbuf, buf, flen);
- lbuf[flen] = '\0';
- buf = lbuf;
- }
key = buf;
while (isspace((unsigned char)*key))
log_warnx("warn: table-ldap: bogus entry \"%s\"", key);
}
- free(lbuf);
+ free(buf);
fclose(fp);
return (1);
}
-/* $OpenBSD: table_passwd.c,v 1.10 2015/01/20 17:37:54 deraadt Exp $ */
+/* $OpenBSD: table_passwd.c,v 1.11 2015/10/11 12:50:00 sunil Exp $ */
/*
* Copyright (c) 2013 Gilles Chehade <gilles@poolp.org>
table_passwd_update(void)
{
FILE *fp;
- char *buf, *lbuf = NULL;
+ char *buf = NULL, *p;
char tmp[LINE_MAX];
- size_t len;
+ size_t sz = 0;
+ ssize_t len;
char *line;
struct passwd pw;
struct dict *npasswd;
dict_init(npasswd);
- while ((buf = fgetln(fp, &len))) {
+ while ((len = getline(&buf, &sz, fp)) != -1) {
if (buf[len - 1] == '\n')
buf[len - 1] = '\0';
- else {
- /* EOF without EOL, copy and add the NUL */
- if ((lbuf = malloc(len + 1)) == NULL)
- err(1, NULL);
- memcpy(lbuf, buf, len);
- lbuf[len] = '\0';
- buf = lbuf;
- }
if (strlcpy(tmp, buf, sizeof tmp) >= sizeof tmp) {
log_warnx("warn: table-passwd: line too long");
err(1, NULL);
dict_set(npasswd, pw.pw_name, line);
}
- free(lbuf);
fclose(fp);
/* swap passwd table and release old one*/
if (passwd)
- while (dict_poproot(passwd, (void**)&buf))
- free(buf);
+ while (dict_poproot(passwd, (void**)&p))
+ free(p);
passwd = npasswd;
return (1);
err:
if (fp)
fclose(fp);
- free(lbuf);
+ free(buf);
/* release passwd table */
if (npasswd) {
- while (dict_poproot(npasswd, (void**)&buf))
- free(buf);
+ while (dict_poproot(npasswd, (void**)&p))
+ free(p);
free(npasswd);
}
return (0);
-/* $OpenBSD: table_sqlite.c,v 1.16 2015/01/20 17:37:54 deraadt Exp $ */
+/* $OpenBSD: table_sqlite.c,v 1.17 2015/10/11 12:50:00 sunil Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
sqlite3_stmt *_stmt_fetch_source;
char *_query_fetch_source;
char *queries[SQL_MAX];
- size_t flen;
- size_t _source_refresh;
+ ssize_t flen;
+ size_t sz = 0, _source_refresh;
int _source_expire;
FILE *fp;
- char *key, *value, *buf, *lbuf, *dbpath;
+ char *key, *value, *buf = NULL, *dbpath;
const char *e;
int i, ret;
long long ll;
if (fp == NULL)
return (0);
- lbuf = NULL;
- while ((buf = fgetln(fp, &flen))) {
+ while ((flen = getline(&buf, &sz, fp)) != -1) {
if (buf[flen - 1] == '\n')
buf[flen - 1] = '\0';
- else {
- lbuf = malloc(flen + 1);
- if (lbuf == NULL) {
- log_warn("warn: table-sqlite: malloc");
- return (0);
- }
- memcpy(lbuf, buf, flen);
- lbuf[flen] = '\0';
- buf = lbuf;
- }
key = buf;
while (isspace((unsigned char)*key))
free(dbpath);
free(_query_fetch_source);
- free(lbuf);
+ free(buf);
fclose(fp);
return (ret);
}
-/* $OpenBSD: table_static.c,v 1.10 2015/01/20 17:37:54 deraadt Exp $ */
+/* $OpenBSD: table_static.c,v 1.11 2015/10/11 12:50:00 sunil Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
table_static_parse(struct table *t, const char *config, enum table_type type)
{
FILE *fp;
- char *buf, *lbuf;
- size_t flen;
+ char *buf = NULL;
+ size_t sz = 0;
+ ssize_t flen;
char *keyp;
char *valp;
size_t ret = 0;
if (fp == NULL)
return 0;
- lbuf = NULL;
- while ((buf = fgetln(fp, &flen))) {
+ while ((flen = getline(&buf, &sz, fp)) != -1) {
if (buf[flen - 1] == '\n')
buf[flen - 1] = '\0';
- else {
- lbuf = xmalloc(flen + 1, "table_config_parse");
- memcpy(lbuf, buf, flen);
- lbuf[flen] = '\0';
- buf = lbuf;
- }
keyp = buf;
while (isspace((unsigned char)*keyp))
ret = 1;
end:
- free(lbuf);
+ free(buf);
fclose(fp);
return ret;
}