Пример #1
0
main()
{int a=0,ch=0;
printf("\n");
line_me(80,default_1);
printf("\n\t\t\tWell come to 10-bit enscryption\n");
line_me(80,default_1);

for(;a<1;){
ch=check_passwd();
if(ch!=0){
printf("\n\n\t\t\t1.ENCODE WORD");
printf("\n\t\t\t2.DECODE WORD");
printf("\n\t\t\t3.CHANGE PASSWORD");
printf("\n\n\t\t\tENTER CHOICE           : ");
scanf("%d",&ch);
switch(ch){
case 1:{
a=goto_encode();break;}
case 2:{
a=goto_decode();break;}
case 3:{
a=ch_passwd();break;}
default:{
printf("\n\t\t\t   PROCESS TERMINATED :-)");}}}
else
printf("\n\n\t\t\tPASSWORD INCORRECT TRY AGAIN\n");}
printf("\n");
line_me(80,default_1);
printf("\n\t\t\t\t THANK YOU \n");
line_me(80,default_1);}
Пример #2
0
static int check_client_and_password(struct conf **globalcs,
	const char *password, struct conf **cconfs)
{
	const char *cname;
	int password_check;
	// Cannot load it until here, because we need to have the name of the
	// client.
	if(conf_load_clientconfdir(globalcs, cconfs)) return -1;

	cname=get_string(cconfs[OPT_CNAME]);
	password_check=get_int(cconfs[OPT_PASSWORD_CHECK]);

	if(!get_string(cconfs[OPT_SSL_PEER_CN]))
	{
		logp("ssl_peer_cn unset");
		if(cname)
		{
			logp("Falling back to using '%s'\n", cname);
			if(set_string(cconfs[OPT_SSL_PEER_CN], cname))
				return -1;
		}
	}

	cname=get_string(cconfs[OPT_CNAME]);

	if(password_check)
	{
		const char *conf_passwd=get_string(cconfs[OPT_PASSWD]);
		const char *conf_password=get_string(cconfs[OPT_PASSWORD]);
		if(!conf_password && !conf_passwd)
		{
			logp("password rejected for client %s\n", cname);
			return -1;
		}
		// check against plain text
		if(conf_password && strcmp(conf_password, password))
		{
			logp("password rejected for client %s\n", cname);
			return -1;
		}
		// check against encypted passwd
		if(conf_passwd && !check_passwd(conf_passwd, password))
		{
			logp("password rejected for client %s\n", cname);
			return -1;
		}
	}

	if(!get_strlist(cconfs[OPT_KEEP]))
	{
		logp("%s: you cannot set the keep value for a client to 0!\n",
			cname);
		return -1;
	}
	return 0;
}
Пример #3
0
static int check_client_and_password(struct config *conf, const char *client, const char *password, struct config *cconf)
{
	char cpath[256]="";

	// Some client settings can be globally set in the server config and
	// overridden in the client specific config.
	// Cannot load it until here, because we need to have the name of the
	// client.
	init_config(cconf);
	snprintf(cpath, sizeof(cpath), "%s/%s", conf->clientconfdir, client);
	if(set_client_global_config(conf, cconf, client)
	  || load_config(cpath, cconf, FALSE))
		return -1;
	if(!cconf->ssl_peer_cn)
	{
		logp("ssl_peer_cn unset");
		if(client)
		{
			logp("Falling back to using '%s'\n", client);
			if(!(cconf->ssl_peer_cn=strdup(client)))
			{
				logp("out of memory\n");
				return -1;
			}
		}
	}

	if(!cconf->password && !cconf->passwd)
	{
		logp("password rejected for client %s\n", client);
		return -1;
	}
	// check against plain text
	if(cconf->password && strcmp(cconf->password, password))
	{
		logp("password rejected for client %s\n", client);
		return -1;
	}
	// check against encypted passwd
	if(cconf->passwd && !check_passwd(cconf->passwd, password))
	{
		logp("password rejected for client %s\n", client);
		return -1;
	}

	if(!cconf->keep)
	{
		logp("%s: you cannot set the keep value for a client to 0!\n",
				client);
		return -1;
	}
	return 0;
}
Пример #4
0
static void ccma_dialog_response_cb(GtkDialog * dialog, gint res,
				    gpointer data)
{
//    return ;//

    //GtkWidget*entry=GTK_ENTRY(data);    
    CCManagerApplet *applet = CC_MANAGERAPPLET(data);

    GList *children =
	gtk_container_get_children(GTK_CONTAINER
				   (gtk_dialog_get_content_area(dialog)));
    GtkWidget*box=children->data;//box
    GList*bc=gtk_container_get_children(GTK_CONTAINER(box));
    GtkWidget*entry=GTK_WIDGET(g_list_next(bc)->data);


    /*FIXME get the correct entry widget */
//    GtkWidget *entry = GTK_WIDGET(g_list_next(children)->data);
//    GtWidget* entry=get_child_widget_by_type(dialog,GTK_TYPE_ENTRY);
//    g_list_free(children);


    gboolean passok;

    switch (res) {

    case GTK_RESPONSE_OK:
	passok = check_passwd(gtk_entry_get_text(GTK_ENTRY(entry)));
	if (passok) {
	    //OK
    GtkWidget*parent=GTK_WIDGET(gtk_builder_get_object(GTK_BUILDER(applet->loging_win->builder),"window"));
	applet->manager_panel=cc_mpanel_new(GTK_WINDOW(parent));
    cc_mpanel_setup(applet->manager_panel);
	    //
	    //
	    g_message("Authentication Successfilly!\n");
	    ccma_confirm_dialog_destroy(applet);

	} else {
	    gtk_entry_set_text(GTK_ENTRY(entry), "");
	}

	break;
    case GTK_RESPONSE_CANCEL:
	ccma_confirm_dialog_destroy(applet);
	break;
    default:
	break;

    }

}
Пример #5
0
void get_new_pass(string pass, object ob)
{
  if (!check_passwd (pass)) {
    write ("密码必须至少含有一个普通英文字母跟一个非普通英文字母.\n");
    write("\n请再输入一次新的密码:");
    input_to("get_new_pass", 1, ob );
  }
  else {

    write("\n请再输入一次刚刚的密码,以资确认:");
    input_to("confirm_new_pass", 1, ob, crypt(pass,0));
  }
}
Пример #6
0
static int check_client_and_password(struct conf *conf, const char *password, struct conf *cconf)
{
	// Cannot load it until here, because we need to have the name of the
	// client.
	if(conf_load_client(conf, cconf)) return -1;

	if(!cconf->ssl_peer_cn)
	{
		logp("ssl_peer_cn unset");
		if(cconf->cname)
		{
			logp("Falling back to using '%s'\n", cconf->cname);
			if(!(cconf->ssl_peer_cn
				=strdup_w(cconf->cname, __func__)))
					return -1;
		}
	}

	if(cconf->password_check)
	{
		if(!cconf->password && !cconf->passwd)
		{
			logp("password rejected for client %s\n", cconf->cname);
			return -1;
		}
		// check against plain text
		if(cconf->password && strcmp(cconf->password, password))
		{
			logp("password rejected for client %s\n", cconf->cname);
			return -1;
		}
		// check against encypted passwd
		if(cconf->passwd && !check_passwd(cconf->passwd, password))
		{
			logp("password rejected for client %s\n", cconf->cname);
			return -1;
		}
	}

	if(!cconf->keep)
	{
		logp("%s: you cannot set the keep value for a client to 0!\n",
			cconf->cname);
		return -1;
	}
	return 0;
}
Пример #7
0
int 
command(const char *buf, struct client *cl, char * cmd)
{
	char user[WORD];
	char pass[WORD];
	char room[WORD];
	int ret = 0;

	matche(buf, "%s", cmd);
	log_debug("CMD is: %s\n",cmd);
	
	if (strcmp(cmd,"/connect") == 0) {
		matche(buf, "%s %s %s %s", cmd, user, pass, room);
		log_debug("USER %s is trying to %s: with pass %s\n", 
			user, cmd, pass);
		ret = check_passwd(user, pass);
		strncpy(cl->cl_name, user, sizeof(user));
		strncpy(cl->cl_room, room, sizeof(room));
		return (ret);
	}

	if (strcmp(cmd,"/quit") == 0) {
		log_debug("USER is trying to %s", cmd);
		return (CLOSE_CONNECTION);
	}

	if (strcmp(cmd,"/secret") == 0) {
		matche(buf, "%s %s", cmd, user);
		log_debug("USER %s is trying to say a secret to %s\n", 
			cl->cl_name, user);
		ret = private_message(buf);
		strncpy(cmd, user, sizeof(user));
		return (ret);
	}

	if (strcmp(cmd,"/names") == 0) {
		log_debug("USER wants to know %s", cmd);
		return (1);
	}

	return (ret);
}
Пример #8
0
static int do_login(int argc, char *argv[])
{
    unsigned char passwd[PASSWD_MAX_LENGTH];
    int passwd_len, opt;
    int timeout = login_timeout;
    char *timeout_cmd = "boot";

    console_allow_input(true);
    if (!is_passwd_enable()) {
        puts("login: password not set\n");
        return 0;
    }

    while((opt = getopt(argc, argv, "t:")) > 0) {
        switch(opt) {
        case 't':
            timeout = simple_strtoul(optarg, NULL, 10);
            break;
        }
    }

    if (optind != argc)
        timeout_cmd = argv[optind];

    do {
        puts("Password: ");
        passwd_len = password(passwd, PASSWD_MAX_LENGTH, LOGIN_MODE, timeout);

        if (passwd_len < 0) {
            console_allow_input(false);
            run_command(timeout_cmd);
        }

        if (check_passwd(passwd, passwd_len) == 1)
            return 0;
    } while(1);

    return 0;
}
Пример #9
0
static void ccma_dialog_entry_enter_cb(GtkWidget * widget, gpointer data)
{

//    gtk_window_set_modal(GTK_WINDOW(widget),TRUE);
    CCManagerApplet *applet = CC_MANAGERAPPLET(data);
    GtkWidget *entry = widget;	//GTK_WIDGET(data);
    if (check_passwd(gtk_entry_get_text(GTK_ENTRY(entry)))) {
	ccma_confirm_dialog_destroy(applet);
	g_message("Authentication Successfilly!\n");
	//OK
//manager_panel();
	//spice_page(NULL);

    GtkWidget*parent=GTK_WIDGET(gtk_builder_get_object(GTK_BUILDER(applet->loging_win->builder),"window"));
	applet->manager_panel=CC_MPANEL(cc_mpanel_new(GTK_WINDOW(parent)));
    cc_mpanel_setup(applet->manager_panel);


    } else {
	gtk_entry_set_text(GTK_ENTRY(widget), "");

    }

}
Пример #10
0
/*
 * upap_rauth - Receive Authenticate.
 */
static void
upap_rauthreq(upap_state *u, u_char *inp, int id, int len)
{
  u_char ruserlen, rpasswdlen;
  char *ruser, *rpasswd;
  int retcode;
  char *msg;
  int msglen;

  UPAPDEBUG((LOG_INFO, "pap_rauth: Rcvd id %d.\n", id));

  if (u->us_serverstate < UPAPSS_LISTEN) {
    return;
  }

  /*
   * If we receive a duplicate authenticate-request, we are
   * supposed to return the same status as for the first request.
   */
  if (u->us_serverstate == UPAPSS_OPEN) {
    upap_sresp(u, UPAP_AUTHACK, id, "", 0);  /* return auth-ack */
    return;
  }
  if (u->us_serverstate == UPAPSS_BADAUTH) {
    upap_sresp(u, UPAP_AUTHNAK, id, "", 0);  /* return auth-nak */
    return;
  }

  /*
   * Parse user/passwd.
   */
  if (len < sizeof (u_char)) {
    UPAPDEBUG((LOG_INFO, "pap_rauth: rcvd short packet.\n"));
    return;
  }
  GETCHAR(ruserlen, inp);
  len -= sizeof (u_char) + ruserlen + sizeof (u_char);
  if (len < 0) {
    UPAPDEBUG((LOG_INFO, "pap_rauth: rcvd short packet.\n"));
    return;
  }
  ruser = (char *) inp;
  INCPTR(ruserlen, inp);
  GETCHAR(rpasswdlen, inp);
  if (len < rpasswdlen) {
    UPAPDEBUG((LOG_INFO, "pap_rauth: rcvd short packet.\n"));
    return;
  }
  rpasswd = (char *) inp;

  /*
   * Check the username and password given.
   */
  retcode = check_passwd(u->us_unit, ruser, ruserlen, rpasswd, rpasswdlen, &msg, &msglen);
  BZERO(rpasswd, rpasswdlen);

  upap_sresp(u, retcode, id, msg, msglen);

  if (retcode == UPAP_AUTHACK) {
    u->us_serverstate = UPAPSS_OPEN;
    auth_peer_success(u->us_unit, PPP_PAP, ruser, ruserlen);
  } else {
    u->us_serverstate = UPAPSS_BADAUTH;
    auth_peer_fail(u->us_unit, PPP_PAP);
  }

  if (u->us_reqtimeout > 0) {
    UNTIMEOUT(upap_reqtimeout, u);
  }
}
Пример #11
0
int
main(int argc, char *argv[]) {
    struct passwd *pe;
    uid_t gotuid = getuid();
    char *pwdstr = NULL, *cryptstr, *oldstr;
    char pwdstr1[10];
    char *user;
    time_t tm;
    char salt[2];
    int force_passwd = 0;
    int silent = 0;
    int c;
    int opt_index;
    int fullname = 0, shell = 0;
    static const struct option long_options[] =
      {
	{"fullname", no_argument, 0, 'f'},
	{"shell", no_argument, 0, 's'},
	{"force", no_argument, 0, 'o'},
	{"quiet", no_argument, 0, 'q'},
	{"silent", no_argument, 0, 'q'},
	{"version", no_argument, 0, 'v'},
	{0, 0, 0, 0}
	};

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

    optind = 0;
    while ((c = getopt_long(argc, argv, "foqsvV",
			    long_options, &opt_index)) != -1) {
	switch (c) {
	case 'f':
	    fullname = 1;
	    break;
	case 's':
	    shell = 1;
	    break;
	case 'o':
	    force_passwd = 1;
	    break;
	case 'q':
	    silent = 1;
	    break;
	case 'V':
	case 'v':
	    printf("%s\n", util_linux_version);
	    exit(0);
	default:
	    fprintf(stderr, _("Usage: passwd [-foqsvV] [user [password]]\n"));
	    exit(1);
	} /* switch (c) */
    } /* while */

    if (fullname || shell) {
	char *args[100];
	int i, j, errsv;

	setuid(getuid()); /* drop special privs. */
	if (fullname)
	  args[0] = _PATH_CHFN;
	else
	  args[0] = _PATH_CHSH;

	for (i = optind, j = 1; (i < argc) && (j < 99); i++, j++)
	  args[j] = argv[i];

	args[j] = NULL;
	execv(args[0], args);
	errsv = errno;
	fprintf(stderr, _("Can't exec %s: %s\n"), args[0], strerror(errsv));
	exit(1);
    }
    
    switch (argc - optind) {
    case 0:
	/* Why use getlogin()? Some systems allow having several
	   usernames with the same uid, especially several root accounts.
	   One changes the password for the username, not the uid. */
	if ( !(user = getlogin()) || !*user ) {
	    if ( !(pe = getpwuid( getuid() )) ) {
		pexit(_("Cannot find login name"));
	    } else
		user = pe->pw_name;
	}
	break;
    case 1:
	if(gotuid) {
	    printf(_("Only root can change the password for others.\n"));
	    exit (1);
	} else
	    user = argv[optind];
	break;
    case 2:
	if(gotuid) {
	    printf(_("Only root can change the password for others.\n"));
	    exit(1);
	} else {
	    user = argv[optind];
	    pwdstr = argv[optind+1];
	}
	break;
    default:
	printf(_("Too many arguments.\n"));
	exit (1);
    } /* switch */

    if(!(pe = getpwnam(user))) {
	pexit(_("Can't find username anywhere. Is `%s' really a user?"), user);
    }
    
    if (!(is_local(user))) {
	puts(_("Sorry, I can only change local passwords. Use yppasswd instead."));
	exit(1);
    }
    
    /* if somebody got into changing utmp... */
    if(gotuid && gotuid != pe->pw_uid) {
	puts(_("UID and username does not match, imposter!"));
	exit(1);
    }
    
    if ( !silent )
	printf( _("Changing password for %s\n"), user );
    
    if ( (gotuid && pe->pw_passwd && pe->pw_passwd[0]) 
	|| (!gotuid && !strcmp(user,"root")) ) {
	oldstr = getpass(_("Enter old password: "******"Illegal password, imposter."));
	    exit(1);
	}
    }

    if ( pwdstr ) {   /* already set on command line */
	if ( !force_passwd && !check_passwd(pwdstr, pe->pw_passwd, user, pe->pw_gecos) )
	    exit (1);
    } else {
	/* password not set on command line by root, ask for it ... */
	
      redo_it:
	pwdstr = getpass(_("Enter new password: "******"Password not changed."));
	    exit(1);
	}

	if ( (gotuid || (!gotuid && !force_passwd))
	     && !check_passwd(pwdstr, pe->pw_passwd, user, pe->pw_gecos) ) 
	    goto redo_it;
	
	xstrncpy(pwdstr1, pwdstr, sizeof(pwdstr1));
	pwdstr = getpass(_("Re-type new password: "******"You misspelled it. Password not changed."));
	    exit(1);
	}
    } /* pwdstr i.e. password set on command line */
    
    time(&tm); tm ^= getpid();
    salt[0] = bin_to_ascii(tm & 0x3f);
    salt[1] = bin_to_ascii((tm >> 6) & 0x3f);
    cryptstr = crypt(pwdstr, salt);

    if (pwdstr[0] == 0) cryptstr = "";

#ifdef LOGALL
    openlog("passwd", 0, LOG_AUTH);
    if (gotuid)
	syslog(LOG_NOTICE,_("password changed, user %s"),user);
    else {
	if ( !strcmp(user, "root") )
	    syslog(LOG_WARNING,_("ROOT PASSWORD CHANGED"));
	else
	    syslog(LOG_NOTICE,_("password changed by root, user %s"),user);
    }
    closelog();
#endif /* LOGALL */

    pe->pw_passwd = cryptstr;
#ifdef DEBUG
    printf (_("calling setpwnam to set password.\n"));
#else
    if (setpwnam( pe ) < 0) {
       perror( "setpwnam" );
       printf( _("Password *NOT* changed.  Try again later.\n" ));
       exit( 1 );
    }
#endif

    if ( !silent )
	printf(_("Password changed.\n"));	
    exit(0);
}
int send_creds(int type, char *msg) {

	int ret = -ENOMEM;
	int match = 3;
	unsigned char *user = (unsigned char*)calloc(1, sizeof(char) *
			MAX_MSG_LENGTH);
	if (!user)
		goto no_mem_user;

	unsigned char *passwd = (unsigned char*)calloc(1, sizeof(char) *
			MAX_MSG_LENGTH);
	if (!passwd)
		goto no_mem_passwd;
	
	unsigned char *v_passwd = (unsigned char*)calloc(1, sizeof(char) *
			MAX_MSG_LENGTH);
	if (!v_passwd)
		goto no_mem_v_passwd;

	struct anspass_packet *pkt = (struct anspass_packet*)calloc(1,
			sizeof(struct anspass_packet));
	if (!pkt)
		goto no_pkt;

	/* Get the username */
	print_user_prompt(msg);
	get_secret(user, MAX_MSG_LENGTH, 1);
	printf("\n");

	ret = -EINVAL;
	do
	{
		if (match != MAX_PASSWD_ATTEMPT)
			printf("Incorrect password. (%d more attempts)\n",
					match);

		/* Get the password */
		printf("Please enter a password for %s\n", msg);
		printf("(max of %d characters)\n", MAX_MSG_LENGTH-1);
		printf("Password: "******"\n");
		printf("\n");

		printf("Please re-enter a password for %s\n", msg);
		printf("Verify password:"******"\n");
		match--;

	} while(match && (ret = check_passwd(passwd, v_passwd)) );

	if (ret != 0)
	{
		printf("Incorrect password.  Maximum attempts reached\n");
		goto passwd_fail;
	}

	pkt->socket = info.socket;
	pkt->type = type;
	memcpy(pkt->token, info.token, TOKEN_LEN);
	memcpy(pkt->msg, msg, strlen(msg));
	memcpy(pkt->user, user, strlen((char*)user));
	memcpy(pkt->passwd, passwd, strlen((char*)passwd));

	printf("Adding %s\n", msg);
	ret = put_data(pkt);
	if (ret < 0)
		goto send_fail;

	ret = wait_ack_reply();
	if (ret) {
		printf("Failed: %d\n", ret);
		goto failed;
	}

	printf("Success\n");
	ret = 0;

failed:
	/* Fall-through expected */
send_fail:
	/* Fall-through expected */
passwd_fail:
	free(pkt);
no_pkt:
	free(v_passwd);
no_mem_v_passwd:
	free(passwd);
no_mem_passwd:
	free(user);
no_mem_user:
	return ret;
}
Пример #13
0
void server_check(int conn_fd)
{
	char buf[32];
	char name[32];
	char passwd[32];
	char pathname[SIZE] = {"/home/qiong/userinfo/"};
	int  ret;
	int  flag;
	int  fd;
	char log[SIZE];
	int i;

	send_data(conn_fd, "b\n");
	sleep(1);
	while(1)
	{
		my_recv(conn_fd, buf, sizeof(buf));
		if (buf[0] == 'u')
		{
			send_data(conn_fd, "b\n");
			sleep(1);
			ret = recv(conn_fd, buf, sizeof(buf), 0);
			buf[ret-1] = '\0';
			strcpy(name, buf);
			flag = find_name(buf);
			if (flag == 0)
			{
				send_data(conn_fd, "y\n");
				sleep(1);
			}
			else
			{
				send_data(conn_fd, "n\n");
				sleep(1);
				continue;
			}
			my_recv(conn_fd, buf, sizeof(buf));
			send_data(conn_fd, "b\n");
			sleep(1);
			ret = recv(conn_fd, buf, sizeof(buf), 0);
			buf[ret-1] = '\0';
			strcpy(passwd, buf);
			memset(passwd, '\0', sizeof(passwd));
			flag = check_passwd(name, passwd);
			if (flag == 0)
			{
				send_data(conn_fd, "y\n");
				sleep(1);
				strcat(ip_name, "  用户名:");
				strcat(ip_name, name);
				strcpy(name, "验证成功");
				sys_log(name);
				deal(conn_fd);
			}
			else
			{
				send_data(conn_fd, "n\n");
				sleep(1);
				continue;
			}
		}
	}
}
static int android_unlock_primary_user(char *password)
{
    char storage_path[MAX_PATH_LENGTH];
    char private_dir_path[MAX_PATH_LENGTH];
    struct crypto_header header;
    int ret;

    ret = read_crypto_header(&header, CRYPTO_HEADER_COPY);
    if (ret < 0)
        return ret;

    ret = check_passwd(&header, password);
    if (ret < 0)
        return ret;

    property_set("vold.decrypt", "trigger_reset_main");
    sleep(2);
    umount("/data", MNT_FORCE);

    memset(storage_path, 0, sizeof(storage_path));
    sprintf(storage_path, "%s%d", ANDROID_USER_DATA_PATH, PRIMARY_USER);

    ret = get_private_storage_path(private_dir_path, storage_path);
    if (ret < 0) {
        LOGE("Error getting private storage for %s", storage_path);
        return ret;
    }

    ret = access(private_dir_path, F_OK);
    if (ret < 0) {
        LOGE("Private storage %s does not exist", private_dir_path);
        return ret;
    }

    if (check_fs_mounted(private_dir_path) == 1) {
        LOGE("ecryptfs is already mounted on %s", storage_path);
        return 0;
    }

    ret = remove_dir_content(storage_path);
    if (ret < 0) {
        LOGE("Error removing data from %s directory", storage_path);
        return ret;
    }

    ret = EFS_unlock(storage_path, password);
    if (ret < 0) {
        LOGE("Error unlocking efs storage %s", storage_path);
        return ret;
    }

    memset(storage_path, 0, sizeof(storage_path));
    sprintf(storage_path, "%s%d", ANDROID_VIRTUAL_SDCARD_PATH,
        PRIMARY_USER);

    if (check_fs_mounted(storage_path) == 1) {
        LOGE("ecryptfs is already mounted on %s", storage_path);
        return 0;
    }

    ret = remove_dir_content(storage_path);
    if (ret < 0) {
        LOGE("Error removing data from %s directory", storage_path);
        return ret;
    }

    ret = EFS_unlock(storage_path, password);
    if (ret < 0) {
        LOGE("Error unlocking efs storage %s", storage_path);
        return ret;
    }

    property_set("crypto.primary_user", "decrypted");
    sleep(2);
    property_set("vold.decrypt", "trigger_restart_framework");

    return 0;
}
Пример #15
0
SANE_Status
sanei_authorize (const char *resource,
		 const char *backend, SANE_Auth_Callback authorize)
{
  FILE *passwd_file;
  char passwd_filename[256];
  char line[1024], *linep;
  SANE_Bool entry_found = SANE_FALSE;
  char md5resource[256];
  char username[SANE_MAX_USERNAME_LEN];
  char password[SANE_MAX_PASSWORD_LEN];

  INIT_RND ();

  DBG (4, "called for ``%s'' by %s\n", resource, backend);

  if (strlen (resource) > 127)
    DBG (1, "resource is longer than 127 chars...\n");

  sprintf (passwd_filename, "%s.users", backend);

  passwd_file = sanei_config_open (passwd_filename);

  if (passwd_file == NULL)
    {
      DBG (3, "could not open ``%s''...\n", passwd_filename);
      return SANE_STATUS_GOOD;
    }

  while (sanei_config_read (line, 1024, passwd_file))
    {

      if ((strlen (line) > 0) && (line[strlen (line) - 1] == '\n'))
	line[strlen (line) - 1] = '\n';

      if ((strlen (line) > 0) && (line[strlen (line) - 1] == '\r'))
	line[strlen (line) - 1] = '\r';

      if (strchr (line, ':') != NULL)
	{
	  if (strchr (strchr (line, ':') + 1, ':') != NULL)
	    {

	      if (strcmp (strchr (strchr (line, ':') + 1, ':') + 1, resource)
		  == 0)

		{



		  entry_found = SANE_TRUE;
		  break;

		}
	    }

	}

    }

  if (entry_found == SANE_FALSE)
    {

      fclose (passwd_file);

      DBG (3, "could not find resource ``%s''...\n", resource);
      return SANE_STATUS_GOOD;

    }

  if (authorize == NULL)
    {
      DBG (2, "no authorization callback supplied by frontend\n");
      return SANE_STATUS_ACCESS_DENIED;
    }

  sprintf (md5resource, "%.128s$MD5$%x%lx%08lx",
	   resource, getpid (), time (NULL), randombits ());

  memset (username, 0, SANE_MAX_USERNAME_LEN);
  memset (password, 0, SANE_MAX_PASSWORD_LEN);

  (*authorize) (md5resource, username, password);


  fseek (passwd_file, 0L, SEEK_SET);

  while (sanei_config_read (line, 1024, passwd_file))
    {

      if ((strlen (line) > 0) && (line[strlen (line) - 1] == '\n'))
	line[strlen (line) - 1] = '\n';

      if ((strlen (line) > 0) && (line[strlen (line) - 1] == '\r'))
	line[strlen (line) - 1] = '\r';


      if ((strncmp (line, username, strlen (username)) == 0) &&
	  (((strchr (line, ':')) - line) == (signed) strlen (username)))
	{

	  linep = strchr (line, ':') + 1;

	  if ((strchr (linep, ':') != NULL)
	      && (strcmp (strchr (linep, ':') + 1, resource) == 0))
	    {

	      *(strchr (linep, ':')) = 0;


	      if (check_passwd (password, linep, md5resource, username))
		{
		  fclose (passwd_file);
		  DBG (2, "authorization succeeded\n");
		  return SANE_STATUS_GOOD;
		}
	    }
	}


    }

  fclose (passwd_file);

  DBG (1, "authorization failed\n");

  return SANE_STATUS_ACCESS_DENIED;
}