aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2017-11-10 11:08:35 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2017-11-10 11:08:35 +0200
commit2f1214a79a6befb629466c3e81a993123733a2fe (patch)
treeacf5e1cc9289cf4b655aa873d0b01642090b1391
parent3457c19206858d3e8155dcfc776df8818d05824b (diff)
downloadsmap-2f1214a79a6befb629466c3e81a993123733a2fe.tar.gz
smap-2f1214a79a6befb629466c3e81a993123733a2fe.tar.bz2
Placate cc warnings
-rw-r--r--lib/parseopt.c5
-rw-r--r--lib/sockmapstr.c2
-rw-r--r--lib/stream.c4
-rw-r--r--modules/ldap/ldap.c23
-rw-r--r--src/smapc.c2
-rw-r--r--src/userprivs.c2
6 files changed, 15 insertions, 23 deletions
diff --git a/lib/parseopt.c b/lib/parseopt.c
index cc0c9a6..cf5319d 100644
--- a/lib/parseopt.c
+++ b/lib/parseopt.c
@@ -1,46 +1,47 @@
/* This file is part of Smap.
- Copyright (C) 2008, 2010, 2014 Sergey Poznyakoff
+ Copyright (C) 2008, 2010, 2014, 2017 Sergey Poznyakoff
Smap is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
Smap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Smap. If not, see <http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <smap/parseopt.h>
#include <smap/diag.h>
#include <string.h>
+#include <ctype.h>
static struct smap_option const *
find_opt(struct smap_option const *opt, const char *str, const char **value,
int flags)
{
size_t len = strlen(str);
int isbool;
int delim = flags & SMAP_DELIM_MASK;
if (len > 2 && (flags & SMAP_IGNORECASE
? strncasecmp
: strncmp)(str, "no", 2) == 0) {
*value = NULL;
str += 2;
isbool = 1;
} else {
isbool = 0;
*value = str;
}
for (; opt->name; opt++) {
if (len >= opt->len
&& (flags & SMAP_IGNORECASE
? strncasecmp
@@ -154,50 +155,48 @@ smap_parseline(struct smap_option const *opt, const char *line, int flags,
case smap_opt_enum:
n = find_value(p->v.enumstr, value);
if (n == -1) {
*errmsg = "invalid value";
rc = SMAP_PARSE_INVAL;
break;
}
*(int*)p->data = n;
break;
case smap_opt_null:
break;
}
if (p->func && p->func(p, value, errmsg))
rc = SMAP_PARSE_INVAL;
return rc;
}
int
smap_parseopt(struct smap_option const *opt, int argc, char **argv, int flags,
int *pindex)
{
int i;
- long n;
- char *s;
int rc = 0;
const char *modname = argv[0];
for (i = (flags & SMAP_PARSEOPT_PARSE_ARGV0) ? 0 : 1;
i < argc; i++) {
char *errmsg;
int res;
res = smap_parseline(opt, argv[i], SMAP_DELIM_EQ, &errmsg);
if (res == SMAP_PARSE_SUCCESS)
continue;
else if (res == SMAP_PARSE_NOENT) {
if (pindex) {
if (flags & SMAP_PARSEOPT_PERMUTE) {
int j;
struct smap_option const *p = NULL;
const char *value;
for (j = i + 1; j < argc; j++)
if ((p = find_opt(opt,
argv[j],
&value,
SMAP_DELIM_EQ)))
diff --git a/lib/sockmapstr.c b/lib/sockmapstr.c
index 1c0d749..7e188f2 100644
--- a/lib/sockmapstr.c
+++ b/lib/sockmapstr.c
@@ -206,49 +206,49 @@ report_invalid_prefix(struct sockmap_input_stream *sp, const char *diag)
smap_stream_write(smap_debug_str, buf, n, NULL);
smap_stream_write(smap_debug_str, "\n", 1, NULL);
}
int
read_payload_length(struct sockmap_input_stream *sp)
{
int len = 0;
sp->cp = 0;
while (len < SIZE_T_STRLEN_BOUND) {
ssize_t n;
char *p;
n = recv(sp->fd, sp->nbuf + len, SIZE_T_STRLEN_BOUND - len, 0);
if (n < 0) {
smap_debug(sp->debug_idx, 1,
("error reading from fd #%d: %s", sp->fd,
strerror(errno)));
return errno;
}
if (n == 0)
return EOF;
len += n;
- if (p = memchr(sp->nbuf, ':', len)) {
+ if ((p = memchr(sp->nbuf, ':', len))) {
sp->cp = p - sp->nbuf;
sp->nbuf[len] = 0;
sp->nlen = len;
return 0;
}
}
sp->nbuf[len] = 0;
sp->nlen = len;
if (smap_debug_np(sp->debug_idx, 1))
report_invalid_prefix(sp, "prefix too long");
return EPROTO;
}
#define ISDIGIT(c) ('0' <= (c) && (c) <= '9')
static int
_sockmap_input_stream_read(struct _smap_stream *stream, char *buf,
size_t size, size_t *pret)
{
struct sockmap_input_stream *sp =
(struct sockmap_input_stream *)stream;
int rc;
size_t reqsz;
char *pb = buf;
diff --git a/lib/stream.c b/lib/stream.c
index d039c08..c217ca6 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -204,54 +204,54 @@ _stream_flush_buffer(struct _smap_stream *stream, int all)
stream->level,
1, NULL)))
return rc;
if (all)
_stream_advance_buffer(stream, stream->level);
break;
case smap_buffer_line:
if (stream->level == 0)
break;
for (end = memchr(stream->cur, '\n', stream->level);
end;
end = memchr(stream->cur, '\n', stream->level)) {
size_t size = end - stream->cur + 1;
rc = smap_stream_write_unbuffered(stream,
stream->cur,
size, 1,
NULL);
if (rc)
return rc;
_stream_advance_buffer(stream, size);
}
if (stream->level) {
if (all) {
- if (rc = _force_flush_buffer(stream))
+ if ((rc = _force_flush_buffer(stream)))
return rc;
} else if (BUFFER_FULL_P(stream)) {
if (stream->flags & SMAP_STREAM_EXPBUF)
return _stream_realloc_buffer(stream, 0);
- if (rc = _force_flush_buffer(stream))
+ if ((rc = _force_flush_buffer(stream)))
return rc;
}
}
}
} else if (all)
_stream_advance_buffer(stream, stream->level);
if (stream->level) {
if (stream->cur > stream->buffer)
memmove(stream->buffer, stream->cur, stream->level);
} else {
stream->flags &= ~_SMAP_STR_DIRTY;
stream->level = 0;
}
stream->cur = stream->buffer;
return 0;
}
smap_stream_t
_smap_stream_create(size_t size, int flags)
{
struct _smap_stream *str;
if (size < sizeof(str))
diff --git a/modules/ldap/ldap.c b/modules/ldap/ldap.c
index d686f6b..b34c560 100644
--- a/modules/ldap/ldap.c
+++ b/modules/ldap/ldap.c
@@ -87,49 +87,49 @@ argz_free(char **a)
{
int i;
if (!a)
return;
for (i = 0; a[i]; i++)
free(a[i]);
free(a);
}
static int
argz_copy(char ***dst, char **a)
{
int i, n;
char **b;
if (!a) {
*dst = NULL;
return 0;
}
for (n = 0; a[n]; n++)
;
- b = calloc(i + 1, sizeof(b[0]));
+ b = calloc(n + 1, sizeof(b[0]));
if (!b)
return -1;
for (i = 0; i < n; i++) {
b[i] = strdup(a[i]);
if (!b[i])
return -1;
}
b[i] = NULL;
return 0;
}
static void
ldap_conf_free(struct ldap_conf *cp)
{
free(cp->config_file);
free(cp->uri);
free(cp->base);
free(cp->cacert);
free(cp->filter);
argz_free(cp->attrs);
free(cp->binddn);
free(cp->bindpw);
free(cp->bindpwfile);
@@ -179,49 +179,49 @@ ldap_conf_cpy(struct ldap_conf *dst, struct ldap_conf *src)
STRCPY(joinstr);
return dst;
}
static int
parse_ldap_conf(const char *name, struct smap_option const *opt)
{
int rc = 0;
FILE *fp;
char buf[1024];
unsigned line;
char *p;
fp = fopen(name, "r");
if (!fp) {
smap_error("can't open LDAP config file %s: %s",
name, strerror(errno));
return -1;
}
line = 0;
- while (p = fgets(buf, sizeof(buf), fp)) {
+ while ((p = fgets(buf, sizeof(buf), fp))) {
size_t len;
char *errmsg;
++line;
while (*p && isspace(*p))
++p;
if (*p == '#')
continue;
len = strlen(p);
if (len) {
if (p[len-1] == '\n')
p[--len] = 0;
else if (!feof(fp)) {
smap_error("%s:%u: line too long, skipping", name, line);
while (!feof(fp) && fgetc(fp) != '\n')
;
++line;
continue;
}
while (len > 0 && isspace(p[len-1]))
@@ -233,56 +233,58 @@ parse_ldap_conf(const char *name, struct smap_option const *opt)
p[len] = 0;
switch (smap_parseline(opt, p, SMAP_IGNORECASE|SMAP_DELIM_WS,
&errmsg)) {
case SMAP_PARSE_SUCCESS:
smap_debug(dbgid, 2, ("%s:%u: accepted line %s",
name, line, p));
break;
case SMAP_PARSE_INVAL:
smap_error("%s:%u: %s", name, line, errmsg);
rc = 1;
break;
case SMAP_PARSE_NOENT:
smap_debug(dbgid, 2, ("%s:%u: unrecognized line %s",
name, line, p));
}
}
fclose(fp);
return rc;
}
+#if 0
static int
readconf(struct smap_option const *opt, const char *val, char **errmsg)
{
int rc = parse_ldap_conf(val, opt);
if (rc)
*errmsg = "parse error";
return rc;
}
+#endif
#define MKOPT_DEFAULT 0
#define MKOPT_REUSE 0x01
#define MKOPT_RESET 0x02
static int
make_options(struct ldap_conf *conf, int flags,
struct smap_option **ret_options)
{
static struct smap_option init_option[] = {
{ SMAP_OPTSTR(config-file), smap_opt_null,
(void*)offsetof(struct ldap_conf, config_file) },
{ SMAP_OPTSTR(tls_cacert), smap_opt_string,
(void*)offsetof(struct ldap_conf, cacert) },
{ SMAP_OPTSTR(tls-cacert), smap_opt_string,
(void*)offsetof(struct ldap_conf, cacert) },
{ SMAP_OPTSTR(uri), smap_opt_string,
(void*)offsetof(struct ldap_conf, uri) },
{ SMAP_OPTSTR(base), smap_opt_string,
(void*)offsetof(struct ldap_conf, base) },
{ SMAP_OPTSTR(filter), smap_opt_string,
(void*)offsetof(struct ldap_conf, filter) },
@@ -481,50 +483,48 @@ parse_ldap_uri(const char *uri)
*ludp = lud->lud_next;
lud->lud_next = NULL;
ldap_free_urldesc(lud);
}
if (ludlist) {
ldap_free_urldesc(ludlist);
return NULL;
} else if (!urls)
return NULL;
ldapuri = argcv_concat(nurls, urls);
if (!ldapuri)
smap_error("%s", strerror(errno));
ber_memvfree((void **)urls);
return ldapuri;
}
static LDAP *
ldap_connect(struct ldap_conf *conf)
{
int rc;
char *ldapuri = NULL;
LDAP *ld = NULL;
- char *val;
- unsigned long lval;
if (ldap_debug_level) {
if (ber_set_option(NULL, LBER_OPT_DEBUG_LEVEL,
&ldap_debug_level)
!= LBER_OPT_SUCCESS )
smap_error("cannot set LBER_OPT_DEBUG_LEVEL %d",
ldap_debug_level);
if (ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL,
&ldap_debug_level)
!= LDAP_OPT_SUCCESS )
smap_error("could not set LDAP_OPT_DEBUG_LEVEL %d",
ldap_debug_level);
}
if (conf->uri) {
ldapuri = parse_ldap_uri(conf->uri);
if (!ldapuri)
return NULL;
}
smap_debug(dbgid, 1, ("constructed LDAP URI: %s",
ldapuri ? ldapuri : "<DEFAULT>"));
@@ -584,75 +584,73 @@ full_read(int fd, char *file, char *buf, size_t size)
while (size) {
ssize_t n;
n = read(fd, buf, size);
if (n == -1) {
if (errno == EAGAIN || errno == EINTR)
continue;
smap_error("error reading from %s: %s",
file, strerror(errno));
return -1;
} else if (n == 0) {
smap_error("short read from %s", file);
return -1;
}
buf += n;
size -= n;
}
return 0;
}
static int
get_passwd(struct ldap_conf *conf, struct berval *pwd, char **palloc)
{
- char *file;
-
if (conf->bindpwfile) {
struct stat st;
int fd, rc;
char *mem, *p;
- fd = open(file, O_RDONLY);
+ fd = open(conf->bindpwfile, O_RDONLY);
if (fd == -1) {
smap_error("can't open password file %s: %s",
- file, strerror(errno));
+ conf->bindpwfile, strerror(errno));
return -1;
}
if (fstat(fd, &st)) {
smap_error("can't stat password file %s: %s",
- file, strerror(errno));
+ conf->bindpwfile, strerror(errno));
close(fd);
return -1;
}
mem = malloc(st.st_size + 1);
if (!mem) {
smap_error("can't allocate memory (%lu bytes)",
(unsigned long) st.st_size+1);
close(fd);
return -1;
}
- rc = full_read(fd, file, mem, st.st_size);
+ rc = full_read(fd, conf->bindpwfile, mem, st.st_size);
close(fd);
if (rc)
return rc;
mem[st.st_size] = 0;
p = strchr(mem, '\n');
if (p)
*p = 0;
*palloc = mem;
pwd->bv_val = mem;
} else
pwd->bv_val = conf->bindpw;
pwd->bv_len = pwd->bv_val ? strlen(pwd->bv_val) : 0;
return 0;
}
static int
ldap_bind(LDAP *ld, struct ldap_conf *conf)
{
int msgid, err, rc;
LDAPMessage *result;
LDAPControl **ctrls;
char msgbuf[256];
char *matched = NULL;
char *info = NULL;
@@ -710,49 +708,48 @@ ldap_bind(LDAP *ld, struct ldap_conf *conf)
if (refs && *refs) {
int i;
smap_debug(dbgid, 3, ("referrals:"));
for (i = 0; refs[i]; i++)
smap_debug(dbgid, 3, ("%s", refs[i]));
}
}
if (matched)
ber_memfree(matched);
if (info)
ber_memfree(info);
if (refs)
ber_memvfree((void **)refs);
free(alloc_ptr);
return !(err == LDAP_SUCCESS);
}
static smap_database_t
mod_ldap_init_db(const char *dbid, int argc, char **argv)
{
- LDAP *ldap;
struct ldap_db *db;
struct ldap_conf conf;
size_t i, j;
struct smap_option *opt;
if (!ldap_conf_cpy(&conf, &dfl_conf))
return NULL;
if (make_options(&conf, MKOPT_RESET, &opt)) {
smap_error("not enough memory");
ldap_conf_free(&conf);
return NULL;
}
if (smap_parseopt(opt, argc, argv, 0, NULL)) {
ldap_conf_free(&conf);
return NULL;
}
make_options(&conf, MKOPT_REUSE, &opt);
if (!conf.config_file && access(dfl_config_file, R_OK) == 0)
conf.config_file = strdup(dfl_config_file);
@@ -859,49 +856,48 @@ struct getvar_data {
LDAP *ld;
char const **env;
LDAPMessage *msg;
char *joinstr;
};
static char *
getvar(const char *var, size_t len, void *data)
{
struct getvar_data *gd = data;
if (len == 2 && memcmp(var, "dn", len) == 0)
return ldap_get_dn(gd->ld, gd->msg);
if (gd->env) {
int i;
for (i = 0; gd->env[i]; i += 2)
if (strlen(gd->env[i]) == len
&& memcmp(var, gd->env[i], len) == 0)
return strdup(gd->env[i+1]);
}
if (gd->ld) {
- struct berval bv;
char *p;
struct berval **values;
char *attr = malloc(len+1);
if (!attr)
return NULL;
memcpy(attr, var, len);
attr[len] = 0;
values = ldap_get_values_len(gd->ld, gd->msg, attr);
free(attr);
if (!values)
return strdup("");
if (!gd->joinstr) {
p = malloc(values[0]->bv_len + 1);
if (!p)
return NULL;
memcpy(p, values[0]->bv_val, values[0]->bv_len);
p[values[0]->bv_len] = 0;
} else {
size_t i, len, dlen = strlen(gd->joinstr);
char *q;
len = values[0]->bv_len;
@@ -968,54 +964,51 @@ send_reply(smap_stream_t ostr, const char *template, char const **env,
WRDSF_GETVAR |
WRDSF_CLOSURE |
WRDSF_ERROR |
WRDSF_SHOWERR);
if (rc) {
smap_error("cannot format reply");
wordsplit_free(&ws);
return 1;
}
smap_debug(dbgid, 1, ("reply: %s", ws.ws_wordv[0]));
smap_stream_printf(ostr, "%s\n", ws.ws_wordv[0]);
wordsplit_free(&ws);
return 0;
}
static int
mod_ldap_query(smap_database_t dbp,
smap_stream_t ostr,
const char *map, const char *key,
struct smap_conninfo const *conninfo)
{
struct ldap_db *db = (struct ldap_db *) dbp;
char const *inenv[5];
- char **env;
- char **attrs;
struct wordsplit ws;
ber_int_t msgid;
int rc;
- char *reply = NULL;
LDAPMessage *res, *msg;
# define __smap_s_cat2__(a,b) a ## b
# define REPLY(d,s) \
((d)->conf.__smap_s_cat2__(s,_reply) \
? (d)->conf.__smap_s_cat2__(s,_reply) \
: __smap_s_cat3__(dfl_,s,_reply))
inenv[0] = "map";
inenv[1] = map;
inenv[2] = "key";
inenv[3] = key;
inenv[4] = NULL;
ws.ws_env = (const char **) inenv;
ws.ws_error = smap_error;
rc = wordsplit(db->conf.filter, &ws,
WRDSF_NOSPLIT |
WRDSF_NOCMD |
WRDSF_ENV |
WRDSF_ENV_KV |
WRDSF_ERROR |
WRDSF_SHOWERR);
diff --git a/src/smapc.c b/src/smapc.c
index 88ddb0c..422afcd 100644
--- a/src/smapc.c
+++ b/src/smapc.c
@@ -629,49 +629,49 @@ shell_banner()
}
static void
read_eval_loop(FILE *fp, int interactive)
{
char *p;
char *map;
int flags = WRDSF_DEFFLAGS |
WRDSF_COMMENT |
WRDSF_ENOMEMABRT |
WRDSF_SHOWERR;
struct wordsplit ws;
ws.ws_comment = "#";
#ifdef WITH_READLINE
if (interactive) {
rl_readline_name = smap_progname;
rl_attempted_completion_function = _command_completion;
read_history(get_history_file_name());
}
#endif
if (interactive && !quiet_startup)
shell_banner();
- while (p = get_input_line(fp, interactive)) {
+ while ((p = get_input_line(fp, interactive))) {
#ifdef WITH_READLINE
if (interactive) {
if (retrieve_history(p))
continue;
add_history(p);
}
#endif
if (p[0] == '?') {
cmd_help(0, NULL);
continue;
}
if (cmdprefix == 0 || p[0] == cmdprefix) {
if (wordsplit(p + !!cmdprefix, &ws, flags)) {
wordsplit_perror(&ws);
break;
}
flags |= WRDSF_REUSE;
if (ws.ws_wordc && handle_command(&ws))
break;
continue;
}
while (*p && isspace(*p))
diff --git a/src/userprivs.c b/src/userprivs.c
index 46e546f..eb424fe 100644
--- a/src/userprivs.c
+++ b/src/userprivs.c
@@ -49,49 +49,49 @@ privinfo_add_grpgid(struct privinfo *pi, gid_t gid)
void
privinfo_add_grpnam(struct privinfo *pi, const char *name)
{
struct group *gr = getgrnam(name);
if (!gr) {
smap_error("%s: no such group", name);
return;
}
privinfo_add_grpgid(pi, gr->gr_gid);
}
void
get_user_groups(struct privinfo *pi)
{
struct group *gr;
struct passwd *pw;
const char *user;
pw = getpwuid(pi->uid);
if (!pw)
return;
user = pw->pw_name;
setgrent();
- while (gr = getgrent()) {
+ while ((gr = getgrent())) {
char **p;
for (p = gr->gr_mem; *p; p++)
if (strcmp(*p, user) == 0) {
privinfo_add_grpgid(pi, gr->gr_gid);
break;
}
}
endgrent();
}
void
privinfo_expand_user_groups(struct privinfo *pi)
{
if (pi->allgroups) {
get_user_groups(pi);
pi->allgroups = 0;
}
}
/* Switch to the given UID/GID */
int
switch_to_privs(struct privinfo *pi)
{
int rc = 0;

Return to:

Send suggestions and report system problems to the System administrator.