Esempio n. 1
0
int
main(int argc, char **argv)
{
	int envargc, argcnt;
	char *envargv[3];
	struct passwd *pw;
	static char myname[] = "finger";

	if (getuid() == 0 || geteuid() == 0) {
		invoker_root = 1;
		if ((pw = getpwnam(UNPRIV_NAME)) && pw->pw_uid > 0) {
			if (setgid(pw->pw_gid) != 0)
				err(1, "setgid()");
			if (setuid(pw->pw_uid) != 0)
				err(1, "setuid()");
		} else {
			if (setgid(UNPRIV_UGID) != 0)
				err(1, "setgid()");
			if (setuid(UNPRIV_UGID) != 0)
				err(1, "setuid()");
		}
	}

	(void) setlocale(LC_ALL, "");

				/* remove this line to get remote host */
	oflag = 1;		/* default to old "office" behavior */

	/*
	 * Process environment variables followed by command line arguments.
	 */
	if ((envargv[1] = getenv("FINGER"))) {
		envargc = 2;
		envargv[0] = myname;
		envargv[2] = NULL;
		(void) option(envargc, envargv);
	}

	argcnt = option(argc, argv);
	argc -= argcnt;
	argv += argcnt;

	(void)time(&now);
	setpassent(1);
	if (!*argv) {
		/*
		 * Assign explicit "small" format if no names given and -l
		 * not selected.  Force the -s BEFORE we get names so proper
		 * screening will be done.
		 */
		if (!lflag)
			sflag = 1;	/* if -l not explicit, force -s */
		loginlist();
		if (entries == 0)
			(void)printf("No one logged on.\n");
	} else {
		userlist(argc, argv);
		/*
		 * Assign explicit "large" format if names given and -s not
		 * explicitly stated.  Force the -l AFTER we get names so any
		 * remote finger attempts specified won't be mishandled.
		 */
		if (!sflag)
			lflag = 1;	/* if -s not explicit, force -l */
	}
	if (entries) {
		if (lflag)
			lflag_print();
		else
			sflag_print();
	}
	return (0);
}
Esempio n. 2
0
int
main(int argc, char **argv)
{
	int ch;

	/* Allow user's locale settings to affect character output. */
	setlocale(LC_CTYPE, "");

	/*
	 * Reset back to the C locale, unless we are using a known
	 * single-byte 8-bit locale.
	 */
	if (strncmp(nl_langinfo(CODESET), "ISO8859-", 8))
		setlocale(LC_CTYPE, "C");

	oflag = 1;		/* default to old "office" behavior */

	while ((ch = getopt(argc, argv, "lmpshog8")) != -1)
		switch(ch) {
		case 'l':
			lflag = 1;		/* long format */
			break;
		case 'm':
			mflag = 1;		/* force exact match of names */
			break;
		case 'p':
			pplan = 1;		/* don't show .plan/.project */
			break;
		case 's':
			sflag = 1;		/* short format */
			break;
		case 'h':
			oflag = 0;		/* remote host info */
			break;
		case 'o':
			oflag = 1;		/* office info */
			break;
		case 'g':
			gflag = 1;		/* no gecos info, besides name */
			break;
		case '8':
			eightflag = 1;		/* 8-bit pass-through */
			break;
		case '?':
		default:
			(void)fprintf(stderr,
			    "usage: finger [-lmpshog8] [login ...]\n");
			exit(1);
		}
	argc -= optind;
	argv += optind;

	(void)time(&now);
	setpassent(1);
	entries = getutentries(NULL, &ehead);
	if (argc == 0) {
		/*
		 * Assign explicit "small" format if no names given and -l
		 * not selected.  Force the -s BEFORE we get names so proper
		 * screening will be done.
		 */
		if (!lflag)
			sflag = 1;	/* if -l not explicit, force -s */
		loginlist();
		if (entries == 0)
			(void)printf("No one logged on.\n");
	} else {
		userlist(argc, argv);
		/*
		 * Assign explicit "large" format if names given and -s not
		 * explicitly stated.  Force the -l AFTER we get names so any
		 * remote finger attempts specified won't be mishandled.
		 */
		if (!sflag)
			lflag = 1;	/* if -s not explicit, force -l */
	}
	if (entries) {
		if (lflag)
			lflag_print();
		else
			sflag_print();
	}
	return (0);
}