dispatch.c revision 26795
1/*
2 * The new sysinstall program.
3 *
4 * This is probably the last program in the `sysinstall' line - the next
5 * generation being essentially a complete rewrite.
6 *
7 * $Id: dispatch.c,v 1.18 1997/06/21 15:45:08 jkh Exp $
8 *
9 * Copyright (c) 1995
10 *	Jordan Hubbard.  All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer,
17 *    verbatim and that no modifications are made prior to this
18 *    point in the file.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 *    notice, this list of conditions and the following disclaimer in the
21 *    documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED.  IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 */
36
37#include "sysinstall.h"
38#include <ctype.h>
39
40static int _shutdown(dialogMenuItem *unused);
41static int _systemExecute(dialogMenuItem *unused);
42
43static struct _word {
44    char *name;
45    int (*handler)(dialogMenuItem *self);
46} resWords[] = {
47    { "configAnonFTP",		configAnonFTP		},
48    { "configRouter",		configRouter		},
49    { "configNFSServer",	configNFSServer		},
50    { "configSamba",		configSamba		},
51    { "configNTP",		configNTP		},
52    { "configPCNFSD",		configPCNFSD		},
53    { "configNFSServer",	configNFSServer		},
54    { "configPackages",		configPackages		},
55    { "configRegister",		configRegister		},
56    { "configRouter",		configRouter		},
57    { "configUsers",		configUsers		},
58    { "configXEnvironment",	configXEnvironment	},
59    { "diskPartitionEditor",	diskPartitionEditor	},
60    { "diskPartitionWrite",	diskPartitionWrite	},
61    { "diskLabelEditor",	diskLabelEditor		},
62    { "diskLabelCommit",	diskLabelCommit		},
63    { "distReset",		distReset		},
64    { "distSetCustom",		distSetCustom		},
65    { "distSetDeveloper",	distSetDeveloper	},
66    { "distSetXDeveloper",	distSetXDeveloper	},
67    { "distSetKernDeveloper",	distSetKernDeveloper	},
68    { "distSetUser",		distSetUser		},
69    { "distSetXUser",		distSetXUser		},
70    { "distSetMinimum",		distSetMinimum		},
71    { "distSetEverything",	distSetEverything	},
72    { "distSetDES",		distSetDES		},
73    { "distSetSrc",		distSetSrc		},
74    { "distSetXF86",		distSetXF86		},
75    { "distExtractAll",		distExtractAll		},
76    { "docBrowser",		docBrowser		},
77    { "docShowDocument",	docShowDocument		},
78    { "installCommit",		installCommit		},
79    { "installExpress",		installExpress		},
80    { "installNovice",		installNovice		},
81    { "installUpgrade",		installUpgrade		},
82    { "installFixup",		installFixup		},
83    { "installFixitHoloShell",	installFixitHoloShell	},
84    { "installFixitCDROM",	installFixitCDROM	},
85    { "installFixitFloppy",	installFixitFloppy	},
86    { "installFilesystems",	installFilesystems	},
87    { "installVarDefaults",	installVarDefaults	},
88    { "mediaSetCDROM",		mediaSetCDROM		},
89    { "mediaSetFloppy",		mediaSetFloppy		},
90    { "mediaSetDOS",		mediaSetDOS		},
91    { "mediaSetTape",		mediaSetTape		},
92    { "mediaSetFTP",		mediaSetFTP		},
93    { "mediaSetFTPActive",	mediaSetFTPActive	},
94    { "mediaSetFTPPassive",	mediaSetFTPPassive	},
95    { "mediaSetUFS",		mediaSetUFS		},
96    { "mediaSetNFS",		mediaSetNFS		},
97    { "mediaSetFTPUserPass",	mediaSetFTPUserPass	},
98    { "mediaSetCPIOVerbosity",	mediaSetCPIOVerbosity	},
99    { "mediaGetType",		mediaGetType		},
100    { "optionsEditor",		optionsEditor		},
101    { "register",		configRegister		},	/* Alias */
102    { "packageAdd",		packageAdd		},
103    { "addGroup",		userAddGroup		},
104    { "addUser",		userAddUser		},
105    { "shutdown",		_shutdown 		},
106    { "system",			_systemExecute 		},
107    { NULL, NULL },
108};
109
110static int
111call_possible_resword(char *name, dialogMenuItem *value, int *status)
112{
113    int i, rval;
114
115    rval = 0;
116    for (i = 0; resWords[i].name; i++) {
117	if (!strcmp(name, resWords[i].name)) {
118	    *status = resWords[i].handler(value);
119	    rval = 1;
120	    break;
121	}
122    }
123    return rval;
124}
125
126/* Just convenience */
127static int
128_shutdown(dialogMenuItem *unused)
129{
130    systemShutdown(0);
131    return DITEM_FAILURE;
132}
133
134static int
135_systemExecute(dialogMenuItem *unused)
136{
137    char *cmd = variable_get("command");
138
139    if (cmd)
140	return systemExecute(cmd) ? DITEM_FAILURE : DITEM_SUCCESS;
141    else
142	msgDebug("_systemExecute: No command passed in `command' variable.\n");
143    return DITEM_FAILURE;
144}
145
146/* For a given string, call it or spit out an undefined command diagnostic */
147int
148dispatchCommand(char *str)
149{
150    int i;
151    char *cp;
152
153    if (!str || !*str) {
154	msgConfirm("Null or zero-length string passed to dispatchCommand");
155	return DITEM_FAILURE;
156    }
157    /* If it's got a newline, trim it */
158    if ((cp = index(str, '\n')) != NULL)
159	*cp = '\0';
160
161    /* If it's got a `=' sign in there, assume it's a variable setting */
162    if (index(str, '=')) {
163	if (isDebug())
164	    msgDebug("dispatch: setting variable `%s'\n", str);
165	variable_set(str);
166	i = DITEM_SUCCESS;
167    }
168    else {
169	/* A command might be a pathname if it's encoded in argv[0], which we also support */
170	if ((cp = rindex(str, '/')) != NULL)
171	    str = cp + 1;
172	if (isDebug())
173	    msgDebug("dispatch: calling resword `%s'\n", str);
174	if (!call_possible_resword(str, NULL, &i)) {
175	    msgNotify("Warning: No such command ``%s''", str);
176	    i = DITEM_FAILURE;
177	}
178    }
179    return i;
180}
181