Check return value of malloc (or use xmalloc to malloc-or-die).
Prevent a handful of buffer overruns
SRVOBJ=mr_main.o mr_sauth.o mr_scall.o mr_shutdown.o \
mr_util.o qrtn.o queries2.o qsupport.o qsubs.o \
increment.o cache.o qvalidate.o \
- qaccess.o qsetup.o qfollow.o
+ qaccess.o qsetup.o qfollow.o ../db/moira_schema.o
GLUOBJS=mr_glue.o qrtn.o queries2.o qsupport.o qsubs.o \
../lib/mr_et.o mr_sauth.o \
../lib/krb_et.o mr_util.o increment.o cache.o \
/* Cache parameters: */
#define CACHESIZE 101 /* number of cache slots */
-#define NAMESZ 257 /* max size of a name */
struct item {
- char name[NAMESZ];
+ char name[MAX_FIELD_WIDTH];
enum tables type;
int nhash;
int id;
case SUBNET_TABLE:
EXEC SQL SELECT snet_id INTO :j FROM subnet WHERE name = UPPER(:iname);
break;
- case CLUSTER_TABLE:
+ case CLUSTERS_TABLE:
EXEC SQL SELECT clu_id INTO :j FROM clusters WHERE name = :iname;
break;
case FILESYS_TABLE:
if (cachesize < CACHESIZE)
{
i = malloc(sizeof(struct item));
+ if (!i)
+ return MR_SUCCESS;
cachesize++;
}
else
{
struct item *i, *t;
EXEC SQL BEGIN DECLARE SECTION;
- char iname[NAMESZ];
+ char iname[MAX_FIELD_WIDTH];
int j;
EXEC SQL END DECLARE SECTION;
if (i->id != id || type != i->type)
continue;
free(*name);
- *name = strdup(i->name);
+ *name = xstrdup(i->name);
cachehits++;
i->next->prev = i->prev;
i->prev->next = i->next;
case SUBNET_TABLE:
EXEC SQL SELECT name INTO :iname FROM subnet WHERE snet_id = :j;
break;
- case CLUSTER_TABLE:
+ case CLUSTERS_TABLE:
EXEC SQL SELECT name INTO :iname FROM clusters WHERE clu_id = :j;
break;
case FILESYS_TABLE:
{
free(*name);
sprintf(iname, "#%d", j);
- *name = strdup(iname);
+ *name = xstrdup(iname);
return MR_NO_MATCH;
}
if (sqlca.sqlerrd[2] > 1)
if (sqlca.sqlcode)
return MR_DBMS_ERR;
free(*name);
- *name = strdup(strtrim(iname));
+ *name = xstrdup(strtrim(iname));
if (**name == '#' && type != USERS_TABLE)
return MR_SUCCESS;
if (cachesize < CACHESIZE)
{
i = malloc(sizeof(struct item));
+ if (!i)
+ return MR_SUCCESS;
cachesize++;
}
else
if (cachesize < CACHESIZE)
{
i = malloc(sizeof(struct item));
+ if (!i)
+ return MR_SUCCESS;
cachesize++;
}
else
};
void next_incremental(void);
-char **copy_argv(char **argv, int argc);
void free_argv(char **argv, int argc);
int table_num(char *table);
for (i = 0; i < MAXARGC; i++)
{
- before[i] = malloc(ARGLEN);
- after[i] = malloc(ARGLEN);
+ before[i] = xmalloc(MAX_FIELD_WIDTH);
+ after[i] = xmalloc(MAX_FIELD_WIDTH);
}
}
dosql(before);
beforec = 2;
break;
- case CLUSTER_TABLE:
+ case CLUSTERS_TABLE:
sprintf(stmt_buf, "SELECT c.name, c.description, c.location "
"FROM clusters c WHERE %s", qual);
dosql(before);
dosql(after);
afterc = 2;
break;
- case CLUSTER_TABLE:
+ case CLUSTERS_TABLE:
sprintf(stmt_buf, "SELECT c.name, c.description, c.location "
"FROM clusters c WHERE %s", qual);
dosql(after);
break;
}
- iu = malloc(sizeof(struct iupdate));
+ iu = xmalloc(sizeof(struct iupdate));
iu->table = table_name[table];
iu->beforec = beforec;
- iu->before = copy_argv(before, beforec);
+ iu->before = mr_copy_args(before, beforec);
iu->afterc = afterc;
- iu->after = copy_argv(after, afterc);
+ iu->after = mr_copy_args(after, afterc);
sq_save_data(incremental_sq, iu);
}
static struct inc_cache *cache;
struct inc_cache *c;
EXEC SQL BEGIN DECLARE SECTION;
- char tab[17], serv[17];
+ char tab[INCREMENTAL_TABLE_NAME_SIZE], serv[INCREMENTAL_SERVICE_SIZE];
EXEC SQL END DECLARE SECTION;
struct iupdate *iu;
EXEC SQL FETCH inc INTO :tab, :serv;
if (sqlca.sqlcode)
break;
- c = malloc(sizeof(struct inc_cache));
+ c = xmalloc(sizeof(struct inc_cache));
c->next = cache;
- c->table = strdup(strtrim(tab));
- c->service = strdup(strtrim(serv));
+ c->table = xstrdup(strtrim(tab));
+ c->service = xstrdup(strtrim(serv));
cache = c;
}
EXEC SQL CLOSE inc;
{
iu->service = c->service;
sq_save_data(incremental_exec, iu);
+ break;
}
}
+ if (!c)
+ {
+ free_argv(iu->before, iu->beforec);
+ free_argv(iu->after, iu->afterc);
+ free(iu);
+ }
}
if (inc_running == 0)
next_incremental();
void next_incremental(void)
{
struct iupdate *iu;
- char *argv[MAXARGC * 2 + 4], cafter[3], cbefore[3], prog[BUFSIZ];
+ char *argv[MAXARGC * 2 + 4], cafter[3], cbefore[3], prog[MAXPATHLEN];
int i;
sigset_t sigs;
}
-char **copy_argv(char **argv, int argc)
-{
- char **ret = malloc(sizeof(char *) * argc);
- while (--argc >= 0)
- ret[argc] = strdup(strtrim(argv[argc]));
- return ret;
-}
-
void free_argv(char **argv, int argc)
{
while (--argc >= 0)
int mr_auth(char *prog)
{
struct passwd *pw;
- char buf[1024];
+ char buf[MAX_K_NAME_SZ];
CHECK_CONNECTED;
pw = getpwuid(getuid());
int trigger_dcm(struct query *q, char *argv[], client *cl)
{
int pid, status;
- char prog[128];
+ char prog[MAXPATHLEN];
if ((status = check_query_access(&pseudo_query, 0, cl)))
return status;
com_err(whoami, errno, "Unable to get local hostname");
exit(1);
}
- host = canonicalize_hostname(strdup(uts.nodename));
+ host = canonicalize_hostname(xstrdup(uts.nodename));
for (p = host; *p && *p != '.'; p++)
{
if (isupper(*p))
*/
nclients = 0;
clientssize = 10;
- clients = malloc(clientssize * sizeof(client *));
+ clients = xmalloc(clientssize * sizeof(client *));
mr_setup_signals();
if (!rcache)
{
- rcache = malloc(sizeof(replay_cache));
+ rcache = xmalloc(sizeof(replay_cache));
memset(rcache, 0, sizeof(replay_cache));
}
/* add new entry */
time(&now);
- rcnew = malloc(sizeof(replay_cache));
+ rcnew = xmalloc(sizeof(replay_cache));
memcpy(&(rcnew->auth), &auth, sizeof(KTEXT_ST));
rcnew->expires = now + 2 * CLOCK_SKEW;
rcnew->next = rcache->next;
memcpy(cl->kname.name, ad.pname, ANAME_SZ);
memcpy(cl->kname.inst, ad.pinst, INST_SZ);
memcpy(cl->kname.realm, ad.prealm, REALM_SZ);
- strcpy(cl->clname, kname_unparse(ad.pname, ad.pinst, ad.prealm));
+ strncpy(cl->clname, kname_unparse(ad.pname, ad.pinst, ad.prealm),
+ sizeof(cl->clname));
+ cl->clname[sizeof(cl->clname) - 1] = '\0';
if (ad.pinst[0] == 0 && !strcmp(ad.prealm, krb_realm))
ok = 1;
{
com_err(whoami, 0, "procno out of range");
client_reply(cl, MR_UNKNOWN_PROC);
+ mr_destroy_reply(req);
return;
}
log_args(procnames[pn], 2, req.mr_argc, req.mr_argv);
{
client_reply(cl, MR_DOWN);
com_err(whoami, MR_DOWN, "(query refused)");
+ mr_destroy_reply(req);
return;
}
{
case MR_NOOP:
client_reply(cl, MR_SUCCESS);
- return;
+ break;
case MR_AUTH:
do_auth(cl, req);
- return;
+ break;
case MR_QUERY:
do_retr(cl, req);
- return;
+ break;
case MR_ACCESS:
do_access(cl, req);
- return;
+ break;
case MR_SHUTDOWN:
do_shutdown(cl);
- return;
+ break;
case MR_DO_UPDATE:
client_reply(cl, MR_PERM);
- return;
+ break;
case MR_MOTD:
get_motd(cl);
- return;
+ break;
}
+ mr_destroy_reply(req);
}
/* Set the final return status for a query. We always keep one more
#include <moira.h>
#include <mr_private.h>
#include <moira_site.h>
+#include <moira_schema.h>
#include <netinet/in.h>
void do_shutdown(client *cl);
/* prototypes from mr_util.c */
-char *requote(char *buf, char *cp, int len);
+char *requote(char *buf);
void log_args(char *tag, int version, int argc, char **argv);
void mr_com_err(const char *whoami, long code, const char *fmt, va_list pvar);
int mr_trim_args(int argc, char **argv);
char **mr_copy_args(char **argv, int argc);
void *xmalloc(size_t);
void *xrealloc(void *, size_t);
+char *xstrdup(char *);
/* prototypes from qaccess.pc */
int access_user(struct query *q, char *argv[], client *cl);
extern char *whoami;
-char *requote(char *buf, char *cp, int len)
+char *requote(char *cp)
{
- int count = 0;
- unsigned char c;
- if (len <= 2)
- return buf;
- *buf++ = '"';
- count++;
- len--;
- for (; (count < 258) && (len > 1) && (c = *cp); cp++, --len, ++count)
+ int len = 0;
+ char *out = xmalloc(4 * strlen(cp) + 3), *op = out;
+
+ *op++ = '"';
+ len++;
+ while (*cp)
{
- if (c == '\\' || c == '"')
- *buf++ = '\\';
- if (isprint(c))
- *buf++ = c;
+ if (*cp == '\\' || *cp == '"')
+ {
+ *op++ = '\\';
+ len++;
+ }
+ if (isprint(*cp))
+ {
+ *op++ = *cp++;
+ len++;
+ }
else
{
- sprintf(buf, "\\%03o", c);
- buf = strchr(buf, '\0');
+ sprintf(op, "\\%03o", *cp++);
+ op += 4;
+ len += 4;
}
}
- if (len > 1)
- {
- *buf++ = '"';
- count++;
- len--;
- }
- if (len > 1)
- *buf = '\0';
- return buf;
+
+ strcpy(op, "\"");
+ len += 2;
+
+ out = realloc(out, len); /* shrinking, so can't fail */
+ return out;
}
void log_args(char *tag, int version, int argc, char **argv)
{
- char buf[BUFSIZ];
- int i;
+ char *buf, **qargv;
+ int i, len;
char *bp;
- i = strlen(tag);
- sprintf(buf, "%s[%d]: ", tag, version);
- for (bp = buf; *bp; bp++)
- ;
+ qargv = xmalloc(argc * sizeof(char *));
- for (i = 0; i < argc && ((buf - bp) + BUFSIZ) > 2; i++)
+ for (i = len = 0; i < argc; i++)
{
- if (i != 0)
- {
- *bp++ = ',';
- *bp++ = ' ';
- }
- bp = requote(bp, argv[i], (buf - bp) + BUFSIZ);
+ qargv[i] = requote(argv[i]);
+ len += strlen(qargv[i]) + 2;
}
- *bp = '\0';
- com_err(whoami, 0, "%s", buf);
+
+ buf = xmalloc(len + 1);
+
+ for (i = 0, *buf = '\0'; i < argc; i++)
+ {
+ if (i)
+ strcat(buf, ", ");
+ strcat(buf, qargv[i]);
+ free(qargv[i]);
+ }
+ free(qargv);
+
+ com_err(whoami, 0, "%s[%d]: %s", tag, version, buf);
+ free(buf);
}
void mr_com_err(const char *whoami, long code, const char *fmt, va_list pvar)
char **a;
int i;
- a = malloc(argc * sizeof(char *));
- if (!a)
- return a;
+ a = xmalloc(argc * sizeof(char *));
for (i = 0; i < argc; i++)
- a[i] = strdup(argv[i]);
+ a[i] = xstrdup(argv[i]);
return a;
}
critical_alert("moirad", "Out of memory");
exit(1);
}
+
+char *xstrdup(char *str)
+{
+ char *buf = strdup(str);
+
+ if (buf)
+ return buf;
+
+ critical_alert("moirad", "Out of memory");
+ exit(1);
+}
extern char *whoami;
extern int dbms_errno, mr_errcode;
-EXEC SQL BEGIN DECLARE SECTION;
-extern char stmt_buf[];
-EXEC SQL END DECLARE SECTION;
-
EXEC SQL WHENEVER SQLERROR DO dbmserr();
* Inputs: argv[0] - list_id
* q - query name
* argv[2] - member ID (only for queries "amtl" and "dmfl")
- * argv[7] - group IID (only for query "ulis")
+ * argv[7] - group ID (only for query "ulis")
* cl - client name
*
* - check that client is a member of the access control list
{
EXEC SQL BEGIN DECLARE SECTION;
int list_id, acl_id, flags, gid, users_id;
- char acl_type[9], name[33], *newname;
+ char acl_type[LIST_ACL_TYPE_SIZE], name[LIST_NAME_SIZE], *newname;
EXEC SQL END DECLARE SECTION;
int status;
{
EXEC SQL BEGIN DECLARE SECTION;
int list_id, acl_id, flags ;
- char acl_type[9];
+ char acl_type[LIST_ACL_TYPE_SIZE];
EXEC SQL END DECLARE SECTION;
int status;
{
EXEC SQL BEGIN DECLARE SECTION;
int acl_id, flags, rowcount;
- char acl_type[9], *listname;
+ char acl_type[LIST_ACL_TYPE_SIZE], *listname;
EXEC SQL END DECLARE SECTION;
int status;
{
EXEC SQL BEGIN DECLARE SECTION;
int acl_id;
- char *name, acl_type[9];
+ char *name, acl_type[LIST_ACL_TYPE_SIZE];
EXEC SQL END DECLARE SECTION;
int status;
char *c;
{
EXEC SQL BEGIN DECLARE SECTION;
int mid, sid, id;
- char mtype[9], stype[9];
+ char mtype[MACHINE_OWNER_TYPE_SIZE], stype[SUBNET_OWNER_TYPE_SIZE];
EXEC SQL END DECLARE SECTION;
int status;
{
EXEC SQL BEGIN DECLARE SECTION;
int status, acomment, use, ocomment, snid;
- char contact[33], address[33];
+ char contact[MACHINE_CONTACT_SIZE], address[MACHINE_ADDRESS_SIZE];
EXEC SQL END DECLARE SECTION;
id = *(int *)argv[0];
{
EXEC SQL BEGIN DECLARE SECTION;
int cnt, id, mid, sid;
- char mtype[256], stype[256];
+ char mtype[MACHINE_OWNER_TYPE_SIZE], stype[SUBNET_OWNER_TYPE_SIZE];
EXEC SQL END DECLARE SECTION;
int status;
extern char stmt_buf[];
EXEC SQL END DECLARE SECTION;
-static void hex_dump(unsigned char *p);
-
EXEC SQL WHENEVER SQLERROR DO dbmserr();
int i, j;
char **argv;
#ifdef GDSS
- unsigned char sigbuf[256];
+ unsigned char sigbuf[512];
char *kname;
SigInfo si;
EXEC SQL BEGIN DECLARE SECTION;
int timestamp, who;
char *login;
- char rsig[256];
- EXEC SQL VAR rsig IS STRING(256);
+ char rsig[USERS_SIGNATURE_SIZE];
+ EXEC SQL VAR rsig IS STRING(USERS_SIGNATURE_SIZE);
EXEC SQL END DECLARE SECTION;
#endif /* GDSS */
int id, status;
WHERE login = :login;
if (dbms_errno)
return mr_errcode;
- kname = malloc(1);
+ kname = malloc(0);
status = id_to_name(who, STRINGS_TABLE, &kname);
si.timestamp = timestamp;
si.SigInfoVersion = 0; /* XXXXX this isn't used */
kname_parse(si.pname, si.pinst, si.prealm, kname);
free(kname);
- si.rawsig = (unsigned char *)strdup(rsig);
+ si.rawsig = (unsigned char *)xstrdup(rsig);
GDSS_Recompose(&si, sigbuf);
free(si.rawsig);
free(argv[U_SIGNATURE]);
- argv[U_SIGNATURE] = strdup(sigbuf);
+ argv[U_SIGNATURE] = xstrdup(sigbuf);
}
#endif /* GDSS */
(*action)(q->vcnt, argv, actarg);
EXEC SQL BEGIN DECLARE SECTION;
int who, status;
char *login, *entity, *name;
- char fullname[129];
+ char fullname[USERS_FIRST_SIZE + USERS_MIDDLE_SIZE + USERS_LAST_SIZE];
EXEC SQL END DECLARE SECTION;
#ifdef GDSS
- char databuf[32];
+ char databuf[USERS_LOGIN_SIZE + USERS_CLEARID_SIZE];
EXEC SQL BEGIN DECLARE SECTION;
- char rawsig[128];
+ char rawsig[512];
int sigwho, timestamp;
EXEC SQL END DECLARE SECTION;
SigInfo si;
char *entity, *name;
EXEC SQL END DECLARE SECTION;
#ifdef GDSS
- char databuf[32];
+ char databuf[USERS_LOGIN_SIZE + USERS_CLEARID_SIZE];
EXEC SQL BEGIN DECLARE SECTION;
- char rawsig[128];
+ char rawsig[512];
char *login;
int sigwho, timestamp;
EXEC SQL END DECLARE SECTION;
#ifdef GDSS
if (q->vcnt == U_MODTIME && *argv[U_SIGNATURE + 1])
{
- login = malloc(1);
+ login = malloc(0);
status = id_to_name(id, USERS_TABLE, &login);
sprintf(databuf, "%s:%s", login, argv[U_MITID + 1]);
free(login);
{
status = 0;
free(argv[idx]);
- argv[idx] = strdup("NONE");
+ argv[idx] = xstrdup("NONE");
}
else
{
status = 0;
free(argv[idx]);
- argv[idx] = strdup("???");
+ argv[idx] = xstrdup("???");
}
if (status && status != MR_NO_MATCH)
return status;
{
status = 0;
free(argv[idx]);
- argv[idx] = strdup("NONE");
+ argv[idx] = xstrdup("NONE");
}
else
{
status = 0;
free(argv[idx]);
- argv[idx] = strdup("???");
+ argv[idx] = xstrdup("???");
}
if (status && status != MR_NO_MATCH)
return status;
{
status = 0;
free(argv[idx]);
- argv[idx] = strdup("NONE");
+ argv[idx] = xstrdup("NONE");
}
else
{
status = 0;
free(argv[idx]);
- argv[idx] = strdup("???");
+ argv[idx] = xstrdup("???");
}
if (status && status != MR_NO_MATCH)
return status;
if (!strcmp(q->shortname, "glin") && atoi(argv[6]) == -1)
{
- argv[6] = realloc(argv[6], strlen(UNIQUE_GID) + 1);
+ argv[6] = xrealloc(argv[6], strlen(UNIQUE_GID) + 1);
strcpy(argv[6], UNIQUE_GID);
}
break;
case 'A':
free(argv[2]);
- argv[2] = strdup("system:anyuser");
+ argv[2] = xstrdup("system:anyuser");
break;
default:
id = atoi(argv[2]);
- argv[2] = malloc(8);
+ argv[2] = xmalloc(8);
sprintf(argv[2], "%d", id);
}
}
id = atoi(argv[idx]);
free(argv[idx]);
- argv[idx] = malloc(256);
+ argv[idx] = xmalloc(id ? NFSPHYS_DIR_SIZE : FILESYS_NAME_SIZE);
name = argv[idx];
- memset(name, 0, 256);
+ name[0] = '\0';
if (id == 0)
{
label = argv[0];
{
status = 0;
free(argv[i + 1]);
- argv[i + 1] = strdup("NONE");
+ argv[i + 1] = xstrdup("NONE");
}
else
{
status = 0;
free(argv[i + 1]);
- argv[i + 1] = strdup("???");
+ argv[i + 1] = xstrdup("???");
}
if (status && status != MR_NO_MATCH)
return status;
{
status = 0;
free(argv[2]);
- argv[2] = strdup("NONE");
+ argv[2] = xstrdup("NONE");
}
else
{
status = 0;
free(argv[2]);
- argv[2] = strdup("???");
+ argv[2] = xstrdup("???");
}
if (status && status != MR_NO_MATCH)
return status;
int trigger_dcm(struct query *q, char *argv[], client *cl)
{
pid_t pid;
- char prog[128];
+ char prog[MAXPATHLEN];
sprintf(prog, "%s/startdcm", BIN_DIR);
pid = vfork();
* Used by the SQL query routines of the Moira server.
*/
-#define MR_CDUMMY_LEN 256
#define MR_STMTBUF_LEN 1024
extern int mr_sig_length;
SQLDA *mr_sqlda;
EXEC SQL BEGIN DECLARE SECTION;
int mr_sig_length;
-int idummy;
-char cdummy[MR_CDUMMY_LEN];
char stmt_buf[MR_STMTBUF_LEN];
EXEC SQL END DECLARE SECTION;
/* initialize local argv */
for (i = 0; i < 16; i++)
- Argv[i] = malloc(ARGLEN);
+ Argv[i] = xmalloc(MAX_FIELD_WIDTH);
mr_sqlda = mr_alloc_sqlda();
EXEC SQL COMMIT WORK;
if (journal)
{
- char buf[1024];
+ char *buf;
int i;
extern time_t now;
{
if (i != 0)
putc(' ', journal);
- requote(buf, argv_ro[i], sizeof(buf));
+ buf = requote(argv_ro[i]);
fputs(buf, journal);
+ free(buf);
}
putc('\n', journal);
fflush(journal);
/* copy the arguments into a local argv that we can modify */
for (i = 0; i < argc; i++)
{
- for (to = Argv[i], fr = argv_ro[i], stop = to + ARGLEN; (*fr) && (to < stop);)
+ for (to = Argv[i], fr = argv_ro[i], stop = to + MAX_FIELD_WIDTH; (*fr) && (to < stop);)
*to++ = *fr++;
if (*fr)
{
mr_sqlda->V[i] = buffers[i];
mr_sqlda->T[i] = 97;
- mr_sqlda->L[i] = ARGLEN;
+ mr_sqlda->L[i] = MAX_FIELD_WIDTH;
}
EXEC SQL FETCH inc_crs USING DESCRIPTOR mr_sqlda;
{
mr_sqlda->V[i] = sqlbuffer[i];
mr_sqlda->T[i] = 97;
- mr_sqlda->L[i] = ARGLEN;
+ mr_sqlda->L[i] = MAX_FIELD_WIDTH;
}
while (1)
{
EXEC SQL BEGIN DECLARE SECTION;
int id, mid;
- char type[9];
+ char type[USERS_POTYPE_SIZE];
EXEC SQL END DECLARE SECTION;
id = *(int *)argv[0];
{
EXEC SQL BEGIN DECLARE SECTION;
int id, user;
- char type[9];
+ char type[USERS_POTYPE_SIZE];
EXEC SQL END DECLARE SECTION;
user = *(int *)argv[0];
int mach_id;
EXEC SQL BEGIN DECLARE SECTION;
int ok;
- char ftype[32], *rwaccess;
+ char ftype[FILESYS_TYPE_SIZE + 10], *rwaccess;
EXEC SQL END DECLARE SECTION;
type = argv[1];
char *type, *name;
EXEC SQL BEGIN DECLARE SECTION;
int fid, total, who, ok;
- char *entity, ftype[32], *access;
+ char *entity, ftype[FILESYS_TYPE_SIZE + 10], *access;
short int total_null;
EXEC SQL END DECLARE SECTION;
int check_nfs(int mach_id, char *name, char *access)
{
EXEC SQL BEGIN DECLARE SECTION;
- char dir[81];
+ char dir[NFSPHYS_DIR_SIZE];
int mid = mach_id;
EXEC SQL END DECLARE SECTION;
int status;
int setup_ahst(struct query *q, char **argv, client *cl)
{
EXEC SQL BEGIN DECLARE SECTION;
- char *name, oldname[41], vendor[17], model[25], os[17];
+ char *name, oldname[MACHINE_NAME_SIZE], vendor[MACHINE_VENDOR_SIZE];
+ char *model[MACHINE_MODEL_SIZE], os[MACHINE_OS_SIZE];
int value, id, saddr, mask, high, low, cnt;
EXEC SQL END DECLARE SECTION;
int row;
count = QueryCount2;
if (!squeries2)
{
- sq = malloc(count * sizeof(struct query *));
+ sq = xmalloc(count * sizeof(struct query *));
squeries2 = sq;
q = Queries2;
for (i = count; --i >= 0; )
{
EXEC SQL BEGIN DECLARE SECTION;
int user, id;
- char *box, potype[9];
+ char *box, potype[USERS_POTYPE_SIZE];
EXEC SQL END DECLARE SECTION;
int status;
{
char *argv[13];
EXEC SQL BEGIN DECLARE SECTION;
- char *name, acl_type[9], listname[33], active[5], public[5], hidden[5];
- char maillist[5], grouplist[5], gid_str[6], desc[256];
- char modtime[27], modwith[9];
+ char *name, acl_type[LIST_ACL_TYPE_SIZE], listname[LIST_NAME_SIZE];
+ char active[5], public[5], hidden[5];
+ char maillist[5], grouplist[5], gid_str[LIST_GID_SIZE];
+ char desc[LIST_DESCRIPTION_SIZE], modtime[LIST_MODTIME_SIZE];
+ char modwith[LIST_MODWITH_SIZE];
int id, rowcount, acl_id, hid, modby_id;
EXEC SQL END DECLARE SECTION;
int returned, status;
{
status = 0;
free(argv[8]);
- argv[8] = strdup("NONE");
+ argv[8] = xstrdup("NONE");
}
else
{
status = 0;
free(argv[8]);
- argv[8] = strdup("???");
+ argv[8] = xstrdup("???");
}
if (status && status != MR_NO_MATCH)
return status;
{
EXEC SQL BEGIN DECLARE SECTION;
int id, lid, mid, error, who, ref, rowcnt;
- char *mtype, dtype[9], *entity;
+ char *mtype, dtype[IMEMBERS_MEMBER_TYPE_SIZE], *entity;
EXEC SQL END DECLARE SECTION;
int ancestors[MAXLISTDEPTH], aref[MAXLISTDEPTH], acount, a;
int descendants[MAXLISTDEPTH], dref[MAXLISTDEPTH], dcount, d;
{
EXEC SQL BEGIN DECLARE SECTION;
int id, lid, mid, cnt, error, who, ref;
- char *mtype, dtype[9], *entity;
+ char *mtype, dtype[IMEMBERS_MEMBER_TYPE_SIZE], *entity;
EXEC SQL END DECLARE SECTION;
int ancestors[MAXLISTDEPTH], aref[MAXLISTDEPTH], acount, a;
int descendants[MAXLISTDEPTH], dref[MAXLISTDEPTH], dcount, d;
char *rargv[2];
int found = 0;
EXEC SQL BEGIN DECLARE SECTION;
- char name[33], *type = atype;
+ char name[LIST_NAME_SIZE], *type = atype;
int id = aid;
EXEC SQL END DECLARE SECTION;
EXEC SQL BEGIN DECLARE SECTION;
char *atype;
int aid;
- char name[33], active[5], public[5], hidden[5], maillist[5], grouplist[5];
+ char name[LIST_NAME_SIZE];
+ char active[5], public[5], hidden[5], maillist[5], grouplist[5];
EXEC SQL END DECLARE SECTION;
atype = argv[0];
{
EXEC SQL BEGIN DECLARE SECTION;
int list_id, direct;
- char member_name[129];
+ char member_name[MAX_FIELD_WIDTH];
EXEC SQL END DECLARE SECTION;
char *targv[2];
int register_user(struct query *q, char **argv, client *cl)
{
EXEC SQL BEGIN DECLARE SECTION;
- char *login, *entity, directory[129], machname[33];
+ char *login, *entity;
+ char directory[FILESYS_NAME_SIZE], machname[MACHINE_NAME_SIZE];
int who, rowcount, mid, uid, users_id, utype, list_id;
int ostatus, nstatus, fsidval;
static int m_id = 0, def_quota = 0;
static char ZEPH[] = "zephyr";
static char ZEPH_ID[] = "xmt_id";
-/* Table Names */
-char *table_name[] = {
- "none", USERS, "krbmap", MACHINE, "hostalias", SUBNET, CLUSTER,
- "mcmap", "svc", LIST, "imembers", SERVERS, "serverhosts", FILESYS,
- "fsgroup", "nfsphys", "quota", ZEPH, HOSTACCESS, "strings", "services",
- PRINTCAP, "palladium", "capacls", "alias", "numvalues", "tblstats",
- "incremental"};
-int num_tables = 27;
-
-
/* VALOBJS
* These are commonly used validation objects, defined here so that they
* can be shared.
};
static struct valobj VOclu0[] = {
- {V_ID, 0, CLUSTER_TABLE, NAME, CLU_ID, MR_CLUSTER},
+ {V_ID, 0, CLUSTERS_TABLE, NAME, CLU_ID, MR_CLUSTER},
};
static struct valobj VOlist0[] = {
};
static struct valobj aclu_valobj[] = {
- {V_LOCK, 0, CLUSTER_TABLE, 0, CLU_ID, MR_DEADLOCK},
- {V_CHAR, 0, CLUSTER_TABLE, NAME},
- {V_LEN, 1, CLUSTER_TABLE, DESC},
- {V_LEN, 2, CLUSTER_TABLE, LOCATION},
+ {V_LOCK, 0, CLUSTERS_TABLE, 0, CLU_ID, MR_DEADLOCK},
+ {V_CHAR, 0, CLUSTERS_TABLE, NAME},
+ {V_LEN, 1, CLUSTERS_TABLE, DESC},
+ {V_LEN, 2, CLUSTERS_TABLE, LOCATION},
};
static struct validate aclu_validate =
};
static struct valobj uclu_valobj[] = {
- {V_LOCK, 0, CLUSTER_TABLE, 0, CLU_ID, MR_DEADLOCK},
- {V_ID, 0, CLUSTER_TABLE, NAME, CLU_ID, MR_CLUSTER},
- {V_RENAME, 1, CLUSTER_TABLE, NAME, CLU_ID, MR_NOT_UNIQUE},
- {V_LEN, 2, CLUSTER_TABLE, DESC},
- {V_LEN, 3, CLUSTER_TABLE, LOCATION},
+ {V_LOCK, 0, CLUSTERS_TABLE, 0, CLU_ID, MR_DEADLOCK},
+ {V_ID, 0, CLUSTERS_TABLE, NAME, CLU_ID, MR_CLUSTER},
+ {V_RENAME, 1, CLUSTERS_TABLE, NAME, CLU_ID, MR_NOT_UNIQUE},
+ {V_LEN, 2, CLUSTERS_TABLE, DESC},
+ {V_LEN, 3, CLUSTERS_TABLE, LOCATION},
};
static struct validate uclu_validate = {
static struct valobj amtc_valobj[] = /* ADD_MACHINE_TO_CLUSTER */
{ /* DELETE_MACHINE_FROM_CLUSTER */
{V_ID, 0, MACHINE_TABLE, NAME, MACH_ID, MR_MACHINE},
- {V_ID, 1, CLUSTER_TABLE, NAME, CLU_ID, MR_CLUSTER},
+ {V_ID, 1, CLUSTERS_TABLE, NAME, CLU_ID, MR_CLUSTER},
};
static struct validate amtc_validate = /* for amtc and dmfc */
static struct valobj acld_valobj[] =
{
- {V_ID, 0, CLUSTER_TABLE, NAME, CLU_ID, MR_CLUSTER},
+ {V_ID, 0, CLUSTERS_TABLE, NAME, CLU_ID, MR_CLUSTER},
{V_CHAR, 1, SVC_TABLE, "serv_label"},
{V_CHAR, 2, SVC_TABLE, "serv_cluster"}
};
static struct valobj dcld_valobj[] =
{
- {V_ID, 0, CLUSTER_TABLE, NAME, CLU_ID, MR_CLUSTER},
+ {V_ID, 0, CLUSTERS_TABLE, NAME, CLU_ID, MR_CLUSTER},
};
static struct validate dcld_validate =
"gclu",
RETRIEVE,
"c",
- CLUSTER_TABLE,
+ CLUSTERS_TABLE,
"name, description, location, TO_CHAR(modtime, 'DD-mon-YYYY HH24:MI:SS'), modby, modwith FROM clusters",
gclu_fields,
6,
"aclu",
APPEND,
"c",
- CLUSTER_TABLE,
+ CLUSTERS_TABLE,
"INTO clusters (name, description, location, clu_id) VALUES ('%s', NVL('%s', CHR(0)), NVL('%s', CHR(0)), %s)",
aclu_fields,
3,
"uclu",
UPDATE,
"c",
- CLUSTER_TABLE,
+ CLUSTERS_TABLE,
"clusters SET name = '%s', description = NVL('%s', CHR(0)), location = NVL('%s', CHR(0))",
uclu_fields,
3,
"dclu",
DELETE,
"c",
- CLUSTER_TABLE,
+ CLUSTERS_TABLE,
NULL,
dclu_fields,
0,
/* Query Types */
enum query_type {RETRIEVE, UPDATE, APPEND, DELETE, SPECIAL};
-/* Tables */
-enum tables {NO_TABLE, USERS_TABLE, KRBMAP_TABLE, MACHINE_TABLE,
- HOSTALIAS_TABLE, SUBNET_TABLE, CLUSTER_TABLE, MCMAP_TABLE,
- SVC_TABLE, LIST_TABLE, IMEMBERS_TABLE, SERVERS_TABLE,
- SERVERHOSTS_TABLE, FILESYS_TABLE, FSGROUP_TABLE, NFSPHYS_TABLE,
- QUOTA_TABLE, ZEPHYR_TABLE, HOSTACCESS_TABLE, STRINGS_TABLE,
- SERVICES_TABLE, PRINTCAP_TABLE, PALLADIUM_TABLE, CAPACLS_TABLE,
- ALIAS_TABLE, NUMVALUES_TABLE, TBLSTATS_TABLE, INCREMENTAL_TABLE};
-
/* Query Definition Structure */
struct query
{
if ((tbl == USERS_TABLE && !strcmp(namefield, "login")) ||
tbl == MACHINE_TABLE || tbl == SUBNET_TABLE || tbl == FILESYS_TABLE ||
- tbl == LIST_TABLE || tbl == CLUSTER_TABLE || tbl == STRINGS_TABLE)
+ tbl == LIST_TABLE || tbl == CLUSTERS_TABLE || tbl == STRINGS_TABLE)
{
if (tbl == MACHINE_TABLE || tbl == SUBNET_TABLE)
{
for (j = 0; j < QMAXARGS; j++)
{
- it->V[j] = sqlbuffer[j] = malloc(ARGLEN);
+ it->V[j] = sqlbuffer[j] = xmalloc(ARGLEN);
it->T[j] = 97; /* 97 = CHARZ = null-terminated string */
it->L[j] = ARGLEN;
}