aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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,34 +1,35 @@
/* 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) {
@@ -166,26 +167,24 @@ smap_parseline(struct smap_option const *opt, const char *line, int flags,
}
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;
diff --git a/lib/sockmapstr.c b/lib/sockmapstr.c
index 1c0d749..7e188f2 100644
--- a/lib/sockmapstr.c
+++ b/lib/sockmapstr.c
@@ -218,25 +218,25 @@ read_payload_length(struct sockmap_input_stream *sp)
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;
}
diff --git a/lib/stream.c b/lib/stream.c
index d039c08..c217ca6 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -216,30 +216,30 @@ _stream_flush_buffer(struct _smap_stream *stream, int all)
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;
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
@@ -99,25 +99,25 @@ 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
@@ -191,25 +191,25 @@ parse_ldap_conf(const char *name, struct smap_option const *opt)
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);
@@ -245,32 +245,34 @@ parse_ldap_conf(const char *name, struct smap_option const *opt)
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) },
@@ -493,26 +495,24 @@ parse_ldap_uri(const char *uri)
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",
@@ -596,51 +596,49 @@ full_read(int fd, char *file, char *buf, size_t size)
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;
@@ -722,25 +720,24 @@ ldap_bind(LDAP *ld, struct ldap_conf *conf)
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;
@@ -871,25 +868,24 @@ getvar(const char *var, size_t len, void *data)
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("");
@@ -980,30 +976,27 @@ send_reply(smap_stream_t ostr, const char *template, char const **env,
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";
diff --git a/src/smapc.c b/src/smapc.c
index 88ddb0c..422afcd 100644
--- a/src/smapc.c
+++ b/src/smapc.c
@@ -641,25 +641,25 @@ read_eval_loop(FILE *fp, int interactive)
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;
}
diff --git a/src/userprivs.c b/src/userprivs.c
index 46e546f..eb424fe 100644
--- a/src/userprivs.c
+++ b/src/userprivs.c
@@ -61,25 +61,25 @@ 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)

Return to:

Send suggestions and report system problems to the System administrator.