本文整理汇总了C++中crypt函数的典型用法代码示例。如果您正苦于以下问题:C++ crypt函数的具体用法?C++ crypt怎么用?C++ crypt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了crypt函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: pw_unix_check
//.........这里部分代码省略.........
int i;
for (i = 0; i < RCP_CRYPT_SALT_LEN; i++)
solt[i] = admin->password[i];
solt[RCP_CRYPT_SALT_LEN] = '\0';
char *cp = rcpCrypt(password, solt);
if (strcmp(admin->password + RCP_CRYPT_SALT_LEN + 1, cp + RCP_CRYPT_SALT_LEN + 4) != 0)
return;
}
// user/password combination is ok
// for the login into /home/rcp, with rcp as the real user
account = "rcp";
//RCP
const char *cpwd = NULL;
struct passwd pw, *pw_;
#ifdef USE_SHADOW
struct spwd *spw;
#endif
char *dir = NULL;
(void) sa;
(void) peer;
result->auth_ok = 0;
if ((pw_ = getpwnam(account)) == NULL) {
/*RCP*/dbgmsg("failed getpwnam");
return;
}
pw = *pw_;
result->auth_ok--;
#ifdef HAVE_SETUSERSHELL
if (pw.pw_shell == NULL) {
/*RCP*/dbgmsg("failed pw_shell");
return;
}
#if 0 // RCP disabled
if (strcasecmp(pw.pw_shell, FAKE_SHELL) != 0) {
const char *shell;
setusershell();
while ((shell = (char *) getusershell()) != NULL &&
strcmp(pw.pw_shell, shell) != 0);
endusershell();
if (shell == NULL) {
return;
}
}
#endif //RCP
#endif
if ((dir = strdup(pw.pw_dir)) == NULL) {
/*RCP*/dbgmsg("failed strdup");
return;
}
#if 0 //disabeld for RCP
#ifdef USE_SHADOW
if ((((pw.pw_passwd)[0] == 'x' && (pw.pw_passwd)[1] == 0) ||
((pw.pw_passwd)[0] == '#' && (pw.pw_passwd)[1] == '#' &&
strcmp(pw.pw_passwd + 2, account) == 0)) &&
(spw = getspnam(account)) != NULL && spw->sp_pwdp != NULL) {
cpwd = spw->sp_pwdp[0] == '@' ? NULL : spw->sp_pwdp;
if (spw->sp_expire > 0 || spw->sp_max > 0) {
long today = time(NULL) / (24L * 60L * 60L);
if (spw->sp_expire > 0 && spw->sp_expire < today) {
goto bye; /* account expired */
}
if (spw->sp_max > 0 && spw->sp_lstchg > 0 &&
(spw->sp_lstchg + spw->sp_max < today)) {
goto bye; /* password expired */
}
}
} else
#endif
{
cpwd = pw.pw_passwd;
}
{
const char *crypted;
if (cpwd == NULL ||
(crypted = (const char *) crypt(password, cpwd)) == NULL ||
strcmp(cpwd, crypted) != 0) {
goto bye;
}
}
#endif //RCP
result->uid = pw.pw_uid;
result->gid = pw.pw_gid;
result->dir = dir;
result->slow_tilde_expansion = 0;
result->auth_ok = -result->auth_ok;
/*RCP*/dbgmsg("RCP admin check ok");
return;
bye:
free(dir);
/*RCP*/dbgmsg("failed RCP admin check");
}
开发者ID:a5216652166,项目名称:rcp100,代码行数:101,代码来源:log_unix.c
示例2: main
//.........这里部分代码省略.........
unsigned int c = strlen(salt_arg);
if (c < salt_minlen || c > salt_maxlen) {
if (salt_minlen == salt_maxlen)
fprintf(stderr, ngettext(
"Wrong salt length: %d byte when %d expected.\n",
"Wrong salt length: %d bytes when %d expected.\n", c),
c, salt_maxlen);
else
fprintf(stderr, ngettext(
"Wrong salt length: %d byte when %d <= n <= %d"
" expected.\n",
"Wrong salt length: %d bytes when %d <= n <= %d"
" expected.\n", c),
c, salt_minlen, salt_maxlen);
exit(1);
}
while (c-- > 0) {
if (strchr(valid_salts, salt_arg[c]) == NULL) {
fprintf(stderr, _("Illegal salt character '%c'.\n"),
salt_arg[c]);
exit(1);
}
}
salt = NOFAIL(malloc(strlen(salt_prefix) + strlen(rounds_str)
+ strlen(salt_arg) + 1));
*salt = '\0';
strcat(salt, salt_prefix);
strcat(salt, rounds_str);
strcat(salt, salt_arg);
} else {
#ifdef HAVE_SOLARIS_CRYPT_GENSALT
#error "This code path is untested on Solaris. Please send a patch."
salt = crypt_gensalt(salt_prefix, NULL);
if (!salt)
perror(stderr, "crypt_gensalt");
#elif defined HAVE_LINUX_CRYPT_GENSALT
void *entropy = get_random_bytes(64);
salt = crypt_gensalt(salt_prefix, rounds, entropy, 64);
if (!salt) {
fprintf(stderr, "crypt_gensalt failed.\n");
exit(2);
}
free(entropy);
#else
unsigned int salt_len = salt_maxlen;
if (salt_minlen != salt_maxlen) { /* salt length can vary */
srand(time(NULL) + getpid());
salt_len = rand() % (salt_maxlen - salt_minlen + 1) + salt_minlen;
}
salt = NOFAIL(malloc(strlen(salt_prefix) + strlen(rounds_str)
+ salt_len + 1));
*salt = '\0';
strcat(salt, salt_prefix);
strcat(salt, rounds_str);
generate_salt(salt + strlen(salt), salt_len);
#endif
}
if (password) {
} else if (password_fd != -1) {
FILE *fp;
char *p;
开发者ID:sunzhongwei,项目名称:whois-debian,代码行数:67,代码来源:mkpasswd.c
示例3: daemon_AuthUserPwd
int daemon_AuthUserPwd(char *username, char *password, char *errbuf)
{
#ifdef WIN32
/*
Warning: the user which launches the process must have the SE_TCB_NAME right.
This corresponds to have the "Act as part of the Operating System" turined on
(administrative tools, local security settings, local policies, user right assignment)
However, it seems to me that if you run it as a service, this right should be
provided by default.
*/
HANDLE Token;
if (LogonUser(username, ".", password, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &Token) == 0)
{
int error;
error = GetLastError();
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, errbuf,
PCAP_ERRBUF_SIZE, NULL);
return -1;
}
// This call should change the current thread to the selected user.
// I didn't test it.
if (ImpersonateLoggedOnUser(Token) == 0)
{
int error;
error = GetLastError();
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, errbuf,
PCAP_ERRBUF_SIZE, NULL);
CloseHandle(Token);
return -1;
}
CloseHandle(Token);
return 0;
#else
/* Standard user authentication:
http://www.unixpapa.com/incnote/passwd.html
Problem: it is not able to merge the standard pwd file with the shadow one
Shadow user authentication:
http://www.tldp.org/HOWTO/Shadow-Password-HOWTO-8.html
Problem: the program must either (1) run as root, or (2) run as user, but it
must be owned by root and must be SUID root (chmod u+s rpcapd)
*/
struct passwd *user;
#ifdef linux
struct spwd *usersp;
#endif
// This call is needed to get the uid
if ((user= getpwnam(username)) == NULL)
{
snprintf(errbuf, PCAP_ERRBUF_SIZE, "Authentication failed: no such user");
return -1;
}
#ifdef linux
// This call is needed to get the password; otherwise 'x' is returned
if ((usersp= getspnam(username)) == NULL)
{
snprintf(errbuf, PCAP_ERRBUF_SIZE, "Authentication failed: no such user");
return -1;
}
if (strcmp(usersp->sp_pwdp, (char *) crypt(password, usersp->sp_pwdp) ) != 0)
{
snprintf(errbuf, PCAP_ERRBUF_SIZE, "Authentication failed: password incorrect");
return -1;
}
#endif
#ifdef bsd
if (strcmp(user->pw_passwd, (char *) crypt(password, user->pw_passwd) ) != 0)
{
snprintf(errbuf, PCAP_ERRBUF_SIZE, "Authentication failed: password incorrect");
return -1;
}
#endif
if (setuid(user->pw_uid) )
{
snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s", pcap_strerror(errno) );
return -1;
}
/* if (setgid(user->pw_gid) )
{
SOCK_ASSERT("setgid failed", 1);
snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s", pcap_strerror(errno) );
return -1;
}
*/
return 0;
//.........这里部分代码省略.........
开发者ID:frgtn,项目名称:rpcapd-linux,代码行数:101,代码来源:daemon.c
示例4: handleClient
void handleClient(int csd){
printf("\tClient connected via socket %d.\n", csd);
int n;
char* buffer = malloc(1024); // buffer for reading
char* fullRequest = malloc(1024); // final buffer
char* current = fullRequest; // tracker on where the buffer should copy to
memset(buffer, '0',sizeof(buffer)); // zero out buffer
memset(fullRequest, '0', sizeof(fullRequest)); // zero out final buffer
while((n = read(csd,buffer,sizeof(buffer)-1))>0) // read the request in
{
buffer[n] = 0; // set last character to 0
if(fullRequest + sizeof(fullRequest) < current + n){ // if the request will overflow the buffer make it bigger
int size = current - fullRequest;
fullRequest = realloc(fullRequest, current + n - fullRequest);
current = fullRequest + size;
}
memcpy(current, buffer, n+1); // dump the buffer into the final buffer
current+=n; // increment the dump position
if(!strcmp(buffer, username))
break;
}
printf("\tUser: %s\n", fullRequest);
int authNum = rand();
char* num = malloc(33);
sprintf(num, "%d", authNum);
write(csd, num, strlen(num) );
//memset(fullRequest, '0',strlen(fullRequest));
char* hash = crypt(password, num);
read(csd, fullRequest, strlen(hash));
//printf("My Hash: %s\n", hash);
//printf("Received Hash: %s\n", fullRequest);
write(csd, strncmp(hash, fullRequest, strlen(hash)) ? "0" : "1", 2);
if(strncmp(hash, fullRequest, strlen(hash)))
return;
else
puts("\tPasswords matched, authenticated.");
current = fullRequest;
n = read(csd,buffer,1024);
buffer[n] = 0;
printf("\tReceived Command: %s\n", buffer);
int childPID = fork();
if(childPID == 0){
char* frd = strdup((const char *)buffer);
char* argument;
char* program = strtok(frd, " ");
int length = 40;
int numArgs = 1;
int i;
char* command = (char*) calloc(length, sizeof(char));
char** arguments = (char**) calloc(numArgs, sizeof(char*));
arguments[0] = program;
for(i = 1; argument = strtok(NULL, " "); i++){
if(i == numArgs){
numArgs *= 1.3;
arguments = realloc(arguments, numArgs * sizeof(char *));
if(!arguments)
puts("Error: Could not allocate enough space for arguments");
}
arguments[i] = argument;
}
//write(csd, "stuff", 5);
//close(0);
puts("\tExecuting command...");
fflush(stdout);
dup2(csd, 1);
dup2(csd, 2);
execvp(program, arguments);
exit(1);
}
int status;
wait(&status);
shutdown(csd, SHUT_RDWR);
if(status == 256)
puts("Couldn't find program");
free(buffer); // free buffer
free(fullRequest); // free final buffer
}
开发者ID:nileshp87,项目名称:CS4513,代码行数:85,代码来源:server.c
示例5: shadow_user_pass_verify
int shadow_user_pass_verify(const char *username, const char *password) {
#if defined(COMPILE_WIN32) || defined(NO_SHADOW_H)
errno = ENOSYS;
return -1;
#else
int errsv = 0;
struct spwd *spentp = NULL;
size_t salt_len = 0;
char *salt = NULL, *local_hash = NULL, *user_hash = NULL;
#ifdef _GNU_SOURCE
char sp_buf[8192];
struct spwd spent;
struct crypt_data cd;
#endif
/* Pre-check */
if (!username || !password) {
errno = EINVAL;
return -1;
}
#if defined(_GNU_SOURCE)
/* GNU implementations support native reentrant functions */
if (getspnam_r(username, &spent, sp_buf, sizeof(sp_buf), &spentp) < 0)
return -1;
#else
pthread_mutex_lock(&_auth_shadow_mutex);
spentp = getspnam(username);
errsv = errno;
pthread_mutex_unlock(&_auth_shadow_mutex);
#endif
/* Validate that spentp is valid */
if (!spentp) {
errno = errsv;
return -1;
}
/* Search for '$' in the local hash. If found, extensions (non-POSIX) are enabled */
if (!(local_hash = strrchr(spentp->sp_pwdp, '$'))) {
/* DES (default) */
if (strlen(spentp->sp_pwdp) <= 2) {
errno = ENOSYS;
return -1;
}
salt_len = 2;
} else {
/* Extensions */
local_hash ++;
salt_len = local_hash - spentp->sp_pwdp;
}
/* Allocate memory for salt */
if (!(salt = malloc(salt_len + 1)))
return -1;
/* Isolate salt */
memcpy(salt, spentp->sp_pwdp, salt_len);
salt[salt_len] = 0;
#ifdef _GNU_SOURCE
/* cd.initialized = 0; */
tc_memset(&cd, 0, sizeof(struct crypt_data));
/* Generate password hash */
if (!(user_hash = crypt_r(password, salt, &cd))) {
errsv = errno;
free(salt);
errno = errsv;
return -1;
}
#else
pthread_mutex_lock(&_auth_shadow_mutex);
/* Generate password hash (non-reentrant) */
if (!(user_hash = crypt(password, salt))) {
errsv = errno;
free(salt);
errno = errsv;
return -1;
}
pthread_mutex_unlock(&_auth_shadow_mutex);
#endif
/* Free unused memory */
free(salt);
/* Compare hashes */
if (strcmp(spentp->sp_pwdp, user_hash)) {
errno = EINVAL;
return -1;
}
return 0;
//.........这里部分代码省略.........
开发者ID:ucodev,项目名称:libpsec,代码行数:101,代码来源:generic.c
示例6: verify_user
//.........这里部分代码省略.........
print_exit_failure("mysql_query failed (Schueler - Lehrer)");
}
result = mysql_store_result(my);
if(mysql_num_rows(result) == 1){
found=true;
isAcronym=false; //Da wir jetzt eine Person mit Kürzel gefunden haben
}else{
//Person nicht vorhanden, oder Fehler
//print_exit_failure("mysql: Person nicht vorhanden, oder Passwort falsch."); //Was auch immer
found=false;
isAcronym=false;
}
free(sql_query);
}
//Ab hier wurde die SQL-Query für Lehrer oder Schüler ausgeführt.
if(found == true){
MYSQL_ROW row;
row=mysql_fetch_row(result);
#ifdef DEBUG
fprintf(stderr, "\nEin Ergebnis!\n Name: %s, Pass: %s, SID: '%s'\n", row[COL_NAME], row[COL_PASS], row[COL_SID]);
#endif // DEBUG
//Auslesen des Salt
char * salt=calloc(SALT_LENGTH+1, sizeof(char));
//strncat(salt, row[COL_PASS], 1);
//strncat(salt, row[COL_PASS]+1, 1);
for(int i=0; i<SALT_LENGTH; i++){
strncat(salt, row[COL_PASS]+i, 1);
}
char * arg=NULL;
asprintf(&arg, "$6$%s$", salt);
char * encr=crypt(pers->password, arg);
free(pers->password);
char * load_pw=NULL;
asprintf(&load_pw, "%s%s", salt, encr+strlen(arg));
//pers->password=encr+strlen(arg);
if(strcmp(load_pw, row[COL_PASS]) == 0){
pers->auth=true;
//Name holen
//pers->name=calloc(strlen(row[COL_NAME])+1, sizeof(char));
//strcpy(pers->name, row[COL_NAME]);
asprintf(&pers->name, "%s", row[COL_NAME]);
//pers->first_name=calloc(strlen(row[COL_VORNAME])+1, sizeof(char));
//strcpy(pers->first_name, row[COL_VORNAME]);
asprintf(&pers->first_name, "%s", row[COL_VORNAME]);
if(isAcronym){
//Person hat Kürzel angegeben --> es ist eine Leherer --> email holen holen
pers->email=calloc(strlen(row[COL_EMAIL])+1, sizeof(char));
strcpy(pers->email, row[COL_EMAIL]);
}else{
//Person hat ihre Email-Adresse statt dem Kürzel angegeben --> (Falls es ein Lehrer ist, dessen Kürzel holen)
pers->acronym=NULL;
if(row[COL_ACR] != NULL){
//Die Person hat ein Küzel --> Lehrer
pers->acronym=calloc(strlen(row[COL_ACR])+1, sizeof(char));
strcpy(pers->acronym, row[COL_ACR]);
pers->isTeacher=true;
}else{
pers->isTeacher=false;
}
}
//Kurse (falls vorhanden)
if(row[COL_COURSE] != NULL){
pers->courses=calloc(strlen(row[COL_COURSE])+1, sizeof(char));
strcpy(pers->courses, row[COL_COURSE]);
}
//ID holen
if(row[COL_ID] != NULL){
pers->id=atoi(row[COL_ID]);
}
if(row[COL_SID] != NULL){
//Benutzer ist schon angemeldet
user_state=PW_CORRECT_ALREADY_LOGGED_IN;
pers->auth=true;
pers->sid=atoi(row[COL_SID]);
}else{
user_state=PW_CORRECT;
create_session(pers);
}
}else{
user_state=PW_INCORRECT;
pers->auth=false;
pers->sid=0;
}
}
mysql_free_result(result);
mysql_close(my);
return user_state;
}
开发者ID:ATL4s789,项目名称:ISS,代码行数:101,代码来源:SQL_functions_v1.c
示例7: main
//.........这里部分代码省略.........
brief_usage();
/* NOT REACHED */
break;
default:
printf("Invalid Option: -%c\n", c);
break;
}
}
if (flag & FLAG_MD5)
{
if (length == 0)
length = 8;
if (flag & FLAG_SALT)
salt = make_md5_salt_para(saltpara);
else
salt = make_md5_salt(length);
}
else if (flag & FLAG_SHA256)
{
if (length == 0)
length = 16;
if (flag & FLAG_SALT)
salt = make_sha256_salt_para(saltpara);
else
salt = make_sha256_salt(length);
}
else if (flag & FLAG_SHA512)
{
if (length == 0)
length = 16;
if (flag & FLAG_SALT)
salt = make_sha512_salt_para(saltpara);
else
salt = make_sha512_salt(length);
}
else if (flag & FLAG_BLOWFISH)
{
if (length == 0)
length = 22;
if (flag & FLAG_SALT)
salt = make_bf_salt_para(rounds, saltpara);
else
salt = make_bf_salt(rounds, length);
}
else if (flag & FLAG_EXT)
{
/* XXX - rounds needs to be done */
if (flag & FLAG_SALT)
{
if ((strlen(saltpara) == 4))
{
salt = make_ext_salt_para(rounds, saltpara);
}
else
{
printf("Invalid salt, please enter 4 alphanumeric characters\n");
exit(1);
}
}
else
{
salt = make_ext_salt(rounds);
}
}
else if (flag & FLAG_RAW)
{
salt = saltpara;
}
else /* Default to DES */
{
if (flag & FLAG_SALT)
{
if ((strlen(saltpara) == 2))
{
salt = saltpara;
}
else
{
printf("Invalid salt, please enter 2 alphanumeric characters\n");
exit(1);
}
}
else
{
salt = make_des_salt();
}
}
if (flag & FLAG_PASS)
{
if (!plaintext)
printf("Please enter a valid password\n");
}
else
plaintext = getpass("plaintext: ");
printf("%s\n", crypt(plaintext, salt));
return 0;
}
开发者ID:jmaurice,项目名称:ircd-hybrid,代码行数:101,代码来源:mkpasswd.c
示例8: readpw
readpw(Display *dpy, const char *pws)
#endif
{
char buf[32], passwd[256];
int num, screen;
unsigned int len, llen;
KeySym ksym;
XEvent ev;
XIM im;
XIMStyles *im_styles;
XIMStyle im_style = 0;
char *imvalret;
XIC ic;
Status status;
im = XOpenIM(dpy, NULL, NULL, NULL);
if (im == NULL)
die("slock: XOpenIM failed");
if(im) {
imvalret = XGetIMValues(im, XNQueryInputStyle, &im_styles, NULL);
if (imvalret != NULL || im_styles == NULL) {
die("slock: input method doesn't support any styles");
}
if (im_styles) {
im_style = 0;
/* for now just pick the first style if it exists */
if (im_styles->count_styles)
im_style = im_styles->supported_styles[0];
}
if (im_style == 0) {
die("slock: input method doesn't support the styles we support");
}
XFree(im_styles);
}
if (im && im_style) {
ic = XCreateIC(im, XNInputStyle, im_style, NULL);
}
len = llen = 0;
running = True;
/* As "slock" stands for "Simple X display locker", the DPMS settings
* had been removed and you can set it with "xset" or some other
* utility. This way the user can easily set a customized DPMS
* timeout. */
while(running && !XNextEvent(dpy, &ev)) {
if(ev.type == KeyPress) {
buf[0] = 0;
num = Xutf8LookupString(ic, &ev.xkey, buf, sizeof buf, &ksym, &status);
switch (status) {
case XBufferOverflow:
die("slock: XBufferOverflow");
case XLookupNone:
continue;
case XLookupChars:
/* Add the chars to the supposed password */
if (num) {
memcpy(passwd + len, buf, num);
len += num;
if(running != False)
XBell(dpy, 100);
}
break;
case XLookupBoth:
switch(ksym) {
case XK_KP_Enter:
case XK_Return:
passwd[len] = 0;
#ifdef HAVE_BSD_AUTH
running = !auth_userokay(getlogin(), NULL, "auth-xlock", passwd);
#else
running = strcmp(crypt(passwd, pws), pws);
#endif
if(running != False)
XBell(dpy, 100);
len = 0;
break;
case XK_Escape:
len = 0;
break;
case XK_BackSpace:
if(len)
--len;
break;
default:
if (num) {
memcpy(passwd + len, buf, num);
len += num;
if(running != False)
XBell(dpy, 100);
}
break;
}
break;
//.........这里部分代码省略.........
开发者ID:reynir,项目名称:uslock,代码行数:101,代码来源:slock.c
示例9: main
int main(int argc, char **argv)
{
long count;
static unsigned char buf[BUFSIZE];
static DES_cblock key =
{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
static DES_cblock key2 =
{ 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 };
static DES_cblock key3 =
{ 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 };
DES_key_schedule sch, sch2, sch3;
double a, b, c, d, e;
#ifndef SIGALRM
long ca, cb, cc, cd, ce;
#endif
#ifndef TIMES
printf("To get the most accurate results, try to run this\n");
printf("program when this computer is idle.\n");
#endif
DES_set_key_unchecked(&key2, &sch2);
DES_set_key_unchecked(&key3, &sch3);
#ifndef SIGALRM
printf("First we calculate the approximate speed ...\n");
DES_set_key_unchecked(&key, &sch);
count = 10;
do {
long i;
DES_LONG data[2];
count *= 2;
Time_F(START);
for (i = count; i; i--)
DES_encrypt1(data, &sch, DES_ENCRYPT);
d = Time_F(STOP);
} while (d < 3.0);
ca = count;
cb = count * 3;
cc = count * 3 * 8 / BUFSIZE + 1;
cd = count * 8 / BUFSIZE + 1;
ce = count / 20 + 1;
printf("Doing set_key %ld times\n", ca);
# define COND(d) (count != (d))
# define COUNT(d) (d)
#else
# define COND(c) (run)
# define COUNT(d) (count)
signal(SIGALRM, sig_done);
printf("Doing set_key for 10 seconds\n");
alarm(10);
#endif
Time_F(START);
for (count = 0, run = 1; COND(ca); count++)
DES_set_key_unchecked(&key, &sch);
d = Time_F(STOP);
printf("%ld set_key's in %.2f seconds\n", count, d);
a = ((double)COUNT(ca)) / d;
#ifdef SIGALRM
printf("Doing DES_encrypt's for 10 seconds\n");
alarm(10);
#else
printf("Doing DES_encrypt %ld times\n", cb);
#endif
Time_F(START);
for (count = 0, run = 1; COND(cb); count++) {
DES_LONG data[2];
DES_encrypt1(data, &sch, DES_ENCRYPT);
}
d = Time_F(STOP);
printf("%ld DES_encrypt's in %.2f second\n", count, d);
b = ((double)COUNT(cb) * 8) / d;
#ifdef SIGALRM
printf("Doing DES_cbc_encrypt on %ld byte blocks for 10 seconds\n",
BUFSIZE);
alarm(10);
#else
printf("Doing DES_cbc_encrypt %ld times on %ld byte blocks\n", cc,
BUFSIZE);
#endif
Time_F(START);
for (count = 0, run = 1; COND(cc); count++)
DES_ncbc_encrypt(buf, buf, BUFSIZE, &sch, &key, DES_ENCRYPT);
d = Time_F(STOP);
printf("%ld DES_cbc_encrypt's of %ld byte blocks in %.2f second\n",
count, BUFSIZE, d);
c = ((double)COUNT(cc) * BUFSIZE) / d;
#ifdef SIGALRM
printf("Doing DES_ede_cbc_encrypt on %ld byte blocks for 10 seconds\n",
BUFSIZE);
alarm(10);
#else
printf("Doing DES_ede_cbc_encrypt %ld times on %ld byte blocks\n", cd,
BUFSIZE);
//.........这里部分代码省略.........
开发者ID:1Project,项目名称:SafeBoardMessenger,代码行数:101,代码来源:speed.c
示例10: pw_ldap_check
void pw_ldap_check(AuthResult * const result,
const char *account, const char *password,
const struct sockaddr_storage * const sa,
const struct sockaddr_storage * const peer)
{
struct passwd *pw;
const char *spwd; /* Stored pwd */
const char *cpwd = NULL; /* Computed pwd */
signed char nocase = 0; /* Insensitive strcmp */
(void) sa;
(void) peer;
result->auth_ok = 0;
if (account == NULL || *account == 0 || password == NULL ||
(pw = pw_ldap_getpwnam(account, result)) == NULL) {
return;
}
result->auth_ok--; /* -1 */
if (use_ldap_bind_method == 1 && result->backend_data != NULL) {
LDAP *ld;
char *dn = (char *) result->backend_data;
int ok = 0;
/* Verify password by binding to LDAP */
if (password != NULL && *password != 0 &&
(ld = pw_ldap_connect(dn, password)) != NULL) {
ldap_unbind(ld);
ok = 1;
}
free(result->backend_data);
result->backend_data = NULL;
if (ok <= 0) {
return;
}
} else {
free(result->backend_data);
result->backend_data = NULL;
spwd = pw->pw_passwd;
#ifdef HAVE_LIBSODIUM
if (strncasecmp(spwd, PASSWD_LDAP_SCRYPT_PREFIX,
sizeof PASSWD_LDAP_SCRYPT_PREFIX - 1U) == 0) {
spwd += (sizeof PASSWD_LDAP_SCRYPT_PREFIX - 1U);
if (crypto_pwhash_scryptsalsa208sha256_str_verify
(spwd, password, strlen(password)) == 0) {
goto pwd_ok;
}
return;
} else
#endif
if (strncasecmp(spwd, PASSWD_LDAP_MD5_PREFIX,
sizeof PASSWD_LDAP_MD5_PREFIX - 1U) == 0) {
spwd += (sizeof PASSWD_LDAP_MD5_PREFIX - 1U);
if (strlen(spwd) >= 32U) {
nocase++;
}
cpwd = crypto_hash_md5(password, nocase);
} else if (strncasecmp(spwd, PASSWD_LDAP_SHA_PREFIX,
sizeof PASSWD_LDAP_SHA_PREFIX - 1U) == 0) {
spwd += (sizeof PASSWD_LDAP_SHA_PREFIX - 1U);
if (strlen(spwd) >= 40U) {
nocase++;
}
cpwd = crypto_hash_sha1(password, nocase);
} else if (strncasecmp(spwd, PASSWD_LDAP_SSHA_PREFIX,
sizeof PASSWD_LDAP_SSHA_PREFIX - 1U) == 0) {
spwd += (sizeof PASSWD_LDAP_SSHA_PREFIX - 1U);
cpwd = crypto_hash_ssha1(password, spwd);
} else if (strncasecmp(spwd, PASSWD_LDAP_SMD5_PREFIX,
sizeof PASSWD_LDAP_SMD5_PREFIX - 1U) == 0) {
spwd += (sizeof PASSWD_LDAP_SMD5_PREFIX - 1U);
cpwd = crypto_hash_smd5(password, spwd);
} else if (strncasecmp(spwd, PASSWD_LDAP_CRYPT_PREFIX,
sizeof PASSWD_LDAP_CRYPT_PREFIX - 1U) == 0) {
spwd += (sizeof PASSWD_LDAP_CRYPT_PREFIX - 1U);
cpwd = (const char *) crypt(password, spwd);
} else if (*password != 0) {
cpwd = password; /* Cleartext */
} else {
return; /* Refuse null passwords */
}
if (cpwd == NULL) {
return;
}
if (nocase != 0) {
if (strcasecmp(cpwd, spwd) != 0) {
return;
}
}
if (pure_strcmp(cpwd, spwd) != 0) {
return;
}
}
pwd_ok:
result->uid = pw->pw_uid;
result->gid = pw->pw_gid;
if (result->uid <= (uid_t) 0 || result->gid <= (gid_t) 0) {
return;
//.........这里部分代码省略.........
开发者ID:abrodkin,项目名称:pure-ftpd,代码行数:101,代码来源:log_ldap.c
示例11: svr_getopts
//.........这里部分代码省略.........
//case 'U':
// Berserker - end
case 'G':
case 'R':
nextignored = 1;
break;
case 'A':
break;
#endif
default:
fprintf(stderr, "Unknown argument %s\n", argv[i]);
printhelp(argv[0]);
exit(EXIT_FAILURE);
break;
}
}
}
/* Set up listening ports */
if (svr_opts.portcount == 0) {
svr_opts.ports[0] = m_strdup(DROPBEAR_DEFPORT);
svr_opts.addresses[0] = m_strdup(DROPBEAR_DEFADDRESS);
svr_opts.portcount = 1;
}
if (svr_opts.dsskeyfile == NULL) {
svr_opts.dsskeyfile = DSS_PRIV_FILENAME;
}
if (svr_opts.rsakeyfile == NULL) {
svr_opts.rsakeyfile = RSA_PRIV_FILENAME;
}
if (svr_opts.bannerfile) {
struct stat buf;
if (stat(svr_opts.bannerfile, &buf) != 0) {
dropbear_exit("Error opening banner file '%s'",
svr_opts.bannerfile);
}
if (buf.st_size > MAX_BANNER_SIZE) {
dropbear_exit("Banner file too large, max is %d bytes",
MAX_BANNER_SIZE);
}
svr_opts.banner = buf_new(buf.st_size);
if (buf_readfile(svr_opts.banner, svr_opts.bannerfile)!=DROPBEAR_SUCCESS) {
dropbear_exit("Error reading banner file '%s'",
svr_opts.bannerfile);
}
buf_setpos(svr_opts.banner, 0);
}
if (recv_window_arg) {
opts.recv_window = atol(recv_window_arg);
if (opts.recv_window == 0 || opts.recv_window > MAX_RECV_WINDOW) {
dropbear_exit("Bad recv window '%s'", recv_window_arg);
}
}
if (keepalive_arg) {
unsigned int val;
if (m_str_to_uint(keepalive_arg, &val) == DROPBEAR_FAILURE) {
dropbear_exit("Bad keepalive '%s'", keepalive_arg);
}
opts.keepalive_secs = val;
}
if (idle_timeout_arg) {
unsigned int val;
if (m_str_to_uint(idle_timeout_arg, &val) == DROPBEAR_FAILURE) {
dropbear_exit("Bad idle_timeout '%s'", idle_timeout_arg);
}
opts.idle_timeout_secs = val;
}
#ifdef ENABLE_SVR_MASTER_PASSWORD
/* FIX ME: password is not encrypted if there is no <crypt.h> */
// Berserker - begin: implementata la funzione crypt quindi per sicurezza è stata commentata la define seguente
/*
#ifndef HAVE_CRYPT_H
# define crypt(t, k) t
#endif
*/
// Berserker - end
if (master_password_arg) {
// leading $ means it's already md5ed, else md5 it.
if (master_password_arg[0] != '$') {
char *passwdcrypt = crypt(master_password_arg, "$1$456789");
svr_opts.master_password = m_strdup(passwdcrypt);
} else {
svr_opts.master_password = m_strdup(master_password_arg);
}
// Hide the password from ps or /proc/cmdline
m_burn(master_password_arg, strlen(master_password_arg));
}
#endif
}
开发者ID:mikemakepen,项目名称:android_dropbear,代码行数:101,代码来源:svr-runopts.c
示例12: main
int
main(int argc, char **argv)
{
char name[MAXNETNAMELEN+1];
char public[HEXKEYBYTES + 1];
char secret[HEXKEYBYTES + 1];
char crypt1[HEXKEYBYTES + KEYCHECKSUMSIZE + 1];
char crypt2[HEXKEYBYTES + KEYCHECKSUMSIZE + 1];
int status;
char *pass;
struct passwd *pw;
uid_t uid;
int force = 0;
int ch;
#ifdef YP
char *master;
#endif
#ifdef YPPASSWD
char *cryptpw;
#endif
while ((ch = getopt(argc, argv, "f")) != -1)
switch(ch) {
case 'f':
force = 1;
break;
default:
usage();
}
argc -= optind;
argv += optind;
if (argc != 0)
usage();
#ifdef YP
(void)yp_get_default_domain(&domain);
if (yp_master(domain, PKMAP, &master) != 0)
errx(1, "can't find master of publickey database");
#endif
uid = getuid() /*geteuid()*/;
if (uid == 0) {
if (host2netname(name, NULL, NULL) == 0)
errx(1, "cannot convert hostname to netname");
} else {
if (user2netname(name, uid, NULL) == 0)
errx(1, "cannot convert username to netname");
}
(void)printf("Generating new key for %s.\n", name);
if (!force) {
if (uid != 0) {
#ifdef YPPASSWD
pw = ypgetpwuid(uid);
#else
pw = getpwuid(uid);
#endif
if (pw == NULL) {
#ifdef YPPASSWD
errx(1,
"no NIS password entry found: can't change key");
#else
errx(1,
"no password entry found: can't change key");
#endif
}
} else {
pw = getpwuid(0);
if (pw == NULL)
errx(1, "no password entry found: can't change key");
}
}
pass = getpass("Password:");
#ifdef YPPASSWD
if (!force) {
cryptpw = crypt(pass, pw->pw_passwd);
if (cryptpw == NULL || strcmp(cryptpw, pw->pw_passwd) != 0)
errx(1, "invalid password");
}
#else
force = 1; /* Make this mandatory */
#endif
genkeys(public, secret, pass);
memcpy(crypt1, secret, HEXKEYBYTES);
memcpy(crypt1 + HEXKEYBYTES, secret, KEYCHECKSUMSIZE);
crypt1[HEXKEYBYTES + KEYCHECKSUMSIZE] = 0;
xencrypt(crypt1, pass);
if (force) {
memcpy(crypt2, crypt1, HEXKEYBYTES + KEYCHECKSUMSIZE + 1);
xdecrypt(crypt2, getpass("Retype password:"));
if (memcmp(crypt2, crypt2 + HEXKEYBYTES, KEYCHECKSUMSIZE) != 0
|| memcmp(crypt2, secret, HEXKEYBYTES) != 0)
errx(1, "password incorrect");
}
#ifdef YP
(void)printf("Sending key change request to %s...\n", master);
#endif
//.........这里部分代码省略.........
开发者ID:2asoft,项目名称:freebsd,代码行数:101,代码来源:chkey.c
示例13: crypt
static int crypt(struct blkcipher_desc *d,
struct blkcipher_walk *w, struct priv *ctx,
void (*fn)(struct crypto_tfm *, u8 *, const u8 *))
{
int err;
unsigned int avail;
const int bs = crypto_cipher_blocksize(ctx->child);
struct sinfo s = {
.tfm = crypto_cipher_tfm(ctx->child),
.fn = fn
};
be128 *iv;
u8 *wsrc;
u8 *wdst;
err = blkcipher_walk_virt(d, w);
if (!(avail = w->nbytes))
return err;
wsrc = w->src.virt.addr;
wdst = w->dst.virt.addr;
/* calculate first value of T */
iv = (be128 *)w->iv;
s.t = *iv;
/* T <- I*Key2 */
gf128mul_64k_bbe(&s.t, ctx->table);
goto first;
for (;;) {
do {
/* T <- I*Key2, using the optimization
* discussed in the specification */
be128_xor(&s.t, &s.t, &ctx->mulinc[get_index128(iv)]);
inc(iv);
first:
lrw_round(&s, wdst, wsrc);
wsrc += bs;
wdst += bs;
} while ((avail -= bs) >= bs);
err = blkcipher_walk_done(d, w, avail);
if (!(avail = w->nbytes))
break;
wsrc = w->src.virt.addr;
wdst = w->dst.virt.addr;
}
return err;
}
static int encrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
struct scatterlist *src, unsigned int nbytes)
{
struct priv *ctx = crypto_blkcipher_ctx(desc->tfm);
struct blkcipher_walk w;
blkcipher_walk_init(&w, dst, src, nbytes);
return crypt(desc, &w, ctx,
crypto_cipher_alg(ctx->child)->cia_encrypt);
}
static int decrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
struct scatterlist *src, unsigned int nbytes)
{
struct priv *ctx = crypto_blkcipher_ctx(desc->tfm);
struct blkcipher_walk w;
blkcipher_walk_init(&w, dst, src, nbytes);
return crypt(desc, &w, ctx,
crypto_cipher_alg(ctx->child)->cia_decrypt);
}
static int init_tfm(struct crypto_tfm *tfm)
{
struct crypto_cipher *cipher;
struct crypto_instance *inst = (void *)tfm->__crt_alg;
struct crypto_spawn *spawn = crypto_instance_ctx(inst);
struct priv *ctx = crypto_tfm_ctx(tfm);
u32 *flags = &tfm->crt_flags;
cipher = crypto_spawn_cipher(spawn);
if (IS_ERR(cipher))
return PTR_ERR(cipher);
if (crypto_cipher_blocksize(cipher) != 16) {
*flags |= CRYPTO_TFM_RES_BAD_BLOCK_LEN;
return -EINVAL;
}
ctx->child = cipher;
return 0;
}
static void exit_tfm(struct crypto_tfm *tfm)
//.........这里部分代码省略.........
开发者ID:mikeberkelaar,项目名称:grhardened,代码行数:101,代码来源:lrw.c
示例14: readpw
readpw(Display *dpy, const char *pws)
#endif
{
char buf[32], passwd[256];
int num, screen;
unsigned int len, llen;
KeySym ksym;
XEvent ev;
len = llen = 0;
running = True;
/* As "slock" stands for "Simple X display locker", the DPMS settings
* had been removed and you can set it with "xset" or some other
* utility. This way the user can easily set a customized DPMS
* timeout. */
while(running && !XNextEvent(dpy, &ev)) {
if(ev.type == KeyPress) {
buf[0] = 0;
num = XLookupString(&ev.xkey, buf, sizeof buf, &ksym, 0);
if(IsKeypadKey(ksym)) {
if(ksym == XK_KP_Enter)
ksym = XK_Return;
else if(ksym >= XK_KP_0 && ksym <= XK_KP_9)
ksym = (ksym - XK_KP_0) + XK_0;
}
if(IsFunctionKey(ksym) || IsKeypadKey(ksym)
|| IsMiscFunctionKey(ksym) || IsPFKey(ksym)
|| IsPrivateKeypadKey(ksym))
continue;
switch(ksym) {
case XK_Return:
break;
case XK_Escape:
len = 0;
break;
case XK_BackSpace:
if(len)
--len;
break;
default:
if(num && !iscntrl((int) buf[0]) && (len + num < sizeof passwd)) {
memcpy(passwd + len, buf, num);
len += num;
passwd[len] = '\0';
#ifdef HAVE_BSD_AUTH
running = !auth_userokay(getlogin(), NULL, "auth-xlock", passwd);
#else
running = strcmp(crypt(passwd, pws), pws);
#endif
}
break;
}
if(llen == 0 && len != 0) {
for(screen = 0; screen < nscreens; screen++) {
XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[1]);
XClearWindow(dpy, locks[screen]->win);
}
} else if(llen != 0 && len == 0) {
for(screen = 0; screen < nscreens; screen++) {
XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[0]);
XClearWindow(dpy, locks[screen]->win);
}
}
llen = len;
}
else for(screen = 0; screen < nscreens; screen++)
XRaiseWindow(dpy, locks[screen]->win);
}
}
开发者ID:eepp,项目名称:slock,代码行数:71,代码来源:slock.c
示例15: verify_user_password
/** \brief Überprüfen ob das Passwort einer angemeldeten Person stimmt
*
* \param pers person* Person, mit E-Mail-Adresse und SessionID
* \return bool true: Passwort ist richtig; false: Passwort ist falsch
*
*/
bool verify_user_password(person * pers){
char * query=NULL;
bool password_state=false;
MYSQL * my=NULL;
if(pers->password == NULL || pers->sid==0){
print_exit_failure("Programm falsch (verify_user_password)");
}
if(asprintf(&query, "SELECT * FROM Benutzer WHERE sid='%d' AND email='%s'", pers->sid, pers->email) == -1){
print_exit_failure("Es konnte kein Speicher angefordert werden (verify_user_password)");
}
my=mysql_init(NULL);
if(my == NULL){
print_exit_failure("MYSQL init failure (verify_user_password)");
}
if(mysql_real_connect(my, "localhost", SQL_USER, SQL_PASS, SQL_BASE, 0, NULL, 0) == NULL){
print_exit_failure("MYSQL-connection error!");
}
if(mysql_query(my, query)){
print_exit_failure("mysql_query failed (verify_user_password)");
#ifdef DEBUG
fprintf(stderr, "sql_query:\n%s\nfailed\n", query);
#endif // DEBUG
}else{
MYSQL_RES * result=NULL;
result = mysql_store_result(my);
if(mysql_num_rows(result) == 1){
MYSQL_ROW * row=NULL;
row=mysql_fetch_row(result);
#ifdef DEBUG
fprintf(stderr, "Benutzer gefunden (verify_user_password)\n");
#endif // DEBUG
char * password_encrypted=NULL;
char * password_db=NULL;
char * salt=NULL;
password_db=row[COL_PASS];
salt=salt_extract(password_db);
char * arg=NULL;
asprintf(&arg, "$6$%s$", salt);
char * encr=crypt(pers->password, arg);
//free(pers->password);
asprintf(&password_encrypted, "%s%s", salt, encr+strlen(arg));
free(salt);
free(arg);
free(encr);
if(strcmp(password_db, password_encrypted) == 0){
#ifdef DEBUG
fprintf(stderr, "Passwort war richtig! (Benutzer: %s)", pers->email);
#endif // DEBUG
password_state=true;
}else{
password_state=false;
}
}else{
pers->auth=false;
}
mysql_free_result(result);
}
mysql_close(my);
free(query);
return password_state;
}
开发者ID:ATL4s789,项目名称:ISS,代码行数:82,代码来源:SQL_functions_v1.c
示例16: crypto
int crypto(){
char username[BUFSIZ], *password="";
char buf[BUFSIZ];
char *user_file, *pass_file;
char filename[]="psss";
FILE *infile;
int flag=0;
int emptyflag=0;
char *crybuf;
printf("Username: ");
scanf("%s", username);
password = getpass("Password: ");
if((infile = fopen(filename, "r")) == NULL){
printf("\nFile error!\nAborting...\n");
} else {
while (!feof(infile)) {
buf[0] = '\0';
fscanf(infile, "%s", buf);
if(strlen(buf) == 0) continue;
user_file = buf;
pass_file = strchr(buf, ':');
pass_file[0] = '\0';
pass_file++;
if(strcmp(user_file, username) == 0){
crybuf=crypt(password, pass_file);
if(strcmp(crybuf, pass_file) == 0){
flag=1;
} else {
if(flag==0)
printf("Invalid password!\n\n");
}
break;
}
emptyflag=1;
flag=999;
}
}
if(strlen(buf)==0 && emptyflag==0){
printf("We could not find your Login credentials.Please Register :\n");
flag=signup();
}
fclose(infile);
return flag;
}
开发者ID:melvinvarkey,项目名称:encyptoFS,代码行数:74,代码来源:checks.c
示例17: insert_user
/** \brief Nutzer mit Name, (ggf. Kürzel) und Passwort in die DB einfügen
*
* \param pers person* Personen-Struktur
* \return void
* Eine Person in die DB einfügen, falls diese noch nicht existiert.
* Das Passwort wird mithilfe von crypt() verschlüsselt
*/
void insert_user(person * pers){
MYSQL *my=NULL;
char * query=NULL;
if(pers == NULL){
print_exit_failure("Programm falsch.\n Wörk!");
}
if(email_exists(pers->email)){
print_exit_failure("Benutzer Existiert schon!");
}
my=mysql_init(NULL);
if(my == NULL){
print_exit_failure("MYSQL init failure\n Wörk!");
}
if(mysql_real_connect(my, "localhost", SQL_ALTERNATE_USER, SQL_ALTERNATE_PASS, SQL_BASE, 0, NULL, 0) == NULL){
print_exit_failure("MYSQL-connection error!");
}
char * salt=NULL;
salt_generate(&salt);
//Verhi
|
请发表评论