def main(wait_thread):
    parser = parse()
    args, unknown_args = parser.parse_known_args()
    wait_thread.start()

#    if os.path.basename(sys.argv[0]) != 'cl-console':
#        args.method = '_temp_'
#        args.host = 'localhost'

    if not args.method and args.help:
        wait_thread.stop()
        sys.stdout.write('\r')
        sys.stdout.flush()
        parser.print_help()
        return 0

    if not args.method:
        if unknown_args:
            wait_thread.stop()
            sys.stdout.write('\r')
            sys.stdout.flush()
            args = parser.parse_args()

    logging.basicConfig(level=logging.FATAL)
    logging.getLogger('sudsds.client').setLevel(logging.FATAL)
    logging.getLogger('sudsds.transport').setLevel(logging.FATAL)
    logging.getLogger('sudsds.transport.http').setLevel(logging.FATAL)
    logging.getLogger('sudsds.umx.typed').setLevel(logging.ERROR)

    clVarsCore = DataVarsCore()
    clVarsCore.importCore()
    clVarsCore.flIniFile()

    homePath = clVarsCore.Get('ur_home_path')

    port = args.port
    host = args.host
    path_to_cert = args.path_to_cert
    if not path_to_cert:
        path_to_cert = clVarsCore.Get('core.cl_client_cert_dir')
    path_to_cert = path_to_cert.replace("~",homePath)

    for dirs in ['', 'ca', 'trusted']:
        dir_path = os.path.join(path_to_cert, dirs)
        if not os.path.isdir(dir_path):
            if not makeDirectory(dir_path):
                wait_thread.stop()
                sys.stdout.write('\r')
                sys.stdout.flush()
                print _("Failed to create directory %s") %dir_path
                return 1

    if args.update_crl:
        wait_thread.stop()
        getCRL = threading.Thread(target=get_CRL, args = (path_to_cert, ))
        getCRL.start()
        getCRL.join()
        print 'GRL updated'
        return 0

    if args.by_host:
        wait_thread.stop()
        client_post_request (path_to_cert, args)
        return 0
    if args.from_host:
        wait_thread.stop()
        client_get_cert (path_to_cert, args)
        return 0

    url = "https://%s:%d/?wsdl" %(host, port)

    clear()
    serv_hostname = get_server_hostname(host, path_to_cert)
    get_name_flag = False
    if serv_hostname:
        Connect_Error = 1
        crypto_Error = 0
        client, Connect_Error, crypto_Error, passwd_flag, e = \
                    connect_with_cert (serv_hostname, path_to_cert, url, args,
                         wait_thread, clVarsCore, crypto_Error, Connect_Error)
        if not wait_thread.isAlive():
            wait_thread = StoppableThread()
            wait_thread.start()
        get_name_flag = True
        if Connect_Error:
            if crypto_Error and passwd_flag:
                wait_thread.stop()
                sys.stdout.write('\r')
                sys.stdout.flush()
                print _('Invalid password')
                # delete password from daemon list
                clear_password(host, port)
            elif e:
                wait_thread.stop()
                if type(e.message) != int:
                    print _('Error: '), e
            get_name_flag = False

    if get_name_flag:
        try:
            client.port = port
            return_val = 1
            try:
                return_val = https_server(client, args, unknown_args, url, \
                                          clVarsCore, wait_thread)
            except urllib2.URLError, e:
                print _('Error: '), e
            except KeyboardInterrupt:
                wait_thread.stop()
                red = '\n'+'\033[31m * \033[0m'
                print red + _("Manually interrupted")
            except Exception, e:
                wait_thread.stop()
                if type(e.message) != int:
                    if e.message:
                        print e.message
                    elif e.args:
                        print e
#                    tb.print_exc()
                return 1
            wait_thread.stop()
            return return_val
Exemple #2
0
        return 1
    req_id = create_request(server_cert, cert_path, data_path, certbase, \
                            client_cert_path, user_name)
    sign_certificate(req_id, cert_path, data_path)
    get_certificate(cert_path,data_path,certbase,client_cert_path,user_name)

def check_user_path(user_name):
    try:
        pwdObj = pwd.getpwnam(user_name)
    except KeyError, e:
        print e
        return None

    home_dir = pwdObj.pw_dir
    if not os.path.isdir(home_dir):
        if not makeDirectory(home_dir):
            return None
        os.chown(home_dir, pwdObj.pw_uid, pwdObj.pw_gid)
        os.chmod(home_dir, 0700)
    calc_dir = os.path.join(home_dir, '.calculate')
    cert_dir = os.path.join(calc_dir, 'client_cert')
    for directory in [calc_dir, cert_dir]:
        if not os.path.isdir(directory):
            if not makeDirectory(directory):
                return None
        os.chown(directory, pwdObj.pw_uid, pwdObj.pw_gid)
        os.chmod(directory, 0755)

    for path in os.walk(cert_dir):
        os.chown(path[0], pwdObj.pw_uid, pwdObj.pw_gid)
        for _file in path[2]: