prototype \
slave \
tests \
- util/support
+ util
BSDFILES = \
kadmin/cli/strftime.c \
lib/krb5/krb/strptime.c \
slave/kpropd_rpc.c \
util/support/mkstemp.c \
- util/support/strlcpy.c
+ util/support/strlcpy.c \
+ util/windows/getopt.c \
+ util/windows/getopt.h \
+ util/windows/getopt_long.c
OTHEREXCLUDES = \
include/iprop.h \
tests/asn.1/utility.h \
tests/gss-threads/gss-misc.c \
tests/gss-threads/gss-misc.h \
- tests/hammer/kdc5_hammer.c
+ tests/hammer/kdc5_hammer.c \
+ util/et/com_err.h \
+ util/profile/prof_int.h \
+ util/profile/profile.hin \
+ util/profile/profile_tcl.c
EXCLUDES = `for i in $(BSDFILES) $(OTHEREXCLUDES); do echo $$i; done | $(AWK) '{ print "-path", $$1, "-o" }'` -path /dev/null
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 1997 by Massachusetts Institute of Technology
*
#if defined(_WIN32)
BOOL isGuiApp() {
- DWORD mypid;
- HANDLE myprocess;
- mypid = GetCurrentProcessId();
- myprocess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, mypid);
- return GetGuiResources(myprocess, 1) > 0;
- }
+ DWORD mypid;
+ HANDLE myprocess;
+ mypid = GetCurrentProcessId();
+ myprocess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, mypid);
+ return GetGuiResources(myprocess, 1) > 0;
+}
#endif
static void default_com_err_proc (const char *whoami, errcode_t code,
- const char *fmt, va_list ap)
+ const char *fmt, va_list ap)
{
#if defined(_WIN32)
- char errbuf[1024] = "";
-
- if (whoami) {
- errbuf[sizeof(errbuf) - 1] = '\0';
- strncat (errbuf, whoami, sizeof(errbuf) - 1 - strlen(errbuf));
- strncat (errbuf, ": ", sizeof(errbuf) - 1 - strlen(errbuf));
- }
- if (code) {
- errbuf[sizeof(errbuf) - 1] = '\0';
- strncat (errbuf, error_message(code), sizeof(errbuf) - 1 - strlen(errbuf));
- strncat (errbuf, " ", sizeof(errbuf) - 1 - strlen(errbuf));
- }
- if (fmt)
- /* ITS4: ignore vsprintf */
- vsprintf (errbuf + strlen (errbuf), fmt, ap);
- errbuf[sizeof(errbuf) - 1] = '\0';
-
- if (_isatty(_fileno(stderr)) || !isGuiApp()) {
- fputs(errbuf, stderr);
- fputc('\r', stderr);
- fputc('\n', stderr);
- fflush(stderr);
- } else
- MessageBox ((HWND)NULL, errbuf, "Kerberos", MB_ICONEXCLAMATION);
+ char errbuf[1024] = "";
+
+ if (whoami) {
+ errbuf[sizeof(errbuf) - 1] = '\0';
+ strncat (errbuf, whoami, sizeof(errbuf) - 1 - strlen(errbuf));
+ strncat (errbuf, ": ", sizeof(errbuf) - 1 - strlen(errbuf));
+ }
+ if (code) {
+ errbuf[sizeof(errbuf) - 1] = '\0';
+ strncat (errbuf, error_message(code), sizeof(errbuf) - 1 - strlen(errbuf));
+ strncat (errbuf, " ", sizeof(errbuf) - 1 - strlen(errbuf));
+ }
+ if (fmt)
+ /* ITS4: ignore vsprintf */
+ vsprintf (errbuf + strlen (errbuf), fmt, ap);
+ errbuf[sizeof(errbuf) - 1] = '\0';
+
+ if (_isatty(_fileno(stderr)) || !isGuiApp()) {
+ fputs(errbuf, stderr);
+ fputc('\r', stderr);
+ fputc('\n', stderr);
+ fflush(stderr);
+ } else
+ MessageBox ((HWND)NULL, errbuf, "Kerberos", MB_ICONEXCLAMATION);
#else /* !_WIN32 */
- if (whoami) {
- fputs(whoami, stderr);
- fputs(": ", stderr);
- }
- if (code) {
- fputs(error_message(code), stderr);
- fputs(" ", stderr);
- }
- if (fmt) {
- vfprintf(stderr, fmt, ap);
- }
- /* should do this only on a tty in raw mode */
- putc('\r', stderr);
- putc('\n', stderr);
- fflush(stderr);
+ if (whoami) {
+ fputs(whoami, stderr);
+ fputs(": ", stderr);
+ }
+ if (code) {
+ fputs(error_message(code), stderr);
+ fputs(" ", stderr);
+ }
+ if (fmt) {
+ vfprintf(stderr, fmt, ap);
+ }
+ /* should do this only on a tty in raw mode */
+ putc('\r', stderr);
+ putc('\n', stderr);
+ fflush(stderr);
#endif
}
void KRB5_CALLCONV com_err_va(const char *whoami,
- errcode_t code,
- const char *fmt,
- va_list ap)
+ errcode_t code,
+ const char *fmt,
+ va_list ap)
{
int err;
et_old_error_hook_func p;
err = com_err_finish_init();
if (err)
- goto best_try;
+ goto best_try;
err = k5_mutex_lock(&com_err_hook_lock);
if (err)
- goto best_try;
+ goto best_try;
p = com_err_hook ? com_err_hook : default_com_err_proc;
(*p)(whoami, code, fmt, ap);
k5_mutex_unlock(&com_err_hook_lock);
there's a good chance it has to do with failed initialization
of the caller. */
if (!com_err_hook)
- default_com_err_proc(whoami, code, fmt, ap);
+ default_com_err_proc(whoami, code, fmt, ap);
else
- (com_err_hook)(whoami, code, fmt, ap);
+ (com_err_hook)(whoami, code, fmt, ap);
assert(err == 0);
abort();
}
void KRB5_CALLCONV_C com_err(const char *whoami,
- errcode_t code,
- const char *fmt, ...)
+ errcode_t code,
+ const char *fmt, ...)
{
- va_list ap;
+ va_list ap;
- va_start(ap, fmt);
- com_err_va(whoami, code, fmt, ap);
- va_end(ap);
+ va_start(ap, fmt);
+ com_err_va(whoami, code, fmt, ap);
+ va_end(ap);
}
/* Make a separate function because the assert invocations below
et_old_error_hook_func set_com_err_hook (et_old_error_hook_func new_proc)
{
- et_old_error_hook_func x;
-
- /* Broken initialization? What can we do? */
- assert(com_err_finish_init() == 0);
- assert(com_err_lock_hook_handle() == 0);
- x = com_err_hook;
- com_err_hook = new_proc;
- k5_mutex_unlock(&com_err_hook_lock);
- return x;
+ et_old_error_hook_func x;
+
+ /* Broken initialization? What can we do? */
+ assert(com_err_finish_init() == 0);
+ assert(com_err_lock_hook_handle() == 0);
+ x = com_err_hook;
+ com_err_hook = new_proc;
+ k5_mutex_unlock(&com_err_hook_lock);
+ return x;
}
et_old_error_hook_func reset_com_err_hook ()
{
- et_old_error_hook_func x;
-
- /* Broken initialization? What can we do? */
- assert(com_err_finish_init() == 0);
- assert(com_err_lock_hook_handle() == 0);
- x = com_err_hook;
- com_err_hook = NULL;
- k5_mutex_unlock(&com_err_hook_lock);
- return x;
+ et_old_error_hook_func x;
+
+ /* Broken initialization? What can we do? */
+ assert(com_err_finish_init() == 0);
+ assert(com_err_lock_hook_handle() == 0);
+ x = com_err_hook;
+ com_err_hook = NULL;
+ k5_mutex_unlock(&com_err_hook_lock);
+ return x;
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
*
* Copyright 1986, 1987, 1988
char * xmalloc (size) unsigned int size; {
char * p = malloc (size);
if (!p) {
- perror (whoami);
- exit (1);
+ perror (whoami);
+ exit (1);
}
return p;
}
static int check_arg (str_list, arg) char const *const *str_list, *arg; {
while (*str_list)
- if (!strcmp(arg, *str_list++))
- return 1;
+ if (!strcmp(arg, *str_list++))
+ return 1;
return 0;
}
"/*\n * %s:\n * This file is automatically generated; please do not edit it.\n */\n";
/* pathnames */
-char c_file[MAXPATHLEN]; /* output file */
-char h_file[MAXPATHLEN]; /* output */
+char c_file[MAXPATHLEN]; /* output file */
+char h_file[MAXPATHLEN]; /* output */
static void usage () {
fprintf (stderr, "%s: usage: %s ERROR_TABLE\n",
- whoami, whoami);
+ whoami, whoami);
exit (1);
}
static void dup_err (type, one, two) char const *type, *one, *two; {
fprintf (stderr, "%s: multiple %s specified: `%s' and `%s'\n",
- whoami, type, one, two);
+ whoami, type, one, two);
usage ();
}
whoami = argv[0];
p = strrchr (whoami, '/');
if (p)
- whoami = p+1;
+ whoami = p+1;
while (argv++, --argc) {
- char *arg = *argv;
- if (arg[0] != '-') {
- if (filename)
- dup_err ("filenames", filename, arg);
- filename = arg;
- }
- else {
- arg++;
- if (check_arg (debug_args, arg))
- debug++;
- else if (check_arg (lang_args, arg)) {
- got_language++;
- arg = *++argv, argc--;
- if (!arg)
- usage ();
- if (language)
- dup_err ("languanges", language_names[(int)language], arg);
+ char *arg = *argv;
+ if (arg[0] != '-') {
+ if (filename)
+ dup_err ("filenames", filename, arg);
+ filename = arg;
+ }
+ else {
+ arg++;
+ if (check_arg (debug_args, arg))
+ debug++;
+ else if (check_arg (lang_args, arg)) {
+ got_language++;
+ arg = *++argv, argc--;
+ if (!arg)
+ usage ();
+ if (language)
+ dup_err ("languanges", language_names[(int)language], arg);
#define check_lang(x,v) else if (!strcasecmp(arg,x)) language = v
- check_lang ("c", lang_C);
- check_lang ("ansi_c", lang_C);
- check_lang ("ansi-c", lang_C);
- check_lang ("krc", lang_KRC);
- check_lang ("kr_c", lang_KRC);
- check_lang ("kr-c", lang_KRC);
- check_lang ("k&r-c", lang_KRC);
- check_lang ("k&r_c", lang_KRC);
- check_lang ("c++", lang_CPP);
- check_lang ("cplusplus", lang_CPP);
- check_lang ("c-plus-plus", lang_CPP);
+ check_lang ("c", lang_C);
+ check_lang ("ansi_c", lang_C);
+ check_lang ("ansi-c", lang_C);
+ check_lang ("krc", lang_KRC);
+ check_lang ("kr_c", lang_KRC);
+ check_lang ("kr-c", lang_KRC);
+ check_lang ("k&r-c", lang_KRC);
+ check_lang ("k&r_c", lang_KRC);
+ check_lang ("c++", lang_CPP);
+ check_lang ("cplusplus", lang_CPP);
+ check_lang ("c-plus-plus", lang_CPP);
#undef check_lang
- else {
- fprintf (stderr, "%s: unknown language name `%s'\n",
- whoami, arg);
- fprintf (stderr, "\tpick one of: C K&R-C\n");
- exit (1);
- }
- }
- else {
- fprintf (stderr, "%s: unknown control argument -`%s'\n",
- whoami, arg);
- usage ();
- }
- }
+ else {
+ fprintf (stderr, "%s: unknown language name `%s'\n",
+ whoami, arg);
+ fprintf (stderr, "\tpick one of: C K&R-C\n");
+ exit (1);
+ }
+ }
+ else {
+ fprintf (stderr, "%s: unknown control argument -`%s'\n",
+ whoami, arg);
+ usage ();
+ }
+ }
}
if (!filename)
- usage ();
+ usage ();
if (!got_language)
- language = lang_KRC;
+ language = lang_KRC;
else if (language == lang_CPP) {
- fprintf (stderr, "%s: Sorry, C++ support is not yet finished.\n",
- whoami);
- exit (1);
+ fprintf (stderr, "%s: Sorry, C++ support is not yet finished.\n",
+ whoami);
+ exit (1);
}
p = xmalloc (strlen (filename) + 5);
filename = p;
p = strrchr(filename, '/');
if (p == (char *)NULL)
- p = filename;
+ p = filename;
else
- p++;
+ p++;
ename = p;
len = strlen (ename);
p += len - 3;
if (strcmp (p, ".et"))
- p += 3;
+ p += 3;
*p++ = '.';
/* now p points to where "et" suffix should start */
/* generate new filenames */
yyin = fopen(filename, "r");
if (!yyin) {
- perror(filename);
- exit(1);
+ perror(filename);
+ exit(1);
}
hfile = fopen(h_file, "w");
if (hfile == (FILE *)NULL) {
- perror(h_file);
- exit(1);
+ perror(h_file);
+ exit(1);
}
fprintf (hfile, warning, h_file);
cfile = fopen(c_file, "w");
if (cfile == (FILE *)NULL) {
- perror(c_file);
- exit(1);
+ perror(c_file);
+ exit(1);
}
fprintf (cfile, warning, c_file);
/* prologue */
if (language == lang_C)
- cpp = c_src_prolog;
+ cpp = c_src_prolog;
else if (language == lang_KRC)
- cpp = krc_src_prolog;
+ cpp = krc_src_prolog;
else
- abort ();
+ abort ();
while (*cpp)
- fputs (*cpp++, cfile);
+ fputs (*cpp++, cfile);
/* parse it */
yyparse();
- fclose(yyin); /* bye bye input file */
+ fclose(yyin); /* bye bye input file */
fputs (" 0\n};\n\n", cfile);
for (cpp = struct_def; *cpp; cpp++)
- fputs (*cpp, cfile);
+ fputs (*cpp, cfile);
fprintf(cfile,
- "const struct error_table et_%s_error_table = { text, %ldL, %d };\n\n",
- table_name, table_number, current);
+ "const struct error_table et_%s_error_table = { text, %ldL, %d };\n\n",
+ table_name, table_number, current);
fputs("static struct et_list link = { 0, 0 };\n\n",
- cfile);
+ cfile);
fprintf(cfile, "void initialize_%s_error_table (%s) {\n",
- table_name, (language == lang_C) ? "void" : "NOARGS");
+ table_name, (language == lang_C) ? "void" : "NOARGS");
fputs(" if (!link.table) {\n", cfile);
fputs(" link.next = _et_list;\n", cfile);
fprintf(cfile, " link.table = &et_%s_error_table;\n", table_name);
fclose(cfile);
fprintf (hfile, "extern void initialize_%s_error_table ();\n",
- table_name);
+ table_name);
fprintf (hfile, "#define ERROR_TABLE_BASE_%s (%ldL)\n",
- table_name, table_number);
+ table_name, table_number);
/* compatibility... */
fprintf (hfile, "\n/* for compatibility with older versions... */\n");
fprintf (hfile, "#define init_%s_err_tbl initialize_%s_error_table\n",
- table_name, table_name);
+ table_name, table_name);
fprintf (hfile, "#define %s_err_base ERROR_TABLE_BASE_%s\n", table_name,
- table_name);
- fclose(hfile); /* bye bye include file */
+ table_name);
+ fclose(hfile); /* bye bye include file */
return 0;
-}
+ }
int yyerror(s) char *s; {
fputs(s, stderr);
fprintf(stderr, "\nLast token was '%s'\n", current_token);
#else
fprintf(stderr, "\nLine number %d; last token was '%s'\n",
- yylineno, current_token);
+ yylineno, current_token);
#endif
}
* specifies the terms and conditions for redistribution.
*/
-/* based on @(#)strcasecmp.c 1.3 (Berkeley) 8/3/87 */
+/* based on @(#)strcasecmp.c 1.3 (Berkeley) 8/3/87 */
/*
* This array is designed for mapping upper and lower case letter
* based upon ascii character sequences.
*/
static char charmap[] = {
- '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
- '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
- '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
- '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
- '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
- '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
- '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
- '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
- '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
- '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
- '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
- '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
- '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
- '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
- '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
- '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
- '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
- '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
- '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
- '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
- '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
- '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
- '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
- '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
- '\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
- '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
- '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
- '\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337',
- '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
- '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
- '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
- '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
+ '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
+ '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
+ '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
+ '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
+ '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
+ '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
+ '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
+ '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
+ '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
+ '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
+ '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
+ '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
+ '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
+ '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
+ '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
+ '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
+ '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
+ '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
+ '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
+ '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
+ '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
+ '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
+ '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
+ '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
+ '\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
+ '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
+ '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
+ '\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337',
+ '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
+ '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
+ '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
+ '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
};
strcasecmp(s1, s2)
- register char *s1, *s2;
+register char *s1, *s2;
{
- register char *cm = charmap;
+ register char *cm = charmap;
- while (cm[*s1] == cm[*s2++])
- if (*s1++ == '\0')
- return(0);
- return(cm[*s1] - cm[*--s2]);
+ while (cm[*s1] == cm[*s2++])
+ if (*s1++ == '\0')
+ return(0);
+ return(cm[*s1] - cm[*--s2]);
}
#endif
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* definitions common to the source files of the error table compiler
*/
enum lang {
- lang_C, /* ANSI C (default) */
- lang_KRC, /* C: ANSI + K&R */
- lang_CPP /* C++ */
+ lang_C, /* ANSI C (default) */
+ lang_KRC, /* C: ANSI + K&R */
+ lang_CPP /* C++ */
};
-int debug; /* dump debugging info? */
-char *filename; /* error table source */
+int debug; /* dump debugging info? */
+char *filename; /* error table source */
enum lang language;
const char *whoami;
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 1997,2000,2001,2004,2008 by Massachusetts Institute of Technology
*
/*@null@*/ static struct et_list * _et_list = (struct et_list *) NULL;
/*@null@*//*@only@*/static struct dynamic_et_list * et_list_dynamic;
static k5_mutex_t et_list_lock = K5_MUTEX_PARTIAL_INITIALIZER;
-static int terminated = 0; /* for debugging shlib fini sequence errors */
+static int terminated = 0; /* for debugging shlib fini sequence errors */
MAKE_INIT_FUNCTION(com_err_initialize);
MAKE_FINI_FUNCTION(com_err_terminate);
terminated = 0;
err = k5_mutex_finish_init(&et_list_lock);
if (err)
- return err;
+ return err;
err = k5_mutex_finish_init(&com_err_hook_lock);
if (err)
- return err;
+ return err;
err = k5_key_register(K5_KEY_COM_ERR, free);
if (err)
- return err;
+ return err;
return 0;
}
struct dynamic_et_list *e, *enext;
if (! INITIALIZER_RAN(com_err_initialize) || PROGRAM_EXITING()) {
#ifdef SHOW_INITFINI_FUNCS
- printf("com_err_terminate: skipping\n");
+ printf("com_err_terminate: skipping\n");
#endif
- return;
+ return;
}
#ifdef SHOW_INITFINI_FUNCS
printf("com_err_terminate\n");
k5_key_delete(K5_KEY_COM_ERR);
k5_mutex_destroy(&com_err_hook_lock);
if (k5_mutex_lock(&et_list_lock) != 0)
- return;
+ return;
for (e = et_list_dynamic; e; e = enext) {
- enext = e->next;
- free(e);
+ enext = e->next;
+ free(e);
}
k5_mutex_unlock(&et_list_lock);
k5_mutex_destroy(&et_list_lock);
char *cp;
cp = k5_getspecific(K5_KEY_COM_ERR);
if (cp == NULL) {
- cp = malloc(ET_EBUFSIZ);
- if (cp == NULL) {
- return NULL;
- }
- if (k5_setspecific(K5_KEY_COM_ERR, cp) != 0) {
- free(cp);
- return NULL;
- }
+ cp = malloc(ET_EBUFSIZ);
+ if (cp == NULL) {
+ return NULL;
+ }
+ if (k5_setspecific(K5_KEY_COM_ERR, cp) != 0) {
+ free(cp);
+ return NULL;
+ }
}
return cp;
}
const char * KRB5_CALLCONV
error_message(long code)
- /*@modifies internalState@*/
+/*@modifies internalState@*/
{
- unsigned long offset;
- unsigned long l_offset;
- struct et_list *et;
- struct dynamic_et_list *det;
- unsigned long table_num;
- int started = 0;
- unsigned int divisor = 100;
- char *cp, *cp1;
- const struct error_table *table;
- int merr;
+ unsigned long offset;
+ unsigned long l_offset;
+ struct et_list *et;
+ struct dynamic_et_list *det;
+ unsigned long table_num;
+ int started = 0;
+ unsigned int divisor = 100;
+ char *cp, *cp1;
+ const struct error_table *table;
+ int merr;
- l_offset = (unsigned long)code & ((1<<ERRCODE_RANGE)-1);
- offset = l_offset;
- table_num = ((unsigned long)code - l_offset) & ERRCODE_MAX;
- if (table_num == 0
+ l_offset = (unsigned long)code & ((1<<ERRCODE_RANGE)-1);
+ offset = l_offset;
+ table_num = ((unsigned long)code - l_offset) & ERRCODE_MAX;
+ if (table_num == 0
#ifdef __sgi
- /* Irix 6.5 uses a much bigger table than other UNIX
- systems I've looked at, but the table is sparse. The
- sparse entries start around 500, but sys_nerr is only
- 152. */
- || (code > 0 && code <= 1600)
+ /* Irix 6.5 uses a much bigger table than other UNIX
+ systems I've looked at, but the table is sparse. The
+ sparse entries start around 500, but sys_nerr is only
+ 152. */
+ || (code > 0 && code <= 1600)
#endif
- ) {
- if (code == 0)
- goto oops;
+ ) {
+ if (code == 0)
+ goto oops;
- /* This could trip if int is 16 bits. */
- if ((unsigned long)(int)code != (unsigned long)code)
- abort ();
+ /* This could trip if int is 16 bits. */
+ if ((unsigned long)(int)code != (unsigned long)code)
+ abort ();
#ifdef HAVE_STRERROR_R
- cp = get_thread_buffer();
- if (cp && strerror_r((int) code, cp, ET_EBUFSIZ) == 0)
- return cp;
+ cp = get_thread_buffer();
+ if (cp && strerror_r((int) code, cp, ET_EBUFSIZ) == 0)
+ return cp;
#endif
#ifdef HAVE_STRERROR
- cp = strerror((int) code);
- if (cp)
- return cp;
+ cp = strerror((int) code);
+ if (cp)
+ return cp;
#elif defined HAVE_SYS_ERRLIST
- if (offset < sys_nerr)
- return(sys_errlist[offset]);
+ if (offset < sys_nerr)
+ return(sys_errlist[offset]);
#endif
- goto oops;
- }
+ goto oops;
+ }
- if (CALL_INIT_FUNCTION(com_err_initialize))
- return 0;
- merr = k5_mutex_lock(&et_list_lock);
- if (merr)
- goto oops;
- dprintf (("scanning static list for %x\n", table_num));
- for (et = _et_list; et != NULL; et = et->next) {
- if (et->table == NULL)
- continue;
- dprintf (("\t%x = %s\n", et->table->base & ERRCODE_MAX,
- et->table->msgs[0]));
- if ((et->table->base & ERRCODE_MAX) == table_num) {
- table = et->table;
- goto found;
- }
- }
- dprintf (("scanning dynamic list for %x\n", table_num));
- for (det = et_list_dynamic; det != NULL; det = det->next) {
- dprintf (("\t%x = %s\n", det->table->base & ERRCODE_MAX,
- det->table->msgs[0]));
- if ((det->table->base & ERRCODE_MAX) == table_num) {
- table = det->table;
- goto found;
- }
- }
- goto no_table_found;
+ if (CALL_INIT_FUNCTION(com_err_initialize))
+ return 0;
+ merr = k5_mutex_lock(&et_list_lock);
+ if (merr)
+ goto oops;
+ dprintf (("scanning static list for %x\n", table_num));
+ for (et = _et_list; et != NULL; et = et->next) {
+ if (et->table == NULL)
+ continue;
+ dprintf (("\t%x = %s\n", et->table->base & ERRCODE_MAX,
+ et->table->msgs[0]));
+ if ((et->table->base & ERRCODE_MAX) == table_num) {
+ table = et->table;
+ goto found;
+ }
+ }
+ dprintf (("scanning dynamic list for %x\n", table_num));
+ for (det = et_list_dynamic; det != NULL; det = det->next) {
+ dprintf (("\t%x = %s\n", det->table->base & ERRCODE_MAX,
+ det->table->msgs[0]));
+ if ((det->table->base & ERRCODE_MAX) == table_num) {
+ table = det->table;
+ goto found;
+ }
+ }
+ goto no_table_found;
- found:
- k5_mutex_unlock(&et_list_lock);
- dprintf (("found it!\n"));
- /* This is the right table */
+found:
+ k5_mutex_unlock(&et_list_lock);
+ dprintf (("found it!\n"));
+ /* This is the right table */
- /* This could trip if int is 16 bits. */
- if ((unsigned long)(unsigned int)offset != offset)
- goto no_table_found;
+ /* This could trip if int is 16 bits. */
+ if ((unsigned long)(unsigned int)offset != offset)
+ goto no_table_found;
- if (table->n_msgs <= (unsigned int) offset)
- goto no_table_found;
+ if (table->n_msgs <= (unsigned int) offset)
+ goto no_table_found;
- return table->msgs[offset];
+ return table->msgs[offset];
- no_table_found:
- k5_mutex_unlock(&et_list_lock);
+no_table_found:
+ k5_mutex_unlock(&et_list_lock);
#if defined(_WIN32)
- /*
- * WinSock errors exist in the 10000 and 11000 ranges
- * but might not appear if WinSock is not initialized
- */
- if (code >= WSABASEERR && code < WSABASEERR + 1100) {
- table_num = 0;
- offset = code;
- divisor = WSABASEERR;
- }
+ /*
+ * WinSock errors exist in the 10000 and 11000 ranges
+ * but might not appear if WinSock is not initialized
+ */
+ if (code >= WSABASEERR && code < WSABASEERR + 1100) {
+ table_num = 0;
+ offset = code;
+ divisor = WSABASEERR;
+ }
#endif
#ifdef _WIN32
- {
- LPVOID msgbuf;
+ {
+ LPVOID msgbuf;
- if (! FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- NULL /* lpSource */,
- (DWORD) code,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR) &msgbuf,
- (DWORD) 0 /*sizeof(buffer)*/,
- NULL /* va_list */ )) {
- /*
- * WinSock errors exist in the 10000 and 11000 ranges
- * but might not appear if WinSock is not initialized
- */
- if (code >= WSABASEERR && code < WSABASEERR + 1100) {
- table_num = 0;
- offset = code;
- divisor = 10000;
- }
+ if (! FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL /* lpSource */,
+ (DWORD) code,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) &msgbuf,
+ (DWORD) 0 /*sizeof(buffer)*/,
+ NULL /* va_list */ )) {
+ /*
+ * WinSock errors exist in the 10000 and 11000 ranges
+ * but might not appear if WinSock is not initialized
+ */
+ if (code >= WSABASEERR && code < WSABASEERR + 1100) {
+ table_num = 0;
+ offset = code;
+ divisor = 10000;
+ }
- goto oops;
- } else {
- char *buffer;
- cp = get_thread_buffer();
- if (cp == NULL)
- return "Unknown error code";
- buffer = cp;
- strncpy(buffer, msgbuf, ET_EBUFSIZ);
- buffer[ET_EBUFSIZ-1] = '\0';
- cp = buffer + strlen(buffer) - 1;
- if (*cp == '\n') *cp-- = '\0';
- if (*cp == '\r') *cp-- = '\0';
- if (*cp == '.') *cp-- = '\0';
+ goto oops;
+ } else {
+ char *buffer;
+ cp = get_thread_buffer();
+ if (cp == NULL)
+ return "Unknown error code";
+ buffer = cp;
+ strncpy(buffer, msgbuf, ET_EBUFSIZ);
+ buffer[ET_EBUFSIZ-1] = '\0';
+ cp = buffer + strlen(buffer) - 1;
+ if (*cp == '\n') *cp-- = '\0';
+ if (*cp == '\r') *cp-- = '\0';
+ if (*cp == '.') *cp-- = '\0';
- LocalFree(msgbuf);
- return buffer;
- }
- }
+ LocalFree(msgbuf);
+ return buffer;
+ }
+ }
#endif
oops:
- cp = get_thread_buffer();
- if (cp == NULL)
- return "Unknown error code";
- cp1 = cp;
- strlcpy(cp, "Unknown code ", ET_EBUFSIZ);
- cp += sizeof("Unknown code ") - 1;
- if (table_num != 0L) {
- (void) error_table_name_r(table_num, cp);
- while (*cp != '\0')
- cp++;
- *cp++ = ' ';
- }
- while (divisor > 1) {
- if (started != 0 || offset >= divisor) {
- *cp++ = '0' + offset / divisor;
- offset %= divisor;
- started++;
- }
- divisor /= 10;
- }
- *cp++ = '0' + offset;
- *cp = '\0';
- return(cp1);
+ cp = get_thread_buffer();
+ if (cp == NULL)
+ return "Unknown error code";
+ cp1 = cp;
+ strlcpy(cp, "Unknown code ", ET_EBUFSIZ);
+ cp += sizeof("Unknown code ") - 1;
+ if (table_num != 0L) {
+ (void) error_table_name_r(table_num, cp);
+ while (*cp != '\0')
+ cp++;
+ *cp++ = ' ';
+ }
+ while (divisor > 1) {
+ if (started != 0 || offset >= divisor) {
+ *cp++ = '0' + offset / divisor;
+ offset %= divisor;
+ started++;
+ }
+ divisor /= 10;
+ }
+ *cp++ = '0' + offset;
+ *cp = '\0';
+ return(cp1);
}
/*@-incondefs@*/ /* _et_list is global on unix but not in header annotations */
errcode_t KRB5_CALLCONV
add_error_table(/*@dependent@*/ const struct error_table * et)
- /*@modifies _et_list,et_list_dynamic@*/
+/*@modifies _et_list,et_list_dynamic@*/
/*@=incondefs@*/
{
struct dynamic_et_list *del;
int merr;
if (CALL_INIT_FUNCTION(com_err_initialize))
- return 0;
+ return 0;
del = (struct dynamic_et_list *)malloc(sizeof(struct dynamic_et_list));
if (del == NULL)
- return ENOMEM;
+ return ENOMEM;
del->table = et;
merr = k5_mutex_lock(&et_list_lock);
if (merr) {
- free(del);
- return merr;
+ free(del);
+ return merr;
}
del->next = et_list_dynamic;
et_list_dynamic = del;
/*@-incondefs@*/ /* _et_list is global on unix but not in header annotations */
errcode_t KRB5_CALLCONV
remove_error_table(const struct error_table * et)
- /*@modifies _et_list,et_list_dynamic@*/
+/*@modifies _et_list,et_list_dynamic@*/
/*@=incondefs@*/
{
struct dynamic_et_list **del;
int merr;
if (CALL_INIT_FUNCTION(com_err_initialize))
- return 0;
+ return 0;
merr = k5_mutex_lock(&et_list_lock);
if (merr)
- return merr;
+ return merr;
/* Remove the entry that matches the error table instance. Prefer dynamic
entries, but if there are none, check for a static one too. */
for (del = &et_list_dynamic; *del; del = &(*del)->next)
- if ((*del)->table == et) {
- /*@only@*/ struct dynamic_et_list *old = *del;
- *del = old->next;
- free (old);
- return k5_mutex_unlock(&et_list_lock);
- }
+ if ((*del)->table == et) {
+ /*@only@*/ struct dynamic_et_list *old = *del;
+ *del = old->next;
+ free (old);
+ return k5_mutex_unlock(&et_list_lock);
+ }
for (el = &_et_list; *el; el = &(*el)->next)
- if ((*el)->table == et) {
- struct et_list *old = *el;
- *el = old->next;
- old->next = NULL;
- old->table = NULL;
- return k5_mutex_unlock(&et_list_lock);
- }
+ if ((*el)->table == et) {
+ struct et_list *old = *el;
+ *el = old->next;
+ old->next = NULL;
+ old->table = NULL;
+ return k5_mutex_unlock(&et_list_lock);
+ }
k5_mutex_unlock(&et_list_lock);
return ENOENT;
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 1988 by the Student Information Processing Board of the
* Massachusetts Institute of Technology.
/*@dependent@*/ const struct error_table *table;
};
-#define ERRCODE_RANGE 8 /* # of bits to shift table number */
-#define BITS_PER_CHAR 6 /* # bits to shift per character in name */
+#define ERRCODE_RANGE 8 /* # of bits to shift table number */
+#define BITS_PER_CHAR 6 /* # bits to shift per character in name */
#define ERRCODE_MAX 0xFFFFFFFFUL /* Mask for maximum error table */
extern /*@observer@*/ const char *error_table_name (unsigned long)
- /*@modifies internalState@*/;
+ /*@modifies internalState@*/;
extern const char *error_table_name_r (unsigned long,
- /*@out@*/ /*@returned@*/ char *outbuf)
- /*@modifies outbuf@*/;
+ /*@out@*/ /*@returned@*/ char *outbuf)
+ /*@modifies outbuf@*/;
#include "k5-thread.h"
extern k5_mutex_t com_err_hook_lock;
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 1997 by Massachusetts Institute of Technology
*
#include "error_table.h"
static const char char_set[] =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
const char *
error_table_name_r (unsigned long num,
- /*@out@*/ /*@returned@*/ char *outbuf)
- /*@modifies outbuf@*/
+ /*@out@*/ /*@returned@*/ char *outbuf)
+/*@modifies outbuf@*/
{
- long ch;
- int i;
- /*@out@*/ char *p;
+ long ch;
+ int i;
+ /*@out@*/ char *p;
- p = outbuf;
- num >>= ERRCODE_RANGE;
+ p = outbuf;
+ num >>= ERRCODE_RANGE;
- for (i = 3; i >= 0; i--) {
- ch = (num >> BITS_PER_CHAR * i) & ((1 << BITS_PER_CHAR) - 1);
- if (ch != 0)
- *p++ = char_set[ch-1];
- }
- *p = '\0';
- return(outbuf);
+ for (i = 3; i >= 0; i--) {
+ ch = (num >> BITS_PER_CHAR * i) & ((1 << BITS_PER_CHAR) - 1);
+ if (ch != 0)
+ *p++ = char_set[ch-1];
+ }
+ *p = '\0';
+ return(outbuf);
}
/*@observer@*/
const char * error_table_name(unsigned long num)
- /*@modifies internalState@*/
+/*@modifies internalState@*/
{
- static char buf[6];
+ static char buf[6];
- return error_table_name_r(num, buf);
+ return error_table_name_r(num, buf);
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 1997, 2008 by Massachusetts Institute of Technology
*
struct foobar * new_et;
if (!base || !count || !msgs)
- return 0;
+ return 0;
new_et = (struct foobar *) malloc(sizeof(struct foobar));
if (!new_et)
- return ENOMEM; /* oops */
+ return ENOMEM; /* oops */
new_et->etl.table = &new_et->et;
new_et->et.msgs = msgs;
new_et->et.base = base;
}
extern errcode_t KRB5_CALLCONV et_init(ectx)
- et_ctx *ectx;
+ et_ctx *ectx;
{
- struct et_context *ctx;
+ struct et_context *ctx;
- ctx = malloc(sizeof(struct et_context));
- if (!ctx)
- return ENOMEM;
- ctx->tables = 0;
- ctx->hook_func = 0;
- ctx->hook_func_data = 0;
+ ctx = malloc(sizeof(struct et_context));
+ if (!ctx)
+ return ENOMEM;
+ ctx->tables = 0;
+ ctx->hook_func = 0;
+ ctx->hook_func_data = 0;
- *ectx = ctx;
- return 0;
+ *ectx = ctx;
+ return 0;
}
extern void KRB5_CALLCONV et_shutdown(ectx)
- et_ctx ectx;
+ et_ctx ectx;
{
- struct et_list *p, *n;
-
- p = ectx->tables;
- while (p) {
- n = p->next;
- free(p);
- p = n;
- }
- free(ectx);
+ struct et_list *p, *n;
+
+ p = ectx->tables;
+ while (p) {
+ n = p->next;
+ free(p);
+ p = n;
+ }
+ free(ectx);
}
extern errcode_t KRB5_CALLCONV et_add_error_table(ectx, tbl)
- et_ctx ectx;
- struct error_table *tbl;
+ et_ctx ectx;
+ struct error_table *tbl;
{
- struct et_list *e;
+ struct et_list *e;
- e = malloc(sizeof(struct et_list));
- if (!e)
- return ENOMEM;
+ e = malloc(sizeof(struct et_list));
+ if (!e)
+ return ENOMEM;
- e->table = tbl;
- e->next = ectx->tables;
- ectx->tables = e;
+ e->table = tbl;
+ e->next = ectx->tables;
+ ectx->tables = e;
- return 0;
+ return 0;
}
#endif
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* internal include file for com_err package
*/
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
-Copyright 1987, 1988 by the Student Information Processing Board
- of the Massachusetts Institute of Technology
+ Copyright 1987, 1988 by the Student Information Processing Board
+ of the Massachusetts Institute of Technology
-Permission to use, copy, modify, and distribute this software
-and its documentation for any purpose and without fee is
-hereby granted, provided that the above copyright notice
-appear in all copies and that both that copyright notice and
-this permission notice appear in supporting documentation,
-and that the names of M.I.T. and the M.I.T. S.I.P.B. not be
-used in advertising or publicity pertaining to distribution
-of the software without specific, written prior permission.
-Furthermore if you modify this software you must label
-your software as modified software and not distribute it in such a
-fashion that it might be confused with the original M.I.T. software.
-M.I.T. and the M.I.T. S.I.P.B. make no representations about
-the suitability of this software for any purpose. It is
-provided "as is" without express or implied warranty.
+ Permission to use, copy, modify, and distribute this software
+ and its documentation for any purpose and without fee is
+ hereby granted, provided that the above copyright notice
+ appear in all copies and that both that copyright notice and
+ this permission notice appear in supporting documentation,
+ and that the names of M.I.T. and the M.I.T. S.I.P.B. not be
+ used in advertising or publicity pertaining to distribution
+ of the software without specific, written prior permission.
+ Furthermore if you modify this software you must label
+ your software as modified software and not distribute it in such a
+ fashion that it might be confused with the original M.I.T. software.
+ M.I.T. and the M.I.T. S.I.P.B. make no representations about
+ the suitability of this software for any purpose. It is
+ provided "as is" without express or implied warranty.
*/
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "et1.h"
#include "et2.h"
-int misc_err, known_err; /* known_err is err in whether or not
+int misc_err, known_err; /* known_err is err in whether or not
table is 'known' to library */
int fail;
snprintf (buffy, sizeof(buffy), "error table %d message %d", table, msgno);
if (0 == strcmp (buffy, msg)) {
- if (!known) {
- known_err++;
- }
- return;
+ if (!known) {
+ known_err++;
+ }
+ return;
}
snprintf (buffy, sizeof(buffy), "Unknown code et%d %d", table, msgno);
if (!strcmp (buffy, msg)) {
- if (known)
- known_err++;
- return;
+ if (known)
+ known_err++;
+ return;
}
printf ("error code %ld got unrecognized message '%s',\n"
- "should have been table %d message %d\n",
- (long) code, msg, table, msgno);
+ "should have been table %d message %d\n",
+ (long) code, msg, table, msgno);
misc_err++;
}
static void
try_table (int table, int known, int lineno,
- errcode_t c0, errcode_t c1, errcode_t c2)
+ errcode_t c0, errcode_t c1, errcode_t c2)
{
try_one (c0, known, table, 0);
try_one (c1, known, table, 1);
try_one (c2, known, table, 2);
if (misc_err != 0 || known_err != 0) {
- fail++;
- if (known_err)
- printf ("table list error from line %d, table %d\n", lineno,
- table);
- if (misc_err)
- printf ("misc errors from line %d table %d\n", lineno, table);
- misc_err = known_err = 0;
+ fail++;
+ if (known_err)
+ printf ("table list error from line %d, table %d\n", lineno,
+ table);
+ if (misc_err)
+ printf ("misc errors from line %d table %d\n", lineno, table);
+ misc_err = known_err = 0;
}
}
err = pthread_create(&t, 0, run, 0);
if (err) {
- fprintf(stderr, "pthread_create error: %s\n", strerror(err));
- exit(1);
+ fprintf(stderr, "pthread_create error: %s\n", strerror(err));
+ exit(1);
}
err = pthread_join(t, &t_retval);
if (err) {
- fprintf(stderr, "pthread_join error: %s\n", strerror(err));
- exit(1);
+ fprintf(stderr, "pthread_join error: %s\n", strerror(err));
+ exit(1);
}
return fail;
#else
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#include <stdio.h>
#include <errno.h>
#include "com_err.h"
int main()
{
- printf("Before initiating error table:\n\n");
+ printf("Before initiating error table:\n\n");
#ifndef EXPORT_LIST
- printf("Table name '%s'\n", error_table_name(KRB_MK_AP_TGTEXP));
- printf("UNIX name '%s'\n", error_table_name(EPERM));
+ printf("Table name '%s'\n", error_table_name(KRB_MK_AP_TGTEXP));
+ printf("UNIX name '%s'\n", error_table_name(EPERM));
#endif
- printf("Msg TGT-expired is '%s'\n", error_message(KRB_MK_AP_TGTEXP));
- printf("Msg EPERM is '%s'\n", error_message(EPERM));
- printf("Msg FOO_ERR is '%s'\n", error_message(FOO_ERR));
- printf("Msg 1002 is '%s'\n", error_message (1002));
+ printf("Msg TGT-expired is '%s'\n", error_message(KRB_MK_AP_TGTEXP));
+ printf("Msg EPERM is '%s'\n", error_message(EPERM));
+ printf("Msg FOO_ERR is '%s'\n", error_message(FOO_ERR));
+ printf("Msg 1002 is '%s'\n", error_message (1002));
#ifdef HAVE_SYS_ERRLIST
- printf("Msg {sys_nerr-1} is '%s'\n", error_message(sys_nerr-1));
- printf("Msg {sys_nerr} is '%s'\n", error_message(sys_nerr));
+ printf("Msg {sys_nerr-1} is '%s'\n", error_message(sys_nerr-1));
+ printf("Msg {sys_nerr} is '%s'\n", error_message(sys_nerr));
#endif
- printf("Msg 0 is '%s'\n", error_message(0));
+ printf("Msg 0 is '%s'\n", error_message(0));
- printf("With 0: tgt-expired -> %s\n", error_message(KRB_MK_AP_TGTEXP));
+ printf("With 0: tgt-expired -> %s\n", error_message(KRB_MK_AP_TGTEXP));
- initialize_krb_error_table();
+ initialize_krb_error_table();
#ifndef EXPORT_LIST
- printf("KRB error table initialized: base %ld (%s), name %s\n",
- ERROR_TABLE_BASE_krb, error_message(ERROR_TABLE_BASE_krb),
- error_table_name(ERROR_TABLE_BASE_krb));
+ printf("KRB error table initialized: base %ld (%s), name %s\n",
+ ERROR_TABLE_BASE_krb, error_message(ERROR_TABLE_BASE_krb),
+ error_table_name(ERROR_TABLE_BASE_krb));
#else
- printf("KRB error table initialized: base %ld (%s)\n",
- ERROR_TABLE_BASE_krb, error_message(ERROR_TABLE_BASE_krb));
+ printf("KRB error table initialized: base %ld (%s)\n",
+ ERROR_TABLE_BASE_krb, error_message(ERROR_TABLE_BASE_krb));
#endif
- add_error_table(&et_krb_error_table);
- printf("With krb: tgt-expired -> %s\n",
- error_message(KRB_MK_AP_TGTEXP));
+ add_error_table(&et_krb_error_table);
+ printf("With krb: tgt-expired -> %s\n",
+ error_message(KRB_MK_AP_TGTEXP));
- add_error_table(&et_quux_error_table);
+ add_error_table(&et_quux_error_table);
#ifndef EXPORT_LIST
- printf("QUUX error table initialized: base %ld (%s), name %s\n",
- ERROR_TABLE_BASE_quux, error_message(ERROR_TABLE_BASE_quux),
- error_table_name(ERROR_TABLE_BASE_quux));
+ printf("QUUX error table initialized: base %ld (%s), name %s\n",
+ ERROR_TABLE_BASE_quux, error_message(ERROR_TABLE_BASE_quux),
+ error_table_name(ERROR_TABLE_BASE_quux));
#else
- printf("QUUX error table initialized: base %ld (%s)\n",
- ERROR_TABLE_BASE_quux, error_message(ERROR_TABLE_BASE_quux));
+ printf("QUUX error table initialized: base %ld (%s)\n",
+ ERROR_TABLE_BASE_quux, error_message(ERROR_TABLE_BASE_quux));
#endif
- printf("Msg for TGT-expired is '%s'\n",
- error_message(KRB_MK_AP_TGTEXP));
+ printf("Msg for TGT-expired is '%s'\n",
+ error_message(KRB_MK_AP_TGTEXP));
#ifdef HAVE_SYS_ERRLIST
- printf("Msg {sys_nerr-1} is '%s'\n", error_message(sys_nerr-1));
+ printf("Msg {sys_nerr-1} is '%s'\n", error_message(sys_nerr-1));
#endif
- printf("Msg FOO_ERR is '%s'\n", error_message(FOO_ERR));
- printf("Msg KRB_SKDC_CANT is '%s'\n",
- error_message(KRB_SKDC_CANT));
- printf("Msg 1e6 (8B 64) is '%s'\n", error_message(1000000));
- printf("\n\nCOM_ERR tests:\n");
- com_err("whoami", FOO_ERR, (char *)NULL);
- com_err("whoami", FOO_ERR, " -- message goes %s", "here");
- com_err("whoami", 0, (char *)0);
- com_err("whoami", 0, "error number %d\n", 0);
- return 0;
+ printf("Msg FOO_ERR is '%s'\n", error_message(FOO_ERR));
+ printf("Msg KRB_SKDC_CANT is '%s'\n",
+ error_message(KRB_SKDC_CANT));
+ printf("Msg 1e6 (8B 64) is '%s'\n", error_message(1000000));
+ printf("\n\nCOM_ERR tests:\n");
+ com_err("whoami", FOO_ERR, (char *)NULL);
+ com_err("whoami", FOO_ERR, " -- message goes %s", "here");
+ com_err("whoami", 0, (char *)0);
+ com_err("whoami", 0, "error number %d\n", 0);
+ return 0;
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* util/exitsleep.c
*
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* $Header$
*
/* global service ports and mutex to protect it */
static k5_mutex_t g_service_ports_mutex = K5_MUTEX_PARTIAL_INITIALIZER;
static k5_ipc_service_port g_service_ports[KIPC_SERVICE_COUNT] = {
-{ "edu.mit.Kerberos.CCacheServer", MACH_PORT_NULL },
-{ "edu.mit.Kerberos.KerberosAgent", MACH_PORT_NULL } };
+ { "edu.mit.Kerberos.CCacheServer", MACH_PORT_NULL },
+ { "edu.mit.Kerberos.KerberosAgent", MACH_PORT_NULL } };
/* ------------------------------------------------------------------------ */
/* initializer for k5_ipc_request_port to fill in server names in TLS */
static const char *k5_ipc_known_services[KIPC_SERVICE_COUNT] = {
-"edu.mit.Kerberos.CCacheServer",
-"edu.mit.Kerberos.KerberosAgent" };
+ "edu.mit.Kerberos.CCacheServer",
+ "edu.mit.Kerberos.KerberosAgent" };
/* ------------------------------------------------------------------------ */
if (!err) {
if (in_inl_replyCnt) {
err = krb5int_ipc_stream_write (cinfo->reply_stream,
- in_inl_reply, in_inl_replyCnt);
+ in_inl_reply, in_inl_replyCnt);
} else if (in_ool_replyCnt) {
err = krb5int_ipc_stream_write (cinfo->reply_stream,
- in_ool_reply, in_ool_replyCnt);
+ in_ool_reply, in_ool_replyCnt);
} else {
err = EINVAL;
done = 1;
/* Because we use ",dealloc" ool_request will be freed by mach.
- * Don't double free it. */
+ * Don't double free it. */
ool_request = NULL;
ool_request_length = 0;
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* $Header$
*
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* $Header$
*
if (!err) {
len = CFStringGetMaximumSizeForEncoding (CFStringGetLength (id_string),
- kCFStringEncodingUTF8) + 1;
+ kCFStringEncodingUTF8) + 1;
}
if (!err) {
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* $Header$
*
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/* $Copyright:
-*
-* Copyright 2004-2006 by the Massachusetts Institute of Technology.
-*
-* All rights reserved.
-*
-* Export of this software from the United States of America may require a
-* specific license from the United States Government. It is the
-* responsibility of any person or organization contemplating export to
-* obtain such a license before exporting.
-*
-* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute
-* this software and its documentation for any purpose and without fee is
-* hereby granted, provided that the above copyright notice appear in all
-* copies and that both that copyright notice and this permission notice
-* appear in supporting documentation, and that the name of M.I.T. not be
-* used in advertising or publicity pertaining to distribution of the
-* software without specific, written prior permission. Furthermore if you
-* modify this software you must label your software as modified software
-* and not distribute it in such a fashion that it might be confused with
-* the original MIT software. M.I.T. makes no representations about the
-* suitability of this software for any purpose. It is provided "as is"
-* without express or implied warranty.
-*
-* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
-* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
-* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-*
-* Individual source code files are copyright MIT, Cygnus Support,
-* OpenVision, Oracle, Sun Soft, FundsXpress, and others.
-*
-* Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira,
-* and Zephyr are trademarks of the Massachusetts Institute of Technology
-* (MIT). No commercial use of these trademarks may be made without prior
-* written permission of MIT.
-*
-* "Commercial use" means use of a name in a product or other for-profit
-* manner. It does NOT prevent a commercial firm from referring to the MIT
-* trademarks in order to convey information (although in doing so,
-* recognition of their trademark status should be given).
-* $
-*/
+ *
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.
+ *
+ * All rights reserved.
+ *
+ * Export of this software from the United States of America may require a
+ * specific license from the United States Government. It is the
+ * responsibility of any person or organization contemplating export to
+ * obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute
+ * this software and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice appear in all
+ * copies and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of M.I.T. not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission. Furthermore if you
+ * modify this software you must label your software as modified software
+ * and not distribute it in such a fashion that it might be confused with
+ * the original MIT software. M.I.T. makes no representations about the
+ * suitability of this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
+ * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Individual source code files are copyright MIT, Cygnus Support,
+ * OpenVision, Oracle, Sun Soft, FundsXpress, and others.
+ *
+ * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira,
+ * and Zephyr are trademarks of the Massachusetts Institute of Technology
+ * (MIT). No commercial use of these trademarks may be made without prior
+ * written permission of MIT.
+ *
+ * "Commercial use" means use of a name in a product or other for-profit
+ * manner. It does NOT prevent a commercial firm from referring to the MIT
+ * trademarks in order to convey information (although in doing so,
+ * recognition of their trademark status should be given).
+ * $
+ */
#ifndef K5_MIG_TYPES_H
#define K5_MIG_TYPES_H
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* argv_parse.c --- utility function for parsing a string into a
- * argc, argv array.
+ * argc, argv array.
*
* This file defines a function argv_parse() which parsing a
* passed-in string, handling double quotes and backslashes, and
#include <string.h>
#include "argv_parse.h"
-#define STATE_WHITESPACE 1
-#define STATE_TOKEN 2
-#define STATE_QUOTED 3
+#define STATE_WHITESPACE 1
+#define STATE_TOKEN 2
+#define STATE_QUOTED 3
/*
* Returns 0 on success, -1 on failure.
*/
int argv_parse(char *in_buf, int *ret_argc, char ***ret_argv)
{
- int argc = 0, max_argc = 0;
- char **argv, **new_argv, *buf, ch;
- char *cp = 0, *outcp = 0;
- int state = STATE_WHITESPACE;
+ int argc = 0, max_argc = 0;
+ char **argv, **new_argv, *buf, ch;
+ char *cp = 0, *outcp = 0;
+ int state = STATE_WHITESPACE;
- buf = malloc(strlen(in_buf)+1);
- if (!buf)
- return -1;
+ buf = malloc(strlen(in_buf)+1);
+ if (!buf)
+ return -1;
- max_argc = 0; argc = 0; argv = 0;
- outcp = buf;
- for (cp = in_buf; (ch = *cp); cp++) {
- if (state == STATE_WHITESPACE) {
- if (isspace((int) ch))
- continue;
- /* Not whitespace, so start a new token */
- state = STATE_TOKEN;
- if (argc >= max_argc) {
- max_argc += 3;
- new_argv = realloc(argv,
- (max_argc+1)*sizeof(char *));
- if (!new_argv) {
- if (argv) free(argv);
- free(buf);
- return -1;
- }
- argv = new_argv;
- }
- argv[argc++] = outcp;
- }
- if (state == STATE_QUOTED) {
- if (ch == '"')
- state = STATE_TOKEN;
- else
- *outcp++ = ch;
- continue;
- }
- /* Must be processing characters in a word */
- if (isspace((int) ch)) {
- /*
- * Terminate the current word and start
- * looking for the beginning of the next word.
- */
- *outcp++ = 0;
- state = STATE_WHITESPACE;
- continue;
- }
- if (ch == '"') {
- state = STATE_QUOTED;
- continue;
- }
- if (ch == '\\') {
- ch = *++cp;
- switch (ch) {
- case '\0':
- ch = '\\'; cp--; break;
- case 'n':
- ch = '\n'; break;
- case 't':
- ch = '\t'; break;
- case 'b':
- ch = '\b'; break;
- }
- }
- *outcp++ = ch;
- }
- if (state != STATE_WHITESPACE)
- *outcp++ = '\0';
- if (argv == 0) {
- argv = malloc(sizeof(char *));
- free(buf);
- }
- argv[argc] = 0;
- if (ret_argc)
- *ret_argc = argc;
- if (ret_argv)
- *ret_argv = argv;
- return 0;
+ max_argc = 0; argc = 0; argv = 0;
+ outcp = buf;
+ for (cp = in_buf; (ch = *cp); cp++) {
+ if (state == STATE_WHITESPACE) {
+ if (isspace((int) ch))
+ continue;
+ /* Not whitespace, so start a new token */
+ state = STATE_TOKEN;
+ if (argc >= max_argc) {
+ max_argc += 3;
+ new_argv = realloc(argv,
+ (max_argc+1)*sizeof(char *));
+ if (!new_argv) {
+ if (argv) free(argv);
+ free(buf);
+ return -1;
+ }
+ argv = new_argv;
+ }
+ argv[argc++] = outcp;
+ }
+ if (state == STATE_QUOTED) {
+ if (ch == '"')
+ state = STATE_TOKEN;
+ else
+ *outcp++ = ch;
+ continue;
+ }
+ /* Must be processing characters in a word */
+ if (isspace((int) ch)) {
+ /*
+ * Terminate the current word and start
+ * looking for the beginning of the next word.
+ */
+ *outcp++ = 0;
+ state = STATE_WHITESPACE;
+ continue;
+ }
+ if (ch == '"') {
+ state = STATE_QUOTED;
+ continue;
+ }
+ if (ch == '\\') {
+ ch = *++cp;
+ switch (ch) {
+ case '\0':
+ ch = '\\'; cp--; break;
+ case 'n':
+ ch = '\n'; break;
+ case 't':
+ ch = '\t'; break;
+ case 'b':
+ ch = '\b'; break;
+ }
+ }
+ *outcp++ = ch;
+ }
+ if (state != STATE_WHITESPACE)
+ *outcp++ = '\0';
+ if (argv == 0) {
+ argv = malloc(sizeof(char *));
+ free(buf);
+ }
+ argv[argc] = 0;
+ if (ret_argc)
+ *ret_argc = argc;
+ if (ret_argv)
+ *ret_argv = argv;
+ return 0;
}
void argv_free(char **argv)
{
- if (*argv)
- free(*argv);
- free(argv);
+ if (*argv)
+ free(*argv);
+ free(argv);
}
#ifdef DEBUG
int main(int argc, char **argv)
{
- int ac, ret;
- char **av, **cpp;
- char buf[256];
+ int ac, ret;
+ char **av, **cpp;
+ char buf[256];
- while (!feof(stdin)) {
- if (fgets(buf, sizeof(buf), stdin) == NULL)
- break;
- ret = argv_parse(buf, &ac, &av);
- if (ret != 0) {
- printf("Argv_parse returned %d!\n", ret);
- continue;
- }
- printf("Argv_parse returned %d arguments...\n", ac);
- for (cpp = av; *cpp; cpp++) {
- if (cpp != av)
- printf(", ");
- printf("'%s'", *cpp);
- }
- printf("\n");
- argv_free(av);
- }
- exit(0);
+ while (!feof(stdin)) {
+ if (fgets(buf, sizeof(buf), stdin) == NULL)
+ break;
+ ret = argv_parse(buf, &ac, &av);
+ if (ret != 0) {
+ printf("Argv_parse returned %d!\n", ret);
+ continue;
+ }
+ printf("Argv_parse returned %d arguments...\n", ac);
+ for (cpp = av; *cpp; cpp++) {
+ if (cpp != av)
+ printf(", ");
+ printf("'%s'", *cpp);
+ }
+ printf("\n");
+ argv_free(av);
+ }
+ exit(0);
}
#endif /* DEBUG */
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* argv_parse.h --- header file for the argv parser.
*
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* prof_FSp_glue.c --- Deprecated FSSpec functions. Mac-only.
*/
errcode_t KRB5_CALLCONV
FSp_profile_init(files, ret_profile)
- const FSSpec* files;
- profile_t *ret_profile;
+ const FSSpec* files;
+ profile_t *ret_profile;
{
unsigned int fileCount = 0;
const FSSpec *nextSpec;
errcode_t KRB5_CALLCONV
FSp_profile_init_path(files, ret_profile)
- const FSSpec* files;
- profile_t *ret_profile;
+ const FSSpec* files;
+ profile_t *ret_profile;
{
return FSp_profile_init (files, ret_profile);
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* prof_file.c ---- routines that manipulate an individual profile file.
*/
#include "k5-platform.h"
struct global_shared_profile_data {
- /* This is the head of the global list of shared trees */
- prf_data_t trees;
- /* Lock for above list. */
- k5_mutex_t mutex;
+ /* This is the head of the global list of shared trees */
+ prf_data_t trees;
+ /* Lock for above list. */
+ k5_mutex_t mutex;
};
-#define g_shared_trees (krb5int_profile_shared_data.trees)
-#define g_shared_trees_mutex (krb5int_profile_shared_data.mutex)
+#define g_shared_trees (krb5int_profile_shared_data.trees)
+#define g_shared_trees_mutex (krb5int_profile_shared_data.mutex)
static struct global_shared_profile_data krb5int_profile_shared_data = {
0,
{
if (! INITIALIZER_RAN(profile_library_initializer) || PROGRAM_EXITING()) {
#ifdef SHOW_INITFINI_FUNCS
- printf("profile_library_finalizer: skipping\n");
+ printf("profile_library_finalizer: skipping\n");
#endif
- return;
+ return;
}
#ifdef SHOW_INITFINI_FUNCS
printf("profile_library_finalizer\n");
#if 0
-#define scan_shared_trees_locked() \
- { \
- prf_data_t d; \
- k5_mutex_assert_locked(&g_shared_trees_mutex); \
- for (d = g_shared_trees; d; d = d->next) { \
- assert(d->magic == PROF_MAGIC_FILE_DATA); \
- assert((d->flags & PROFILE_FILE_SHARED) != 0); \
- assert(d->filespec[0] != 0); \
- assert(d->fslen <= 1000); /* XXX */ \
- assert(d->filespec[d->fslen] == 0); \
- assert(d->fslen = strlen(d->filespec)); \
- assert(d->root != NULL); \
- } \
- }
-
-#define scan_shared_trees_unlocked() \
- { \
- int r; \
- r = k5_mutex_lock(&g_shared_trees_mutex); \
- assert (r == 0); \
- scan_shared_trees_locked(); \
- k5_mutex_unlock(&g_shared_trees_mutex); \
- }
+#define scan_shared_trees_locked() \
+ { \
+ prf_data_t d; \
+ k5_mutex_assert_locked(&g_shared_trees_mutex); \
+ for (d = g_shared_trees; d; d = d->next) { \
+ assert(d->magic == PROF_MAGIC_FILE_DATA); \
+ assert((d->flags & PROFILE_FILE_SHARED) != 0); \
+ assert(d->filespec[0] != 0); \
+ assert(d->fslen <= 1000); /* XXX */ \
+ assert(d->filespec[d->fslen] == 0); \
+ assert(d->fslen = strlen(d->filespec)); \
+ assert(d->root != NULL); \
+ } \
+ }
+
+#define scan_shared_trees_unlocked() \
+ { \
+ int r; \
+ r = k5_mutex_lock(&g_shared_trees_mutex); \
+ assert (r == 0); \
+ scan_shared_trees_locked(); \
+ k5_mutex_unlock(&g_shared_trees_mutex); \
+ }
#else
-#define scan_shared_trees_locked() { ; }
-#define scan_shared_trees_unlocked() { ; }
+#define scan_shared_trees_locked() { ; }
+#define scan_shared_trees_unlocked() { ; }
#endif
static int rw_access(const_profile_filespec_t filespec)
{
#ifdef HAVE_ACCESS
- if (access(filespec, W_OK) == 0)
- return 1;
- else
- return 0;
+ if (access(filespec, W_OK) == 0)
+ return 1;
+ else
+ return 0;
#else
- /*
- * We're on a substandard OS that doesn't support access. So
- * we kludge a test using stdio routines, and hope fopen
- * checks the r/w permissions.
- */
- FILE *f;
-
- f = fopen(filespec, "r+");
- if (f) {
- fclose(f);
- return 1;
- }
- return 0;
+ /*
+ * We're on a substandard OS that doesn't support access. So
+ * we kludge a test using stdio routines, and hope fopen
+ * checks the r/w permissions.
+ */
+ FILE *f;
+
+ f = fopen(filespec, "r+");
+ if (f) {
+ fclose(f);
+ return 1;
+ }
+ return 0;
#endif
}
static int r_access(const_profile_filespec_t filespec)
{
#ifdef HAVE_ACCESS
- if (access(filespec, R_OK) == 0)
- return 1;
- else
- return 0;
+ if (access(filespec, R_OK) == 0)
+ return 1;
+ else
+ return 0;
#else
- /*
- * We're on a substandard OS that doesn't support access. So
- * we kludge a test using stdio routines, and hope fopen
- * checks the r/w permissions.
- */
- FILE *f;
-
- f = fopen(filespec, "r");
- if (f) {
- fclose(f);
- return 1;
- }
- return 0;
+ /*
+ * We're on a substandard OS that doesn't support access. So
+ * we kludge a test using stdio routines, and hope fopen
+ * checks the r/w permissions.
+ */
+ FILE *f;
+
+ f = fopen(filespec, "r");
+ if (f) {
+ fclose(f);
+ return 1;
+ }
+ return 0;
#endif
}
slen = offsetof(struct _prf_data_t, filespec);
len = slen + flen + 1;
if (len < sizeof(struct _prf_data_t))
- len = sizeof(struct _prf_data_t);
+ len = sizeof(struct _prf_data_t);
d = malloc(len);
if (d == NULL)
- return NULL;
+ return NULL;
memset(d, 0, len);
fcopy = (char *) d + slen;
assert(fcopy == d->filespec);
}
errcode_t profile_open_file(const_profile_filespec_t filespec,
- prf_file_t *ret_prof)
+ prf_file_t *ret_prof)
{
- prf_file_t prf;
- errcode_t retval;
- char *home_env = 0;
- prf_data_t data;
- char *expanded_filename;
-
- retval = CALL_INIT_FUNCTION(profile_library_initializer);
- if (retval)
- return retval;
-
- scan_shared_trees_unlocked();
-
- prf = malloc(sizeof(struct _prf_file_t));
- if (!prf)
- return ENOMEM;
- memset(prf, 0, sizeof(struct _prf_file_t));
- prf->magic = PROF_MAGIC_FILE;
-
- if (filespec[0] == '~' && filespec[1] == '/') {
- home_env = getenv("HOME");
+ prf_file_t prf;
+ errcode_t retval;
+ char *home_env = 0;
+ prf_data_t data;
+ char *expanded_filename;
+
+ retval = CALL_INIT_FUNCTION(profile_library_initializer);
+ if (retval)
+ return retval;
+
+ scan_shared_trees_unlocked();
+
+ prf = malloc(sizeof(struct _prf_file_t));
+ if (!prf)
+ return ENOMEM;
+ memset(prf, 0, sizeof(struct _prf_file_t));
+ prf->magic = PROF_MAGIC_FILE;
+
+ if (filespec[0] == '~' && filespec[1] == '/') {
+ home_env = getenv("HOME");
#ifdef HAVE_PWD_H
- if (home_env == NULL) {
- uid_t uid;
- struct passwd *pw, pwx;
- char pwbuf[BUFSIZ];
-
- uid = getuid();
- if (!k5_getpwuid_r(uid, &pwx, pwbuf, sizeof(pwbuf), &pw)
- && pw != NULL && pw->pw_dir[0] != 0)
- home_env = pw->pw_dir;
- }
+ if (home_env == NULL) {
+ uid_t uid;
+ struct passwd *pw, pwx;
+ char pwbuf[BUFSIZ];
+
+ uid = getuid();
+ if (!k5_getpwuid_r(uid, &pwx, pwbuf, sizeof(pwbuf), &pw)
+ && pw != NULL && pw->pw_dir[0] != 0)
+ home_env = pw->pw_dir;
+ }
#endif
- }
- if (home_env) {
- if (asprintf(&expanded_filename, "%s%s", home_env,
- filespec + 1) < 0)
- expanded_filename = 0;
- } else
- expanded_filename = strdup(filespec);
- if (expanded_filename == 0) {
- free(prf);
- return ENOMEM;
- }
-
- retval = k5_mutex_lock(&g_shared_trees_mutex);
- if (retval) {
- free(expanded_filename);
- free(prf);
- scan_shared_trees_unlocked();
- return retval;
- }
- scan_shared_trees_locked();
- for (data = g_shared_trees; data; data = data->next) {
- if (!strcmp(data->filespec, expanded_filename)
- /* Check that current uid has read access. */
- && r_access(data->filespec))
- break;
- }
- if (data) {
- data->refcount++;
- (void) k5_mutex_unlock(&g_shared_trees_mutex);
- retval = profile_update_file_data(data);
- free(expanded_filename);
- prf->data = data;
- *ret_prof = prf;
- scan_shared_trees_unlocked();
- return retval;
- }
- (void) k5_mutex_unlock(&g_shared_trees_mutex);
- data = profile_make_prf_data(expanded_filename);
- if (data == NULL) {
- free(prf);
- free(expanded_filename);
- return ENOMEM;
- }
- free(expanded_filename);
- prf->data = data;
-
- retval = k5_mutex_init(&data->lock);
- if (retval) {
- free(data);
- free(prf);
- return retval;
- }
-
- retval = profile_update_file(prf);
- if (retval) {
- profile_close_file(prf);
- return retval;
- }
-
- retval = k5_mutex_lock(&g_shared_trees_mutex);
- if (retval) {
- profile_close_file(prf);
- scan_shared_trees_unlocked();
- return retval;
- }
- scan_shared_trees_locked();
- data->flags |= PROFILE_FILE_SHARED;
- data->next = g_shared_trees;
- g_shared_trees = data;
- scan_shared_trees_locked();
- (void) k5_mutex_unlock(&g_shared_trees_mutex);
-
- *ret_prof = prf;
- return 0;
+ }
+ if (home_env) {
+ if (asprintf(&expanded_filename, "%s%s", home_env,
+ filespec + 1) < 0)
+ expanded_filename = 0;
+ } else
+ expanded_filename = strdup(filespec);
+ if (expanded_filename == 0) {
+ free(prf);
+ return ENOMEM;
+ }
+
+ retval = k5_mutex_lock(&g_shared_trees_mutex);
+ if (retval) {
+ free(expanded_filename);
+ free(prf);
+ scan_shared_trees_unlocked();
+ return retval;
+ }
+ scan_shared_trees_locked();
+ for (data = g_shared_trees; data; data = data->next) {
+ if (!strcmp(data->filespec, expanded_filename)
+ /* Check that current uid has read access. */
+ && r_access(data->filespec))
+ break;
+ }
+ if (data) {
+ data->refcount++;
+ (void) k5_mutex_unlock(&g_shared_trees_mutex);
+ retval = profile_update_file_data(data);
+ free(expanded_filename);
+ prf->data = data;
+ *ret_prof = prf;
+ scan_shared_trees_unlocked();
+ return retval;
+ }
+ (void) k5_mutex_unlock(&g_shared_trees_mutex);
+ data = profile_make_prf_data(expanded_filename);
+ if (data == NULL) {
+ free(prf);
+ free(expanded_filename);
+ return ENOMEM;
+ }
+ free(expanded_filename);
+ prf->data = data;
+
+ retval = k5_mutex_init(&data->lock);
+ if (retval) {
+ free(data);
+ free(prf);
+ return retval;
+ }
+
+ retval = profile_update_file(prf);
+ if (retval) {
+ profile_close_file(prf);
+ return retval;
+ }
+
+ retval = k5_mutex_lock(&g_shared_trees_mutex);
+ if (retval) {
+ profile_close_file(prf);
+ scan_shared_trees_unlocked();
+ return retval;
+ }
+ scan_shared_trees_locked();
+ data->flags |= PROFILE_FILE_SHARED;
+ data->next = g_shared_trees;
+ g_shared_trees = data;
+ scan_shared_trees_locked();
+ (void) k5_mutex_unlock(&g_shared_trees_mutex);
+
+ *ret_prof = prf;
+ return 0;
}
errcode_t profile_update_file_data_locked(prf_data_t data)
{
- errcode_t retval;
+ errcode_t retval;
#ifdef HAVE_STAT
- struct stat st;
- unsigned long frac;
- time_t now;
+ struct stat st;
+ unsigned long frac;
+ time_t now;
#endif
- FILE *f;
+ FILE *f;
#ifdef HAVE_STAT
- now = time(0);
- if (now == data->last_stat && data->root != NULL) {
- return 0;
- }
- if (stat(data->filespec, &st)) {
- return errno;
- }
- data->last_stat = now;
+ now = time(0);
+ if (now == data->last_stat && data->root != NULL) {
+ return 0;
+ }
+ if (stat(data->filespec, &st)) {
+ return errno;
+ }
+ data->last_stat = now;
#if defined HAVE_STRUCT_STAT_ST_MTIMENSEC
- frac = st.st_mtimensec;
+ frac = st.st_mtimensec;
#elif defined HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
- frac = st.st_mtimespec.tv_nsec;
+ frac = st.st_mtimespec.tv_nsec;
#elif defined HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
- frac = st.st_mtim.tv_nsec;
+ frac = st.st_mtim.tv_nsec;
#else
- frac = 0;
+ frac = 0;
#endif
- if (st.st_mtime == data->timestamp
- && frac == data->frac_ts
- && data->root != NULL) {
- return 0;
- }
- if (data->root) {
- profile_free_node(data->root);
- data->root = 0;
- }
- if (data->comment) {
- free(data->comment);
- data->comment = 0;
- }
+ if (st.st_mtime == data->timestamp
+ && frac == data->frac_ts
+ && data->root != NULL) {
+ return 0;
+ }
+ if (data->root) {
+ profile_free_node(data->root);
+ data->root = 0;
+ }
+ if (data->comment) {
+ free(data->comment);
+ data->comment = 0;
+ }
#else
- /*
- * If we don't have the stat() call, assume that our in-core
- * memory image is correct. That is, we won't reread the
- * profile file if it changes.
- */
- if (data->root) {
- return 0;
- }
+ /*
+ * If we don't have the stat() call, assume that our in-core
+ * memory image is correct. That is, we won't reread the
+ * profile file if it changes.
+ */
+ if (data->root) {
+ return 0;
+ }
#endif
- errno = 0;
- f = fopen(data->filespec, "r");
- if (f == NULL) {
- retval = errno;
- if (retval == 0)
- retval = ENOENT;
- return retval;
- }
- set_cloexec_file(f);
- data->upd_serial++;
- data->flags &= PROFILE_FILE_SHARED; /* FIXME same as '=' operator */
- retval = profile_parse_file(f, &data->root);
- fclose(f);
- if (retval) {
- return retval;
- }
- assert(data->root != NULL);
+ errno = 0;
+ f = fopen(data->filespec, "r");
+ if (f == NULL) {
+ retval = errno;
+ if (retval == 0)
+ retval = ENOENT;
+ return retval;
+ }
+ set_cloexec_file(f);
+ data->upd_serial++;
+ data->flags &= PROFILE_FILE_SHARED; /* FIXME same as '=' operator */
+ retval = profile_parse_file(f, &data->root);
+ fclose(f);
+ if (retval) {
+ return retval;
+ }
+ assert(data->root != NULL);
#ifdef HAVE_STAT
- data->timestamp = st.st_mtime;
- data->frac_ts = frac;
+ data->timestamp = st.st_mtime;
+ data->frac_ts = frac;
#endif
- return 0;
+ return 0;
}
errcode_t profile_update_file_data(prf_data_t data)
retval = k5_mutex_lock(&data->lock);
if (retval)
- return retval;
+ return retval;
retval = profile_update_file_data_locked(data);
retval2 = k5_mutex_unlock(&data->lock);
return retval ? retval : retval2;
}
static errcode_t write_data_to_file(prf_data_t data, const char *outfile,
- int can_create)
+ int can_create)
{
- FILE *f;
- profile_filespec_t new_file;
- profile_filespec_t old_file;
- errcode_t retval = 0;
-
- retval = ENOMEM;
-
- new_file = old_file = 0;
- if (asprintf(&new_file, "%s.$$$", outfile) < 0) {
- new_file = NULL;
- goto errout;
- }
- if (asprintf(&old_file, "%s.bak", outfile) < 0) {
- old_file = NULL;
- goto errout;
- }
-
- errno = 0;
-
- f = fopen(new_file, "w");
- if (!f) {
- retval = errno;
- if (retval == 0)
- retval = PROF_FAIL_OPEN;
- goto errout;
- }
-
- set_cloexec_file(f);
- profile_write_tree_file(data->root, f);
- if (fclose(f) != 0) {
- retval = errno;
- goto errout;
- }
-
- unlink(old_file);
- if (make_hard_link(outfile, old_file) == 0) {
- /* Okay, got the hard link. Yay. Now we've got our
- backup version, so just put the new version in
- place. */
- if (rename(new_file, outfile)) {
- /* Weird, the rename didn't work. But the old version
- should still be in place, so no special cleanup is
- needed. */
- retval = errno;
- goto errout;
- }
- } else if (errno == ENOENT && can_create) {
- if (rename(new_file, outfile)) {
- retval = errno;
- goto errout;
- }
- } else {
- /* Couldn't make the hard link, so there's going to be a
- small window where data->filespec does not refer to
- either version. */
+ FILE *f;
+ profile_filespec_t new_file;
+ profile_filespec_t old_file;
+ errcode_t retval = 0;
+
+ retval = ENOMEM;
+
+ new_file = old_file = 0;
+ if (asprintf(&new_file, "%s.$$$", outfile) < 0) {
+ new_file = NULL;
+ goto errout;
+ }
+ if (asprintf(&old_file, "%s.bak", outfile) < 0) {
+ old_file = NULL;
+ goto errout;
+ }
+
+ errno = 0;
+
+ f = fopen(new_file, "w");
+ if (!f) {
+ retval = errno;
+ if (retval == 0)
+ retval = PROF_FAIL_OPEN;
+ goto errout;
+ }
+
+ set_cloexec_file(f);
+ profile_write_tree_file(data->root, f);
+ if (fclose(f) != 0) {
+ retval = errno;
+ goto errout;
+ }
+
+ unlink(old_file);
+ if (make_hard_link(outfile, old_file) == 0) {
+ /* Okay, got the hard link. Yay. Now we've got our
+ backup version, so just put the new version in
+ place. */
+ if (rename(new_file, outfile)) {
+ /* Weird, the rename didn't work. But the old version
+ should still be in place, so no special cleanup is
+ needed. */
+ retval = errno;
+ goto errout;
+ }
+ } else if (errno == ENOENT && can_create) {
+ if (rename(new_file, outfile)) {
+ retval = errno;
+ goto errout;
+ }
+ } else {
+ /* Couldn't make the hard link, so there's going to be a
+ small window where data->filespec does not refer to
+ either version. */
#ifndef _WIN32
- sync();
+ sync();
#endif
- if (rename(outfile, old_file)) {
- retval = errno;
- goto errout;
- }
- if (rename(new_file, outfile)) {
- retval = errno;
- rename(old_file, outfile); /* back out... */
- goto errout;
- }
- }
-
- data->flags = 0;
- retval = 0;
+ if (rename(outfile, old_file)) {
+ retval = errno;
+ goto errout;
+ }
+ if (rename(new_file, outfile)) {
+ retval = errno;
+ rename(old_file, outfile); /* back out... */
+ goto errout;
+ }
+ }
+
+ data->flags = 0;
+ retval = 0;
errout:
- if (new_file)
- free(new_file);
- if (old_file)
- free(old_file);
- return retval;
+ if (new_file)
+ free(new_file);
+ if (old_file)
+ free(old_file);
+ return retval;
}
errcode_t profile_flush_file_data_to_buffer (prf_data_t data, char **bufp)
{
- errcode_t retval;
- retval = k5_mutex_lock(&data->lock);
- if (retval)
- return retval;
- retval = profile_write_tree_to_buffer(data->root, bufp);
- k5_mutex_unlock(&data->lock);
- return retval;
+ errcode_t retval;
+ retval = k5_mutex_lock(&data->lock);
+ if (retval)
+ return retval;
+ retval = profile_write_tree_to_buffer(data->root, bufp);
+ k5_mutex_unlock(&data->lock);
+ return retval;
}
errcode_t profile_flush_file_data(prf_data_t data)
{
- errcode_t retval = 0;
+ errcode_t retval = 0;
- if (!data || data->magic != PROF_MAGIC_FILE_DATA)
- return PROF_MAGIC_FILE_DATA;
+ if (!data || data->magic != PROF_MAGIC_FILE_DATA)
+ return PROF_MAGIC_FILE_DATA;
- retval = k5_mutex_lock(&data->lock);
- if (retval)
- return retval;
+ retval = k5_mutex_lock(&data->lock);
+ if (retval)
+ return retval;
- if ((data->flags & PROFILE_FILE_DIRTY) == 0) {
- k5_mutex_unlock(&data->lock);
- return 0;
- }
+ if ((data->flags & PROFILE_FILE_DIRTY) == 0) {
+ k5_mutex_unlock(&data->lock);
+ return 0;
+ }
- retval = write_data_to_file(data, data->filespec, 0);
- k5_mutex_unlock(&data->lock);
- return retval;
+ retval = write_data_to_file(data, data->filespec, 0);
+ k5_mutex_unlock(&data->lock);
+ return retval;
}
errcode_t profile_flush_file_data_to_file(prf_data_t data, const char *outfile)
errcode_t retval = 0;
if (!data || data->magic != PROF_MAGIC_FILE_DATA)
- return PROF_MAGIC_FILE_DATA;
+ return PROF_MAGIC_FILE_DATA;
retval = k5_mutex_lock(&data->lock);
if (retval)
- return retval;
+ return retval;
retval = write_data_to_file(data, outfile, 1);
k5_mutex_unlock(&data->lock);
return retval;
int err;
err = k5_mutex_lock(&g_shared_trees_mutex);
if (err)
- return;
+ return;
profile_dereference_data_locked(data);
(void) k5_mutex_unlock(&g_shared_trees_mutex);
}
scan_shared_trees_locked();
data->refcount--;
if (data->refcount == 0)
- profile_free_file_data(data);
+ profile_free_file_data(data);
scan_shared_trees_locked();
}
{
scan_shared_trees_locked();
if (data->flags & PROFILE_FILE_SHARED) {
- /* Remove from linked list. */
- if (g_shared_trees == data)
- g_shared_trees = data->next;
- else {
- prf_data_t prev, next;
- prev = g_shared_trees;
- next = prev->next;
- while (next) {
- if (next == data) {
- prev->next = next->next;
- break;
- }
- prev = next;
- next = next->next;
- }
- }
+ /* Remove from linked list. */
+ if (g_shared_trees == data)
+ g_shared_trees = data->next;
+ else {
+ prf_data_t prev, next;
+ prev = g_shared_trees;
+ next = prev->next;
+ while (next) {
+ if (next == data) {
+ prev->next = next->next;
+ break;
+ }
+ prev = next;
+ next = next->next;
+ }
+ }
}
if (data->root)
- profile_free_node(data->root);
+ profile_free_node(data->root);
if (data->comment)
- free(data->comment);
+ free(data->comment);
data->magic = 0;
k5_mutex_destroy(&data->lock);
free(data);
errcode_t profile_close_file(prf_file_t prf)
{
- errcode_t retval;
+ errcode_t retval;
- retval = profile_flush_file(prf);
- if (retval)
- return retval;
- profile_free_file(prf);
- return 0;
+ retval = profile_flush_file(prf);
+ if (retval)
+ return retval;
+ profile_free_file(prf);
+ return 0;
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* prof_get.c --- routines that expose the public interfaces for
- * querying items from the profile.
+ * querying items from the profile.
*
*/
*/
struct profile_string_list {
- char **list;
- unsigned int num;
- unsigned int max;
+ char **list;
+ unsigned int num;
+ unsigned int max;
};
/*
*/
static errcode_t init_list(struct profile_string_list *list)
{
- list->num = 0;
- list->max = 10;
- list->list = malloc(list->max * sizeof(char *));
- if (list->list == 0)
- return ENOMEM;
- list->list[0] = 0;
- return 0;
+ list->num = 0;
+ list->max = 10;
+ list->list = malloc(list->max * sizeof(char *));
+ if (list->list == 0)
+ return ENOMEM;
+ list->list[0] = 0;
+ return 0;
}
/*
*/
static void end_list(struct profile_string_list *list, char ***ret_list)
{
- char **cp;
-
- if (list == 0)
- return;
-
- if (ret_list) {
- *ret_list = list->list;
- return;
- } else {
- for (cp = list->list; *cp; cp++)
- free(*cp);
- free(list->list);
- }
- list->num = list->max = 0;
- list->list = 0;
+ char **cp;
+
+ if (list == 0)
+ return;
+
+ if (ret_list) {
+ *ret_list = list->list;
+ return;
+ } else {
+ for (cp = list->list; *cp; cp++)
+ free(*cp);
+ free(list->list);
+ }
+ list->num = list->max = 0;
+ list->list = 0;
}
/*
*/
static errcode_t add_to_list(struct profile_string_list *list, const char *str)
{
- char *newstr, **newlist;
- unsigned int newmax;
-
- if (list->num+1 >= list->max) {
- newmax = list->max + 10;
- newlist = realloc(list->list, newmax * sizeof(char *));
- if (newlist == 0)
- return ENOMEM;
- list->max = newmax;
- list->list = newlist;
- }
- newstr = strdup(str);
- if (newstr == 0)
- return ENOMEM;
-
- list->list[list->num++] = newstr;
- list->list[list->num] = 0;
- return 0;
+ char *newstr, **newlist;
+ unsigned int newmax;
+
+ if (list->num+1 >= list->max) {
+ newmax = list->max + 10;
+ newlist = realloc(list->list, newmax * sizeof(char *));
+ if (newlist == 0)
+ return ENOMEM;
+ list->max = newmax;
+ list->list = newlist;
+ }
+ newstr = strdup(str);
+ if (newstr == 0)
+ return ENOMEM;
+
+ list->list[list->num++] = newstr;
+ list->list[list->num] = 0;
+ return 0;
}
/*
*/
static int is_list_member(struct profile_string_list *list, const char *str)
{
- char **cpp;
+ char **cpp;
- if (!list->list)
- return 0;
+ if (!list->list)
+ return 0;
- for (cpp = list->list; *cpp; cpp++) {
- if (!strcmp(*cpp, str))
- return 1;
- }
- return 0;
+ for (cpp = list->list; *cpp; cpp++) {
+ if (!strcmp(*cpp, str))
+ return 1;
+ }
+ return 0;
}
/*
*/
void KRB5_CALLCONV profile_free_list(char **list)
{
- char **cp;
+ char **cp;
if (list == 0)
- return;
+ return;
for (cp = list; *cp; cp++)
- free(*cp);
+ free(*cp);
free(list);
}
errcode_t KRB5_CALLCONV
profile_get_values(profile_t profile, const char *const *names,
- char ***ret_values)
+ char ***ret_values)
{
- errcode_t retval;
- void *state;
- char *value;
- struct profile_string_list values;
-
- if ((retval = profile_node_iterator_create(profile, names,
- PROFILE_ITER_RELATIONS_ONLY,
- &state)))
- return retval;
-
- if ((retval = init_list(&values)))
- return retval;
-
- do {
- if ((retval = profile_node_iterator(&state, 0, 0, &value)))
- goto cleanup;
- if (value)
- add_to_list(&values, value);
- } while (state);
-
- if (values.num == 0) {
- retval = PROF_NO_RELATION;
- goto cleanup;
- }
-
- end_list(&values, ret_values);
- return 0;
+ errcode_t retval;
+ void *state;
+ char *value;
+ struct profile_string_list values;
+
+ if ((retval = profile_node_iterator_create(profile, names,
+ PROFILE_ITER_RELATIONS_ONLY,
+ &state)))
+ return retval;
+
+ if ((retval = init_list(&values)))
+ return retval;
+
+ do {
+ if ((retval = profile_node_iterator(&state, 0, 0, &value)))
+ goto cleanup;
+ if (value)
+ add_to_list(&values, value);
+ } while (state);
+
+ if (values.num == 0) {
+ retval = PROF_NO_RELATION;
+ goto cleanup;
+ }
+
+ end_list(&values, ret_values);
+ return 0;
cleanup:
- end_list(&values, 0);
- return retval;
+ end_list(&values, 0);
+ return retval;
}
/*
* helper function for profile_get_string, profile_get_integer, etc.
*/
errcode_t profile_get_value(profile_t profile, const char **names,
- const char **ret_value)
+ const char **ret_value)
{
- errcode_t retval;
- void *state;
- char *value;
+ errcode_t retval;
+ void *state;
+ char *value;
- if ((retval = profile_node_iterator_create(profile, names,
- PROFILE_ITER_RELATIONS_ONLY,
- &state)))
- return retval;
+ if ((retval = profile_node_iterator_create(profile, names,
+ PROFILE_ITER_RELATIONS_ONLY,
+ &state)))
+ return retval;
- if ((retval = profile_node_iterator(&state, 0, 0, &value)))
- goto cleanup;
+ if ((retval = profile_node_iterator(&state, 0, 0, &value)))
+ goto cleanup;
- if (value)
- *ret_value = value;
- else
- retval = PROF_NO_RELATION;
+ if (value)
+ *ret_value = value;
+ else
+ retval = PROF_NO_RELATION;
cleanup:
- profile_node_iterator_free(&state);
- return retval;
+ profile_node_iterator_free(&state);
+ return retval;
}
errcode_t KRB5_CALLCONV
profile_get_string(profile_t profile, const char *name, const char *subname,
- const char *subsubname, const char *def_val,
- char **ret_string)
+ const char *subsubname, const char *def_val,
+ char **ret_string)
{
- const char *value;
- errcode_t retval;
- const char *names[4];
-
- if (profile) {
- names[0] = name;
- names[1] = subname;
- names[2] = subsubname;
- names[3] = 0;
- retval = profile_get_value(profile, names, &value);
- if (retval == PROF_NO_SECTION || retval == PROF_NO_RELATION)
- value = def_val;
- else if (retval)
- return retval;
- } else
- value = def_val;
-
- if (value) {
- *ret_string = strdup(value);
- if (*ret_string == 0)
- return ENOMEM;
- } else
- *ret_string = 0;
- return 0;
+ const char *value;
+ errcode_t retval;
+ const char *names[4];
+
+ if (profile) {
+ names[0] = name;
+ names[1] = subname;
+ names[2] = subsubname;
+ names[3] = 0;
+ retval = profile_get_value(profile, names, &value);
+ if (retval == PROF_NO_SECTION || retval == PROF_NO_RELATION)
+ value = def_val;
+ else if (retval)
+ return retval;
+ } else
+ value = def_val;
+
+ if (value) {
+ *ret_string = strdup(value);
+ if (*ret_string == 0)
+ return ENOMEM;
+ } else
+ *ret_string = 0;
+ return 0;
}
errcode_t KRB5_CALLCONV
profile_get_integer(profile_t profile, const char *name, const char *subname,
- const char *subsubname, int def_val, int *ret_int)
+ const char *subsubname, int def_val, int *ret_int)
{
- const char *value;
- errcode_t retval;
- const char *names[4];
- char *end_value;
- long ret_long;
-
- *ret_int = def_val;
- if (profile == 0)
- return 0;
-
- names[0] = name;
- names[1] = subname;
- names[2] = subsubname;
- names[3] = 0;
- retval = profile_get_value(profile, names, &value);
- if (retval == PROF_NO_SECTION || retval == PROF_NO_RELATION) {
- *ret_int = def_val;
- return 0;
- } else if (retval)
- return retval;
-
- if (value[0] == 0)
- /* Empty string is no good. */
- return PROF_BAD_INTEGER;
- errno = 0;
- ret_long = strtol (value, &end_value, 10);
-
- /* Overflow or underflow. */
- if ((ret_long == LONG_MIN || ret_long == LONG_MAX) && errno != 0)
- return PROF_BAD_INTEGER;
- /* Value outside "int" range. */
- if ((long) (int) ret_long != ret_long)
- return PROF_BAD_INTEGER;
- /* Garbage in string. */
- if (end_value != value + strlen (value))
- return PROF_BAD_INTEGER;
-
-
- *ret_int = ret_long;
- return 0;
+ const char *value;
+ errcode_t retval;
+ const char *names[4];
+ char *end_value;
+ long ret_long;
+
+ *ret_int = def_val;
+ if (profile == 0)
+ return 0;
+
+ names[0] = name;
+ names[1] = subname;
+ names[2] = subsubname;
+ names[3] = 0;
+ retval = profile_get_value(profile, names, &value);
+ if (retval == PROF_NO_SECTION || retval == PROF_NO_RELATION) {
+ *ret_int = def_val;
+ return 0;
+ } else if (retval)
+ return retval;
+
+ if (value[0] == 0)
+ /* Empty string is no good. */
+ return PROF_BAD_INTEGER;
+ errno = 0;
+ ret_long = strtol (value, &end_value, 10);
+
+ /* Overflow or underflow. */
+ if ((ret_long == LONG_MIN || ret_long == LONG_MAX) && errno != 0)
+ return PROF_BAD_INTEGER;
+ /* Value outside "int" range. */
+ if ((long) (int) ret_long != ret_long)
+ return PROF_BAD_INTEGER;
+ /* Garbage in string. */
+ if (end_value != value + strlen (value))
+ return PROF_BAD_INTEGER;
+
+
+ *ret_int = ret_long;
+ return 0;
}
static const char *const conf_yes[] = {
const char *const *p;
if (ret_boolean == NULL)
- return PROF_EINVAL;
+ return PROF_EINVAL;
for(p=conf_yes; *p; p++) {
- if (!strcasecmp(*p,s)) {
- *ret_boolean = 1;
- return 0;
- }
+ if (!strcasecmp(*p,s)) {
+ *ret_boolean = 1;
+ return 0;
+ }
}
for(p=conf_no; *p; p++) {
- if (!strcasecmp(*p,s)) {
- *ret_boolean = 0;
- return 0;
- }
+ if (!strcasecmp(*p,s)) {
+ *ret_boolean = 0;
+ return 0;
+ }
}
- return PROF_BAD_BOOLEAN;
+ return PROF_BAD_BOOLEAN;
}
errcode_t KRB5_CALLCONV
profile_get_boolean(profile_t profile, const char *name, const char *subname,
- const char *subsubname, int def_val, int *ret_boolean)
+ const char *subsubname, int def_val, int *ret_boolean)
{
- const char *value;
- errcode_t retval;
- const char *names[4];
-
- if (profile == 0) {
- *ret_boolean = def_val;
- return 0;
- }
-
- names[0] = name;
- names[1] = subname;
- names[2] = subsubname;
- names[3] = 0;
- retval = profile_get_value(profile, names, &value);
- if (retval == PROF_NO_SECTION || retval == PROF_NO_RELATION) {
- *ret_boolean = def_val;
- return 0;
- } else if (retval)
- return retval;
-
- return profile_parse_boolean (value, ret_boolean);
+ const char *value;
+ errcode_t retval;
+ const char *names[4];
+
+ if (profile == 0) {
+ *ret_boolean = def_val;
+ return 0;
+ }
+
+ names[0] = name;
+ names[1] = subname;
+ names[2] = subsubname;
+ names[3] = 0;
+ retval = profile_get_value(profile, names, &value);
+ if (retval == PROF_NO_SECTION || retval == PROF_NO_RELATION) {
+ *ret_boolean = def_val;
+ return 0;
+ } else if (retval)
+ return retval;
+
+ return profile_parse_boolean (value, ret_boolean);
}
/*
*/
errcode_t KRB5_CALLCONV
profile_get_subsection_names(profile_t profile, const char **names,
- char ***ret_names)
+ char ***ret_names)
{
- errcode_t retval;
- void *state;
- char *name;
- struct profile_string_list values;
+ errcode_t retval;
+ void *state;
+ char *name;
+ struct profile_string_list values;
- if ((retval = profile_node_iterator_create(profile, names,
- PROFILE_ITER_LIST_SECTION | PROFILE_ITER_SECTIONS_ONLY,
- &state)))
- return retval;
+ if ((retval = profile_node_iterator_create(profile, names,
+ PROFILE_ITER_LIST_SECTION | PROFILE_ITER_SECTIONS_ONLY,
+ &state)))
+ return retval;
- if ((retval = init_list(&values)))
- return retval;
+ if ((retval = init_list(&values)))
+ return retval;
- do {
- if ((retval = profile_node_iterator(&state, 0, &name, 0)))
- goto cleanup;
- if (name)
- add_to_list(&values, name);
- } while (state);
+ do {
+ if ((retval = profile_node_iterator(&state, 0, &name, 0)))
+ goto cleanup;
+ if (name)
+ add_to_list(&values, name);
+ } while (state);
- end_list(&values, ret_names);
- return 0;
+ end_list(&values, ret_names);
+ return 0;
cleanup:
- end_list(&values, 0);
- return retval;
+ end_list(&values, 0);
+ return retval;
}
/*
*/
errcode_t KRB5_CALLCONV
profile_get_relation_names(profile_t profile, const char **names,
- char ***ret_names)
+ char ***ret_names)
{
- errcode_t retval;
- void *state;
- char *name;
- struct profile_string_list values;
+ errcode_t retval;
+ void *state;
+ char *name;
+ struct profile_string_list values;
- if ((retval = profile_node_iterator_create(profile, names,
- PROFILE_ITER_LIST_SECTION | PROFILE_ITER_RELATIONS_ONLY,
- &state)))
- return retval;
+ if ((retval = profile_node_iterator_create(profile, names,
+ PROFILE_ITER_LIST_SECTION | PROFILE_ITER_RELATIONS_ONLY,
+ &state)))
+ return retval;
- if ((retval = init_list(&values)))
- return retval;
+ if ((retval = init_list(&values)))
+ return retval;
- do {
- if ((retval = profile_node_iterator(&state, 0, &name, 0)))
- goto cleanup;
- if (name && !is_list_member(&values, name))
- add_to_list(&values, name);
- } while (state);
+ do {
+ if ((retval = profile_node_iterator(&state, 0, &name, 0)))
+ goto cleanup;
+ if (name && !is_list_member(&values, name))
+ add_to_list(&values, name);
+ } while (state);
- end_list(&values, ret_names);
- return 0;
+ end_list(&values, ret_names);
+ return 0;
cleanup:
- end_list(&values, 0);
- return retval;
+ end_list(&values, 0);
+ return retval;
}
errcode_t KRB5_CALLCONV
profile_iterator_create(profile_t profile, const char *const *names, int flags,
- void **ret_iter)
+ void **ret_iter)
{
- return profile_node_iterator_create(profile, names, flags, ret_iter);
+ return profile_node_iterator_create(profile, names, flags, ret_iter);
}
void KRB5_CALLCONV
profile_iterator_free(void **iter_p)
{
- profile_node_iterator_free(iter_p);
+ profile_node_iterator_free(iter_p);
}
errcode_t KRB5_CALLCONV
profile_iterator(void **iter_p, char **ret_name, char **ret_value)
{
- char *name, *value;
- errcode_t retval;
-
- retval = profile_node_iterator(iter_p, 0, &name, &value);
- if (retval)
- return retval;
-
- if (ret_name) {
- if (name) {
- *ret_name = strdup(name);
- if (!*ret_name)
- return ENOMEM;
- } else
- *ret_name = 0;
- }
- if (ret_value) {
- if (value) {
- *ret_value = strdup(value);
- if (!*ret_value) {
- if (ret_name) {
- free(*ret_name);
- *ret_name = 0;
- }
- return ENOMEM;
- }
- } else
- *ret_value = 0;
- }
- return 0;
+ char *name, *value;
+ errcode_t retval;
+
+ retval = profile_node_iterator(iter_p, 0, &name, &value);
+ if (retval)
+ return retval;
+
+ if (ret_name) {
+ if (name) {
+ *ret_name = strdup(name);
+ if (!*ret_name)
+ return ENOMEM;
+ } else
+ *ret_name = 0;
+ }
+ if (ret_value) {
+ if (value) {
+ *ret_value = strdup(value);
+ if (!*ret_value) {
+ if (ret_name) {
+ free(*ret_name);
+ *ret_name = 0;
+ }
+ return ENOMEM;
+ }
+ } else
+ *ret_value = 0;
+ }
+ return 0;
}
void KRB5_CALLCONV
profile_release_string(char *str)
{
- free(str);
+ free(str);
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* prof_init.c --- routines that manipulate the user-visible profile_t
- * object.
+ * object.
*/
#include "prof_int.h"
errcode_t KRB5_CALLCONV
profile_init(const_profile_filespec_t *files, profile_t *ret_profile)
{
- const_profile_filespec_t *fs;
- profile_t profile;
- prf_file_t new_file, last = 0;
- errcode_t retval = 0;
-
- profile = malloc(sizeof(struct _profile_t));
- if (!profile)
- return ENOMEM;
- memset(profile, 0, sizeof(struct _profile_t));
- profile->magic = PROF_MAGIC_PROFILE;
-
- /*
- * If the filenames list is not specified or empty, return an empty
- * profile.
- */
- if ( files && !PROFILE_LAST_FILESPEC(*files) ) {
- for (fs = files; !PROFILE_LAST_FILESPEC(*fs); fs++) {
- retval = profile_open_file(*fs, &new_file);
- /* if this file is missing, skip to the next */
- if (retval == ENOENT || retval == EACCES || retval == EPERM) {
- continue;
- }
- if (retval) {
- profile_release(profile);
- return retval;
- }
- if (last)
- last->next = new_file;
- else
- profile->first_file = new_file;
- last = new_file;
- }
- /*
- * If last is still null after the loop, then all the files were
- * missing, so return the appropriate error.
- */
- if (!last) {
- profile_release(profile);
- return ENOENT;
- }
- }
-
- *ret_profile = profile;
- return 0;
+ const_profile_filespec_t *fs;
+ profile_t profile;
+ prf_file_t new_file, last = 0;
+ errcode_t retval = 0;
+
+ profile = malloc(sizeof(struct _profile_t));
+ if (!profile)
+ return ENOMEM;
+ memset(profile, 0, sizeof(struct _profile_t));
+ profile->magic = PROF_MAGIC_PROFILE;
+
+ /*
+ * If the filenames list is not specified or empty, return an empty
+ * profile.
+ */
+ if ( files && !PROFILE_LAST_FILESPEC(*files) ) {
+ for (fs = files; !PROFILE_LAST_FILESPEC(*fs); fs++) {
+ retval = profile_open_file(*fs, &new_file);
+ /* if this file is missing, skip to the next */
+ if (retval == ENOENT || retval == EACCES || retval == EPERM) {
+ continue;
+ }
+ if (retval) {
+ profile_release(profile);
+ return retval;
+ }
+ if (last)
+ last->next = new_file;
+ else
+ profile->first_file = new_file;
+ last = new_file;
+ }
+ /*
+ * If last is still null after the loop, then all the files were
+ * missing, so return the appropriate error.
+ */
+ if (!last) {
+ profile_release(profile);
+ return ENOENT;
+ }
+ }
+
+ *ret_profile = profile;
+ return 0;
}
-#define COUNT_LINKED_LIST(COUNT, PTYPE, START, FIELD) \
- { \
- size_t cll_counter = 0; \
- PTYPE cll_ptr = (START); \
- while (cll_ptr != NULL) { \
- cll_counter++; \
- cll_ptr = cll_ptr->FIELD; \
- } \
- (COUNT) = cll_counter; \
- }
+#define COUNT_LINKED_LIST(COUNT, PTYPE, START, FIELD) \
+ { \
+ size_t cll_counter = 0; \
+ PTYPE cll_ptr = (START); \
+ while (cll_ptr != NULL) { \
+ cll_counter++; \
+ cll_ptr = cll_ptr->FIELD; \
+ } \
+ (COUNT) = cll_counter; \
+ }
errcode_t KRB5_CALLCONV
profile_copy(profile_t old_profile, profile_t *new_profile)
COUNT_LINKED_LIST (size, prf_file_t, old_profile->first_file, next);
files = malloc ((size+1) * sizeof(*files));
if (files == NULL)
- return ENOMEM;
+ return ENOMEM;
for (i = 0, file = old_profile->first_file; i < size; i++, file = file->next)
- files[i] = file->data->filespec;
+ files[i] = file->data->filespec;
files[size] = NULL;
err = profile_init (files, new_profile);
free (files);
errcode_t KRB5_CALLCONV
profile_init_path(const_profile_filespec_list_t filepath,
- profile_t *ret_profile)
+ profile_t *ret_profile)
{
- unsigned int n_entries;
- int i;
- unsigned int ent_len;
- const char *s, *t;
- profile_filespec_t *filenames;
- errcode_t retval;
-
- /* count the distinct filename components */
- for(s = filepath, n_entries = 1; *s; s++) {
- if (*s == ':')
- n_entries++;
- }
-
- /* the array is NULL terminated */
- filenames = (profile_filespec_t*) malloc((n_entries+1) * sizeof(char*));
- if (filenames == 0)
- return ENOMEM;
-
- /* measure, copy, and skip each one */
- for(s = filepath, i=0; (t = strchr(s, ':')) || (t=s+strlen(s)); s=t+1, i++) {
- ent_len = (unsigned int) (t-s);
- filenames[i] = (char*) malloc(ent_len + 1);
- if (filenames[i] == 0) {
- /* if malloc fails, free the ones that worked */
- while(--i >= 0) free(filenames[i]);
- free(filenames);
- return ENOMEM;
- }
- strncpy(filenames[i], s, ent_len);
- filenames[i][ent_len] = 0;
- if (*t == 0) {
- i++;
- break;
- }
- }
- /* cap the array */
- filenames[i] = 0;
-
- retval = profile_init((const_profile_filespec_t *) filenames,
- ret_profile);
-
- /* count back down and free the entries */
- while(--i >= 0) free(filenames[i]);
- free(filenames);
-
- return retval;
+ unsigned int n_entries;
+ int i;
+ unsigned int ent_len;
+ const char *s, *t;
+ profile_filespec_t *filenames;
+ errcode_t retval;
+
+ /* count the distinct filename components */
+ for(s = filepath, n_entries = 1; *s; s++) {
+ if (*s == ':')
+ n_entries++;
+ }
+
+ /* the array is NULL terminated */
+ filenames = (profile_filespec_t*) malloc((n_entries+1) * sizeof(char*));
+ if (filenames == 0)
+ return ENOMEM;
+
+ /* measure, copy, and skip each one */
+ for(s = filepath, i=0; (t = strchr(s, ':')) || (t=s+strlen(s)); s=t+1, i++) {
+ ent_len = (unsigned int) (t-s);
+ filenames[i] = (char*) malloc(ent_len + 1);
+ if (filenames[i] == 0) {
+ /* if malloc fails, free the ones that worked */
+ while(--i >= 0) free(filenames[i]);
+ free(filenames);
+ return ENOMEM;
+ }
+ strncpy(filenames[i], s, ent_len);
+ filenames[i][ent_len] = 0;
+ if (*t == 0) {
+ i++;
+ break;
+ }
+ }
+ /* cap the array */
+ filenames[i] = 0;
+
+ retval = profile_init((const_profile_filespec_t *) filenames,
+ ret_profile);
+
+ /* count back down and free the entries */
+ while(--i >= 0) free(filenames[i]);
+ free(filenames);
+
+ return retval;
}
errcode_t KRB5_CALLCONV
errcode_t KRB5_CALLCONV
profile_flush(profile_t profile)
{
- if (!profile || profile->magic != PROF_MAGIC_PROFILE)
- return PROF_MAGIC_PROFILE;
+ if (!profile || profile->magic != PROF_MAGIC_PROFILE)
+ return PROF_MAGIC_PROFILE;
- if (profile->first_file)
- return profile_flush_file(profile->first_file);
+ if (profile->first_file)
+ return profile_flush_file(profile->first_file);
- return 0;
+ return 0;
}
errcode_t KRB5_CALLCONV
profile_flush_to_file(profile_t profile, const_profile_filespec_t outfile)
{
- if (!profile || profile->magic != PROF_MAGIC_PROFILE)
- return PROF_MAGIC_PROFILE;
+ if (!profile || profile->magic != PROF_MAGIC_PROFILE)
+ return PROF_MAGIC_PROFILE;
- if (profile->first_file)
- return profile_flush_file_to_file(profile->first_file,
- outfile);
+ if (profile->first_file)
+ return profile_flush_file_to_file(profile->first_file,
+ outfile);
- return 0;
+ return 0;
}
errcode_t KRB5_CALLCONV
void KRB5_CALLCONV
profile_abandon(profile_t profile)
{
- prf_file_t p, next;
+ prf_file_t p, next;
- if (!profile || profile->magic != PROF_MAGIC_PROFILE)
- return;
+ if (!profile || profile->magic != PROF_MAGIC_PROFILE)
+ return;
- for (p = profile->first_file; p; p = next) {
- next = p->next;
- profile_free_file(p);
- }
- profile->magic = 0;
- free(profile);
+ for (p = profile->first_file; p; p = next) {
+ next = p->next;
+ profile_free_file(p);
+ }
+ profile->magic = 0;
+ free(profile);
}
void KRB5_CALLCONV
profile_release(profile_t profile)
{
- prf_file_t p, next;
+ prf_file_t p, next;
- if (!profile || profile->magic != PROF_MAGIC_PROFILE)
- return;
+ if (!profile || profile->magic != PROF_MAGIC_PROFILE)
+ return;
- for (p = profile->first_file; p; p = next) {
- next = p->next;
- profile_close_file(p);
- }
- profile->magic = 0;
- free(profile);
+ for (p = profile->first_file; p; p = next) {
+ next = p->next;
+ profile_close_file(p);
+ }
+ profile->magic = 0;
+ free(profile);
}
/*
* Here begins the profile serialization functions.
*/
errcode_t profile_ser_size(const char *unused, profile_t profile,
- size_t *sizep)
+ size_t *sizep)
{
- size_t required;
- prf_file_t pfp;
+ size_t required;
+ prf_file_t pfp;
required = 3*sizeof(prof_int32);
for (pfp = profile->first_file; pfp; pfp = pfp->next) {
- required += sizeof(prof_int32);
- required += strlen(pfp->data->filespec);
+ required += sizeof(prof_int32);
+ required += strlen(pfp->data->filespec);
}
*sizep += required;
return 0;
}
errcode_t profile_ser_externalize(const char *unused, profile_t profile,
- unsigned char **bufpp, size_t *remainp)
+ unsigned char **bufpp, size_t *remainp)
{
- errcode_t retval;
- size_t required;
- unsigned char *bp;
- size_t remain;
- prf_file_t pfp;
- prof_int32 fcount, slen;
+ errcode_t retval;
+ size_t required;
+ unsigned char *bp;
+ size_t remain;
+ prf_file_t pfp;
+ prof_int32 fcount, slen;
required = 0;
bp = *bufpp;
remain = *remainp;
retval = EINVAL;
if (profile) {
- retval = ENOMEM;
- (void) profile_ser_size(unused, profile, &required);
- if (required <= remain) {
- fcount = 0;
- for (pfp = profile->first_file; pfp; pfp = pfp->next)
- fcount++;
- pack_int32(PROF_MAGIC_PROFILE, &bp, &remain);
- pack_int32(fcount, &bp, &remain);
- for (pfp = profile->first_file; pfp; pfp = pfp->next) {
- slen = (prof_int32) strlen(pfp->data->filespec);
- pack_int32(slen, &bp, &remain);
- if (slen) {
- memcpy(bp, pfp->data->filespec, (size_t) slen);
- bp += slen;
- remain -= (size_t) slen;
- }
- }
- pack_int32(PROF_MAGIC_PROFILE, &bp, &remain);
- retval = 0;
- *bufpp = bp;
- *remainp = remain;
- }
+ retval = ENOMEM;
+ (void) profile_ser_size(unused, profile, &required);
+ if (required <= remain) {
+ fcount = 0;
+ for (pfp = profile->first_file; pfp; pfp = pfp->next)
+ fcount++;
+ pack_int32(PROF_MAGIC_PROFILE, &bp, &remain);
+ pack_int32(fcount, &bp, &remain);
+ for (pfp = profile->first_file; pfp; pfp = pfp->next) {
+ slen = (prof_int32) strlen(pfp->data->filespec);
+ pack_int32(slen, &bp, &remain);
+ if (slen) {
+ memcpy(bp, pfp->data->filespec, (size_t) slen);
+ bp += slen;
+ remain -= (size_t) slen;
+ }
+ }
+ pack_int32(PROF_MAGIC_PROFILE, &bp, &remain);
+ retval = 0;
+ *bufpp = bp;
+ *remainp = remain;
+ }
}
return(retval);
}
static int unpack_int32(prof_int32 *intp, unsigned char **bufpp,
- size_t *remainp)
+ size_t *remainp)
{
if (*remainp >= sizeof(prof_int32)) {
- *intp = load_32_be(*bufpp);
- *bufpp += sizeof(prof_int32);
- *remainp -= sizeof(prof_int32);
- return 0;
+ *intp = load_32_be(*bufpp);
+ *bufpp += sizeof(prof_int32);
+ *remainp -= sizeof(prof_int32);
+ return 0;
}
else
- return 1;
+ return 1;
}
errcode_t profile_ser_internalize(const char *unused, profile_t *profilep,
- unsigned char **bufpp, size_t *remainp)
+ unsigned char **bufpp, size_t *remainp)
{
- errcode_t retval;
- unsigned char *bp;
- size_t remain;
- int i;
- prof_int32 fcount, tmp;
- profile_filespec_t *flist = 0;
-
- bp = *bufpp;
- remain = *remainp;
- fcount = 0;
-
- if (remain >= 12)
- (void) unpack_int32(&tmp, &bp, &remain);
- else
- tmp = 0;
-
- if (tmp != PROF_MAGIC_PROFILE) {
- retval = EINVAL;
- goto cleanup;
- }
-
- (void) unpack_int32(&fcount, &bp, &remain);
- retval = ENOMEM;
-
- flist = (profile_filespec_t *) malloc(sizeof(profile_filespec_t) * (size_t) (fcount + 1));
- if (!flist)
- goto cleanup;
-
- memset(flist, 0, sizeof(char *) * (size_t) (fcount+1));
- for (i=0; i<fcount; i++) {
- if (!unpack_int32(&tmp, &bp, &remain)) {
- flist[i] = (char *) malloc((size_t) (tmp+1));
- if (!flist[i])
- goto cleanup;
- memcpy(flist[i], bp, (size_t) tmp);
- flist[i][tmp] = '\0';
- bp += tmp;
- remain -= (size_t) tmp;
- }
- }
-
- if (unpack_int32(&tmp, &bp, &remain) ||
- (tmp != PROF_MAGIC_PROFILE)) {
- retval = EINVAL;
- goto cleanup;
- }
-
- if ((retval = profile_init((const_profile_filespec_t *) flist,
- profilep)))
- goto cleanup;
-
- *bufpp = bp;
- *remainp = remain;
+ errcode_t retval;
+ unsigned char *bp;
+ size_t remain;
+ int i;
+ prof_int32 fcount, tmp;
+ profile_filespec_t *flist = 0;
+
+ bp = *bufpp;
+ remain = *remainp;
+ fcount = 0;
+
+ if (remain >= 12)
+ (void) unpack_int32(&tmp, &bp, &remain);
+ else
+ tmp = 0;
+
+ if (tmp != PROF_MAGIC_PROFILE) {
+ retval = EINVAL;
+ goto cleanup;
+ }
+
+ (void) unpack_int32(&fcount, &bp, &remain);
+ retval = ENOMEM;
+
+ flist = (profile_filespec_t *) malloc(sizeof(profile_filespec_t) * (size_t) (fcount + 1));
+ if (!flist)
+ goto cleanup;
+
+ memset(flist, 0, sizeof(char *) * (size_t) (fcount+1));
+ for (i=0; i<fcount; i++) {
+ if (!unpack_int32(&tmp, &bp, &remain)) {
+ flist[i] = (char *) malloc((size_t) (tmp+1));
+ if (!flist[i])
+ goto cleanup;
+ memcpy(flist[i], bp, (size_t) tmp);
+ flist[i][tmp] = '\0';
+ bp += tmp;
+ remain -= (size_t) tmp;
+ }
+ }
+
+ if (unpack_int32(&tmp, &bp, &remain) ||
+ (tmp != PROF_MAGIC_PROFILE)) {
+ retval = EINVAL;
+ goto cleanup;
+ }
+
+ if ((retval = profile_init((const_profile_filespec_t *) flist,
+ profilep)))
+ goto cleanup;
+
+ *bufpp = bp;
+ *remainp = remain;
cleanup:
- if (flist) {
- for (i=0; i<fcount; i++) {
- if (flist[i])
- free(flist[i]);
- }
- free(flist);
- }
- return(retval);
+ if (flist) {
+ for (i=0; i<fcount; i++) {
+ if (flist[i])
+ free(flist[i]);
+ }
+ free(flist);
+ }
+ return(retval);
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#include "prof_int.h"
#include <stdio.h>
#define SECTION_SEP_CHAR '/'
-#define STATE_INIT_COMMENT 1
-#define STATE_STD_LINE 2
-#define STATE_GET_OBRACE 3
+#define STATE_INIT_COMMENT 1
+#define STATE_STD_LINE 2
+#define STATE_GET_OBRACE 3
struct parse_state {
- int state;
- int group_level;
- struct profile_node *root_section;
- struct profile_node *current_section;
+ int state;
+ int group_level;
+ struct profile_node *root_section;
+ struct profile_node *current_section;
};
static char *skip_over_blanks(char *cp)
{
- while (*cp && isspace((int) (*cp)))
- cp++;
- return cp;
+ while (*cp && isspace((int) (*cp)))
+ cp++;
+ return cp;
}
static void strip_line(char *line)
{
- char *p = line + strlen(line);
- while (p > line && (p[-1] == '\n' || p[-1] == '\r'))
- *p-- = 0;
+ char *p = line + strlen(line);
+ while (p > line && (p[-1] == '\n' || p[-1] == '\r'))
+ *p-- = 0;
}
static void parse_quoted_string(char *str)
{
- char *to, *from;
-
- to = from = str;
-
- for (to = from = str; *from && *from != '"'; to++, from++) {
- if (*from == '\\') {
- from++;
- switch (*from) {
- case 'n':
- *to = '\n';
- break;
- case 't':
- *to = '\t';
- break;
- case 'b':
- *to = '\b';
- break;
- default:
- *to = *from;
- }
- continue;
- }
- *to = *from;
- }
- *to = '\0';
+ char *to, *from;
+
+ to = from = str;
+
+ for (to = from = str; *from && *from != '"'; to++, from++) {
+ if (*from == '\\') {
+ from++;
+ switch (*from) {
+ case 'n':
+ *to = '\n';
+ break;
+ case 't':
+ *to = '\t';
+ break;
+ case 'b':
+ *to = '\b';
+ break;
+ default:
+ *to = *from;
+ }
+ continue;
+ }
+ *to = *from;
+ }
+ *to = '\0';
}
static errcode_t parse_init_state(struct parse_state *state)
{
- state->state = STATE_INIT_COMMENT;
- state->group_level = 0;
+ state->state = STATE_INIT_COMMENT;
+ state->group_level = 0;
- return profile_create_node("(root)", 0, &state->root_section);
+ return profile_create_node("(root)", 0, &state->root_section);
}
static errcode_t parse_std_line(char *line, struct parse_state *state)
{
- char *cp, ch, *tag, *value;
- char *p;
- errcode_t retval;
- struct profile_node *node;
- int do_subsection = 0;
- void *iter = 0;
-
- if (*line == 0)
- return 0;
- cp = skip_over_blanks(line);
- if (cp[0] == ';' || cp[0] == '#')
- return 0;
- strip_line(cp);
- ch = *cp;
- if (ch == 0)
- return 0;
- if (ch == '[') {
- if (state->group_level > 0)
- return PROF_SECTION_NOTOP;
- cp++;
- p = strchr(cp, ']');
- if (p == NULL)
- return PROF_SECTION_SYNTAX;
- *p = '\0';
- retval = profile_find_node_subsection(state->root_section,
- cp, &iter, 0,
- &state->current_section);
- if (retval == PROF_NO_SECTION) {
- retval = profile_add_node(state->root_section,
- cp, 0,
- &state->current_section);
- if (retval)
- return retval;
- } else if (retval)
- return retval;
-
- /*
- * Finish off the rest of the line.
- */
- cp = p+1;
- if (*cp == '*') {
- profile_make_node_final(state->current_section);
- cp++;
- }
- /*
- * A space after ']' should not be fatal
- */
- cp = skip_over_blanks(cp);
- if (*cp)
- return PROF_SECTION_SYNTAX;
- return 0;
- }
- if (ch == '}') {
- if (state->group_level == 0)
- return PROF_EXTRA_CBRACE;
- if (*(cp+1) == '*')
- profile_make_node_final(state->current_section);
- retval = profile_get_node_parent(state->current_section,
- &state->current_section);
- if (retval)
- return retval;
- state->group_level--;
- return 0;
- }
- /*
- * Parse the relations
- */
- tag = cp;
- cp = strchr(cp, '=');
- if (!cp)
- return PROF_RELATION_SYNTAX;
- if (cp == tag)
- return PROF_RELATION_SYNTAX;
- *cp = '\0';
- p = tag;
- /* Look for whitespace on left-hand side. */
- while (p < cp && !isspace((int)*p))
- p++;
- if (p < cp) {
- /* Found some sort of whitespace. */
- *p++ = 0;
- /* If we have more non-whitespace, it's an error. */
- while (p < cp) {
- if (!isspace((int)*p))
- return PROF_RELATION_SYNTAX;
- p++;
- }
- }
- cp = skip_over_blanks(cp+1);
- value = cp;
- if (value[0] == '"') {
- value++;
- parse_quoted_string(value);
- } else if (value[0] == 0) {
- do_subsection++;
- state->state = STATE_GET_OBRACE;
- } else if (value[0] == '{' && *(skip_over_blanks(value+1)) == 0)
- do_subsection++;
- else {
- cp = value + strlen(value) - 1;
- while ((cp > value) && isspace((int) (*cp)))
- *cp-- = 0;
- }
- if (do_subsection) {
- p = strchr(tag, '*');
- if (p)
- *p = '\0';
- retval = profile_add_node(state->current_section,
- tag, 0, &state->current_section);
- if (retval)
- return retval;
- if (p)
- profile_make_node_final(state->current_section);
- state->group_level++;
- return 0;
- }
- p = strchr(tag, '*');
- if (p)
- *p = '\0';
- profile_add_node(state->current_section, tag, value, &node);
- if (p)
- profile_make_node_final(node);
- return 0;
+ char *cp, ch, *tag, *value;
+ char *p;
+ errcode_t retval;
+ struct profile_node *node;
+ int do_subsection = 0;
+ void *iter = 0;
+
+ if (*line == 0)
+ return 0;
+ cp = skip_over_blanks(line);
+ if (cp[0] == ';' || cp[0] == '#')
+ return 0;
+ strip_line(cp);
+ ch = *cp;
+ if (ch == 0)
+ return 0;
+ if (ch == '[') {
+ if (state->group_level > 0)
+ return PROF_SECTION_NOTOP;
+ cp++;
+ p = strchr(cp, ']');
+ if (p == NULL)
+ return PROF_SECTION_SYNTAX;
+ *p = '\0';
+ retval = profile_find_node_subsection(state->root_section,
+ cp, &iter, 0,
+ &state->current_section);
+ if (retval == PROF_NO_SECTION) {
+ retval = profile_add_node(state->root_section,
+ cp, 0,
+ &state->current_section);
+ if (retval)
+ return retval;
+ } else if (retval)
+ return retval;
+
+ /*
+ * Finish off the rest of the line.
+ */
+ cp = p+1;
+ if (*cp == '*') {
+ profile_make_node_final(state->current_section);
+ cp++;
+ }
+ /*
+ * A space after ']' should not be fatal
+ */
+ cp = skip_over_blanks(cp);
+ if (*cp)
+ return PROF_SECTION_SYNTAX;
+ return 0;
+ }
+ if (ch == '}') {
+ if (state->group_level == 0)
+ return PROF_EXTRA_CBRACE;
+ if (*(cp+1) == '*')
+ profile_make_node_final(state->current_section);
+ retval = profile_get_node_parent(state->current_section,
+ &state->current_section);
+ if (retval)
+ return retval;
+ state->group_level--;
+ return 0;
+ }
+ /*
+ * Parse the relations
+ */
+ tag = cp;
+ cp = strchr(cp, '=');
+ if (!cp)
+ return PROF_RELATION_SYNTAX;
+ if (cp == tag)
+ return PROF_RELATION_SYNTAX;
+ *cp = '\0';
+ p = tag;
+ /* Look for whitespace on left-hand side. */
+ while (p < cp && !isspace((int)*p))
+ p++;
+ if (p < cp) {
+ /* Found some sort of whitespace. */
+ *p++ = 0;
+ /* If we have more non-whitespace, it's an error. */
+ while (p < cp) {
+ if (!isspace((int)*p))
+ return PROF_RELATION_SYNTAX;
+ p++;
+ }
+ }
+ cp = skip_over_blanks(cp+1);
+ value = cp;
+ if (value[0] == '"') {
+ value++;
+ parse_quoted_string(value);
+ } else if (value[0] == 0) {
+ do_subsection++;
+ state->state = STATE_GET_OBRACE;
+ } else if (value[0] == '{' && *(skip_over_blanks(value+1)) == 0)
+ do_subsection++;
+ else {
+ cp = value + strlen(value) - 1;
+ while ((cp > value) && isspace((int) (*cp)))
+ *cp-- = 0;
+ }
+ if (do_subsection) {
+ p = strchr(tag, '*');
+ if (p)
+ *p = '\0';
+ retval = profile_add_node(state->current_section,
+ tag, 0, &state->current_section);
+ if (retval)
+ return retval;
+ if (p)
+ profile_make_node_final(state->current_section);
+ state->group_level++;
+ return 0;
+ }
+ p = strchr(tag, '*');
+ if (p)
+ *p = '\0';
+ profile_add_node(state->current_section, tag, value, &node);
+ if (p)
+ profile_make_node_final(node);
+ return 0;
}
static errcode_t parse_line(char *line, struct parse_state *state)
{
- char *cp;
-
- switch (state->state) {
- case STATE_INIT_COMMENT:
- if (line[0] != '[')
- return 0;
- state->state = STATE_STD_LINE;
- case STATE_STD_LINE:
- return parse_std_line(line, state);
- case STATE_GET_OBRACE:
- cp = skip_over_blanks(line);
- if (*cp != '{')
- return PROF_MISSING_OBRACE;
- state->state = STATE_STD_LINE;
- }
- return 0;
+ char *cp;
+
+ switch (state->state) {
+ case STATE_INIT_COMMENT:
+ if (line[0] != '[')
+ return 0;
+ state->state = STATE_STD_LINE;
+ case STATE_STD_LINE:
+ return parse_std_line(line, state);
+ case STATE_GET_OBRACE:
+ cp = skip_over_blanks(line);
+ if (*cp != '{')
+ return PROF_MISSING_OBRACE;
+ state->state = STATE_STD_LINE;
+ }
+ return 0;
}
errcode_t profile_parse_file(FILE *f, struct profile_node **root)
{
-#define BUF_SIZE 2048
- char *bptr;
- errcode_t retval;
- struct parse_state state;
-
- bptr = malloc (BUF_SIZE);
- if (!bptr)
- return ENOMEM;
-
- retval = parse_init_state(&state);
- if (retval) {
- free (bptr);
- return retval;
- }
- while (!feof(f)) {
- if (fgets(bptr, BUF_SIZE, f) == NULL)
- break;
+#define BUF_SIZE 2048
+ char *bptr;
+ errcode_t retval;
+ struct parse_state state;
+
+ bptr = malloc (BUF_SIZE);
+ if (!bptr)
+ return ENOMEM;
+
+ retval = parse_init_state(&state);
+ if (retval) {
+ free (bptr);
+ return retval;
+ }
+ while (!feof(f)) {
+ if (fgets(bptr, BUF_SIZE, f) == NULL)
+ break;
#ifndef PROFILE_SUPPORTS_FOREIGN_NEWLINES
- retval = parse_line(bptr, &state);
- if (retval) {
- profile_free_node(state.root_section);
- free (bptr);
- return retval;
- }
+ retval = parse_line(bptr, &state);
+ if (retval) {
+ profile_free_node(state.root_section);
+ free (bptr);
+ return retval;
+ }
#else
- {
- char *p, *end;
-
- if (strlen(bptr) >= BUF_SIZE - 1) {
- /* The string may have foreign newlines and
- gotten chopped off on a non-newline
- boundary. Seek backwards to the last known
- newline. */
- long offset;
- char *c = bptr + strlen (bptr);
- for (offset = 0; offset > -BUF_SIZE; offset--) {
- if (*c == '\r' || *c == '\n') {
- *c = '\0';
- fseek (f, offset, SEEK_CUR);
- break;
- }
- c--;
- }
- }
-
- /* First change all newlines to \n */
- for (p = bptr; *p != '\0'; p++) {
- if (*p == '\r')
- *p = '\n';
- }
- /* Then parse all lines */
- p = bptr;
- end = bptr + strlen (bptr);
- while (p < end) {
- char* newline;
- char* newp;
-
- newline = strchr (p, '\n');
- if (newline != NULL)
- *newline = '\0';
-
- /* parse_line modifies contents of p */
- newp = p + strlen (p) + 1;
- retval = parse_line (p, &state);
- if (retval) {
- profile_free_node(state.root_section);
- free (bptr);
- return retval;
- }
-
- p = newp;
- }
- }
+ {
+ char *p, *end;
+
+ if (strlen(bptr) >= BUF_SIZE - 1) {
+ /* The string may have foreign newlines and
+ gotten chopped off on a non-newline
+ boundary. Seek backwards to the last known
+ newline. */
+ long offset;
+ char *c = bptr + strlen (bptr);
+ for (offset = 0; offset > -BUF_SIZE; offset--) {
+ if (*c == '\r' || *c == '\n') {
+ *c = '\0';
+ fseek (f, offset, SEEK_CUR);
+ break;
+ }
+ c--;
+ }
+ }
+
+ /* First change all newlines to \n */
+ for (p = bptr; *p != '\0'; p++) {
+ if (*p == '\r')
+ *p = '\n';
+ }
+ /* Then parse all lines */
+ p = bptr;
+ end = bptr + strlen (bptr);
+ while (p < end) {
+ char* newline;
+ char* newp;
+
+ newline = strchr (p, '\n');
+ if (newline != NULL)
+ *newline = '\0';
+
+ /* parse_line modifies contents of p */
+ newp = p + strlen (p) + 1;
+ retval = parse_line (p, &state);
+ if (retval) {
+ profile_free_node(state.root_section);
+ free (bptr);
+ return retval;
+ }
+
+ p = newp;
+ }
+ }
#endif
- }
- *root = state.root_section;
+ }
+ *root = state.root_section;
- free (bptr);
- return 0;
+ free (bptr);
+ return 0;
}
/*
*/
static int need_double_quotes(char *str)
{
- if (!str)
- return 0;
- if (str[0] == '\0')
- return 1;
- if (isspace((int) (*str)) ||isspace((int) (*(str + strlen(str) - 1))))
- return 1;
- if (strchr(str, '\n') || strchr(str, '\t') || strchr(str, '\b'))
- return 1;
- return 0;
+ if (!str)
+ return 0;
+ if (str[0] == '\0')
+ return 1;
+ if (isspace((int) (*str)) ||isspace((int) (*(str + strlen(str) - 1))))
+ return 1;
+ if (strchr(str, '\n') || strchr(str, '\t') || strchr(str, '\b'))
+ return 1;
+ return 0;
}
/*
* of characters as necessary.
*/
static void output_quoted_string(char *str, void (*cb)(const char *,void *),
- void *data)
+ void *data)
{
- char ch;
- char buf[2];
-
- cb("\"", data);
- if (!str) {
- cb("\"", data);
- return;
- }
- buf[1] = 0;
- while ((ch = *str++)) {
- switch (ch) {
- case '\\':
- cb("\\\\", data);
- break;
- case '\n':
- cb("\\n", data);
- break;
- case '\t':
- cb("\\t", data);
- break;
- case '\b':
- cb("\\b", data);
- break;
- default:
- /* This would be a lot faster if we scanned
- forward for the next "interesting"
- character. */
- buf[0] = ch;
- cb(buf, data);
- break;
- }
- }
- cb("\"", data);
+ char ch;
+ char buf[2];
+
+ cb("\"", data);
+ if (!str) {
+ cb("\"", data);
+ return;
+ }
+ buf[1] = 0;
+ while ((ch = *str++)) {
+ switch (ch) {
+ case '\\':
+ cb("\\\\", data);
+ break;
+ case '\n':
+ cb("\\n", data);
+ break;
+ case '\t':
+ cb("\\t", data);
+ break;
+ case '\b':
+ cb("\\b", data);
+ break;
+ default:
+ /* This would be a lot faster if we scanned
+ forward for the next "interesting"
+ character. */
+ buf[0] = ch;
+ cb(buf, data);
+ break;
+ }
+ }
+ cb("\"", data);
}
/* Errors should be returned, not ignored! */
static void dump_profile(struct profile_node *root, int level,
- void (*cb)(const char *, void *), void *data)
+ void (*cb)(const char *, void *), void *data)
{
- int i;
- struct profile_node *p;
- void *iter;
- long retval;
- char *name, *value;
-
- iter = 0;
- do {
- retval = profile_find_node_relation(root, 0, &iter,
- &name, &value);
- if (retval)
- break;
- for (i=0; i < level; i++)
- cb("\t", data);
- if (need_double_quotes(value)) {
- cb(name, data);
- cb(" = ", data);
- output_quoted_string(value, cb, data);
- cb(EOL, data);
- } else {
- cb(name, data);
- cb(" = ", data);
- cb(value, data);
- cb(EOL, data);
- }
- } while (iter != 0);
-
- iter = 0;
- do {
- retval = profile_find_node_subsection(root, 0, &iter,
- &name, &p);
- if (retval)
- break;
- if (level == 0) { /* [xxx] */
- cb("[", data);
- cb(name, data);
- cb("]", data);
- cb(profile_is_node_final(p) ? "*" : "", data);
- cb(EOL, data);
- dump_profile(p, level+1, cb, data);
- cb(EOL, data);
- } else { /* xxx = { ... } */
- for (i=0; i < level; i++)
- cb("\t", data);
- cb(name, data);
- cb(" = {", data);
- cb(EOL, data);
- dump_profile(p, level+1, cb, data);
- for (i=0; i < level; i++)
- cb("\t", data);
- cb("}", data);
- cb(profile_is_node_final(p) ? "*" : "", data);
- cb(EOL, data);
- }
- } while (iter != 0);
+ int i;
+ struct profile_node *p;
+ void *iter;
+ long retval;
+ char *name, *value;
+
+ iter = 0;
+ do {
+ retval = profile_find_node_relation(root, 0, &iter,
+ &name, &value);
+ if (retval)
+ break;
+ for (i=0; i < level; i++)
+ cb("\t", data);
+ if (need_double_quotes(value)) {
+ cb(name, data);
+ cb(" = ", data);
+ output_quoted_string(value, cb, data);
+ cb(EOL, data);
+ } else {
+ cb(name, data);
+ cb(" = ", data);
+ cb(value, data);
+ cb(EOL, data);
+ }
+ } while (iter != 0);
+
+ iter = 0;
+ do {
+ retval = profile_find_node_subsection(root, 0, &iter,
+ &name, &p);
+ if (retval)
+ break;
+ if (level == 0) { /* [xxx] */
+ cb("[", data);
+ cb(name, data);
+ cb("]", data);
+ cb(profile_is_node_final(p) ? "*" : "", data);
+ cb(EOL, data);
+ dump_profile(p, level+1, cb, data);
+ cb(EOL, data);
+ } else { /* xxx = { ... } */
+ for (i=0; i < level; i++)
+ cb("\t", data);
+ cb(name, data);
+ cb(" = {", data);
+ cb(EOL, data);
+ dump_profile(p, level+1, cb, data);
+ for (i=0; i < level; i++)
+ cb("\t", data);
+ cb("}", data);
+ cb(profile_is_node_final(p) ? "*" : "", data);
+ cb(EOL, data);
+ }
+ } while (iter != 0);
}
static void dump_profile_to_file_cb(const char *str, void *data)
{
- fputs(str, data);
+ fputs(str, data);
}
errcode_t profile_write_tree_file(struct profile_node *root, FILE *dstfile)
{
- dump_profile(root, 0, dump_profile_to_file_cb, dstfile);
- return 0;
+ dump_profile(root, 0, dump_profile_to_file_cb, dstfile);
+ return 0;
}
struct prof_buf {
- char *base;
- size_t cur, max;
- int err;
+ char *base;
+ size_t cur, max;
+ int err;
};
static void add_data_to_buffer(struct prof_buf *b, const void *d, size_t len)
{
- if (b->err)
- return;
- if (b->max - b->cur < len) {
- size_t newsize;
- char *newptr;
-
- newsize = b->max + (b->max >> 1) + len + 1024;
- newptr = realloc(b->base, newsize);
- if (newptr == NULL) {
- b->err = 1;
- return;
- }
- b->base = newptr;
- b->max = newsize;
- }
- memcpy(b->base + b->cur, d, len);
- b->cur += len; /* ignore overflow */
+ if (b->err)
+ return;
+ if (b->max - b->cur < len) {
+ size_t newsize;
+ char *newptr;
+
+ newsize = b->max + (b->max >> 1) + len + 1024;
+ newptr = realloc(b->base, newsize);
+ if (newptr == NULL) {
+ b->err = 1;
+ return;
+ }
+ b->base = newptr;
+ b->max = newsize;
+ }
+ memcpy(b->base + b->cur, d, len);
+ b->cur += len; /* ignore overflow */
}
static void dump_profile_to_buffer_cb(const char *str, void *data)
{
- add_data_to_buffer((struct prof_buf *)data, str, strlen(str));
+ add_data_to_buffer((struct prof_buf *)data, str, strlen(str));
}
errcode_t profile_write_tree_to_buffer(struct profile_node *root,
- char **buf)
+ char **buf)
{
- struct prof_buf prof_buf = { 0, 0, 0, 0 };
-
- dump_profile(root, 0, dump_profile_to_buffer_cb, &prof_buf);
- if (prof_buf.err) {
- *buf = NULL;
- return ENOMEM;
- }
- add_data_to_buffer(&prof_buf, "", 1); /* append nul */
- if (prof_buf.max - prof_buf.cur > (prof_buf.max >> 3)) {
- char *newptr = realloc(prof_buf.base, prof_buf.cur);
- if (newptr)
- prof_buf.base = newptr;
- }
- *buf = prof_buf.base;
- return 0;
+ struct prof_buf prof_buf = { 0, 0, 0, 0 };
+
+ dump_profile(root, 0, dump_profile_to_buffer_cb, &prof_buf);
+ if (prof_buf.err) {
+ *buf = NULL;
+ return ENOMEM;
+ }
+ add_data_to_buffer(&prof_buf, "", 1); /* append nul */
+ if (prof_buf.max - prof_buf.cur > (prof_buf.max >> 3)) {
+ char *newptr = realloc(prof_buf.base, prof_buf.cur);
+ if (newptr)
+ prof_buf.base = newptr;
+ }
+ *buf = prof_buf.base;
+ return 0;
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* prof_set.c --- routines that expose the public interfaces for
- * inserting, updating and deleting items from the profile.
+ * inserting, updating and deleting items from the profile.
*
* WARNING: These routines only look at the first file opened in the
* profile. It's not clear how to handle multiple files, actually.
static errcode_t rw_setup(profile_t profile)
{
- prf_file_t file;
- errcode_t retval = 0;
-
- if (!profile)
- return PROF_NO_PROFILE;
-
- if (profile->magic != PROF_MAGIC_PROFILE)
- return PROF_MAGIC_PROFILE;
-
- file = profile->first_file;
-
- retval = profile_lock_global();
- if (retval)
- return retval;
-
- /* Don't update the file if we've already made modifications */
- if (file->data->flags & PROFILE_FILE_DIRTY) {
- profile_unlock_global();
- return 0;
- }
-
- if ((file->data->flags & PROFILE_FILE_SHARED) != 0) {
- prf_data_t new_data;
- new_data = profile_make_prf_data(file->data->filespec);
- if (new_data == NULL) {
- retval = ENOMEM;
- } else {
- retval = k5_mutex_init(&new_data->lock);
- if (retval == 0) {
- new_data->root = NULL;
- new_data->flags = file->data->flags & ~PROFILE_FILE_SHARED;
- new_data->timestamp = 0;
- new_data->upd_serial = file->data->upd_serial;
- }
- }
-
- if (retval != 0) {
- profile_unlock_global();
- free(new_data);
- return retval;
- }
- profile_dereference_data_locked(file->data);
- file->data = new_data;
- }
-
- profile_unlock_global();
- retval = profile_update_file(file);
-
- return retval;
+ prf_file_t file;
+ errcode_t retval = 0;
+
+ if (!profile)
+ return PROF_NO_PROFILE;
+
+ if (profile->magic != PROF_MAGIC_PROFILE)
+ return PROF_MAGIC_PROFILE;
+
+ file = profile->first_file;
+
+ retval = profile_lock_global();
+ if (retval)
+ return retval;
+
+ /* Don't update the file if we've already made modifications */
+ if (file->data->flags & PROFILE_FILE_DIRTY) {
+ profile_unlock_global();
+ return 0;
+ }
+
+ if ((file->data->flags & PROFILE_FILE_SHARED) != 0) {
+ prf_data_t new_data;
+ new_data = profile_make_prf_data(file->data->filespec);
+ if (new_data == NULL) {
+ retval = ENOMEM;
+ } else {
+ retval = k5_mutex_init(&new_data->lock);
+ if (retval == 0) {
+ new_data->root = NULL;
+ new_data->flags = file->data->flags & ~PROFILE_FILE_SHARED;
+ new_data->timestamp = 0;
+ new_data->upd_serial = file->data->upd_serial;
+ }
+ }
+
+ if (retval != 0) {
+ profile_unlock_global();
+ free(new_data);
+ return retval;
+ }
+ profile_dereference_data_locked(file->data);
+ file->data = new_data;
+ }
+
+ profile_unlock_global();
+ retval = profile_update_file(file);
+
+ return retval;
}
*/
errcode_t KRB5_CALLCONV
profile_update_relation(profile_t profile, const char **names,
- const char *old_value, const char *new_value)
+ const char *old_value, const char *new_value)
{
- errcode_t retval;
- struct profile_node *section, *node;
- void *state;
- const char **cpp;
-
- retval = rw_setup(profile);
- if (retval)
- return retval;
-
- if (names == 0 || names[0] == 0 || names[1] == 0)
- return PROF_BAD_NAMESET;
-
- if (!old_value || !*old_value)
- return PROF_EINVAL;
-
- retval = k5_mutex_lock(&profile->first_file->data->lock);
- if (retval)
- return retval;
- section = profile->first_file->data->root;
- for (cpp = names; cpp[1]; cpp++) {
- state = 0;
- retval = profile_find_node(section, *cpp, 0, 1,
- &state, §ion);
- if (retval) {
- k5_mutex_unlock(&profile->first_file->data->lock);
- return retval;
- }
- }
-
- state = 0;
- retval = profile_find_node(section, *cpp, old_value, 0, &state, &node);
- if (retval == 0) {
- if (new_value)
- retval = profile_set_relation_value(node, new_value);
- else
- retval = profile_remove_node(node);
- }
- if (retval == 0)
- profile->first_file->data->flags |= PROFILE_FILE_DIRTY;
- k5_mutex_unlock(&profile->first_file->data->lock);
-
- return retval;
+ errcode_t retval;
+ struct profile_node *section, *node;
+ void *state;
+ const char **cpp;
+
+ retval = rw_setup(profile);
+ if (retval)
+ return retval;
+
+ if (names == 0 || names[0] == 0 || names[1] == 0)
+ return PROF_BAD_NAMESET;
+
+ if (!old_value || !*old_value)
+ return PROF_EINVAL;
+
+ retval = k5_mutex_lock(&profile->first_file->data->lock);
+ if (retval)
+ return retval;
+ section = profile->first_file->data->root;
+ for (cpp = names; cpp[1]; cpp++) {
+ state = 0;
+ retval = profile_find_node(section, *cpp, 0, 1,
+ &state, §ion);
+ if (retval) {
+ k5_mutex_unlock(&profile->first_file->data->lock);
+ return retval;
+ }
+ }
+
+ state = 0;
+ retval = profile_find_node(section, *cpp, old_value, 0, &state, &node);
+ if (retval == 0) {
+ if (new_value)
+ retval = profile_set_relation_value(node, new_value);
+ else
+ retval = profile_remove_node(node);
+ }
+ if (retval == 0)
+ profile->first_file->data->flags |= PROFILE_FILE_DIRTY;
+ k5_mutex_unlock(&profile->first_file->data->lock);
+
+ return retval;
}
/*
errcode_t KRB5_CALLCONV
profile_clear_relation(profile_t profile, const char **names)
{
- errcode_t retval;
- struct profile_node *section, *node;
- void *state;
- const char **cpp;
-
- retval = rw_setup(profile);
- if (retval)
- return retval;
-
- if (names == 0 || names[0] == 0 || names[1] == 0)
- return PROF_BAD_NAMESET;
-
- section = profile->first_file->data->root;
- for (cpp = names; cpp[1]; cpp++) {
- state = 0;
- retval = profile_find_node(section, *cpp, 0, 1,
- &state, §ion);
- if (retval)
- return retval;
- }
-
- state = 0;
- do {
- retval = profile_find_node(section, *cpp, 0, 0, &state, &node);
- if (retval)
- return retval;
- retval = profile_remove_node(node);
- if (retval)
- return retval;
- } while (state);
-
- profile->first_file->data->flags |= PROFILE_FILE_DIRTY;
-
- return 0;
+ errcode_t retval;
+ struct profile_node *section, *node;
+ void *state;
+ const char **cpp;
+
+ retval = rw_setup(profile);
+ if (retval)
+ return retval;
+
+ if (names == 0 || names[0] == 0 || names[1] == 0)
+ return PROF_BAD_NAMESET;
+
+ section = profile->first_file->data->root;
+ for (cpp = names; cpp[1]; cpp++) {
+ state = 0;
+ retval = profile_find_node(section, *cpp, 0, 1,
+ &state, §ion);
+ if (retval)
+ return retval;
+ }
+
+ state = 0;
+ do {
+ retval = profile_find_node(section, *cpp, 0, 0, &state, &node);
+ if (retval)
+ return retval;
+ retval = profile_remove_node(node);
+ if (retval)
+ return retval;
+ } while (state);
+
+ profile->first_file->data->flags |= PROFILE_FILE_DIRTY;
+
+ return 0;
}
/*
*/
errcode_t KRB5_CALLCONV
profile_rename_section(profile_t profile, const char **names,
- const char *new_name)
+ const char *new_name)
{
- errcode_t retval;
- struct profile_node *section, *node;
- void *state;
- const char **cpp;
-
- retval = rw_setup(profile);
- if (retval)
- return retval;
-
- if (names == 0 || names[0] == 0 || names[1] == 0)
- return PROF_BAD_NAMESET;
-
- retval = k5_mutex_lock(&profile->first_file->data->lock);
- if (retval)
- return retval;
- section = profile->first_file->data->root;
- for (cpp = names; cpp[1]; cpp++) {
- state = 0;
- retval = profile_find_node(section, *cpp, 0, 1,
- &state, §ion);
- if (retval) {
- k5_mutex_unlock(&profile->first_file->data->lock);
- return retval;
- }
- }
-
- state = 0;
- retval = profile_find_node(section, *cpp, 0, 1, &state, &node);
- if (retval == 0) {
- if (new_name)
- retval = profile_rename_node(node, new_name);
- else
- retval = profile_remove_node(node);
- }
- if (retval == 0)
- profile->first_file->data->flags |= PROFILE_FILE_DIRTY;
- k5_mutex_unlock(&profile->first_file->data->lock);
- return retval;
+ errcode_t retval;
+ struct profile_node *section, *node;
+ void *state;
+ const char **cpp;
+
+ retval = rw_setup(profile);
+ if (retval)
+ return retval;
+
+ if (names == 0 || names[0] == 0 || names[1] == 0)
+ return PROF_BAD_NAMESET;
+
+ retval = k5_mutex_lock(&profile->first_file->data->lock);
+ if (retval)
+ return retval;
+ section = profile->first_file->data->root;
+ for (cpp = names; cpp[1]; cpp++) {
+ state = 0;
+ retval = profile_find_node(section, *cpp, 0, 1,
+ &state, §ion);
+ if (retval) {
+ k5_mutex_unlock(&profile->first_file->data->lock);
+ return retval;
+ }
+ }
+
+ state = 0;
+ retval = profile_find_node(section, *cpp, 0, 1, &state, &node);
+ if (retval == 0) {
+ if (new_name)
+ retval = profile_rename_node(node, new_name);
+ else
+ retval = profile_remove_node(node);
+ }
+ if (retval == 0)
+ profile->first_file->data->flags |= PROFILE_FILE_DIRTY;
+ k5_mutex_unlock(&profile->first_file->data->lock);
+ return retval;
}
/*
*/
errcode_t KRB5_CALLCONV
profile_add_relation(profile_t profile, const char **names,
- const char *new_value)
+ const char *new_value)
{
- errcode_t retval;
- struct profile_node *section;
- const char **cpp;
- void *state;
-
- retval = rw_setup(profile);
- if (retval)
- return retval;
-
- if (names == 0 || names[0] == 0 || names[1] == 0)
- return PROF_BAD_NAMESET;
-
- retval = k5_mutex_lock(&profile->first_file->data->lock);
- if (retval)
- return retval;
- section = profile->first_file->data->root;
- for (cpp = names; cpp[1]; cpp++) {
- state = 0;
- retval = profile_find_node(section, *cpp, 0, 1,
- &state, §ion);
- if (retval == PROF_NO_SECTION)
- retval = profile_add_node(section, *cpp, 0, §ion);
- if (retval) {
- k5_mutex_unlock(&profile->first_file->data->lock);
- return retval;
- }
- }
-
- if (new_value == 0) {
- retval = profile_find_node(section, *cpp, 0, 1, &state, 0);
- if (retval == 0) {
- k5_mutex_unlock(&profile->first_file->data->lock);
- return PROF_EXISTS;
- } else if (retval != PROF_NO_SECTION) {
- k5_mutex_unlock(&profile->first_file->data->lock);
- return retval;
- }
- }
-
- retval = profile_add_node(section, *cpp, new_value, 0);
- if (retval) {
- k5_mutex_unlock(&profile->first_file->data->lock);
- return retval;
- }
-
- profile->first_file->data->flags |= PROFILE_FILE_DIRTY;
- k5_mutex_unlock(&profile->first_file->data->lock);
- return 0;
+ errcode_t retval;
+ struct profile_node *section;
+ const char **cpp;
+ void *state;
+
+ retval = rw_setup(profile);
+ if (retval)
+ return retval;
+
+ if (names == 0 || names[0] == 0 || names[1] == 0)
+ return PROF_BAD_NAMESET;
+
+ retval = k5_mutex_lock(&profile->first_file->data->lock);
+ if (retval)
+ return retval;
+ section = profile->first_file->data->root;
+ for (cpp = names; cpp[1]; cpp++) {
+ state = 0;
+ retval = profile_find_node(section, *cpp, 0, 1,
+ &state, §ion);
+ if (retval == PROF_NO_SECTION)
+ retval = profile_add_node(section, *cpp, 0, §ion);
+ if (retval) {
+ k5_mutex_unlock(&profile->first_file->data->lock);
+ return retval;
+ }
+ }
+
+ if (new_value == 0) {
+ retval = profile_find_node(section, *cpp, 0, 1, &state, 0);
+ if (retval == 0) {
+ k5_mutex_unlock(&profile->first_file->data->lock);
+ return PROF_EXISTS;
+ } else if (retval != PROF_NO_SECTION) {
+ k5_mutex_unlock(&profile->first_file->data->lock);
+ return retval;
+ }
+ }
+
+ retval = profile_add_node(section, *cpp, new_value, 0);
+ if (retval) {
+ k5_mutex_unlock(&profile->first_file->data->lock);
+ return retval;
+ }
+
+ profile->first_file->data->flags |= PROFILE_FILE_DIRTY;
+ k5_mutex_unlock(&profile->first_file->data->lock);
+ return 0;
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* prof_tree.c --- these routines maintain the parse tree of the
- * config file.
+ * config file.
*
* All of the details of how the tree is stored is abstracted away in
* this file; all of the other profile routines build, access, and
#include <ctype.h>
struct profile_node {
- errcode_t magic;
- char *name;
- char *value;
- int group_level;
- unsigned int final:1; /* Indicate don't search next file */
- unsigned int deleted:1;
- struct profile_node *first_child;
- struct profile_node *parent;
- struct profile_node *next, *prev;
+ errcode_t magic;
+ char *name;
+ char *value;
+ int group_level;
+ unsigned int final:1; /* Indicate don't search next file */
+ unsigned int deleted:1;
+ struct profile_node *first_child;
+ struct profile_node *parent;
+ struct profile_node *next, *prev;
};
-#define CHECK_MAGIC(node) \
- if ((node)->magic != PROF_MAGIC_NODE) \
- return PROF_MAGIC_NODE;
+#define CHECK_MAGIC(node) \
+ if ((node)->magic != PROF_MAGIC_NODE) \
+ return PROF_MAGIC_NODE;
/*
* Free a node, and any children
*/
void profile_free_node(struct profile_node *node)
{
- struct profile_node *child, *next;
+ struct profile_node *child, *next;
- if (node->magic != PROF_MAGIC_NODE)
- return;
+ if (node->magic != PROF_MAGIC_NODE)
+ return;
- if (node->name)
- free(node->name);
- if (node->value)
- free(node->value);
+ if (node->name)
+ free(node->name);
+ if (node->value)
+ free(node->value);
- for (child=node->first_child; child; child = next) {
- next = child->next;
- profile_free_node(child);
- }
- node->magic = 0;
+ for (child=node->first_child; child; child = next) {
+ next = child->next;
+ profile_free_node(child);
+ }
+ node->magic = 0;
- free(node);
+ free(node);
}
#ifndef HAVE_STRDUP
size_t sz = strlen(s) + 1;
char *p = malloc(sz);
if (p != 0)
- memcpy(p, s, sz);
+ memcpy(p, s, sz);
return p;
}
#endif
* Create a node
*/
errcode_t profile_create_node(const char *name, const char *value,
- struct profile_node **ret_node)
+ struct profile_node **ret_node)
{
- struct profile_node *new;
-
- new = malloc(sizeof(struct profile_node));
- if (!new)
- return ENOMEM;
- memset(new, 0, sizeof(struct profile_node));
- /* Set magic here so profile_free_node will free memory */
- new->magic = PROF_MAGIC_NODE;
- new->name = strdup(name);
- if (new->name == 0) {
- profile_free_node(new);
- return ENOMEM;
- }
- if (value) {
- new->value = strdup(value);
- if (new->value == 0) {
- profile_free_node(new);
- return ENOMEM;
- }
- }
-
- *ret_node = new;
- return 0;
+ struct profile_node *new;
+
+ new = malloc(sizeof(struct profile_node));
+ if (!new)
+ return ENOMEM;
+ memset(new, 0, sizeof(struct profile_node));
+ /* Set magic here so profile_free_node will free memory */
+ new->magic = PROF_MAGIC_NODE;
+ new->name = strdup(name);
+ if (new->name == 0) {
+ profile_free_node(new);
+ return ENOMEM;
+ }
+ if (value) {
+ new->value = strdup(value);
+ if (new->value == 0) {
+ profile_free_node(new);
+ return ENOMEM;
+ }
+ }
+
+ *ret_node = new;
+ return 0;
}
/*
*/
errcode_t profile_verify_node(struct profile_node *node)
{
- struct profile_node *p, *last;
- errcode_t retval;
-
- CHECK_MAGIC(node);
-
- if (node->value && node->first_child)
- return PROF_SECTION_WITH_VALUE;
-
- last = 0;
- for (p = node->first_child; p; last = p, p = p->next) {
- if (p->prev != last)
- return PROF_BAD_LINK_LIST;
- if (last && (last->next != p))
- return PROF_BAD_LINK_LIST;
- if (node->group_level+1 != p->group_level)
- return PROF_BAD_GROUP_LVL;
- if (p->parent != node)
- return PROF_BAD_PARENT_PTR;
- retval = profile_verify_node(p);
- if (retval)
- return retval;
- }
- return 0;
+ struct profile_node *p, *last;
+ errcode_t retval;
+
+ CHECK_MAGIC(node);
+
+ if (node->value && node->first_child)
+ return PROF_SECTION_WITH_VALUE;
+
+ last = 0;
+ for (p = node->first_child; p; last = p, p = p->next) {
+ if (p->prev != last)
+ return PROF_BAD_LINK_LIST;
+ if (last && (last->next != p))
+ return PROF_BAD_LINK_LIST;
+ if (node->group_level+1 != p->group_level)
+ return PROF_BAD_GROUP_LVL;
+ if (p->parent != node)
+ return PROF_BAD_PARENT_PTR;
+ retval = profile_verify_node(p);
+ if (retval)
+ return retval;
+ }
+ return 0;
}
/*
* Add a node to a particular section
*/
errcode_t profile_add_node(struct profile_node *section, const char *name,
- const char *value, struct profile_node **ret_node)
+ const char *value, struct profile_node **ret_node)
{
- errcode_t retval;
- struct profile_node *p, *last, *new;
-
- CHECK_MAGIC(section);
-
- if (section->value)
- return PROF_ADD_NOT_SECTION;
-
- /*
- * Find the place to insert the new node. We look for the
- * place *after* the last match of the node name, since
- * order matters.
- */
- for (p=section->first_child, last = 0; p; last = p, p = p->next) {
- int cmp;
- cmp = strcmp(p->name, name);
- if (cmp > 0)
- break;
- }
- retval = profile_create_node(name, value, &new);
- if (retval)
- return retval;
- new->group_level = section->group_level+1;
- new->deleted = 0;
- new->parent = section;
- new->prev = last;
- new->next = p;
- if (p)
- p->prev = new;
- if (last)
- last->next = new;
- else
- section->first_child = new;
- if (ret_node)
- *ret_node = new;
- return 0;
+ errcode_t retval;
+ struct profile_node *p, *last, *new;
+
+ CHECK_MAGIC(section);
+
+ if (section->value)
+ return PROF_ADD_NOT_SECTION;
+
+ /*
+ * Find the place to insert the new node. We look for the
+ * place *after* the last match of the node name, since
+ * order matters.
+ */
+ for (p=section->first_child, last = 0; p; last = p, p = p->next) {
+ int cmp;
+ cmp = strcmp(p->name, name);
+ if (cmp > 0)
+ break;
+ }
+ retval = profile_create_node(name, value, &new);
+ if (retval)
+ return retval;
+ new->group_level = section->group_level+1;
+ new->deleted = 0;
+ new->parent = section;
+ new->prev = last;
+ new->next = p;
+ if (p)
+ p->prev = new;
+ if (last)
+ last->next = new;
+ else
+ section->first_child = new;
+ if (ret_node)
+ *ret_node = new;
+ return 0;
}
/*
*/
errcode_t profile_make_node_final(struct profile_node *node)
{
- CHECK_MAGIC(node);
+ CHECK_MAGIC(node);
- node->final = 1;
- return 0;
+ node->final = 1;
+ return 0;
}
/*
*/
int profile_is_node_final(struct profile_node *node)
{
- return (node->final != 0);
+ return (node->final != 0);
}
/*
*/
const char *profile_get_node_name(struct profile_node *node)
{
- return node->name;
+ return node->name;
}
/*
*/
const char *profile_get_node_value(struct profile_node *node)
{
- return node->value;
+ return node->value;
}
/*
*
*/
errcode_t profile_find_node(struct profile_node *section, const char *name,
- const char *value, int section_flag, void **state,
- struct profile_node **node)
+ const char *value, int section_flag, void **state,
+ struct profile_node **node)
{
- struct profile_node *p;
-
- CHECK_MAGIC(section);
- p = *state;
- if (p) {
- CHECK_MAGIC(p);
- } else
- p = section->first_child;
-
- for (; p; p = p->next) {
- if (name && (strcmp(p->name, name)))
- continue;
- if (section_flag) {
- if (p->value)
- continue;
- } else {
- if (!p->value)
- continue;
- if (value && (strcmp(p->value, value)))
- continue;
- }
- if (p->deleted)
- continue;
- /* A match! */
- if (node)
- *node = p;
- break;
- }
- if (p == 0) {
- *state = 0;
- return section_flag ? PROF_NO_SECTION : PROF_NO_RELATION;
- }
- /*
- * OK, we've found one match; now let's try to find another
- * one. This way, if we return a non-zero state pointer,
- * there's guaranteed to be another match that's returned.
- */
- for (p = p->next; p; p = p->next) {
- if (name && (strcmp(p->name, name)))
- continue;
- if (section_flag) {
- if (p->value)
- continue;
- } else {
- if (!p->value)
- continue;
- if (value && (strcmp(p->value, value)))
- continue;
- }
- /* A match! */
- break;
- }
- *state = p;
- return 0;
+ struct profile_node *p;
+
+ CHECK_MAGIC(section);
+ p = *state;
+ if (p) {
+ CHECK_MAGIC(p);
+ } else
+ p = section->first_child;
+
+ for (; p; p = p->next) {
+ if (name && (strcmp(p->name, name)))
+ continue;
+ if (section_flag) {
+ if (p->value)
+ continue;
+ } else {
+ if (!p->value)
+ continue;
+ if (value && (strcmp(p->value, value)))
+ continue;
+ }
+ if (p->deleted)
+ continue;
+ /* A match! */
+ if (node)
+ *node = p;
+ break;
+ }
+ if (p == 0) {
+ *state = 0;
+ return section_flag ? PROF_NO_SECTION : PROF_NO_RELATION;
+ }
+ /*
+ * OK, we've found one match; now let's try to find another
+ * one. This way, if we return a non-zero state pointer,
+ * there's guaranteed to be another match that's returned.
+ */
+ for (p = p->next; p; p = p->next) {
+ if (name && (strcmp(p->name, name)))
+ continue;
+ if (section_flag) {
+ if (p->value)
+ continue;
+ } else {
+ if (!p->value)
+ continue;
+ if (value && (strcmp(p->value, value)))
+ continue;
+ }
+ /* A match! */
+ break;
+ }
+ *state = p;
+ return 0;
}
* exported interface), it should be strdup()'ed.
*/
errcode_t profile_find_node_relation(struct profile_node *section,
- const char *name, void **state,
- char **ret_name, char **value)
+ const char *name, void **state,
+ char **ret_name, char **value)
{
- struct profile_node *p;
- errcode_t retval;
-
- retval = profile_find_node(section, name, 0, 0, state, &p);
- if (retval)
- return retval;
-
- if (p) {
- if (value)
- *value = p->value;
- if (ret_name)
- *ret_name = p->name;
- }
- return 0;
+ struct profile_node *p;
+ errcode_t retval;
+
+ retval = profile_find_node(section, name, 0, 0, state, &p);
+ if (retval)
+ return retval;
+
+ if (p) {
+ if (value)
+ *value = p->value;
+ if (ret_name)
+ *ret_name = p->name;
+ }
+ return 0;
}
/*
* profile_find_node.
*/
errcode_t profile_find_node_subsection(struct profile_node *section,
- const char *name, void **state,
- char **ret_name,
- struct profile_node **subsection)
+ const char *name, void **state,
+ char **ret_name,
+ struct profile_node **subsection)
{
- struct profile_node *p;
- errcode_t retval;
-
- retval = profile_find_node(section, name, 0, 1, state, &p);
- if (retval)
- return retval;
-
- if (p) {
- if (subsection)
- *subsection = p;
- if (ret_name)
- *ret_name = p->name;
- }
- return 0;
+ struct profile_node *p;
+ errcode_t retval;
+
+ retval = profile_find_node(section, name, 0, 1, state, &p);
+ if (retval)
+ return retval;
+
+ if (p) {
+ if (subsection)
+ *subsection = p;
+ if (ret_name)
+ *ret_name = p->name;
+ }
+ return 0;
}
/*
* This function returns the parent of a particular node.
*/
errcode_t profile_get_node_parent(struct profile_node *section,
- struct profile_node **parent)
+ struct profile_node **parent)
{
- *parent = section->parent;
- return 0;
+ *parent = section->parent;
+ return 0;
}
/*
* match the specified name array.
*/
struct profile_iterator {
- prf_magic_t magic;
- profile_t profile;
- int flags;
- const char *const *names;
- const char *name;
- prf_file_t file;
- int file_serial;
- int done_idx;
- struct profile_node *node;
- int num;
+ prf_magic_t magic;
+ profile_t profile;
+ int flags;
+ const char *const *names;
+ const char *name;
+ prf_file_t file;
+ int file_serial;
+ int done_idx;
+ struct profile_node *node;
+ int num;
};
errcode_t profile_node_iterator_create(profile_t profile,
- const char *const *names, int flags,
- void **ret_iter)
+ const char *const *names, int flags,
+ void **ret_iter)
{
- struct profile_iterator *iter;
- int done_idx = 0;
-
- if (profile == 0)
- return PROF_NO_PROFILE;
- if (profile->magic != PROF_MAGIC_PROFILE)
- return PROF_MAGIC_PROFILE;
- if (!names)
- return PROF_BAD_NAMESET;
- if (!(flags & PROFILE_ITER_LIST_SECTION)) {
- if (!names[0])
- return PROF_BAD_NAMESET;
- done_idx = 1;
- }
-
- if ((iter = malloc(sizeof(struct profile_iterator))) == NULL)
- return ENOMEM;
-
- iter->magic = PROF_MAGIC_ITERATOR;
- iter->profile = profile;
- iter->names = names;
- iter->flags = flags;
- iter->file = profile->first_file;
- iter->done_idx = done_idx;
- iter->node = 0;
- iter->num = 0;
- *ret_iter = iter;
- return 0;
+ struct profile_iterator *iter;
+ int done_idx = 0;
+
+ if (profile == 0)
+ return PROF_NO_PROFILE;
+ if (profile->magic != PROF_MAGIC_PROFILE)
+ return PROF_MAGIC_PROFILE;
+ if (!names)
+ return PROF_BAD_NAMESET;
+ if (!(flags & PROFILE_ITER_LIST_SECTION)) {
+ if (!names[0])
+ return PROF_BAD_NAMESET;
+ done_idx = 1;
+ }
+
+ if ((iter = malloc(sizeof(struct profile_iterator))) == NULL)
+ return ENOMEM;
+
+ iter->magic = PROF_MAGIC_ITERATOR;
+ iter->profile = profile;
+ iter->names = names;
+ iter->flags = flags;
+ iter->file = profile->first_file;
+ iter->done_idx = done_idx;
+ iter->node = 0;
+ iter->num = 0;
+ *ret_iter = iter;
+ return 0;
}
void profile_node_iterator_free(void **iter_p)
{
- struct profile_iterator *iter;
-
- if (!iter_p)
- return;
- iter = *iter_p;
- if (!iter || iter->magic != PROF_MAGIC_ITERATOR)
- return;
- free(iter);
- *iter_p = 0;
+ struct profile_iterator *iter;
+
+ if (!iter_p)
+ return;
+ iter = *iter_p;
+ if (!iter || iter->magic != PROF_MAGIC_ITERATOR)
+ return;
+ free(iter);
+ *iter_p = 0;
}
/*
* strdup()'ed.
*/
errcode_t profile_node_iterator(void **iter_p, struct profile_node **ret_node,
- char **ret_name, char **ret_value)
+ char **ret_name, char **ret_value)
{
- struct profile_iterator *iter = *iter_p;
- struct profile_node *section, *p;
- const char *const *cpp;
- errcode_t retval;
- int skip_num = 0;
-
- if (!iter || iter->magic != PROF_MAGIC_ITERATOR)
- return PROF_MAGIC_ITERATOR;
- if (iter->file && iter->file->magic != PROF_MAGIC_FILE)
- return PROF_MAGIC_FILE;
- if (iter->file && iter->file->data->magic != PROF_MAGIC_FILE_DATA)
- return PROF_MAGIC_FILE_DATA;
- /*
- * If the file has changed, then the node pointer is invalid,
- * so we'll have search the file again looking for it.
- */
- if (iter->file) {
- retval = k5_mutex_lock(&iter->file->data->lock);
- if (retval)
- return retval;
- }
- if (iter->node && (iter->file->data->upd_serial != iter->file_serial)) {
- iter->flags &= ~PROFILE_ITER_FINAL_SEEN;
- skip_num = iter->num;
- iter->node = 0;
- }
- if (iter->node && iter->node->magic != PROF_MAGIC_NODE) {
- if (iter->file)
- k5_mutex_unlock(&iter->file->data->lock);
- return PROF_MAGIC_NODE;
- }
+ struct profile_iterator *iter = *iter_p;
+ struct profile_node *section, *p;
+ const char *const *cpp;
+ errcode_t retval;
+ int skip_num = 0;
+
+ if (!iter || iter->magic != PROF_MAGIC_ITERATOR)
+ return PROF_MAGIC_ITERATOR;
+ if (iter->file && iter->file->magic != PROF_MAGIC_FILE)
+ return PROF_MAGIC_FILE;
+ if (iter->file && iter->file->data->magic != PROF_MAGIC_FILE_DATA)
+ return PROF_MAGIC_FILE_DATA;
+ /*
+ * If the file has changed, then the node pointer is invalid,
+ * so we'll have search the file again looking for it.
+ */
+ if (iter->file) {
+ retval = k5_mutex_lock(&iter->file->data->lock);
+ if (retval)
+ return retval;
+ }
+ if (iter->node && (iter->file->data->upd_serial != iter->file_serial)) {
+ iter->flags &= ~PROFILE_ITER_FINAL_SEEN;
+ skip_num = iter->num;
+ iter->node = 0;
+ }
+ if (iter->node && iter->node->magic != PROF_MAGIC_NODE) {
+ if (iter->file)
+ k5_mutex_unlock(&iter->file->data->lock);
+ return PROF_MAGIC_NODE;
+ }
get_new_file:
- if (iter->node == 0) {
- if (iter->file == 0 ||
- (iter->flags & PROFILE_ITER_FINAL_SEEN)) {
- if (iter->file)
- k5_mutex_unlock(&iter->file->data->lock);
- profile_node_iterator_free(iter_p);
- if (ret_node)
- *ret_node = 0;
- if (ret_name)
- *ret_name = 0;
- if (ret_value)
- *ret_value =0;
- return 0;
- }
- if ((retval = profile_update_file_locked(iter->file))) {
- k5_mutex_unlock(&iter->file->data->lock);
- if (retval == ENOENT || retval == EACCES) {
- /* XXX memory leak? */
- iter->file = iter->file->next;
- if (iter->file) {
- retval = k5_mutex_lock(&iter->file->data->lock);
- if (retval) {
- profile_node_iterator_free(iter_p);
- return retval;
- }
- }
- skip_num = 0;
- retval = 0;
- goto get_new_file;
- } else {
- profile_node_iterator_free(iter_p);
- return retval;
- }
- }
- iter->file_serial = iter->file->data->upd_serial;
- /*
- * Find the section to list if we are a LIST_SECTION,
- * or find the containing section if not.
- */
- section = iter->file->data->root;
- assert(section != NULL);
- for (cpp = iter->names; cpp[iter->done_idx]; cpp++) {
- for (p=section->first_child; p; p = p->next) {
- if (!strcmp(p->name, *cpp) && !p->value)
- break;
- }
- if (!p) {
- section = 0;
- break;
- }
- section = p;
- if (p->final)
- iter->flags |= PROFILE_ITER_FINAL_SEEN;
- }
- if (!section) {
- k5_mutex_unlock(&iter->file->data->lock);
- iter->file = iter->file->next;
- if (iter->file) {
- retval = k5_mutex_lock(&iter->file->data->lock);
- if (retval) {
- profile_node_iterator_free(iter_p);
- return retval;
- }
- }
- skip_num = 0;
- goto get_new_file;
- }
- iter->name = *cpp;
- iter->node = section->first_child;
- }
- /*
- * OK, now we know iter->node is set up correctly. Let's do
- * the search.
- */
- for (p = iter->node; p; p = p->next) {
- if (iter->name && strcmp(p->name, iter->name))
- continue;
- if ((iter->flags & PROFILE_ITER_SECTIONS_ONLY) &&
- p->value)
- continue;
- if ((iter->flags & PROFILE_ITER_RELATIONS_ONLY) &&
- !p->value)
- continue;
- if (skip_num > 0) {
- skip_num--;
- continue;
- }
- if (p->deleted)
- continue;
- break;
- }
- iter->num++;
- if (!p) {
- k5_mutex_unlock(&iter->file->data->lock);
- iter->file = iter->file->next;
- if (iter->file) {
- retval = k5_mutex_lock(&iter->file->data->lock);
- if (retval) {
- profile_node_iterator_free(iter_p);
- return retval;
- }
- }
- iter->node = 0;
- skip_num = 0;
- goto get_new_file;
- }
- k5_mutex_unlock(&iter->file->data->lock);
- if ((iter->node = p->next) == NULL)
- iter->file = iter->file->next;
- if (ret_node)
- *ret_node = p;
- if (ret_name)
- *ret_name = p->name;
- if (ret_value)
- *ret_value = p->value;
- return 0;
+ if (iter->node == 0) {
+ if (iter->file == 0 ||
+ (iter->flags & PROFILE_ITER_FINAL_SEEN)) {
+ if (iter->file)
+ k5_mutex_unlock(&iter->file->data->lock);
+ profile_node_iterator_free(iter_p);
+ if (ret_node)
+ *ret_node = 0;
+ if (ret_name)
+ *ret_name = 0;
+ if (ret_value)
+ *ret_value =0;
+ return 0;
+ }
+ if ((retval = profile_update_file_locked(iter->file))) {
+ k5_mutex_unlock(&iter->file->data->lock);
+ if (retval == ENOENT || retval == EACCES) {
+ /* XXX memory leak? */
+ iter->file = iter->file->next;
+ if (iter->file) {
+ retval = k5_mutex_lock(&iter->file->data->lock);
+ if (retval) {
+ profile_node_iterator_free(iter_p);
+ return retval;
+ }
+ }
+ skip_num = 0;
+ retval = 0;
+ goto get_new_file;
+ } else {
+ profile_node_iterator_free(iter_p);
+ return retval;
+ }
+ }
+ iter->file_serial = iter->file->data->upd_serial;
+ /*
+ * Find the section to list if we are a LIST_SECTION,
+ * or find the containing section if not.
+ */
+ section = iter->file->data->root;
+ assert(section != NULL);
+ for (cpp = iter->names; cpp[iter->done_idx]; cpp++) {
+ for (p=section->first_child; p; p = p->next) {
+ if (!strcmp(p->name, *cpp) && !p->value)
+ break;
+ }
+ if (!p) {
+ section = 0;
+ break;
+ }
+ section = p;
+ if (p->final)
+ iter->flags |= PROFILE_ITER_FINAL_SEEN;
+ }
+ if (!section) {
+ k5_mutex_unlock(&iter->file->data->lock);
+ iter->file = iter->file->next;
+ if (iter->file) {
+ retval = k5_mutex_lock(&iter->file->data->lock);
+ if (retval) {
+ profile_node_iterator_free(iter_p);
+ return retval;
+ }
+ }
+ skip_num = 0;
+ goto get_new_file;
+ }
+ iter->name = *cpp;
+ iter->node = section->first_child;
+ }
+ /*
+ * OK, now we know iter->node is set up correctly. Let's do
+ * the search.
+ */
+ for (p = iter->node; p; p = p->next) {
+ if (iter->name && strcmp(p->name, iter->name))
+ continue;
+ if ((iter->flags & PROFILE_ITER_SECTIONS_ONLY) &&
+ p->value)
+ continue;
+ if ((iter->flags & PROFILE_ITER_RELATIONS_ONLY) &&
+ !p->value)
+ continue;
+ if (skip_num > 0) {
+ skip_num--;
+ continue;
+ }
+ if (p->deleted)
+ continue;
+ break;
+ }
+ iter->num++;
+ if (!p) {
+ k5_mutex_unlock(&iter->file->data->lock);
+ iter->file = iter->file->next;
+ if (iter->file) {
+ retval = k5_mutex_lock(&iter->file->data->lock);
+ if (retval) {
+ profile_node_iterator_free(iter_p);
+ return retval;
+ }
+ }
+ iter->node = 0;
+ skip_num = 0;
+ goto get_new_file;
+ }
+ k5_mutex_unlock(&iter->file->data->lock);
+ if ((iter->node = p->next) == NULL)
+ iter->file = iter->file->next;
+ if (ret_node)
+ *ret_node = p;
+ if (ret_name)
+ *ret_name = p->name;
+ if (ret_value)
+ *ret_value = p->value;
+ return 0;
}
/*
*/
errcode_t profile_remove_node(struct profile_node *node)
{
- CHECK_MAGIC(node);
+ CHECK_MAGIC(node);
- if (node->parent == 0)
- return PROF_EINVAL; /* Can't remove the root! */
+ if (node->parent == 0)
+ return PROF_EINVAL; /* Can't remove the root! */
- node->deleted = 1;
+ node->deleted = 1;
- return 0;
+ return 0;
}
/*
* TYT, 2/25/99
*/
errcode_t profile_set_relation_value(struct profile_node *node,
- const char *new_value)
+ const char *new_value)
{
- char *cp;
+ char *cp;
- CHECK_MAGIC(node);
+ CHECK_MAGIC(node);
- if (!node->value)
- return PROF_SET_SECTION_VALUE;
+ if (!node->value)
+ return PROF_SET_SECTION_VALUE;
- cp = strdup(new_value);
- if (!cp)
- return ENOMEM;
+ cp = strdup(new_value);
+ if (!cp)
+ return ENOMEM;
- free(node->value);
- node->value = cp;
+ free(node->value);
+ node->value = cp;
- return 0;
+ return 0;
}
/*
*/
errcode_t profile_rename_node(struct profile_node *node, const char *new_name)
{
- char *new_string;
- struct profile_node *p, *last;
-
- CHECK_MAGIC(node);
-
- if (strcmp(new_name, node->name) == 0)
- return 0; /* It's the same name, return */
-
- /*
- * Make sure we can allocate memory for the new name, first!
- */
- new_string = strdup(new_name);
- if (!new_string)
- return ENOMEM;
-
- /*
- * Find the place to where the new node should go. We look
- * for the place *after* the last match of the node name,
- * since order matters.
- */
- for (p=node->parent->first_child, last = 0; p; last = p, p = p->next) {
- if (strcmp(p->name, new_name) > 0)
- break;
- }
-
- /*
- * If we need to move the node, do it now.
- */
- if ((p != node) && (last != node)) {
- /*
- * OK, let's detach the node
- */
- if (node->prev)
- node->prev->next = node->next;
- else
- node->parent->first_child = node->next;
- if (node->next)
- node->next->prev = node->prev;
-
- /*
- * Now let's reattach it in the right place.
- */
- if (p)
- p->prev = node;
- if (last)
- last->next = node;
- else
- node->parent->first_child = node;
- node->next = p;
- node->prev = last;
- }
-
- free(node->name);
- node->name = new_string;
- return 0;
+ char *new_string;
+ struct profile_node *p, *last;
+
+ CHECK_MAGIC(node);
+
+ if (strcmp(new_name, node->name) == 0)
+ return 0; /* It's the same name, return */
+
+ /*
+ * Make sure we can allocate memory for the new name, first!
+ */
+ new_string = strdup(new_name);
+ if (!new_string)
+ return ENOMEM;
+
+ /*
+ * Find the place to where the new node should go. We look
+ * for the place *after* the last match of the node name,
+ * since order matters.
+ */
+ for (p=node->parent->first_child, last = 0; p; last = p, p = p->next) {
+ if (strcmp(p->name, new_name) > 0)
+ break;
+ }
+
+ /*
+ * If we need to move the node, do it now.
+ */
+ if ((p != node) && (last != node)) {
+ /*
+ * OK, let's detach the node
+ */
+ if (node->prev)
+ node->prev->next = node->next;
+ else
+ node->parent->first_child = node->next;
+ if (node->next)
+ node->next->prev = node->prev;
+
+ /*
+ * Now let's reattach it in the right place.
+ */
+ if (p)
+ p->prev = node;
+ if (last)
+ last->next = node;
+ else
+ node->parent->first_child = node;
+ node->next = p;
+ node->prev = last;
+ }
+
+ free(node->name);
+ node->name = new_string;
+ return 0;
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#include "prof_int.h"
#include <stdio.h>
void dump_profile (struct profile_node *root, int level);
int main(argc, argv)
- int argc;
- char **argv;
+ int argc;
+ char **argv;
{
- struct profile_node *root;
- unsigned long retval;
- FILE *f;
-
- initialize_prof_error_table();
- if (argc != 2) {
- fprintf(stderr, "%s: Usage <filename>\n", argv[0]);
- exit(1);
- }
-
- f = fopen(argv[1], "r");
- if (!f) {
- perror(argv[1]);
- exit(1);
- }
-
- retval = profile_parse_file(f, &root);
- if (retval) {
- printf("profile_parse_file error %s\n",
- error_message((errcode_t) retval));
- exit(1);
- }
- fclose(f);
-
- printf("\n\nDebugging dump.\n");
- profile_write_tree_file(root, stdout);
-
- retval = profile_verify_node(root);
- if (retval) {
- printf("profile_verify_node reported an error: %s\n",
- error_message((errcode_t) retval));
- exit(1);
- }
-
- profile_free_node(root);
-
- return 0;
+ struct profile_node *root;
+ unsigned long retval;
+ FILE *f;
+
+ initialize_prof_error_table();
+ if (argc != 2) {
+ fprintf(stderr, "%s: Usage <filename>\n", argv[0]);
+ exit(1);
+ }
+
+ f = fopen(argv[1], "r");
+ if (!f) {
+ perror(argv[1]);
+ exit(1);
+ }
+
+ retval = profile_parse_file(f, &root);
+ if (retval) {
+ printf("profile_parse_file error %s\n",
+ error_message((errcode_t) retval));
+ exit(1);
+ }
+ fclose(f);
+
+ printf("\n\nDebugging dump.\n");
+ profile_write_tree_file(root, stdout);
+
+ retval = profile_verify_node(root);
+ if (retval) {
+ printf("profile_verify_node reported an error: %s\n",
+ error_message((errcode_t) retval));
+ exit(1);
+ }
+
+ profile_free_node(root);
+
+ return 0;
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* test_profile.c --- testing program for the profile routine
*/
const char *program_name = "test_profile";
-#define PRINT_VALUE 1
-#define PRINT_VALUES 2
+#define PRINT_VALUE 1
+#define PRINT_VALUES 2
static void do_batchmode(profile)
- profile_t profile;
+ profile_t profile;
{
- errcode_t retval;
- int argc, ret;
- char **argv, **values, **cpp;
- char buf[256];
- const char **names, *value;
- char *cmd;
- int print_status;
+ errcode_t retval;
+ int argc, ret;
+ char **argv, **values, **cpp;
+ char buf[256];
+ const char **names, *value;
+ char *cmd;
+ int print_status;
- while (!feof(stdin)) {
- if (fgets(buf, sizeof(buf), stdin) == NULL)
- break;
- printf(">%s", buf);
- ret = argv_parse(buf, &argc, &argv);
- if (ret != 0) {
- printf("Argv_parse returned %d!\n", ret);
- continue;
- }
- cmd = *(argv);
- names = (const char **) argv + 1;
- print_status = 0;
- retval = 0;
- if (cmd == 0) {
- argv_free(argv);
- continue;
- }
- if (!strcmp(cmd, "query")) {
- retval = profile_get_values(profile, names, &values);
- print_status = PRINT_VALUES;
- } else if (!strcmp(cmd, "query1")) {
- retval = profile_get_value(profile, names, &value);
- print_status = PRINT_VALUE;
- } else if (!strcmp(cmd, "list_sections")) {
- retval = profile_get_subsection_names(profile, names,
- &values);
- print_status = PRINT_VALUES;
- } else if (!strcmp(cmd, "list_relations")) {
- retval = profile_get_relation_names(profile, names,
- &values);
- print_status = PRINT_VALUES;
- } else if (!strcmp(cmd, "dump")) {
- retval = profile_write_tree_file
- (profile->first_file->data->root, stdout);
- } else if (!strcmp(cmd, "clear")) {
- retval = profile_clear_relation(profile, names);
- } else if (!strcmp(cmd, "update")) {
- retval = profile_update_relation(profile, names+2,
- *names, *(names+1));
- } else if (!strcmp(cmd, "verify")) {
- retval = profile_verify_node
- (profile->first_file->data->root);
- } else if (!strcmp(cmd, "rename_section")) {
- retval = profile_rename_section(profile, names+1,
- *names);
- } else if (!strcmp(cmd, "add")) {
- value = *names;
- if (strcmp(value, "NULL") == 0)
- value = NULL;
- retval = profile_add_relation(profile, names+1,
- value);
- } else if (!strcmp(cmd, "flush")) {
- retval = profile_flush(profile);
- } else {
- printf("Invalid command.\n");
- }
- if (retval) {
- com_err(cmd, retval, "");
- print_status = 0;
- }
- switch (print_status) {
- case PRINT_VALUE:
- printf("%s\n", value);
- break;
- case PRINT_VALUES:
- for (cpp = values; *cpp; cpp++)
- printf("%s\n", *cpp);
- profile_free_list(values);
- break;
- }
- printf("\n");
- argv_free(argv);
- }
- profile_release(profile);
- exit(0);
+ while (!feof(stdin)) {
+ if (fgets(buf, sizeof(buf), stdin) == NULL)
+ break;
+ printf(">%s", buf);
+ ret = argv_parse(buf, &argc, &argv);
+ if (ret != 0) {
+ printf("Argv_parse returned %d!\n", ret);
+ continue;
+ }
+ cmd = *(argv);
+ names = (const char **) argv + 1;
+ print_status = 0;
+ retval = 0;
+ if (cmd == 0) {
+ argv_free(argv);
+ continue;
+ }
+ if (!strcmp(cmd, "query")) {
+ retval = profile_get_values(profile, names, &values);
+ print_status = PRINT_VALUES;
+ } else if (!strcmp(cmd, "query1")) {
+ retval = profile_get_value(profile, names, &value);
+ print_status = PRINT_VALUE;
+ } else if (!strcmp(cmd, "list_sections")) {
+ retval = profile_get_subsection_names(profile, names,
+ &values);
+ print_status = PRINT_VALUES;
+ } else if (!strcmp(cmd, "list_relations")) {
+ retval = profile_get_relation_names(profile, names,
+ &values);
+ print_status = PRINT_VALUES;
+ } else if (!strcmp(cmd, "dump")) {
+ retval = profile_write_tree_file
+ (profile->first_file->data->root, stdout);
+ } else if (!strcmp(cmd, "clear")) {
+ retval = profile_clear_relation(profile, names);
+ } else if (!strcmp(cmd, "update")) {
+ retval = profile_update_relation(profile, names+2,
+ *names, *(names+1));
+ } else if (!strcmp(cmd, "verify")) {
+ retval = profile_verify_node
+ (profile->first_file->data->root);
+ } else if (!strcmp(cmd, "rename_section")) {
+ retval = profile_rename_section(profile, names+1,
+ *names);
+ } else if (!strcmp(cmd, "add")) {
+ value = *names;
+ if (strcmp(value, "NULL") == 0)
+ value = NULL;
+ retval = profile_add_relation(profile, names+1,
+ value);
+ } else if (!strcmp(cmd, "flush")) {
+ retval = profile_flush(profile);
+ } else {
+ printf("Invalid command.\n");
+ }
+ if (retval) {
+ com_err(cmd, retval, "");
+ print_status = 0;
+ }
+ switch (print_status) {
+ case PRINT_VALUE:
+ printf("%s\n", value);
+ break;
+ case PRINT_VALUES:
+ for (cpp = values; *cpp; cpp++)
+ printf("%s\n", *cpp);
+ profile_free_list(values);
+ break;
+ }
+ printf("\n");
+ argv_free(argv);
+ }
+ profile_release(profile);
+ exit(0);
}
int main(argc, argv)
- int argc;
- char **argv;
+ int argc;
+ char **argv;
{
- profile_t profile;
- long retval;
- char **values, **cpp;
- const char *value;
- const char **names;
- char *cmd;
- int print_value = 0;
+ profile_t profile;
+ long retval;
+ char **values, **cpp;
+ const char *value;
+ const char **names;
+ char *cmd;
+ int print_value = 0;
if (argc < 2) {
- fprintf(stderr, "Usage: %s filename [cmd argset]\n", program_name);
- exit(1);
+ fprintf(stderr, "Usage: %s filename [cmd argset]\n", program_name);
+ exit(1);
}
initialize_prof_error_table();
retval = profile_init_path(argv[1], &profile);
if (retval) {
- com_err(program_name, retval, "while initializing profile");
- exit(1);
+ com_err(program_name, retval, "while initializing profile");
+ exit(1);
}
cmd = *(argv+2);
names = (const char **) argv+3;
if (!cmd || !strcmp(cmd, "batch"))
- do_batchmode(profile);
+ do_batchmode(profile);
if (!strcmp(cmd, "query")) {
- retval = profile_get_values(profile, names, &values);
+ retval = profile_get_values(profile, names, &values);
} else if (!strcmp(cmd, "query1")) {
- retval = profile_get_value(profile, names, &value);
- print_value++;
+ retval = profile_get_value(profile, names, &value);
+ print_value++;
} else if (!strcmp(cmd, "list_sections")) {
- retval = profile_get_subsection_names(profile, names, &values);
+ retval = profile_get_subsection_names(profile, names, &values);
} else if (!strcmp(cmd, "list_relations")) {
- retval = profile_get_relation_names(profile, names, &values);
+ retval = profile_get_relation_names(profile, names, &values);
} else {
- fprintf(stderr, "Invalid command.\n");
- exit(1);
+ fprintf(stderr, "Invalid command.\n");
+ exit(1);
}
if (retval) {
- com_err(argv[0], retval, "while getting values");
- profile_release(profile);
- exit(1);
+ com_err(argv[0], retval, "while getting values");
+ profile_release(profile);
+ exit(1);
}
if (print_value) {
- printf("%s\n", value);
+ printf("%s\n", value);
} else {
- for (cpp = values; *cpp; cpp++)
- printf("%s\n", *cpp);
- profile_free_list(values);
+ for (cpp = values; *cpp; cpp++)
+ printf("%s\n", *cpp);
+ profile_free_list(values);
}
profile_release(profile);
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
-Copyright 1987, 1989 by the Student Information Processing Board
- of the Massachusetts Institute of Technology
+ Copyright 1987, 1989 by the Student Information Processing Board
+ of the Massachusetts Institute of Technology
-Permission to use, copy, modify, and distribute this software
-and its documentation for any purpose and without fee is
-hereby granted, provided that the above copyright notice
-appear in all copies and that both that copyright notice and
-this permission notice appear in supporting documentation,
-and that the names of M.I.T. and the M.I.T. S.I.P.B. not be
-used in advertising or publicity pertaining to distribution
-of the software without specific, written prior permission.
-Furthermore if you modify this software you must label
-your software as modified software and not distribute it in such a
-fashion that it might be confused with the original M.I.T. software.
-M.I.T. and the M.I.T. S.I.P.B. make no representations about
-the suitability of this software for any purpose. It is
-provided "as is" without express or implied warranty.
+ Permission to use, copy, modify, and distribute this software
+ and its documentation for any purpose and without fee is
+ hereby granted, provided that the above copyright notice
+ appear in all copies and that both that copyright notice and
+ this permission notice appear in supporting documentation,
+ and that the names of M.I.T. and the M.I.T. S.I.P.B. not be
+ used in advertising or publicity pertaining to distribution
+ of the software without specific, written prior permission.
+ Furthermore if you modify this software you must label
+ your software as modified software and not distribute it in such a
+ fashion that it might be confused with the original M.I.T. software.
+ M.I.T. and the M.I.T. S.I.P.B. make no representations about
+ the suitability of this software for any purpose. It is
+ provided "as is" without express or implied warranty.
*/
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 1987, 1988, 1989 Massachusetts Institute of Technology
* (Student Information Processing Board)
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 2007 Massachusetts Institute of Technology.
* All Rights Reserved.
infop = ss_info(sci_idx);
if (infop->current_request == (char const *)NULL) {
- return strdup(infop->subsystem_name);
+ return strdup(infop->subsystem_name);
} else {
- char *ret_val;
- if (asprintf(&ret_val, "%s (%s)",
- infop->subsystem_name, infop->current_request) < 0)
- return NULL;
- return ret_val;
+ char *ret_val;
+ if (asprintf(&ret_val, "%s (%s)",
+ infop->subsystem_name, infop->current_request) < 0)
+ return NULL;
+ return ret_val;
}
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 1987, 1988, 1989 by Massachusetts Institute of Technology
*
info->argc = argc;
info->argv = argv;
for (i = 0; (request = get_request(rqtbl, i))->command_names; i++) {
- for (name = request->command_names; *name; name++)
- if (!strcmp(*name, string)) {
- info->current_request = request->command_names[0];
- (request->function)(argc, (const char *const *) argv,
- sci_idx,info->info_ptr);
- info->current_request = (char *)NULL;
- return(0);
- }
+ for (name = request->command_names; *name; name++)
+ if (!strcmp(*name, string)) {
+ info->current_request = request->command_names[0];
+ (request->function)(argc, (const char *const *) argv,
+ sci_idx,info->info_ptr);
+ info->current_request = (char *)NULL;
+ return(0);
+ }
}
return(SS_ET_COMMAND_NOT_FOUND);
}
* ss_execute_command(sci_idx, argv)
*
* Function:
- * Executes a parsed command list within the subsystem.
+ * Executes a parsed command list within the subsystem.
* Arguments:
- * sci_idx (int)
- * ss-internal index for subsystem control info structure
- * argv (char *[])
- * parsed argument list
+ * sci_idx (int)
+ * ss-internal index for subsystem control info structure
+ * argv (char *[])
+ * parsed argument list
* Returns:
- * (int)
- * Zero if successful, ss_et_command_not_found otherwise.
+ * (int)
+ * Zero if successful, ss_et_command_not_found otherwise.
* Notes:
*/
int
ss_execute_command(sci_idx, argv)
- int sci_idx;
- register char *argv[];
+ int sci_idx;
+ register char *argv[];
{
- register unsigned int i, argc;
- char **argp;
- int ret;
-
- argc = 0;
- for (argp = argv; *argp; argp++)
- argc++;
- argp = (char **)malloc((argc+1)*sizeof(char *));
- for (i = 0; i <= argc; i++)
- argp[i] = argv[i];
- ret = really_execute_command(sci_idx, argc, &argp);
- free(argp);
- return(ret);
+ register unsigned int i, argc;
+ char **argp;
+ int ret;
+
+ argc = 0;
+ for (argp = argv; *argp; argp++)
+ argc++;
+ argp = (char **)malloc((argc+1)*sizeof(char *));
+ for (i = 0; i <= argc; i++)
+ argp[i] = argv[i];
+ ret = really_execute_command(sci_idx, argc, &argp);
+ free(argp);
+ return(ret);
}
/*
* Pointer to command line to be parsed.
* Returns:
* (int)
- * Error code.
+ * Error code.
* Notes:
*/
else {
line_ptr++;
system(line_ptr);
- return 0;
+ return 0;
}
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 1987, 1988 by MIT Student Information Processing Board
*
#include <sys/types.h>
#include <errno.h>
#include <sys/file.h>
-#include <fcntl.h> /* just for O_* */
+#include <fcntl.h> /* just for O_* */
#include <sys/wait.h>
#include "ss_internal.h"
#include "copyright.h"
request_name = ss_current_request(sci_idx, &code);
if (code != 0) {
- ss_perror(sci_idx, code, "");
- return; /* no ss_abort_line, if invalid invocation */
+ ss_perror(sci_idx, code, "");
+ return; /* no ss_abort_line, if invalid invocation */
}
if (argc == 1) {
- ss_list_requests(argc, argv, sci_idx, info_ptr);
- return;
+ ss_list_requests(argc, argv, sci_idx, info_ptr);
+ return;
}
else if (argc != 2) {
- /* should do something better than this */
- snprintf(buffer, sizeof(buffer),
- "usage:\n\t%s [topic|command]\nor\t%s\n",
- request_name, request_name);
- ss_perror(sci_idx, 0, buffer);
- return;
+ /* should do something better than this */
+ snprintf(buffer, sizeof(buffer),
+ "usage:\n\t%s [topic|command]\nor\t%s\n",
+ request_name, request_name);
+ ss_perror(sci_idx, 0, buffer);
+ return;
}
info = ss_info(sci_idx);
if (info->info_dirs == (char **)NULL) {
- ss_perror(sci_idx, SS_ET_NO_INFO_DIR, (char *)NULL);
- return;
+ ss_perror(sci_idx, SS_ET_NO_INFO_DIR, (char *)NULL);
+ return;
}
if (info->info_dirs[0] == (char *)NULL) {
- ss_perror(sci_idx, SS_ET_NO_INFO_DIR, (char *)NULL);
- return;
+ ss_perror(sci_idx, SS_ET_NO_INFO_DIR, (char *)NULL);
+ return;
}
for (idx = 0; info->info_dirs[idx] != (char *)NULL; idx++) {
- (void) strncpy(buffer, info->info_dirs[idx], sizeof(buffer) - 1);
- buffer[sizeof(buffer) - 1] = '\0';
- (void) strncat(buffer, "/", sizeof(buffer) - 1 - strlen(buffer));
- (void) strncat(buffer, argv[1], sizeof(buffer) - 1 - strlen(buffer));
- (void) strncat(buffer, ".info", sizeof(buffer) - 1 - strlen(buffer));
- if ((fd = open(&buffer[0], O_RDONLY)) >= 0) goto got_it;
+ (void) strncpy(buffer, info->info_dirs[idx], sizeof(buffer) - 1);
+ buffer[sizeof(buffer) - 1] = '\0';
+ (void) strncat(buffer, "/", sizeof(buffer) - 1 - strlen(buffer));
+ (void) strncat(buffer, argv[1], sizeof(buffer) - 1 - strlen(buffer));
+ (void) strncat(buffer, ".info", sizeof(buffer) - 1 - strlen(buffer));
+ if ((fd = open(&buffer[0], O_RDONLY)) >= 0) goto got_it;
}
if ((fd = open(&buffer[0], O_RDONLY)) < 0) {
- char buf[MAXPATHLEN];
- strncpy(buf, "No info found for ", sizeof(buf) - 1);
- buf[sizeof(buf) - 1] = '\0';
- strncat(buf, argv[1], sizeof(buf) - 1 - strlen(buf));
- ss_perror(sci_idx, 0, buf);
- return;
+ char buf[MAXPATHLEN];
+ strncpy(buf, "No info found for ", sizeof(buf) - 1);
+ buf[sizeof(buf) - 1] = '\0';
+ strncat(buf, argv[1], sizeof(buf) - 1 - strlen(buf));
+ ss_perror(sci_idx, 0, buf);
+ return;
}
got_it:
switch (child = fork()) {
case -1:
- ss_perror(sci_idx, errno, "Can't fork for pager");
- close(fd);
- return;
+ ss_perror(sci_idx, errno, "Can't fork for pager");
+ close(fd);
+ return;
case 0:
- (void) dup2(fd, 0); /* put file on stdin */
- ss_page_stdin();
+ (void) dup2(fd, 0); /* put file on stdin */
+ ss_page_stdin();
default:
- (void) close(fd); /* what can we do if it fails? */
+ (void) close(fd); /* what can we do if it fails? */
#ifdef WAIT_USES_INT
- while (wait((int *)NULL) != child) {
+ while (wait((int *)NULL) != child) {
#else
- while (wait((union wait *)NULL) != child) {
+ while (wait((union wait *)NULL) != child) {
#endif
- /* do nothing if wrong pid */
- };
+ /* do nothing if wrong pid */
+ };
+ }
}
-}
#ifndef USE_DIRENT_H
#include <sys/dir.h>
#include <dirent.h>
#endif
-void ss_add_info_dir(sci_idx, info_dir, code_ptr)
- int sci_idx;
+ void ss_add_info_dir(sci_idx, info_dir, code_ptr)
+ int sci_idx;
char *info_dir;
int *code_ptr;
-{
- register ss_data *info;
- DIR *d;
- int n_dirs;
- register char **dirs;
+ {
+ register ss_data *info;
+ DIR *d;
+ int n_dirs;
+ register char **dirs;
- info = ss_info(sci_idx);
- if ((info_dir == NULL) || (*info_dir == '\0')) {
- *code_ptr = SS_ET_NO_INFO_DIR;
- return;
+ info = ss_info(sci_idx);
+ if ((info_dir == NULL) || (*info_dir == '\0')) {
+ *code_ptr = SS_ET_NO_INFO_DIR;
+ return;
+ }
+ if ((d = opendir(info_dir)) == (DIR *)NULL) {
+ *code_ptr = errno;
+ return;
+ }
+ closedir(d);
+ dirs = info->info_dirs;
+ for (n_dirs = 0; dirs[n_dirs] != (char *)NULL; n_dirs++)
+ ; /* get number of non-NULL dir entries */
+ dirs = (char **)realloc((char *)dirs,
+ (unsigned)(n_dirs + 2)*sizeof(char *));
+ if (dirs == (char **)NULL) {
+ info->info_dirs = (char **)NULL;
+ *code_ptr = errno;
+ return;
+ }
+ info->info_dirs = dirs;
+ dirs[n_dirs + 1] = (char *)NULL;
+ dirs[n_dirs] = strdup(info_dir);
+ *code_ptr = 0;
}
- if ((d = opendir(info_dir)) == (DIR *)NULL) {
- *code_ptr = errno;
- return;
- }
- closedir(d);
- dirs = info->info_dirs;
- for (n_dirs = 0; dirs[n_dirs] != (char *)NULL; n_dirs++)
- ; /* get number of non-NULL dir entries */
- dirs = (char **)realloc((char *)dirs,
- (unsigned)(n_dirs + 2)*sizeof(char *));
- if (dirs == (char **)NULL) {
- info->info_dirs = (char **)NULL;
- *code_ptr = errno;
- return;
- }
- info->info_dirs = dirs;
- dirs[n_dirs + 1] = (char *)NULL;
- dirs[n_dirs] = strdup(info_dir);
- *code_ptr = 0;
-}
-void ss_delete_info_dir(sci_idx, info_dir, code_ptr)
- int sci_idx;
+ void ss_delete_info_dir(sci_idx, info_dir, code_ptr)
+ int sci_idx;
char *info_dir;
int *code_ptr;
-{
- register char **i_d;
- register char **info_dirs;
+ {
+ register char **i_d;
+ register char **info_dirs;
- info_dirs = ss_info(sci_idx)->info_dirs;
- for (i_d = info_dirs; *i_d; i_d++) {
- if (!strcmp(*i_d, info_dir)) {
- while (*i_d) {
- *i_d = *(i_d+1);
- i_d++;
- }
- *code_ptr = 0;
- return;
- }
+ info_dirs = ss_info(sci_idx)->info_dirs;
+ for (i_d = info_dirs; *i_d; i_d++) {
+ if (!strcmp(*i_d, info_dir)) {
+ while (*i_d) {
+ *i_d = *(i_d+1);
+ i_d++;
+ }
+ *code_ptr = 0;
+ return;
+ }
+ }
+ *code_ptr = SS_ET_NO_INFO_DIR;
}
- *code_ptr = SS_ET_NO_INFO_DIR;
-}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 2007 Massachusetts Institute of Technology.
* All Rights Reserved.
*/
#include "ss_internal.h"
#include "copyright.h"
-#define size sizeof(ss_data *)
+#define size sizeof(ss_data *)
/* XXX The memory in _ss_table never gets freed up until program exit!
If you change the code to free it and stick a null pointer into
not assume there are no null pointers in the middle of the
array. */
int ss_create_invocation(subsystem_name, version_string, info_ptr,
- request_table_ptr, code_ptr)
- char *subsystem_name, *version_string;
- char *info_ptr;
- ss_request_table *request_table_ptr;
- int *code_ptr;
+ request_table_ptr, code_ptr)
+ char *subsystem_name, *version_string;
+ char *info_ptr;
+ ss_request_table *request_table_ptr;
+ int *code_ptr;
{
- register int sci_idx;
- register ss_data *new_table;
- register ss_data **table, **tmp;
+ register int sci_idx;
+ register ss_data *new_table;
+ register ss_data **table, **tmp;
- *code_ptr = 0;
- table = _ss_table;
- new_table = (ss_data *) malloc(sizeof(ss_data));
- if (new_table == NULL) {
- *code_ptr = errno;
- return -1;
- }
+ *code_ptr = 0;
+ table = _ss_table;
+ new_table = (ss_data *) malloc(sizeof(ss_data));
+ if (new_table == NULL) {
+ *code_ptr = errno;
+ return -1;
+ }
- if (table == (ss_data **) NULL) {
- table = (ss_data **) malloc(2 * size);
- if (table == NULL) {
- *code_ptr = errno;
- return -1;
- }
- table[0] = table[1] = (ss_data *)NULL;
- _ss_table = table;
- }
- initialize_ss_error_table ();
+ if (table == (ss_data **) NULL) {
+ table = (ss_data **) malloc(2 * size);
+ if (table == NULL) {
+ *code_ptr = errno;
+ return -1;
+ }
+ table[0] = table[1] = (ss_data *)NULL;
+ _ss_table = table;
+ }
+ initialize_ss_error_table ();
- for (sci_idx = 1; table[sci_idx] != (ss_data *)NULL; sci_idx++)
- ;
- tmp = (ss_data **) realloc((char *)table,
- ((unsigned)sci_idx+2)*size);
- if (tmp == NULL) {
- *code_ptr = errno;
- return 0;
- }
- _ss_table = table = tmp;
- table[sci_idx+1] = (ss_data *) NULL;
- table[sci_idx] = NULL;
+ for (sci_idx = 1; table[sci_idx] != (ss_data *)NULL; sci_idx++)
+ ;
+ tmp = (ss_data **) realloc((char *)table,
+ ((unsigned)sci_idx+2)*size);
+ if (tmp == NULL) {
+ *code_ptr = errno;
+ return 0;
+ }
+ _ss_table = table = tmp;
+ table[sci_idx+1] = (ss_data *) NULL;
+ table[sci_idx] = NULL;
- new_table->subsystem_name = subsystem_name;
- new_table->subsystem_version = version_string;
- new_table->argv = (char **)NULL;
- new_table->current_request = (char *)NULL;
- new_table->info_dirs = (char **)malloc(sizeof(char *));
- if (new_table->info_dirs == NULL) {
- *code_ptr = errno;
- free(new_table);
- return 0;
- }
- *new_table->info_dirs = (char *)NULL;
- new_table->info_ptr = info_ptr;
- if (asprintf(&new_table->prompt, "%s: ", subsystem_name) < 0) {
- *code_ptr = errno;
- free(new_table->info_dirs);
- free(new_table);
- return 0;
- }
- new_table->abbrev_info = NULL;
- new_table->flags.escape_disabled = 0;
- new_table->flags.abbrevs_disabled = 0;
- new_table->rqt_tables =
- (ss_request_table **) calloc(2, sizeof(ss_request_table *));
- if (new_table->rqt_tables == NULL) {
- *code_ptr = errno;
- free(new_table->prompt);
- free(new_table->info_dirs);
- free(new_table);
- return 0;
- }
- *(new_table->rqt_tables) = request_table_ptr;
- *(new_table->rqt_tables+1) = (ss_request_table *) NULL;
- table[sci_idx] = new_table;
- return(sci_idx);
+ new_table->subsystem_name = subsystem_name;
+ new_table->subsystem_version = version_string;
+ new_table->argv = (char **)NULL;
+ new_table->current_request = (char *)NULL;
+ new_table->info_dirs = (char **)malloc(sizeof(char *));
+ if (new_table->info_dirs == NULL) {
+ *code_ptr = errno;
+ free(new_table);
+ return 0;
+ }
+ *new_table->info_dirs = (char *)NULL;
+ new_table->info_ptr = info_ptr;
+ if (asprintf(&new_table->prompt, "%s: ", subsystem_name) < 0) {
+ *code_ptr = errno;
+ free(new_table->info_dirs);
+ free(new_table);
+ return 0;
+ }
+ new_table->abbrev_info = NULL;
+ new_table->flags.escape_disabled = 0;
+ new_table->flags.abbrevs_disabled = 0;
+ new_table->rqt_tables =
+ (ss_request_table **) calloc(2, sizeof(ss_request_table *));
+ if (new_table->rqt_tables == NULL) {
+ *code_ptr = errno;
+ free(new_table->prompt);
+ free(new_table->info_dirs);
+ free(new_table);
+ return 0;
+ }
+ *(new_table->rqt_tables) = request_table_ptr;
+ *(new_table->rqt_tables+1) = (ss_request_table *) NULL;
+ table[sci_idx] = new_table;
+ return(sci_idx);
}
void
ss_delete_invocation(sci_idx)
- int sci_idx;
+ int sci_idx;
{
- register ss_data *t;
- int ignored_code;
+ register ss_data *t;
+ int ignored_code;
- t = ss_info(sci_idx);
- free(t->prompt);
- free(t->rqt_tables);
- while(t->info_dirs[0] != (char *)NULL)
- ss_delete_info_dir(sci_idx, t->info_dirs[0], &ignored_code);
- free(t->info_dirs);
- free(t);
+ t = ss_info(sci_idx);
+ free(t->prompt);
+ free(t->rqt_tables);
+ while(t->info_dirs[0] != (char *)NULL)
+ ss_delete_info_dir(sci_idx, t->info_dirs[0], &ignored_code);
+ free(t->info_dirs);
+ free(t);
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 1987, 1988 by MIT Student Information Processing Board
*
func = signal(SIGINT, SIG_IGN);
#endif
- fd = ss_pager_create(); /* FD_CLOEXEC set */
+ fd = ss_pager_create(); /* FD_CLOEXEC set */
output = fdopen(fd, "w");
#ifdef POSIX_SIGNALS
#endif
fprintf (output, "Available %s requests:\n\n",
- ss_info (sci_idx) -> subsystem_name);
+ ss_info (sci_idx) -> subsystem_name);
for (table = ss_info(sci_idx)->rqt_tables; *table; table++) {
entry = (*table)->requests;
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Listener loop for subsystem library libss.a.
*
- * util/ss/listen.c
+ * util/ss/listen.c
*
* Copyright 1987, 1988 by MIT Student Information Processing Board
*
struct termios termbuf;
if (tcgetattr(STDIN_FILENO, &termbuf) == 0) {
- termbuf.c_lflag |= ICANON|ISIG|ECHO;
- tcsetattr(STDIN_FILENO, TCSANOW, &termbuf);
+ termbuf.c_lflag |= ICANON|ISIG|ECHO;
+ tcsetattr(STDIN_FILENO, TCSANOW, &termbuf);
}
(void) fputs(current_info->prompt, stdout);
(void) fflush(stdout);
(void) sigsetmask(mask);
#endif
while(!info->abort) {
- print_prompt();
- *end = '\0';
+ print_prompt();
+ *end = '\0';
#ifdef POSIX_SIGNALS
- nsig.sa_handler = listen_int_handler; /* fgets is not signal-safe */
- osig = csig;
- sigaction(SIGCONT, &nsig, &csig);
- if ((RETSIGTYPE (*)())csig.sa_handler==(RETSIGTYPE (*)())listen_int_handler)
- csig = osig;
+ nsig.sa_handler = listen_int_handler; /* fgets is not signal-safe */
+ osig = csig;
+ sigaction(SIGCONT, &nsig, &csig);
+ if ((RETSIGTYPE (*)())csig.sa_handler==(RETSIGTYPE (*)())listen_int_handler)
+ csig = osig;
#else
- old_sig_cont = sig_cont;
- sig_cont = signal(SIGCONT, print_prompt);
- if (sig_cont == print_prompt)
- sig_cont = old_sig_cont;
+ old_sig_cont = sig_cont;
+ sig_cont = signal(SIGCONT, print_prompt);
+ if (sig_cont == print_prompt)
+ sig_cont = old_sig_cont;
#endif
- if (fgets(input, BUFSIZ, stdin) != input) {
- code = SS_ET_EOF;
- goto egress;
- }
- cp = strchr(input, '\n');
- if (cp) {
- *cp = '\0';
- if (cp == input)
- continue;
- }
+ if (fgets(input, BUFSIZ, stdin) != input) {
+ code = SS_ET_EOF;
+ goto egress;
+ }
+ cp = strchr(input, '\n');
+ if (cp) {
+ *cp = '\0';
+ if (cp == input)
+ continue;
+ }
#ifdef POSIX_SIGNALS
- sigaction(SIGCONT, &csig, (struct sigaction *)0);
+ sigaction(SIGCONT, &csig, (struct sigaction *)0);
#else
- (void) signal(SIGCONT, sig_cont);
+ (void) signal(SIGCONT, sig_cont);
#endif
- for (end = input; *end; end++)
- ;
-
- code = ss_execute_line (sci_idx, input);
- if (code == SS_ET_COMMAND_NOT_FOUND) {
- register char *c = input;
- while (*c == ' ' || *c == '\t')
- c++;
- cp = strchr (c, ' ');
- if (cp)
- *cp = '\0';
- cp = strchr (c, '\t');
- if (cp)
- *cp = '\0';
- ss_error (sci_idx, 0,
- "Unknown request \"%s\". Type \"?\" for a request list.",
- c);
- }
+ for (end = input; *end; end++)
+ ;
+
+ code = ss_execute_line (sci_idx, input);
+ if (code == SS_ET_COMMAND_NOT_FOUND) {
+ register char *c = input;
+ while (*c == ' ' || *c == '\t')
+ c++;
+ cp = strchr (c, ' ');
+ if (cp)
+ *cp = '\0';
+ cp = strchr (c, '\t');
+ if (cp)
+ *cp = '\0';
+ ss_error (sci_idx, 0,
+ "Unknown request \"%s\". Type \"?\" for a request list.",
+ c);
+ }
}
code = 0;
egress:
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
-Copyright 1987 by the Student Information Processing Board
- of the Massachusetts Institute of Technology
+ Copyright 1987 by the Student Information Processing Board
+ of the Massachusetts Institute of Technology
-Permission to use, copy, modify, and distribute this software
-and its documentation for any purpose and without fee is
-hereby granted, provided that the above copyright notice
-appear in all copies and that both that copyright notice and
-this permission notice appear in supporting documentation,
-and that the names of M.I.T. and the M.I.T. S.I.P.B. not be
-used in advertising or publicity pertaining to distribution
-of the software without specific, written prior permission.
-Furthermore if you modify this software you must label
-your software as modified software and not distribute it in such a
-fashion that it might be confused with the original M.I.T. software.
-M.I.T. and the M.I.T. S.I.P.B. make no representations about
-the suitability of this software for any purpose. It is
-provided "as is" without express or implied warranty.
+ Permission to use, copy, modify, and distribute this software
+ and its documentation for any purpose and without fee is
+ hereby granted, provided that the above copyright notice
+ appear in all copies and that both that copyright notice and
+ this permission notice appear in supporting documentation,
+ and that the names of M.I.T. and the M.I.T. S.I.P.B. not be
+ used in advertising or publicity pertaining to distribution
+ of the software without specific, written prior permission.
+ Furthermore if you modify this software you must label
+ your software as modified software and not distribute it in such a
+ fashion that it might be confused with the original M.I.T. software.
+ M.I.T. and the M.I.T. S.I.P.B. make no representations about
+ the suitability of this software for any purpose. It is
+ provided "as is" without express or implied warranty.
*/
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* make_commands.c
*
char *path, *p, *q;
if (argc != 2) {
- fputs("Usage: ", stderr);
- fputs(argv[0], stderr);
- fputs("cmdtbl.ct\n", stderr);
- exit(1);
+ fputs("Usage: ", stderr);
+ fputs(argv[0], stderr);
+ fputs("cmdtbl.ct\n", stderr);
+ exit(1);
}
path = malloc(strlen(argv[1])+4); /* extra space to add ".ct" */
strcpy(path, argv[1]);
p = strrchr(path, '/');
if (p == (char *)NULL)
- p = path;
+ p = path;
else
- p++;
+ p++;
p = strrchr(p, '.');
if (p == (char *)NULL || strcmp(p, ".ct"))
- strcat(path, ".ct");
+ strcat(path, ".ct");
yyin = fopen(path, "r");
if (!yyin) {
- perror(path);
- exit(1);
+ perror(path);
+ exit(1);
}
p = strrchr(path, '.');
output_file = fopen(c_file, "w+");
if (!output_file) {
- perror(c_file);
- exit(1);
+ perror(c_file);
+ exit(1);
}
fputs("/* ", output_file);
/* parse it */
result = yyparse();
/* put file descriptors back where they belong */
- fclose(yyin); /* bye bye input file */
- fclose(output_file); /* bye bye output file */
+ fclose(yyin); /* bye bye input file */
+ fclose(output_file); /* bye bye output file */
return result;
}
yyerror(s)
- char *s;
+char *s;
{
fputs(s, stderr);
#ifdef NO_YYLINENO
fprintf(stderr, "\nLast token was '%s'\n", last_token);
#else
fprintf(stderr, "\nLine %d; last token was '%s'\n",
- yylineno, last_token);
+ yylineno, last_token);
#endif
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 1987, 1988 by MIT Student Information Processing Board
*
#include "ss.h"
struct option {
- char *text;
- long value;
+ char *text;
+ long value;
};
static struct option options[] = {
- { "dont_list", SS_OPT_DONT_LIST },
- { "^list", SS_OPT_DONT_LIST },
- { "dont_summarize", SS_OPT_DONT_SUMMARIZE },
- { "^summarize", SS_OPT_DONT_SUMMARIZE },
- { (char *)NULL, 0 }
+ { "dont_list", SS_OPT_DONT_LIST },
+ { "^list", SS_OPT_DONT_LIST },
+ { "dont_summarize", SS_OPT_DONT_SUMMARIZE },
+ { "^summarize", SS_OPT_DONT_SUMMARIZE },
+ { (char *)NULL, 0 }
};
long
flag_val(string)
- register char *string;
+ register char *string;
{
- register struct option *opt;
- for (opt = options; opt->text; opt++)
- if (!strcmp(opt->text, string))
- return(opt->value);
- return(0);
+ register struct option *opt;
+ for (opt = options; opt->text; opt++)
+ if (!strcmp(opt->text, string))
+ return(opt->value);
+ return(0);
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Pager: Routines to create a "more" running out of a particular file
* descriptor.
#ifndef NO_FORK
int ss_pager_create()
{
- int filedes[2];
+ int filedes[2];
- if (pipe(filedes) != 0)
- return(-1);
+ if (pipe(filedes) != 0)
+ return(-1);
- switch((int) fork()) {
- case -1:
- return(-1);
- case 0:
- /*
- * Child; dup read half to 0, close all but 0, 1, and 2
- */
- if (dup2(filedes[0], 0) == -1)
- exit(1);
- ss_page_stdin();
- default:
- /*
- * Parent: close "read" side of pipe, return
- * "write" side.
- */
- (void) close(filedes[0]);
- set_cloexec_fd(filedes[1]);
- return(filedes[1]);
- }
+ switch((int) fork()) {
+ case -1:
+ return(-1);
+ case 0:
+ /*
+ * Child; dup read half to 0, close all but 0, 1, and 2
+ */
+ if (dup2(filedes[0], 0) == -1)
+ exit(1);
+ ss_page_stdin();
+ default:
+ /*
+ * Parent: close "read" side of pipe, return
+ * "write" side.
+ */
+ (void) close(filedes[0]);
+ set_cloexec_fd(filedes[1]);
+ return(filedes[1]);
+ }
}
#else /* don't fork */
int ss_pager_create()
int fd;
fd = open("/dev/tty", O_WRONLY, 0);
if (fd >= 0)
- set_cloexec_fd(fd);
+ set_cloexec_fd(fd);
return fd;
}
#endif
void ss_page_stdin()
{
- int i;
+ int i;
#ifdef POSIX_SIGNALS
- struct sigaction sa;
- sigset_t mask;
+ struct sigaction sa;
+ sigset_t mask;
#endif
- for (i = 3; i < 32; i++)
- (void) close(i);
+ for (i = 3; i < 32; i++)
+ (void) close(i);
#ifdef POSIX_SIGNALS
- sa.sa_handler = SIG_DFL;
- sigemptyset(&sa.sa_mask);
- sa.sa_flags = 0;
- sigaction(SIGINT, &sa, (struct sigaction *)0);
+ sa.sa_handler = SIG_DFL;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sigaction(SIGINT, &sa, (struct sigaction *)0);
#else
- (void) signal(SIGINT, SIG_DFL);
+ (void) signal(SIGINT, SIG_DFL);
#endif
- {
+ {
#ifdef POSIX_SIGNALS
- sigemptyset(&mask);
- sigaddset(&mask, SIGINT);
- sigprocmask(SIG_UNBLOCK, &mask, (sigset_t *)0);
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGINT);
+ sigprocmask(SIG_UNBLOCK, &mask, (sigset_t *)0);
#else
- int mask = sigblock(0);
- mask &= ~sigmask(SIGINT);
- sigsetmask(mask);
+ int mask = sigblock(0);
+ mask &= ~sigmask(SIGINT);
+ sigsetmask(mask);
#endif
- }
- if (_ss_pager_name == (char *)NULL) {
- if ((_ss_pager_name = getenv("PAGER")) == (char *)NULL)
- _ss_pager_name = MORE;
- }
- (void) execlp(_ss_pager_name, _ss_pager_name, (char *) NULL);
- {
- /* minimal recovery if pager program isn't found */
- char buf[80];
- register int n;
- while ((n = read(0, buf, 80)) > 0)
- write(1, buf, (unsigned) n);
- }
- exit(errno);
+ }
+ if (_ss_pager_name == (char *)NULL) {
+ if ((_ss_pager_name = getenv("PAGER")) == (char *)NULL)
+ _ss_pager_name = MORE;
+ }
+ (void) execlp(_ss_pager_name, _ss_pager_name, (char *) NULL);
+ {
+ /* minimal recovery if pager program isn't found */
+ char buf[80];
+ register int n;
+ while ((n = read(0, buf, 80)) > 0)
+ write(1, buf, (unsigned) n);
+ }
+ exit(errno);
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 2007 Massachusetts Institute of Technology.
* All Rights Reserved.
* Series of pointers to parsed tokens in the original string.
*/
-#define NEW_ARGV(old,n) (char **)realloc((char *)old,\
- (unsigned)(n+2)*sizeof(char*))
+#define NEW_ARGV(old,n) (char **)realloc((char *)old, \
+ (unsigned)(n+2)*sizeof(char*))
char **ss_parse (sci_idx, line_ptr, argc_ptr)
int sci_idx;
argv = (char **) malloc (sizeof(char *));
if (argv == (char **)NULL) {
- ss_error(sci_idx, errno, "Can't allocate storage");
- *argc_ptr = 0;
- return(argv);
+ ss_error(sci_idx, errno, "Can't allocate storage");
+ *argc_ptr = 0;
+ return(argv);
}
*argv = (char *)NULL;
argc = 0;
- parse_mode = WHITESPACE; /* flushing whitespace */
- cp = line_ptr; /* cp is for output */
+ parse_mode = WHITESPACE; /* flushing whitespace */
+ cp = line_ptr; /* cp is for output */
while (1) {
#ifdef DEBUG
- {
- printf ("character `%c', mode %d\n", *line_ptr, parse_mode);
- }
+ {
+ printf ("character `%c', mode %d\n", *line_ptr, parse_mode);
+ }
#endif
- while (parse_mode == WHITESPACE) {
- if (*line_ptr == '\0')
- goto end_of_line;
- if (*line_ptr == ' ' || *line_ptr == '\t') {
- line_ptr++;
- continue;
- }
- if (*line_ptr == '"') {
- /* go to quoted-string mode */
- parse_mode = QUOTED_STRING;
- cp = line_ptr++;
- newargv = NEW_ARGV (argv, argc);
- if (newargv == NULL) {
- out_of_mem_in_argv:
- free(argv);
- ss_error(sci_idx, errno, "Can't allocate storage");
- *argc_ptr = 0;
- return NULL;
- }
- argv = newargv;
- argv[argc++] = cp;
- argv[argc] = NULL;
- }
- else {
- /* random-token mode */
- parse_mode = TOKEN;
- cp = line_ptr;
- newargv = NEW_ARGV (argv, argc);
- if (newargv == NULL)
- goto out_of_mem_in_argv;
- argv = newargv;
- argv[argc++] = line_ptr;
- argv[argc] = NULL;
- }
- }
- while (parse_mode == TOKEN) {
- if (*line_ptr == '\0') {
- *cp++ = '\0';
- goto end_of_line;
- }
- else if (*line_ptr == ' ' || *line_ptr == '\t') {
- *cp++ = '\0';
- line_ptr++;
- parse_mode = WHITESPACE;
- }
- else if (*line_ptr == '"') {
- line_ptr++;
- parse_mode = QUOTED_STRING;
- }
- else {
- *cp++ = *line_ptr++;
- }
- }
- while (parse_mode == QUOTED_STRING) {
- if (*line_ptr == '\0') {
- ss_error (sci_idx, 0,
- "Unbalanced quotes in command line");
- free (argv);
- *argc_ptr = 0;
- return NULL;
- }
- else if (*line_ptr == '"') {
- if (*++line_ptr == '"') {
- *cp++ = '"';
- line_ptr++;
- }
- else {
- parse_mode = TOKEN;
- }
- }
- else {
- *cp++ = *line_ptr++;
- }
- }
+ while (parse_mode == WHITESPACE) {
+ if (*line_ptr == '\0')
+ goto end_of_line;
+ if (*line_ptr == ' ' || *line_ptr == '\t') {
+ line_ptr++;
+ continue;
+ }
+ if (*line_ptr == '"') {
+ /* go to quoted-string mode */
+ parse_mode = QUOTED_STRING;
+ cp = line_ptr++;
+ newargv = NEW_ARGV (argv, argc);
+ if (newargv == NULL) {
+ out_of_mem_in_argv:
+ free(argv);
+ ss_error(sci_idx, errno, "Can't allocate storage");
+ *argc_ptr = 0;
+ return NULL;
+ }
+ argv = newargv;
+ argv[argc++] = cp;
+ argv[argc] = NULL;
+ }
+ else {
+ /* random-token mode */
+ parse_mode = TOKEN;
+ cp = line_ptr;
+ newargv = NEW_ARGV (argv, argc);
+ if (newargv == NULL)
+ goto out_of_mem_in_argv;
+ argv = newargv;
+ argv[argc++] = line_ptr;
+ argv[argc] = NULL;
+ }
+ }
+ while (parse_mode == TOKEN) {
+ if (*line_ptr == '\0') {
+ *cp++ = '\0';
+ goto end_of_line;
+ }
+ else if (*line_ptr == ' ' || *line_ptr == '\t') {
+ *cp++ = '\0';
+ line_ptr++;
+ parse_mode = WHITESPACE;
+ }
+ else if (*line_ptr == '"') {
+ line_ptr++;
+ parse_mode = QUOTED_STRING;
+ }
+ else {
+ *cp++ = *line_ptr++;
+ }
+ }
+ while (parse_mode == QUOTED_STRING) {
+ if (*line_ptr == '\0') {
+ ss_error (sci_idx, 0,
+ "Unbalanced quotes in command line");
+ free (argv);
+ *argc_ptr = 0;
+ return NULL;
+ }
+ else if (*line_ptr == '"') {
+ if (*++line_ptr == '"') {
+ *cp++ = '"';
+ line_ptr++;
+ }
+ else {
+ parse_mode = TOKEN;
+ }
+ }
+ else {
+ *cp++ = *line_ptr++;
+ }
+ }
}
end_of_line:
*argc_ptr = argc;
#ifdef DEBUG
{
- int i;
- printf ("argc = %d\n", argc);
- for (i = 0; i <= argc; i++)
- printf ("\targv[%2d] = `%s'\n", i,
- argv[i] ? argv[i] : "<NULL>");
+ int i;
+ printf ("argc = %d\n", argc);
+ for (i = 0; i <= argc; i++)
+ printf ("\targv[%2d] = `%s'\n", i,
+ argv[i] ? argv[i] : "<NULL>");
}
#endif
return(argv);
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* prompt.c: Routines for retrieving and setting a prompt.
*
void
ss_set_prompt(sci_idx, new_prompt)
- int sci_idx;
- char *new_prompt;
+ int sci_idx;
+ char *new_prompt;
{
- ss_info(sci_idx)->prompt = new_prompt;
+ ss_info(sci_idx)->prompt = new_prompt;
}
char *
ss_get_prompt(sci_idx)
- int sci_idx;
+ int sci_idx;
{
- return(ss_info(sci_idx)->prompt);
+ return(ss_info(sci_idx)->prompt);
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 1987, 1988 by MIT Student Information Processing Board
*
#include "copyright.h"
#include "ss_internal.h"
-#define ssrt ss_request_table /* for some readable code... */
+#define ssrt ss_request_table /* for some readable code... */
void
ss_add_request_table(sci_idx, rqtbl_ptr, position, code_ptr)
- int sci_idx;
- ssrt *rqtbl_ptr;
- int position; /* 1 -> becomes second... */
- int *code_ptr;
+ int sci_idx;
+ ssrt *rqtbl_ptr;
+ int position; /* 1 -> becomes second... */
+ int *code_ptr;
{
- register ss_data *info;
- register int i, size;
+ register ss_data *info;
+ register int i, size;
- info = ss_info(sci_idx);
- for (size=0; info->rqt_tables[size] != (ssrt *)NULL; size++)
- ;
- /* size == C subscript of NULL == #elements */
- size += 2; /* new element, and NULL */
- info->rqt_tables = (ssrt **)realloc(info->rqt_tables,
- size*sizeof(ssrt *));
- if (info->rqt_tables == (ssrt **)NULL) {
- *code_ptr = errno;
- return;
- }
- if (position > size - 2)
- position = size - 2;
+ info = ss_info(sci_idx);
+ for (size=0; info->rqt_tables[size] != (ssrt *)NULL; size++)
+ ;
+ /* size == C subscript of NULL == #elements */
+ size += 2; /* new element, and NULL */
+ info->rqt_tables = (ssrt **)realloc(info->rqt_tables,
+ size*sizeof(ssrt *));
+ if (info->rqt_tables == (ssrt **)NULL) {
+ *code_ptr = errno;
+ return;
+ }
+ if (position > size - 2)
+ position = size - 2;
- if (size > 1)
- for (i = size - 2; i >= position; i--)
- info->rqt_tables[i+1] = info->rqt_tables[i];
+ if (size > 1)
+ for (i = size - 2; i >= position; i--)
+ info->rqt_tables[i+1] = info->rqt_tables[i];
- info->rqt_tables[position] = rqtbl_ptr;
- info->rqt_tables[size-1] = (ssrt *)NULL;
- *code_ptr = 0;
+ info->rqt_tables[position] = rqtbl_ptr;
+ info->rqt_tables[size-1] = (ssrt *)NULL;
+ *code_ptr = 0;
}
void
ss_delete_request_table(sci_idx, rqtbl_ptr, code_ptr)
- int sci_idx;
- ssrt *rqtbl_ptr;
- int *code_ptr;
+ int sci_idx;
+ ssrt *rqtbl_ptr;
+ int *code_ptr;
{
- register ss_data *info;
- register ssrt **rt1, **rt2;
+ register ss_data *info;
+ register ssrt **rt1, **rt2;
- *code_ptr = SS_ET_TABLE_NOT_FOUND;
- info = ss_info(sci_idx);
- rt1 = info->rqt_tables;
- for (rt2 = rt1; *rt1; rt1++) {
- if (*rt1 != rqtbl_ptr) {
- *rt2++ = *rt1;
- *code_ptr = 0;
- }
- }
- *rt2 = (ssrt *)NULL;
- return;
+ *code_ptr = SS_ET_TABLE_NOT_FOUND;
+ info = ss_info(sci_idx);
+ rt1 = info->rqt_tables;
+ for (rt2 = rt1; *rt1; rt1++) {
+ if (*rt1 != rqtbl_ptr) {
+ *rt2++ = *rt1;
+ *code_ptr = 0;
+ }
+ }
+ *rt2 = (ssrt *)NULL;
+ return;
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Various minor routines...
*
#include <stdio.h>
#include "ss_internal.h"
-#define DECLARE(name) void name(argc,argv,sci_idx,info_ptr)int argc,sci_idx;const char * const *argv; pointer info_ptr;
+#define DECLARE(name) void name(argc,argv,sci_idx,info_ptr)int argc,sci_idx;const char * const *argv; pointer info_ptr;
/*
* ss_self_identify -- assigned by default to the "." request
*/
DECLARE(ss_self_identify)
{
- register ss_data *info = ss_info(sci_idx);
- printf("%s version %s\n", info->subsystem_name,
- info->subsystem_version);
+ register ss_data *info = ss_info(sci_idx);
+ printf("%s version %s\n", info->subsystem_name,
+ info->subsystem_version);
}
/*
*/
DECLARE(ss_subsystem_name)
{
- printf("%s\n", ss_info(sci_idx)->subsystem_name);
+ printf("%s\n", ss_info(sci_idx)->subsystem_name);
}
/*
*/
DECLARE(ss_subsystem_version)
{
- printf("%s\n", ss_info(sci_idx)->subsystem_version);
+ printf("%s\n", ss_info(sci_idx)->subsystem_version);
}
/*
*/
DECLARE(ss_unimplemented)
{
- ss_perror(sci_idx, SS_ET_UNIMPLEMENTED, "");
+ ss_perror(sci_idx, SS_ET_UNIMPLEMENTED, "");
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 1987, 1988 by MIT Student Information Processing Board
*
typedef __SS_CONST struct _ss_request_entry {
__SS_CONST char * __SS_CONST *command_names; /* whatever */
void (* __SS_CONST function) __SS_PROTO; /* foo */
- __SS_CONST char * __SS_CONST info_string; /* NULL */
- int flags; /* 0 */
+ __SS_CONST char * __SS_CONST info_string; /* NULL */
+ int flags; /* 0 */
} ss_request_entry;
typedef __SS_CONST struct _ss_request_table {
ss_request_entry *requests;
} ss_request_table;
-#define SS_RQT_TBL_V2 2
+#define SS_RQT_TBL_V2 2
-typedef struct _ss_rp_options { /* DEFAULT VALUES */
- int version; /* SS_RP_V1 */
- void (*unknown) __SS_PROTO; /* call for unknown command */
+typedef struct _ss_rp_options { /* DEFAULT VALUES */
+ int version; /* SS_RP_V1 */
+ void (*unknown) __SS_PROTO; /* call for unknown command */
int allow_suspend;
int catch_int;
} ss_rp_options;
#define SS_RP_V1 1
-#define SS_OPT_DONT_LIST 0x0001
-#define SS_OPT_DONT_SUMMARIZE 0x0002
+#define SS_OPT_DONT_LIST 0x0001
+#define SS_OPT_DONT_SUMMARIZE 0x0002
void ss_help __SS_PROTO;
void ss_list_requests __SS_PROTO;
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 1987, 1988 by MIT Student Information Processing Board
*
#define LOCAL_FREE(x)
extern pointer alloca (unsigned);
#else
-#if defined(__HIGHC__) /* Barf! */
+#if defined(__HIGHC__) /* Barf! */
pragma on(alloca);
#define LOCAL_ALLOC(x) alloca(x)
#define LOCAL_FREE(x)
#define LOCAL_FREE(x) free(x)
#endif
#endif
-#endif /* LOCAL_ALLOC stuff */
+#endif /* LOCAL_ALLOC stuff */
typedef char BOOL;
typedef struct _ss_abbrev_entry {
- char *name; /* abbrev name */
- char **abbrev; /* new tokens to insert */
+ char *name; /* abbrev name */
+ char **abbrev; /* new tokens to insert */
unsigned int beginning_of_line : 1;
} ss_abbrev_entry;
ss_abbrev_list abbrevs[127];
} ss_abbrev_info;
-typedef struct _ss_data { /* init values */
+typedef struct _ss_data { /* init values */
/* this subsystem */
char *subsystem_name;
char *subsystem_version;
/* current request info */
int argc;
- char **argv; /* arg list */
+ char **argv; /* arg list */
char const *current_request; /* primary name */
/* info directory for 'help' */
char **info_dirs;
/* to be extracted by subroutines */
- pointer info_ptr; /* (void *) NULL */
+ pointer info_ptr; /* (void *) NULL */
/* for ss_listen processing */
char *prompt;
ss_request_table **rqt_tables;
ss_abbrev_info *abbrev_info;
struct {
- unsigned int escape_disabled : 1,
- abbrevs_disabled : 1;
+ unsigned int escape_disabled : 1,
+ abbrevs_disabled : 1;
} flags;
/* to get out */
- int abort; /* exit subsystem */
+ int abort; /* exit subsystem */
int exit_status;
} ss_data;
#define CURRENT_SS_VERSION 1
-#define ss_info(sci_idx) (_ss_table[sci_idx])
-#define ss_current_request(sci_idx,code_ptr) \
- (*code_ptr=0,ss_info(sci_idx)->current_request)
+#define ss_info(sci_idx) (_ss_table[sci_idx])
+#define ss_current_request(sci_idx,code_ptr) \
+ (*code_ptr=0,ss_info(sci_idx)->current_request)
void ss_unknown_function();
void ss_delete_info_dir();
char **ss_parse (int, char *, int *);
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* util/ss/test_ss.c
*/
int code;
char *argv0 = argv[0];
char *initial_request = (char *)NULL;
- int quit = FALSE; /* quit after processing request */
+ int quit = FALSE; /* quit after processing request */
int sci_idx;
char *subsystem_name;
subsystem_name = def_subsystem_name;
for (; *argv; ++argv, --argc) {
- printf("checking arg: %s\n", *argv);
- if (!strcmp(*argv, "-prompt")) {
- if (argc == 1) {
- fprintf(stderr,
- "No argument supplied with -prompt\n");
- exit(1);
- }
- argc--; argv++;
- subsystem_name = *argv;
- }
- else if (!strcmp(*argv, "-request") || !strcmp(*argv, "-rq")) {
- if (argc == 1) {
- fprintf(stderr,
- "No string supplied with -request.\n");
- exit(1);
- }
- argc--; argv++;
- initial_request = *argv;
- }
- else if (!strcmp(*argv, "-quit"))
- quit = TRUE;
- else if (!strcmp(*argv, "-no_quit"))
- quit = FALSE;
- else if (**argv == '-') {
- fprintf(stderr, "Unknown control argument %s\n",
- *argv);
- fprintf(stderr,
- "Usage: %s [gateway] [ -prompt name ] [ -request name ] [ -quit ]\n",
- argv0);
- exit(1);
- }
+ printf("checking arg: %s\n", *argv);
+ if (!strcmp(*argv, "-prompt")) {
+ if (argc == 1) {
+ fprintf(stderr,
+ "No argument supplied with -prompt\n");
+ exit(1);
+ }
+ argc--; argv++;
+ subsystem_name = *argv;
+ }
+ else if (!strcmp(*argv, "-request") || !strcmp(*argv, "-rq")) {
+ if (argc == 1) {
+ fprintf(stderr,
+ "No string supplied with -request.\n");
+ exit(1);
+ }
+ argc--; argv++;
+ initial_request = *argv;
+ }
+ else if (!strcmp(*argv, "-quit"))
+ quit = TRUE;
+ else if (!strcmp(*argv, "-no_quit"))
+ quit = FALSE;
+ else if (**argv == '-') {
+ fprintf(stderr, "Unknown control argument %s\n",
+ *argv);
+ fprintf(stderr,
+ "Usage: %s [gateway] [ -prompt name ] [ -request name ] [ -quit ]\n",
+ argv0);
+ exit(1);
+ }
}
sci_idx = ss_create_invocation(subsystem_name, version,
- (char *)NULL, &test_cmds, &code);
+ (char *)NULL, &test_cmds, &code);
if (code) {
- ss_perror(sci_idx, code, "creating invocation");
- exit(1);
+ ss_perror(sci_idx, code, "creating invocation");
+ exit(1);
}
(void) ss_add_request_table (sci_idx, &ss_std_requests, 1, &code);
if (code) {
- ss_perror (sci_idx, code, "adding standard requests");
- exit (1);
+ ss_perror (sci_idx, code, "adding standard requests");
+ exit (1);
}
if (!quit)
- printf("test version %s. Type '?' for a list of commands.\n\n",
- version);
+ printf("test version %s. Type '?' for a list of commands.\n\n",
+ version);
if (initial_request != (char *)NULL) {
- code = ss_execute_line(sci_idx, initial_request);
- if (code != 0)
- ss_perror(sci_idx, code, initial_request);
+ code = ss_execute_line(sci_idx, initial_request);
+ if (code != 0)
+ ss_perror(sci_idx, code, initial_request);
}
if (!quit || code)
- code = ss_listen (sci_idx);
+ code = ss_listen (sci_idx);
exit(0);
}
char **argv;
{
while (++argv, --argc)
- fputs(*argv, stdout);
+ fputs(*argv, stdout);
putchar ('\n');
}
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 1987, 1988 by MIT Student Information Processing Board
*
#include <string.h>
#include "copyright.h"
-#include "ss_internal.h" /* includes stdio and string */
+#include "ss_internal.h" /* includes stdio and string */
extern FILE *output_file;
var_name = generate_cmds_string(cmds);
generate_function_definition(func_name);
asprintf(&string, " { %s,\n %s,\n %s,\n %d },\n",
- var_name, func_name, info_string, options);
+ var_name, func_name, info_string, options);
return(string);
}
char *
gensym(name)
- char *name;
+ char *name;
{
- char *symbol;
+ char *symbol;
- gensym_n++;
- asprintf(&symbol, "%s%05ld", name, gensym_n);
- return(symbol);
+ gensym_n++;
+ asprintf(&symbol, "%s%05ld", name, gensym_n);
+ return(symbol);
}
/* concatenate three strings and return the result */
char *str_concat3(a, b, c)
- register char *a, *b, *c;
+ register char *a, *b, *c;
{
- char *result;
+ char *result;
- asprintf(&result, "%s%s%s", a, c, b);
- return(result);
+ asprintf(&result, "%s%s%s", a, c, b);
+ return(result);
}
/* return copy of string enclosed in double-quotes */
char *quote(string)
- register char *string;
+ register char *string;
{
- register char *result;
+ register char *result;
- asprintf(&result, "\"%s\"", string);
- return(result);
+ asprintf(&result, "\"%s\"", string);
+ return(result);
}
#ifndef HAVE_STRDUP
/* make duplicate of string and return pointer */
char *strdup(s)
- register char *s;
+ register char *s;
{
- register int len = strlen(s) + 1;
- register char *new;
- new = malloc(len);
- strncpy(new, s, len);
- return(new);
+ register int len = strlen(s) + 1;
+ register char *new;
+ new = malloc(len);
+ strncpy(new, s, len);
+ return(new);
}
#endif
+/* -*- mode: c; c-file-style: "bsd"; indent-tabs-mode: t -*- */
/* $NetBSD: getopt.c,v 1.16 1999/12/02 13:15:56 kleink Exp $ */
/*
static char *__progname = 0;
static char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */
- __progname = __progname?__progname:_progname(*nargv);
+ __progname = __progname?__progname:_progname(*nargv);
_DIAGASSERT(nargv != NULL);
_DIAGASSERT(ostr != NULL);
+/* -*- mode: c; c-file-style: "bsd"; indent-tabs-mode: t -*- */
#ifndef __GETOPT_H__
#define __GETOPT_H__
+/* -*- mode: c; c-file-style: "bsd"; indent-tabs-mode: t -*- */
/*
* Copyright (c) 1987, 1993, 1994, 1996
* The Regents of the University of California. All rights reserved.
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* libecho.c
*
int
main(int argc, char *argv[])
{
- int i;
- char *prefix;
+ int i;
+ char *prefix;
- prefix = "";
+ prefix = "";
- if (argc < 2) {
- fprintf(stderr, "Usage: libecho [-p prefix] list...\n");
- return 1;
- }
+ if (argc < 2) {
+ fprintf(stderr, "Usage: libecho [-p prefix] list...\n");
+ return 1;
+ }
- for (i = 1 ; i < argc ; i++)
- if (!stricmp(argv[i], "-p"))
- prefix = argv[++i];
- else
- echo_files(prefix, argv[i]);
+ for (i = 1 ; i < argc ; i++)
+ if (!stricmp(argv[i], "-p"))
+ prefix = argv[++i];
+ else
+ echo_files(prefix, argv[i]);
- return 0;
+ return 0;
}
void
echo_files(char *prefix, char *f)
{
- long ff;
- struct _finddata_t fdt;
- char *slash;
- char filepath[256];
+ long ff;
+ struct _finddata_t fdt;
+ char *slash;
+ char filepath[256];
- /*
- * We're unix based quite a bit here. Look for normal slashes and
- * make them reverse slashes.
- */
- while((slash = strrchr(f, '/')) != NULL)
- *slash = '\\';
+ /*
+ * We're unix based quite a bit here. Look for normal slashes and
+ * make them reverse slashes.
+ */
+ while((slash = strrchr(f, '/')) != NULL)
+ *slash = '\\';
- strcpy(filepath, f);
+ strcpy(filepath, f);
- slash = strrchr(filepath, '\\');
+ slash = strrchr(filepath, '\\');
- if (slash) {
- slash++;
- *slash = 0;
- } else {
- filepath[0] = '\0';
- }
+ if (slash) {
+ slash++;
+ *slash = 0;
+ } else {
+ filepath[0] = '\0';
+ }
- ff = _findfirst(f, &fdt);
+ ff = _findfirst(f, &fdt);
- if (ff < 0)
- return;
+ if (ff < 0)
+ return;
- printf("%s%s%s\n", prefix, filepath, fdt.name);
-
- for (;;) {
- if (_findnext(ff, &fdt) < 0)
- break;
printf("%s%s%s\n", prefix, filepath, fdt.name);
- }
- _findclose(ff);
+
+ for (;;) {
+ if (_findnext(ff, &fdt) < 0)
+ break;
+ printf("%s%s%s\n", prefix, filepath, fdt.name);
+ }
+ _findclose(ff);
}