[Initng-svn] r2397 - in initng: plugins/bash_launcher
plugins/dparser plugins/find plugins/inetd plugins/iparser
plugins/ngc2 plugins/pidfile plugins/simple_launcher
plugins/splash src tools
svn at initng.thinktux.net
svn at initng.thinktux.net
Mon Dec 12 23:26:16 CET 2005
Author: jimmy
Date: Mon Dec 12 23:26:15 2005
New Revision: 2397
Modified:
initng/plugins/bash_launcher/initng_bash_launcher.c
initng/plugins/dparser/initng_d_parser.c
initng/plugins/find/initng_find.c
initng/plugins/inetd/initng_inetd.c
initng/plugins/iparser/initng_i_parser.c
initng/plugins/ngc2/initng_ngc2.c
initng/plugins/ngc2/ngc2.c
initng/plugins/pidfile/initng_pidfile.c
initng/plugins/simple_launcher/initng_simple_launcher.c
initng/plugins/splash/initng_splash.c
initng/src/initng_active_db.c
initng/src/initng_active_db.h
initng/src/initng_env_variable.c
initng/src/initng_handler.c
initng/src/initng_load_module.c
initng/src/initng_service_cache.c
initng/src/initng_service_cache.h
initng/src/initng_struct_data.c
initng/src/initng_struct_data.h
initng/src/sulogin.c
initng/tools/install_service.c
initng/tools/mountpoint.c
Log:
An indent_all.sh run.
Modified: initng/plugins/bash_launcher/initng_bash_launcher.c
==============================================================================
--- initng/plugins/bash_launcher/initng_bash_launcher.c (original)
+++ initng/plugins/bash_launcher/initng_bash_launcher.c Mon Dec 12 23:26:15 2005
@@ -80,7 +80,7 @@
/* get the arguments if any */
args = active_db_get_string_var(&SCRIPT_OPT, process->pt->name, service);
- /*D_("initng_bash(%s, %s, %s);\n", service->name, e, args);*/
+ /*D_("initng_bash(%s, %s, %s);\n", service->name, e, args); */
return (bash_exec(process, service, e, args));
}
@@ -89,10 +89,10 @@
{
/* temporary argv */
char **argtmp;
-
-
+
+
D_("bash_this(%s);\n", s->name);
-
+
/* Todo : move bash_this into initng_bash_launcher and parse args properly\n" */
@@ -106,26 +106,27 @@
argtmp[1] = i_strdup("-c");
argtmp[2] = i_strdup(bash_code);
argtmp[3] = i_strdup(s->name);
-
- if(args)
- argtmp[4] = i_strdup(args);
+
+ if (args)
+ argtmp[4] = i_strdup(args);
argtmp[5] = NULL;
-
+
/* execute */
execve("/bin/sh", argtmp, new_environ(s));
-
+
/* free them all */
{
- int i=0;
- while(argtmp[i])
- {
- free(argtmp[i]);
- argtmp[i]=NULL;
- i++;
- }
+ int i = 0;
+
+ while (argtmp[i])
+ {
+ free(argtmp[i]);
+ argtmp[i] = NULL;
+ i++;
+ }
}
free(argtmp);
-
+
/* put an error message up */
F_("bash_this(): child died!\n EEEEEEEEEEEEEEEEEEEEEEERRRRRRRRRRRROOOOOOOOOORR!\n");
Modified: initng/plugins/dparser/initng_d_parser.c
==============================================================================
--- initng/plugins/dparser/initng_d_parser.c (original)
+++ initng/plugins/dparser/initng_d_parser.c Mon Dec 12 23:26:15 2005
@@ -27,7 +27,7 @@
#include <fcntl.h>
#include <stdlib.h>
#include <assert.h>
- /*#include <dirent.h> *//* opendir() closedir() */
+ /*#include <dirent.h> *//* opendir() closedir() */
#include "../../src/initng_global.h"
#include "../../src/initng_string_tools.h"
Modified: initng/plugins/find/initng_find.c
==============================================================================
--- initng/plugins/find/initng_find.c (original)
+++ initng/plugins/find/initng_find.c Mon Dec 12 23:26:15 2005
@@ -51,30 +51,30 @@
struct dirent *dir_e;
char t[100];
char d[30];
-
+
sprintf(d, "%s/%s", INITNG_ROOT, dir);
-
+
path = opendir(d);
if (!path)
- return(NULL);
-
+ return (NULL);
+
while ((dir_e = readdir(path)))
{
- if(!strstr(dir_e->d_name, from))
- continue;
-
- strncpy(t, dir, 40);
+ if (!strstr(dir_e->d_name, from))
+ continue;
+
+ strncpy(t, dir, 40);
strcpy(t, "/");
strncat(t, from, 40);
W_("Service should be %s/%s\n", dir, from);
if ((tmp = parse_service(t)))
- {
- closedir(path);
+ {
+ closedir(path);
return (tmp);
}
}
closedir(path);
- return(NULL);
+ return (NULL);
}
/* Load a service from a process_name or process_path */
@@ -99,22 +99,22 @@
}
}
- if((tmp=search_dir(service, "system")))
- return(tmp);
-
- if((tmp=search_dir(service, "daemon")))
- return(tmp);
+ if ((tmp = search_dir(service, "system")))
+ return (tmp);
+
+ if ((tmp = search_dir(service, "daemon")))
+ return (tmp);
/* try get from alias file */
- if(!(tmp_serv=get_find_alias(service)));
- return(NULL);
+ if (!(tmp_serv = get_find_alias(service))) ;
+ return (NULL);
if ((tmp = parse_service(tmp_serv)))
{
- free(tmp_serv);
- return(tmp);
+ free(tmp_serv);
+ return (tmp);
}
-
+
free(tmp_serv);
return (NULL);
}
@@ -122,8 +122,8 @@
#define ALIAS_FILE "/etc/initng/service_alias"
static char *get_find_alias(const char *from)
{
- int from_len=0;
- int i=0;
+ int from_len = 0;
+ int i = 0;
char *file_content = NULL;
char *point = NULL;
@@ -136,8 +136,8 @@
return (NULL);
/* get lengt of what we are searching */
- from_len=strlen(from);
-
+ from_len = strlen(from);
+
/* Start Parsing */
point = file_content;
while (point[0])
@@ -153,37 +153,39 @@
JUMP_TO_NEXT_ROW(point);
continue;
}
-
- printf("parse row \"%s\"\n", point);
- /* chek if first word is a match */
- if(strncasecmp(point, from, from_len)!=0)
- {
- printf("Not the one");
+
+ printf("parse row \"%s\"\n", point);
+ /* chek if first word is a match */
+ if (strncasecmp(point, from, from_len) != 0)
+ {
+ printf("Not the one");
JUMP_TO_NEXT_ROW(point);
continue;
- }
-
- printf("point[from_len]='%c', point[from_len+1]='%c'\n", point[from_len], point[from_len+1]);
+ }
+
+ printf("point[from_len]='%c', point[from_len+1]='%c'\n",
+ point[from_len], point[from_len + 1]);
+
-
- if (!point[from_len] || !point[from_len+1] || point[from_len] != '=')
+ if (!point[from_len] || !point[from_len + 1]
+ || point[from_len] != '=')
{
JUMP_TO_NEXT_ROW(point);
continue;
}
-
- /* Put pointer to result after the '=' */
- point_result=&point[from_len+1];
-
- while(point_result[i] && point_result[i]!='\n')
- i++;
-
- /* copy the rest of line */
- ret=i_strndup(point_result, i);
-
- free(file_content);
- printf("ret=\"%s\", len=%i\n", ret, i);
- return(ret);
+
+ /* Put pointer to result after the '=' */
+ point_result = point + from_len + 1;
+
+ while (point_result[i] && point_result[i] != '\n')
+ i++;
+
+ /* copy the rest of line */
+ ret = i_strndup(point_result, i);
+
+ free(file_content);
+ printf("ret=\"%s\", len=%i\n", ret, i);
+ return (ret);
}
free(file_content);
return (NULL);
Modified: initng/plugins/inetd/initng_inetd.c
==============================================================================
--- initng/plugins/inetd/initng_inetd.c (original)
+++ initng/plugins/inetd/initng_inetd.c Mon Dec 12 23:26:15 2005
@@ -145,7 +145,8 @@
{
D_("module_init(ngc2);\n"); if (strcmp(version, INITNG_VERSION) != 0)
{
- F_("This module is compiled for \"%s\" version and initng is compiled on \"%s\" version, won't load this module!\n",
+ F_
+ ("This module is compiled for \"%s\" version and initng is compiled on \"%s\" version, won't load this module!\n",
INITNG_VERSION, version); return (FALSE);}
Modified: initng/plugins/iparser/initng_i_parser.c
==============================================================================
--- initng/plugins/iparser/initng_i_parser.c (original)
+++ initng/plugins/iparser/initng_i_parser.c Mon Dec 12 23:26:15 2005
@@ -118,7 +118,8 @@
/* calculate lenght to newline */
len = strcspn(g_pointer, "\n");
- if (len>100) len = 100; /* TODO: really needed, or implicated by some constraints?? */
+ if (len > 100)
+ len = 100; /* TODO: really needed, or implicated by some constraints?? */
/* fill the line, with a line with data */
strncpy(line, g_pointer, len);
@@ -144,27 +145,27 @@
const char *service = NULL;
assert(service_to_find);
-
+
/* Make sure the filename of 200 chars abow are more than enought */
if (strlen(service_to_find) > 50)
{
F_("Service name to long, initng_i_parser can't look for this service!\n");
return (NULL);
}
-
+
/*
* now set up path and service.
* if service_to_find is system/initial/udevd
* path should be "system/initial"
* and service "udevd"
*/
-
+
/* set up a patch copy, has to be free() */
- path=st_get_path(service_to_find);
-
+ path = st_get_path(service_to_find);
+
/* this is a pointer to a entry in service_to_find */
- service=st_strip_path(service_to_find);
-
+ service = st_strip_path(service_to_find);
+
D_("initng_i_parser(%s);\n", service_to_find);
/* example INITNG_ROOT=/etc/initng service_to_find="deamon/sshd INITNG_EXT=".i" */
/* TRY NO 1, try load "/etc/initng/daemon/sshd.i" */
@@ -183,7 +184,7 @@
strcat(filetoparse, INITNG_EXT);
if ((got_serv = parse_file(filetoparse, service_to_find)))
{
- free(path);
+ free(path);
return (got_serv);
}
filetoparse[0] = '\0';
@@ -194,7 +195,7 @@
strcat(filetoparse, INITNG_EXT);
if ((got_serv = parse_file(filetoparse, service_to_find)))
{
- free(path);
+ free(path);
return (got_serv);
}
filetoparse[0] = '\0';
@@ -205,33 +206,33 @@
strcat(filetoparse, "/default" INITNG_EXT);
if ((got_serv = parse_file(filetoparse, service_to_find)))
{
- free(path);
+ free(path);
return (got_serv);
}
filetoparse[0] = '\0';
/* TRY NO 4, try "/etc/initng/daemon/default.i" */
- strcpy(filetoparse, INITNG_ROOT "/");
- strcat(filetoparse, path);
- strcat(filetoparse, "/default" INITNG_EXT);
-
- if ((got_serv = parse_file(filetoparse, service_to_find)))
- {
- free(path);
- return (got_serv);
- }
+ strcpy(filetoparse, INITNG_ROOT "/");
+ strcat(filetoparse, path);
+ strcat(filetoparse, "/default" INITNG_EXT);
+
+ if ((got_serv = parse_file(filetoparse, service_to_find)))
+ {
+ free(path);
+ return (got_serv);
+ }
filetoparse[0] = '\0';
- strcpy(filetoparse, INITNG_ROOT "/");
- strcat(filetoparse, path);
- strcat(filetoparse, "/");
- strcat(filetoparse, path);
- strcat(filetoparse, INITNG_EXT);
- if ((got_serv = parse_file(filetoparse, service_to_find)))
- {
- free(path);
- return (got_serv);
- }
+ strcpy(filetoparse, INITNG_ROOT "/");
+ strcat(filetoparse, path);
+ strcat(filetoparse, "/");
+ strcat(filetoparse, path);
+ strcat(filetoparse, INITNG_EXT);
+ if ((got_serv = parse_file(filetoparse, service_to_find)))
+ {
+ free(path);
+ return (got_serv);
+ }
filetoparse[0] = '\0';
/* TRY NO 6, try "/etc/initng/sshd.i" */
@@ -240,21 +241,21 @@
strcat(filetoparse, INITNG_EXT);
if ((got_serv = parse_file(filetoparse, service_to_find)))
{
- free(path);
+ free(path);
return (got_serv);
}
filetoparse[0] = '\0';
/* TRY NO 7, try "/etc/initng/daemon.i" */
- strcpy(filetoparse, INITNG_ROOT "/");
- strcat(filetoparse, path);
- strcat(filetoparse, INITNG_EXT);
- if ((got_serv = parse_file(filetoparse, service_to_find)))
- {
- free(path);
- return (got_serv);
- }
- filetoparse[0] = '\0';
+ strcpy(filetoparse, INITNG_ROOT "/");
+ strcat(filetoparse, path);
+ strcat(filetoparse, INITNG_EXT);
+ if ((got_serv = parse_file(filetoparse, service_to_find)))
+ {
+ free(path);
+ return (got_serv);
+ }
+ filetoparse[0] = '\0';
D_("Was not able to parse: %s\n", service_to_find);
free(path);
@@ -505,10 +506,10 @@
/* | */
new_service = service_db_new(name, type);
-
- /* from here, dont use name anymore, use new_service->name */
- free(name);
- name=NULL;
+
+ /* from here, dont use name anymore, use new_service->name */
+ free(name);
+ name = NULL;
/* FROM NOW, we should not free name or father_name, becouse its ADDED, and required */
Modified: initng/plugins/ngc2/initng_ngc2.c
==============================================================================
--- initng/plugins/ngc2/initng_ngc2.c (original)
+++ initng/plugins/ngc2/initng_ngc2.c Mon Dec 12 23:26:15 2005
@@ -658,7 +658,7 @@
{
active_h *serv = NULL;
active_row row;
-
+
memset(&row, 0, sizeof row);
/* argument required */
@@ -792,7 +792,7 @@
if (!current->opt_name)
continue;
- row.d[0] = '\0';
+ row.d[0] = '\0';
strncpy(row.n, current->opt_name, 100);
if (current->opt_desc)
Modified: initng/plugins/ngc2/ngc2.c
==============================================================================
--- initng/plugins/ngc2/ngc2.c (original)
+++ initng/plugins/ngc2/ngc2.c Mon Dec 12 23:26:15 2005
@@ -131,8 +131,8 @@
{
if (sock != -1)
{
- close(sock);
- sock = -1;
+ close(sock);
+ sock = -1;
}
return (sock);
}
Modified: initng/plugins/pidfile/initng_pidfile.c
==============================================================================
--- initng/plugins/pidfile/initng_pidfile.c (original)
+++ initng/plugins/pidfile/initng_pidfile.c Mon Dec 12 23:26:15 2005
@@ -176,8 +176,7 @@
/* If we cant open pidfile, this is bad */
if (fd == -1)
{
- W_("Unable to open pidfile: %s, \"%s\", it might not be created yet.\n",
- name, strerror(errno));
+ W_("Unable to open pidfile: %s, \"%s\", it might not be created yet.\n", name, strerror(errno));
return (-1);
}
Modified: initng/plugins/simple_launcher/initng_simple_launcher.c
==============================================================================
--- initng/plugins/simple_launcher/initng_simple_launcher.c (original)
+++ initng/plugins/simple_launcher/initng_simple_launcher.c Mon Dec 12 23:26:15 2005
@@ -108,7 +108,8 @@
/* get the env-path variable */
PATH = i_strdup(getenv("PATH"));
- D_("initng_s_launch: %s is not an absolute path, searching $PATH\n", exec);
+ D_("initng_s_launch: %s is not an absolute path, searching $PATH\n",
+ exec);
/* Make sure we got a path */
if (!PATH)
Modified: initng/plugins/splash/initng_splash.c
==============================================================================
--- initng/plugins/splash/initng_splash.c (original)
+++ initng/plugins/splash/initng_splash.c Mon Dec 12 23:26:15 2005
@@ -188,8 +188,8 @@
if (strncmp(service->name, "net/", 4) == 0)
{
strncpy(svc_name, service->name, 100);
- svc_name[99] = '\0';
- svc_name[3] = '.';
+ svc_name[99] = '\0';
+ svc_name[3] = '.';
}
else
{
@@ -198,7 +198,7 @@
if (service->name[i])
i++;
strncpy(svc_name, service->name + i, 100);
- svc_name[99] = '\0';
+ svc_name[99] = '\0';
}
if (service->a_state == &LOADING ||
Modified: initng/src/initng_active_db.c
==============================================================================
--- initng/src/initng_active_db.c (original)
+++ initng/src/initng_active_db.c Mon Dec 12 23:26:15 2005
@@ -49,7 +49,7 @@
{
active_h *current = NULL;
- D_("(%s);\n", (char*)service);
+ D_("(%s);\n", (char *) service);
assert(service);
@@ -75,7 +75,7 @@
assert(service);
active_h *current = NULL;
- D_("(%s);\n", (char*)service);
+ D_("(%s);\n", (char *) service);
/* first give the exact find a shot */
if ((current = active_db_find_by_exact_name(service)))
@@ -108,7 +108,7 @@
assert(service);
- D_("(%s);\n", (char*)service);
+ D_("(%s);\n", (char *) service);
/* first search by name */
if ((current = active_db_find_by_name(service)))
@@ -578,7 +578,7 @@
/* ######## Data handlers ############## */
const char *active_db_get_string_var(s_entry * type, const char *vn,
- active_h * from_active)
+ active_h * from_active)
{
const char *t = NULL;
@@ -617,7 +617,8 @@
}
const char *active_db_get_next_string_var(s_entry * type, const char *vn,
- active_h * from_active, const char *last)
+ active_h * from_active,
+ const char *last)
{
const char *r = NULL;
Modified: initng/src/initng_active_db.h
==============================================================================
--- initng/src/initng_active_db.h (original)
+++ initng/src/initng_active_db.h Mon Dec 12 23:26:15 2005
@@ -102,9 +102,10 @@
int active_db_get_int_var(s_entry * type, const char *vn,
active_h * from_active);
const char *active_db_get_string_var(s_entry * type, const char *vn,
- active_h * from_active);
+ active_h * from_active);
const char *active_db_get_next_string_var(s_entry * type, const char *vn,
- active_h * from_active, const char *last);
+ active_h * from_active,
+ const char *last);
int active_db_is_var(s_entry * type, const char *vn, active_h * from_active);
/* count the total number of this type */
Modified: initng/src/initng_env_variable.c
==============================================================================
--- initng/src/initng_env_variable.c (original)
+++ initng/src/initng_env_variable.c Mon Dec 12 23:26:15 2005
@@ -32,7 +32,7 @@
#include <stdlib.h> /* free() exit() */
#include <sys/reboot.h> /* reboot() RB_DISABLE_CAD */
#include <assert.h>
-#include <ctype.h> /* isgraph */
+#include <ctype.h> /* isgraph */
/* own header */
#include "initng_env_variable.h"
@@ -181,11 +181,12 @@
env[nr] = NULL;
/* insert all env strings from config */
- if ((env[nr] = (char *)active_db_get_next_string(&ENV, s, NULL)))
+ if ((env[nr] = (char *) active_db_get_next_string(&ENV, s, NULL)))
{
nr++;
while (((nr + 1) < allocate) &&
- (env[nr] = (char *)active_db_get_next_string(&ENV, s, env[nr - 1])))
+ (env[nr] =
+ (char *) active_db_get_next_string(&ENV, s, env[nr - 1])))
nr++;
}
@@ -268,11 +269,11 @@
if (from[0] == '{') /* if this is a ${VARIABLE} */
{
from++;
- for( ; from[len] && from[len] != '}'; len++);
+ for (; from[len] && from[len] != '}'; len++) ;
}
else /* else a $VARIABLE */
{
- for( ;isgraph( from[len]); len++);
+ for (; isgraph(from[len]); len++) ;
}
/*
@@ -281,7 +282,8 @@
if (strncasecmp(from, "NAME", len) == 0)
{
- const char *tmp=NULL;
+ const char *tmp = NULL;
+
if ((tmp = st_strip_path(s->name)))
{
strcpy(set, tmp);
@@ -297,7 +299,8 @@
if (strncasecmp(from, "CLASS", len) == 0)
{
- char *tmp=NULL;
+ char *tmp = NULL;
+
if ((tmp = st_get_path(s->name)))
{
strcpy(set, tmp);
@@ -340,17 +343,18 @@
}
/* get variable from ENV type */
- {
- const char *tmp = NULL;
- while ((tmp = active_db_get_next_string(&ENV, s, tmp)))
{
- if (strncasecmp(from, tmp, len) == 0 && tmp[len] == '=')
+ const char *tmp = NULL;
+
+ while ((tmp = active_db_get_next_string(&ENV, s, tmp)))
{
- strcpy(set, &tmp[len + 1]);
- goto go_forward;
+ if (strncasecmp(from, tmp, len) == 0 && tmp[len] == '=')
+ {
+ strcpy(set, &tmp[len + 1]);
+ goto go_forward;
+ }
}
}
- }
/* Get the variable from the data set on an initng_variable */
{
@@ -358,6 +362,7 @@
/* Copy the string, so that we can put an '\0' on the end */
char *tmp = i_strndup(from, len);
+
if (!tmp)
goto print_error;
@@ -382,8 +387,10 @@
case STRINGS:
{
const char *tmp2 = NULL;
+
while ((tmp2 =
- active_db_get_next_string(entry, s, tmp2)))
+ active_db_get_next_string(entry, s,
+ tmp2)))
{
strcat(set, tmp2);
strcat(set, " ");
@@ -399,8 +406,7 @@
}
default:
{
- D_("Don't know how to set a variable with %s:%i\n",
- entry->opt_name, entry->opt_type);
+ D_("Don't know how to set a variable with %s:%i\n", entry->opt_name, entry->opt_type);
break;
}
}
@@ -410,11 +416,12 @@
print_error:
/* Print a fancy error message */
- {
- char *tmp = strndup(from, len);
- W_("Service %s Unknown variable ${%s}!\n", s->name, tmp);
- free(tmp);
- }
+ {
+ char *tmp = strndup(from, len);
+
+ W_("Service %s Unknown variable ${%s}!\n", s->name, tmp);
+ free(tmp);
+ }
copy_char:
/* Copy the char, and move on. */
set[0] = from[0];
Modified: initng/src/initng_handler.c
==============================================================================
--- initng/src/initng_handler.c (original)
+++ initng/src/initng_handler.c Mon Dec 12 23:26:15 2005
@@ -127,8 +127,7 @@
if (kill(process->pid, 0) < 0 && (errno == ESRCH))
{
/* This process is already dead */
- F_("process %s pid %i service %s is already dead, cleaning up.\n",
- to_term->name, process->pid, to_term->name);
+ F_("process %s pid %i service %s is already dead, cleaning up.\n", to_term->name, process->pid, to_term->name);
list_del(&process->list);
process_db_free(process);
@@ -176,7 +175,8 @@
/* check system state, if we can launch. */
if (g.sys_state != STATE_STARTING && g.sys_state != STATE_UP)
{
- F_("Can't start service %s, when system status is: %i !\n", service_to_start->name, g.sys_state);
+ F_("Can't start service %s, when system status is: %i !\n",
+ service_to_start->name, g.sys_state);
return (FALSE);
}
@@ -235,7 +235,8 @@
if (!service_to_stop->a_state)
{
- F_("A status is not set, so i can't stop_service %s\n", service_to_stop->name);
+ F_("A status is not set, so i can't stop_service %s\n",
+ service_to_stop->name);
return (FALSE);
}
Modified: initng/src/initng_load_module.c
==============================================================================
--- initng/src/initng_load_module.c (original)
+++ initng/src/initng_load_module.c Mon Dec 12 23:26:15 2005
@@ -197,7 +197,7 @@
{
errmsg = dlerror();
F_("Error reading module_init(); %s\n", errmsg);
- close_and_free_module(m);
+ close_and_free_module(m);
return (NULL);
}
@@ -208,7 +208,7 @@
{
errmsg = dlerror();
F_("Error reading module_unload(); %s\n", errmsg);
- close_and_free_module(m);
+ close_and_free_module(m);
return (NULL);
}
@@ -232,19 +232,19 @@
assert(m != NULL);
/* free module name */
- if(m->module_name)
+ if (m->module_name)
{
- free(m->module_name);
- m->module_name = NULL;
+ free(m->module_name);
+ m->module_name = NULL;
}
/* close the lib */
- if(m->module_dlhandle)
- dlclose(m->module_dlhandle);
-
+ if (m->module_dlhandle)
+ dlclose(m->module_dlhandle);
+
/* remove from list if added */
list_del(&m->list);
-
+
/* free struct */
free(m);
}
@@ -362,7 +362,7 @@
/* run the unload hook */
(*module->module_unload) ();
-
+
/* close and free the module entry in db */
close_and_free_module(module);
}
@@ -445,12 +445,12 @@
/* add this to the list of loaded modules */
if (!current)
- {
- free(module_name);
- module_name=NULL;
- continue;
- }
-
+ {
+ free(module_name);
+ module_name = NULL;
+ continue;
+ }
+
/* add to list and continue */
assert(current->module_name);
list_add(¤t->list, &g.module_db.list);
Modified: initng/src/initng_service_cache.c
==============================================================================
--- initng/src/initng_service_cache.c (original)
+++ initng/src/initng_service_cache.c Mon Dec 12 23:26:15 2005
@@ -355,7 +355,8 @@
* service_db_get_string(), look in the service_h->data entry, but also
* checks fathers->data, that will also apply for this service.
*/
-const char *service_db_get_string_var(s_entry * type, const char *vn, service_h * s)
+const char *service_db_get_string_var(s_entry * type, const char *vn,
+ service_h * s)
{
const char *tmp = NULL;
@@ -397,7 +398,7 @@
* checks fathers->data, that will also apply for this service.
*/
const char *service_db_get_next_string_var(s_entry * type, const char *vn,
- service_h * s, const char *last)
+ service_h * s, const char *last)
{
const char *tmp = NULL;
Modified: initng/src/initng_service_cache.h
==============================================================================
--- initng/src/initng_service_cache.h (original)
+++ initng/src/initng_service_cache.h Mon Dec 12 23:26:15 2005
@@ -89,10 +89,10 @@
/* variable */
int service_db_is_var(s_entry * type, const char *vn, service_h * s);
const char *service_db_get_string_var(s_entry * type, const char *vn,
- service_h * s);
+ service_h * s);
int service_db_get_int_var(s_entry * type, const char *vn, service_h * s);
const char *service_db_get_next_string_var(s_entry * type, const char *vn,
- service_h * s, const char *last);
+ service_h * s, const char *last);
#define service_db_set_string_var(type, vn, from_service, string) d_set_string_var(type, vn, &from_service->data.list, string)
#define service_db_set_another_string_var(type, vn, from_service, string) d_set_another_string_var(type, vn, &from_service->data.list, string)
Modified: initng/src/initng_struct_data.c
==============================================================================
--- initng/src/initng_struct_data.c (original)
+++ initng/src/initng_struct_data.c Mon Dec 12 23:26:15 2005
@@ -57,7 +57,7 @@
const char *d_get_string_var(s_entry * type, const char *vn,
- struct list_head *address)
+ struct list_head *address)
{
s_data *current = NULL;
@@ -137,7 +137,7 @@
const char *d_get_next_string_var(s_entry * type, const char *vn,
- struct list_head *d, const char *last)
+ struct list_head *d, const char *last)
{
s_data *current = NULL;
@@ -184,7 +184,7 @@
}
/* if this is last, return next string */
- return ((const char *)current->t.s);
+ return ((const char *) current->t.s);
}
/* no match */
return (NULL);
Modified: initng/src/initng_struct_data.h
==============================================================================
--- initng/src/initng_struct_data.h (original)
+++ initng/src/initng_struct_data.h Mon Dec 12 23:26:15 2005
@@ -56,11 +56,12 @@
int d_get_int_var(s_entry * type, const char *vn, struct list_head *d);
#define d_get_string(t,d) d_get_string_var(t,NULL,d)
-const char *d_get_string_var(s_entry * type, const char *vn, struct list_head *d);
+const char *d_get_string_var(s_entry * type, const char *vn,
+ struct list_head *d);
#define d_get_next_string(t,d,l) d_get_next_string_var(t,NULL,d,l)
const char *d_get_next_string_var(s_entry * type, const char *vn,
- struct list_head *d, const char *last);
+ struct list_head *d, const char *last);
#define d_set(t,d) d_set_var(t, NULL, d)
void d_set_var(s_entry * type, char *vn, struct list_head *d);
Modified: initng/src/sulogin.c
==============================================================================
--- initng/src/sulogin.c (original)
+++ initng/src/sulogin.c Mon Dec 12 23:26:15 2005
@@ -1,14 +1,14 @@
/*
- * sulogin This program gives Linux machines a reasonable
- * secure way to boot single user. It forces the
- * user to supply the root password before a
- * shell is started.
+ * sulogin This program gives Linux machines a reasonable
+ * secure way to boot single user. It forces the
+ * user to supply the root password before a
+ * shell is started.
*
- * If there is a shadow password file and the
- * encrypted root password is "x" the shadow
- * password will be used.
+ * If there is a shadow password file and the
+ * encrypted root password is "x" the shadow
+ * password will be used.
*
- * Version: @(#)sulogin 2.85-3 23-Apr-2003 miquels at cistron.nl
+ * Version: @(#)sulogin 2.85-3 23-Apr-2003 miquels at cistron.nl
*
*/
@@ -46,411 +46,445 @@
#if 0
/*
- * Fix the tty modes and set reasonable defaults.
- * (I'm not sure if this is needed under Linux, but..)
+ * Fix the tty modes and set reasonable defaults.
+ * (I'm not sure if this is needed under Linux, but..)
*/
void fixtty(void)
{
- struct termios tty;
+ struct termios tty;
- tcgetattr(0, &tty);
+ tcgetattr(0, &tty);
- /*
- * Set or adjust tty modes.
- */
- tty.c_iflag &= ~(INLCR|IGNCR|IUCLC);
- tty.c_iflag |= ICRNL;
- tty.c_oflag &= ~(OCRNL|OLCUC|ONOCR|ONLRET|OFILL);
- tty.c_oflag |= OPOST|ONLCR;
- tty.c_cflag |= CLOCAL;
- tty.c_lflag = ISIG|ICANON|ECHO|ECHOE|ECHOK|ECHOCTL|ECHOKE;
-
- /*
- * Set the most important characters */
- */
- tty.c_cc[VINTR] = 3;
- tty.c_cc[VQUIT] = 28;
- tty.c_cc[VERASE] = 127;
- tty.c_cc[VKILL] = 24;
- tty.c_cc[VEOF] = 4;
- tty.c_cc[VTIME] = 0;
- tty.c_cc[VMIN] = 1;
- tty.c_cc[VSTART] = 17;
- tty.c_cc[VSTOP] = 19;
- tty.c_cc[VSUSP] = 26;
-
- tcsetattr(0, TCSANOW, &tty);
+ /*
+ * Set or adjust tty modes.
+ */
+ tty.c_iflag &= ~(INLCR | IGNCR | IUCLC);
+ tty.c_iflag |= ICRNL;
+ tty.c_oflag &= ~(OCRNL | OLCUC | ONOCR | ONLRET | OFILL);
+ tty.c_oflag |= OPOST | ONLCR;
+ tty.c_cflag |= CLOCAL;
+ tty.c_lflag = ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE;
+
+ /*
+ * Set the most important characters */
+ */tty.c_cc[VINTR] = 3;
+ tty.c_cc[VQUIT] = 28;
+ tty.c_cc[VERASE] = 127;
+ tty.c_cc[VKILL] = 24;
+ tty.c_cc[VEOF] = 4;
+ tty.c_cc[VTIME] = 0;
+ tty.c_cc[VMIN] = 1;
+ tty.c_cc[VSTART] = 17;
+ tty.c_cc[VSTOP] = 19;
+ tty.c_cc[VSUSP] = 26;
+
+ tcsetattr(0, TCSANOW, &tty);
}
#endif
/*
- * Called at timeout.
+ * Called at timeout.
*/
void alrm_handler()
{
}
/*
- * See if an encrypted password is valid. The encrypted
- * password is checked for traditional-style DES and
- * FreeBSD-style MD5 encryption.
+ * See if an encrypted password is valid. The encrypted
+ * password is checked for traditional-style DES and
+ * FreeBSD-style MD5 encryption.
*/
int valid(char *pass)
{
- char *s;
- int len;
+ char *s;
+ int len;
- if (pass[0] == 0) return 1;
+ if (pass[0] == 0)
+ return 1;
#if CHECK_MD5
- /*
- * 3 bytes for the signature $1$
- * up to 8 bytes for the salt
- * $
- * the MD5 hash (128 bits or 16 bytes) encoded in base64 = 22 bytes
- */
- if (strncmp(pass, "$1$", 3) == 0) {
- for(s = pass + 3; *s && *s != '$'; s++)
- ;
- if (*s++ != '$') return 0;
- len = strlen(s);
- if (len < 22 || len > 24) return 0;
+ /*
+ * 3 bytes for the signature $1$
+ * up to 8 bytes for the salt
+ * $
+ * the MD5 hash (128 bits or 16 bytes) encoded in base64 = 22 bytes
+ */
+ if (strncmp(pass, "$1$", 3) == 0)
+ {
+ for (s = pass + 3; *s && *s != '$'; s++)
+ ;
+ if (*s++ != '$')
+ return 0;
+ len = strlen(s);
+ if (len < 22 || len > 24)
+ return 0;
- return 1;
- }
+ return 1;
+ }
#endif
#if CHECK_DES
- if (strlen(pass) != 13) return 0;
- for (s = pass; *s; s++) {
- if ((*s < '0' || *s > '9') &&
- (*s < 'a' || *s > 'z') &&
- (*s < 'A' || *s > 'Z') &&
- *s != '.' && *s != '/') return 0;
- }
+ if (strlen(pass) != 13)
+ return 0;
+ for (s = pass; *s; s++)
+ {
+ if ((*s < '0' || *s > '9') &&
+ (*s < 'a' || *s > 'z') &&
+ (*s < 'A' || *s > 'Z') && *s != '.' && *s != '/')
+ return 0;
+ }
#endif
- return 1;
+ return 1;
}
/*
- * Set a variable if the value is not NULL.
+ * Set a variable if the value is not NULL.
*/
void set(char **var, char *val)
{
- if (val) *var = val;
+ if (val)
+ *var = val;
}
/*
- * Get the root password entry.
+ * Get the root password entry.
*/
struct passwd *getrootpwent(int try_manually)
{
- static struct passwd pwd;
- struct passwd *pw;
- struct spwd *spw;
- FILE *fp;
- static char line[256];
- static char sline[256];
- char *p;
-
- /*
- * First, we try to get the password the standard
- * way using normal library calls.
- */
- if ((pw = getpwnam("root")) &&
- !strcmp(pw->pw_passwd, "x") &&
- (spw = getspnam("root")))
- pw->pw_passwd = spw->sp_pwdp;
- if (pw || !try_manually) return pw;
-
- /*
- * If we come here, we could not retrieve the root
- * password through library calls and we try to
- * read the password and shadow files manually.
- */
- pwd.pw_name = "root";
- pwd.pw_passwd = "";
- pwd.pw_gecos = "Super User";
- pwd.pw_dir = "/";
- pwd.pw_shell = "";
- pwd.pw_uid = 0;
- pwd.pw_gid = 0;
-
- if ((fp = fopen(F_PASSWD, "r")) == NULL) {
- perror(F_PASSWD);
- return &pwd;
- }
-
- /*
- * Find root in the password file.
- */
- while((p = fgets(line, 256, fp)) != NULL) {
- if (strncmp(line, "root:", 5) != 0)
- continue;
- p += 5;
- set(&pwd.pw_passwd, strsep(&p, ":"));
- (void)strsep(&p, ":");
- (void)strsep(&p, ":");
- set(&pwd.pw_gecos, strsep(&p, ":"));
- set(&pwd.pw_dir, strsep(&p, ":"));
- set(&pwd.pw_shell, strsep(&p, "\n"));
- p = line;
- break;
- }
- fclose(fp);
-
- /*
- * If the encrypted password is valid
- * or not found, return.
- */
- if (p == NULL) {
- fprintf(stderr, "%s: no entry for root\n", F_PASSWD);
- return &pwd;
- }
- if (valid(pwd.pw_passwd)) return &pwd;
-
- /*
- * The password is invalid. If there is a
- * shadow password, try it.
- */
- strcpy(pwd.pw_passwd, "");
- if ((fp = fopen(F_SHADOW, "r")) == NULL) {
- fprintf(stderr, "%s: root password garbled\n", F_PASSWD);
- return &pwd;
- }
- while((p = fgets(sline, 256, fp)) != NULL) {
- if (strncmp(sline, "root:", 5) != 0)
- continue;
- p += 5;
- set(&pwd.pw_passwd, strsep(&p, ":"));
- break;
- }
- fclose(fp);
-
- /*
- * If the password is still invalid,
- * NULL it, and return.
- */
- if (p == NULL) {
- fprintf(stderr, "%s: no entry for root\n", F_SHADOW);
- strcpy(pwd.pw_passwd, "");
- }
- if (!valid(pwd.pw_passwd)) {
- fprintf(stderr, "%s: root password garbled\n", F_SHADOW);
- strcpy(pwd.pw_passwd, ""); }
- return &pwd;
+ static struct passwd pwd;
+ struct passwd *pw;
+ struct spwd *spw;
+ FILE *fp;
+ static char line[256];
+ static char sline[256];
+ char *p;
+
+ /*
+ * First, we try to get the password the standard
+ * way using normal library calls.
+ */
+ if ((pw = getpwnam("root")) &&
+ !strcmp(pw->pw_passwd, "x") && (spw = getspnam("root")))
+ pw->pw_passwd = spw->sp_pwdp;
+ if (pw || !try_manually)
+ return pw;
+
+ /*
+ * If we come here, we could not retrieve the root
+ * password through library calls and we try to
+ * read the password and shadow files manually.
+ */
+ pwd.pw_name = "root";
+ pwd.pw_passwd = "";
+ pwd.pw_gecos = "Super User";
+ pwd.pw_dir = "/";
+ pwd.pw_shell = "";
+ pwd.pw_uid = 0;
+ pwd.pw_gid = 0;
+
+ if ((fp = fopen(F_PASSWD, "r")) == NULL)
+ {
+ perror(F_PASSWD);
+ return &pwd;
+ }
+
+ /*
+ * Find root in the password file.
+ */
+ while ((p = fgets(line, 256, fp)) != NULL)
+ {
+ if (strncmp(line, "root:", 5) != 0)
+ continue;
+ p += 5;
+ set(&pwd.pw_passwd, strsep(&p, ":"));
+ (void) strsep(&p, ":");
+ (void) strsep(&p, ":");
+ set(&pwd.pw_gecos, strsep(&p, ":"));
+ set(&pwd.pw_dir, strsep(&p, ":"));
+ set(&pwd.pw_shell, strsep(&p, "\n"));
+ p = line;
+ break;
+ }
+ fclose(fp);
+
+ /*
+ * If the encrypted password is valid
+ * or not found, return.
+ */
+ if (p == NULL)
+ {
+ fprintf(stderr, "%s: no entry for root\n", F_PASSWD);
+ return &pwd;
+ }
+ if (valid(pwd.pw_passwd))
+ return &pwd;
+
+ /*
+ * The password is invalid. If there is a
+ * shadow password, try it.
+ */
+ strcpy(pwd.pw_passwd, "");
+ if ((fp = fopen(F_SHADOW, "r")) == NULL)
+ {
+ fprintf(stderr, "%s: root password garbled\n", F_PASSWD);
+ return &pwd;
+ }
+ while ((p = fgets(sline, 256, fp)) != NULL)
+ {
+ if (strncmp(sline, "root:", 5) != 0)
+ continue;
+ p += 5;
+ set(&pwd.pw_passwd, strsep(&p, ":"));
+ break;
+ }
+ fclose(fp);
+
+ /*
+ * If the password is still invalid,
+ * NULL it, and return.
+ */
+ if (p == NULL)
+ {
+ fprintf(stderr, "%s: no entry for root\n", F_SHADOW);
+ strcpy(pwd.pw_passwd, "");
+ }
+ if (!valid(pwd.pw_passwd))
+ {
+ fprintf(stderr, "%s: root password garbled\n", F_SHADOW);
+ strcpy(pwd.pw_passwd, "");
+ }
+ return &pwd;
}
/*
- * Ask for the password. Note that there is no
- * default timeout as we normally skip this during boot.
+ * Ask for the password. Note that there is no
+ * default timeout as we normally skip this during boot.
*/
char *getpasswd(char *crypted)
{
- struct sigaction sa;
- struct termios old, tty;
- static char pass[128];
- char *ret = pass;
- int i;
-
- if (crypted[0])
- printf("Give root password for maintenance\n");
- else
- printf("Press enter for maintenance\n");
- printf("(or type Control-D to continue): ");
- fflush(stdout);
-
- tcgetattr(0, &old);
- tcgetattr(0, &tty);
- tty.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY);
- tty.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP);
- tcsetattr(0, TCSANOW, &tty);
-
- pass[sizeof(pass) - 1] = 0;
-
- sa.sa_handler = alrm_handler;
- sa.sa_flags = 0;
- sigaction(SIGALRM, &sa, NULL);
- if (timeout) alarm(timeout);
-
- if (read(0, pass, sizeof(pass) - 1) <= 0)
- ret = NULL;
- else {
- for(i = 0; i < sizeof(pass) && pass[i]; i++)
- if (pass[i] == '\r' || pass[i] == '\n') {
- pass[i] = 0;
- break;
- }
- }
- alarm(0);
- tcsetattr(0, TCSANOW, &old);
- printf("\n");
+ struct sigaction sa;
+ struct termios old, tty;
+ static char pass[128];
+ char *ret = pass;
+ int i;
+
+ if (crypted[0])
+ printf("Give root password for maintenance\n");
+ else
+ printf("Press enter for maintenance\n");
+ printf("(or type Control-D to continue): ");
+ fflush(stdout);
+
+ tcgetattr(0, &old);
+ tcgetattr(0, &tty);
+ tty.c_iflag &= ~(IUCLC | IXON | IXOFF | IXANY);
+ tty.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | TOSTOP);
+ tcsetattr(0, TCSANOW, &tty);
+
+ pass[sizeof(pass) - 1] = 0;
+
+ sa.sa_handler = alrm_handler;
+ sa.sa_flags = 0;
+ sigaction(SIGALRM, &sa, NULL);
+ if (timeout)
+ alarm(timeout);
+
+ if (read(0, pass, sizeof(pass) - 1) <= 0)
+ ret = NULL;
+ else
+ {
+ for (i = 0; i < sizeof(pass) && pass[i]; i++)
+ if (pass[i] == '\r' || pass[i] == '\n')
+ {
+ pass[i] = 0;
+ break;
+ }
+ }
+ alarm(0);
+ tcsetattr(0, TCSANOW, &old);
+ printf("\n");
- return ret;
+ return ret;
}
/*
- * Password was OK, execute a shell.
+ * Password was OK, execute a shell.
*/
void sushell(struct passwd *pwd)
{
- char shell[128];
- char home[128];
- char *p;
- char *sushell;
-
- /*
- * Set directory and shell.
- */
- (void)chdir(pwd->pw_dir);
- if ((p = getenv("SUSHELL")) != NULL)
- sushell = p;
- else if ((p = getenv("sushell")) != NULL)
- sushell = p;
- else {
- if (pwd->pw_shell[0])
- sushell = pwd->pw_shell;
- else
- sushell = BINSH;
- }
- if ((p = strrchr(sushell, '/')) == NULL)
- p = sushell;
- else
- p++;
- snprintf(shell, sizeof(shell), profile ? "-%s" : "%s", p);
-
- /*
- * Set some important environment variables.
- */
- getcwd(home, sizeof(home));
- setenv("HOME", home, 1);
- setenv("LOGNAME", "root", 1);
- setenv("USER", "root", 1);
- if (!profile)
- setenv("SHLVL","0",1);
-
- /*
- * Try to execute a shell.
- */
- setenv("SHELL", sushell, 1);
- signal(SIGINT, SIG_DFL);
- signal(SIGTSTP, SIG_DFL);
- signal(SIGQUIT, SIG_DFL);
- execl(sushell, shell, NULL);
- perror(sushell);
-
- setenv("SHELL", BINSH, 1);
- execl(BINSH, profile ? "-sh" : "sh", NULL);
- perror(BINSH);
+ char shell[128];
+ char home[128];
+ char *p;
+ char *sushell;
+
+ /*
+ * Set directory and shell.
+ */
+ (void) chdir(pwd->pw_dir);
+ if ((p = getenv("SUSHELL")) != NULL)
+ sushell = p;
+ else if ((p = getenv("sushell")) != NULL)
+ sushell = p;
+ else
+ {
+ if (pwd->pw_shell[0])
+ sushell = pwd->pw_shell;
+ else
+ sushell = BINSH;
+ }
+ if ((p = strrchr(sushell, '/')) == NULL)
+ p = sushell;
+ else
+ p++;
+ snprintf(shell, sizeof(shell), profile ? "-%s" : "%s", p);
+
+ /*
+ * Set some important environment variables.
+ */
+ getcwd(home, sizeof(home));
+ setenv("HOME", home, 1);
+ setenv("LOGNAME", "root", 1);
+ setenv("USER", "root", 1);
+ if (!profile)
+ setenv("SHLVL", "0", 1);
+
+ /*
+ * Try to execute a shell.
+ */
+ setenv("SHELL", sushell, 1);
+ signal(SIGINT, SIG_DFL);
+ signal(SIGTSTP, SIG_DFL);
+ signal(SIGQUIT, SIG_DFL);
+ execl(sushell, shell, NULL);
+ perror(sushell);
+
+ setenv("SHELL", BINSH, 1);
+ execl(BINSH, profile ? "-sh" : "sh", NULL);
+ perror(BINSH);
}
void usage(void)
{
- fprintf(stderr, "Usage: sulogin [-e] [-p] [-t timeout] [tty device]\n");
+ fprintf(stderr, "Usage: sulogin [-e] [-p] [-t timeout] [tty device]\n");
}
int main(int argc, char **argv)
{
- char *tty = NULL;
- char *p;
- struct passwd *pwd;
- int c, fd = -1;
- int opt_e = 0;
- pid_t pid, pgrp, ppgrp, ttypgrp;
-
- /*
- * See if we have a timeout flag.
- */
- opterr = 0;
- while((c = getopt(argc, argv, "ept:")) != EOF) switch(c) {
- case 't':
- timeout = atoi(optarg);
- break;
- case 'p':
- profile = 1;
- break;
- case 'e':
- opt_e = 1;
- break;
- default:
- usage();
- /* Do not exit! */
- break;
- }
-
- if (geteuid() != 0) {
- fprintf(stderr, "sulogin: only root can run sulogin.\n");
- exit(1);
- }
-
- /*
- * See if we need to open an other tty device.
- */
- signal(SIGINT, SIG_IGN);
- signal(SIGQUIT, SIG_IGN);
- signal(SIGTSTP, SIG_IGN);
- if (optind < argc) tty = argv[optind];
- if (tty) {
- if ((fd = open(tty, O_RDWR)) < 0) {
- perror(tty);
- } else if (!isatty(fd)) {
- fprintf(stderr, "%s: not a tty\n", tty);
- close(fd);
- } else {
-
- /*
- * Only go through this trouble if the new
- * tty doesn't fall in this process group.
- */
- pid = getpid();
- pgrp = getpgid(0);
- ppgrp = getpgid(getppid());
- ioctl(fd, TIOCGPGRP, &ttypgrp);
-
- if (pgrp != ttypgrp && ppgrp != ttypgrp) {
- if (pid != getsid(0)) {
- if (pid == getpgid(0))
- setpgid(0, getpgid(getppid()));
- setsid();
- }
-
- signal(SIGHUP, SIG_IGN);
- ioctl(0, TIOCNOTTY, (char *)1);
- signal(SIGHUP, SIG_DFL);
- close(0);
- close(1);
- close(2);
- close(fd);
- fd = open(tty, O_RDWR);
- ioctl(0, TIOCSCTTY, (char *)1);
- dup(fd);
- dup(fd);
- } else
- close(fd);
- }
- }
-
- /*
- * Get the root password.
- */
- if ((pwd = getrootpwent(opt_e)) == NULL) {
- fprintf(stderr, "sulogin: cannot open password database!\n");
- sleep(2);
- }
-
- /*
- * Ask for the password.
- */
- while(pwd) {
- if ((p = getpasswd(pwd->pw_passwd)) == NULL) break;
- if (pwd->pw_passwd[0] == 0 ||
- strcmp(crypt(p, pwd->pw_passwd), pwd->pw_passwd) == 0)
- sushell(pwd);
- printf("Login incorrect.\n");
- }
-
- /*
- * User pressed Control-D.
- */
- return 0;
+ char *tty = NULL;
+ char *p;
+ struct passwd *pwd;
+ int c, fd = -1;
+ int opt_e = 0;
+ pid_t pid, pgrp, ppgrp, ttypgrp;
+
+ /*
+ * See if we have a timeout flag.
+ */
+ opterr = 0;
+ while ((c = getopt(argc, argv, "ept:")) != EOF)
+ switch (c)
+ {
+ case 't':
+ timeout = atoi(optarg);
+ break;
+ case 'p':
+ profile = 1;
+ break;
+ case 'e':
+ opt_e = 1;
+ break;
+ default:
+ usage();
+ /* Do not exit! */
+ break;
+ }
+
+ if (geteuid() != 0)
+ {
+ fprintf(stderr, "sulogin: only root can run sulogin.\n");
+ exit(1);
+ }
+
+ /*
+ * See if we need to open an other tty device.
+ */
+ signal(SIGINT, SIG_IGN);
+ signal(SIGQUIT, SIG_IGN);
+ signal(SIGTSTP, SIG_IGN);
+ if (optind < argc)
+ tty = argv[optind];
+ if (tty)
+ {
+ if ((fd = open(tty, O_RDWR)) < 0)
+ {
+ perror(tty);
+ }
+ else if (!isatty(fd))
+ {
+ fprintf(stderr, "%s: not a tty\n", tty);
+ close(fd);
+ }
+ else
+ {
+
+ /*
+ * Only go through this trouble if the new
+ * tty doesn't fall in this process group.
+ */
+ pid = getpid();
+ pgrp = getpgid(0);
+ ppgrp = getpgid(getppid());
+ ioctl(fd, TIOCGPGRP, &ttypgrp);
+
+ if (pgrp != ttypgrp && ppgrp != ttypgrp)
+ {
+ if (pid != getsid(0))
+ {
+ if (pid == getpgid(0))
+ setpgid(0, getpgid(getppid()));
+ setsid();
+ }
+
+ signal(SIGHUP, SIG_IGN);
+ ioctl(0, TIOCNOTTY, (char *) 1);
+ signal(SIGHUP, SIG_DFL);
+ close(0);
+ close(1);
+ close(2);
+ close(fd);
+ fd = open(tty, O_RDWR);
+ ioctl(0, TIOCSCTTY, (char *) 1);
+ dup(fd);
+ dup(fd);
+ }
+ else
+ close(fd);
+ }
+ }
+
+ /*
+ * Get the root password.
+ */
+ if ((pwd = getrootpwent(opt_e)) == NULL)
+ {
+ fprintf(stderr, "sulogin: cannot open password database!\n");
+ sleep(2);
+ }
+
+ /*
+ * Ask for the password.
+ */
+ while (pwd)
+ {
+ if ((p = getpasswd(pwd->pw_passwd)) == NULL)
+ break;
+ if (pwd->pw_passwd[0] == 0 ||
+ strcmp(crypt(p, pwd->pw_passwd), pwd->pw_passwd) == 0)
+ sushell(pwd);
+ printf("Login incorrect.\n");
+ }
+
+ /*
+ * User pressed Control-D.
+ */
+ return 0;
}
-
Modified: initng/tools/install_service.c
==============================================================================
--- initng/tools/install_service.c (original)
+++ initng/tools/install_service.c Mon Dec 12 23:26:15 2005
@@ -326,7 +326,7 @@
}
/* handle some special phrases */
- for (i=0; STATIC_OVERLAYS[i].opt; ++i)
+ for (i = 0; STATIC_OVERLAYS[i].opt; ++i)
{
if (strcmp(fullphrase, STATIC_OVERLAYS[i].opt) == 0)
{
@@ -372,7 +372,7 @@
i = 0;
while (path[i])
{
- memset(filename, 0, sizeof filename);
+ memset(filename, 0, sizeof filename);
strncpy(filename, path[i], FILENAME_LEN - 2);
len = strlen(filename);
if (filename[len - 1] != '/')
Modified: initng/tools/mountpoint.c
==============================================================================
--- initng/tools/mountpoint.c (original)
+++ initng/tools/mountpoint.c Mon Dec 12 23:26:15 2005
@@ -1,17 +1,17 @@
/*
- * mountpoint See if a directory is a mountpoint.
+ * mountpoint See if a directory is a mountpoint.
*
- * Author: Miquel van Smoorenburg.
+ * Author: Miquel van Smoorenburg.
*
- * Version: @(#)mountpoint 2.85-12 17-Mar-2004 miquels at cistron.nl
+ * Version: @(#)mountpoint 2.85-12 17-Mar-2004 miquels at cistron.nl
*
- * This file is part of the sysvinit suite,
- * Copyright 1991-2004 Miquel van Smoorenburg.
+ * This file is part of the sysvinit suite,
+ * Copyright 1991-2004 Miquel van Smoorenburg.
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
*/
#include <sys/stat.h>
@@ -25,95 +25,99 @@
int dostat(char *path, struct stat *st, int do_lstat, int quiet)
{
- int n;
+ int n;
- if (do_lstat)
- n = lstat(path, st);
- else
- n = stat(path, st);
-
- if (n != 0) {
- if (!quiet)
- fprintf(stderr, "mountpoint: %s: %s\n", path,
- strerror(errno));
- return -1;
- }
- return 0;
+ if (do_lstat)
+ n = lstat(path, st);
+ else
+ n = stat(path, st);
+
+ if (n != 0)
+ {
+ if (!quiet)
+ fprintf(stderr, "mountpoint: %s: %s\n", path, strerror(errno));
+ return -1;
+ }
+ return 0;
}
-void usage(void) {
- fprintf(stderr, "Usage: mountpoint [-q] [-d] [-x] path\n");
- exit(1);
+void usage(void)
+{
+ fprintf(stderr, "Usage: mountpoint [-q] [-d] [-x] path\n");
+ exit(1);
}
int main(int argc, char **argv)
{
- struct stat st, st2;
- char buf[256];
- char *path;
- int quiet = 0;
- int showdev = 0;
- int xdev = 0;
- int c, r;
-
- while ((c = getopt(argc, argv, "dqx")) != EOF) switch(c) {
- case 'd':
- showdev = 1;
- break;
- case 'q':
- quiet = 1;
- break;
- case 'x':
- xdev = 1;
- break;
- default:
- usage();
- break;
- }
- if (optind != argc - 1) usage();
- path = argv[optind];
+ struct stat st, st2;
+ char buf[256];
+ char *path;
+ int quiet = 0;
+ int showdev = 0;
+ int xdev = 0;
+ int c, r;
+
+ while ((c = getopt(argc, argv, "dqx")) != EOF)
+ switch (c)
+ {
+ case 'd':
+ showdev = 1;
+ break;
+ case 'q':
+ quiet = 1;
+ break;
+ case 'x':
+ xdev = 1;
+ break;
+ default:
+ usage();
+ break;
+ }
+ if (optind != argc - 1)
+ usage();
+ path = argv[optind];
- if (dostat(path, &st, !xdev, quiet) < 0)
- return 1;
+ if (dostat(path, &st, !xdev, quiet) < 0)
+ return 1;
- if (xdev) {
+ if (xdev)
+ {
#ifdef __linux__
- if (!S_ISBLK(st.st_mode))
+ if (!S_ISBLK(st.st_mode))
#else
- if (!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode))
+ if (!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode))
#endif
- {
- if (quiet)
- printf("\n");
- else
- fprintf(stderr, "mountpoint: %s: not a block device\n",
- path);
- return 1;
- }
- printf("%u:%u\n", major(st.st_rdev), minor(st.st_rdev));
- return 0;
- }
-
- if (!S_ISDIR(st.st_mode)) {
- if (!quiet)
- fprintf(stderr, "mountpoint: %s: not a directory\n",
- path);
- return 1;
- }
-
- memset(buf, 0, sizeof(buf));
- strncpy(buf, path, sizeof(buf) - 4);
- strcat(buf, "/..");
- if (dostat(buf, &st2, 0, quiet) < 0)
- return 1;
-
- r = (st.st_dev != st2.st_dev) ||
- (st.st_dev == st2.st_dev && st.st_ino == st2.st_ino);
-
- if (!quiet && !showdev)
- printf("%s is %sa mountpoint\n", path, r ? "" : "not ");
- if (showdev)
- printf("%u:%u\n", major(st.st_dev), minor(st.st_dev));
+ {
+ if (quiet)
+ printf("\n");
+ else
+ fprintf(stderr, "mountpoint: %s: not a block device\n", path);
+ return 1;
+ }
+ printf("%u:%u\n", major(st.st_rdev), minor(st.st_rdev));
+ return 0;
+ }
+
+ if (!S_ISDIR(st.st_mode))
+ {
+ if (!quiet)
+ fprintf(stderr, "mountpoint: %s: not a directory\n", path);
+ return 1;
+ }
+
+ memset(buf, 0, sizeof(buf));
+ strncpy(buf, path, sizeof(buf) - 4);
+ strcat(buf, "/..");
+ if (dostat(buf, &st2, 0, quiet) < 0)
+ return 1;
+
+ r = (st.st_dev != st2.st_dev) ||
+ (st.st_dev == st2.st_dev && st.st_ino == st2.st_ino);
+
+ if (!quiet && !showdev)
+ printf("%s is %sa mountpoint\n", path, r ? "" : "not ");
+ if (showdev)
+ printf("%u:%u\n", major(st.st_dev), minor(st.st_dev));
- return r ? 0 : 1;
+ return r ? 0 : 1;
}
More information about the Initng-svn
mailing list