OwnCloud Modifikationen

//Compile Command:
//rm -frv mysql_user_check; clear; g++ -g -Wall -o mysql_user_check mysql_user_check.cpp -L/usr/lib64/mysql -lmysqlclient; ./mysql_user_check;
//rm -frv mysql_user_check;clear; g++ -g -c -O2 -Wall -o sha1.o sha1.c ;g++ -g -c -O2 -Wall -o mysql_user_check.o mysql_user_check.cpp; g++ -Wall -g -o mysql_user_check mysql_user_check.o sha1.o -L/usr/lib64/mysql -lmysqlclient;  ./mysql_user_check;
//quick compile command: g++ -g -c -O2 -Wall -o mysql_user_check.o mysql_user_check.cpp; g++ -Wall -g -o mysql_user_check mysql_user_check.o sha1.o -L/usr/lib64/mysql -lmysqlclient;
//TO DO:
//Wenn nur ein Parameter übergeben wird, Abbruch verhindern.
//Assert einbauen
//via Samba Home Share mounten
//LDAP Abgleichs Check welche AD User vailde sind und welche nicht und ggf. aus DB löschen.

#include <mysql/mysql.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <cstdio>
#include <sstream>
#include "sha1.h"

using namespace std;

int main(int argc, char *argv[])
{
	//Via ARGV, Passwort aus PHP nach CPP übergeben.
	
	MYSQL *mysql_handle;
	MYSQL_RES *result;
	MYSQL_ROW row;
	char *query;
	int mysql_status_code;
	int reihen_nummer;
	int zellen_nummer;

	mysql_handle = mysql_init(NULL);

	//cout<<"Mysql Handle: "<<mysql_handle<<endl;

	//mysql_real_connect(mysql_handle,"127.0.0.1","root","Passwort!","test_datenbank",0,NULL,0);
	mysql_real_connect(mysql_handle,"127.0.0.1","root","Passwort!","owncloud3",0,NULL,0);
	
	//query="SELECT * FROM `owncloud3`.`oc_users`;";
	//query="INSERT INTO `owncloud3`.`oc_users` (`uid`, `password`) VALUES ('USER', '60c6d277a8bd81de7fdde19201bf9c58a3df08f4');";
	//query="SELECT * FROM `owncloud3`.`oc_users` WHERE uid='test2';";
	//cout<<"User: "<<argv[1]<<"\n";
	
	string user;
	user=argv[1];
	string password;
	password=argv[2];
	//cout<<"USER: "<<user<<"\n";
	//cout<<"Passowrd: "<<password<<"\n";
	string query_string;
	query_string = "SELECT * FROM `owncloud3`.`oc_users` WHERE uid='" + user + "';";
	//query_string = "INSERT INTO `owncloud3`.`oc_users` (`uid`, `password`) VALUES ('" + user + "', '" + password + "');";
	query = (char *) query_string.c_str();
	
	//cout<<"SQL Query: "<<query<<endl;
	
	mysql_status_code=mysql_real_query(mysql_handle,query,(unsigned int) strlen(query));
	//cout<<"mysql status code: "<<mysql_status_code<<endl;
	
	if (mysql_status_code > 0)
		{
			//cout<<"Fehler mit dem SQL Server: "<<mysql_error(mysql_handle)<<endl;;
		}
	else 
		{
			//cout<<"Query erfolgreich !!"<<endl;
		}
	
	result=mysql_use_result(mysql_handle);
	//cout<<"MYsql Result: "<<result<<endl;

	//cout<<"Filed count: "<<mysql_field_count<<endl<<endl;

	for(reihen_nummer=0;reihen_nummer<=mysql_field_count(mysql_handle);reihen_nummer++)
	{
		row=mysql_fetch_row(result);

		//cout<<"row: "<<row<<endl;
		/*
		if(row==0)
		{
			cout<<"Ende des Datenbank Inhalts !!"<<endl;
			break;
		}
		*/
		/*
		for(zellen_nummer=0; zellen_nummer < mysql_num_fields(result); zellen_nummer++)
		{
			cout<<"Zelleninhalt: "<<row[zellen_nummer]<<endl;
			//Check ob User Bereits in Datenbank, wenn ja nichts machen wenn nicht eintragen
		}
		
		cout<<endl;
		*/
		if (row > 0)
			{
				//cout<<"Gefunden\n";
				//Wenn gefunden nichts machen
				exit(0);
			}
		else
			{
				//cout<<"NICHT Gefunden\n";
				//Wenn nicht gefunden user anlegen. SHA1 Engine anbinden.
				//################################################################################################
					SHA1Context sha; //SHA1 wird initialisiert

					//char text[] = {"user"}; //Klartext String der berechnet werden soll
					char *text = {(char *) password.c_str()}; //Klartext String der berechnet werden soll

					//cout<<"SHA1 Klartext: "<<text<<endl;

					int status = 0;

					//cout<<"Textlaenge: "<<strlen(text)<<endl;

					status = SHA1Reset(&sha);

					//cout<<"SHA1Reset: "<<status<<endl;

					status = SHA1Input(&sha,(const unsigned char *) text, strlen(text)); //Klartext Daten werden berechnet

					//cout<<"SHA1Input: "<<status<<endl;

					uint8_t Message_Digest[20];
					//char Message_Digest[20];

					SHA1Result(&sha, Message_Digest);
						
					string sha1_password;
						//###############################################
						
						//###############################################
					for(int i = 0; i < 20 ; ++i)
					{
						//printf("%02X", Message_Digest[i]); //Ausgabe des SHA1 Hashes
						//printf("%02X", Message_Digest[i]); //Ausgabe des SHA1 Hashes
						//cout << "  0x" << hex << uppercase << setprecision(2) << setfill('0') << setw(2) << Message_Digest[i];
						//cout << "  0x" << hex << uppercase << Message_Digest[i];
						//cout<<i<<endl;
						//cout<<Message_Digest[i];
						//password_vector.push_back(reinterpret_cast<const char*>(Message_Digest[i]));
						//password_vector.push_back((const char*)Message_Digest[i]);
						//cout<<hex<<Message_Digest[i];
						//printf("%s", Message_Digest[i]);
						//cout << "0x" << setfill('0') << setw(2) << hex << Message_Digest[i] << endl;
						//char_pass = Message_Digest[i];
						//strcat(char_pass,(char *)Message_Digest[i]);
						//(void)Uart2_Transmit(*char_pass,30,NULL);
						//memcpy (char_pass,Message_Digest[i],strlen(Message_Digest[i]));
						//Message_Digest[i] = ($ID.text->chars);
						//typeName.append(1,*widget); 
						//Message_Digest[i] = new char char_pass[Message_Digest[i]];
						//cout<<Message_Digest[i];
						//cout << (unsigned int)Message_Digest[i];
						//cout <<hex<< (unsigned int)Message_Digest[i];		//So geht die Ausgabe auch
						
						ostringstream sha1_dezimal;
						sha1_dezimal << hex << (unsigned int)Message_Digest[i];
						sha1_password.append(sha1_dezimal.str());
						/*
						std::stringstream ConvertStream;
						ConvertStream<<	(unsigned int)Message_Digest[i];
						ConvertStream>>password;
						*/
					}
					//cout<<sha1_password<<endl;
					//cout << "0x" << setfill('0') << setw(2) << hex << 10 << endl;

					//printf("%02X", Message_Digest[19]); 
					//password = Message_Digest[19];
					//cout<<password[19]<<endl;
					//cout<<Message_Digest[19]<<endl;
				//################################################################################################
					
					query_string = "INSERT INTO `owncloud3`.`oc_users` (`uid`, `password`) VALUES ('"+ user +" ', '" + sha1_password +"');";
					query = (char *) query_string.c_str(); 
					mysql_status_code=mysql_real_query(mysql_handle,query,(unsigned int) strlen(query));
					exit(0);
			}
		
	}
	
	mysql_close(mysql_handle);
	
	//Home Shares via Samba in User Verzeichnis mounten.
	//Kommando: mount -t cifs //wdf-filer02/user$ //usr/local/apache2/htdocs/owncloud/data/user.user\@domain.net/files/home_share/ -o user=user,uid=daemon
	//schauen ob homeshare schon gemounted.
	
	//system("mount -t cifs //wdf-filer02/user$ //usr/local/apache2/htdocs/owncloud/data/user.user\@domain.net/files/home_share/ -o user=user,uid=daemon");
	
}


Post Revisions: