Ejemplo n.º 1
0
int check_utc ( void )
{
	int utc = 0;
	FILE *f = fopen ( "/etc/adjtime", "r" );
	
	if ( f ) {
		char buffer [128];
	
		while ( fgets ( buffer, sizeof( buffer ), f )) {
			int len = bb_strlen ( buffer );
			
			while ( len && isspace ( buffer [len - 1] ))
				len--;
				
			buffer [len] = 0;
		
			if ( strncmp ( buffer, "UTC", 3 ) == 0 ) {
				utc = 1;
				break;
			}
		}
		fclose ( f );
	}
	return utc;
}
Ejemplo n.º 2
0
static int check_tty ( const char *tty )
{
	FILE *fp;
	int i;
	char buf[BUFSIZ];

	if (( fp = fopen ( bb_path_securetty_file, "r" ))) {
		while ( fgets ( buf, sizeof( buf ) - 1, fp )) {
			for ( i = bb_strlen( buf ) - 1; i >= 0; --i ) {
				if ( !isspace ( buf[i] ))
					break;
			}
			buf[++i] = '\0';
			if (( buf [0] == '\0' ) || ( buf [0] == '#' ))
				continue;

			if ( strcmp ( buf, tty ) == 0 ) {
				fclose ( fp );
				return 1;
			}
		}
		fclose(fp);
		return 0;
	}
	/* A missing securetty file is not an error. */
	return 1;
}
Ejemplo n.º 3
0
int correct_password ( const struct passwd *pw )
{
	char *unencrypted, *encrypted, *correct;

#ifdef CONFIG_FEATURE_SHADOWPASSWDS
	if (( strcmp ( pw-> pw_passwd, "x" ) == 0 ) || ( strcmp ( pw-> pw_passwd, "*" ) == 0 )) {
		struct spwd *sp = getspnam ( pw-> pw_name );

		if ( !sp )
			bb_error_msg_and_die ( "\nno valid shadow password" );

		correct = sp-> sp_pwdp;
	}
	else
#endif
		correct = pw-> pw_passwd;

	if ( correct == 0 || correct[0] == '\0' )
		return 1;

	unencrypted = bb_askpass ( 0, "Password: " );
	if ( !unencrypted )
	{
		return 0;
	}
	encrypted = crypt ( unencrypted, correct );
	memset ( unencrypted, 0, bb_strlen ( unencrypted ));
	return ( strcmp ( encrypted, correct ) == 0 ) ? 1 : 0;
}
Ejemplo n.º 4
0
/*
 *     Display all the sysctl settings
 *
 */
int sysctl_display_all(const char *path, int output, int show_table)
{
	int retval = 0;
	int retval2;
	DIR *dp;
	struct dirent *de;
	char *tmpdir;
	struct stat ts;

	if (!(dp = opendir(path))) {
		bb_perror_msg(ERR_OPENING_DIR, path);
		retval = -1;
	} else {
		while ((de = readdir(dp)) != NULL) {
			tmpdir = concat_subpath_file(path, de->d_name);
			if(tmpdir == NULL)
				continue;
			if ((retval2 = stat(tmpdir, &ts)) != 0)
				bb_perror_msg(tmpdir);
			else {
				if (S_ISDIR(ts.st_mode)) {
					sysctl_display_all(tmpdir, output, show_table);
				} else
					retval |=
						sysctl_read_setting(tmpdir + bb_strlen(PROC_PATH),
											output);

			}
			free(tmpdir);
		}				/* end while */
		closedir(dp);
	}

	return retval;
}						/* end sysctl_display_all() */
Ejemplo n.º 5
0
int sysctl_preload_file(const char *filename, int output)
{
	int lineno = 0;
	char oneline[PRELOAD_BUF];
	char buffer[PRELOAD_BUF];
	char *name, *value, *ptr;
	FILE *fp = NULL;

	if (!filename || ((fp = fopen(filename, "r")) == NULL)) {
		bb_error_msg_and_die(ERR_PRELOAD_FILE, filename);
	}

	while (fgets(oneline, sizeof(oneline) - 1, fp)) {
		oneline[sizeof(oneline) - 1] = 0;
		lineno++;
		trim(oneline);
		ptr = (char *) oneline;

		if (*ptr == '#' || *ptr == ';')
			continue;

		if (bb_strlen(ptr) < 2)
			continue;

		name = strtok(ptr, "=");
		if (!name || !*name) {
			bb_error_msg(WARN_BAD_LINE, filename, lineno);
			continue;
		}

		trim(name);

		value = strtok(NULL, "\n\r");
		if (!value || !*value) {
			bb_error_msg(WARN_BAD_LINE, filename, lineno);
			continue;
		}

		while ((*value == ' ' || *value == '\t') && *value != 0)
			value++;
		strcpy(buffer, name);
		strcat(buffer, "=");
		strcat(buffer, value);
		sysctl_write_setting(buffer, output);
	}
	fclose(fp);
	return 0;
}						/* end sysctl_preload_file() */
Ejemplo n.º 6
0
int show_clock ( int utc )
{
	struct tm *ptm;
	time_t t;
	char buffer [64];

	t = read_rtc ( utc );		
	ptm = localtime ( &t );  /* Sets 'tzname[]' */
	
	safe_strncpy ( buffer, ctime ( &t ), sizeof( buffer ));
	if ( buffer [0] )
		buffer [bb_strlen ( buffer ) - 1] = 0;
	
	//printf ( "%s  %.6f seconds %s\n", buffer, 0.0, utc ? "" : ( ptm-> tm_isdst ? tzname [1] : tzname [0] ));
	printf ( "%s  %.6f seconds\n", buffer, 0.0 );
	
	return 0;
}
Ejemplo n.º 7
0
int date_main(int argc, char **argv)
{
	char *date_str = NULL;
	char *date_fmt = NULL;
	char *t_buff;
	int set_time;
	int utc;
	int use_arg = 0;
	time_t tm;
	unsigned long opt;
	struct tm tm_time;
	char *filename = NULL;

#ifdef CONFIG_FEATURE_DATE_ISOFMT
	int ifmt = 0;
	char *isofmt_arg;

# define GETOPT_ISOFMT  "I::"
#else
# define GETOPT_ISOFMT
#endif
	bb_opt_complementaly = "d~ds:s~ds";
	opt = bb_getopt_ulflags(argc, argv, "Rs:ud:r:" GETOPT_ISOFMT,
					&date_str, &date_str, &filename
#ifdef CONFIG_FEATURE_DATE_ISOFMT
					, &isofmt_arg
#endif
					);
	set_time = opt & DATE_OPT_SET;
	utc = opt & DATE_OPT_UTC;
	if ((utc) && (putenv("TZ=UTC0") != 0)) {
		bb_error_msg_and_die(bb_msg_memory_exhausted);
	}
	use_arg = opt & DATE_OPT_DATE;
	if(opt & 0x80000000UL)
		bb_show_usage();
#ifdef CONFIG_FEATURE_DATE_ISOFMT
	if(opt & DATE_OPT_TIMESPEC) {
		if (!isofmt_arg) {
			ifmt = 1;
		} else {
			int ifmt_len = bb_strlen(isofmt_arg);

			if ((ifmt_len <= 4)
				&& (strncmp(isofmt_arg, "date", ifmt_len) == 0)) {
				ifmt = 1;
			} else if ((ifmt_len <= 5)
				   && (strncmp(isofmt_arg, "hours", ifmt_len) == 0)) {
				ifmt = 2;
			} else if ((ifmt_len <= 7)
				   && (strncmp(isofmt_arg, "minutes", ifmt_len) == 0)) {
				ifmt = 3;
			} else if ((ifmt_len <= 7)
				   && (strncmp(isofmt_arg, "seconds", ifmt_len) == 0)) {
				ifmt = 4;
			}
		}
		if (!ifmt) {
			bb_show_usage();
		}
	}
#endif

	if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+')) {
		date_fmt = &argv[optind][1];	/* Skip over the '+' */
	} else if (date_str == NULL) {
		set_time = 1;
		date_str = argv[optind];
	}

	/* Now we have parsed all the information except the date format
	   which depends on whether the clock is being set or read */

	if(filename) {
		struct stat statbuf;
		if(stat(filename,&statbuf))
			bb_perror_msg_and_die("File '%s' not found.\n",filename);
		tm=statbuf.st_mtime;
	} else time(&tm);
	memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
	/* Zero out fields - take her back to midnight! */
	if (date_str != NULL) {
		tm_time.tm_sec = 0;
		tm_time.tm_min = 0;
		tm_time.tm_hour = 0;

		/* Process any date input to UNIX time since 1 Jan 1970 */
		if (strchr(date_str, ':') != NULL) {
			date_conv_ftime(&tm_time, date_str);
		} else {
			date_conv_time(&tm_time, date_str);
		}

		/* Correct any day of week and day of year etc. fields */
		tm_time.tm_isdst = -1;	/* Be sure to recheck dst. */
		tm = mktime(&tm_time);
		if (tm < 0) {
			bb_error_msg_and_die(bb_msg_invalid_date, date_str);
		}
		if (utc && (putenv("TZ=UTC0") != 0)) {
			bb_error_msg_and_die(bb_msg_memory_exhausted);
		}

		/* if setting time, set it */
		if (set_time && (stime(&tm) < 0)) {
			bb_perror_msg("cannot set date");
		}
	}

	/* Display output */

	/* Deal with format string */
	if (date_fmt == NULL) {
#ifdef CONFIG_FEATURE_DATE_ISOFMT
		switch (ifmt) {
		case 4:
			date_fmt = utc ? "%Y-%m-%dT%H:%M:%SZ" : "%Y-%m-%dT%H:%M:%S%z";
			break;
		case 3:
			date_fmt = utc ? "%Y-%m-%dT%H:%MZ" : "%Y-%m-%dT%H:%M%z";
			break;
		case 2:
			date_fmt = utc ? "%Y-%m-%dT%HZ" : "%Y-%m-%dT%H%z";
			break;
		case 1:
			date_fmt = "%Y-%m-%d";
			break;
		case 0:
		default:
#endif
			date_fmt = (opt & DATE_OPT_RFC2822 ?
					(utc ? "%a, %d %b %Y %H:%M:%S GMT" :
					"%a, %d %b %Y %H:%M:%S %z") :
					"%a %b %e %H:%M:%S %Z %Y");

#ifdef CONFIG_FEATURE_DATE_ISOFMT
			break;
		}
#endif
	} else if (*date_fmt == '\0') {
		/* Imitate what GNU 'date' does with NO format string! */
		printf("\n");
		return EXIT_SUCCESS;
	}

	/* Handle special conversions */

	if (strncmp(date_fmt, "%f", 2) == 0) {
		date_fmt = "%Y.%m.%d-%H:%M:%S";
	}

	/* Print OUTPUT (after ALL that!) */
	t_buff = xmalloc(201);
	strftime(t_buff, 200, date_fmt, &tm_time);
	puts(t_buff);

	return EXIT_SUCCESS;
}