Last active
August 4, 2023 13:41
-
-
Save kou1okada/29d77a8bcf22373a67a5 to your computer and use it in GitHub Desktop.
LSA (Local Security Authority) configration tool.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dump_comp_stat () # | |
# Dump bash completion status. | |
{ | |
local -a COMP_TYPE_DESC=( | |
[ 9]=" 9 # HT : normal completion" | |
[33]="33 # ! : listing alternatives on partial word completion" | |
[37]="37 # % : menu completion" | |
[63]="63 # ? : listing completions after successive tabs" | |
[64]="64 # @ : list completions if the word is not unmodified" | |
) | |
# Display variables for completion | |
echo | |
echo "prev : $prev" | |
echo "cur : $cur" | |
echo "COMP_CWORD : $COMP_CWORD" | |
echo "COMP_KEY : $COMP_KEY" | |
echo "COMP_LINE : $COMP_LINE" | |
echo "COMP_POINT : $COMP_POINT" | |
echo "COMP_TYPE : ${COMP_TYPE_DESC[COMP_TYPE]}" | |
echo "COMP_WORDBREAKS : ${COMP_WORDBREAKS@Q})" | |
echo "#COMP_WORDS[@] : ${#COMP_WORDS[@]}" | |
local i | |
for i in "${!COMP_WORDS[@]}"; do | |
echo "COMP_WORDS[$i] : ${COMP_WORDS[i]}" | |
done | |
for i in "${!COMPREPLY[@]}"; do | |
echo "COMPREPLY[$i] : ${COMPREPLY[i]}" | |
done | |
# Redisplay the prompt | |
if (( COMP_TYPE == 9 )); then | |
echo -n "${PS1@P}$COMP_LINE" | |
(( ${#COMP_LINE} > ${COMP_POINT} )) \ | |
&& echo -en "\e[$((${#COMP_LINE}-${COMP_POINT}))D" | |
fi | |
} | |
function __lsaconfig () | |
{ | |
local cur prev | |
_get_comp_words_by_ref -n : cur prev | |
if (( ${#COMP_WORDS[@]} == 2 )); then | |
COMPREPLY=( lmcompatibilitylevel --help -h ) | |
fi | |
if (( ${#COMP_WORDS[@]} == 3 )) && [ ${COMP_WORDS[-2]} = lmcompatibilitylevel ]; then | |
COMPREPLY=( 0 1 2 3 4 5 ) | |
fi | |
[ -n "$COMP_DEBUG" ] && { | |
dump_comp_stat | |
echo | |
cat <<-EOD | |
compgen -W "${COMPREPLY[*]@Q}" -- "$cur" | |
EOD | |
} | |
readarray -t COMPREPLY < <(compgen -W "${COMPREPLY[*]@Q}" -- "$cur") | |
[ -n "$COMP_DEBUG" ] && { | |
echo "" | |
compgen -W "${COMPREPLY[*]@Q}" -- "$cur" | |
dump_comp_stat | |
} | |
} | |
complete -F __lsaconfig lsaconfig.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Copyright (c) 2014 kou1okada. All rights reserved. | |
# This script is distributed under the MIT license. | |
function usage () | |
{ | |
cat <<EOD | |
Usage: ${SCRIPT_FILE} subcommand | |
Subcommands: | |
lmcompatibilitylevel [Security-level] | |
LM Compatibility Level: | |
Security-level Clients DCs Default | |
0 LN,NTLM LM,NTLM,NTLMv2 XP | |
1 LM,NTLM,NTLMv2 LM,NTLM,NTLMv2 | |
2 NTLM,NTLMv2 LM,NTLM,NTLMv2 2003 | |
3 NTLMv2 LM,NTLM,NTLMv2 Vista/2008,7/2008R2 | |
4 NTLM,NTLMv2 NTLM,NTLMv2 | |
5 NTLMv2 NTLMv2 | |
EOD | |
} | |
function lsaconfig-help () | |
{ | |
usage | |
} | |
# @reference | |
# for LmCompatibilityLevel | |
# [MS-NLMP]: NT LAN Manager (NTLM) Authentication Protocol | |
# http://msdn.microsoft.com/en-us/library/cc236621%28prot.20%29.aspx | |
# What is the default level setting for NTLMv2 for different Windows editions? | |
# http://social.msdn.microsoft.com/Forums/en-US/41ed0ba1-6a0f-4d5d-87de-401082a10a0c/what-is-the-default-level-setting-for-ntlmv2-for-different-windows-editions?forum=os_windowsprotocols | |
# @reference | |
# for sudo | |
# There's no 'sudo' command in Cygwin | |
# http://superuser.com/questions/122418/theres-no-sudo-command-in-cygwin | |
function lsaconfig-lmcompatibilitylevel () | |
{ | |
local KEYNAME='HKLM\SYSTEM\CurrentControlSet\Control\Lsa' | |
local VALNAME='LmCompatibilityLevel' | |
if [ 0 -lt $# ]; then | |
cygstart --wait --hide --action=runas REG ADD "$KEYNAME" /v "$VALNAME" /t "REG_DWORD" /d "$1" /f | |
fi | |
REG QUERY "$KEYNAME" /v "$VALNAME" | |
} | |
function parse_args () | |
{ | |
local UNKNOWN_OPTION | |
while [ $# -gt 0 ]; do | |
case "$1" in | |
--help|-h) | |
usage | |
exit 0 | |
;; | |
-*) | |
UNKNOWN_OPTION="$1" | |
break | |
;; | |
*) | |
ARGS+=( "$1" ) | |
shift | |
;; | |
esac | |
done | |
if [ -n "$UNKNOWN_OPTION" ]; then | |
error "Unknown option: $unknown_option" | |
exit 1 | |
fi | |
if [ $# -gt 0 ]; then | |
error "Number of parameters is not enough: $@" | |
exit 1 | |
fi | |
} #/parse_args | |
function error () | |
{ | |
echo -e "\e[31;1m${BASH_SOURCE[0]}: In function '${FUNCNAME[1]}':\e[30;0m" | |
echo -e "\e[31;1m${BASH_SOURCE[0]}:${BASH_LINENO[0]}: error:\e[30;0m $@" | |
exit 1 | |
} > /dev/stderr | |
function invoke_subcommand () | |
{ | |
local SUBCOMMAND="${@:1:1}" | |
local ARGS=( "${@:2}" ) | |
local ACTION="${SCRIPT_NAME}-${SUBCOMMAND:-help}" | |
if type "$ACTION" >& /dev/null; then | |
"$ACTION" "${ARGS[@]}" | |
else | |
error "unknown subcommand: $SUBCOMMAND" | |
exit 1 | |
fi | |
} #/invoke_subcommand | |
SCRIPT_PATH="$0" | |
SCRIPT_FILE="${SCRIPT_PATH##*/}" | |
SCRIPT_NAME="${SCRIPT_FILE%.*}" | |
SCRIPT_DIR="${SCRIPT_PATH%/*}" | |
parse_args "$@" | |
invoke_subcommand "${ARGS[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment