error: incompatible types in asignment

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 );
}
 
E

Eric Sosman

Dennis said:
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?

Arrays are not assignable in C.
char encryptedinput[20];

This should probably be `char *encryptedinput;'.
[...]
if( ( encryptedinput = crypt( pass, salta ) ) == NULL ) {

If you do not understand the difference between an array
and a pointer, please see Question 6.8 -- in fact, all of
Section 6 -- in the comp.lang.c Frequently Asked Questions
(FAQ) list at

http://www.eskimo.com/~scs/C-faq/top.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top