17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers. 37c478bd9Sstevel@tonic-gate * All rights reserved. 47c478bd9Sstevel@tonic-gate * Copyright (c) 1983 Eric P. Allman. All rights reserved. 57c478bd9Sstevel@tonic-gate * Copyright (c) 1988, 1993 67c478bd9Sstevel@tonic-gate * The Regents of the University of California. All rights reserved. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * By using this file, you agree to the terms and conditions set 97c478bd9Sstevel@tonic-gate * forth in the LICENSE file which can be found at the top level of 107c478bd9Sstevel@tonic-gate * the sendmail distribution. 117c478bd9Sstevel@tonic-gate * 127c478bd9Sstevel@tonic-gate */ 137c478bd9Sstevel@tonic-gate 147c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 157c478bd9Sstevel@tonic-gate 167c478bd9Sstevel@tonic-gate #include <sm/gen.h> 177c478bd9Sstevel@tonic-gate 187c478bd9Sstevel@tonic-gate SM_IDSTR(copyright, 197c478bd9Sstevel@tonic-gate "@(#) Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers.\n\ 207c478bd9Sstevel@tonic-gate All rights reserved.\n\ 217c478bd9Sstevel@tonic-gate Copyright (c) 1983 Eric P. Allman. All rights reserved.\n\ 227c478bd9Sstevel@tonic-gate Copyright (c) 1988, 1993\n\ 237c478bd9Sstevel@tonic-gate The Regents of the University of California. All rights reserved.\n") 247c478bd9Sstevel@tonic-gate 25*7800901eSjbeck SM_IDSTR(id, "@(#)$Id: praliases.c,v 8.94 2007/05/11 18:50:36 ca Exp $") 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #include <sys/types.h> 287c478bd9Sstevel@tonic-gate #include <ctype.h> 297c478bd9Sstevel@tonic-gate #include <stdlib.h> 307c478bd9Sstevel@tonic-gate #include <unistd.h> 317c478bd9Sstevel@tonic-gate #ifdef EX_OK 327c478bd9Sstevel@tonic-gate # undef EX_OK /* unistd.h may have another use for this */ 337c478bd9Sstevel@tonic-gate #endif /* EX_OK */ 347c478bd9Sstevel@tonic-gate #include <sysexits.h> 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #ifndef NOT_SENDMAIL 387c478bd9Sstevel@tonic-gate # define NOT_SENDMAIL 397c478bd9Sstevel@tonic-gate #endif /* ! NOT_SENDMAIL */ 407c478bd9Sstevel@tonic-gate #include <sendmail/sendmail.h> 417c478bd9Sstevel@tonic-gate #include <sendmail/pathnames.h> 427c478bd9Sstevel@tonic-gate #include <libsmdb/smdb.h> 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate static void praliases __P((char *, int, char **)); 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate uid_t RealUid; 477c478bd9Sstevel@tonic-gate gid_t RealGid; 487c478bd9Sstevel@tonic-gate char *RealUserName; 497c478bd9Sstevel@tonic-gate uid_t RunAsUid; 50*7800901eSjbeck gid_t RunAsGid; 517c478bd9Sstevel@tonic-gate char *RunAsUserName; 527c478bd9Sstevel@tonic-gate int Verbose = 2; 537c478bd9Sstevel@tonic-gate bool DontInitGroups = false; 547c478bd9Sstevel@tonic-gate uid_t TrustedUid = 0; 557c478bd9Sstevel@tonic-gate BITMAP256 DontBlameSendmail; 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate # define DELIMITERS " ,/" 587c478bd9Sstevel@tonic-gate # define PATH_SEPARATOR ':' 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate int 617c478bd9Sstevel@tonic-gate main(argc, argv) 627c478bd9Sstevel@tonic-gate int argc; 637c478bd9Sstevel@tonic-gate char **argv; 647c478bd9Sstevel@tonic-gate { 657c478bd9Sstevel@tonic-gate char *cfile; 667c478bd9Sstevel@tonic-gate char *filename = NULL; 677c478bd9Sstevel@tonic-gate SM_FILE_T *cfp; 687c478bd9Sstevel@tonic-gate int ch; 697c478bd9Sstevel@tonic-gate char afilebuf[MAXLINE]; 707c478bd9Sstevel@tonic-gate char buf[MAXLINE]; 717c478bd9Sstevel@tonic-gate struct passwd *pw; 727c478bd9Sstevel@tonic-gate static char rnamebuf[MAXNAME]; 737c478bd9Sstevel@tonic-gate extern char *optarg; 747c478bd9Sstevel@tonic-gate extern int optind; 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate clrbitmap(DontBlameSendmail); 777c478bd9Sstevel@tonic-gate RunAsUid = RealUid = getuid(); 787c478bd9Sstevel@tonic-gate RunAsGid = RealGid = getgid(); 797c478bd9Sstevel@tonic-gate pw = getpwuid(RealUid); 807c478bd9Sstevel@tonic-gate if (pw != NULL) 817c478bd9Sstevel@tonic-gate { 827c478bd9Sstevel@tonic-gate if (strlen(pw->pw_name) > MAXNAME - 1) 837c478bd9Sstevel@tonic-gate pw->pw_name[MAXNAME] = 0; 847c478bd9Sstevel@tonic-gate sm_snprintf(rnamebuf, sizeof rnamebuf, "%s", pw->pw_name); 857c478bd9Sstevel@tonic-gate } 867c478bd9Sstevel@tonic-gate else 877c478bd9Sstevel@tonic-gate (void) sm_snprintf(rnamebuf, sizeof rnamebuf, 887c478bd9Sstevel@tonic-gate "Unknown UID %d", (int) RealUid); 897c478bd9Sstevel@tonic-gate RunAsUserName = RealUserName = rnamebuf; 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate cfile = getcfname(0, 0, SM_GET_SENDMAIL_CF, NULL); 927c478bd9Sstevel@tonic-gate while ((ch = getopt(argc, argv, "C:f:")) != -1) 937c478bd9Sstevel@tonic-gate { 947c478bd9Sstevel@tonic-gate switch ((char)ch) { 957c478bd9Sstevel@tonic-gate case 'C': 967c478bd9Sstevel@tonic-gate cfile = optarg; 977c478bd9Sstevel@tonic-gate break; 987c478bd9Sstevel@tonic-gate case 'f': 997c478bd9Sstevel@tonic-gate filename = optarg; 1007c478bd9Sstevel@tonic-gate break; 1017c478bd9Sstevel@tonic-gate case '?': 1027c478bd9Sstevel@tonic-gate default: 1037c478bd9Sstevel@tonic-gate (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, 1047c478bd9Sstevel@tonic-gate "usage: praliases [-C cffile] [-f aliasfile]\n"); 1057c478bd9Sstevel@tonic-gate exit(EX_USAGE); 1067c478bd9Sstevel@tonic-gate } 1077c478bd9Sstevel@tonic-gate } 1087c478bd9Sstevel@tonic-gate argc -= optind; 1097c478bd9Sstevel@tonic-gate argv += optind; 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate if (filename != NULL) 1127c478bd9Sstevel@tonic-gate { 1137c478bd9Sstevel@tonic-gate praliases(filename, argc, argv); 1147c478bd9Sstevel@tonic-gate exit(EX_OK); 1157c478bd9Sstevel@tonic-gate } 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate if ((cfp = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, cfile, SM_IO_RDONLY, 1187c478bd9Sstevel@tonic-gate NULL)) == NULL) 1197c478bd9Sstevel@tonic-gate { 1207c478bd9Sstevel@tonic-gate (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, 1217c478bd9Sstevel@tonic-gate "praliases: %s: %s\n", cfile, 1227c478bd9Sstevel@tonic-gate sm_errstring(errno)); 1237c478bd9Sstevel@tonic-gate exit(EX_NOINPUT); 1247c478bd9Sstevel@tonic-gate } 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate while (sm_io_fgets(cfp, SM_TIME_DEFAULT, buf, sizeof(buf)) != NULL) 1277c478bd9Sstevel@tonic-gate { 1287c478bd9Sstevel@tonic-gate register char *b, *p; 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate b = strchr(buf, '\n'); 1317c478bd9Sstevel@tonic-gate if (b != NULL) 1327c478bd9Sstevel@tonic-gate *b = '\0'; 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate b = buf; 1357c478bd9Sstevel@tonic-gate switch (*b++) 1367c478bd9Sstevel@tonic-gate { 1377c478bd9Sstevel@tonic-gate case 'O': /* option -- see if alias file */ 1387c478bd9Sstevel@tonic-gate if (sm_strncasecmp(b, " AliasFile", 10) == 0 && 1397c478bd9Sstevel@tonic-gate !(isascii(b[10]) && isalnum(b[10]))) 1407c478bd9Sstevel@tonic-gate { 1417c478bd9Sstevel@tonic-gate /* new form -- find value */ 1427c478bd9Sstevel@tonic-gate b = strchr(b, '='); 1437c478bd9Sstevel@tonic-gate if (b == NULL) 1447c478bd9Sstevel@tonic-gate continue; 1457c478bd9Sstevel@tonic-gate while (isascii(*++b) && isspace(*b)) 1467c478bd9Sstevel@tonic-gate continue; 1477c478bd9Sstevel@tonic-gate } 1487c478bd9Sstevel@tonic-gate else if (*b++ != 'A') 1497c478bd9Sstevel@tonic-gate { 1507c478bd9Sstevel@tonic-gate /* something else boring */ 1517c478bd9Sstevel@tonic-gate continue; 1527c478bd9Sstevel@tonic-gate } 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate /* this is the A or AliasFile option -- save it */ 1557c478bd9Sstevel@tonic-gate if (sm_strlcpy(afilebuf, b, sizeof afilebuf) >= 1567c478bd9Sstevel@tonic-gate sizeof afilebuf) 1577c478bd9Sstevel@tonic-gate { 1587c478bd9Sstevel@tonic-gate (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, 1597c478bd9Sstevel@tonic-gate "praliases: AliasFile filename too long: %.30s\n", 1607c478bd9Sstevel@tonic-gate b); 1617c478bd9Sstevel@tonic-gate (void) sm_io_close(cfp, SM_TIME_DEFAULT); 1627c478bd9Sstevel@tonic-gate exit(EX_CONFIG); 1637c478bd9Sstevel@tonic-gate } 1647c478bd9Sstevel@tonic-gate b = afilebuf; 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate for (p = b; p != NULL; ) 1677c478bd9Sstevel@tonic-gate { 1687c478bd9Sstevel@tonic-gate while (isascii(*p) && isspace(*p)) 1697c478bd9Sstevel@tonic-gate p++; 1707c478bd9Sstevel@tonic-gate if (*p == '\0') 1717c478bd9Sstevel@tonic-gate break; 1727c478bd9Sstevel@tonic-gate b = p; 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate p = strpbrk(p, DELIMITERS); 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate /* find end of spec */ 1777c478bd9Sstevel@tonic-gate if (p != NULL) 1787c478bd9Sstevel@tonic-gate { 1797c478bd9Sstevel@tonic-gate bool quoted = false; 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate for (; *p != '\0'; p++) 1827c478bd9Sstevel@tonic-gate { 1837c478bd9Sstevel@tonic-gate /* 1847c478bd9Sstevel@tonic-gate ** Don't break into a quoted 1857c478bd9Sstevel@tonic-gate ** string. 1867c478bd9Sstevel@tonic-gate */ 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate if (*p == '"') 1897c478bd9Sstevel@tonic-gate quoted = !quoted; 1907c478bd9Sstevel@tonic-gate else if (*p == ',' && !quoted) 1917c478bd9Sstevel@tonic-gate break; 1927c478bd9Sstevel@tonic-gate } 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate /* No more alias specs follow */ 1957c478bd9Sstevel@tonic-gate if (*p == '\0') 1967c478bd9Sstevel@tonic-gate { 1977c478bd9Sstevel@tonic-gate /* chop trailing whitespace */ 1987c478bd9Sstevel@tonic-gate while (isascii(*p) && 1997c478bd9Sstevel@tonic-gate isspace(*p) && 2007c478bd9Sstevel@tonic-gate p > b) 2017c478bd9Sstevel@tonic-gate p--; 2027c478bd9Sstevel@tonic-gate *p = '\0'; 2037c478bd9Sstevel@tonic-gate p = NULL; 2047c478bd9Sstevel@tonic-gate } 2057c478bd9Sstevel@tonic-gate } 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate if (p != NULL) 2087c478bd9Sstevel@tonic-gate { 2097c478bd9Sstevel@tonic-gate char *e = p - 1; 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate /* chop trailing whitespace */ 2127c478bd9Sstevel@tonic-gate while (isascii(*e) && 2137c478bd9Sstevel@tonic-gate isspace(*e) && 2147c478bd9Sstevel@tonic-gate e > b) 2157c478bd9Sstevel@tonic-gate e--; 2167c478bd9Sstevel@tonic-gate *++e = '\0'; 2177c478bd9Sstevel@tonic-gate *p++ = '\0'; 2187c478bd9Sstevel@tonic-gate } 2197c478bd9Sstevel@tonic-gate praliases(b, argc, argv); 2207c478bd9Sstevel@tonic-gate } 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate default: 2237c478bd9Sstevel@tonic-gate continue; 2247c478bd9Sstevel@tonic-gate } 2257c478bd9Sstevel@tonic-gate } 2267c478bd9Sstevel@tonic-gate (void) sm_io_close(cfp, SM_TIME_DEFAULT); 2277c478bd9Sstevel@tonic-gate exit(EX_OK); 2287c478bd9Sstevel@tonic-gate /* NOTREACHED */ 2297c478bd9Sstevel@tonic-gate return EX_OK; 2307c478bd9Sstevel@tonic-gate } 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate static void 2337c478bd9Sstevel@tonic-gate praliases(filename, argc, argv) 2347c478bd9Sstevel@tonic-gate char *filename; 2357c478bd9Sstevel@tonic-gate int argc; 2367c478bd9Sstevel@tonic-gate char **argv; 2377c478bd9Sstevel@tonic-gate { 2387c478bd9Sstevel@tonic-gate int result; 2397c478bd9Sstevel@tonic-gate char *colon; 2407c478bd9Sstevel@tonic-gate char *db_name; 2417c478bd9Sstevel@tonic-gate char *db_type; 2427c478bd9Sstevel@tonic-gate SMDB_DATABASE *database = NULL; 2437c478bd9Sstevel@tonic-gate SMDB_CURSOR *cursor = NULL; 2447c478bd9Sstevel@tonic-gate SMDB_DBENT db_key, db_value; 2457c478bd9Sstevel@tonic-gate SMDB_DBPARAMS params; 2467c478bd9Sstevel@tonic-gate SMDB_USER_INFO user_info; 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate colon = strchr(filename, PATH_SEPARATOR); 2497c478bd9Sstevel@tonic-gate if (colon == NULL) 2507c478bd9Sstevel@tonic-gate { 2517c478bd9Sstevel@tonic-gate db_name = filename; 2527c478bd9Sstevel@tonic-gate db_type = SMDB_TYPE_DEFAULT; 2537c478bd9Sstevel@tonic-gate } 2547c478bd9Sstevel@tonic-gate else 2557c478bd9Sstevel@tonic-gate { 2567c478bd9Sstevel@tonic-gate *colon = '\0'; 2577c478bd9Sstevel@tonic-gate db_name = colon + 1; 2587c478bd9Sstevel@tonic-gate db_type = filename; 2597c478bd9Sstevel@tonic-gate } 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate /* clean off arguments */ 2627c478bd9Sstevel@tonic-gate for (;;) 2637c478bd9Sstevel@tonic-gate { 2647c478bd9Sstevel@tonic-gate while (isascii(*db_name) && isspace(*db_name)) 2657c478bd9Sstevel@tonic-gate db_name++; 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate if (*db_name != '-') 2687c478bd9Sstevel@tonic-gate break; 2697c478bd9Sstevel@tonic-gate while (*db_name != '\0' && 2707c478bd9Sstevel@tonic-gate !(isascii(*db_name) && isspace(*db_name))) 2717c478bd9Sstevel@tonic-gate db_name++; 2727c478bd9Sstevel@tonic-gate } 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate /* Skip non-file based DB types */ 2757c478bd9Sstevel@tonic-gate if (db_type != NULL && *db_type != '\0') 2767c478bd9Sstevel@tonic-gate { 2777c478bd9Sstevel@tonic-gate if (db_type != SMDB_TYPE_DEFAULT && 2787c478bd9Sstevel@tonic-gate strcmp(db_type, "hash") != 0 && 2797c478bd9Sstevel@tonic-gate strcmp(db_type, "btree") != 0 && 2807c478bd9Sstevel@tonic-gate strcmp(db_type, "dbm") != 0) 2817c478bd9Sstevel@tonic-gate { 2827c478bd9Sstevel@tonic-gate sm_io_fprintf(smioerr, SM_TIME_DEFAULT, 2837c478bd9Sstevel@tonic-gate "praliases: Skipping non-file based alias type %s\n", 2847c478bd9Sstevel@tonic-gate db_type); 2857c478bd9Sstevel@tonic-gate return; 2867c478bd9Sstevel@tonic-gate } 2877c478bd9Sstevel@tonic-gate } 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate if (*db_name == '\0' || (db_type != NULL && *db_type == '\0')) 2907c478bd9Sstevel@tonic-gate { 2917c478bd9Sstevel@tonic-gate if (colon != NULL) 2927c478bd9Sstevel@tonic-gate *colon = ':'; 2937c478bd9Sstevel@tonic-gate (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, 2947c478bd9Sstevel@tonic-gate "praliases: illegal alias specification: %s\n", filename); 2957c478bd9Sstevel@tonic-gate goto fatal; 2967c478bd9Sstevel@tonic-gate } 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate memset(¶ms, '\0', sizeof params); 2997c478bd9Sstevel@tonic-gate params.smdbp_cache_size = 1024 * 1024; 3007c478bd9Sstevel@tonic-gate 3017c478bd9Sstevel@tonic-gate user_info.smdbu_id = RunAsUid; 3027c478bd9Sstevel@tonic-gate user_info.smdbu_group_id = RunAsGid; 3037c478bd9Sstevel@tonic-gate (void) sm_strlcpy(user_info.smdbu_name, RunAsUserName, 3047c478bd9Sstevel@tonic-gate SMDB_MAX_USER_NAME_LEN); 3057c478bd9Sstevel@tonic-gate 3067c478bd9Sstevel@tonic-gate result = smdb_open_database(&database, db_name, O_RDONLY, 0, 3077c478bd9Sstevel@tonic-gate SFF_ROOTOK, db_type, &user_info, ¶ms); 3087c478bd9Sstevel@tonic-gate if (result != SMDBE_OK) 3097c478bd9Sstevel@tonic-gate { 3107c478bd9Sstevel@tonic-gate sm_io_fprintf(smioerr, SM_TIME_DEFAULT, 3117c478bd9Sstevel@tonic-gate "praliases: %s: open: %s\n", 3127c478bd9Sstevel@tonic-gate db_name, sm_errstring(result)); 3137c478bd9Sstevel@tonic-gate goto fatal; 3147c478bd9Sstevel@tonic-gate } 3157c478bd9Sstevel@tonic-gate 3167c478bd9Sstevel@tonic-gate if (argc == 0) 3177c478bd9Sstevel@tonic-gate { 3187c478bd9Sstevel@tonic-gate memset(&db_key, '\0', sizeof db_key); 3197c478bd9Sstevel@tonic-gate memset(&db_value, '\0', sizeof db_value); 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate result = database->smdb_cursor(database, &cursor, 0); 3227c478bd9Sstevel@tonic-gate if (result != SMDBE_OK) 3237c478bd9Sstevel@tonic-gate { 3247c478bd9Sstevel@tonic-gate (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, 3257c478bd9Sstevel@tonic-gate "praliases: %s: set cursor: %s\n", db_name, 3267c478bd9Sstevel@tonic-gate sm_errstring(result)); 3277c478bd9Sstevel@tonic-gate goto fatal; 3287c478bd9Sstevel@tonic-gate } 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate while ((result = cursor->smdbc_get(cursor, &db_key, &db_value, 3317c478bd9Sstevel@tonic-gate SMDB_CURSOR_GET_NEXT)) == 3327c478bd9Sstevel@tonic-gate SMDBE_OK) 3337c478bd9Sstevel@tonic-gate { 3347c478bd9Sstevel@tonic-gate #if 0 3357c478bd9Sstevel@tonic-gate /* skip magic @:@ entry */ 3367c478bd9Sstevel@tonic-gate if (db_key.size == 2 && 3377c478bd9Sstevel@tonic-gate db_key.data[0] == '@' && 3387c478bd9Sstevel@tonic-gate db_key.data[1] == '\0' && 3397c478bd9Sstevel@tonic-gate db_value.size == 2 && 3407c478bd9Sstevel@tonic-gate db_value.data[0] == '@' && 3417c478bd9Sstevel@tonic-gate db_value.data[1] == '\0') 3427c478bd9Sstevel@tonic-gate continue; 3437c478bd9Sstevel@tonic-gate #endif /* 0 */ 3447c478bd9Sstevel@tonic-gate 3457c478bd9Sstevel@tonic-gate (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, 3467c478bd9Sstevel@tonic-gate "%.*s:%.*s\n", 3477c478bd9Sstevel@tonic-gate (int) db_key.size, 3487c478bd9Sstevel@tonic-gate (char *) db_key.data, 3497c478bd9Sstevel@tonic-gate (int) db_value.size, 3507c478bd9Sstevel@tonic-gate (char *) db_value.data); 3517c478bd9Sstevel@tonic-gate } 3527c478bd9Sstevel@tonic-gate 3537c478bd9Sstevel@tonic-gate if (result != SMDBE_OK && result != SMDBE_LAST_ENTRY) 3547c478bd9Sstevel@tonic-gate { 3557c478bd9Sstevel@tonic-gate (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, 3567c478bd9Sstevel@tonic-gate "praliases: %s: get value at cursor: %s\n", 3577c478bd9Sstevel@tonic-gate db_name, sm_errstring(result)); 3587c478bd9Sstevel@tonic-gate goto fatal; 3597c478bd9Sstevel@tonic-gate } 3607c478bd9Sstevel@tonic-gate } 3617c478bd9Sstevel@tonic-gate else for (; *argv != NULL; ++argv) 3627c478bd9Sstevel@tonic-gate { 3637c478bd9Sstevel@tonic-gate int get_res; 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate memset(&db_key, '\0', sizeof db_key); 3667c478bd9Sstevel@tonic-gate memset(&db_value, '\0', sizeof db_value); 3677c478bd9Sstevel@tonic-gate db_key.data = *argv; 3687c478bd9Sstevel@tonic-gate db_key.size = strlen(*argv); 3697c478bd9Sstevel@tonic-gate get_res = database->smdb_get(database, &db_key, &db_value, 0); 3707c478bd9Sstevel@tonic-gate if (get_res == SMDBE_NOT_FOUND) 3717c478bd9Sstevel@tonic-gate { 3727c478bd9Sstevel@tonic-gate db_key.size++; 3737c478bd9Sstevel@tonic-gate get_res = database->smdb_get(database, &db_key, 3747c478bd9Sstevel@tonic-gate &db_value, 0); 3757c478bd9Sstevel@tonic-gate } 3767c478bd9Sstevel@tonic-gate if (get_res == SMDBE_OK) 3777c478bd9Sstevel@tonic-gate { 3787c478bd9Sstevel@tonic-gate (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, 3797c478bd9Sstevel@tonic-gate "%.*s:%.*s\n", 3807c478bd9Sstevel@tonic-gate (int) db_key.size, 3817c478bd9Sstevel@tonic-gate (char *) db_key.data, 3827c478bd9Sstevel@tonic-gate (int) db_value.size, 3837c478bd9Sstevel@tonic-gate (char *) db_value.data); 3847c478bd9Sstevel@tonic-gate } 3857c478bd9Sstevel@tonic-gate else 3867c478bd9Sstevel@tonic-gate (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, 3877c478bd9Sstevel@tonic-gate "%s: No such key\n", 3887c478bd9Sstevel@tonic-gate (char *)db_key.data); 3897c478bd9Sstevel@tonic-gate } 3907c478bd9Sstevel@tonic-gate 3917c478bd9Sstevel@tonic-gate fatal: 3927c478bd9Sstevel@tonic-gate if (cursor != NULL) 3937c478bd9Sstevel@tonic-gate (void) cursor->smdbc_close(cursor); 3947c478bd9Sstevel@tonic-gate if (database != NULL) 3957c478bd9Sstevel@tonic-gate (void) database->smdb_close(database); 3967c478bd9Sstevel@tonic-gate if (colon != NULL) 3977c478bd9Sstevel@tonic-gate *colon = ':'; 3987c478bd9Sstevel@tonic-gate return; 3997c478bd9Sstevel@tonic-gate } 400