nserror gui_window_save_link(struct gui_window *g, nsurl *url, const char *title) { char fname[1024]; STRPTR openurlstring,linkname; struct DiskObject *dobj = NULL; linkname = ASPrintf("Link_to_%s",FilePart(nsurl_access(url))); if(AslRequestTags(savereq, ASLFR_Window, g->shared->win, ASLFR_SleepWindow, TRUE, ASLFR_TitleText,messages_get("NetSurf"), ASLFR_Screen,scrn, ASLFR_InitialFile,linkname, TAG_DONE)) { strlcpy(fname, savereq->fr_Drawer, 1024); AddPart(fname,savereq->fr_File,1024); ami_set_pointer(g->shared, GUI_POINTER_WAIT, false); if(ami_download_check_overwrite(fname, g->shared->win, 0)) { BPTR fh; if((fh = FOpen(fname,MODE_NEWFILE,0))) { /* \todo Should be URLOpen on OS4.1 */ openurlstring = ASPrintf("openurl \"%s\"\n",nsurl_access(url)); FWrite(fh,openurlstring,1,strlen(openurlstring)); FClose(fh); FreeVec(openurlstring); SetComment(fname, nsurl_access(url)); dobj = GetIconTags(NULL,ICONGETA_GetDefaultName,"url", ICONGETA_GetDefaultType,WBPROJECT, TAG_DONE); dobj->do_DefaultTool = "IconX"; PutIconTags(fname,dobj, ICONPUTA_NotifyWorkbench,TRUE, TAG_DONE); FreeDiskObject(dobj); } FreeVec(linkname); } ami_reset_pointer(g->shared); } return NSERROR_OK; }
int32 ami_warn_user_multi(const char *body, const char *opt1, const char *opt2, struct Window *win) { int res = 0; char *utf8text = ami_utf8_easy(body); char *utf8gadget1 = ami_utf8_easy(messages_get(opt1)); char *utf8gadget2 = ami_utf8_easy(messages_get(opt2)); char *utf8gadgets = ASPrintf("%s|%s", utf8gadget1, utf8gadget2); free(utf8gadget1); free(utf8gadget2); #ifdef __amigaos4__ res = TimedDosRequesterTags(TDR_ImageType, TDRIMAGE_WARNING, TDR_TitleString, messages_get("NetSurf"), TDR_FormatString, utf8text, TDR_GadgetString, utf8gadgets, TDR_Window, win, TAG_DONE); #else struct EasyStruct easyreq = { sizeof(struct EasyStruct), 0, messages_get("NetSurf"), utf8text, utf8gadgets, }; res = EasyRequest(win, &easyreq, NULL); #endif if(utf8text) free(utf8text); if(utf8gadgets) FreeVec(utf8gadgets); return res; }
void warn_user(const char *warning, const char *detail) { Object *req = NULL; char *utf8warning = ami_utf8_easy(messages_get(warning)); STRPTR bodytext = NULL; LOG(("%s %s", warning, detail)); bodytext = ASPrintf("\33b%s\33n\n%s", utf8warning != NULL ? utf8warning : warning, detail); req = NewObject(REQUESTER_GetClass(), NULL, REQ_Type, REQTYPE_INFO, REQ_TitleText, messages_get("NetSurf"), REQ_BodyText, bodytext, REQ_GadgetText, messages_get("OK"), #ifdef __amigaos4__ REQ_VarArgs, REQ_Image, (struct Image *)REQIMAGE_WARNING, /* REQ_CharSet, 106, */ #endif TAG_DONE); if (req) { LONG result = IDoMethod(req, RM_OPENREQ, NULL, NULL, scrn); DisposeObject(req); } if(bodytext) FreeVec(bodytext); if(utf8warning) free(utf8warning); }
void warn_user(const char *warning, const char *detail) { char *utf8warning = ami_utf8_easy(messages_get(warning)); STRPTR bodytext = ASPrintf("\33b%s\33n\n%s", utf8warning != NULL ? utf8warning : warning, detail); ami_misc_req(bodytext, TDRIMAGE_WARNING); if(bodytext) FreeVec(bodytext); if(utf8warning) free(utf8warning); }
BOOL ami_download_check_overwrite(const char *file, struct Window *win, ULONG size) { /* Return TRUE if file can be (over-)written */ int32 res = 0; BPTR lock = 0; char *overwritetext; if(nsoption_bool(ask_overwrite) == false) return TRUE; lock = Lock(file, ACCESS_READ); if(lock) { if(size) { BPTR fh; int64 oldsize = 0; if((fh = OpenFromLock(lock))) { oldsize = GetFileSize(fh); Close(fh); } overwritetext = ASPrintf("%s\n\n%s %s\n%s %s", messages_get("OverwriteFile"), messages_get("amiSizeExisting"), human_friendly_bytesize((ULONG)oldsize), messages_get("amiSizeNew"), human_friendly_bytesize(size)); } else { UnLock(lock); overwritetext = ASPrintf(messages_get("OverwriteFile")); } res = amiga_warn_user_multi(overwritetext, "Replace", "DontReplace", win); FreeVec(overwritetext); } else return TRUE; if(res == 1) return TRUE; else return FALSE; }
int32 ami_warn_user_multi(const char *body, const char *opt1, const char *opt2, struct Window *win) { int res = 0; char *utf8text = ami_utf8_easy(body); char *utf8gadget1 = ami_utf8_easy(messages_get(opt1)); char *utf8gadget2 = ami_utf8_easy(messages_get(opt2)); char *utf8gadgets = ASPrintf("%s|%s", utf8gadget1, utf8gadget2); free(utf8gadget1); free(utf8gadget2); res = TimedDosRequesterTags(TDR_ImageType, TDRIMAGE_WARNING, TDR_TitleString, messages_get("NetSurf"), TDR_FormatString, utf8text, TDR_GadgetString, utf8gadgets, TDR_Window, win, TAG_DONE); if(utf8text) free(utf8text); if(utf8gadgets) FreeVec(utf8gadgets); return res; }
static void ami_menu_item_project_about(struct Hook *hook, APTR window, struct IntuiMessage *msg) { struct gui_window_2 *gwin; char *temp, *temp2; int sel; nsurl *url = NULL; nserror error; GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); ami_set_pointer(gwin, GUI_POINTER_WAIT, false); temp = ASPrintf("%s|%s|%s", messages_get("OK"), messages_get("HelpCredits"), messages_get("HelpLicence")); temp2 = ami_utf8_easy(temp); FreeVec(temp); sel = TimedDosRequesterTags(TDR_ImageType,TDRIMAGE_INFO, TDR_TitleString, messages_get("NetSurf"), TDR_Window, gwin->win, TDR_GadgetString, temp2, #ifndef NDEBUG TDR_FormatString,"NetSurf %s\n%s\nBuild date %s\n\nhttp://www.netsurf-browser.org", #else TDR_FormatString,"NetSurf %s\n%s\n\nhttp://www.netsurf-browser.org", #endif TDR_Arg1,netsurf_version, #ifdef NS_AMIGA_CAIRO TDR_Arg2,"Cairo (OS4.1+) SObjs build", #else TDR_Arg2,"graphics.library static build", #endif TDR_Arg3,verdate, TAG_DONE); free(temp2); if(sel == 2) { error = nsurl_create("about:credits", &url); } else if(sel == 0) { error = nsurl_create("about:licence", &url); } if(url) { if (error == NSERROR_OK) { error = browser_window_create(BW_CREATE_HISTORY, url, NULL, NULL, NULL); nsurl_unref(url); } if (error != NSERROR_OK) { warn_user(messages_get_errorcode(error), 0); } } ami_reset_pointer(gwin); }
HOOKF(void, ami_menu_item_project_about, APTR, window, struct IntuiMessage *) { struct gui_window_2 *gwin; char *temp, *temp2; int sel; nsurl *url = NULL; nserror error = NSERROR_OK; GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); ami_set_pointer(gwin, GUI_POINTER_WAIT, false); temp = ASPrintf("%s|%s|%s", messages_get("OK"), messages_get("HelpCredits"), messages_get("HelpLicence")); temp2 = ami_utf8_easy(temp); FreeVec(temp); #ifdef __amigaos4__ sel = TimedDosRequesterTags(TDR_ImageType,TDRIMAGE_INFO, TDR_TitleString, messages_get("NetSurf"), TDR_Window, gwin->win, TDR_GadgetString, temp2, TDR_FormatString,"NetSurf %s\nBuild date %s\n\nhttp://www.netsurf-browser.org", TDR_Arg1,netsurf_version, TDR_Arg2,verdate, TAG_DONE); #else struct EasyStruct about_req = { sizeof(struct EasyStruct), 0, "NetSurf", "NetSurf %s\nBuild date %s\n\nhttp://www.netsurf-browser.org", temp2, }; sel = EasyRequest(gwin->win, &about_req, NULL, netsurf_version, verdate); #endif free(temp2); if(sel == 2) { error = nsurl_create("about:credits", &url); } else if(sel == 0) { error = nsurl_create("about:licence", &url); } if(url) { if (error == NSERROR_OK) { error = browser_window_create(BW_CREATE_HISTORY, url, NULL, NULL, NULL); nsurl_unref(url); } if (error != NSERROR_OK) { amiga_warn_user(messages_get_errorcode(error), 0); } } ami_reset_pointer(gwin); }
int startClient( volatile int *pid ) { const char *home, *sessargs, *desksess; char **env, *xma; char **argv, *fname, *str; #ifdef USE_PAM char ** volatile pam_env; # ifndef HAVE_PAM_GETENVLIST char **saved_env; # endif int pretc; #else # ifdef _AIX char *msg; char **theenv; extern char **newenv; /* from libs.a, this is set up by setpenv */ # endif #endif #ifdef HAVE_SETUSERCONTEXT extern char **environ; #endif char *failsafeArgv[2]; char *buf, *buf2; int i; if (strCmp( dmrcuser, curuser )) { if (curdmrc) { free( curdmrc ); curdmrc = 0; } if (dmrcuser) { free( dmrcuser ); dmrcuser = 0; } } #if defined(USE_PAM) || defined(_AIX) if (!(p = getpwnam( curuser ))) { logError( "getpwnam(%s) failed.\n", curuser ); pError: displayStr( V_MSG_ERR, 0 ); return 0; } #endif #ifndef USE_PAM # ifdef _AIX msg = NULL; loginsuccess( curuser, hostname, tty, &msg ); if (msg) { debug( "loginsuccess() - %s\n", msg ); free( (void *)msg ); } # else /* _AIX */ # if defined(KERBEROS) && defined(AFS) if (krbtkfile[0] != '\0') { if (k_hasafs()) { int fail = 0; if (k_setpag() == -1) { logError( "setpag() for %s failed\n", curuser ); fail = 1; } if ((ret = k_afsklog( NULL, NULL )) != KSUCCESS) { logError( "AFS Warning: %s\n", krb_get_err_text( ret ) ); fail = 1; } if (fail) displayMsg( V_MSG_ERR, "Warning: Problems during Kerberos4/AFS setup." ); } } # endif /* KERBEROS && AFS */ # endif /* _AIX */ #endif /* !PAM */ curuid = p->pw_uid; curgid = p->pw_gid; env = baseEnv( curuser ); xma = 0; strApp( &xma, "method=", curtype, (char *)0 ); if (td_setup) strApp( &xma, ",auto", (char *)0 ); if (xma) { env = setEnv( env, "XDM_MANAGED", xma ); free( xma ); } if (td->autoLock && cursource == PWSRC_AUTOLOGIN) env = setEnv( env, "DESKTOP_LOCKED", "true" ); env = setEnv( env, "PATH", curuid ? td->userPath : td->systemPath ); env = setEnv( env, "SHELL", p->pw_shell ); env = setEnv( env, "HOME", p->pw_dir ); #if !defined(USE_PAM) && !defined(_AIX) && defined(KERBEROS) if (krbtkfile[0] != '\0') env = setEnv( env, "KRBTKFILE", krbtkfile ); #endif userEnviron = inheritEnv( env, envvars ); env = systemEnv( curuser ); systemEnviron = setEnv( env, "HOME", p->pw_dir ); debug( "user environment:\n%[|''>'\n's" "system environment:\n%[|''>'\n's" "end of environments\n", userEnviron, systemEnviron ); /* * for user-based authorization schemes, * add the user to the server's allowed "hosts" list. */ for (i = 0; i < td->authNum; i++) { #ifdef SECURE_RPC if (td->authorizations[i]->name_length == 9 && !memcmp( td->authorizations[i]->name, "SUN-DES-1", 9 )) { XHostAddress addr; char netname[MAXNETNAMELEN+1]; char domainname[MAXNETNAMELEN+1]; getdomainname( domainname, sizeof(domainname) ); user2netname( netname, curuid, domainname ); addr.family = FamilyNetname; addr.length = strlen( netname ); addr.address = netname; XAddHost( dpy, &addr ); } #endif #ifdef K5AUTH if (td->authorizations[i]->name_length == 14 && !memcmp( td->authorizations[i]->name, "MIT-KERBEROS-5", 14 )) { /* Update server's auth file with user-specific info. * Don't need to AddHost because X server will do that * automatically when it reads the cache we are about * to point it at. */ XauDisposeAuth( td->authorizations[i] ); td->authorizations[i] = krb5GetAuthFor( 14, "MIT-KERBEROS-5", td->name ); saveServerAuthorizations( td, td->authorizations, td->authNum ); } #endif } if (*dmrcDir) mergeSessionArgs( TRUE ); debug( "now starting the session\n" ); #ifdef USE_PAM # ifdef HAVE_SETUSERCONTEXT if (setusercontext( lc, p, p->pw_uid, LOGIN_SETGROUP )) { logError( "setusercontext(groups) for %s failed: %m\n", curuser ); goto pError; } # else if (!setGid( curuser, curgid )) goto pError; # endif # ifndef HAVE_PAM_GETENVLIST if (!(pam_env = initStrArr( 0 ))) { resetGids(); goto pError; } saved_env = environ; environ = pam_env; # endif removeCreds = 1; /* set it first - i don't trust PAM's rollback */ pretc = pam_setcred( pamh, 0 ); reInitErrorLog(); # ifndef HAVE_PAM_GETENVLIST pam_env = environ; environ = saved_env; # endif # ifdef HAVE_INITGROUPS /* This seems to be a strange place for it, but do it: - after the initial groups are set - after pam_setcred might have set something, even in the error case - before pam_setcred(DELETE_CRED) might need it */ if (!saveGids()) goto pError; # endif if (pretc != PAM_SUCCESS) { logError( "pam_setcred() for %s failed: %s\n", curuser, pam_strerror( pamh, pretc ) ); resetGids(); return 0; } removeSession = 1; /* set it first - same as above */ pretc = pam_open_session( pamh, 0 ); reInitErrorLog(); if (pretc != PAM_SUCCESS) { logError( "pam_open_session() for %s failed: %s\n", curuser, pam_strerror( pamh, pretc ) ); resetGids(); return 0; } /* we don't want sessreg and the startup/reset scripts run with user credentials. unfortunately, we can reset only the gids. */ resetGids(); # define D_LOGIN_SETGROUP LOGIN_SETGROUP #else /* USE_PAM */ # define D_LOGIN_SETGROUP 0 #endif /* USE_PAM */ removeAuth = 1; chownCtrl( &td->ctrl, curuid ); endpwent(); #if !defined(USE_PAM) && defined(USESHADOW) && !defined(_AIX) endspent(); #endif ctltalk.pipe = &ctlpipe; ASPrintf( &buf, "sub-daemon for display %s", td->name ); ASPrintf( &buf2, "client for display %s", td->name ); switch (gFork( &ctlpipe, buf, buf2, 0, 0, mstrtalk.pipe, pid )) { case 0: gCloseOnExec( ctltalk.pipe ); if (Setjmp( ctltalk.errjmp )) exit( 1 ); gCloseOnExec( mstrtalk.pipe ); if (Setjmp( mstrtalk.errjmp )) goto cError; #ifndef NOXDMTITLE setproctitle( "%s'", td->name ); #endif strApp( &prog, " '", (char *)0 ); reInitErrorLog(); setsid(); sessreg( td, getpid(), curuser, curuid ); /* We do this here, as we want to have the session as parent. */ switch (source( systemEnviron, td->startup, td_setup )) { case 0: break; case wcCompose( 0, 0, 127 ): goto cError; default: /* Explicit failure => message already displayed. */ logError( "Startup script returned non-zero exit code\n" ); exit( 1 ); } /* Memory leaks are ok here as we exec() soon. */ #if defined(USE_PAM) || !defined(_AIX) # ifdef USE_PAM /* pass in environment variables set by libpam and modules it called */ # ifdef HAVE_PAM_GETENVLIST pam_env = pam_getenvlist( pamh ); reInitErrorLog(); # endif if (pam_env) for (; *pam_env; pam_env++) userEnviron = putEnv( *pam_env, userEnviron ); # endif # ifdef HAVE_SETLOGIN if (setlogin( curuser ) < 0) { logError( "setlogin for %s failed: %m\n", curuser ); goto cError; } # define D_LOGIN_SETLOGIN LOGIN_SETLOGIN # else # define D_LOGIN_SETLOGIN 0 # endif # if defined(USE_PAM) && defined(HAVE_INITGROUPS) if (!restoreGids()) goto cError; # endif # ifndef HAVE_SETUSERCONTEXT # ifdef USE_PAM if (!setUid( curuser, curuid )) goto cError; # else if (!setUser( curuser, curuid, curgid )) goto cError; # endif # else /* !HAVE_SETUSERCONTEXT */ /* * Destroy environment. * We need to do this before setusercontext() because that may * set or reset some environment variables. */ if (!(environ = initStrArr( 0 ))) goto cError; /* * Set the user's credentials: uid, gid, groups, * environment variables, resource limits, and umask. */ if (setusercontext( lc, p, p->pw_uid, LOGIN_SETALL & ~(D_LOGIN_SETGROUP|D_LOGIN_SETLOGIN) ) < 0) { logError( "setusercontext for %s failed: %m\n", curuser ); goto cError; } for (i = 0; environ[i]; i++) userEnviron = putEnv( environ[i], userEnviron ); # endif /* !HAVE_SETUSERCONTEXT */ #else /* PAM || !_AIX */ /* * Set the user's credentials: uid, gid, groups, * audit classes, user limits, and umask. */ if (setpcred( curuser, NULL ) == -1) { logError( "setpcred for %s failed: %m\n", curuser ); goto cError; } /* * Set the users process environment. Store protected variables and * obtain updated user environment list. This call will initialize * global 'newenv'. */ if (setpenv( curuser, PENV_INIT | PENV_ARGV | PENV_NOEXEC, userEnviron, NULL ) != 0) { logError( "Cannot set %s's process environment\n", curuser ); goto cError; } userEnviron = newenv; #endif /* _AIX */ /* * for user-based authorization schemes, * use the password to get the user's credentials. */ #ifdef SECURE_RPC /* do like "keylogin" program */ if (!curpass[0]) logInfo( "No password for NIS provided.\n" ); else { char netname[MAXNETNAMELEN+1], secretkey[HEXKEYBYTES+1]; int nameret, keyret; int len; int key_set_ok = 0; struct key_netstarg netst; nameret = getnetname( netname ); debug( "user netname: %s\n", netname ); len = strlen( curpass ); if (len > 8) bzero( curpass + 8, len - 8 ); keyret = getsecretkey( netname, secretkey, curpass ); debug( "getsecretkey returns %d, key length %d\n", keyret, strlen( secretkey ) ); netst.st_netname = netname; memcpy( netst.st_priv_key, secretkey, HEXKEYBYTES ); memset( netst.st_pub_key, 0, HEXKEYBYTES ); if (key_setnet( &netst ) < 0) debug( "Could not set secret key.\n" ); /* is there a key, and do we have the right password? */ if (keyret == 1) { if (*secretkey) { keyret = key_setsecret( secretkey ); debug( "key_setsecret returns %d\n", keyret ); if (keyret == -1) logError( "Failed to set NIS secret key\n" ); else key_set_ok = 1; } else { /* found a key, but couldn't interpret it */ logError( "Password incorrect for NIS principal %s\n", nameret ? netname : curuser ); } } if (!key_set_ok) nukeAuth( 9, "SUN-DES-1" ); bzero( secretkey, strlen( secretkey ) ); } #endif #ifdef K5AUTH /* do like "kinit" program */ if (!curpass[0]) logInfo( "No password for Kerberos5 provided.\n" ); else if ((str = krb5Init( curuser, curpass, td->name ))) userEnviron = setEnv( userEnviron, "KRB5CCNAME", str ); else nukeAuth( 14, "MIT-KERBEROS-5" ); #endif /* K5AUTH */ if (td->autoReLogin) { gSet( &mstrtalk ); gSendInt( D_ReLogin ); gSendStr( curuser ); gSendStr( curpass ); gSendStr( newdmrc ); } if (curpass) bzero( curpass, strlen( curpass ) ); setUserAuthorization( td ); home = getEnv( userEnviron, "HOME" ); if (home && chdir( home ) < 0) { logError( "Cannot chdir to %s's home %s: %m\n", curuser, home ); sendStr( V_MSG_ERR, "Cannot enter home directory. Using /.\n" ); chdir( "/" ); userEnviron = setEnv( userEnviron, "HOME", "/" ); home = 0; } if (home || td->clientLogFile[0] == '/') { if (!createClientLog( td->clientLogFile )) { logWarn( "Session log file according to %s cannot be created: %m\n", td->clientLogFile ); goto tmperr; } } else { tmperr: if (!createClientLog( td->clientLogFallback )) logError( "Fallback session log file according to %s cannot be created: %m\n", td->clientLogFallback ); /* Could inform the user, but I guess this is only confusing. */ } if (!*dmrcDir) mergeSessionArgs( home != 0 ); if (!(desksess = iniEntry( curdmrc, "Desktop", "Session", 0 ))) desksess = "failsafe"; /* only due to OOM */ gSet( &mstrtalk ); gSendInt( D_User ); gSendInt( curuid ); gSendStr( curuser ); gSendStr( desksess ); close( mstrtalk.pipe->fd.w ); userEnviron = setEnv( userEnviron, "DESKTOP_SESSION", desksess ); for (i = 0; td->sessionsDirs[i]; i++) { fname = 0; if (strApp( &fname, td->sessionsDirs[i], "/", desksess, ".desktop", (char *)0 )) { if ((str = iniLoad( fname ))) { if (!strCmp( iniEntry( str, "Desktop Entry", "Hidden", 0 ), "true" ) || !(sessargs = iniEntry( str, "Desktop Entry", "Exec", 0 ))) sessargs = ""; free( str ); free( fname ); goto gotit; } free( fname ); } } if (!strcmp( desksess, "failsafe" ) || !strcmp( desksess, "default" ) || !strcmp( desksess, "custom" )) sessargs = desksess; else sessargs = ""; gotit: if (!(argv = parseArgs( (char **)0, td->session )) || !(argv = addStrArr( argv, sessargs, -1 ))) exit( 1 ); if (argv[0] && *argv[0]) { debug( "executing session %\"[s\n", argv ); execute( argv, userEnviron ); logError( "Session %\"s execution failed: %m\n", argv[0] ); } else logError( "Session has no command/arguments\n" ); failsafeArgv[0] = td->failsafeClient; failsafeArgv[1] = 0; execute( failsafeArgv, userEnviron ); logError( "Failsafe client %\"s execution failed: %m\n", failsafeArgv[0] ); cError: sendStr( V_MSG_ERR, 0 ); exit( 1 ); case -1: free( buf ); return 0; } debug( "StartSession, fork succeeded %d\n", *pid ); free( buf ); gSet( &ctltalk ); if (!Setjmp( ctltalk.errjmp )) while (gRecvCmd( &i )) { buf = gRecvStr(); displayStr( i, buf ); free( buf ); gSet( &ctltalk ); gSendInt( 0 ); } gClosen( ctltalk.pipe ); finishGreet(); return 1; }
void ami_fetch_file_poll(const char *scheme_ignored) { struct nsObject *node; struct nsObject *nnode; struct ami_file_fetch_info *fetch; fetch_error_code errorcode; if(IsMinListEmpty(ami_file_fetcher_list)) return; node = (struct nsObject *)GetHead((struct List *)ami_file_fetcher_list); do { errorcode = FETCH_ERROR_NO_ERROR; nnode=(struct nsObject *)GetSucc((struct Node *)node); fetch = (struct ami_file_fetch_info *)node->objstruct; if(fetch->locked) continue; if(!fetch->aborted) { if(fetch->fh) { ULONG len; len = FRead(fetch->fh,ami_file_fetcher_buffer,1,1024); if (len == (ULONG)-1) errorcode = FETCH_ERROR_MISC; else if (len > 0) ami_fetch_file_send_callback( FETCH_DATA, fetch, ami_file_fetcher_buffer, len, errorcode); if((len<1024) && (!fetch->aborted)) { ami_fetch_file_send_callback(FETCH_FINISHED, fetch, NULL, 0, errorcode); fetch->aborted = true; } } else { fetch->fh = FOpen(fetch->path,MODE_OLDFILE,0); if(fetch->fh) { char header[64]; struct ExamineData *fib; if(fib = ExamineObjectTags(EX_FileHandleInput,fetch->fh,TAG_DONE)) { fetch->len = fib->FileSize; FreeDosObject(DOS_EXAMINEDATA,fib); } fetch_set_http_code(fetch->fetch_handle,200); fetch->mimetype = fetch_mimetype(fetch->path); LOG(("mimetype %s len %ld",fetch->mimetype,fetch->len)); snprintf(header, sizeof header, "Content-Type: %s", fetch->mimetype); ami_fetch_file_send_callback(FETCH_HEADER, fetch, header, strlen(header), errorcode); snprintf(header, sizeof header, "Content-Length: %ld", fetch->len); ami_fetch_file_send_callback(FETCH_HEADER, fetch, header, strlen(header), errorcode); } else { STRPTR errorstring; errorstring = ASPrintf("%s %s",messages_get("FileError"),fetch->path); fetch_set_http_code(fetch->fetch_handle,404); errorcode = FETCH_ERROR_HTTP_NOT2; ami_fetch_file_send_callback(FETCH_ERROR, fetch, errorstring, 0, errorcode); fetch->aborted = true; FreeVec(errorstring); } } } if(fetch && fetch->aborted) { fetch_remove_from_queues(fetch->fetch_handle); fetch_free(fetch->fetch_handle); return; } }while(node=nnode); }
void gui_cert_verify(struct browser_window *bw, hlcache_handle *c, const struct ssl_cert_info *certs, unsigned long num) { const struct ssl_cert_info *from; struct session_cert *to; struct session_data *data; struct tree *tree; struct node *node; long i; STRPTR yesorno,reqcontents; int res = 0; struct treeview_window *twin; assert(bw && c && certs); /* copy the certificate information */ data = calloc(1, sizeof(struct session_data)); if (!data) { warn_user("NoMemory", 0); return; } data->url = strdup(content_get_url(c)); if (!data->url) { free(data); warn_user("NoMemory", 0); return; } data->bw = bw; data->num = num; data->certs = calloc(num, sizeof(struct session_cert)); if (!data->certs) { free(data->url); free(data); warn_user("NoMemory", 0); return; } for (i = 0; i < (long)num; i++) { to = &data->certs[i]; from = &certs[i]; to->subject_t = strdup(from->subject); to->issuer_t = strdup(from->issuer); if ((!to->subject_t) || (!to->issuer_t)) { for (; i >= 0; i--) { to = &data->certs[i]; free(to->subject_t); free(to->issuer_t); } free(data->certs); free(data->url); free(data); warn_user("NoMemory", 0); return; } snprintf(to->version, sizeof data->certs->version, "%ld", from->version); snprintf(to->valid_from, sizeof data->certs->valid_from, "%s", from->not_before); snprintf(to->type, sizeof data->certs->type, "%d", from->cert_type); snprintf(to->valid_to, sizeof data->certs->valid_to, "%s", from->not_after); snprintf(to->serial, sizeof data->certs->serial, "%ld", from->serial); } tree = calloc(sizeof(struct tree), 1); if (!tree) { //ro_gui_cert_close(ssl_w); warn_user("NoMemory", 0); return; } tree->root = tree_create_folder_node(NULL, "Root"); if (!tree->root) { // ro_gui_cert_close(ssl_w); warn_user("NoMemory", 0); free(tree); tree = NULL; return; } tree->root->expanded = true; tree->handle = 0; tree->movable = false; tree->no_drag = true; tree->no_vscroll = true; tree->no_furniture = true; tree->single_selection = true; data->tree = tree; /* put the SSL names in the tree */ for (i = 0; i < (long)num; i++) { node = tree_create_leaf_node(tree->root, certs[i].subject); if (node) { node->data.data = TREE_ELEMENT_SSL; tree_set_node_sprite(node, "small_xxx", "small_xxx"); } } tree_initialise(tree); ami_open_tree(tree,AMI_TREE_SSLCERT); twin = (struct treeview_window *)data->tree->handle; if(yesorno = ASPrintf("%s|%s",messages_get("Accept"),messages_get("Reject"))) { if(reqcontents = ASPrintf("%s\n\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s", messages_get("SSLError"), messages_get("Subject"), to->subject_t, messages_get("Issuer"), to->issuer_t, messages_get("Version"), to->version, messages_get("ValidFrom"), to->valid_from, messages_get("ValidTo"), to->valid_to)) { res = TimedDosRequesterTags(TDR_ImageType,TDRIMAGE_QUESTION, TDR_Window,twin->win, TDR_TitleString,messages_get("NetSurf"), TDR_GadgetString,yesorno, TDR_FormatString,reqcontents, TAG_DONE); FreeVec(reqcontents); } FreeVec(yesorno); } if(res == 1) { ami_gui_cert_apply(data); } ami_gui_cert_close(data); }
char *NetworkAddressToHostname(CARD16 connectionType, ARRAY8Ptr connectionAddress) { switch(connectionType) { case FamilyInternet: #if defined(IPv6) && defined(AF_INET6) case FamilyInternet6: #endif { struct hostent *he; char *myDot, *name, *lname; int af_type; #if defined(IPv6) && defined(AF_INET6) char dotted[INET6_ADDRSTRLEN]; if(connectionType == FamilyInternet6) af_type = AF_INET6; else #endif af_type = AF_INET; he = gethostbyaddr((char *)connectionAddress->data, connectionAddress->length, af_type); if(he) { #if defined(IPv6) && defined(AF_INET6) struct addrinfo *ai, *nai; if(!getaddrinfo(he->h_name, NULL, NULL, &ai)) { for(nai = ai; nai; nai = nai->ai_next) { if(af_type == nai->ai_family && !memcmp(nai->ai_family == AF_INET ? (char *)&((struct sockaddr_in *)nai->ai_addr)->sin_addr : (char *)&((struct sockaddr_in6 *)nai->ai_addr)->sin6_addr, connectionAddress->data, connectionAddress->length)) { freeaddrinfo(ai); goto oki; } } freeaddrinfo(ai); #else if((he = gethostbyname(he->h_name)) && he->h_addrtype == AF_INET) { int i; for(i = 0; he->h_addr_list[i]; i++) if(!memcmp(he->h_addr_list[i], connectionAddress->data, 4)) goto oki; #endif LogError("DNS spoof attempt or misconfigured resolver.\n"); } goto gotnone; oki: if(StrDup(&name, he->h_name) && !strchr(name, '.') && (myDot = strchr(localHostname(), '.'))) { if(ASPrintf(&lname, "%s%s", name, myDot)) { #if defined(IPv6) && defined(AF_INET6) if(!getaddrinfo(lname, NULL, NULL, &ai)) { for(nai = ai; nai; nai = nai->ai_next) { if(af_type == nai->ai_family && !memcmp(nai->ai_family == AF_INET ? (char *)&((struct sockaddr_in *)nai->ai_addr)->sin_addr : (char *)&((struct sockaddr_in6 *)nai->ai_addr)->sin6_addr, connectionAddress->data, connectionAddress->length)) { freeaddrinfo(ai); free(name); return lname; } } freeaddrinfo(ai); } #else if((he = gethostbyname(lname)) && he->h_addrtype == AF_INET) { int i; for(i = 0; he->h_addr_list[i]; i++) if(!memcmp(he->h_addr_list[i], connectionAddress->data, 4)) { free(name); return lname; } } #endif free(lname); } } } else { gotnone: /* can't get name, so use emergency fallback */ #if defined(IPv6) && defined(AF_INET6) inet_ntop(af_type, connectionAddress->data, dotted, sizeof(dotted)); StrDup(&name, dotted); #else ASPrintf(&name, "%[4|'.'hhu", connectionAddress->data); #endif LogWarn("Cannot convert Internet address %s to host name\n", name); } return name; } #ifdef DNET case FamilyDECnet: break; #endif /* DNET */ default: break; } return 0; }
static char *NetworkAddressToName(CARD16 connectionType, ARRAY8Ptr connectionAddress, struct sockaddr *originalAddress, CARD16 displayNumber) { switch(connectionType) { case FamilyInternet: #if defined(IPv6) && defined(AF_INET6) case FamilyInternet6: #endif { CARD8 *data; struct hostent *hostent; char *hostname = NULL; char *name; const char *localhost; int multiHomed = 0; int type; #if defined(IPv6) && defined(AF_INET6) struct addrinfo *ai = NULL, *nai, hints; char dotted[INET6_ADDRSTRLEN]; if(connectionType == FamilyInternet6) type = AF_INET6; else #endif type = AF_INET; data = connectionAddress->data; hostent = gethostbyaddr((char *)data, connectionAddress->length, type); if(hostent) { if(sourceAddress) { #if defined(IPv6) && defined(AF_INET6) bzero(&hints, sizeof(hints)); hints.ai_flags = AI_CANONNAME; if(!getaddrinfo(hostent->h_name, NULL, &hints, &ai)) { hostname = ai->ai_canonname; for(nai = ai->ai_next; nai; nai = nai->ai_next) if(ai->ai_protocol == nai->ai_protocol && memcmp(ai->ai_addr, nai->ai_addr, ai->ai_addrlen)) multiHomed = 1; } #else hostent = gethostbyname(hostent->h_name); if(hostent && hostent->h_addrtype == AF_INET) { multiHomed = hostent->h_addr_list[1] != NULL; hostname = hostent->h_name; } #endif } else hostname = hostent->h_name; } localhost = localHostname(); /* * protect against bogus host names */ if(hostname && *hostname && *hostname != '.' && !multiHomed) { if(!strcmp(localhost, hostname)) ASPrintf(&name, "localhost:%d", displayNumber); else { if(removeDomainname) { char *localDot, *remoteDot; /* check for a common domain name. This * could reduce names by recognising common * super-domain names as well, but I don't think * this is as useful, and will confuse more * people */ if((localDot = strchr(localhost, '.')) && (remoteDot = strchr(hostname, '.'))) { /* smash the name in place; it won't * be needed later. */ if(!strcmp(localDot + 1, remoteDot + 1)) *remoteDot = '\0'; } } ASPrintf(&name, "%s:%d", hostname, displayNumber); } } else { #if defined(IPv6) && defined(AF_INET6) if(multiHomed) { if(connectionType == FamilyInternet) { data = (CARD8 *)&((struct sockaddr_in *)originalAddress)->sin_addr; } else { data = (CARD8 *)&((struct sockaddr_in6 *)originalAddress)->sin6_addr; } } inet_ntop(type, data, dotted, sizeof(dotted)); ASPrintf(&name, "%s:%d", dotted, displayNumber); #else if(multiHomed) data = (CARD8 *)&((struct sockaddr_in *)originalAddress)->sin_addr; ASPrintf(&name, "%[4|'.'hhu:%d", data, displayNumber); #endif } #if defined(IPv6) && defined(AF_INET6) if(ai) freeaddrinfo(ai); #endif return name; } #ifdef DNET case FamilyDECnet: return NULL; #endif /* DNET */ default: return NULL; } }