D
Dennis Schulz
Hi all,
the following programm is supposed to check for login and password
with inbuilt linux functions. in line 57 and 64 there are erorrs:
incompatible types in asignment. whats wrong with this? the crypt
function returns a pointer to a char. why an assignment to a char
vector is not possible?
MfG Dennis
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _XOPEN_SOURCE
#include <assert.h>
#include "auth.h"
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <shadow.h>
#include <unistd.h>
int main() {
struct passwd *pw;
struct spwd *spw;
char temp[4];
char user[20];
char pass[20];
char encryptedinput[20];
char encryptedpw[30];
char salta[12];
char saltb[2];
printf("%s", "User: ");
scanf("%s", &user);
printf("\n\n");
printf("%s", "Passwort: ");
scanf("%s", &pass);
printf("\n\n");
// prueft ob user vorhanden
if( ( pw = getpwnam( user ) ) == NULL ) {
fprintf( stderr, "getpwnam: unknown %s\n",user );
exit( EXIT_FAILURE );
}
// pruefe ob superuser
if (strcmp(pw->pw_passwd, "x") == 0) {
if( ( spw = getspnam( user ) ) == NULL ) {
fprintf( stderr, "getspnam: unknown %s\n",user );
exit( EXIT_FAILURE );
}
strcpy(encryptedpw,spw->sp_pwdp);
// wenn kein superuser
} else {
strcpy(encryptedpw,pw->pw_passwd);
}
// hole erste drei zeichen
strncpy(temp,encryptedpw,3);
temp[3]='\0';
if ((strcmp(temp,"$1$"))==0) {
strncpy(salta,encryptedpw,12);
salta[12]='\0';
if( ( encryptedinput = crypt( pass, salta ) ) == NULL ) {
fprintf( stderr, "Fehler beim verschluesseln");
exit( EXIT_FAILURE );
}
} else {
strncpy(saltb,encryptedpw,2);
saltb[2]='\0';
if( ( encryptedinput = crypt( pass, saltb ) ) == NULL ) {
fprintf( stderr, "Fehler beim verschluesseln");
exit( EXIT_FAILURE );
}
}
// verschluessle passwort
if (strcmp(encryptedinput, encryptedpw) == 0) {
printf("%s\n\n","LOGIN ERFOLGREICH!!!");
} else {
printf("%s\n\n","LOGIN FEHLGESCHLAGEN!!!");
}
exit( EXIT_SUCCESS );
}
the following programm is supposed to check for login and password
with inbuilt linux functions. in line 57 and 64 there are erorrs:
incompatible types in asignment. whats wrong with this? the crypt
function returns a pointer to a char. why an assignment to a char
vector is not possible?
MfG Dennis
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _XOPEN_SOURCE
#include <assert.h>
#include "auth.h"
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <shadow.h>
#include <unistd.h>
int main() {
struct passwd *pw;
struct spwd *spw;
char temp[4];
char user[20];
char pass[20];
char encryptedinput[20];
char encryptedpw[30];
char salta[12];
char saltb[2];
printf("%s", "User: ");
scanf("%s", &user);
printf("\n\n");
printf("%s", "Passwort: ");
scanf("%s", &pass);
printf("\n\n");
// prueft ob user vorhanden
if( ( pw = getpwnam( user ) ) == NULL ) {
fprintf( stderr, "getpwnam: unknown %s\n",user );
exit( EXIT_FAILURE );
}
// pruefe ob superuser
if (strcmp(pw->pw_passwd, "x") == 0) {
if( ( spw = getspnam( user ) ) == NULL ) {
fprintf( stderr, "getspnam: unknown %s\n",user );
exit( EXIT_FAILURE );
}
strcpy(encryptedpw,spw->sp_pwdp);
// wenn kein superuser
} else {
strcpy(encryptedpw,pw->pw_passwd);
}
// hole erste drei zeichen
strncpy(temp,encryptedpw,3);
temp[3]='\0';
if ((strcmp(temp,"$1$"))==0) {
strncpy(salta,encryptedpw,12);
salta[12]='\0';
if( ( encryptedinput = crypt( pass, salta ) ) == NULL ) {
fprintf( stderr, "Fehler beim verschluesseln");
exit( EXIT_FAILURE );
}
} else {
strncpy(saltb,encryptedpw,2);
saltb[2]='\0';
if( ( encryptedinput = crypt( pass, saltb ) ) == NULL ) {
fprintf( stderr, "Fehler beim verschluesseln");
exit( EXIT_FAILURE );
}
}
// verschluessle passwort
if (strcmp(encryptedinput, encryptedpw) == 0) {
printf("%s\n\n","LOGIN ERFOLGREICH!!!");
} else {
printf("%s\n\n","LOGIN FEHLGESCHLAGEN!!!");
}
exit( EXIT_SUCCESS );
}