コード例 #1
0
ファイル: gpasswd.c プロジェクト: DavidChenLiang/study
static void change_passwd (struct group *gr)
#endif
{
	char *cp;
	static char pass[BUFSIZ];
	int retries;

	/*
	 * A new password is to be entered and it must be encrypted, etc.
	 * The password will be prompted for twice, and both entries must be
	 * identical. There is no need to validate the old password since
	 * the invoker is either the group owner, or root.
	 */
	printf (_("Changing the password for group %s\n"), group);

	for (retries = 0; retries < RETRIES; retries++) {
		cp = getpass (_("New Password: "******"Re-enter new password: "******"They don't match; try again"));
		}
	}

	if (retries == RETRIES) {
		fprintf (stderr, _("%s: Try again later\n"), Prog);
		exit (1);
	}

	cp = pw_encrypt (pass, crypt_make_salt (NULL, NULL));
	memzero (pass, sizeof pass);
#ifdef SHADOWGRP
	if (is_shadowgrp) {
		gr->gr_passwd = SHADOW_PASSWD_STRING;
		sg->sg_passwd = cp;
	} else
#endif
	{
		gr->gr_passwd = cp;
	}
}
コード例 #2
0
ファイル: main.c プロジェクト: shattered/dmd-dev5620
main()
{
	register got;
	request(KBD|MOUSE|RCV|SEND);
	newlnsz=defont.height;
	init();
	strzero(&snarfbuf);
	waitunix(&diagdone);	/* when menu is loaded */
	for(got=0; ; got=wait(MOUSE|KBD|RCV)){
		if(P->state&RESHAPED){
			rectf(&display, Drect, F_CLR);
			closeall();
			init();
			P->state&=~RESHAPED;
		}
		/* NOTE: cursor is OFF at all times... */
		if((got&RCV) && rcv()){
			curse(current->frame);
			(void)message();
			curse(current->frame);
		}
		if((got&MOUSE) && bttn123() && ptinrect(mouse.xy, display.rect)){
			curse(current->frame);
			buttonhit(mouse.xy, mouse.buttons);
			curse(current->frame);
		}
		if((got&KBD) && current)	/* ...except in type */
			type(current);	/* manages cursor itself */
	}
}
コード例 #3
0
ファイル: func.cpp プロジェクト: RCwukaka/myHand
struct room* Initroom(void)
{
	struct room *head;
	head = (struct room *)calloc(1,sizeof(struct room));
	head->transhead = (struct transmiter*)calloc(1,sizeof(struct transmiter));
	if(head == NULL || head->transhead == NULL)
	{
		printf("calloc error\n");
		return NULL;
	}
	head->ID = 0;
	strzero(head->image); 
	strzero(head->name);
	head->next = NULL;
	head->transhead->next = NULL;
	
	return head;
}
コード例 #4
0
ファイル: func.cpp プロジェクト: RCwukaka/myHand
char *getTime(void)
{
	static char timebuf[10];   //attention static
	struct tm *t;
	time_t tt;
	time(&tt);
	t = localtime(&tt);
	strzero(timebuf);
	sprintf(timebuf,"%d:%d:%d:%d",t->tm_hour,t->tm_min,t->tm_sec,t->tm_wday);
	//printf("%d %d %d %d:%d:%d\n",t->tm_year+1900,t->tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
	return timebuf;
	
}
コード例 #5
0
ファイル: func.cpp プロジェクト: RCwukaka/myHand
int Changetransmiterinfo(char *roomname,char *transname,char *newtransname,char *newtransimage)
{
	struct transmiter *temp;
	if((temp = Searchtransmiter(roomname, newtransname,0)) != NULL)
	{
		//the new name trasmiter is already exist
		return 1;
	}
	
	if((temp = Searchtransmiter(roomname, transname,0)) == NULL)  //find the room
	{
		//the old name transmitter is not exist
		return -1;
	}

	/*change room's information*/
	strzero(temp->name);
	strzero(temp->image);
	strncpy(temp->name,newtransname,20);
	strncpy(temp->image,newtransimage,20);

	return 0;	
}
コード例 #6
0
ファイル: func.cpp プロジェクト: RCwukaka/myHand
//Changeroominfo:修改房间信息
int Changeroominfo(char *roomname,char *newrmname,char *newrmimage)
{
	struct room *temp;
	if((temp = Searchroom(newrmname,0)) != NULL)	
	{
		return 1; //the newroomname is already exist
	}
	else
	{
		if((temp = Searchroom(roomname,0)) == NULL)  //find the room
		{
			//printf("the %d room is not exixt\n",roomname);
			return -1;
		}

		/*change room's information*/
		strzero(temp->name);
		strzero(temp->image);
		strncpy(temp->name,newrmname,20);
		strncpy(temp->image,newrmimage,20);

		return 0;		
	}
}
コード例 #7
0
ファイル: func.cpp プロジェクト: RCwukaka/myHand
int Savetransvalue(char *rmname,char *transname,int channel,struct transvalues *temp)
{
	int i = 0 ;  //i 表示遥控器ID号  从0开始
	struct transmiter *transtemp;

	//确定此房间遥控器链表头
	if((transtemp = Searchtransmiter(rmname,transname,0)) == NULL)  //find the dev
	{
		return -1; //the dev is not exist 
	}
	
	//init new transmitter list Node
	strzero(&(transtemp->vv[channel]));
	transtemp->vv[channel] = *temp;
	
	return 0;	
}
コード例 #8
0
ファイル: func.cpp プロジェクト: RCwukaka/myHand
//Changescensinfo:修改情景组(name)
int Changescensinfo(char *name,char *newname)
{
	struct Scenarios *temp;
	if((temp = Searchscens(newname,0)) != NULL)	
	{
		return 1; //the newname scenraios is already exist
	}
	else
	{
		if((temp = Searchscens(name,0)) == NULL)  //find the scenraios
		{
			//printf("the scenraios is not exixt\n",roomname);
			return -1;
		}

		/*change scenraios's information*/
		strzero(temp->name);
		strncpy(temp->name,newname,20);

		return 0;		
	}
}
コード例 #9
0
ファイル: pwauth.c プロジェクト: OPSF/uClinux
int
pw_auth (const char *cipher, const char *user, int reason, const char *input)
{
	char prompt[1024];
	char *clear = NULL;
	const char *cp;
	int retval;

#ifdef	SKEY
	int use_skey = 0;
	char challenge_info[40];
	struct skey skey;
#endif

	/*
	 * There are programs for adding and deleting authentication data.
	 */

	if (reason == PW_ADD || reason == PW_DELETE)
		return 0;

	/*
	 * There are even programs for changing the user name ...
	 */

	if (reason == PW_CHANGE && input != (char *) 0)
		return 0;

	/*
	 * WARNING:
	 *
	 * When we change a password and we are root, we don't prompt.
	 * This is so root can change any password without having to
	 * know it.  This is a policy decision that might have to be
	 * revisited.
	 */

	if (reason == PW_CHANGE && getuid () == 0)
		return 0;

	/*
	 * WARNING:
	 *
	 * When we are logging in a user with no ciphertext password,
	 * we don't prompt for the password or anything.  In reality
	 * the user could just hit <ENTER>, so it doesn't really
	 * matter.
	 */

	if (cipher == (char *) 0 || *cipher == '\0')
		return 0;

#ifdef	SKEY
	/*
	 * If the user has an S/KEY entry show them the pertinent info
	 * and then we can try validating the created cyphertext and the SKEY.
	 * If there is no SKEY information we default to not using SKEY.
	 */

	if (skeychallenge (&skey, user, challenge_info) == 0)
		use_skey = 1;
#endif

	/*
	 * Prompt for the password as required.  FTPD and REXECD both
	 * get the cleartext password for us.
	 */

	if (reason != PW_FTP && reason != PW_REXEC && !input) {
		if (!(cp = getdef_str ("LOGIN_STRING")))
			cp = _(PROMPT);
#ifdef	SKEY
		if (use_skey)
			printf ("[%s]\n", challenge_info);
#endif

		snprintf (prompt, sizeof prompt, cp, user);
		clear = getpass (prompt);
		if (!clear) {
			static char c[1];

			c[0] = '\0';
			clear = c;
		}
		input = clear;
	}

	/*
	 * Convert the cleartext password into a ciphertext string.
	 * If the two match, the return value will be zero, which is
	 * SUCCESS. Otherwise we see if SKEY is being used and check
	 * the results there as well.
	 */

	retval = strcmp (pw_encrypt (input, cipher), cipher);

#ifdef  SKEY
	/*
	 * If (1) The password fails to match, and
	 * (2) The password is empty and
	 * (3) We are using OPIE or S/Key, then
	 * ...Re-prompt, with echo on.
	 * -- AR 8/22/1999
	 */
	if (retval && !input[0] && (use_skey)) {
		strncat (prompt, "(Echo on) ",
			 (sizeof (prompt) - strlen (prompt)));
		clear = getpass_with_echo (prompt);
		if (!clear) {
			static char c[1];

			c[0] = '\0';
			clear = c;
		}
		input = clear;
	}

	if (retval && use_skey) {
		int passcheck = -1;

		if (skeyverify (&skey, input) == 0)
			passcheck = skey.n;
		if (passcheck > 0)
			retval = 0;
	}
#endif

	/*
	 * Things like RADIUS authentication may need the password -
	 * if the external variable wipe_clear_pass is zero, we will
	 * not wipe it (the caller should wipe clear_pass when it is
	 * no longer needed).  --marekm
	 */

	clear_pass = clear;
	if (wipe_clear_pass && clear && *clear)
		strzero (clear);
	return retval;
}
コード例 #10
0
ファイル: sulogin.c プロジェクト: brauner/shadow
 /*ARGSUSED*/ int main (int argc, char **argv)
{
#ifndef USE_PAM
	const char *env;
#endif				/* !USE_PAM */
	char **envp = environ;
	TERMIO termio;
	int err = 0;

#ifdef	USE_TERMIO
	ioctl (0, TCGETA, &termio);
	termio.c_iflag |= (ICRNL | IXON);
	termio.c_oflag |= (OPOST | ONLCR);
	termio.c_cflag |= (CREAD);
	termio.c_lflag |= (ISIG | ICANON | ECHO | ECHOE | ECHOK);
	ioctl (0, TCSETAF, &termio);
#endif
#ifdef	USE_TERMIOS
	tcgetattr (0, &termio);
	termio.c_iflag |= (ICRNL | IXON);
	termio.c_oflag |= (CREAD);
	termio.c_lflag |= (ECHO | ECHOE | ECHOK | ICANON | ISIG);
	tcsetattr (0, TCSANOW, &termio);
#endif

	Prog = Basename (argv[0]);
	(void) setlocale (LC_ALL, "");
	(void) bindtextdomain (PACKAGE, LOCALEDIR);
	(void) textdomain (PACKAGE);

#ifdef	USE_SYSLOG
	OPENLOG ("sulogin");
#endif
	initenv ();
	if (argc > 1) {
		close (0);
		close (1);
		close (2);

		if (open (argv[1], O_RDWR) >= 0) {
			dup (0);
			dup (0);
		} else {
#ifdef	USE_SYSLOG
			SYSLOG (LOG_WARN, "cannot open %s\n", argv[1]);
			closelog ();
#endif
			exit (1);
		}
	}
	if (access (PASSWD_FILE, F_OK) == -1) {	/* must be a password file! */
		(void) puts (_("No password file"));
#ifdef	USE_SYSLOG
		SYSLOG (LOG_WARN, "No password file\n");
		closelog ();
#endif
		exit (1);
	}
#if !defined(DEBUG) && defined(SULOGIN_ONLY_INIT)
	if (getppid () != 1) {	/* parent must be INIT */
#ifdef	USE_SYSLOG
		SYSLOG (LOG_WARN, "Pid == %d, not 1\n", getppid ());
		closelog ();
#endif
		exit (1);
	}
#endif
	if ((isatty (0) == 0) || (isatty (1) == 0) || (isatty (2) == 0)) {
#ifdef	USE_SYSLOG
		closelog ();
#endif
		exit (1);	/* must be a terminal */
	}
	/* If we were init, we need to start a new session */
	if (getppid() == 1) {
		setsid();
		if (ioctl(0, TIOCSCTTY, 1) != 0) {
			(void) fputs (_("TIOCSCTTY failed"), stderr);
		}
	}
	while (NULL != *envp) {		/* add inherited environment, */
		addenv (*envp, NULL);	/* some variables change later */
		envp++;
	}

#ifndef USE_PAM
	env = getdef_str ("ENV_TZ");
	if (NULL != env) {
		addenv (('/' == *env) ? tz (env) : env, NULL);
	}
	env = getdef_str ("ENV_HZ");
	if (NULL != env) {
		addenv (env, NULL);	/* set the default $HZ, if one */
	}
#endif				/* !USE_PAM */

	(void) strcpy (name, "root");	/* KLUDGE!!! */

	(void) signal (SIGALRM, catch_signals);	/* exit if the timer expires */
	(void) alarm (ALARM);		/* only wait so long ... */

	while (true) {		/* repeatedly get login/password pairs */
		char *cp;
		pw_entry (name, &pwent);	/* get entry from password file */
		if (pwent.pw_name == (char *) 0) {
			/*
			 * Fail secure
			 */
			(void) puts (_("No password entry for 'root'"));
#ifdef	USE_SYSLOG
			SYSLOG (LOG_WARN, "No password entry for 'root'\n");
			closelog ();
#endif
			exit (1);
		}

		/*
		 * Here we prompt for the root password, or if no password
		 * is given we just exit.
		 */

		/* get a password for root */
		cp = getpass (_(
"\n"
"Type control-d to proceed with normal startup,\n"
"(or give root password for system maintenance):"));
		/*
		 * XXX - can't enter single user mode if root password is
		 * empty.  I think this doesn't happen very often :-). But
		 * it will work with standard getpass() (no NULL on EOF). 
		 * --marekm
		 */
		if ((NULL == cp) || ('\0' == *cp)) {
#ifdef	USE_SYSLOG
			SYSLOG (LOG_INFO, "Normal startup\n");
			closelog ();
#endif
			(void) puts ("");
#ifdef	TELINIT
			execl (PATH_TELINIT, "telinit", RUNLEVEL, (char *) 0);
#endif
			exit (0);
		} else {
			STRFCPY (pass, cp);
			strzero (cp);
		}
		if (valid (pass, &pwent)) {	/* check encrypted passwords ... */
			break;	/* ... encrypted passwords matched */
		}

#ifdef	USE_SYSLOG
		SYSLOG (LOG_WARN, "Incorrect root password\n");
#endif
		sleep (2);
		(void) puts (_("Login incorrect"));
	}
	strzero (pass);
	(void) alarm (0);
	(void) signal (SIGALRM, SIG_DFL);
	environ = newenvp;	/* make new environment active */

	(void) puts (_("Entering System Maintenance Mode"));
#ifdef	USE_SYSLOG
	SYSLOG (LOG_INFO, "System Maintenance Mode\n");
#endif

#ifdef	USE_SYSLOG
	closelog ();
#endif
	/* exec the shell finally. */
	err = shell (pwent.pw_shell, (char *) 0, environ);

	return ((err == ENOENT) ? E_CMD_NOTFOUND : E_CMD_NOEXEC);
}
コード例 #11
0
ファイル: func.cpp プロジェクト: RCwukaka/myHand
//Searchdevinscens:查询情景组中特定房间的遥控器(此房间可能未加入到情景组中)
//key=1 表示查找已添加的设备,key=0 表示查找未添加的设备
char *Searchdevinscens(char *scensname,char *rmname,int key)
{
	struct Scenarios *scenstemp; 
	struct devinscens *devtemp;
	struct room *rmtemp;
	struct transmiter *transtemp,*current;
	char data[80]; //{'trasname':%s,'trasimage':%s}
	static char bufin[512] ;
	static char bufnotin[512];
	int temp = 0; //temp  标志rmname房间是否在情景组中

	strzero(bufin);
	strzero(bufnotin);

	scenstemp = Searchscens(scensname,0); //scenstemp is the scenslist's head
	devtemp = scenstemp->devhead;   //devtemp is the devinscenslist's head

	//1) 当情景组中没添加任何设备时,rmname房间中的遥控器均为未添加的
	//当rmname房间没添加任何设备时,返回空
	//但rmname房间有设备时,均为未添加的
	if(devtemp->next == NULL)
	{
		rmtemp = Searchroom(rmname,0); //rmname 房间肯定存在房间链表中
		transtemp = rmtemp->transhead; //transtemp 是rnmane房间遥控器链表头
	
		if(transtemp->next == NULL)
		{
			//当rmname 房间中没添加任何设备时,返回空
			return NULL;
		}
		else
		{
			//rmname 房间中的遥控器都是未添加到情景组的
			transtemp = transtemp->next; //transtemp 是遥控器链表的第一个节点
			while(transtemp != NULL)
			{
				strzero(data);
				sprintf(data,"{'trasname':'%s','trasimage':'%s'},",transtemp->name,transtemp->image);
				strcat(bufnotin,data);
				transtemp = transtemp->next;//居然忘了这一行,悲剧啊!!!!
			}
		}
	}
	else //2)当情景组已添加设备时
	{
		//先判断rmname房间是否在此情景组中
		while(devtemp->next != NULL) //遍历情景组中的设备
		{
			devtemp = devtemp->next;
			//当rmname房间在情景组中时,说明此房间有遥控器添加到情景组中
			//然后查找此房间的遥控器链表,确定已添加到情景组中的遥控器
			//最后设置此遥控器的scenstate=1,表明已添加到情景组,方便后面操作
			if(strncmp(devtemp->rmname,rmname,20) == 0) 
			{
				temp = 1; 
				// 在遥控器链表中查找情景组中已添加的设备
				transtemp = Searchtransmiter(rmname, devtemp->transname, 0);
			
				//设scenstate=1,表明此设备已添加到情景组
				transtemp->scenstate = 1;
			}
		}
		//temp = 0 rmname房间 不存在此情景组中
		//1)当rmname中没添加任何遥控器时,返回为空
		//2)当rmname中添加了遥控器时,遥控器均为未添加到情景组的
		if(temp == 0) 
		{
			rmtemp = Searchroom(rmname,0); //rmname房间一定存在房间链表
			transtemp = rmtemp->transhead; //transtemp 是rnmane房间遥控器链表头
	
			if(transtemp->next == NULL)
			{
				//当rmname 房间中没添加任何设备时,返回空
				return NULL;
			}
			else
			{
				//rmname 房间中的遥控器都是未添加到情景组的
				transtemp = transtemp->next; //transtemp 是遥控器链表的第一个节点
				while(transtemp != NULL)
				{
					strzero(data);
					sprintf(data,"{'trasname':'%s','trasimage':'%s'},",transtemp->name,transtemp->image);
					strcat(bufnotin,data);
					transtemp = transtemp->next;
				}
			}
		}
		else //temp = 1 rmname 房间存在此情景组中
		{
			//查找 rmname 的房间节点
			rmtemp = Searchroom(rmname,0);
			
			//遍历此房间的设备链表,current为链表头 ,
			//根据scenstate,分离已添加到和未添加到情景组的设备
			//分离后,scenstate的值恢复到默认值 0
			current = rmtemp->transhead; //current 为链表头 
			while(current->next != NULL)
			{
				current = current->next;
				strzero(data);
				sprintf(data,"{'trasname':'%s','trasimage':'%s'},",current->name,current->image);

				if(current->scenstate == 1)
				{
					strcat(bufin,data);
					current->scenstate = 0;
				}	
				else
				{
					strcat(bufnotin,data);
				}
			}			
		}
	}

	if(key == 1)  //查询情景组中已添加的设备
	{
		return bufin;
	}
	else  //key == 0 查询情景组中未添加的设备
	{
		return bufnotin;
	}
}
コード例 #12
0
ファイル: login.c プロジェクト: justinc1985/IntelRangeley
static void process_flags (int argc, char *const *argv)
{
	int arg;
	int flag;

	/*
	 * Check the flags for proper form. Every argument starting with
	 * "-" must be exactly two characters long. This closes all the
	 * clever rlogin, telnet, and getty holes.
	 */
	for (arg = 1; arg < argc; arg++) {
		if (argv[arg][0] == '-' && strlen (argv[arg]) > 2) {
			usage ();
		}
		if (strcmp(argv[arg], "--") == 0) {
			break; /* stop checking on a "--" */
		}
	}

	/*
	 * Process options.
	 */
	while ((flag = getopt (argc, argv, "d:fh:pr:")) != EOF) {
		switch (flag) {
		case 'd':
			/* "-d device" ignored for compatibility */
			break;
		case 'f':
			fflg = true;
			break;
		case 'h':
			hflg = true;
			hostname = optarg;
			reason = PW_TELNET;
			break;
#ifdef	RLOGIN
		case 'r':
			rflg = true;
			hostname = optarg;
			reason = PW_RLOGIN;
			break;
#endif				/* RLOGIN */
		case 'p':
			pflg = true;
			break;
		default:
			usage ();
		}
	}

#ifdef RLOGIN
	/*
	 * Neither -h nor -f should be combined with -r.
	 */

	if (rflg && (hflg || fflg)) {
		usage ();
	}
#endif				/* RLOGIN */

	/*
	 * Allow authentication bypass only if real UID is zero.
	 */

	if ((rflg || fflg || hflg) && !amroot) {
		fprintf (stderr, _("%s: Permission denied.\n"), Prog);
		exit (1);
	}

	/*
	 *  Get the user name.
	 */
	if (optind < argc) {
		assert (NULL == username);
		username = xstrdup (argv[optind]);
		strzero (argv[optind]);
		++optind;
	}

#ifdef	RLOGIN
	if (rflg && (NULL != username)) {
		usage ();
	}
#endif				/* RLOGIN */
	if (fflg && (NULL == username)) {
		usage ();
	}

}
コード例 #13
0
ファイル: passwd.c プロジェクト: Gioragg1/Test
/*
 * new_password - validate old password and replace with new (both old and
 * new in global "char crypt_passwd[128]")
 */
static int new_password (const struct passwd *pw)
{
	char *clear;		/* Pointer to clear text */
	char *cipher;		/* Pointer to cipher text */
	char *cp;		/* Pointer to getpass() response */
	char orig[200];		/* Original password */
	char pass[200];		/* New password */
	int i;			/* Counter for retries */
	int warned;
	int pass_max_len = -1;
	char *method;

#ifdef HAVE_LIBCRACK_HIST
	int HistUpdate (const char *, const char *);
#endif				/* HAVE_LIBCRACK_HIST */

	/*
	 * Authenticate the user. The user will be prompted for their own
	 * password.
	 */

	if (!amroot && crypt_passwd[0]) {
		clear = getpass (_("Old password: "******"incorrect password for %s",
				 pw->pw_name));
			sleep (1);
			fprintf (stderr,
				 _("Incorrect password for %s.\n"),
				 pw->pw_name);
			return -1;
		}
		STRFCPY (orig, clear);
		strzero (clear);
		strzero (cipher);
	} else {
		orig[0] = '\0';
	}

	/*
	 * Get the new password. The user is prompted for the new password
	 * and has five tries to get it right. The password will be tested
	 * for strength, unless it is the root user. This provides an escape
	 * for initial login passwords.
	 */
	if ((method = getdef_str ("ENCRYPT_METHOD")) == NULL) {
		if (!getdef_bool ("MD5_CRYPT_ENAB")) {
			pass_max_len = getdef_num ("PASS_MAX_LEN", 8);
		}
	} else {
		if (   (strcmp (method, "MD5")    == 0)
#ifdef USE_SHA_CRYPT
		    || (strcmp (method, "SHA256") == 0)
		    || (strcmp (method, "SHA512") == 0)
#endif				/* USE_SHA_CRYPT */
		    ) {
			pass_max_len = -1;
		} else {
			pass_max_len = getdef_num ("PASS_MAX_LEN", 8);
		}
	}
	if (!qflg) {
		if (pass_max_len == -1) {
			printf (_(
"Enter the new password (minimum of %d characters)\n"
"Please use a combination of upper and lower case letters and numbers.\n"),
				getdef_num ("PASS_MIN_LEN", 5));
		} else {
			printf (_(
"Enter the new password (minimum of %d, maximum of %d characters)\n"
"Please use a combination of upper and lower case letters and numbers.\n"),
				getdef_num ("PASS_MIN_LEN", 5), pass_max_len);
		}
	}

	warned = 0;
	for (i = getdef_num ("PASS_CHANGE_TRIES", 5); i > 0; i--) {
		cp = getpass (_("New password: "******"Try again."));
			continue;
		}

		/*
		 * If enabled, warn about weak passwords even if you are
		 * root (enter this password again to use it anyway). 
		 * --marekm
		 */
		if (amroot && !warned && getdef_bool ("PASS_ALWAYS_WARN")
		    && (!obscure (orig, pass, pw) || reuse (pass, pw))) {
			puts (_("\nWarning: weak password (enter it again to use it anyway)."));
			warned++;
			continue;
		}
		cp = getpass (_("Re-enter new password: "******"They don't match; try again.\n"), stderr);
		} else {
			strzero (cp);
			break;
		}
	}
	memzero (orig, sizeof orig);

	if (i == 0) {
		memzero (pass, sizeof pass);
		return -1;
	}

	/*
	 * Encrypt the password, then wipe the cleartext password.
	 */
	cp = pw_encrypt (pass, crypt_make_salt (NULL, NULL));
	memzero (pass, sizeof pass);

#ifdef HAVE_LIBCRACK_HIST
	HistUpdate (pw->pw_name, crypt_passwd);
#endif				/* HAVE_LIBCRACK_HIST */
	STRFCPY (crypt_passwd, cp);
	return 0;
}
コード例 #14
0
ファイル: main.cpp プロジェクト: RCwukaka/myHand
int main(int argc, char **argv)
{
   // FCGI_middle fcgi_middle = FCGI_middle();

    int action;
    int rmID, transID, cmd,get_time;
	int ret,nums; //nums 总数
	int rdroom,rdtransmiter,rdscens;     //readroom
	char rmname[20],transname[20],workday[20];
	char rmimage[20],transimage[20];
	char newname[20],newimage[20];
	char scensname[20];
	int state,rdchannel; //state 遥控器状态,rdchannel(0~15) 遥控器通道
	char hour[4],min[4]; //hour minute 遥控器设定时间
    char *pOutput = NULL; 
	char *timestr; //localtime 时间信息
	char *bufstr; //bufstr 情景组中特定房间遥控器信息
	char data[20];
	char transdata[100];
	int times;  //查询次数
	int count = 0;
	int exetime; //情景组延时执行时间

	/*room's linklist init*/
	if((rmhead = Initroom()) == NULL)
	{
		//printf("Init error\n");
		exit(1);
	}

	/*scenraios's linklist init*/
	if((scenshead = InitScenarios()) == NULL)
	{
		//printf("Init error\n");
		exit(1);
	}
	
	//demoHome();//init room
	
    while(FCGI_Accept() >= 0)
    {
		//cgi init
        cgi_init();
        cgi_process_form();
        if((cgi_param("action") == NULL) ||
                (sscanf(cgi_param("action"), "%d", &action) != 1))
        {
            puts("0");
            cgi_end();
            continue;
        }
		printf("Content_type:text/html\r\n"); //头一定要加
        printf("\r\n");		
		//printf("action=%d",action);	
		//printf("rmhead %x\n",rmhead);
		count++;
        //0-99调试
        switch(action)
        {
        case 0:
			printf("FastCGI hello!");
			printf("count=%d ",count);
			printf("rmhead:%x",rmhead);
            break;

        case 100:  //delete room
			if((cgi_param("roomname") != NULL) &&
				(sscanf(cgi_param("roomname"), "%s", rmname) == 1) )	
            {
            	//printf("action=%d,roomname=%s  ",action,rmname);
				//printf("rmhead:%x count=%d ",rmhead,count);
               ret = Delroom(rmname);
			  if(ret == -1)
			   {
					pOutput = "0";
			   }
			   else
			   {
					pOutput = "1";
			   }
            }		
			puts(pOutput);
            break;
			
        case 101://add room
			if((cgi_param("roomname") != NULL) &&
					(cgi_param("roomimage") != NULL) &&
					(sscanf(cgi_param("roomname"), "%s", rmname) == 1) &&
					(sscanf(cgi_param("roomimage"), "%s", rmimage) == 1) )
            {

               ret = Addroom(rmname,rmimage);		       			
				
			   if(ret == -1)  // fail to add room
			   {
					pOutput = "0";
			   }
			   else if(ret == 1) //the name room is already exist
			  	{
					pOutput = "2";
			   	}
			   else    //ret == 0  add room sucess
			   {
					pOutput = "1";
			   }
            }
			puts(pOutput);
            break;
			
		case 110:  //read all rooms num
			if((cgi_param("readroom") != NULL) &&
			   (sscanf(cgi_param("readroom"), "%d", &rdroom) == 1))
			{
				if(rdroom == 1)
				{
					nums = Searchroomnums();
					sprintf(data,"number=%d",nums);
					puts(data);	
					nums = 0;
				}
				else
				{
					puts("0");
				}
			}
			break;

		case 111:  //read all room's simple information
			if((cgi_param("readroom") != NULL) &&
				(cgi_param("time") != NULL) &&
			   (sscanf(cgi_param("readroom"), "%d", &rdroom) == 1) &&
			   (sscanf(cgi_param("time"), "%d", &times) == 1))
            {
               if(rdroom == 0)
               {
					struct room *temp;
					temp = Searchroom(NULL,times);
					if(temp != NULL)
					{
						sprintf(data,"roomname=%s&roomimage=%s",
										temp->name,temp->image);
						puts(data);
					}
					else
					{
						puts("0");
					}
			   }
			   else
			   {
			   		puts("0");
				 //printf("rdroom one room's information error");
			   }
            }			
			break;
			
        case 120://change room's information(newrmname and newrmimage)
			if((cgi_param("roomname") != NULL) &&
				(cgi_param("newroomname") != NULL) &&
					(cgi_param("newroomimage") != NULL) &&
					(sscanf(cgi_param("roomname"), "%s", rmname) == 1) &&
					(sscanf(cgi_param("newroomname"), "%s", newname) == 1) &&
					(sscanf(cgi_param("newroomimage"), "%s", newimage) == 1) )
            {
               ret = Changeroominfo(rmname, newname, newimage);		
				
			   if(ret == -1)
			   {
					pOutput = "0"; //fail to change room's information
			   }
			   else if(ret == 1)
			   {
					pOutput = "2"; //the newroomname is already exist
			   }
			   else  //ret == 0
			   {
					pOutput = "1"; //change room's info success
			   }
            }
			puts(pOutput);
			strzero(newname);
			strzero(newimage);
            break;	
			
		case 200:   //delete transmiter
			if((cgi_param("trasname") != NULL) &&
				(cgi_param("roomname") != NULL) &&
				(sscanf(cgi_param("trasname"), "%s", transname) == 1) &&
				(sscanf(cgi_param("roomname"), "%s", rmname) == 1) )
            {
               ret = Deltransmiter(rmname,transname);
	
			   if(ret == -1)
			   {
					pOutput = "0";
			   }
			   else
			   {
					pOutput = "1";
			   }
            }
			puts(pOutput);
            break;
			
		case 201: //add transmiter
			if((cgi_param("roomname") != NULL) &&
				(cgi_param("trasname") != NULL) &&
				(cgi_param("trasimage") != NULL) &&
				(sscanf(cgi_param("roomname"), "%s", rmname) == 1) &&
				(sscanf(cgi_param("trasname"), "%s", transname) == 1) &&
				(sscanf(cgi_param("trasimage"), "%s", transimage) == 1))
            {
              	ret = Addtransmiter(rmname,transname,transimage);
		       		
			   if(ret == -1)
			   {
					pOutput = "0"; //fail to add transmitter
			   }
			   else if(ret == 1)
			   {
					pOutput = "2"; //the name transmitter is already exist
			   }
			   else  //ret == 0
			   {
					pOutput = "1";//add sucess
			   }
            }
			puts(pOutput);	
			break;

		case 202: //save transmitter's channel value
			if((cgi_param("roomname") != NULL) &&
				(cgi_param("trasname") != NULL) &&
				(cgi_param("channel") != NULL) &&
				(cgi_param("hour") != NULL) &&
				(cgi_param("minute") != NULL) &&
				(cgi_param("workday") != NULL) &&
				(cgi_param("state") != NULL) &&
				(sscanf(cgi_param("roomname"), "%s", rmname) == 1) &&
				(sscanf(cgi_param("trasname"), "%s", transname) == 1) &&
				(sscanf(cgi_param("channel"), "%d", &rdchannel) == 1) &&
				(sscanf(cgi_param("hour"), "%s", hour) == 1) &&
				(sscanf(cgi_param("minute"), "%s", min) == 1) &&
				(sscanf(cgi_param("workday"), "%s", workday) == 1) &&
				(sscanf(cgi_param("state"), "%d", &state) == 1))
            {
				struct transvalues temp;
				strzero(&temp);
				
				//init temp;
				strncpy(temp.hour,hour,4);
				strncpy(temp.minute,min,4);
				strncpy(temp.workday,workday,20);
				temp.state = state;
				
              	ret = Savetransvalue(rmname,transname,rdchannel,&temp);
		       		
			   if(ret == -1)
			   {
					pOutput = "0"; //fail to save channel's value
			   }
			   else  //ret == 0
			   {
					pOutput = "1";//save success
			   }
            }
			puts(pOutput);	
			break;
			
		case 210:// 查询单个房间遥控器总数
			if((cgi_param("readtransmitter") != NULL) &&
				(cgi_param("roomname") != NULL) &&
			   (sscanf(cgi_param("readtransmitter"), "%d", &rdtransmiter) == 1) &&
			   (sscanf(cgi_param("roomname"), "%s", rmname) == 1))
			{
				//printf("readroom=%d",rdroom);
				if(rdtransmiter == 1)
				{
					nums = Searchtransnums(rmname);
					sprintf(data,"number=%d",nums);
					puts(data);	
					nums = 0;
				}
				else
				{
					//printf("rdroom all room's num error\n");
					puts("0");
				}
			}
			break;
			
		case 211: //read one room's transmiter's simple information
			if((cgi_param("readtransmitter") != NULL) &&
				(cgi_param("roomname") != NULL) &&
				(cgi_param("time") != NULL) &&
			   (sscanf(cgi_param("readtransmitter"), "%d", &rdtransmiter) == 1) &&
			   (sscanf(cgi_param("roomname"), "%s", rmname) == 1) &&
			   (sscanf(cgi_param("time"), "%d", &times) == 1))
			{
               if(rdtransmiter == 0)
               {
					struct transmiter *temp;	
				
					if((temp = Searchtransmiter(rmname, NULL,times)) != NULL)
					{
						sprintf(data,"trasname=%s&trasimage=%s",
									temp->name,temp->image);
						puts(data);
					}
					else
					{
						puts("0");
					}	
			   }
			   else
			   	{
					puts("0");
			   	}
			}
			break;
			
		case 212: //read one transmiter's all information
			if((cgi_param("readtransmitter") != NULL) &&
				(cgi_param("roomname") != NULL) &&
				(cgi_param("trasname") != NULL) &&
				(cgi_param("channel") != NULL) &&
			   (sscanf(cgi_param("readtransmitter"), "%d", &rdtransmiter) == 1) &&
			   (sscanf(cgi_param("roomname"), "%s", rmname) == 1) &&
			   (sscanf(cgi_param("trasname"), "%s", transname) == 1) &&
			   (sscanf(cgi_param("channel"), "%d", &rdchannel) == 1))
            {
            	//printf("roomname=%s transname=%s channel=%d",
						//rmname,transname,rdchannel);
               if(rdtransmiter == 2)
               {
					struct transvalues *temp;
					temp = Searchtransvalue(rmname,transname,rdchannel);
					if(temp != NULL)
					{
						strzero(transdata);
						sprintf(transdata,"hour=%s&minute=%s&workday=%s&state=%d",
								temp->hour,temp->minute,temp->workday,temp->state);
						puts(transdata);
					}
					else
					{
						puts("3");
					}	
			   }
			   else
			   {
			   		puts("0");
			   }
            }			
			break;
			
        case 220://change transmiter's information(newtransname and newtransimage)
			if((cgi_param("roomname") != NULL) &&
				(cgi_param("trasname") != NULL) &&
				(cgi_param("newtrasname") != NULL) &&
				(cgi_param("newtrasimage") != NULL) &&
				(sscanf(cgi_param("roomname"), "%s", rmname) == 1) &&
				(sscanf(cgi_param("trasname"), "%s", transname) == 1) &&
				(sscanf(cgi_param("newtrasname"), "%s", newname) == 1) &&
				(sscanf(cgi_param("newtrasimage"), "%s", newimage) == 1) )
            {

               ret = Changetransmiterinfo(rmname, transname,newname,newimage);
		       		
				//printf("transname=%s&transimage=%s",newtransname,newtransimage);		
				
			   if(ret == -1)
			   {
					pOutput = "0"; //fail to change information
			   }
			   else if(ret == 1) 
			   {
					pOutput = "2"; //the new name transmitter is already exist
			   }
			   else  //ret == 0
			   {
					pOutput = "1"; //sucess
			   }
            }
			
			puts(pOutput);
			strzero(newname);
			strzero(newimage);
            break;
 
         case 500:  //get system's time
			if((cgi_param("get_time") != NULL) &&
			   (sscanf(cgi_param("get_time"), "%d", &get_time) == 1))
			{
				if(get_time == 1)
				{
					timestr = getTime();
					puts(timestr);
				}
				else
				{
					puts("0");
				}
			}
			break; 
			
        case 600:  //delete scenraios
			if((cgi_param("groupname") != NULL) &&
				(sscanf(cgi_param("groupname"), "%s", scensname) == 1))	
            {
            	//printf("action=%d,roomname=%s  ",action,rmname);
				//printf("rmhead:%x count=%d ",rmhead,count);
              ret = DelScenarios(scensname);
				
			  if(ret == -1)
			   {
					pOutput = "0";
			   }
			   else
			   {
					pOutput = "1";
			   }
            }		
			puts(pOutput);
            break;	
			
        case 601://add scenraios
			if((cgi_param("groupname") != NULL) &&
				(sscanf(cgi_param("groupname"), "%s", scensname) == 1))	 
            {
               ret = AddScenarios(scensname);		       			
				
			   if(ret == -1)  // fail to add scenraios
			   {
					pOutput = "0";
			   }
			   else if(ret == 1) //the name scenraios is already exist
			  	{
					pOutput = "2";
			   	}
			   else    //ret == 0  add scenraios sucess
			   {
					pOutput = "1";
			   }
            }
			puts(pOutput);
            break;

		case 610:  //read all scenraios's num
			if((cgi_param("read_group") != NULL) &&
			   (sscanf(cgi_param("read_group"), "%d", &rdscens) == 1))
			{
				if(rdscens == 0)
				{
					nums = Searchscensnums();
					sprintf(data,"number=%d",nums);
					puts(data);	
					nums = 0;
				}
				else
				{
					puts("0");
				}
			}
			break;	

		case 611:  //read all scensraios's simple information
			if((cgi_param("read_group") != NULL) &&
				(cgi_param("time") != NULL) &&
			   (sscanf(cgi_param("read_group"), "%d", &rdscens) == 1) &&
			   (sscanf(cgi_param("time"), "%d", &times) == 1))
            {
               if(rdscens == 1)
               {
					struct Scenarios *temp;
					temp = Searchscens(NULL,times);
					if(temp != NULL)
					{
						sprintf(data,"groupname=%s",temp->name);
						puts(data);
					}
					else
					{
						puts("0");
					}
			   }
			   else
			   {
			   		puts("0");
				 //printf("rdscens one scenraios's information error");
			   }

            }			
			break;
			
        case 620://change scenraios's information(newscensname)
			if((cgi_param("groupname") != NULL) &&
				(cgi_param("newgroupname") != NULL) &&
					(sscanf(cgi_param("groupname"), "%s", scensname) == 1) &&
					(sscanf(cgi_param("newgroupname"), "%s", newname) == 1))	 
            {
               ret = Changescensinfo(scensname,newname);
		       		
				//printf("rooname=%s&roomimage=%s",newrmname,newrmimage);		
				
			   if(ret == -1)
			   {
					pOutput = "0"; //fail to change scenraios's information
			   }
			   else if(ret == 1)
			   {
					pOutput = "2"; //the newname is already exist
			   }
			   else  //ret == 0
			   {
					pOutput = "1"; //change scenraios's info success
			   }
            }
			puts(pOutput);
			strzero(newname);
            break;

		case 700:   //delete dev in the scenraios
			if((cgi_param("trasname") != NULL) &&
				(cgi_param("roomname") != NULL) &&
				(cgi_param("groupname") != NULL) &&
				(sscanf(cgi_param("trasname"), "%s", transname) == 1) &&
				(sscanf(cgi_param("roomname"), "%s", rmname) == 1) &&
				(sscanf(cgi_param("groupname"), "%s", scensname) == 1))
            {

               ret = Deldevinscens(scensname,rmname,transname);
			  // printf("rooname=%s&roomimage=%s",rmname,rmimage);		
			   if(ret == -1)
			   {
					pOutput = "0";
			   }
			   else
			   {
					pOutput = "1";
			   }
            }
			puts(pOutput);
            break;
			
		case 701: //add dev in the scenraios
			if((cgi_param("trasname") != NULL) &&
				(cgi_param("trasimage") != NULL) &&
				(cgi_param("roomname") != NULL) &&
				(cgi_param("groupname") != NULL) &&
				(sscanf(cgi_param("trasname"), "%s", transname) == 1) &&
				(sscanf(cgi_param("trasimage"), "%s", transimage) == 1) &&
				(sscanf(cgi_param("roomname"), "%s", rmname) == 1) &&
				(sscanf(cgi_param("groupname"), "%s", scensname) == 1))
            {
               // sprintf(sdata,"roomname=%s&trasname=%s",rmname,transname);
              	ret = ADDdevinscens(scensname,rmname,transname,transimage);
		       		
			   if(ret == -1)
			   {
					pOutput = "0"; //fail to add transmitter
			   }
			   else if(ret == 1)
			   {
					pOutput = "2"; //the name transmitter is already exist
			   }
			   else  //ret == 0
			   {
					pOutput = "1";//add sucess
			   }
            }
			puts(pOutput);	
			break;

		case 730:   //search room's devs that have been in the scenraios
			if((cgi_param("roomname") != NULL) &&
				(cgi_param("groupname") != NULL) &&
				(sscanf(cgi_param("roomname"), "%s", rmname) == 1) &&
				(sscanf(cgi_param("groupname"), "%s", scensname) == 1)) 	
            {
				bufstr = Searchdevinscens(scensname,rmname,1);
				puts(bufstr); //bufstr=NULL 表示空字符串
				//printf("rmname=%s groupname=%s",rmname,scensname);
			}
			
			//puts("1");
            break;

		case 731:   //search room's devs that are not in the scenraios
			if((cgi_param("roomname") != NULL) &&
				(cgi_param("groupname") != NULL) &&
				(sscanf(cgi_param("roomname"), "%s", rmname) == 1) &&
				(sscanf(cgi_param("groupname"), "%s", scensname) == 1)) 	
            {
				bufstr = Searchdevinscens(scensname,rmname,0);
				puts(bufstr); //bufstr=NULL 表示空字符串
			}
            break;
		
		case 740:   //search room's devs that are not in the scenraios
			if((cgi_param("groupname") != NULL) &&
				(cgi_param("time") != NULL) &&
				(sscanf(cgi_param("groupname"), "%s", scensname) == 1) &&
				(sscanf(cgi_param("time"), "%d", &exetime) == 1)) 	
            {
				struct Scenarios *temp;
				temp = Searchscens(scensname, 0);
			   if(temp == NULL)
			   {
					pOutput = "0";
			   }
			   else
			   {
			   		temp->exetime = exetime; //保存前端发送的情景组延时执行时间
					pOutput = "1";
			   }
			}
			puts(pOutput);
            break;

       /* case 800://单个设备发送命令
            if((cgi_param("roomname") != NULL) &&
				(cgi_param("trasname") != NULL) &&
                    (cgi_param("cmd") != NULL) &&
                    (sscanf(cgi_param("roomname"), "%s", rmname) == 1) &&
                    (sscanf(cgi_param("trasname"), "%s", transname) == 1) &&
                    (sscanf(cgi_param("cmd"), "%d", &cmd) == 1))
            {
            	struct room *rmtemp;
				struct transmiter * transtemp;
				//get rmID and transID
				rmtemp = Searchroom(rmname);
				transtemp = Searchtransmiter(rmname,transname);
				rmID = rmtemp->ID;
				transID = transtemp->ID;
				printf("rmid:%d,transId:%d\n",rmID,transID);
                pOutput = fcgi_middle.SendCmd(rmID,transID,cmd);
				puts(pOutput);
            }
            break;*/

        default:
            break;
        }

        cgi_end();
    }

	free(rmhead);
	free(scenshead);
    return 0;
}
コード例 #15
0
int
main(int argc, char **argv)
{
	struct	dialup	*dial;
	struct	dialup	dent;
	struct	stat	sb;
	FILE	*fp;
	char	*sh = 0;
	char	*cp;
	char	pass[BUFSIZ];
	int	fd;
	int	found = 0;
	int	opt;

	Prog = Basename(argv[0]);

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

	openlog(Prog, LOG_PID|LOG_CONS|LOG_NOWAIT, LOG_AUTH);

	while ((opt = getopt (argc, argv, "a:d:")) != EOF) {
		switch (opt) {
			case 'a':
				aflg++;
				sh = optarg;
				break;
			case 'd':
				dflg++;
				sh = optarg;
				break;
			default:
				usage ();
		}
	}
	if (! aflg && ! dflg)
		aflg++;

	if (! sh) {
		if (optind >= argc)
			usage ();
		else
			sh = argv[optind];
	}
	if (aflg + dflg != 1)
		usage ();

	/*
	 * Add a new shell to the password file, or update an existing
	 * entry.  Begin by getting an encrypted password for this
	 * shell.
	 */

	if (aflg) {
		int	tries = 3;

		dent.du_shell = sh;
		dent.du_passwd = "";  /* XXX warning: const */

again:
		if (! (cp = getpass(_("Shell password: "******"re-enter Shell password: "******"%s: Passwords do not match, try again.\n"),
				Prog);

			if (--tries)
				goto again;

			exit(1);
		}
		strzero(cp);
		dent.du_passwd = pw_encrypt(pass, crypt_make_salt());
		strzero(pass);
	}

	/*
	 * Create the temporary file for the updated dialup password
	 * information to be placed into.  Turn it into a (FILE *)
	 * for use by putduent().
	 */

	if ((fd = open (DTMP, O_CREAT|O_EXCL|O_RDWR, 0600)) < 0) {
		snprintf(pass, sizeof pass, _("%s: can't create %s"), Prog, DTMP);
		perror (pass);
		exit (1);
	}
	if (! (fp = fdopen (fd, "r+"))) {
		snprintf(pass, sizeof pass, _("%s: can't open %s"), Prog, DTMP);
		perror (pass);
		unlink (DTMP);
		exit (1);
	}

	/*
	 * Scan the dialup password file for the named entry,
	 * copying out other entries along the way.  Copying
	 * stops when a match is found or the file runs out.
	 */

	while ((dial = getduent ())) {
		if (strcmp (dial->du_shell, sh) == 0) {
			found = 1;
			break;
		}
		if (putduent (dial, fp))
			goto failure;
	}

	/*
	 * To delete the entry, just don't copy it.  To update
	 * the entry, output the modified version - works with
	 * new entries as well.
	 */

	if (dflg && ! found) {
		fprintf(stderr, _("%s: Shell %s not found.\n"), Prog, sh);
		goto failure;
	}
	if (aflg)
		if (putduent (&dent, fp))
			goto failure;

	/*
	 * Now copy out the remaining entries.  Flush and close the
	 * new file before doing anything nasty to the existing
	 * file.
	 */


	while ((dial = getduent ()))
		if (putduent (dial, fp))
			goto failure;

	if (fflush (fp))
		goto failure;

	fclose (fp);

	/*
	 * If the original file did not exist, we must create a new
	 * file with owner "root" and mode 400.  Otherwise we copy
	 * the modes from the existing file to the new file.
	 *
	 * After this is done the new file will replace the old file.
	 */

	pwd_init();

	if (! stat (DIALPWD, &sb)) {
		chown (DTMP, sb.st_uid, sb.st_gid);
		chmod (DTMP, sb.st_mode);
		unlink (DIALPWD);
	} else {
		chown (DTMP, 0, 0);
		chmod (DTMP, 0400);
	}
	if (! link (DTMP, DIALPWD))
		unlink (DTMP);

	if (aflg && ! found)
		SYSLOG((LOG_INFO, DIALADD, sh));
	else if (aflg && found)
		SYSLOG((LOG_INFO, DIALCHG, sh));
	else if (dflg)
		SYSLOG((LOG_INFO, DIALREM, sh));

	closelog();
	sync ();
	exit (0);

failure:
	unlink (DTMP);
	closelog();
	exit (1);
}