Raphael Schneeberger 7 лет назад
Родитель
Сommit
0c5f626110
3 измененных файлов с 0 добавлено и 242 удалено
  1. 0 140
      src/bash_coding_style.txt
  2. 0 5
      src/c_coding_style.txt
  3. 0 97
      src/v-check-user-password.c

+ 0 - 140
src/bash_coding_style.txt

@@ -1,140 +0,0 @@
-BASH CODING STYLE
-
-------------------------------------------------
-Contents:
-
-    1. Introduction
-    2. Naming Convention
-    3. Comments
-    4. Coding Styles
-    5. Basic formating
-    6. If, For, and While   
-    7. Use of shell builtin commands
-
-
-------------------------------------------------
-
-1. Introduction
-    The main reason for using a consistent set of coding conventions is to
-    improve the readability of the source code, allowing core team to
-    understand new code more quickly and thoroughly.
-
-
-2. Naming Convention
-    The names of files, variables and functions serve as comments of a sort.
-    So don’t choose terse names—instead, look for names that give useful
-    information about the meaning. Names should be English, like other
-    comments. They should be descriptive and correspond or to be appropriate to
-    functionality which it implements. Names should not be longer than 30
-    characters. Instead spaces use underscores to separate words in a name. And
-    it is always good idea to stick to lower case, exceptions are only global
-    or enviroment variables.
-
-        iCantReadThis.Shell             # Bad naming
-        backup_mysql_databases.sh       # Good naming
-
-        PATH='/bin:/home/user/bin'      # Global variable (capitals)
-        max_users=0                     # Local variable
-
-        print_user_password() {         #
-            echo $password              #  Function naming example
-        }                               #
-
-
-3. Comments
-    The total length of a line (including comment) must not exceed more than 80
-    characters. Every file must be documented with an introductory comment that
-    provides shorthand information on the file name and its contents.
-        #!/bin/bash
-        # info: adding web domain
-
-    Consecutive line end comments start in the same column. A blank will always
-    follow the introductory character of the comment to simplify the detection
-    of the beginning of the word.
-        cp foo bar                      # Copy foo to bar
-        rm -f foo                       # Remove foo
-
-    Use an extra '#' above and below the comment in the case of multi-line
-    comments:
-        #
-        # Modify the permissions on bar. We need to set them
-        # to root/sys in order to match the package prototype.
-        #
-        chown root bar
-        chgrp sys bar
-
-    Each script have 4 logical part Variables, Verifications, Action and Hestia.
-    Such parts should be devided by following frames.
-        #----------------------------------------------------------#
-        #                    Variable&Function                     #
-        #----------------------------------------------------------#
-
-
-5. Basic Formating
-    The indentation of program constructions has to agree with the logic
-    nesting depth. The indentation of one step usually is 4 spaces. Do not use
-    tabs in your code. You should set your editor to emit spaces when you hit
-    the tab key.
-        cp foo bar                                   
-        cp some_reallllllllly_realllllllllllllly_long_path \
-            to_another_really_long_path
-
-
-6. If, For, and While
-    To match Kernighan and Ritchie style, the sh token equivalent to the C "{"
-    should appear on the same line, separated by a ";", as in:
-        if [ $x = 'something' ]; then
-            echo "$x"
-        fi
-           
-        for i in 1 2 3; do
-            echo $i
-        done
-                   
-        while [ $# -gt 0 ]; do
-            echo $1
-            shift
-        done
-
-
-7. Use of Shell Builtin Commands
-    If possible shell buitins should be preferred to external utilities. Each
-    call of test true sed awk etc generates a new process. Used in a loop this
-    can extend the execution time considerably. So please do not write:
-        if test $# -gt 0; then
-    Instead use:
-        if [ $# -gt 0 ]; then
-
-    In the following example the shell parameter expansion is used to get the
-    base name and the directory of a path:
-        for pathname in $(find -type f -name "*" -print); do
-            basename=${pathname##*/}    # replaces basename
-            dirname=${pathname%/*}      # replaces dirname
-            dirlength=${#dirname}       # expr length
-        done
-
-    The proper way to write an infinite loop in the shell is to use the ":"
-    built-in, which evaluates to true (exit status 0). This is better than
-    using "true", because that is *not* a built-in and thus runs /bin/true.
-        while :; do
-            echo infinite loop
-        done
-
-    Do not test for non-/empty strings by comparing to "" or ''.  always use
-    the test operators -n (non-zero-length string) and -z (zero-length string).
-        if [ -z "$foo" ]; then
-            echo 'you forgot to set $foo'
-        fi
-        if [ -n "$BASEDIR" ]; then
-            echo "\$BASEDIR is set to $BASEDIR"
-        fi
-
-
-
-------------------------------------------------
-
-    BASH CODING STYLE
-    info@hestiacp.com
-    23.10.2018
-
-------------------------------------------------

+ 0 - 5
src/c_coding_style.txt

@@ -1,5 +0,0 @@
-BASH CODING STYLE
-
-Please see GNU Coding Standards
-********************
-http://www.gnu.org/prep/standards/standards.txt

+ 0 - 97
src/v-check-user-password.c

@@ -1,97 +0,0 @@
-/***************************************************************************/
-/*  v_check_user_password.c                                                */
-/*                                                                         */
-/*  This program compare user pasword from input with /etc/shadow          */
-/*  To compile run:                                                        */
-/*  "gcc v-check-user-password.c -o v-check-user-password -lcrypt"         */
-/*                                                                         */
-/*  Thanks to: bogolt, richie and burus                                    */
-/*                                                                         */
-/***************************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <pwd.h>
-#include <shadow.h>
-#include <time.h>
-#include <string.h>
-
-
-int main (int argc, char** argv) {
-    /* define ip */
-    char *ip = "127.0.0.1";
-
-    /* check argument list */
-    if (3 > argc) {
-        printf("Error: bad args\n",argv[0]);
-        printf("Usage: %s user password [ip]\n",argv[0]);
-        exit(1);
-    };
-
-    /* check ip */
-    if (4 <= argc) {
-      ip = (char*)malloc(strlen(argv[3]));
-      strcpy(ip, argv[3]);
-    }
-
-    /* format current time */
-    time_t lt = time(NULL);
-    struct tm* ptr = localtime(&lt);
-    char str[280];
-    strftime(str, 100, "%Y-%m-%d %H:%M:%S ", ptr);
-
-    /* open log file */
-    FILE* pFile = fopen ("/usr/local/hestia/log/auth.log","a+");
-    if (NULL == pFile) {
-        printf("Error: can not open file /usr/local/hestia/log/auth.log \n");
-        exit(12);
-    }
-
-    int len = 0;
-    if(strlen(argv[1]) >= 100) {
-        printf("Too long username\n");
-        exit(1);
-    }
-
-    /* parse user argument */
-    struct passwd* userinfo = getpwnam(argv[1]);
-    if (NULL != userinfo) {
-        struct spwd* passw = getspnam(userinfo->pw_name);
-        if (NULL != passw) {
-            char* cryptedPasswrd = (char*)crypt(argv[2], passw->sp_pwdp);
-            if (strcmp(passw->sp_pwdp,crypt(argv[2],passw->sp_pwdp))==0) {
-                /* concatinate time with user and ip */
-                strcat(str, userinfo->pw_name);
-                strcat(str, " ");
-                strcat(str, ip);
-                strcat(str, " successfully logged in \n");
-                fputs (str,pFile);      /* write */
-                fclose (pFile);         /* close */
-                exit(EXIT_SUCCESS);     /* exit */
-            } else {
-                /* concatinate time with user string */
-                printf ("Error: password missmatch\n");
-                strcat(str, userinfo->pw_name);
-                strcat(str, " ");
-                strcat(str, ip);
-                strcat(str, " failed to login \n");
-                fputs (str,pFile);      /* write */
-                fclose (pFile);         /* close */
-                exit(9);                /* exit */
-            };
-        }
-    } else {
-        printf("Error: no such user\n",argv[1]);
-        strcat(str, argv[1]);
-        strcat(str, " ");
-        strcat(str, ip);
-        strcat(str, " failed to login \n");
-        fputs (str,pFile);      /* write */
-        fclose (pFile);         /* close */
-        exit(3);
-    };
-
-    return EXIT_SUCCESS;
-};