Example #1
0
static BOOL trust_password_file_lock(char *domain, char *name)
{
  pstring mac_file;

  if(mach_passwd_lock_depth == 0) {
    int fd;

    get_trust_account_file_name( domain, name, mac_file);

    if ((fd = sys_open(mac_file, O_RDWR, 0)) == -1)
      return False;

    if((mach_passwd_fp = fdopen(fd, "w+b")) == NULL) {
	DEBUG(0,("trust_password_lock: cannot open file %s - Error was %s.\n",
	      mac_file, strerror(errno) ));
	return False;
    }

    if(!pw_file_lock(fileno(mach_passwd_fp), F_WRLCK, 60, &mach_passwd_lock_depth)) {
      DEBUG(0,("trust_password_lock: cannot lock file %s\n", mac_file));
      fclose(mach_passwd_fp);
      return False;
    }

  }

  return True;
}
Example #2
0
BOOL trust_password_lock( char *domain, char *name, BOOL update)
{
  pstring mac_file;

  if(mach_passwd_lock_depth == 0) {

    get_trust_account_file_name( domain, name, mac_file);

    if((mach_passwd_fp = sys_fopen(mac_file, "r+b")) == NULL) {
      if(errno == ENOENT && update) {
        mach_passwd_fp = sys_fopen(mac_file, "w+b");
      }

      if(mach_passwd_fp == NULL) {
        DEBUG(0,("trust_password_lock: cannot open file %s - Error was %s.\n",
              mac_file, strerror(errno) ));
        return False;
      }
    }

    chmod(mac_file, 0600);

    if(!pw_file_lock(fileno(mach_passwd_fp), (update ? F_WRLCK : F_RDLCK), 
                                      60, &mach_passwd_lock_depth))
    {
      DEBUG(0,("trust_password_lock: cannot lock file %s\n", mac_file));
      fclose(mach_passwd_fp);
      return False;
    }

  }

  return True;
}