/* <b>check</b><em>(dict=nil)</em> * * This interfaces to LibCrack to check the strength of the password. If * _dict_ is given, it is the path to the CrackLib dictionary, minus the * file's extension. For example, if the dictionary is located at * <tt>/usr/lib/cracklib_dict.pwd</tt>, _dict_ would be * <tt>/usr/lib/cracklib_dict</tt>. If it is not given, the dictionary found * at build time will be used. * * If a path is given that does not lead to a legible dictionary, a * Password::DictionaryError exception is raised. On success, +true+ is * returned. On failure, a Password::WeakPassword exception is raised. */ static VALUE passwd_check(VALUE self, VALUE args) { VALUE dict; char *objection; char *buffer; /* pop the one and only argument we may have been passed */ dict = rb_ary_pop(args); if (dict == Qnil || strcmp(STR2CSTR(dict), "") == 0) { /* no argument passed, so use default location from rbcrack.h */ dict = rb_str_new2(CRACK_DICT); } else { buffer = malloc(strlen(STR2CSTR(dict)) + 8); strcpy(buffer, STR2CSTR(dict)); strcat(buffer, ".pwd"); if (access(buffer, R_OK) != 0) { free(buffer); rb_raise(ePassword_DictionaryError, "%s", strerror(errno)); } free(buffer); } /* perform check on password */ objection = FascistCheck(STR2CSTR(self), STR2CSTR(dict)); /* return true on success; raise an exception otherwise */ if (objection) { rb_raise(ePassword_WeakPassword, "%s", objection); } else { return Qtrue; } }