mirror of
https://tinyplantnews.com/git2/ldaphotos
synced 2025-01-10 10:25:15 +00:00
Quicksaving before first run on coldspringsharbor.
Added manipulations.c, which turns an array of bytes into their hex representation. Added a completely useless test suite. Added manifesto.tex, which is, well, a dramatic name for my notes to self and plan. Added local.schema, which will be used by LDAP later on when actually registering the photos in a database.
This commit is contained in:
parent
980784ea29
commit
39a69c947e
8
.gitignore
vendored
8
.gitignore
vendored
@ -2,6 +2,14 @@
|
||||
build/
|
||||
objects/
|
||||
|
||||
# Aux files generated by ldaphotos executable
|
||||
*.aux
|
||||
|
||||
# Aux and log files generated by LaTeX when compiling manifesto.tex
|
||||
manifesto.aux
|
||||
manifesto.pdf
|
||||
manifesto.log
|
||||
|
||||
# Autosave files
|
||||
*~
|
||||
*#
|
||||
|
5
Makefile
5
Makefile
@ -17,8 +17,8 @@ INSTDIR := /usr/local/bin
|
||||
|
||||
REFACTOR := refactor.h
|
||||
|
||||
TESTCFLAGS:= $(pkg-config --cflags criterion)
|
||||
TESTLIBS := $(pkg-config --libs criterion)
|
||||
TESTCFLAGS:= $(shell pkg-config --cflags criterion)
|
||||
TESTLIBS := $(shell pkg-config --libs criterion)
|
||||
TESTDIR := $(SRCDIR)/test
|
||||
TESTOD := $(OBJDIR)/test
|
||||
|
||||
@ -41,6 +41,7 @@ OBJECTS := $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(SOURCES))
|
||||
|
||||
CPPFLAGS := -I$(abspath $(INCDIR)) -MMD -MP -DUSE_LIBNOTIFY -DUSE_SYSLOG
|
||||
CFLAGS := -Wall -Werror -Wpedantic $(shell pkg-config --cflags libnotify) -ggdb
|
||||
|
||||
LDFLAGS := #-Lmath or whatever
|
||||
LDLIBS := $(shell pkg-config --libs libnotify libcrypto) #-lm or whatever
|
||||
|
||||
|
6
local.schema
Normal file
6
local.schema
Normal file
@ -0,0 +1,6 @@
|
||||
attributeType ( 69.420 NAME ( '' '' )
|
||||
DESC ''
|
||||
EQUALITY caseIgnoreMatch
|
||||
SUBSTR caseIgnoreSubstringsMatch
|
||||
SYNTAX
|
||||
)
|
79
manifesto.tex
Normal file
79
manifesto.tex
Normal file
@ -0,0 +1,79 @@
|
||||
\documentclass[12pt]{article}
|
||||
|
||||
\def\thetitle{LDAPhotos Manifesto}
|
||||
\def\myname{Sandy Mossgrave}
|
||||
\def\theprof{LDAP}
|
||||
\def\theclass{LDAPhotos}
|
||||
\title{\thetitle}
|
||||
\author{\myname}
|
||||
\def\shorttitle{\thetitle}
|
||||
|
||||
\usepackage{geometry}
|
||||
\geometry{letterpaper, portrait, margin=1in}
|
||||
|
||||
% Package imports!
|
||||
\usepackage{hyperref}
|
||||
\usepackage{fancyhdr}
|
||||
\usepackage{lastpage}
|
||||
\usepackage{graphicx}
|
||||
\usepackage[utf8]{inputenc}
|
||||
\usepackage{twemojis}
|
||||
\usepackage{cancel}
|
||||
\usepackage{tikz}
|
||||
\usepackage{amsmath}
|
||||
\usepackage{nicefrac}
|
||||
|
||||
\graphicspath{ {./images} }
|
||||
|
||||
\setlength{\parskip}{1ex}
|
||||
\setlength{\parindent}{0pt}
|
||||
\setlength{\jot}{8pt} % Nicer spacing for the lines in an amsmath split environment
|
||||
|
||||
\iffalse
|
||||
\url{windy.com}
|
||||
\fi
|
||||
|
||||
% Unnumbered Equation Command - Mimics the \begin{equation} environment without a number
|
||||
\newcommand{\unneqn}[1]{\center{\Large{$#1$}}}
|
||||
|
||||
\renewcommand{\headrulewidth}{0pt}
|
||||
|
||||
\fancypagestyle{firstpagestyle}
|
||||
{
|
||||
\fancyhf{}
|
||||
\renewcommand{\headrulewidth}{0pt}
|
||||
\fancyhead[RO,RE]{\thepage/\pageref*{LastPage} \myname \\ \today}
|
||||
\fancyhead[LO,LE]{\shorttitle}
|
||||
\fancyfoot[]{}
|
||||
}
|
||||
|
||||
\fancyhead[RO,RE]{\thepage/\pageref*{LastPage} \myname\\ \today}
|
||||
\fancyhead[LO,LE]{\shorttitle}
|
||||
\fancyfoot[]{}
|
||||
|
||||
\begin{document}
|
||||
\pagestyle{fancy}
|
||||
\thispagestyle{firstpagestyle}
|
||||
\begin{center}
|
||||
\Large{\textbf{ \thetitle }}
|
||||
\end{center}
|
||||
|
||||
\section*{To-Do List}
|
||||
|
||||
\begin{itemize}
|
||||
\item Obtain object identifier
|
||||
\item Choose name prefix
|
||||
\item create local schema file
|
||||
\item define custom attribute types
|
||||
\item define custom object classes
|
||||
\end{itemize}
|
||||
|
||||
\newcommand\localschema{\textit{local.schema}}
|
||||
|
||||
\begin{itemize}
|
||||
\item Add a \localschema into \textit{/usr/local/etc/openldap/schema/}
|
||||
\item In \textit{slapd.conf} add an include directive for the above \localschema
|
||||
\item
|
||||
\end{itemize}
|
||||
|
||||
\end{document}
|
@ -10,23 +10,23 @@ static int hasher_initialized = 0;
|
||||
int init_hasher(void){
|
||||
if(hasher_initialized){
|
||||
printf("hasher already initialized");
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
md = EVP_MD_fetch(NULL, "SHA256", NULL);
|
||||
if(md == NULL){
|
||||
ERR_print_errors_fp(stderr);
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
md_ctx = EVP_MD_CTX_new();
|
||||
/*TODO: see whether EVP_MD_CTX_new() ever fails?*/
|
||||
if(md_ctx == NULL){
|
||||
ERR_print_errors_fp(stderr);
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int deinit_hasher(void){
|
||||
|
@ -22,7 +22,7 @@ const char * currtime(void);
|
||||
#define log(Y, ...) syslog(Y, __VA_ARGS__)
|
||||
#endif
|
||||
#ifndef USE_SYSLOG
|
||||
#define log(Y, ...) printf("%s %s", currtime(), __VA_ARGS__)
|
||||
#define log(Y, ...) fprintf(stderr, "%s %s", currtime(), __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#define verb(...) if(run_verbose)log(LOG_DEBUG, __VA_ARGS__)
|
||||
|
@ -2,6 +2,9 @@
|
||||
* Main.h: contains definitions for ldaphotos.c
|
||||
*/
|
||||
|
||||
#ifndef LDAPHOTOS
|
||||
#define LDAPHOTOS
|
||||
|
||||
#define VERSION "v0.0"
|
||||
#define TITLE "LDAP Photo Album, by Catluck Kettlemerry"
|
||||
#define PROGNAME "ldaphotos"
|
||||
@ -18,3 +21,14 @@
|
||||
#define OPTIONS8 ""
|
||||
#define OPTIONS9 ""
|
||||
#define OPTIONS10 "\t-p Print the effects of the given options for this invocation"
|
||||
|
||||
void print_help(void){
|
||||
printf("%s %s\n", TITLE, VERSION);
|
||||
printf("%s %s %s\n", USAGE0, PROGNAME, USAGE1);
|
||||
printf("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
|
||||
OPTIONS0, OPTIONS1, OPTIONS2, OPTIONS3, OPTIONS4,
|
||||
OPTIONS5, OPTIONS6, OPTIONS7, OPTIONS8, OPTIONS9,
|
||||
OPTIONS10);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
6
sources/include/manipulations.h
Normal file
6
sources/include/manipulations.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef MANIPULATIONS
|
||||
#define MANIPULATIONS
|
||||
|
||||
char * atohex(unsigned char * a, size_t len, unsigned int * aalen);
|
||||
|
||||
#endif
|
@ -1,6 +1,9 @@
|
||||
#include <stdio.h> // printf
|
||||
#include <string.h> // memcpy
|
||||
#include <unistd.h> // getopt
|
||||
#include <libgen.h> // dirname/basename
|
||||
#include <limits.h> // realpath
|
||||
#include <stdlib.h> // realpath
|
||||
|
||||
#ifdef USE_SYSLOG
|
||||
#include <syslog.h>
|
||||
@ -9,6 +12,7 @@
|
||||
#include "hasher.h"
|
||||
#include "log.h"
|
||||
#include "main.h"
|
||||
#include "manipulations.h"
|
||||
|
||||
#define PATHBUF 4097
|
||||
#define BUFLEN 2048
|
||||
@ -18,13 +22,73 @@ int run_terse = 0;
|
||||
int force_print_parameters = 0;
|
||||
|
||||
|
||||
void print_help(void){
|
||||
printf("%s %s\n", TITLE, VERSION);
|
||||
printf("%s %s %s\n", USAGE0, PROGNAME, USAGE1);
|
||||
printf("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
|
||||
OPTIONS0, OPTIONS1, OPTIONS2, OPTIONS3, OPTIONS4,
|
||||
OPTIONS5, OPTIONS6, OPTIONS7, OPTIONS8, OPTIONS9,
|
||||
OPTIONS10);
|
||||
FILE * get_outfile(FILE *infile, const char * filepath){
|
||||
FILE* outfile;
|
||||
if(infile == stdin){
|
||||
outfile = stdout;
|
||||
} else {
|
||||
//Taken from man dirname(3)
|
||||
|
||||
const char * extension = ".aux";
|
||||
size_t extlen = sizeof(extension);
|
||||
char * filepath2 = realpath(filepath, NULL);
|
||||
if(run_verbose){
|
||||
printf("Realpath for infile is %s\n", filepath2);
|
||||
}
|
||||
size_t outpathlen = strlen(filepath2) + 3 + extlen;
|
||||
char * outpath = (char*)malloc(outpathlen);
|
||||
char *dirc = strdup(filepath2);
|
||||
char *basec = strdup(filepath2);
|
||||
char *dir = dirname(dirc);
|
||||
char *base = basename(basec);
|
||||
int pathlen;
|
||||
snprintf(outpath, outpathlen, "%s/.%s%s", dir, base, extension);
|
||||
free(dirc);
|
||||
free(basec);
|
||||
free(filepath2);
|
||||
if(run_verbose){
|
||||
printf("Committing hash to auxiliary file %s\n", outpath);
|
||||
}
|
||||
(void)pathlen;
|
||||
outfile = fopen(outpath, "w");
|
||||
}
|
||||
return outfile;
|
||||
}
|
||||
|
||||
/*
|
||||
Give blocks of data to the message digest algorithm.
|
||||
*/
|
||||
size_t digest_file(FILE * infile){
|
||||
|
||||
/*
|
||||
Set up input buffers
|
||||
*/
|
||||
// unsigned char * in stores the unsigned version of signin
|
||||
unsigned char * in = (unsigned char*)malloc(BUFLEN * sizeof *in);
|
||||
/* End set up buffers*/
|
||||
|
||||
size_t bytesdigested = 0;
|
||||
unsigned int round = 0;
|
||||
while(!feof(infile) && !ferror(infile)){
|
||||
round++;
|
||||
size_t bytesread = fread((unsigned char*)in, sizeof(char), sizeof(char) * BUFLEN, infile);
|
||||
if(bytesread==0){
|
||||
verb("0 bytes read, breaking");
|
||||
break;
|
||||
}
|
||||
digest_part(in, bytesread);
|
||||
bytesdigested += bytesread;
|
||||
verb("Passed %lu bytes to digest algorithm in round %u, %lu bytes passed so far", bytesread, round, bytesdigested);
|
||||
}
|
||||
if(run_verbose){
|
||||
printf("Input:\n\t");
|
||||
for(int i = 0; i < bytesdigested; i++){
|
||||
printf("%02x ", in[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
free(in);
|
||||
return bytesdigested;
|
||||
}
|
||||
|
||||
int main(int argc, char *const argv[]){
|
||||
@ -33,9 +97,9 @@ int main(int argc, char *const argv[]){
|
||||
openlog(PROGNAME, 0, LOG_USER);
|
||||
#endif
|
||||
|
||||
char *filepath = (char*)malloc(sizeof(char) * PATHBUF);
|
||||
|
||||
int opt;
|
||||
char *filepath = (char*)malloc(PATHBUF * sizeof *filepath);
|
||||
|
||||
int opt;
|
||||
while((opt = getopt(argc, argv, "vhtpf:")) != -1) {
|
||||
switch(opt){
|
||||
case 'v':
|
||||
@ -76,28 +140,18 @@ int main(int argc, char *const argv[]){
|
||||
printf(PROGNAME " will read input from standard input\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(init_hasher()){
|
||||
if(!init_hasher()){
|
||||
log(LOG_INFO, "Error encountered while initializing hasher");
|
||||
}
|
||||
|
||||
begin_digest();
|
||||
|
||||
/*
|
||||
Set up input buffers
|
||||
*/
|
||||
// unsigned char * in stores the unsigned version of signin
|
||||
unsigned char * in = (unsigned char*)malloc(sizeof(unsigned char) * BUFLEN);
|
||||
char * signin = (char*)malloc(sizeof(char) * BUFLEN);
|
||||
/* End set up buffers*/
|
||||
|
||||
/*
|
||||
Set up the input stream
|
||||
Try to open file pointed to by filepath, or else use stdin
|
||||
*/
|
||||
*/
|
||||
FILE * infile;
|
||||
if(strlen(filepath) >= 0){
|
||||
log(LOG_DEBUG, "Trying to open file %s for input", filepath);
|
||||
@ -108,57 +162,45 @@ int main(int argc, char *const argv[]){
|
||||
}
|
||||
/* End set up the input stream */
|
||||
|
||||
/*
|
||||
Give blocks of data to the message digest algorithm.
|
||||
*/
|
||||
size_t bytesdigested = 0;
|
||||
unsigned int round = 0;
|
||||
while(!feof(infile) && !ferror(infile)){
|
||||
round++;
|
||||
size_t bytesread = fread(signin, sizeof(char), sizeof(char) * BUFLEN, infile);
|
||||
if(bytesread==0){
|
||||
printf("0 bytes read, breaking");
|
||||
break;
|
||||
}
|
||||
memcpy(in, signin, bytesread);
|
||||
digest_part(in, bytesread);
|
||||
bytesdigested += bytesread;
|
||||
verb("Passed %lu bytes to digest algorithm in round %u, %lu bytes passed so far", bytesread, round, bytesdigested);
|
||||
size_t bytesdigested = digest_file(infile);
|
||||
(void)bytesdigested;
|
||||
|
||||
if(infile != stdin){
|
||||
fclose(infile);
|
||||
}
|
||||
/* End give blocks of data to the message digest algorithm */
|
||||
|
||||
printf("Input:\n\t");
|
||||
for(int i = 0; i < bytesdigested; i++){
|
||||
printf("%02x ", in[i]);
|
||||
}
|
||||
printf("\n\t");
|
||||
for(int i = 0; i < bytesdigested; i++){
|
||||
printf(" %c ", in[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
unsigned int len;
|
||||
unsigned char * a = get_digest(&len);
|
||||
char * aa = (char*)malloc(sizeof(char) * 2 * len);
|
||||
printf("Output:\n\t");
|
||||
for(int i = 0; i < len; i++){
|
||||
sprintf(aa + (2 * i), "%02x", a[i]);
|
||||
unsigned int aalen;
|
||||
char *aa = atohex(a, len, &aalen);
|
||||
|
||||
FILE * outfile = get_outfile(infile, filepath);
|
||||
/*
|
||||
Commit hash to auxiliary file
|
||||
*/
|
||||
if(run_verbose){
|
||||
printf("Output:\n\t");
|
||||
}
|
||||
printf("%s\n", aa);
|
||||
if(run_verbose && outfile != stdout){
|
||||
fwrite(aa, sizeof(*aa), aalen, stdout);
|
||||
}
|
||||
size_t bytes_written = 0;
|
||||
size_t bytes_round;
|
||||
while(bytes_written < aalen && !ferror(outfile)){
|
||||
bytes_round = fwrite(aa + bytes_written, sizeof(*aa), aalen - bytes_written, outfile);
|
||||
bytes_written += bytes_round;
|
||||
verb("Round wrote %lu bytes\n", bytes_round);
|
||||
}
|
||||
/* End commit hash to auxiliary file*/
|
||||
|
||||
OPENSSL_free(a);
|
||||
free(aa);
|
||||
if(deinit_hasher()){
|
||||
log(LOG_INFO, "Error encountered while deinitializing hasher");
|
||||
}
|
||||
|
||||
log(LOG_INFO, "hi");
|
||||
|
||||
#ifdef USE_SYSLOG
|
||||
closelog();
|
||||
#endif
|
||||
if(infile != stdin){
|
||||
fclose(infile);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
15
sources/manipulations.c
Normal file
15
sources/manipulations.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include <stdlib.h> // malloc
|
||||
#include <stdio.h> // sprintf
|
||||
|
||||
char * atohex(unsigned char * a, size_t len, unsigned int * aalen){
|
||||
char *aa;
|
||||
//two bytes of output per byte of input, plus newline
|
||||
(*aalen) = 2 * len * sizeof *aa + 1;
|
||||
aa = (char*)malloc((*aalen));
|
||||
|
||||
for(int i = 0; i < len; i++){
|
||||
sprintf(aa + (2 * i), "%02x", a[i]);
|
||||
}
|
||||
aa[(*aalen)-1] = '\n';
|
||||
return aa;
|
||||
}
|
38
sources/test/test.c
Normal file
38
sources/test/test.c
Normal file
@ -0,0 +1,38 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <criterion/criterion.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "manipulations.h"
|
||||
#include "hasher.h"
|
||||
#include "log.h"
|
||||
|
||||
#ifdef USE_LIBNOTIFY
|
||||
#include <libnotify/notify.h>
|
||||
#endif
|
||||
|
||||
Test(misc, passing){
|
||||
cr_assert(1, "ya boi");
|
||||
}
|
||||
|
||||
Test(misc, hashsomething){
|
||||
|
||||
if(!init_hasher()){
|
||||
log(LOG_INFO, "Error encountered while initializing hasher");
|
||||
}
|
||||
|
||||
begin_digest();
|
||||
|
||||
|
||||
unsigned int len;
|
||||
unsigned int aalen;
|
||||
unsigned char * a = get_digest(&len);
|
||||
char *aa = atohex(a, len, &aalen);
|
||||
|
||||
|
||||
|
||||
free(aa);
|
||||
}
|
Loading…
Reference in New Issue
Block a user