10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*3028Smh27603 * Common Development and Distribution License (the "License"). 6*3028Smh27603 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*3028Smh27603 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include "pmconfig.h" 290Sstevel@tonic-gate #include <deflt.h> 300Sstevel@tonic-gate #include <pwd.h> 310Sstevel@tonic-gate 320Sstevel@tonic-gate #ifdef sparc 330Sstevel@tonic-gate #include <libdevinfo.h> 340Sstevel@tonic-gate static char sf_cmt[] = "# Statefile\t\tPath\n"; 350Sstevel@tonic-gate #endif 360Sstevel@tonic-gate 370Sstevel@tonic-gate static char as_cmt[] = 380Sstevel@tonic-gate "# Auto-Shutdown\t\tIdle(min)\tStart/Finish(hh:mm)\tBehavior\n"; 390Sstevel@tonic-gate 400Sstevel@tonic-gate char **line_args; 410Sstevel@tonic-gate int lineno = 0; 420Sstevel@tonic-gate 430Sstevel@tonic-gate /* 440Sstevel@tonic-gate * cpr and pm combined permission/update status 450Sstevel@tonic-gate */ 460Sstevel@tonic-gate prmup_t cpr_status = { 0, OKUP, "cpr" }; 470Sstevel@tonic-gate prmup_t pm_status = { 0, OKUP, "pm" }; 480Sstevel@tonic-gate 490Sstevel@tonic-gate 500Sstevel@tonic-gate /* 510Sstevel@tonic-gate * For config file parsing to work correctly/efficiently, this table 520Sstevel@tonic-gate * needs to be sorted by .keyword and any longer string like "device" 530Sstevel@tonic-gate * must appear before a substring like "dev". 540Sstevel@tonic-gate */ 550Sstevel@tonic-gate static cinfo_t conftab[] = { 560Sstevel@tonic-gate "autopm", autopm, &pm_status, NULL, 2, 0, 1, 570Sstevel@tonic-gate "autoshutdown", autosd, &cpr_status, as_cmt, 5, 0, 1, 58*3028Smh27603 "cpu-threshold", cputhr, &pm_status, NULL, 2, 0, 1, 59*3028Smh27603 "cpupm", cpupm, &pm_status, NULL, 2, 0, 1, 600Sstevel@tonic-gate "device-dependency-property", 610Sstevel@tonic-gate ddprop, &pm_status, NULL, 3, 1, 1, 620Sstevel@tonic-gate "device-dependency", devdep, &pm_status, NULL, 3, 1, 1, 630Sstevel@tonic-gate "device-thresholds", devthr, &pm_status, NULL, 3, 1, 1, 640Sstevel@tonic-gate "diskreads", dreads, &cpr_status, NULL, 2, 0, 1, 650Sstevel@tonic-gate "idlecheck", idlechk, &cpr_status, NULL, 2, 0, 0, 660Sstevel@tonic-gate "loadaverage", loadavg, &cpr_status, NULL, 2, 0, 1, 670Sstevel@tonic-gate "nfsreqs", nfsreq, &cpr_status, NULL, 2, 0, 1, 680Sstevel@tonic-gate #ifdef sparc 690Sstevel@tonic-gate "statefile", sfpath, &cpr_status, sf_cmt, 2, 0, 0, 700Sstevel@tonic-gate #endif 710Sstevel@tonic-gate "system-threshold", systhr, &pm_status, NULL, 2, 0, 1, 720Sstevel@tonic-gate "ttychars", tchars, &cpr_status, NULL, 2, 0, 1, 730Sstevel@tonic-gate NULL, NULL, NULL, NULL, 0, 0, 0, 740Sstevel@tonic-gate }; 750Sstevel@tonic-gate 760Sstevel@tonic-gate 770Sstevel@tonic-gate /* 780Sstevel@tonic-gate * Set cpr/pm permission from default file info. 790Sstevel@tonic-gate */ 800Sstevel@tonic-gate static void 810Sstevel@tonic-gate set_perm(char *defstr, char *user, int *perm, int cons) 820Sstevel@tonic-gate { 830Sstevel@tonic-gate char *dinfo, *tk; 840Sstevel@tonic-gate 850Sstevel@tonic-gate /* 860Sstevel@tonic-gate * /etc/default/power entries are: 870Sstevel@tonic-gate * all (all users + root) 880Sstevel@tonic-gate * - (none + root) 890Sstevel@tonic-gate * <user1[, user2...> (list users + root) 900Sstevel@tonic-gate * console-owner (console onwer + root) 910Sstevel@tonic-gate * Any error in reading/parsing the file limits the 920Sstevel@tonic-gate * access requirement to root. 930Sstevel@tonic-gate */ 940Sstevel@tonic-gate dinfo = defread(defstr); 950Sstevel@tonic-gate mesg(MDEBUG, "set_perm: \"%s\", value \"%s\"\n", 960Sstevel@tonic-gate defstr, dinfo ? dinfo : "NULL"); 970Sstevel@tonic-gate if (dinfo == NULL) 980Sstevel@tonic-gate return; 990Sstevel@tonic-gate else if (strcmp(dinfo, "all") == 0) 1000Sstevel@tonic-gate *perm = 1; 1010Sstevel@tonic-gate else if (strcmp(dinfo, "console-owner") == 0) 1020Sstevel@tonic-gate *perm = cons; 1030Sstevel@tonic-gate else if (user != NULL && 1040Sstevel@tonic-gate (*dinfo == '<') && (tk = strrchr(++dinfo, '>'))) { 1050Sstevel@tonic-gate /* Scan dinfo for a matching user. */ 1060Sstevel@tonic-gate for (*tk = '\0'; tk = strtok(dinfo, ", "); dinfo = NULL) { 1070Sstevel@tonic-gate mesg(MDEBUG, "match_user: cmp (\"%s\", \"%s\")\n", 1080Sstevel@tonic-gate tk, user); 1090Sstevel@tonic-gate if (strcmp(tk, user) == 0) { 1100Sstevel@tonic-gate *perm = 1; 1110Sstevel@tonic-gate break; 1120Sstevel@tonic-gate } 1130Sstevel@tonic-gate } 1140Sstevel@tonic-gate } 1150Sstevel@tonic-gate } 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate /* 1190Sstevel@tonic-gate * Lookup cpr/pm user permissions in "/etc/default/power". 1200Sstevel@tonic-gate */ 1210Sstevel@tonic-gate void 1220Sstevel@tonic-gate lookup_perms(void) 1230Sstevel@tonic-gate { 1240Sstevel@tonic-gate struct passwd *pent; 1250Sstevel@tonic-gate struct stat stbuf; 1260Sstevel@tonic-gate int cons_perm; 1270Sstevel@tonic-gate char *user; 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate if ((ruid = getuid()) == 0) { 1300Sstevel@tonic-gate cpr_status.perm = pm_status.perm = 1; 1310Sstevel@tonic-gate return; 1320Sstevel@tonic-gate } else if ((pent = getpwuid(ruid)) != NULL) { 1330Sstevel@tonic-gate user = pent->pw_name; 1340Sstevel@tonic-gate } else { 1350Sstevel@tonic-gate user = NULL; 1360Sstevel@tonic-gate } 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate if (defopen("/etc/default/power") == -1) 1390Sstevel@tonic-gate return; 1400Sstevel@tonic-gate if (stat("/dev/console", &stbuf) == -1) 1410Sstevel@tonic-gate cons_perm = 0; 1420Sstevel@tonic-gate else 1430Sstevel@tonic-gate cons_perm = (ruid == stbuf.st_uid); 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate set_perm("PMCHANGEPERM=", user, &pm_status.perm, cons_perm); 1460Sstevel@tonic-gate set_perm("CPRCHANGEPERM=", user, &cpr_status.perm, cons_perm); 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate (void) defopen(NULL); 1490Sstevel@tonic-gate } 1500Sstevel@tonic-gate 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate #ifdef sparc 1530Sstevel@tonic-gate /* 1540Sstevel@tonic-gate * Lookup energystar-v[23] property and set estar_vers. 1550Sstevel@tonic-gate */ 1560Sstevel@tonic-gate void 1570Sstevel@tonic-gate lookup_estar_vers(void) 1580Sstevel@tonic-gate { 1590Sstevel@tonic-gate char es_prop[] = "energystar-v?", *fmt = "%s init/access error\n"; 1600Sstevel@tonic-gate di_prom_handle_t ph; 1610Sstevel@tonic-gate di_node_t node; 1620Sstevel@tonic-gate uchar_t *prop_data; 1630Sstevel@tonic-gate int last; 1640Sstevel@tonic-gate char ch; 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate if ((node = di_init("/", DINFOPROP)) == DI_NODE_NIL) { 1670Sstevel@tonic-gate mesg(MERR, fmt, "di_init"); 1680Sstevel@tonic-gate return; 1690Sstevel@tonic-gate } else if ((ph = di_prom_init()) == DI_PROM_HANDLE_NIL) { 1700Sstevel@tonic-gate mesg(MERR, fmt, "di_prom_init"); 1710Sstevel@tonic-gate di_fini(node); 1720Sstevel@tonic-gate return; 1730Sstevel@tonic-gate } 1740Sstevel@tonic-gate last = strlen(es_prop) - 1; 1750Sstevel@tonic-gate for (ch = ESTAR_V2; ch <= ESTAR_V3; ch++) { 1760Sstevel@tonic-gate es_prop[last] = ch; 1770Sstevel@tonic-gate if (di_prom_prop_lookup_bytes(ph, node, 1780Sstevel@tonic-gate es_prop, &prop_data) == 0) { 1790Sstevel@tonic-gate mesg(MDEBUG, "get_estar_vers: %s prop found\n", 1800Sstevel@tonic-gate es_prop); 1810Sstevel@tonic-gate estar_vers = ch; 1820Sstevel@tonic-gate break; 1830Sstevel@tonic-gate } 1840Sstevel@tonic-gate } 1850Sstevel@tonic-gate di_prom_fini(ph); 1860Sstevel@tonic-gate di_fini(node); 1870Sstevel@tonic-gate } 1880Sstevel@tonic-gate #endif /* sparc */ 1890Sstevel@tonic-gate 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate /* 1920Sstevel@tonic-gate * limit open() to the real user 1930Sstevel@tonic-gate */ 1940Sstevel@tonic-gate static int 1950Sstevel@tonic-gate pmc_open(char *name, int oflag) 1960Sstevel@tonic-gate { 1970Sstevel@tonic-gate uid_t euid; 1980Sstevel@tonic-gate int fd; 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate euid = geteuid(); 2010Sstevel@tonic-gate if (seteuid(ruid) == -1) 2020Sstevel@tonic-gate mesg(MEXIT, "cannot reset euid to %d, %s\n", 2030Sstevel@tonic-gate ruid, strerror(errno)); 2040Sstevel@tonic-gate fd = open(name, oflag); 2050Sstevel@tonic-gate (void) seteuid(euid); 2060Sstevel@tonic-gate return (fd); 2070Sstevel@tonic-gate } 2080Sstevel@tonic-gate 2090Sstevel@tonic-gate 2100Sstevel@tonic-gate /* 2110Sstevel@tonic-gate * Alloc space and read a config file; caller needs to free the space. 2120Sstevel@tonic-gate */ 2130Sstevel@tonic-gate static char * 2140Sstevel@tonic-gate get_conf_data(char *name) 2150Sstevel@tonic-gate { 2160Sstevel@tonic-gate struct stat stbuf; 2170Sstevel@tonic-gate ssize_t nread; 2180Sstevel@tonic-gate size_t size; 2190Sstevel@tonic-gate char *buf; 2200Sstevel@tonic-gate int fd; 2210Sstevel@tonic-gate 2220Sstevel@tonic-gate if ((fd = pmc_open(name, O_RDONLY)) == -1) 2230Sstevel@tonic-gate mesg(MEXIT, "cannot open %s\n", name); 2240Sstevel@tonic-gate else if (fstat(fd, &stbuf) == -1) 2250Sstevel@tonic-gate mesg(MEXIT, "cannot stat %s\n", name); 2260Sstevel@tonic-gate size = (size_t)stbuf.st_size; 2270Sstevel@tonic-gate def_src = (stbuf.st_ino == def_info.st_ino && 2280Sstevel@tonic-gate stbuf.st_dev == def_info.st_dev); 2290Sstevel@tonic-gate if ((buf = malloc(size + 1)) == NULL) 2300Sstevel@tonic-gate mesg(MEXIT, "cannot allocate %u for \"%s\"\n", size + 1, name); 2310Sstevel@tonic-gate nread = read(fd, buf, size); 2320Sstevel@tonic-gate (void) close(fd); 2330Sstevel@tonic-gate if (nread != (ssize_t)size) 2340Sstevel@tonic-gate mesg(MEXIT, "read error, expect %u, got %d, file \"%s\"\n", 2350Sstevel@tonic-gate size, nread, name); 2360Sstevel@tonic-gate *(buf + size) = '\0'; 2370Sstevel@tonic-gate return (buf); 2380Sstevel@tonic-gate } 2390Sstevel@tonic-gate 2400Sstevel@tonic-gate 2410Sstevel@tonic-gate /* 2420Sstevel@tonic-gate * Add an arg to line_args, adding space if needed. 2430Sstevel@tonic-gate */ 2440Sstevel@tonic-gate static void 2450Sstevel@tonic-gate newarg(char *arg, int index) 2460Sstevel@tonic-gate { 2470Sstevel@tonic-gate static int alcnt; 2480Sstevel@tonic-gate size_t size; 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate if ((index + 1) > alcnt) { 2510Sstevel@tonic-gate alcnt += 4; 2520Sstevel@tonic-gate size = alcnt * sizeof (*line_args); 2530Sstevel@tonic-gate if ((line_args = realloc(line_args, size)) == NULL) 2540Sstevel@tonic-gate mesg(MEXIT, "cannot alloc %u for line args\n", size); 2550Sstevel@tonic-gate } 2560Sstevel@tonic-gate *(line_args + index) = arg; 2570Sstevel@tonic-gate } 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate 2600Sstevel@tonic-gate /* 2610Sstevel@tonic-gate * Convert blank-delimited words into an arg vector and return 2620Sstevel@tonic-gate * the arg count; character strings get null-terminated in place. 2630Sstevel@tonic-gate */ 2640Sstevel@tonic-gate static int 2650Sstevel@tonic-gate build_args(char *cline, char *tail) 2660Sstevel@tonic-gate { 2670Sstevel@tonic-gate extern int debug; 2680Sstevel@tonic-gate char **vec, *arg, *cp; 2690Sstevel@tonic-gate int cnt = 0; 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate /* 2720Sstevel@tonic-gate * Search logic: look for "\\\n" as a continuation marker, 2730Sstevel@tonic-gate * treat any other "\\*" as ordinary arg data, scan until a 2740Sstevel@tonic-gate * white-space delimiter is found, and if the arg has length, 2750Sstevel@tonic-gate * null-terminate and save arg to line_args. The scan includes 2760Sstevel@tonic-gate * tail so the last arg is found without any special-case code. 2770Sstevel@tonic-gate */ 2780Sstevel@tonic-gate for (arg = cp = cline; cp <= tail; cp++) { 2790Sstevel@tonic-gate if (*cp == '\\') { 2800Sstevel@tonic-gate if (*(cp + 1) && *(cp + 1) != '\n') { 2810Sstevel@tonic-gate cp++; 2820Sstevel@tonic-gate continue; 2830Sstevel@tonic-gate } 2840Sstevel@tonic-gate } else if (strchr(" \t\n", *cp) == NULL) 2850Sstevel@tonic-gate continue; 2860Sstevel@tonic-gate if (cp - arg) { 2870Sstevel@tonic-gate *cp = '\0'; 2880Sstevel@tonic-gate newarg(arg, cnt++); 2890Sstevel@tonic-gate } 2900Sstevel@tonic-gate arg = cp + 1; 2910Sstevel@tonic-gate } 2920Sstevel@tonic-gate newarg(NULL, cnt); 2930Sstevel@tonic-gate 2940Sstevel@tonic-gate if (debug) { 2950Sstevel@tonic-gate mesg(MDEBUG, "\nline %d, found %d args:\n", lineno, cnt); 2960Sstevel@tonic-gate for (vec = line_args; *vec; vec++) 2970Sstevel@tonic-gate mesg(MDEBUG, " \"%s\"\n", *vec); 2980Sstevel@tonic-gate } 2990Sstevel@tonic-gate 3000Sstevel@tonic-gate return (cnt); 3010Sstevel@tonic-gate } 3020Sstevel@tonic-gate 3030Sstevel@tonic-gate 3040Sstevel@tonic-gate /* 3050Sstevel@tonic-gate * Match leading keyword from a conf line and 3060Sstevel@tonic-gate * return a reference to a config info struct. 3070Sstevel@tonic-gate */ 3080Sstevel@tonic-gate static cinfo_t * 3090Sstevel@tonic-gate get_cinfo(void) 3100Sstevel@tonic-gate { 3110Sstevel@tonic-gate cinfo_t *cip, *info = NULL; 3120Sstevel@tonic-gate char *keyword; 3130Sstevel@tonic-gate int chr_diff; 3140Sstevel@tonic-gate 3150Sstevel@tonic-gate /* 3160Sstevel@tonic-gate * Scan the config table for a matching keyword; since the table 3170Sstevel@tonic-gate * is sorted by keyword strings, a few optimizations can be done: 3180Sstevel@tonic-gate * first compare only the first byte of the keyword, skip any 3190Sstevel@tonic-gate * table string that starts with a lower ASCII value, compare the 3200Sstevel@tonic-gate * full string only when the first byte matches, and stop checking 3210Sstevel@tonic-gate * if the table string starts with a higher ASCII value. 3220Sstevel@tonic-gate */ 3230Sstevel@tonic-gate keyword = LINEARG(0); 3240Sstevel@tonic-gate for (cip = conftab; cip->keyword; cip++) { 3250Sstevel@tonic-gate chr_diff = (int)(*cip->keyword - *keyword); 3260Sstevel@tonic-gate #if 0 3270Sstevel@tonic-gate mesg(MDEBUG, "line %d, ('%c' - '%c') = %d\n", 3280Sstevel@tonic-gate lineno, *cip->keyword, *line, chr_diff); 3290Sstevel@tonic-gate #endif 3300Sstevel@tonic-gate if (chr_diff < 0) 3310Sstevel@tonic-gate continue; 3320Sstevel@tonic-gate else if (chr_diff == 0) { 3330Sstevel@tonic-gate if (strcmp(keyword, cip->keyword) == 0) { 3340Sstevel@tonic-gate info = cip; 3350Sstevel@tonic-gate break; 3360Sstevel@tonic-gate } 3370Sstevel@tonic-gate } else 3380Sstevel@tonic-gate break; 3390Sstevel@tonic-gate } 3400Sstevel@tonic-gate return (info); 3410Sstevel@tonic-gate } 3420Sstevel@tonic-gate 3430Sstevel@tonic-gate 3440Sstevel@tonic-gate /* 3450Sstevel@tonic-gate * Find the end of a [possibly continued] conf line 3460Sstevel@tonic-gate * and record the real/lf-delimited line count at *lcnt. 3470Sstevel@tonic-gate */ 3480Sstevel@tonic-gate static char * 3490Sstevel@tonic-gate find_line_end(char *line, int *lcnt) 3500Sstevel@tonic-gate { 3510Sstevel@tonic-gate char *next, *lf; 3520Sstevel@tonic-gate 3530Sstevel@tonic-gate *lcnt = 0; 3540Sstevel@tonic-gate next = line; 3550Sstevel@tonic-gate while (lf = strchr(next, '\n')) { 3560Sstevel@tonic-gate (*lcnt)++; 3570Sstevel@tonic-gate if (lf == line || (*(lf - 1) != '\\') || *(lf + 1) == '\0') 3580Sstevel@tonic-gate break; 3590Sstevel@tonic-gate next = lf + 1; 3600Sstevel@tonic-gate } 3610Sstevel@tonic-gate return (lf); 3620Sstevel@tonic-gate } 3630Sstevel@tonic-gate 3640Sstevel@tonic-gate 3650Sstevel@tonic-gate /* 3660Sstevel@tonic-gate * Parse the named conf file and for each conf line 3670Sstevel@tonic-gate * call the action routine or conftab handler routine. 3680Sstevel@tonic-gate */ 3690Sstevel@tonic-gate void 3700Sstevel@tonic-gate parse_conf_file(char *name, vact_t action) 3710Sstevel@tonic-gate { 3720Sstevel@tonic-gate char *file_buf, *cline, *line, *lend; 3730Sstevel@tonic-gate cinfo_t *cip; 3740Sstevel@tonic-gate int linc, cnt; 3750Sstevel@tonic-gate size_t llen; 3760Sstevel@tonic-gate 3770Sstevel@tonic-gate file_buf = get_conf_data(name); 3780Sstevel@tonic-gate mesg(MDEBUG, "\nnow parsing \"%s\"...\n", name); 3790Sstevel@tonic-gate 3800Sstevel@tonic-gate lineno = 1; 3810Sstevel@tonic-gate line = file_buf; 3820Sstevel@tonic-gate while (lend = find_line_end(line, &linc)) { 3830Sstevel@tonic-gate /* 3840Sstevel@tonic-gate * Each line should start with valid data 3850Sstevel@tonic-gate * but leading white-space can be ignored 3860Sstevel@tonic-gate */ 3870Sstevel@tonic-gate while (line < lend) { 3880Sstevel@tonic-gate if (*line != ' ' && *line != '\t') 3890Sstevel@tonic-gate break; 3900Sstevel@tonic-gate line++; 3910Sstevel@tonic-gate } 3920Sstevel@tonic-gate 3930Sstevel@tonic-gate /* 3940Sstevel@tonic-gate * Copy line into allocated space and null-terminate 3950Sstevel@tonic-gate * without the trailing line-feed. 3960Sstevel@tonic-gate */ 3970Sstevel@tonic-gate if ((llen = (lend - line)) != 0) { 3980Sstevel@tonic-gate if ((cline = malloc(llen + 1)) == NULL) 3990Sstevel@tonic-gate mesg(MEXIT, "cannot alloc %u bytes " 4000Sstevel@tonic-gate "for line copy\n", llen); 4010Sstevel@tonic-gate (void) memcpy(cline, line, llen); 4020Sstevel@tonic-gate *(cline + llen) = '\0'; 4030Sstevel@tonic-gate } else 4040Sstevel@tonic-gate cline = NULL; 4050Sstevel@tonic-gate 4060Sstevel@tonic-gate /* 4070Sstevel@tonic-gate * For blank and comment lines: possibly show a debug 4080Sstevel@tonic-gate * message and otherwise ignore them. For other lines: 4090Sstevel@tonic-gate * parse into an arg vector and try to match the first 4100Sstevel@tonic-gate * arg with conftab keywords. When a match is found, 4110Sstevel@tonic-gate * check for exact or minimum arg count, and call the 4120Sstevel@tonic-gate * action or handler routine; if handler does not return 4130Sstevel@tonic-gate * OKUP, set the referenced update value to NOUP so that 4140Sstevel@tonic-gate * later CPR or PM updates are skipped. 4150Sstevel@tonic-gate */ 4160Sstevel@tonic-gate if (llen == 0) 4170Sstevel@tonic-gate mesg(MDEBUG, "\nline %d, blank...\n", lineno); 4180Sstevel@tonic-gate else if (*line == '#') 4190Sstevel@tonic-gate mesg(MDEBUG, "\nline %d, comment...\n", lineno); 4200Sstevel@tonic-gate else if (cnt = build_args(cline, cline + llen)) { 4210Sstevel@tonic-gate if ((cip = get_cinfo()) == NULL) { 4220Sstevel@tonic-gate mesg(MEXIT, "unrecognized keyword \"%s\"\n", 4230Sstevel@tonic-gate LINEARG(0)); 4240Sstevel@tonic-gate } else if (cnt != cip->argc && 4250Sstevel@tonic-gate (cip->any == 0 || cnt < cip->argc)) { 4260Sstevel@tonic-gate mesg(MEXIT, "found %d args, expect %d%s\n", 4270Sstevel@tonic-gate cnt, cip->argc, cip->any ? "+" : ""); 4280Sstevel@tonic-gate } else if (action) 4290Sstevel@tonic-gate (*action)(line, llen + 1, cip); 4300Sstevel@tonic-gate else if (cip->status->perm && (def_src || cip->alt)) { 4310Sstevel@tonic-gate if ((*cip->handler)() != OKUP) 4320Sstevel@tonic-gate cip->status->update = NOUP; 4330Sstevel@tonic-gate } else { 4340Sstevel@tonic-gate mesg(MDEBUG, 4350Sstevel@tonic-gate "==> handler skipped: %s_perm %d, " 4360Sstevel@tonic-gate "def_src %d, alt %d\n", cip->status->set, 4370Sstevel@tonic-gate cip->status->perm, def_src, cip->alt); 4380Sstevel@tonic-gate } 4390Sstevel@tonic-gate } 4400Sstevel@tonic-gate 4410Sstevel@tonic-gate if (cline) 4420Sstevel@tonic-gate free(cline); 4430Sstevel@tonic-gate line = lend + 1; 4440Sstevel@tonic-gate lineno += linc; 4450Sstevel@tonic-gate } 4460Sstevel@tonic-gate lineno = 0; 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate free(file_buf); 4490Sstevel@tonic-gate } 450