Example #1
0
void main() {
  cJSON *userObject = NULL;
  char *password;
  char *fileInputTemp, *fileInput, *fileOutput;
  char filenameIn[LINE_LEN];
  char filenameOut[LINE_LEN];
  int filenameLen, passLen, fileLen;
  
  userObject = authenticateUser(FILENAME);
  if (!userObject) {
    printf("error\n");
		exit(EXIT_FAILURE); 
  } else {
		printf("Authenticated\n");
  }

	password = cJSON_GetObjectItem(userObject, "password")->valuestring; // password->valuestring
  
  while (1) {
	  printf("Please enter the filename that you wish to run encryption on (.crpt files will decrypt): ");
	  readCommand(filenameIn);
    fileCrypt(filenameIn, password);
  }
  
	exit(EXIT_SUCCESS); 
}
Example #2
0
/**
    Connecting to the target machine.

    @param none
    @return none
*/
bool SSHSession::connect(const char *username, const char *password) {
  auto rc = ssh_connect(mSSHSession);
  
  if (rc != SSH_OK) {
    auto error_msg = ssh_get_error(mSSHSession);
    throw std::runtime_error(error_msg);
  } else {
    auto isKnown = verifyKnownHost(mSSHSession); 
    
    if (isKnown) {
      connected = true;

      // authenticating the user
      rc = authenticateUser(mSSHSession, username, password);
      
      if (rc != SSH_AUTH_SUCCESS) {
        throw std::runtime_error(ssh_get_error(mSSHSession));
      } else {
        std::cout << "Successfully login" << std::endl;
        return true;
      }
    } else {
      throw std::runtime_error("Server not known.");
    }
  }
}
	int CallInAuthenticateUser::doStuff()
	{
		if (authenticateUser() == 0) {
			if (mAuthStatus == 0) {
				return getUserSession();
			}
		}
		return 0;
	}
Example #4
0
int main (void)
{
	char *username;
	char *password;
	unsigned returnCode, group;

	//incluir aceitacao SOMENTE para metodo POST. LibCGI identifica e aceita qualquer metodo

	cgi_init();
	cgi_process_form();
	
	username = cgi_param("username");
	password = cgi_param("password");
	
	//se cgi_end viesse aqui teria problema com o username?
	//a cgi_end libera a memoria alocada, e username eh um ponteiro para uma regiao alocada
	//porem em uma outra cgi, ao usar cgi_end antes de usar username, o valor de username permaneceu
	//pq?
	
	printf ("Content-type: text/html\r\n");
	
	if (!(returnCode = authenticateUser(username,password,&group)))
	{
		/*strncpy(ip,getenv("REMOTE_ADDR"),15); //Creating cookie
		createCookie(username,cookie,ip);
		printf("Set-Cookie: %s=%s; path=/",username,cookie);*/
		printf("Location: principal.cgi?uid=%s\r\n", username);
		printf("\r\n");
	}
	
	/* Mensagem de username ou senha invalido */
	else 
		if ((returnCode==WRONG_PASSWORD) || (returnCode==USER_NOT_FOUND) || (returnCode==NULL_POINTER))
		{
			printf("\r\n");
			
			printf ("<html>\n");
			printf ("<head>\n");
			printf ("	<title>Neural TB - Entrar</title>\n");
			printf ("	<!--<link rel=\"stylesheet\" type=\"text/css\" href=\"css/main.css\">-->\n");
			printf ("	<link rel=\"stylesheet\" type=\"text/css\" href=\"css/login.css\">\n");
			printf ("	<script language=javascript src=\"../js/funcoes.js\"></script>\n");
			printf ("	</head>\n");
			printf ("\n");
			printf ("	<body onLoad=\"login.username.focus()\">\n");
			printf ("	<div align=\"center\">\n");
			printf ("\n");
			printf ("	<img src=\"../imagens/NeuralTB3.jpg\">\n");
			printf ("	<br /><br />\n");
			printf ("	<div class=\"\">\n");
			printf ("	<table>\n");
			printf ("		<tr>\n");
			printf ("			<td style=\"vertical-align:top; padding-top:8px\">\n");
			printf ("				<form name=\"login\" action=\"login.cgi\" method=\"post\">\n");
			printf ("				<table border=\"0\">\n");
			printf ("					<tr>\n");
			printf ("						<td style=\"text-align:right\">Usu&aacute;rio:</td>\n");
			printf ("						<td><input name=\"username\" type=\"text\" maxlength=18 ></td>\n");
			printf ("					</tr>\n");
			printf ("					<tr>\n");
			printf ("						<td style=\"text-align:right\">Senha:</td>\n");
			printf ("						<td><input name=\"password\" type=\"password\" maxlength=18 ></td>\n");
			printf ("					</tr>\n");
			printf ("					<tr>\n");
			printf ("						<td colspan=\"2\" height=\"15\"></td>\n");
			printf ("					</tr>\n");
			printf ("					<tr>\n");
			printf ("						<td></td>\n");
			printf ("						<td style=\"text-align:right\"><input type=\"submit\" value=\"Entrar\"></td>\n");
			printf ("					</tr>\n");
			
			if (!(username)||(!password)) {
			printf ("					<tr>\n");
			printf ("						<td colspan=\"2\" style=\"color:red\">Preencha todos os campos</td>\n");
			printf ("					</tr>\n");
			}
			
			else {
			printf ("					<tr>\n");
			printf ("						<td colspan=\"2\" style=\"color:red\">Usu&aacute;rio e senha nao correspondem</td>\n");
			printf ("					</tr>\n");
			}
			
			printf ("				</table>\n");
			printf ("				</form>\n");
			printf ("			</td>\n");
			printf ("			<td style=\"padding-left:20px\"><img src=\"../imagens/humanSmallest.jpg\" style=\"z-index:-1\"></td>\n");
			printf ("		</tr>\n");
			printf ("	</table>\n");
			printf ("	</div>\n");
			printf ("\n");
			printf ("</div>\n");
			printf ("</body>\n");
			printf ("</html>");
		}
		
		else
		{
			printf("\r\n");
			printf("Erro %u", returnCode);
		}
	
	cgi_end();

	return 0;
}
/*
 * The interface - hook to obtain an AFS token if needed based on the
 * result of a stat (returned by can_access) or an open file
 */
int
afs_auth_internal(request_rec * r, char *cell)
{
    afsassert(r);
    afsassert(r->uri);
    afsassert(cell);
    if (FIND_LINKED_MODULE("afs_module.c") != NULL) {
	int rc, status;
	char *type;
	static int haveToken = 1;	/* assume that we always have a token */
	extern int logAccessErrors;

	/*
	 * Get afs_authtype directive value for that directory or location
	 */
	type = (char *)get_afsauthtype(r);

	/* 
	 * UserDir (tilde) support
	 */
#ifndef APACHE_1_3
	if (FIND_LINKED_MODULE("mod_userdir.c") != NULL) {
	    rc = translate_userdir(r);
	    if ((rc != OK) && (rc != DECLINED)) {
		LOG_REASON("afs_module: Failure while translating userdir",
			   r->uri, r);
		return rc;
	    }
	}
#endif

	afslog(20, ("%s: pid:%d r->uri:%s", module_name, getpid(), r->uri));
	if (type)
	    afslog(20, ("%s: AFSAuthType: %s", module_name, type));
	else
	    afslog(20, ("%s: AFSAuthType NULL", module_name));

	/* if AuthType is not AFS, then unlog any existing tokens and DECLINE */
	if (type == NULL) {
	    if (haveToken)
		unlog();
	    return DECLINED;
	}

	if ((strcasecmp(type, AFS_AUTHTYPE))
	    && (strcasecmp(type, AFS_DFS_AUTHTYPE))) {
	    if (haveToken)
		unlog();
	    afslog(10,
		   ("%s: Error unknown AFSAuthType:%s returning DECLINED",
		    module_name, type));
	    return DECLINED;
	}

	if (cell)
	    status =
		authenticateUser(r, cell, afs_str->cacheExpiration, type);
	else
	    status =
		authenticateUser(r, afs_str->defaultCell,
				 afs_str->cacheExpiration, type);

	if (status != OK) {
	    afslog(10, ("%s: Returning status %d", module_name, status));
	    return status;
	}

	/* can we access this URL? */
	rc = can_access(r);

	if (rc == OK) {
	    return DECLINED;
	}

	if (rc == REDIRECT) {
	    return REDIRECT;
	}

	if (rc == FORBIDDEN) {
	    rc = forbToAuthReqd(r);
	    if (rc == FORBIDDEN) {
		if (logAccessErrors) {
		    log_Access_Error(r);
		}
	    }
	    return rc;
	}
	return DECLINED;
    }
}
Example #6
0
decltype(auto) authAndAccess(Container& c, Index i)     // but still requires
{                                                       // refinement
    authenticateUser();
    return c[i];
}
Example #7
0
decltype(auto) authAndAccess(Container&& c, Index i)    // C++14  version
{
    authenticateUser();
    return std::forward<Container>(c)[i];
}