1/* libpwquality Vala Bindings 2 * Copyright 2013 Evan Nemerson <evan@coeus-group.com> 3 * 4 * Permission is hereby granted, free of charge, to any person 5 * obtaining a copy of this software and associated documentation 6 * files (the "Software"), to deal in the Software without 7 * restriction, including without limitation the rights to use, copy, 8 * modify, merge, publish, distribute, sublicense, and/or sell copies 9 * of the Software, and to permit persons to whom the Software is 10 * furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be 13 * included in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 * SOFTWARE. 23 */ 24 25[CCode (lower_case_cprefix = "pwquality_", cheader_filename = "pwquality.h")] 26namespace PasswordQuality { 27 [CCode (cname = "int", cprefix = "PWQ_SETTING_", has_type_id = false)] 28 public enum Setting { 29 DIFF_OK, 30 MIN_LENGTH, 31 DIG_CREDIT, 32 UP_CREDIT, 33 LOW_CREDIT, 34 OTH_CREDIT, 35 MIN_CLASS, 36 MAX_REPEAT, 37 DICT_PATH, 38 MAX_CLASS_REPEAT, 39 GECOS_CHECK, 40 BAD_WORDS, 41 MAX_SEQUENCE 42 } 43 44 [CCode (cname = "int", cprefix = "PWQ_ERROR_", has_type_id = false)] 45 public enum Error { 46 SUCCESS, 47 FATAL_FAILURE, 48 INTEGER, 49 CFGFILE_OPEN, 50 CFGFILE_MALFORMED, 51 UNKNOWN_SETTING, 52 NON_INT_SETTING, 53 NON_STR_SETTING, 54 MEM_ALLOC, 55 TOO_SIMILAR, 56 MIN_DIGITS, 57 MIN_UPPERS, 58 MIN_LOWERS, 59 MIN_OTHERS, 60 MIN_LENGTH, 61 PALINDROME, 62 CASE_CHANGES_ONLY, 63 ROTATED, 64 MIN_CLASSES, 65 MAX_CONSECUTIVE, 66 EMPTY_PASSWORD, 67 SAME_PASSWORD, 68 CRACKLIB_CHECK, 69 RNG, 70 GENERATION_FAILED, 71 USER_CHECK, 72 GECOS_CHECK, 73 MAX_CLASS_REPEAT, 74 BAD_WORDS, 75 MAX_SEQUENCE; 76 77 [CCode (cname = "pwquality_strerror", instance_pos = 2.5)] 78 private void* strerror (void* buf, size_t len, void* auxerror); 79 80 public string to_string (void* auxerror = null) { 81 string ret = null; 82 string** retp = &ret; 83 *retp = GLib.malloc (PasswordQuality.MAX_ERROR_MESSAGE_LEN); 84 void* res = this.strerror (*retp, PasswordQuality.MAX_ERROR_MESSAGE_LEN, auxerror); 85 86 if ( res != *retp ) { 87 GLib.Memory.copy (*retp, res, ((string) res).length + 1); 88 } 89 90 return ret; 91 } 92 } 93 94 [CCode (cname = "PWQ_MAX_ENTROPY_BITS")] 95 public const int MAX_ENTROPY_BITS; 96 [CCode (cname = "PWQ_MIN_ENTROPY_BITS")] 97 public const int MIN_ENTROPY_BITS; 98 [CCode (cname = "PWQ_MAX_ERROR_MESSAGE_LEN")] 99 public const int MAX_ERROR_MESSAGE_LEN; 100 101 [Compact, CCode (cname = "pwquality_settings_t", lower_case_cprefix = "pwquality_", free_function = "pwquality_free_settings")] 102 public class Settings { 103 [CCode (cname = "pwquality_default_settings")] 104 public Settings (); 105 106 public PasswordQuality.Error read_config (string cfgfile, out void* auxerror); 107 public PasswordQuality.Error set_option (string option); 108 public PasswordQuality.Error set_int_value (PasswordQuality.Setting setting, int value); 109 public PasswordQuality.Error set_str_value (PasswordQuality.Setting setting, string value); 110 public PasswordQuality.Error get_int_value (PasswordQuality.Setting setting, out int value); 111 public PasswordQuality.Error get_str_value (PasswordQuality.Setting setting, out unowned string value); 112 113 public PasswordQuality.Error generate (int entropy_bits, out string password); 114 public int check (string password, string? oldpassword = null, string? user = null, out void* auxerror = null); 115 } 116} 117