|
|
| version 1.18, 2025/03/31 16:33:56 | version 1.20, 2025/04/01 16:37:12 |
|---|---|
| Line 24 | Line 24 |
| * along with FreeM. If not, see <https://www.gnu.org/licenses/>. | * along with FreeM. If not, see <https://www.gnu.org/licenses/>. |
| * | * |
| * $Log$ | * $Log$ |
| * Revision 1.20 2025/04/01 16:37:12 snw | |
| * Configure DEFAULT environment the same as others, and set permissions/ownership directly in fmadm configure. Add env.conf file as a centralized configuration listing all environments. | |
| * | |
| * Revision 1.19 2025/04/01 14:32:11 snw | |
| * Begin work on environment and namespace reorg | |
| * | |
| * Revision 1.18 2025/03/31 16:33:56 snw | * Revision 1.18 2025/03/31 16:33:56 snw |
| * Work on fmadm edit global | * Work on fmadm edit global |
| * | * |
| Line 67 | Line 73 |
| #include <sys/types.h> | #include <sys/types.h> |
| #include <sys/stat.h> | #include <sys/stat.h> |
| #include <pwd.h> | |
| #include <grp.h> | |
| #include <stddef.h> | #include <stddef.h> |
| #include <stdio.h> | #include <stdio.h> |
| #include <string.h> | #include <string.h> |
| Line 139 short fma_explicit_environment = FALSE; | Line 147 short fma_explicit_environment = FALSE; |
| char obj_str[STRLEN]; | char obj_str[STRLEN]; |
| extern char config_file[4096]; | extern char config_file[4096]; |
| extern char env_config_file[4096]; | |
| extern char env_user[255]; | |
| extern char env_group[255]; | |
| int fm_shell(void); | int fm_shell(void); |
| void fm_checkperms(void); | void fm_checkperms(void); |
| Line 146 void fm_reconfigure(void); | Line 157 void fm_reconfigure(void); |
| void fm_configure(void); | void fm_configure(void); |
| void fm_write (FILE *file, char *buf); | void fm_write (FILE *file, char *buf); |
| int fma_jobs_remove (int optc, char **opts); | int fma_jobs_remove (int optc, char **opts); |
| void set_permissions(char *path, char *user, char *grp, int mode); | |
| int main (int argc, char **argv) | int main (int argc, char **argv) |
| { | { |
| Line 193 int main (int argc, char **argv) | Line 206 int main (int argc, char **argv) |
| if (argv[i][0] == '-') { | if (argv[i][0] == '-') { |
| switch (argv[i][1]) { | switch (argv[i][1]) { |
| case 'u': | |
| if (argv[i][2] != '=') { | |
| fprintf (stderr, "fmadm: missing equals sign in flag -%c\n", argv[i][1]); | |
| fmadm_usage (); | |
| exit (1); | |
| } | |
| k = 0; | |
| for (j = 3; j < strlen (argv[i]); j++) { | |
| env_user[k++] = argv[i][j]; | |
| } | |
| fma_explicit_environment = TRUE; | |
| base_arg++; | |
| break; | |
| case 'g': | |
| if (argv[i][2] != '=') { | |
| fprintf (stderr, "fmadm: missing equals sign in flag -%c\n", argv[i][1]); | |
| fmadm_usage (); | |
| exit (1); | |
| } | |
| k = 0; | |
| for (j = 3; j < strlen (argv[i]); j++) { | |
| env_group[k++] = argv[i][j]; | |
| } | |
| fma_explicit_environment = TRUE; | |
| base_arg++; | |
| break; | |
| case 'e': | case 'e': |
| if (argv[i][2] != '=') { | if (argv[i][2] != '=') { |
| Line 233 int main (int argc, char **argv) | Line 283 int main (int argc, char **argv) |
| } | } |
| } | } |
| } | } |
| if (strlen (env_user) == 0) { | |
| fprintf (stderr, "fmadm: assuming user 'freem' for this environment's owner\n"); | |
| snprintf (env_user, 6, "freem"); | |
| } | |
| if (strlen (env_group) == 0) { | |
| fprintf (stderr, "fmadm: assuming group 'freem' for this environment's owner\n"); | |
| snprintf (env_group, 6, "freem"); | |
| } | |
| if (!fma_explicit_environment) snprintf (fma_environment, 4096, "DEFAULT"); | if (!fma_explicit_environment) snprintf (fma_environment, 4096, "DEFAULT"); |
| if (!fma_explicit_namespace) snprintf (fma_namespace, 4096, "SYSTEM"); | if (!fma_explicit_namespace) snprintf (fma_namespace, 4096, "SYSTEM"); |
| snprintf (config_file, 4096, "%s/freem/%s/freem.conf", SYSCONFDIR, fma_environment); | snprintf (config_file, 4096, "%s/freem/%s/freem.conf", SYSCONFDIR, fma_environment); |
| snprintf (env_config_file, 4096, "%s/freem/env.conf", SYSCONFDIR); | |
| /* | /* |
| printf ("action = '%s' object = '%s' environment = '%s' namespace = '%s' config_file = '%s' base_arg = '%d' next argument = '%s'\n", action, obj_str, fma_environment, fma_namespace, config_file, base_arg, argv[base_arg]); | printf ("action = '%s' object = '%s' environment = '%s' namespace = '%s' config_file = '%s' base_arg = '%d' next argument = '%s'\n", action, obj_str, fma_environment, fma_namespace, config_file, base_arg, argv[base_arg]); |
| exit(1); | exit(1); |
| Line 1112 void fm_reconfigure(void) | Line 1174 void fm_reconfigure(void) |
| void fm_configure (void) | void fm_configure (void) |
| { | { |
| char varbase[4096]; | |
| char sysrtn[4096]; | char sysrtn[4096]; |
| char sysgbl[4096]; | char sysgbl[4096]; |
| char usrrtn[4096]; | char usrrtn[4096]; |
| Line 1136 void fm_configure (void) | Line 1198 void fm_configure (void) |
| struct stat etcstat; | struct stat etcstat; |
| int stat_result; | int stat_result; |
| DIR *dir; | |
| struct dirent *ent; | |
| char src_dir[4096]; | |
| char dest_dir[4096]; | |
| char *username = env_user; | |
| char *groupname = env_group; | |
| #if !defined(__OS2__) | |
| struct group *d_grp; | |
| struct passwd *d_user; | |
| gid_t d_gid; | |
| uid_t d_uid; | |
| if ((d_grp = getgrnam (groupname)) == NULL) { | |
| fprintf (stderr, "fmadm: '%s' group must exist before configuring\n", groupname); | |
| exit (1); | |
| } | |
| d_gid = d_grp->gr_gid; | |
| if ((d_user = getpwnam (username)) == NULL) { | |
| fprintf (stderr, "fmadm: '%s' user must exist before configuring\n", username); | |
| exit (1); | |
| } | |
| d_uid = d_user->pw_uid; | |
| #endif | |
| snprintf (varbase, 4095, "%s/freem", LOCALSTATEDIR); | |
| snprintf (sysrtn, 4095, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment); | snprintf (sysrtn, 4095, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment); |
| snprintf (sysgbl, 4095, "%s/freem/%s/SYSTEM/globals", LOCALSTATEDIR, fma_environment); | snprintf (sysgbl, 4095, "%s/freem/%s/SYSTEM/globals", LOCALSTATEDIR, fma_environment); |
| snprintf (usrrtn, 4095, "%s/freem/%s/USER/routines", LOCALSTATEDIR, fma_environment); | snprintf (usrrtn, 4095, "%s/freem/%s/USER/routines", LOCALSTATEDIR, fma_environment); |
| Line 1159 void fm_configure (void) | Line 1250 void fm_configure (void) |
| return; | return; |
| } | } |
| gethostname (hostid, 4095); | gethostname (hostid, 4095); |
| uuid_v4 (buf); | uuid_v4 (buf); |
| snprintf (jnlhostid, 4095, "%s:%s", hostid, buf); | snprintf (jnlhostid, 4095, "%s:%s", hostid, buf); |
| snprintf (confbase, 4095, "%s/freem", SYSCONFDIR); | snprintf (confbase, 4095, "%s/freem", SYSCONFDIR); |
| snprintf (envbase, 4095, "%s/freem/%s", SYSCONFDIR, fma_environment); | snprintf (envbase, 4095, "%s/freem/%s", SYSCONFDIR, fma_environment); |
| snprintf (nsbase, 4095, "%s/freem/%s", LOCALSTATEDIR, fma_environment); | snprintf (nsbase, 4095, "%s/freem/%s", LOCALSTATEDIR, fma_environment); |
| Line 1196 void fm_configure (void) | Line 1285 void fm_configure (void) |
| printf ("---------------------------\n\n"); | printf ("---------------------------\n\n"); |
| printf ("This utility will create the initial configuration file for "); | printf ("This utility will create the initial configuration file for "); |
| printf ("FreeM environment '%s' in %s.\n\n", fma_environment, config_file); | printf ("FreeM environment '%s' (owned by %s:%s) in '%s'.\n\n", fma_environment, username, groupname, config_file); |
| /* check for existence of needed directories */ | /* check for existence of needed directories */ |
| if (stat (SYSCONFDIR, &etcstat) == -1) { | if (stat (SYSCONFDIR, &etcstat) == -1) { |
| fprintf (stderr, "fmadm: creating %s\n", SYSCONFDIR); | fprintf (stderr, "fmadm: creating %s\n", SYSCONFDIR); |
| mkdir (SYSCONFDIR, 0755); | mkdir (SYSCONFDIR, 0775); |
| set_permissions (SYSCONFDIR, username, groupname, 0775); | |
| } | } |
| if (stat (confbase, &etcstat) == -1) { | if (stat (confbase, &etcstat) == -1) { |
| fprintf (stderr, "fmadm: creating %s\n", confbase); | fprintf (stderr, "fmadm: creating %s\n", confbase); |
| mkdir (confbase, 0755); | mkdir (confbase, 0775); |
| set_permissions (confbase, username, groupname, 0775); | |
| } | } |
| if (stat (envbase, &etcstat) == -1) { | if (stat (envbase, &etcstat) == -1) { |
| fprintf (stderr, "fmadm: creating %s\n", envbase); | fprintf (stderr, "fmadm: creating %s\n", envbase); |
| mkdir (envbase, 0755); | mkdir (envbase, 0775); |
| set_permissions (envbase, username, groupname, 0775); | |
| } | } |
| if (stat (varbase, &etcstat) == -1) { | |
| fprintf (stderr, "fmadm: creating %s\n", varbase); | |
| mkdir (varbase, 0775); | |
| set_permissions (varbase, username, groupname, 0775); | |
| } | |
| if (stat (nsbase, &etcstat) == -1) { | if (stat (nsbase, &etcstat) == -1) { |
| fprintf (stderr, "fmadm: creating %s\n", nsbase); | fprintf (stderr, "fmadm: creating %s\n", nsbase); |
| mkdir (nsbase, 0755); | mkdir (nsbase, 0775); |
| set_permissions (nsbase, username, groupname, 0775); | |
| } | } |
| snprintf (src_dir, 4095, "%s/freem/mlib", DATADIR); | |
| snprintf (dest_dir, 4095, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment); | |
| if (strcmp (fma_environment, "DEFAULT") != 0) { | |
| fprintf (stderr, "fmadm: populating new environment '%s'\n", fma_environment); | |
| DIR *dir; | |
| struct dirent *ent; | snprintf (buf, 4095, "%s/freem/%s/SYSTEM", LOCALSTATEDIR, fma_environment); |
| char src_dir[4096]; | mkdir (buf, 0775); |
| char dest_dir[4096]; | set_permissions (buf, username, groupname, 0775); |
| snprintf (buf, 4095, "%s/freem/%s/USER", LOCALSTATEDIR, fma_environment); | |
| mkdir (buf, 0775); | |
| set_permissions (buf, username, groupname, 0775); | |
| snprintf (buf, 4095, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment); | |
| mkdir (buf, 0775); | |
| set_permissions (buf, username, groupname, 0775); | |
| snprintf (buf, 4095, "%s/freem/%s/USER/globals", LOCALSTATEDIR, fma_environment); | |
| mkdir (buf, 0775); | |
| set_permissions (buf, username, groupname, 0775); | |
| snprintf (buf, 4095, "%s/freem/%s/SYSTEM/globals", LOCALSTATEDIR, fma_environment); | |
| mkdir (buf, 0775); | |
| set_permissions (buf, username, groupname, 0775); | |
| snprintf (buf, 4095, "%s/freem/%s/USER/routines", LOCALSTATEDIR, fma_environment); | |
| mkdir (buf, 0775); | |
| set_permissions (buf, username, groupname, 0775); | |
| fprintf (stderr, "fmadm: copying routines from '%s' to '%s'...\n", src_dir, dest_dir); | |
| snprintf (src_dir, 4095, "%s/freem/DEFAULT/SYSTEM/routines", LOCALSTATEDIR); | if ((dir = opendir (src_dir)) == NULL) { |
| snprintf (dest_dir, 4095, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment); | fprintf (stderr, "\nfmadm: could not open source directory %s\n", src_dir); |
| exit (1); | |
| fprintf (stderr, "fmadm: populating new environment '%s'\n", fma_environment); | } |
| while ((ent = readdir (dir)) != NULL) { | |
| char infile[4096]; | |
| char outfile[4096]; | |
| snprintf (buf, 4095, "%s/freem/%s/SYSTEM", LOCALSTATEDIR, fma_environment); | if ((strcmp (ent->d_name, ".") != 0) && (strcmp (ent->d_name, "..") != 0)) { |
| mkdir (buf, 0755); | |
| fprintf (stderr, "\t%s\n", ent->d_name); | |
| snprintf (buf, 4095, "%s/freem/%s/USER", LOCALSTATEDIR, fma_environment); | |
| mkdir (buf, 0755); | snprintf (infile, 4095, "%s/%s", src_dir, ent->d_name); |
| snprintf (outfile, 4095, "%s/%s", dest_dir, ent->d_name); | |
| snprintf (buf, 4095, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment); | |
| mkdir (buf, 0755); | |
| snprintf (buf, 4095, "%s/freem/%s/USER/globals", LOCALSTATEDIR, fma_environment); | |
| mkdir (buf, 0755); | |
| snprintf (buf, 4095, "%s/freem/%s/SYSTEM/globals", LOCALSTATEDIR, fma_environment); | |
| mkdir (buf, 0755); | |
| snprintf (buf, 4095, "%s/freem/%s/USER/routines", LOCALSTATEDIR, fma_environment); | |
| mkdir (buf, 0755); | |
| fprintf (stderr, "fmadm: copying routines from '%s' to '%s'...\n", src_dir, dest_dir); | |
| if ((dir = opendir (src_dir)) == NULL) { | |
| fprintf (stderr, "\nfmadm: could not open source directory %s\n", src_dir); | |
| exit (1); | |
| } | |
| while ((ent = readdir (dir)) != NULL) { | |
| char infile[4096]; | |
| char outfile[4096]; | |
| if ((strcmp (ent->d_name, ".") != 0) && (strcmp (ent->d_name, "..") != 0)) { | |
| fprintf (stderr, "\t%s\n", ent->d_name); | |
| snprintf (infile, 4095, "%s/%s", src_dir, ent->d_name); | |
| snprintf (outfile, 4095, "%s/%s", dest_dir, ent->d_name); | |
| if (cp (outfile, infile) != 0) { | |
| fprintf (stderr, "fmadm: failure copying %s to %s\n", infile, outfile); | |
| } | |
| #if !defined(__OS2__) | |
| if (cp (outfile, infile) != 0) { | |
| fprintf (stderr, "fmadm: failure copying %s to %s\n", infile, outfile); | |
| } | |
| set_permissions (outfile, username, groupname, 0755); | |
| #else | |
| if (DosCopy (infile, outfile, 1) != 0) { | |
| fprintf (stderr, "fmadm: failure copying %s to %s\n", infile, outfile); | |
| } | } |
| #endif | |
| } | } |
| } | } |
| fp = fopen (env_config_file, "a+"); | |
| fprintf (stderr, "Creating %s... ", env_config_file); | |
| snprintf (buf, 4095, "[%s]", fma_environment); | |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "user=%s", env_user); | |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "group=%s", env_group); | |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "env_path=%s/freem/%s", LOCALSTATEDIR, fma_environment); | |
| fm_write (fp, buf); | |
| fclose (fp); | |
| fprintf (stderr, "[OK]\n"); | |
| fp = fopen (config_file, "a+"); | fp = fopen (config_file, "a+"); |
| fprintf (stderr, "Creating %s... ", config_file); | |
| printf ("Creating %s... ", config_file); | |
| snprintf (buf, 4095, "[SYSTEM]"); | snprintf (buf, 4095, "[SYSTEM]"); |
| fm_write (fp, buf); | fm_write (fp, buf); |
| Line 1327 void fm_configure (void) | Line 1444 void fm_configure (void) |
| snprintf (buf, 4095, "globals_path=%s", usrgbl); | snprintf (buf, 4095, "globals_path=%s", usrgbl); |
| fm_write (fp, buf); | fm_write (fp, buf); |
| fclose (fp); | fclose (fp); |
| set_permissions (config_file, username, groupname, 0755); | |
| fprintf (stderr, "[OK]\n"); | |
| printf ("[OK]\n\n"); | |
| /* | |
| printf ("Setting USER namespace permissions... "); | |
| snprintf (buf, 4095, "%s/freem/USER/globals", LOCALSTATEDIR); | |
| chmod (buf, 0777); | |
| snprintf (buf, 4095, "%s/freem/USER/routines", LOCALSTATEDIR); | |
| chmod (buf, 0777); | |
| printf ("[OK]\n"); | |
| printf ("Setting SYSTEM namespace permissions... "); | |
| snprintf (buf, 4095, "%s/freem/SYSTEM/globals", LOCALSTATEDIR); | |
| chmod (buf, 0755); | |
| snprintf (buf, 4095, "%s/freem/SYSTEM/routines", LOCALSTATEDIR); | |
| chmod (buf, 0755); | |
| printf ("[OK]\n\n\n"); | |
| */ | |
| printf ("FreeM initial configuration is complete.\n\n"); | printf ("FreeM initial configuration is complete.\n\n"); |
| printf (" USER globals: %s\n", usrgbl); | printf (" USER globals: %s\n", usrgbl); |
| Line 1366 void fm_configure (void) | Line 1462 void fm_configure (void) |
| } /* fm_configure */ | } /* fm_configure */ |
| void set_permissions(char *path, char *user, char *grp, int mode) | |
| { | |
| #if !defined(__OS2__) | |
| struct group *d_grp; | |
| struct passwd *d_user; | |
| gid_t d_gid; | |
| uid_t d_uid; | |
| #endif | |
| #if !defined(__OS2__) | |
| if ((d_grp = getgrnam (grp)) == NULL) { | |
| fprintf (stderr, "fmadm: '%s' group must exist before configuring\n", grp); | |
| exit (1); | |
| } | |
| d_gid = d_grp->gr_gid; | |
| if ((d_user = getpwnam (user)) == NULL) { | |
| fprintf (stderr, "fmadm: '%s' user must exist before configuring\n", user); | |
| exit (1); | |
| } | |
| d_uid = d_user->pw_uid; | |
| if (chown (path, d_uid, d_gid) != 0) { | |
| fprintf (stderr, "fmadm: error setting ownership on %s\n", path); | |
| exit (1); | |
| } | |
| #endif | |
| if (chmod (path, mode) != 0) { | |
| fprintf (stderr, "fmadm: error setting permissions on %s to %d\n", path, mode); | |
| exit (1); | |
| } | |
| } | |
| void fm_write (FILE *file, char *buf) | void fm_write (FILE *file, char *buf) |
| { | { |
| fprintf (file, "%s\n", buf); | fprintf (file, "%s\n", buf); |