⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rcfile.c

📁 站点映像程序
💻 C
📖 第 1 页 / 共 2 页
字号:
		else if( strcmp( val, "http" ) == 0 ) {		    this_site->protocol = siteproto_http;		    this_site->driver = &dav_driver;		}#endif /* USE_DAV */	        else {		    ret = RC_CORRUPT;		    break;		}	    } else if( strcmp( key, "ftp" ) == 0 ) {		if( strcmp( val, "nopasv" ) == 0 ) {		    this_site->ftp_pasv_mode = false;		} else {		    ret = RC_CORRUPT;		}	    } else if( strcmp( key, "http" ) == 0 ) {		if( strcmp( val, "noexpect" ) == 0 ) {		    this_site->http_no_expect = true;		} else if( strcmp( val, "limit" ) == 0 ) {		    this_site->http_limit = true;		} else {		    ret = RC_CORRUPT;		}	    } else {		/* Unknown key! */		ret = RC_CORRUPT;		break;	    }	} else {	    {		ret = RC_CORRUPT;		break; 	    }	}    }    fclose( fp );    return ret;}const char *rc_get_netrc_password( const char *server, const char *username ) {    netrc_entry *found;    found = search_netrc( netrc_list, server );    if( found == NULL ) {	return NULL;    }    if( strcmp( found->account, username ) == 0 ) {	return found->password;    } else {	return NULL;    }}/* Returns zero if site is properly defined, else non-zero */int rc_verifysite( struct site_t *any_site ) {    struct stat localst;    char *temp;    int ret;    /* Check they specified everything in the rcfile */    if( any_site->server == NULL ) {	return SITE_NOSERVER;    } else if( any_site->username == NULL ) {	return SITE_NOUSERNAME;    } else if( any_site->password == NULL ) {	if( havenetrc ) {	    const char *pass;	    DEBUG( DEBUG_RCFILE, "Checking netrc for password for %s@%s...",		   any_site->username, any_site->server );	    pass = rc_get_netrc_password( any_site->server, any_site->username );	    if( pass == NULL ) {		DEBUG( DEBUG_RCFILE, "none found.\n" );		return SITE_NOPASSWORD;	    } else {		DEBUG( DEBUG_RCFILE, "found!\n" );		any_site->password = (char *) pass;	    }	} else {	    return SITE_NOPASSWORD;	}    }    if( any_site->remote_root_user == NULL ) {	return SITE_NOREMOTEDIR;    } else if( any_site->local_root_user == NULL ) {	return SITE_NOLOCALDIR;    }        /* Need a home directory if we're using relative local root */    if( home == NULL && any_site->local_root )	return SITE_NOLOCALREL;    if( any_site->remote_isrel ) {	any_site->remote_root = strdup( any_site->remote_root_user + 2 );    } else {	any_site->remote_root = strdup( any_site->remote_root_user );    }    if( any_site->local_isrel ) {	/* We skip the first char ('~') of l_r_u */	temp = malloc( strlen( any_site->local_root_user ) + 		       strlen( home ) );	strcpy( temp, home );	strcat( temp, any_site->local_root_user + 1 );	any_site->local_root = temp;    } else {	any_site->local_root = any_site->local_root_user;    }    /* Now check the local directory actually exists.     * To do this, stat `/the/local/root/.', which will fail if the     * can't read the directory or if it's a file not a directory */    temp = malloc( strlen( any_site->local_root ) + 2 );    strcpy( temp, any_site->local_root ); /* must have trailing / */    strcat( temp, "." );     ret = stat( temp, &localst );    free( temp );    if( ret != 0 ) {	return SITE_ACCESSLOCALDIR;    }    /* Protocol-specific checks */    switch( any_site->protocol ) {    case siteproto_ftp:	/* FTP checks */	if( any_site->symlinks == sitesym_maintain ) {	    return SITE_NOMAINTAIN;	}	break;    case siteproto_http:	/* HTTP checks */	if( any_site->remote_isrel ) { 	    return SITE_NOREMOTEREL;	}	if( any_site->perms != sitep_ignore ) {	    return SITE_NOPERMS;	}		/* fall through */    default:	break;    }	      /* Assign default ports if they didn't bother to */    if( any_site->port == 0 ) {	DEBUG( DEBUG_RCFILE, "No port specified... lookup by name %s\n",	       any_site->driver->service_name );	any_site->port = get_tcp_port( any_site->driver->service_name );	if( any_site->port == 0 ) {	    any_site->port = any_site->driver->service_port;	    DEBUG( DEBUG_RCFILE, "Could not find retrieve port by name, using fallback: %d\n", any_site->port );	} else {	    DEBUG( DEBUG_RCFILE, "Assigned default port: %d\n", any_site->port );	}    }    return 0;}int init_netrc( ) {    if( !havenetrc ) return 0;    netrc_list = parse_netrc( netrcfile );    if( netrc_list == NULL ) {	/* Couldn't parse it */	return 1;    } else {	/* Could parse it */	return 0;    }}/* Checks the perms of the rcfile and site storage directory. */int init_paths( ) {    struct stat st;    if( stat( rcfile, &st ) < 0 ) {	DEBUG( DEBUG_RCFILE, "stat failed on %s: %s\n", 	       rcfile, strerror(errno) );	return RC_OPENFILE;    }#if !defined (__EMX__) && !defined(__CYGWIN__)    if( (st.st_mode & ~(S_IFREG | S_IREAD | S_IWRITE )) > 0 ) {	return RC_PERMS;    }#endif    if( (netrcfile == 0) || (stat( netrcfile, &st ) < 0) ) {	havenetrc = false;#if !defined (__EMX__) && !defined(__CYGWIN__)    } else if( (st.st_mode & ~(S_IFREG | S_IREAD | S_IWRITE )) > 0 ) {	return RC_NETRCPERMS;#endif    } else {	havenetrc = true;    }    if( stat( copypath, &st ) < 0 ) {	DEBUG( DEBUG_RCFILE, "stat failed on %s: %s\n", 	       copypath, strerror(errno) );	return RC_DIROPEN;    }#if !defined (__EMX__) && !defined(__CYGWIN__)    if( (st.st_mode & ~(S_IFDIR | S_IREAD | S_IWRITE | S_IEXEC )) > 0 ) {	return RC_DIRPERMS;    }#endif    return 0;}int init_env( ) {    /* Assign default filenames if they didn't give us any */    home = getenv("HOME");    if( home == NULL ) {	if( ( rcfile == NULL ) || ( copypath == NULL ) ) {	    /* We need a $HOME or both rcfile and info dir path */	    return 1;	} else {	    /* No $HOME, but we've got the rcfile and info dir path */	    return 0;	}    }    if( rcfile == NULL ) {	rcfile = malloc( strlen(RCNAME) + strlen(home) + 1);	strcpy( rcfile, home );	strcat( rcfile, RCNAME );    }    if( copypath == NULL ) {	copypath = malloc( strlen(COPYNAME) + strlen(home) + 1);	strcpy( copypath, home );	strcat( copypath, COPYNAME );    }    netrcfile = malloc( strlen(NETRCNAME) + strlen(home) + 1 );    strcpy( netrcfile, home );    strcat( netrcfile, NETRCNAME );    return 0;}/* rcfile_write() by Lee Mallabone, cleaned by JO. * Write the contents of list_of_sites to the specified 'filename' * in the standard sitecopy rc format. * * Any data already in 'filename' is over-written. */int rcfile_write (char *filename, struct site_t *list_of_sites) {      struct site_t *current;   struct exclude_t *excl;   FILE *fp;      if ( (fp = fopen (filename, "w")) == NULL) {      printf ("There was a problem writing to the sitecopy configuration file.\n\nCheck permissions on %s.", filename);      return RC_OPENFILE;   }   /* Set rcfile permissions properly */#if !defined (__EMX__) && !defined(__CYGWIN__)   if (fchmod (fileno(fp), 00600) == -1) {      return RC_PERMS;   }#endif      for (current=list_of_sites; current!=NULL; current=current->next) {      /* Okay so this maybe isn't the most intuitive thing to look at.       * With any luck though, the rcfile's it produces will be. :) */      if (fprintf (fp, "site %s\n", current->name) == -1) {	 return RC_CORRUPT;      }      if (fprintf (fp, "  server %s\n  username %s\n  password %s\n  remote %s\n  local %s\n",	       current->server, 	       current->username,	       current->password, current->remote_root_user,	       current->local_root_user) == -1) {	 return RC_CORRUPT;      }      if (fprintf (fp, "  protocol %s\n", current->protocol==siteproto_ftp?"ftp":"http") == -1) {	 return RC_CORRUPT;      }		/* Makes sense to have protocol (ish) options after we specify the protocol. */		/* Warning, if the http declarations in site_t are ever surrounded by an 			ifdef USE_DAV, then this will need to be changed.		*/		if (fprintf (fp, "%s%s%s%s%s%s",						 current->nodelete?"  nodelete\n":"",						 current->checkmoved?"  checkmoved\n":"",						 current->nooverwrite?"  nooverwrite\n":"",						 current->ftp_pasv_mode?"":"  ftp nopasv\n",						 current->http_limit?"  http limit\n":"",						 current->http_no_expect?"  http noexpect\n":"") == -1) {		  return RC_CORRUPT;		}      if (current->port > 0)  { /* Sanity check */	 if (fprintf (fp, "  port %d\n", current->port) == -1) {	    return RC_CORRUPT;	 }      }            /* Add the site's URL if one has been supplied. */      if (current->url) {	 if (fprintf (fp, "  url %s\n", current->url) == -1) {	    return RC_CORRUPT;	 }      }            /* Permissions now */      switch (current->perms) {       case (sitep_ignore): 	 if (fprintf (fp, "  permissions ignore\n") == -1) {	    return RC_CORRUPT;	 }	 break;       case (sitep_exec):	 if (fprintf (fp, "  permissions exec\n") == -1) {	    return RC_CORRUPT;	 }	 break;       case (sitep_all):	 if (fprintf (fp, "  permissions all\n") == -1) {	    return RC_CORRUPT;	 }	 break;      }      /* Sym link mode */      switch (current->symlinks) {       case (sitesym_ignore): 	 if (fprintf (fp, "  symlinks ignore\n") == -1) {	    return RC_CORRUPT;	 }	 break;       case (sitesym_follow):	 if (fprintf (fp, "  symlinks follow\n") == -1) {	    return RC_CORRUPT;	 }	 break;       case (sitesym_maintain):	 if (fprintf (fp, "  symlinks maintain\n") == -1) {	    return RC_CORRUPT;	 }	 break;      }      /* Excludes */      for (excl=current->excludes; excl!=NULL; excl=excl->next) {	  if (fprintf (fp, "  exclude \"%s\"\n", excl->pattern) == -1) {		return RC_CORRUPT;	    }      }   }   if (fclose (fp) != 0)      return RC_CORRUPT;   return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -