📄 confparser.c
字号:
/* * confparser.c * (C) 2002 Ervin Hegedus * Released under GPL, see COPYING-2.0 for details. * * these routines are for parse the configuration file, * called by mysql_auth.conf * */#include <stdio.h>#include <syslog.h>#include <stdarg.h>#include <stdlib.h>#include <string.h>#include "define.h"int parse (struct my_params * parameters){ FILE *fp; char line[MAXLENGTH]; char *var, *value; int i = 0; // for looks the errors in config file /* * open config file, and read options * CONFIG_FILE path and name are defined in define.h * * my_params struct also defined in define.h */ if ((fp = fopen(CONFIG_FILE, "r"), fp == NULL)) { syslog (LOG_WARNING, "Can't open mysql_auth config file: %s!\n", CONFIG_FILE); return 1; } /* * setting up default values to parameters * there is not too many parameters, i didn't want * to make some difficult algorithm... */ parameters -> var_host_name = malloc (strlen (DEF_HOST_NAME) + 1); strcpy (parameters -> var_host_name, DEF_HOST_NAME); parameters -> var_user_name = malloc (strlen (DEF_USER_NAME) + 1); strcpy (parameters -> var_user_name, DEF_USER_NAME); parameters -> var_user_password = malloc (strlen (DEF_USER_PASSWORD) + 1); strcpy (parameters -> var_user_password, DEF_USER_PASSWORD); parameters -> var_database_name = malloc (strlen (DEF_DATABASE_NAME) + 1); strcpy (parameters -> var_database_name, DEF_DATABASE_NAME); parameters -> var_mysqld_socket = malloc (strlen (DEF_MYSQLD_SOCKET) + 1); strcpy (parameters -> var_mysqld_socket, DEF_MYSQLD_SOCKET); parameters -> var_table_name = malloc (strlen (DEF_TABLE_NAME) + 1); strcpy (parameters -> var_table_name, DEF_TABLE_NAME); parameters -> var_user_column = malloc (strlen (DEF_USER_COLUMN) + 1); strcpy (parameters -> var_user_column, DEF_USER_COLUMN); parameters -> var_password_column = malloc (strlen (DEF_PASSWORD_COLUMN) + 1); strcpy (parameters -> var_password_column, DEF_PASSWORD_COLUMN); parameters -> var_encrypt_password_form = malloc (strlen (DEF_ENCRYPT_PASSWORD_FORM) + 1); strcpy (parameters -> var_encrypt_password_form, DEF_ENCRYPT_PASSWORD_FORM); /* * reading and parsing lines */ while (fgets (line, MAXLENGTH, fp) != NULL) { i++; if (line[0] != '#' && line[0] != '\n') { var = strtok (line, " \t"); if (var == NULL) { syslog (LOG_WARNING, "Error in mysql_auth config file at line %d.", i); } else { value = strtok (NULL, " \t\n"); if (value == NULL) { syslog (LOG_WARNING, "Error in mysql_auth config file at line %d.", i); } else { /* * also not too many parameters, i know, this is * not nice... */ if (strcmp (var, VAR_HOST_NAME) == 0) { free (parameters -> var_host_name); parameters -> var_host_name = malloc (strlen (value) + 1); strcpy (parameters -> var_host_name, value); } if (strcmp (var, VAR_USER_NAME) == 0) { free (parameters -> var_user_name); parameters -> var_user_name = malloc (strlen (value) + 1); strcpy (parameters -> var_user_name, value); } if (strcmp (var, VAR_USER_PASSWORD) == 0) { free (parameters -> var_user_password); parameters -> var_user_password = malloc (strlen (value) + 1); strcpy (parameters -> var_user_password, value); } if (strcmp (var, VAR_DATABASE_NAME) == 0) { free (parameters -> var_database_name); parameters -> var_database_name = malloc (strlen (value) + 1); strcpy (parameters -> var_database_name, value); } if (strcmp (var, VAR_MYSQLD_SOCKET) == 0) { free (parameters -> var_mysqld_socket); parameters -> var_mysqld_socket = malloc (strlen (value) + 1); strcpy (parameters -> var_mysqld_socket, value); } if (strcmp (var, VAR_TABLE_NAME) == 0) { free (parameters -> var_table_name); parameters -> var_table_name = malloc (strlen (value) + 1); strcpy (parameters -> var_table_name, value); } if (strcmp (var, VAR_USER_COLUMN) == 0) { free (parameters -> var_user_column); parameters -> var_user_column = malloc (strlen (value) + 1); strcpy (parameters -> var_user_column, value); } if (strcmp (var, VAR_PASSWORD_COLUMN) == 0) { free (parameters -> var_password_column); parameters -> var_password_column = malloc (strlen (value) + 1); strcpy (parameters -> var_password_column, value); } if (strcmp (var, VAR_ENCRYPT_PASSWORD_FORM) == 0) { free (parameters -> var_encrypt_password_form); parameters -> var_encrypt_password_form = malloc (strlen (value) + 1); strcpy (parameters -> var_encrypt_password_form, value); } } } } } fclose (fp); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -