Exemplo n.º 1
0
Arquivo: setpw.c Projeto: jdreed/moira
int set_password(char *user, char *password, char *domain, char *msg)
{
  int             res_code;
  krb5_error_code retval;
  char            pw[PW_LENGTH+1];
  int newpasswd = 0;

  memset(pw, '\0', sizeof(pw));
  if (strlen(password) != 0)
    {
      strcpy(pw, password);
      newpasswd = 1;
    }
  else
    {
      generate_password(pw);
      newpasswd = 0;
    }
  res_code = 0;

  retval = kdc_set_password(context, ccache, pw, user, domain, &res_code,
			    admin_server);

  if (res_code)
    return(res_code);

  return(retval);
}
Exemplo n.º 2
0
//if attr_value is NULL we generate the password, else we use the one received
int create_stun_password(char *attr_value,unsigned int len,t_stun_username *username,t_stun_password *password)//apare doar in shared secret response
{
    char *pass;
    unsigned int passlen;
    
    if (attr_value == NULL) //generam noi
    {
	//if (generate_string_attr(PASSWORD,&pass,&passlen)<0)	return -1;
	if (generate_password(username->value,username->len,another_private_key,strlen(another_private_key),&pass,&passlen)<0)	return -1;
	password->len = passlen;
	memcpy(password->value,pass,passlen);
	free(pass);
    }
    else
    {
	if (len % 4 != 0) return -2;
	password->len = len;
	memcpy(password->value,attr_value,len);
    }

    password->header.type = PASSWORD;
    password->header.len = password->len;
    
    return 1;
}
Exemplo n.º 3
0
int main(int argc, char** argv)
{
    char *enc;
    char *password;

    if(argc < 2) {
        printf("error : wrong arguments\n");
        return 1;
    }

    password = argv[1];
    enc = generate_password(ENCRYPT_SHA_512, password);
    printf("SHA-512 - %ld Encrypted \n %s\n", strlen(enc), enc);
    enc = generate_password(ENCRYPT_SHA_256, password);
    printf("SHA-256 - %ld Encrypted \n %s\n", strlen(enc), enc);
    return 0;
}
Exemplo n.º 4
0
Arquivo: main.c Projeto: pbleser/mdp
void
print_passwords(int length, int count)
{
	char password[MAX_PASSWORD_LENGTH];
	int i;

	for (i = 0; i < count; i++) {
		generate_password(password, length, "NCL");
		printf("%s\n", password);
	}
}
Exemplo n.º 5
0
// Generate password
void generate_pass (char * str, int * ovector, int size)
{

    // Get password length
    char lngth_str[16];
    sprintf(lngth_str, "%.*s", ovector[2*(size-1)+1] - ovector[2*(size-1)], str + ovector[2*(size-1)]);
    int length = atoi(lngth_str);

    // Generate password and show it
    char * pass = generate_password(length);
    if (pass != NULL) {
        printf("%s\n", pass);
        free(pass);
    }
}
Exemplo n.º 6
0
void
random_password(char *pw, size_t len)
{
#ifdef OTP_STYLE
    {
        OtpKey newkey;

        krb5_generate_random_block(&newkey, sizeof(newkey));
        otp_print_stddict (newkey, pw, len);
        strlwr(pw);
    }
#else
    char *pass;
    generate_password(&pass, 3,
                      "abcdefghijklmnopqrstuvwxyz", 7,
                      "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 2,
                      "@$%&*()-+=:,/<>1234567890", 1);
    strlcpy(pw, pass, len);
    memset(pass, 0, strlen(pass));
    free(pass);
#endif
}
Exemplo n.º 7
0
static void send_with_encryption(gpointer compose)
{
	GSList *alist, *cur;
	GHashTable *hash;
	SylPluginAttachInfo *ainfo;
	gboolean duplicated = FALSE;
	GtkWidget *dialog;
	gchar *password;
	const gchar *tmp_path;
	const gchar *arc_path;
	gchar *zip_path;
	gchar *filename;
	GString *cmdline;
	gint ret;
	gchar *orig_to;
	gchar *orig_cc;
	gchar *orig_bcc;
	gchar *orig_replyto;
	gchar *orig_subject;
	gchar *subject;
	gchar *body;
	gchar send_date[80];

	/* Check attachments */
	alist = syl_plugin_get_attach_list(compose);
	if (!alist) {
		syl_plugin_alertpanel_message(_("No attachment"), _("There is no attachment. Please attach files before sending."), 3);
		return;
	}
	hash = g_hash_table_new(str_case_hash, str_case_equal);
	for (cur = alist; cur != NULL; cur = cur->next) {
		const gchar *base;
		ainfo = (SylPluginAttachInfo *)cur->data;
		debug_print("attach: file: %s (%s) name: %s\n", ainfo->file, ainfo->content_type, ainfo->name);
		base = g_basename(ainfo->file);
		if (g_hash_table_lookup(hash, base)) {
			duplicated = TRUE;
			break;
		} else {
			g_hash_table_insert(hash, (gpointer)base, (gpointer)base);
		}
	}
	g_hash_table_destroy(hash);
	if (duplicated) {
		syl_plugin_alertpanel_message(_("Duplicate filename"), _("There are duplicate filenames. Multiple files with same name cannot be attached."), 3);
		return;
	}

	/* Get recipients */
	orig_to = syl_plugin_compose_entry_get_text(compose, 0);
	orig_cc = syl_plugin_compose_entry_get_text(compose, 1);
	orig_bcc = syl_plugin_compose_entry_get_text(compose, 2);
	orig_replyto = syl_plugin_compose_entry_get_text(compose, 3);
	orig_subject = syl_plugin_compose_entry_get_text(compose, 4);
	if (orig_to) g_strstrip(orig_to);
	if (orig_cc) g_strstrip(orig_cc);
	if (orig_bcc) g_strstrip(orig_bcc);

	if ((!orig_to || *orig_to == '\0') &&
	    (!orig_cc || *orig_cc == '\0') &&
	    (!orig_bcc || *orig_bcc == '\0')) {
		syl_plugin_alertpanel_message(_("No recipients"), _("Recipient is not specified."), 3);
		g_free(orig_subject);
		g_free(orig_replyto);
		g_free(orig_bcc);
		g_free(orig_cc);
		g_free(orig_to);
		return;
	}

	/* Show processing dialog */
	dialog = autoenc_processing_dialog_create();

	/* Generate password */
	password = generate_password();

	/* Generate encrypted zip */
	filename = generate_filename();
	tmp_path = get_autoenc_tmp_dir();
	if (!is_dir_exist(tmp_path)) {
		make_dir(tmp_path);
	}
	arc_path = get_7z_path();
	zip_path = g_strconcat(tmp_path, G_DIR_SEPARATOR_S,
			       filename, NULL);
	cmdline = g_string_new("");
	if (arc_path) {
		g_string_append_printf(cmdline, "\"%s\\7z\" a -y ", arc_path);
	} else {
		g_string_append(cmdline, "7z a -y ");
	}
	g_string_append(cmdline, "-p");
	g_string_append(cmdline, password);
	g_string_append(cmdline, " ");
	g_string_append_printf(cmdline, "\"%s\"", zip_path);
	for (cur = alist; cur != NULL; cur = cur->next) {
		ainfo = (SylPluginAttachInfo *)cur->data;
		g_string_append(cmdline, " ");
		g_string_append_printf(cmdline, "\"%s\"", ainfo->file);
	}
	debug_print("cmdline: %s\n", cmdline->str);
	ret = execute_command_line_async_wait(cmdline->str);

	/* Close processing dialog */
	gtk_widget_destroy(dialog);

	// check if zip was really created
	if (ret != 0 || !is_file_exist(zip_path) || get_file_size(zip_path) <= 0) {
		gchar message[256];

		if (ret < 0) {
			g_snprintf(message, sizeof(message), _("Error occurred while creating encrypted zip file.\n\n7z command could not be executed. Please check if 7-Zip is correctly installed."));
		} else if (ret > 0) {
			g_snprintf(message, sizeof(message), _("Error occurred while creating encrypted zip file.\n\n7z command returned error (%d)"), ret);
		} else {
			g_snprintf(message, sizeof(message), _("Encrypted zip file could not be created."));
		}
		syl_plugin_alertpanel_message(_("Encrypted zip file creation error"), message, 3);
		g_string_free(cmdline, TRUE);
		g_free(zip_path);
		g_free(filename);
		g_free(password);
		g_free(orig_subject);
		g_free(orig_replyto);
		g_free(orig_bcc);
		g_free(orig_cc);
		g_free(orig_to);
		g_slist_free(alist);
		return;
	}
	g_string_free(cmdline, TRUE);
	g_slist_free(alist);

	/* Replace attachments */
	syl_plugin_compose_attach_remove_all(compose);
	syl_plugin_compose_attach_append(compose, zip_path, filename,
					 "application/zip");

	/* Send */
	get_rfc822_date(send_date, sizeof(send_date));
	ret = syl_plugin_compose_send(compose, TRUE);
	if (ret != 0) {
		g_free(zip_path);
		g_free(filename);
		g_free(password);
		g_free(orig_subject);
		g_free(orig_replyto);
		g_free(orig_bcc);
		g_free(orig_cc);
		g_free(orig_to);
		return;
	}

	/* Create password mail */
	subject = create_password_mail_subject(orig_subject, send_date, filename, password);
	body = create_password_mail_body(orig_subject, send_date, filename, password);
	debug_print("%s\n", body);

	compose = syl_plugin_compose_new(NULL, NULL, body, NULL);
	syl_plugin_compose_entry_set(compose, orig_to, 0);
	syl_plugin_compose_entry_set(compose, orig_cc, 1);
	if (orig_bcc && *orig_bcc != '\0')
		syl_plugin_compose_entry_set(compose, orig_bcc, 2);
	if (orig_replyto && *orig_replyto != '\0')
		syl_plugin_compose_entry_set(compose, orig_replyto, 3);
	syl_plugin_compose_entry_set(compose, subject, 4);

	/* Cleanup */
	g_free(body);
	g_free(subject);
	g_free(zip_path);
	g_free(filename);
	g_free(password);
	g_free(orig_subject);
	g_free(orig_replyto);
	g_free(orig_bcc);
	g_free(orig_cc);
	g_free(orig_to);
}
Exemplo n.º 8
0
int main(int argc, char *argv[])
{
    int rc=0, passlen=0;
    FILE *outfp = NULL;
    char outfile[1024];
    unsigned char pass_input[MAX_PASSWD_BUF],
                  pass[MAX_PASSWD_BUF];
    int file_count = 0;
    unsigned char bom[2];
    int password_acquired = 0;

    while ((rc = getopt(argc, argv, "vhg:p:o:")) != -1)
    {
        switch (rc)
        {
            case 'h':
                usage(argv[0]);
                return 0;
            case 'v':
                version(argv[0]);
                return 0;
            case 'g':
                if (password_acquired)
                {
                    fprintf(stderr, "Error: password supplied twice\n");
                    return -1;
                }
                if (optarg != 0)
                {
                    passlen = generate_password(atoi((char*) optarg),
                                                pass);
                    if (passlen < 0)
                    {
                        return -1;
                    }
                }
                password_acquired = 1;
                break;
            case 'p':
                if (password_acquired)
                {
                    fprintf(stderr, "Error: password supplied twice\n");
                    return -1;
                }
                if (optarg != 0)
                {
                    passlen = passwd_to_utf16(  (unsigned char*) optarg,
                                                strlen((char *)optarg),
                                                MAX_PASSWD_LEN,
                                                pass);
                    if (passlen < 0)
                    {
                        return -1;
                    }
                }
                password_acquired = 1;
                break;
            default:
                fprintf(stderr, "Error: Unknown option '%c'\n", rc);
        }
    }
    
    file_count = argc - optind;
    if (file_count != 1)
    {
        fprintf(stderr, "Error: A single output file must be specified.\n");
        usage(argv[0]);
        // For security reasons, erase the password
        memset(pass, 0, MAX_PASSWD_BUF);
        return -1;
    }
    else
    {
        /* What is the filename for the key file? */
        strncpy(outfile, argv[optind++], 1024);
        outfile[1023] = '\0';
    }

    // Prompt for password if not provided on the command line
    if (passlen == 0)
    {
        passlen = read_password(pass_input, ENC);

        switch (passlen)
        {
            case 0: //no password in input
                fprintf(stderr, "Error: No password supplied.\n");
                return -1;
            case AESCRYPT_READPWD_FOPEN:
            case AESCRYPT_READPWD_FILENO:
            case AESCRYPT_READPWD_TCGETATTR:
            case AESCRYPT_READPWD_TCSETATTR:
            case AESCRYPT_READPWD_FGETC:
            case AESCRYPT_READPWD_TOOLONG:
                fprintf(stderr, "Error in read_password: %s.\n",
                        read_password_error(passlen));
                return -1;
            case AESCRYPT_READPWD_NOMATCH:
                fprintf(stderr, "Error: Passwords don't match.\n");
                return -1;
        }

        passlen = passwd_to_utf16(  pass_input,
                                    strlen((char*) pass_input),
                                    MAX_PASSWD_LEN,
                                    pass);

        if (passlen < 0)
        {
            // For security reasons, erase the password
            memset(pass, 0, MAX_PASSWD_BUF);
            return -1;
        }
    }

    if(!strcmp("-", outfile))
    {
        outfp = stdout;
    }
    else if ((outfp = fopen(outfile, "w")) == NULL)
    {
        fprintf(stderr, "Error opening output file %s : ", outfile);
        perror("");
        // For security reasons, erase the password
        memset(pass, 0, MAX_PASSWD_BUF);
        return  -1;
    }

    /* Write the BOM.  AES Crypt uses UTF-16LE */
    bom[0] = 0xFF;
    bom[1] = 0xFE;
    if (fwrite(bom, 1, 2, outfp) != 2)
    {
        fprintf(stderr, "Error: Could not write BOM to password file.\n");
        if (strcmp("-",outfile))
        {
            fclose(outfp);
        }
        cleanup(outfile);
        return  -1;
    }
    
    if (fwrite(pass, 1, passlen, outfp) != passlen)
    {
        fprintf(stderr, "Error: Could not write password file.\n");
        if (strcmp("-",outfile))
        {
            fclose(outfp);
        }
        cleanup(outfile);
        return  -1;
    }

    /* Close the output file, so long as it is not stdout */
    if (strcmp("-",outfile))
    {
        fclose(outfp);
    }

    // For security reasons, erase the password
    memset(pass, 0, MAX_PASSWD_BUF);

    return rc;
}
Exemplo n.º 9
0
c_token c_mint::emit_token () {
	long long token_pss = generate_password();
	c_token token(token_pss);
	m_emited_tokens.insert({token, token_pss});
	return token;
}
Exemplo n.º 10
0
// Benchmark for genpassword
#include <stdio.h>
#include <string.h>

#include "../src/genpassword.c"
#include "../deps/bench/bench.c"

int main() {
	BENCHMARK(genpassword, 3)

	char *password = generate_password(15);
	free(password);

	END_BENCHMARK(genpassword)
	BENCHMARK_SUMMARY(genpassword);

	return 0;
}
Exemplo n.º 11
0
static ret_t
config_server (cherokee_server_t *srv)
{
	ret_t                  ret;
	cherokee_config_node_t conf;
	cuint_t                nthreads;
	cherokee_buffer_t      buf       = CHEROKEE_BUF_INIT;
	cherokee_buffer_t      rrd_dir   = CHEROKEE_BUF_INIT;
	cherokee_buffer_t      rrd_bin   = CHEROKEE_BUF_INIT;
	cherokee_buffer_t      fake;

	/* Generate the password
	 */
	if (unsecure == 0) {
		ret = generate_password (&password);
		if (ret != ret_ok)
			return ret;
	}

	/* Configure the embedded server
	 */
	if (scgi_port > 0) {
		ret = find_empty_port (scgi_port, &scgi_port);
	} else {
		ret = remove_old_socket (DEFAULT_UNIX_SOCKET);
	}
	if (ret != ret_ok) {
		return ret_error;
	}

	cherokee_buffer_add_va  (&buf, "server!bind!1!port = %d\n", port);
	cherokee_buffer_add_str (&buf, "server!ipv6 = 1\n");
	cherokee_buffer_add_str (&buf, "server!max_connection_reuse = 0\n");
	cherokee_buffer_add_va  (&buf, "server!iocache = %d\n", iocache);

	if (bind_to) {
		cherokee_buffer_add_va (&buf, "server!bind!1!interface = %s\n", bind_to);
	}

	if (thread_num != -1) {
		/* Manually set
		 */
		cherokee_buffer_add_va (&buf, "server!thread_number = %d\n", thread_num);
	} else {
		/* Automatically set
		 */
		nthreads = MIN (cherokee_cpu_number, THREAD_MAX_AUTO);
		cherokee_buffer_add_va (&buf, "server!thread_number = %d\n", nthreads);
	}

	cherokee_buffer_add_str (&buf, "vserver!1!nick = default\n");
	cherokee_buffer_add_va  (&buf, "vserver!1!document_root = %s\n", document_root);

	if (scgi_port <= 0) {
		cherokee_buffer_add_va  (&buf,
					 "source!1!nick = app-logic\n"
					 "source!1!type = interpreter\n"
					 "source!1!timeout = " TIMEOUT "\n"
					 "source!1!host = %s\n"
					 "source!1!interpreter = %s/server.py %s %s %s\n"
					 "source!1!env_inherited = 1\n",
					 DEFAULT_UNIX_SOCKET, document_root,
					 DEFAULT_UNIX_SOCKET, config_file,
					 (debug) ? "-x" : "");

	} else {
		cherokee_buffer_add_va  (&buf,
					 "source!1!nick = app-logic\n"
					 "source!1!type = interpreter\n"
					 "source!1!timeout = " TIMEOUT "\n"
					 "source!1!host = localhost:%d\n"
					 "source!1!interpreter = %s/server.py %d %s %s\n"
					 "source!1!env_inherited = 1\n",
					 scgi_port, document_root,
					 scgi_port, config_file,
					 (debug) ? "-x" : "");
	}

	if (debug) {
		cherokee_buffer_add_str  (&buf, "source!1!debug = 1\n");
	}

	cherokee_buffer_add_str  (&buf,
				  RULE_PRE "1!match = default\n"
				  RULE_PRE "1!handler = scgi\n"
				  RULE_PRE "1!timeout = " TIMEOUT "\n"
				  RULE_PRE "1!handler!balancer = round_robin\n"
				  RULE_PRE "1!handler!balancer!source!1 = 1\n");

	cherokee_buffer_add_str  (&buf, RULE_PRE "1!handler!env!CTK_COOKIE = ");
	generate_password  (&buf);
	cherokee_buffer_add_char (&buf, '\n');

	cherokee_buffer_add_str  (&buf, RULE_PRE "1!handler!env!CTK_SUBMITTER_SECRET = ");
	generate_password  (&buf);
	cherokee_buffer_add_char (&buf, '\n');

	if (! debug) {
		cherokee_buffer_add_str (&buf, RULE_PRE "1!encoder!gzip = 1\n");
	}

	if ((unsecure == 0) &&
	    (!cherokee_buffer_is_empty (&password)))
	{
		cherokee_buffer_add_va (&buf,
					RULE_PRE "1!auth = authlist\n"
					RULE_PRE "1!auth!methods = digest\n"
					RULE_PRE "1!auth!realm = Cherokee-admin\n"
					RULE_PRE "1!auth!list!1!user = admin\n"
					RULE_PRE "1!auth!list!1!password = %s\n",
					password.buf);
	}

	cherokee_buffer_add_str (&buf,
				 RULE_PRE "2!match = directory\n"
				 RULE_PRE "2!match!directory = /about\n"
				 RULE_PRE "2!handler = server_info\n");

	cherokee_buffer_add_str (&buf,
				 RULE_PRE "3!match = directory\n"
				 RULE_PRE "3!match!directory = /static\n"
				 RULE_PRE "3!handler = file\n"
				 RULE_PRE "3!expiration = time\n"
				 RULE_PRE "3!expiration!time = 30d\n");

	cherokee_buffer_add_va  (&buf,
				 RULE_PRE "4!match = request\n"
				 RULE_PRE "4!match!request = ^/favicon.ico$\n"
				 RULE_PRE "4!document_root = %s/static/images\n"
				 RULE_PRE "4!handler = file\n"
				 RULE_PRE "4!expiration = time\n"
				 RULE_PRE "4!expiration!time = 30d\n",
				 document_root);

	cherokee_buffer_add_va  (&buf,
				 RULE_PRE "5!match = directory\n"
				 RULE_PRE "5!match!directory = /icons_local\n"
				 RULE_PRE "5!handler = file\n"
				 RULE_PRE "5!document_root = %s\n"
				 RULE_PRE "5!expiration = time\n"
				 RULE_PRE "5!expiration!time = 30d\n",
				 CHEROKEE_ICONSDIR);

	cherokee_buffer_add_va  (&buf,
				 RULE_PRE "6!match = directory\n"
				 RULE_PRE "6!match!directory = /CTK\n"
				 RULE_PRE "6!handler = file\n"
				 RULE_PRE "6!document_root = %s/CTK/static\n"
				 RULE_PRE "6!expiration = time\n"
				 RULE_PRE "6!expiration!time = 30d\n",
				 document_root);

	/* Embedded help
	 */
	cherokee_buffer_add_va  (&buf,
				 RULE_PRE "7!match = and\n"
				 RULE_PRE "7!match!left = directory\n"
				 RULE_PRE "7!match!left!directory = /help\n"
				 RULE_PRE "7!match!right = not\n"
				 RULE_PRE "7!match!right!right = extensions\n"
				 RULE_PRE "7!match!right!right!extensions = html\n"
				 RULE_PRE "7!handler = file\n");

	cherokee_buffer_add_va  (&buf,
				 RULE_PRE "8!match = fullpath\n"
				 RULE_PRE "8!match!fullpath!1 = /static/help_404.html\n"
				 RULE_PRE "8!handler = file\n"
				 RULE_PRE "8!document_root = %s\n", document_root);

	cherokee_buffer_add_va  (&buf,
				 RULE_PRE "9!match = and\n"
				 RULE_PRE "9!match!left = directory\n"
				 RULE_PRE "9!match!left!directory = /help\n"
				 RULE_PRE "9!match!right = not\n"
				 RULE_PRE "9!match!right!right = exists\n"
				 RULE_PRE "9!match!right!right!match_any = 1\n"
				 RULE_PRE "9!handler = redir\n"
				 RULE_PRE "9!handler!rewrite!1!show = 1\n"
				 RULE_PRE "9!handler!rewrite!1!substring = /static/help_404.html\n");

	cherokee_buffer_add_va  (&buf,
				 RULE_PRE "10!match = directory\n"
				 RULE_PRE "10!match!directory = /help\n"
				 RULE_PRE "10!match!final = 0\n"
				 RULE_PRE "10!document_root = %s\n", CHEROKEE_DOCDIR);

	/* GZip
	 */
	if (! debug) {
		cherokee_buffer_add_va (&buf,
					RULE_PRE "15!match = extensions\n"
					RULE_PRE "15!match!extensions = css,js,html\n"
					RULE_PRE "15!match!final = 0\n"
					RULE_PRE "15!encoder!gzip = 1\n");
	}

	/* RRDtool graphs
	 */
	cherokee_config_node_init (&conf);
	cherokee_buffer_fake (&fake, config_file, strlen(config_file));

	ret = cherokee_config_reader_parse (&conf, &fake);
	if (ret == ret_ok) {
		cherokee_config_node_copy (&conf, "server!collector!rrdtool_path", &rrd_bin);
		cherokee_config_node_copy (&conf, "server!collector!database_dir", &rrd_dir);
	}

	if (! cherokee_buffer_is_empty (&rrd_bin)) {
		cherokee_buffer_add_va  (&buf,
					 RULE_PRE "20!handler!rrdtool_path = %s\n", rrd_bin.buf);
	}

	if (! cherokee_buffer_is_empty (&rrd_dir)) {
		cherokee_buffer_add_va  (&buf,
					 RULE_PRE "20!handler!database_dir = %s\n", rrd_dir.buf);
	}

	cherokee_buffer_add_str (&buf,
				 RULE_PRE "20!match = directory\n"
				 RULE_PRE "20!match!directory = /graphs\n"
				 RULE_PRE "20!handler = render_rrd\n"
				 RULE_PRE "20!expiration = epoch\n"
				 RULE_PRE "20!expiration!caching = no-cache\n"
				 RULE_PRE "20!expiration!caching!no-store = 1\n");

	cherokee_buffer_add_str    (&buf, RULE_PRE "20!document_root = ");
	cherokee_buffer_add_buffer (&buf, &cherokee_tmp_dir);
	cherokee_buffer_add_va     (&buf, "/rrd-cache\n");

	/* MIME types
	 */
	cherokee_buffer_add_str (&buf,
				 "mime!text/javascript!extensions = js\n"
				 "mime!text/css!extensions = css\n"
				 "mime!image/png!extensions = png\n"
				 "mime!image/jpeg!extensions = jpeg,jpg\n"
				 "mime!image/svg+xml!extensions = svg,svgz\n"
				 "mime!image/gif!extensions = gif\n");

	ret = cherokee_server_read_config_string (srv, &buf);
	if (ret != ret_ok) {
		PRINT_ERROR_S ("Could not initialize the server\n");
		return ret;
	}

	cherokee_config_node_mrproper (&conf);

	cherokee_buffer_mrproper (&rrd_bin);
	cherokee_buffer_mrproper (&rrd_dir);
	cherokee_buffer_mrproper (&buf);

	return ret_ok;
}
Exemplo n.º 12
0
int main(int argc, char *argv[])
{
   signal(SIGINT, INThandler);
   signal(SIGQUIT, INThandler);
   signal(SIGTERM, INThandler);

   while(flag) 
   {

      int sock;
      struct sockaddr_in serv_add_password;
      struct sockaddr_in client_add_password;
      unsigned int client_add_length;
      char password_buffer[8];
      unsigned short serv_port_password;
      int msg_size = 0; 

    	char *password;

      if(argc == 4)
      {
         password = argv[3];
      }
      else if(argc == 3)
      {
         password = generate_password(atoi(argv[2]));
      }
      else
      {
         printf("Input not valid.\n");
         printf("Input should look like this: passwordServer serverPort N initialPassword(optional)\n");
         exit(1);
      }

    	serv_port_password = atoi(argv[1]);

      printf("Creating Socket...\n");
      if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
         error("Unable to create socket.");

      memset(&serv_add_password, 0, sizeof(serv_add_password));
      serv_add_password.sin_family = AF_INET;
      serv_add_password.sin_addr.s_addr = htonl(INADDR_ANY);
      serv_add_password.sin_port = htons(serv_port_password);

      printf("Binding to port %d...\n", serv_port_password);
      if (bind(sock, (struct sockaddr *) &serv_add_password, sizeof(serv_add_password)) < 0)
         error("Unable to bind to port.");

    	while(flag)
    	{
         client_add_length = sizeof(client_add_password); 
  
         if (((msg_size = recvfrom(sock, password_buffer, 7, 0,
            (struct sockaddr *) &client_add_password, &client_add_length)) >= 0) && (flag == true))
         {
            add_address(client_add_password);
            total_num_recieved++;

            if(strcmp(password, password_buffer) == 0)
            {
               if (sendto(sock, "SUCCESS", 7, 0, 
                     (struct sockaddr *) &client_add_password, sizeof(client_add_password)) != 7)
               {
                  error("Unexpected number of bytes received.");
               }

               password = generate_password(atoi(argv[2]));
               num_correct++;
            }
            else if(strcmp(password, password_buffer) < 0)
            {
               if (sendto(sock, "FAILURE", 7, 0, 
                  (struct sockaddr *) &client_add_password, sizeof(client_add_password)) != 7)
               {
                  error("Unexpected number of bytes received.");
               }
            }
         }
         else
         {
            if(msg_size < 0)
               error("Receive failed.");
            if(!flag) 
            {
               //do nothing
            }
         }
      }
   }

   printf("Number of message received = %d\n",total_num_recieved);
   printf("Number of correct password = %d\n", num_correct);
   printf("Addresses recieved from:\n");
   for(int j = 1; j <= num_addresses_received; j++) 
   {
      printf("%s\n", addresses_received[j]);
   }

	return 0;
}