Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Anonix.

Name: Cudder, HAHAHaruhi, and !w4lolitaKs 2008-05-05 23:42

Readers! Realize a reality rendered repugnant by the repression of reckless relentless regimes. Realize the retrogress of society, a reprehensible rabble of retardation and revolting reluctance. Really? Reevaluate and reconsider. Reexamine the results of today and recall remnants of yesterday. Rise, rebel, and retaliate against regression! A rebirth, redemptive and refreshing. Refuse to react without reason. Rather, rehabilitate the mind and restore knowledge and intelligence. Resurrect progress and never regret. Take the route of restless revival. Reinitiate The Revolution.

ANONIX
http://rapidshare.com/files/112878961/sayanonix.mp3.html

Name: Anonymous 2008-09-17 12:26

>>760
No, like this

/* @chmod.c */
#include <ctype.h>
#include <errno.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>

int opt_R;
char *g_nam,*sav_path;
int (*chmodder)(char *,struct stat *);

void save_path() {
 int pbsize=1024;
 if(!(sav_path=malloc(pbsize))) {
 perror_die:
  perror(0);
  exit(1);
 }
 errno=0;
 while(!getcwd(sav_path,pbsize)) {
  if(errno!=ERANGE)
   goto perror_die;
  if(!(sav_path=realloc(sav_path,2*pbsize)))
   goto perror_die;
  pbsize*=2;
 }
}

void rest_path() {
 if(chdir(sav_path)) {
  fprintf(stderr,"%s: cannot restore path: %s\n",g_nam,strerror(errno));
  exit(1);
 }
 free(sav_path);
}

struct visited {
 struct visited *next;
 dev_t dev;
 ino_t ino;
} *v_stack;

int add_visited(struct stat *s) {
 struct visited *v;
 if(!(v=malloc(sizeof(struct visited))))
  return 1;
 v->dev = s->st_dev;
 v->ino = s->st_ino;
 v->next = v_stack;
 if(v_stack)
  v_stack->next=v;
 else
  v_stack=v;
 return 0;
}

int del_visited() {
 if(v_stack) {
  struct visited *v = v_stack->next;
  free(v_stack);
  v_stack=v;
  return 0;
 }
 return 1;
}

int is_visited(struct stat *s) {
 struct visited *v=v_stack;
 while(v) {
  if(v->dev==s->st_dev && v->ino==s->st_ino)
   return 1;
  v=v->next;
 }
 return 0;
}

mode_t abs_mode;
int abs_chmodder(char *path,struct stat *st) {
 return chmod(path,abs_mode);
}

/* [[ugoa]=|+|-[rwxstugo][,]]... */
char *sym_mode;
int sym_chmodder(char *path,struct stat *st) {
 char *i=sym_mode;

 while(*i) {
  char c;
  char chg;
  mode_t target=0,new,new_mode=st->st_mode;

 m_get:
  c=*(i++);
 m_noget:
  target=0;
  for(;;) {
   switch(c) {
   case 'u':
    target|=07700;
    break;
   case 'g':
    target|=07070;
    break;
   case 'o':
    target|=07007;
    break;
   case 'a':
    target=07777;
    break;
   case ',':
    goto m_get;
   case '=':
   case '+':
   case '-':
    if(!target)
     target=0777 & ~umask(0);
    goto mode_next;
   case 0:
    return chmod(path,new_mode);
   default:
   invalid_mode:
    fprintf(stderr,"%s: invalid symbolic mode\n",g_nam);
    exit(1);
   }
   c=*(i++);
  }
 mode_next:
  chg=c;
  c=*(i++);
  new=0;
  for(;;) {
   switch(c) {
   case 'r':
    new|=0444;
    break;
   case 'w':
    new|=0222;
    break;
   case 'X':
    target|=0111;
   case 'x':
    new|=0111;
    break;
   case 's':
    if(target&0700)
     new|=04000;
    if(target&070)
     new|=02000;
    break;
   case 't':
    new|=01000;
    break;
   case 'u':
    new=(new_mode&0700)|((new_mode&0700)>>3)|((new_mode&0700)>>6);
    goto apply_mode;
   case 'g':
    new=(new_mode&070)|((new_mode&070)<<3)|((new_mode&070)>>3);
    goto apply_mode;
   case 'o':
    new=(new_mode&7)|((new_mode&7)<<3)|((new_mode&7)<<6);
    goto apply_mode;
   case '-':
   case '+':
   case '=':
   case ',':
   case 0:
   apply_mode:
    switch(chg) {
    case '+':
     new_mode|=(new&target);
     break;
    case '-':
     new_mode&=~(new&target);
     break;
    case '=':
     new_mode = (new_mode&~target)|(new&target);
     break;
    }
    if(c=='u' || c=='g' || c=='o')
     break;
    if(c=='+' || c=='-' || c=='=')
     goto mode_next;
    if(!c)
     goto m_noget;
    goto m_get;
   default:
    goto invalid_mode;
   }
   c=*(i++);
  }
 }
 return 0;
}

int do_chmod(char *path) {
 struct stat f_stat;
 DIR *cur;
 struct dirent *cur_file;
 char *filename;
 int i=0;

 if(lstat(path,&f_stat)) {
  fprintf(stderr,"%s: cannot stat %s: %s\n",g_nam,path,strerror(errno));
  return 1;
 }
 if(chmodder(path,&f_stat)) {
  fprintf(stderr,"%s: cannot chmod %s: %s\n",g_nam,path,strerror(errno));
  return 1;
 }
 if(opt_R) {
  if(S_ISDIR(f_stat.st_mode) && !is_visited(&f_stat)) {
   if(chdir(path)) {
    fprintf(stderr,"%s: cannot enter %s: %s\n",g_nam,path,strerror(errno));
    return 1;
   }
   if(add_visited(&f_stat)) {
    fprintf(stderr,"%s: cannot add %s to stack: %s\n",g_nam,path,strerror(errno));
    return 1;
   }
   if(!(cur=opendir("."))) {
    fprintf(stderr,"%s: cannot open directory %s: %s\n",g_nam,path,strerror(errno));
    i=1;
    goto enter_parent;
   }
   while(cur_file=readdir(cur)) {
    filename=cur_file->d_name;
    if(!strcmp(filename,".")||!strcmp(filename,".."))
     continue;
    i|=do_chmod(filename);
   }
   i|=closedir(cur);
  enter_parent:
   del_visited();
   if(chdir("..")) {
    fprintf(stderr,"%s: cannot enter parent of %s: %s\n",g_nam,path,strerror(errno));
    return 1;
   }
  }
 }
 return i;
}

int main(int argc, char **argv) {
 int c;

 g_nam=argv[0];
 opterr=0;
 while((c=getopt(argc,argv,"R"))!=-1) {
  if(c=='R')
   opt_R=1;
  else {
   fprintf(stderr,"%s: unrecognized option %c\n",g_nam,optopt);
   return 1;
  }
 }
 if(!argv[optind]) {
 usage:
  fprintf(stderr,"usage: %s [-R] mode file ...\n",g_nam);
  return 1;
 }
 /* get mode */
 if(isdigit(argv[optind][0])) { /* octal mode */
  sscanf(argv[optind],"%o",&abs_mode);
  chmodder=abs_chmodder;
 } else { /* symbolic mode */
  sym_mode=argv[optind];
  chmodder=sym_chmodder;
 }
 if(optind+1>=argc)
  goto usage;
 /* apply to files (recursively if -R is set) */
 for(optind++,c=0;optind<argc;optind++) {
  save_path();
  c|=do_chmod(argv[optind]);
  rest_path();
 }
 return c;
}

Newer Posts